GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — [URGENT] Go: frank/DeepSeek-V4.1-Flash upstream repeatedly drops prompt cache — ~50% of billed usage is full-context re-reads · Issue #50258 · anomalyco/opencode Closed as not planned Closed as not planned Copy link DescriptionSummaryOn OpenCode Go, the Evidence (console request-log export, 2026-09-20)447 requests, total billed cost $1.76:
Key pattern on
Still happening after
|
| model | cold misses | note |
|---|---|---|
deepseek-v4.1-flash |
1/6 | stable once warm |
deepseek-v4-flash |
1/6 | stable once warm |
glm-5.3-flash |
6/6 | no caching at all |
minimax-m3 |
0/6 | flaps between 128 and 3072 cached |
Consistent with your frank finding that this is upstream-specific rather than model-wide.
5. Client note, in case it affects affinity routing
This client currently sends no per-conversation session id on the adapter path used here (DeepSeek Harness is listed under "Known Problematic Clients" on the Go docs). It is worked around by configuring a fixed x-opencode-session value for all conversations, so every conversation shares one routing key. Flagging it since it is the only session signal the gateway receives from us — though given (1), it cannot be the whole story.
Happy to share the repro script or the raw session records.
I looked into the caching code and here is what I found:
packages/opencode/src/provider/transform.ts:1310-1323)The promptCacheKey is only set for specific SDK packages:
@ai-sdk/deepinfra / @ai-sdk/cerebras → prompt_cache_key (snake_case)@ai-sdk/openai / @ai-sdk/azure / @ai-sdk/xai / @ai-sdk/mistral / venice-ai-sdk-provider → promptCacheKey (camelCase)DeepSeek uses @ai-sdk/openai-compatible, which is NOT in the list. So the V1 path does not send any cache key to DeepSeek by default.
packages/core/src/session/runner/llm.ts:204-214)const promptCacheKey = /^ses_[0-9a-f]{64}$/.test(session.id) ? session.id.slice(4) : session.id providerOptions: { openai: { promptCacheKey } },
V2 sets promptCacheKey under the openai provider options namespace, which may not be forwarded to DeepSeek-compatible endpoints.
DeepSeek prompt cache is content-prefix-based, not key-based:
So prompt_cache_key is actually irrelevant for DeepSeek — the cache is content-addressed.
frank Node ProblemComparing the three upstreams from the reporter data:
| Upstream | Cache Hit Rate | Full Re-reads |
|---|---|---|
frank/DeepSeek-V4.1-Flash |
94.2% | 14 |
deepseek/deepseek-v4.1-flash |
97.2% | 1 |
deepseek-flash |
95.9% | 2 (idle TTL) |
The frank node has significantly worse cache performance. This strongly suggests frank is a replica pool without shared cache, and requests are being routed to different replicas without cache affinity.
The mid-session cache drops (seconds/minutes after a normal hit, not idle TTL) are consistent with a load balancer rotating requests across replicas that each maintain independent caches.
This is a gateway routing / infrastructure issue, not a client-side code bug. The fix needs to happen at the frank upstream level:
The client-side prompt_cache_key cannot solve this because DeepSeek cache is content-addressed, not key-addressed.
Re-checked the current v2 code and two parts of my analysis above need correcting.
1. The V2 request shape has moved and is not what I described.
It is no longer providerOptions.openai.promptCacheKey in runner/llm.ts. On v2 today:
packages/core/src/session/model-request.ts:237-252 sets a first-class promptCacheKey from affinity = session.parentID ?? session.fork?.sessionID ?? session.id, and always sends header affinity on every request: x-session-affinity, X-Session-Id, x-parent-session-id, x-opencode-session.packages/ai/src/protocols/openai-chat.ts:763-779 only adds the body field prompt_cache_key when model.compatibility.supportsPromptCacheKey === true (default off). The comment there notes header-based affinity is unaffected by that gate.packages/core/src/plugin/provider/prompt-cache-key.ts flips that flag on for a whitelist of providers. The OpenCode Go route is not in it, so its body key stays off unless a user opts in.So the client already sends session-header affinity unconditionally. Enabling supportsPromptCacheKey (as the report did at 17:18) adds the body key on top — and the losses continued. That is consistent with the gateway not using either signal for sticky routing, rather than the client omitting a key.
2. The V1 note still holds. The providerID.startsWith("opencode") branch in transform.ts is nested inside the api.id.includes("gpt-5") block, so DeepSeek never reaches it, and the package list I quoted is accurate.
On the question above — detect the drop and fail or back off instead of paying for the re-read:
There is no client-side action that avoids the charge.
cacheRead in the usage after the fact.The conclusion is unchanged: this has to be fixed upstream (cache affinity across replicas, or a shared cache layer), not in the client.
this need to be fixed with priority , just resumed my GO after 2 month , this issue is crazy
using legacy api key always route to direct deepseek endpoint , this is the workaround i found
36-hour measurement from my own account. All 8 rows are the same session, prefix growing monotonically (586k → 595k tokens), model opencode-go/deepseek-v4.1-flash. cached from local session_message usage, billed from the console:
| start (local) | gap since previous request | cached | hit | billed |
|---|---|---|---|---|
| 09-25 17:42:03 | resumed after ~4 days idle (cold start, fine) | 384 | 0.1% | $0.0886 |
| 09-25 17:42:46 | 43 s | 256 | 0.0% | $0.0889 |
| 09-25 17:43:04 | 18 s | 589,312 | 100% | $0.0028 |
| 09-25 17:43:20 | 16 s | 586,752 | 99.2% | $0.0034 |
| 09-26 01:06:01 | 7.4 h idle (cold start, fine) | 384 | 0.1% | $0.0892 |
| 09-26 01:06:36 | 35 s | 593,024 | 99.9% | $0.0021 |
| 09-26 01:06:51 | 15 s | 593,536 | 99.9% | $0.0023 |
| 09-26 01:38:23 | 31.5 min | 256 | 0.0% | $0.0899 |
Two of the four misses are explicable idle cold starts. The other two are the reported pathology: a full ~590k re-read 43 seconds and 31.5 minutes after requests that had just returned ~100% hits on the same session, with a strictly growing prefix. Billing matches the full input rate exactly (590k x $0.15/M ~= $0.0885); the catalog still advertises cache read at $0.003/M, unchanged.
Token hit rate on my traffic: 99.07% on 09-21 (274 requests) -> 49.94% on 09-25 -> 49.97% on 09-26.
Why this matters beyond one account: the Go plan advertises $10/month -> ~$60 of DeepSeek Flash usage (~6x). That arithmetic only works with high cache-hit rates — OpenCode's own request estimate assumes ~68k cache-read tokens vs ~790 fresh input per request. When cache-read collapses to ~256 on turn starts, each 590k-context turn costs ~$0.089 instead of ~$0.002 (~45x), so the $60 credit buys roughly an order of magnitude less. In the window above, $0.37 was billed and ~$0.35 of that was pure cache-failure waste.
This lines up with the two findings already in this thread: the byte-identical raw-HTTP flap (upstream replica/eviction behavior, not client-side), and the source analysis (client sends session affinity headers unconditionally; the gateway does not use them for sticky routing). Nothing client-side can recover credit that has already been billed as full-context input. Fix has to be gateway-side cache affinity (or a shared cache layer).
Thanks for the thorough analysis. This was most likely fixed since it was reported: Go routing and caching for DeepSeek have changed a lot. Closing because there's been no activity for a while. If you run into full-context re-reads again, please open a new issue with the time, session ID and request IDs from the console logs. If it used up your allowance, email [email protected] with your workspace ID.