Agent skill

Stale Cache External Service Recovery

by divinevideo in divinevideo/divine-mobile

Handle stale local cache when external service loses/resets data.

MPL-2.0Auto-check passed

Install Stale Cache External Service Recovery

skills CLI
$ npx skills add divinevideo/divine-mobile --skill stale-cache-external-service-recovery -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install divinevideo/divine-mobile stale-cache-external-service-recovery --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/divinevideo/divine-mobile.git skills-src && mkdir -p .claude/skills && cp -r skills-src/.agents/skills/stale-cache-external-service-recovery .claude/skills/stale-cache-external-service-recovery && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
stale-cache-external-service-recovery
GitHub stars
266
Token cost
~1.4k tokens
SKILL.md length
332 words
Files
1
Skills in repo
103
Repo updated
First seen
Licence
MPL-2.0

At a glance

Handle stale local cache when external service loses/resets data.

  • Works in 6 steps: Attempt normal refresh first: Try to… → Detect 404 specifically: Check for "not… → Delete stale entry: Remove the invalid… → …
  • Token refresh fails with not found
  • SKILL.md covers Problem, Context / Trigger Conditions, Solution and Verification, plus 3 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md

What it does

Stale Cache External Service Recovery is an agent skill from divinevideo/divine-mobile. Handle stale local cache when external service loses/resets data. Use when: (1) Token refresh fails with "not found" or 404 errors, (2) Cached identifiers (pubkeys, user IDs) don't exist on external service anymore, (3) External service was reset/migrated but local cache has old values. Pattern: detect 404 specifically, delete stale cache entry, recreate on external service, update cache with new values. Complements local-cache-idempotency-fallback skill.

Its SKILL.md is about 1.4k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

The licence is MPL-2.0.

When your agent uses it

  • Token refresh fails with not found
  • Cached identifiers (pubkeys
  • User IDs) dont exist on external service anymore
  • External service was reset/migrated but local cache has old values

Example prompts

  • “not found”
  • “/stale-cache-external-service-recovery”

Workflow steps

6 steps, taken from the first numbered list in SKILL.md.

  1. Attempt normal refresh first: Try to validate/refresh cached credentials
  2. Detect 404 specifically: Check for "not found" in error message or 404 status
  3. Delete stale entry: Remove the invalid cache entry before recreating
  4. Recreate on external: Create fresh resource with same input identifiers
  5. Update cache: Store new values for future runs
  6. Distinguish from other errors: Only handle 404; other errors may need different handling

What it can do on your machine

Read from SKILL.md and the folder at commit c3d6f7e. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are typescript).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Stale Cache External Service Recovery loads about 1.4k tokens when it runs. Until then it costs about 124 tokens; SKILL.md has 332 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~124
When it runs · the whole SKILL.md, loaded when a task matches
~1.4k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from divinevideo/divine-mobile at commit c3d6f7e, republished under its MPL-2.0 licence (© divinevideo). 332 words, ~1,406 tokens.

Download SKILL.mdSave it as .claude/skills/stale-cache-external-service-recovery/SKILL.md (or your agent's skills folder).
name
stale-cache-external-service-recovery
description
Handle stale local cache when external service loses/resets data. Use when: (1) Token refresh fails with "not found" or 404 errors, (2) Cached identifiers (pubkeys, user IDs) don't exist on external service anymore, (3) External service was reset/migrated but local cache has old values. Pattern: detect 404 specifically, delete stale cache entry, recreate on external service, update cache with new values. Complements local-cache-idempotency-fallback skill.
author
Claude Code
version
1.0.0
date
2026-01-25

Stale Cache Recovery When External Service Loses Data

Problem

When using your database as a cache/idempotency layer (see local-cache-idempotency-fallback), a new failure mode emerges: the external service loses or resets its data, but your cache still has the old values. Operations fail with misleading errors because the cached identifiers don't exist on the external service anymore.

Context / Trigger Conditions

  • Token refresh fails with 404 "User with pubkey/id not found"
  • Operations fail with "Invalid or expired token" but the real issue is missing user
  • External service was reset, migrated, or lost data
  • Cached identifiers (pubkeys, API keys, user IDs) are valid in cache but not on service
  • Error message is misleading - suggests token issue when it's actually a missing resource

Solution

Detect the specific "not found" case and handle it separately from other errors:

typescript
if (cached) {
  pubkey = cached.pubkey;
  token = cached.token;

  try {
    // Try to refresh/validate the cached credentials
    const freshToken = await externalApi.getTokenByPubkey(pubkey);
    token = freshToken;
    console.log(`Pubkey: ${pubkey} (token refreshed)`);
  } catch (error) {
    const errMsg = error instanceof Error ? error.message : String(error);

    // CRITICAL: Detect "not found" specifically - cache is stale
    if (errMsg.includes("not found") || response.status === 404) {
      console.log(`Cached identifier not on external service, recreating...`);

      // 1. Delete stale cache entry
      await db.deleteUser(userId);

      // 2. Create fresh resource on external service
      const result = await externalApi.createUser(userId, username);
      pubkey = result.pubkey;
      token = result.token;
      console.log(`Pubkey: ${pubkey} (recreated)`);

      // 3. Cache new values
      await db.saveUser({ userId, pubkey, token });
    } else {
      // Other error (e.g., user claimed account, rate limit) - can't proceed
      console.log(`Refresh failed: ${errMsg}`);
      continue; // or throw
    }
  }
}
Key Pattern
  1. Attempt normal refresh first: Try to validate/refresh cached credentials
  2. Detect 404 specifically: Check for "not found" in error message or 404 status
  3. Delete stale entry: Remove the invalid cache entry before recreating
  4. Recreate on external: Create fresh resource with same input identifiers
  5. Update cache: Store new values for future runs
  6. Distinguish from other errors: Only handle 404; other errors may need different handling

Verification

  1. Simulate external service data loss (or clear its database)
  2. Run script with stale local cache
  3. Should see "recreating" message, not crash with 401/404
  4. New values cached and used for subsequent operations
  5. Script completes successfully

Example

Real-world application - Keycast pubkey cache recovery:

typescript
const cached = await pgDb.getImportedUser(creator.user_id);
let pubkey: string;
let token: string;

if (cached) {
  pubkey = cached.pubkey;
  token = cached.token;

  try {
    const freshToken = await keycast.getTokenByPubkey(pubkey);
    token = freshToken;
    await pgDb.saveImportedUser({ ...cached, token: freshToken });
    console.log(`Pubkey: ${pubkey} (token refreshed)`);
  } catch (refreshError) {
    const errMsg = refreshError instanceof Error ? refreshError.message : String(refreshError);

    if (errMsg.includes("not found")) {
      // Keycast doesn't have this pubkey - cache is stale
      console.log(`Cached pubkey not on Keycast, recreating user...`);

      // Delete stale entry
      await pgDb.deleteImportedUser(creator.user_id);

      // Create fresh user
      const result = await keycast.createPreloadedUser(
        creator.user_id,
        username,
        displayName
      );
      pubkey = result.pubkey;
      token = result.token;
      console.log(`Pubkey: ${pubkey} (recreated)`);

      // Cache new account
      await pgDb.saveImportedUser({
        vine_user_id: creator.user_id,
        username: creator.username,
        pubkey,
        token,
        events_published: 0,
      });
    } else {
      // Other error - user may have claimed account, can't proceed
      console.log(`Token refresh failed: ${errMsg}`);
      console.log(`Skipping ${creator.username} - cannot sign events`);
      continue;
    }
  }
}

Notes

  • This complements local-cache-idempotency-fallback - use both together
  • The misleading error chain: 404 "not found" → continue with stale token → 401 "invalid token"
  • Always delete before recreate to avoid accumulating orphan cache entries
  • Consider logging which entries were stale for debugging/monitoring
  • If external service is frequently losing data, investigate root cause
  • The new pubkey will be different from the old one - downstream systems may need updates
  • local-cache-idempotency-fallback: The base pattern this skill extends
  • Database retry logic for connection resets (separate concern)

© divinevideo, MPL-2.0. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in .agents/skills/stale-cache-external-service-recovery of divinevideo/divine-mobile.

Open the folder on GitHubat commit c3d6f7e

Compare with similar skills

Stale Cache External Service Recovery next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Stale Cache External Service Recovery compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Stale Cache External Service Recovery this skilldivinevideo/divine-mobile266—~1.4kAutomated safety check: PassMPL-2.0
Prompt Cachingsickn33/agentic-awesome-skills47k2 repos~3.4kAutomated safety check: PassMIT
Prompt Cachingdavila7/claude-code-templates33k5 repos~452Automated safety check: PassMIT
Error Handlingaffaan-m/ECC277k1 repos~2.7kAutomated safety check: PassMIT
Turborepo Cachingwshobson/agents40k9 repos~2kAutomated safety check: NotesMIT
OmniRoute LLM Cachediegosouzapw/OmniRoute75k—~529Automated safety check: PassMIT

Similar skills

  • Prompt Caching

    sickn33/agentic-awesome-skills

    Caching strategies for LLM prompts including Anthropic prompt caching, response caching, and CAG (Cache Augmented Generation)

    47k GitHub starsUsed in 2 repos~3.4k tokens
    AI & LLM EngineeringAuto-check passed
  • Prompt Caching

    davila7/claude-code-templates

    Caching strategies for LLM prompts including Anthropic prompt caching, response caching, and CAG (Cache Augmented Generation) Use when: prompt caching, cache prompt, response cache, cag, cache…

    33k GitHub starsUsed in 5 repos~452 tokens
    Backend & APIsAuto-check passed
  • Error Handling

    affaan-m/ECC

    Patterns for robust error handling across TypeScript, Python, and Go.

    277k GitHub starsUsed in 1 repo~2.7k tokens
    DevelopmentAuto-check passed
  • Turborepo Caching

    wshobson/agents

    Configures Turborepo pipelines and local or remote caching for monorepo builds, including Vercel remote cache, a self-hosted cache and cache-miss debugging.

    40k GitHub starsUsed in 9 repos~2k tokens
    DevelopmentAuto-check: notes
  • OmniRoute LLM Cache

    diegosouzapw/OmniRoute

    Documents OmniRoute's cache endpoints for reading cache statistics and clearing entries, statistics or the reasoning cache, with notes on TTL and similarity settings.

    75k GitHub stars~529 tokensUpdated today
    Backend & APIsAuto-check passed
  • Caching

    zebbern/claude-code-guide

    Caching strategies — invalidation, TTL guidelines, cache keys, cache layers, and when not to cache.

    4.7k GitHub stars~1.5k tokensUpdated yesterday
    Backend & APIsAuto-check passed

More from divinevideo/divine-mobile

All 103 skills in this repo
  • Fix ArgoCD ExternalSecret deployment failing with "namespace X is not permitted in project Y".

    266 GitHub stars~931 tokensUpdated today
    Auto-check passed
  • Art Direct

    divinevideo/divine-mobile

    Art direction for any content — reads text, PDF, Word, HTML, PPT, then proposes 2-3 creative directions with photography style, mood, and visual language.

    266 GitHub stars~4.8k tokensUpdated today
    Auto-check passed
  • Async Await Null Race Condition

    divinevideo/divine-mobile

    Fix "Null check operator used on a null value" errors when an object is set to null during an async await.

    266 GitHub stars~881 tokensUpdated today
    Auto-check passed
  • AWS V4 Signing Custom Headers Gcs

    divinevideo/divine-mobile

    Add custom metadata headers (x-amz-meta-) to AWS v4 signed requests for GCS S3-compatible API.

    266 GitHub stars~1k tokensUpdated today
    Auto-check passed
  • Bash Herestring Newline Secrets

    divinevideo/divine-mobile

    Fix password/secret authentication failures caused by trailing newlines when creating Google Cloud secrets (or similar) with bash here-strings.

    266 GitHub stars~791 tokensUpdated today
    Auto-check passed
  • Fix silent video/media processing failures caused by URL extraction code that filters on file extensions (.mp4, .webm, .webp).

    266 GitHub stars~1.1k tokensUpdated today
    Auto-check passed

Questions about Stale Cache External Service Recovery

What does Stale Cache External Service Recovery do?

Handle stale local cache when external service loses/resets data. Stale Cache External Service Recovery is an agent skill from divinevideo/divine-mobile. Handle stale local cache when external service loses/resets data.

When should I use Stale Cache External Service Recovery?

Stale Cache External Service Recovery fits situations like: token refresh fails with not found; cached identifiers (pubkeys; user IDs) dont exist on external service anymore; external service was reset/migrated but local cache has old values.

How do I install Stale Cache External Service Recovery in Claude Code?

Run `npx skills add divinevideo/divine-mobile --skill stale-cache-external-service-recovery -a claude-code`. Or copy the skill folder (.agents/skills/stale-cache-external-service-recovery in divinevideo/divine-mobile) into .claude/skills/stale-cache-external-service-recovery in your project. Claude Code loads it when a task matches its description.

How do I install Stale Cache External Service Recovery in Codex?

Run `npx skills add divinevideo/divine-mobile --skill stale-cache-external-service-recovery -a codex`. Or copy the skill folder (.agents/skills/stale-cache-external-service-recovery in divinevideo/divine-mobile) into .agents/skills/stale-cache-external-service-recovery in your project. Codex loads it when a task matches its description.

Can I use Stale Cache External Service Recovery in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add divinevideo/divine-mobile --skill stale-cache-external-service-recovery -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/stale-cache-external-service-recovery, .gemini/skills/stale-cache-external-service-recovery, .github/skills/stale-cache-external-service-recovery and .opencode/skills/stale-cache-external-service-recovery in your project.

What does Stale Cache External Service Recovery need to run?

SKILL.md names no scripts, command-line tools or credentials: Stale Cache External Service Recovery is instructions for the agent only.

Does Stale Cache External Service Recovery access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Stale Cache External Service Recovery safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Stale Cache External Service Recovery use?

Stale Cache External Service Recovery is published under the MPL-2.0 licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Stale Cache External Service Recovery use?

About 1.4k tokens (SKILL.md is roughly 5.6k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Stale Cache External Service Recovery?

Skills that share tags, products or a category with Stale Cache External Service Recovery: Prompt Caching (sickn33/agentic-awesome-skills, 47k stars), Prompt Caching (davila7/claude-code-templates, 33k stars), Error Handling (affaan-m/ECC, 277k stars) and Turborepo Caching (wshobson/agents, 40k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Stale Cache External Service Recovery?

divinevideo (a GitHub organization) maintains it in divinevideo/divine-mobile, which has 266 GitHub stars. The repository holds 103 skills in this directory. The repository was last updated on October 10, 2026.

Source: divinevideo/divine-mobile on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.