Skip to content

fix(deepseek): enable prompt cache key in model catalog#92565

Closed
fsdwen wants to merge 2 commits into
openclaw:mainfrom
fsdwen:fix/91016-deepseek-prompt-cache
Closed

fix(deepseek): enable prompt cache key in model catalog#92565
fsdwen wants to merge 2 commits into
openclaw:mainfrom
fsdwen:fix/91016-deepseek-prompt-cache

Conversation

@fsdwen

@fsdwen fsdwen commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Summary

DeepSeek models don't receive prompt_cache_key in API requests, causing prompt caching to silently fail. This is because the boundary-aware cache system requires compat.supportsPromptCacheKey: true to be explicitly set, and DeepSeek's model catalog never enabled it. Users upgrading from older versions lose cache hit rates (50%+ → 0%), burning through tokens at full cost.

Fix

One field added in buildDeepSeekModelDefinition() (extensions/deepseek/models.ts):

  return {
    ...model,
    api: "openai-completions",
+   compat: {
+     ...model.compat,
+     supportsPromptCacheKey: true,
+   },
  };

When supportsPromptCacheKey is true, the OpenAI-completions provider includes prompt_cache_key in requests. DeepSeek's prefix-based caching can then recognize repeated prefixes and return cached_tokens in the usage response.

Files changed

  • extensions/deepseek/models.ts: +8 (set supportsPromptCacheKey in model catalog)
  • extensions/deepseek/index.test.ts: +27 (2 tests: flag enabled + preserves existing compat)

Related

Fixes #91016

Real behavior proof

  • Behavior addressed: DeepSeek models never send prompt_cache_key → DeepSeek API never returns cached_tokens → OpenClaw reports zero cache reads and users pay full input token cost on every request
  • Real environment tested: Linux Node 24 — the DeepSeek model definition module (extensions/deepseek/models.ts) is loaded and exercised through the plugin registration path used by the OpenClaw provider catalog
  • Exact steps or command run after this patch:
    # Load the DeepSeek extension and verify model definitions include the cache key flag.
    # This exercises the exact buildDeepSeekModelDefinition() production code path.
    $ node --import tsx -e "
    import { buildDeepSeekModelDefinition } from './extensions/deepseek/models.js';
    const v4flash = buildDeepSeekModelDefinition({
      id: 'deepseek-v4-flash', name: 'DeepSeek V4 Flash',
      input: ['text'], reasoning: true,
      contextWindow: 131072, maxTokens: 8192,
      cost: { input: 0.2, output: 0.5, cacheRead: 0.05, cacheWrite: 0.5 },
    });
    console.log('deepseek-v4-flash:');
    console.log('  supportsPromptCacheKey:', v4flash.compat?.supportsPromptCacheKey);
    console.log('  api:', v4flash.api);
    "
  • Evidence after fix:
    $ node --import tsx -e "
    import { buildDeepSeekModelDefinition } from './extensions/deepseek/models.js';
    
    const v4flash = buildDeepSeekModelDefinition({
      id: 'deepseek-v4-flash', name: 'DeepSeek V4 Flash',
      input: ['text'], reasoning: true,
      contextWindow: 131072, maxTokens: 8192,
      cost: { input: 0.2, output: 0.5, cacheRead: 0.05, cacheWrite: 0.5 },
    });
    console.log('deepseek-v4-flash:');
    console.log('  supportsPromptCacheKey:', v4flash.compat?.supportsPromptCacheKey);
    
    const v4pro = buildDeepSeekModelDefinition({
      id: 'deepseek-v4-pro', name: 'DeepSeek V4 Pro',
      input: ['text'], reasoning: true,
      contextWindow: 131072, maxTokens: 8192,
      cost: { input: 0.5, output: 1.5, cacheRead: 0.1, cacheWrite: 1.5 },
      compat: { supportsTools: false },
    });
    console.log('deepseek-v4-pro:');
    console.log('  supportsPromptCacheKey:', v4pro.compat?.supportsPromptCacheKey);
    console.log('  supportsTools:', v4pro.compat?.supportsTools);
    "
    deepseek-v4-flash:
      supportsPromptCacheKey: true
    deepseek-v4-pro:
      supportsPromptCacheKey: true
      supportsTools: false
  • Observed result after fix: All DeepSeek models (v4-flash, v4-pro) now have compat.supportsPromptCacheKey: true in their model definition. The flag is set by buildDeepSeekModelDefinition() which is called when the plugin catalog is built at startup. Any existing compat fields on individual models (e.g. supportsTools) are preserved unchanged.
  • What was not tested: Live DeepSeek API call showing cached_tokens > 0 in the usage response (requires DeepSeek API key with active billing); the model-definition-level change is verified through direct import of the production module

🤖 Generated with Claude Code

DeepSeek uses prefix-based prompt caching, but the cache key was
never sent because compat.supportsPromptCacheKey was not set.
The boundary-aware cache system drops the key for providers that
don't explicitly opt in, causing DeepSeek to never report cache
hits and users to incur full token costs on every request.

Set supportsPromptCacheKey: true in buildDeepSeekModelDefinition
so all DeepSeek models send the prompt_cache_key to the API.

Fixes openclaw#91016

Co-Authored-By: Claude Fable 5 <[email protected]>
@openclaw-barnacle openclaw-barnacle Bot added extensions: deepseek size: XS proof: supplied External PR includes structured after-fix real behavior proof. labels Jun 13, 2026
@clawsweeper

clawsweeper Bot commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed June 12, 2026, 10:09 PM ET / 02:09 UTC.

Summary
Review failed before ClawSweeper could summarize the requested change.

PR surface: Source +8, Tests +31. Total +39 across 2 files.

Reproducibility: unclear. The review failed before ClawSweeper could establish a reproduction path.

Review metrics: none identified.

Stored data model
Persistent data-model change detected: persistent cache schema: extensions/deepseek/index.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge readiness
Overall: 🌊 off-meta tidepool
Proof: 🌊 off-meta tidepool
Patch quality: 🌊 off-meta tidepool
Result: rating does not apply to this item.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Risk before merge

  • [P1] No close action taken because the review did not complete.

Maintainer options:

  1. Decide the mitigation before merge
    Retry the Codex review after fixing the execution failure.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Next step before merge

  • [P1] Review did not complete, so no work-lane recommendation was made.
Review details

Best possible solution:

Retry the Codex review after fixing the execution failure.

Do we have a high-confidence way to reproduce the issue?

Unclear. The review failed before ClawSweeper could establish a reproduction path.

Is this the best way to solve the issue?

Unclear. Retry the review first so ClawSweeper can evaluate the actual issue and fix direction.

AGENTS.md: unclear because the file could not be read completely.

Codex review notes: model internal, reasoning high; reviewed against ded3a9305876.

Label changes

Label justifications:

  • rating: 🌊 off-meta tidepool: Overall readiness is 🌊 off-meta tidepool; proof is 🌊 off-meta tidepool and patch quality is 🌊 off-meta tidepool.
Evidence reviewed

PR surface:

Source +8, Tests +31. Total +39 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 8 0 +8
Tests 1 31 0 +31
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 39 0 +39

What I checked:

  • failure reason: codex execution failed.
  • codex failure detail: Codex review failed for this PR with exit 1.
  • codex stderr: \n@@ -524,4 +525,34 @@ describe("deepseek provider plugin", () => {\n },\n ]);\n });\n+\n+ it("enables prompt cache key for DeepSeek models (⚠️ 升级 2026.6.1 后 DeepSeek Prompt Cache 完全失效,一小时烧掉约 $6 #91016)", () => {\n+ const def = buildDeepSeekModelDefinition({\n+ id: "deepseek-v4-flash",\n+ name: "DeepSeek V4 Flash",\n+ input: ["text"],\n+ reasoning: true,\n+ contextWindow: 131072,\n+ maxTokens: 8192,\n+ cost: { input: 0.2, output: 0.5, cacheRead: 0.05, cacheWrite: 0.5 },\n+ });\n+\n+ expect(def.compat?.supportsPromptCacheKey).toBe(true);\n+ });\n+\n+ it("preserves existing compat fields when adding prompt cache key", () => {\n+ const def = buildDeepSeekModelDefinition({\n+ id: "deepseek-v4-pro",\n+ name: "DeepSeek V4 Pro",\n+ input: ["text"],\n+ reasoning: true,\n+ contextWindow: 131072,\n+ maxTokens: 8192,\n+ cost: { input: 0.5, output: 1.5, cacheRead: 0.1, cacheWrite: 1.5 },\n+ compat: { supportsTools: false },\n+ });\n+\n+ expect(def.compat?.supportsPromptCacheKey).toBe(true);\n+ expect(def.compat?.supportsTools).toBe(false);\n+ });\n });".
  • codex stdout: No stdout captured.

Likely related people:

  • unknown: Codex failed before it could trace repository history. (role: review did not complete; confidence: low)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@clawsweeper clawsweeper Bot added the rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. label Jun 13, 2026
@fsdwen

fsdwen commented Jun 13, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@fsdwen

fsdwen commented Jun 13, 2026

Copy link
Copy Markdown
Contributor Author

@vincentkoc would you mind reviewing this? This enables DeepSeek prompt cache key support — 2 files, +35 lines, CI all green. Fixes #91016 (P1, users losing ~/hr on cache misses). Thanks!

Copy link
Copy Markdown
Contributor

Closing this because supportsPromptCacheKey is not the DeepSeek cache contract and does not fix #91016.

DeepSeek’s official docs say context caching is automatic and requires no request changes. The current Chat Completions schema reports cache reuse through top-level usage.prompt_cache_hit_tokens / prompt_cache_miss_tokens; it does not document OpenAI’s prompt_cache_key.

Live proof against deepseek-v4-flash on June 13, 2026:

  • First identical-prefix request, without prompt_cache_key: 18,010 prompt tokens, 0 cache hits.
  • Second request after 5 seconds, still without the field: 17,920 cache-hit tokens, 90 misses.
  • Third request with prompt_cache_key: exactly the same 17,920 hits / 90 misses.

So the field is silently ignored and adds no cache benefit. Current OpenClaw’s openai-completions parser already maps DeepSeek’s top-level prompt_cache_hit_tokens into usage.cacheRead in src/llm/providers/openai-completions.ts. The canonical issue remains open for a controlled OpenClaw prefix-stability investigation; adding an unsupported OpenAI cache-routing hint is not the right fix. Thanks for preparing the focused patch and tests.

@fsdwen

fsdwen commented Jun 13, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the thorough review and live proof, @steipete — really appreciate you taking the time to test this against the actual DeepSeek API. I see now that DeepSeek's caching is automatic and doesn't use OpenAI's prompt_cache_key contract at all. The live data (17,920 cache hits with or without the field) makes it clear this was the wrong approach. Lesson learned: verify the provider's actual caching contract before assuming OpenAI compatibility. Thanks again for the guidance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: deepseek proof: supplied External PR includes structured after-fix real behavior proof. rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

⚠️ 升级 2026.6.1 后 DeepSeek Prompt Cache 完全失效,一小时烧掉约 $6

2 participants