Repository navigation
[Bug] Compaction request misses provider prefix cache entirely — summarizer doesn't inherit reasoningEffort / adds maxTokens #1944
Replies: 13 comments 2 replies
|
Thanks @zoahdev for the source-level confirmation and the fix branch — the 124/124 tests with the two new coverage cases make it solid. Good to see the analysis independently validated. Looking forward to the PR once contributions are enabled. |
|
Sure, go ahead and add the reproduction note — happy to help reviewers verify without a long session. Thanks for folding the session numbers into the branch description and docs patch list. |
|
Cross-linking a case where inheriting the header wholesale would cut the wrong way: #3565
That is not an argument against this fix — faithful inheritance is clearly right when the header is current, and cherry-picking two fields out of it is clearly wrong. It is an argument for pairing it with a freshness condition, so that a header which is stale relative to the agent's current options isn't inherited more completely than it is today. |
|
补充两条复核结论,均基于 一、压缩调用实际发出的推理档位不是「无档位」,而是模型条目的默认档位
因此本串所说「不继承 二、常规请求的
|
|
Third-party reproduction + a config-level workaround (no code change) — and 0.1.7-rc.2 still carries the bug Reproduced this on a different provider shape than the OP: a custom Evidence (one audited session, 96 requests, 13 auto-compactions in a single long turn):
Both split parameters confirmed against the shipped code (
Config-level workaround (no code change) — derived from the shipped code paths, not yet A/B-tested:
Both land through existing config surfaces (the profile patch layer here); no patched build needed. I'll report back with before/after compaction usage once verified, using the same metric as the OP. One amplifier worth noting for anyone measuring this: Cross-referencing #7794 and #3002 — same root cause observed from a third environment. 中文摘要:在另一类 provider(openai-responses 第三方网关、256K/128K 模型、会话档位 high)上复现同一缺陷;0.1.7-rc.2(npm next 最新)仍未修复。13 次自动压缩中,摘要调用 9 次 |
|
Independent reproduction on a different provider shape (DeepSeek official route), a 13-day local corpus, and a status check: this is still unfixed on Environment: DSH Desktop 2.0.17 shipping 1. One fold, measured against the turn it replacedSame session, minutes apart:
The summarizer re-billed ~132K tokens at the fresh-input rate for a request the module's own comment says is built "so the provider's warm prefix cache is reused". Output 3,749 tokens, wall 17.0 s. 2. Corpus: 51 folds across 216 archived sessions, 2026-09-28 → 2026-10-11
3. Both halves are live here, and the second one needs its own ruleRouted header from {"config":{"provider":"deepseek-account","model":"deepseek-flash",
"reasoningEffort":"max","maxTokens":256000},
"adapterDefaults":{"maxTokens":true}}The summarizer envelope built by
One note for whoever writes the fix: the "inherit the header, drop the fields 4.
|
|
Result of the A/B I promised above: aligning the summarization envelope fixes it — same session, same command, 11.8% → 99.7% cache hit. Short version: with the routed envelope mirrored into the compaction request, the fold's fresh-input bill drops from 132,528 tokens to 560, and the replayed conversation prefix hits in full. Setup. A ~40-line client-side plugin on the A/B — same session, same route (
The after-fold's fresh input is 560 tokens, and the instruction appended as the final user message is 2,336 chars (≈560 tokens at ~4.2 chars/token). So once the envelope agrees, the entire replayed prefix is cache-served and the only full-rate input left is the directive itself — exactly what the doc comment on What the before-state says about the cache key. Over the 51-fold corpus the cached portion was a constant ~17.3–18K regardless of fold size — a fixed head, never the replayed prefix. That only makes sense if the cache is partitioned by the request envelope: the mismatched envelope ( Confounds, stated for completeness.
Auditing note for whoever picks this up. Still unfixed on |
|
Follow-up: the archived corpus already isolates the field — it is I re-scanned the 52 LLM folds in my local archives that have a
All 7 fully-hitting folds still sent a mismatched Two independent confirmations from the same corpus:
Net effect for the fix: |
|
Heads-up for anyone reaching for an off-the-shelf fix: the package whose name promises this does not fix it — it reproduces the same envelope.
const options = {
provider, model, messages,
toolHistory: agent.session.toolHistory(),
...(input.tools === undefined ? {} : { tools: [...input.tools] }),
maxTokens: this.config.summaryMaxTokens, // 16384
sessionId: agent.session.id,
purpose: 'compaction' as const,
...(signal === undefined ? {} : { signal }),
}
So installing it changes the checkpoint structure and carries the miss along with it, with For completeness, the rest of the npm landscape in this seam, checked 2026-10-11: |
|
Another reproduction, on a local server whose chat template renders the effort at the very start of the prompt, plus a server-side workaround for people on that server. Setup. DSH Desktop 0.2.0-rc.2 (Windows), provider The two request bodies, captured on the server (an ordinary turn and the
On a local GPU this is time, not money: in the server's log over several days there are 135 compaction requests, median prompt 88,647 tokens, none of them reusing anything - 9,721 s of prompt reading, and the full read also displaced the conversation's cached state, so the next turn read the compacted conversation from the start too. Workaround on the server side (for Strata users; no DSH change):
This only hides the mismatch on servers that can move the effort; the request still goes out with another effort than the session's, so +1 for carrying the routed A related cost on the same setup, in case it helps whoever tunes the defaults: with |
|
针对该问题,我已在一个专门的 Q&A 讨论帖中附上了经过测试的补丁:#10573 It covers the effort parity discussed here (same route only, with the effective effort recorded on compaction/summary) and a second, independent cache break that parity alone leaves in place: the tool-result pruner rewrites the region the summary call replays. On master @ 687f282 the new specs fail; with the patch all 236 compaction tests pass. |
|
Independent reproduction of exactly this failure on Setup. Hand-declared GPT-class reasoning model on an What the gateway log shows. Every 17 such pairs in one 18-minute turn; 261 of these 400s on that gateway in a single day, all from compaction. The path is the one described above: Consequence beyond the failed compaction. Because the summary never commits, the session grows past Fix we are applying locally (same shape as the patch in this thread and #1944): mirror the routed request header's |
|
Still present in Suggested fix: take the effort from Workarounds:
|
Uh oh!
There was an error while loading. Please reload this page.
[Bug Report] Compaction request misses the provider prefix cache entirely — summarizer doesn't inherit reasoningEffort / adds maxTokens
Category: Ideas (bug report)
Summary
When
@deepseek-ai/dsh-compaction-basictriggers a compaction (autocompactIfNeededor manual/compact), the summarizer LLM call is sent with different request parameters than normal agent turns. Under providers with prefix caching (e.g. theopencode-gogateway fordeepseek-v4-flash), that cache-key divergence makes the compaction request itself miss the cache completely, re-billing the entire context (~100k+ tokens) at full price.Evidence (real session data,
opencode-go/deepseek-v4-flash/reasoningEffort: high)Before fix — compaction request usage:
After locally patching
summarizeWithLlmto inheritreasoningEffortand drop the extramaxTokens— next compaction:The shadowed range was ~158k tokens; a full miss means ~122k tokens re-priced on every compaction. In a long-running session with frequent auto-compaction this is a substantial recurring cost.
Root cause
dsh-compaction-basic/lib/index.js,summarizeWithLlm(~lines 267-316) builds the summarizer options as:It picks
provider/modelfrom the last routed request header, but does not inherit the rest of the header config — notablyreasoningEffort(we use"high") — and it addsmaxTokens: 8192that normal turns don't send (normal requests indsh-agent-loopinheritheader.configwholesale, no explicitmaxTokens).The compaction call is intentionally a genuine prefix of the last routed request (per the design comments, so the provider KV cache is reused) — but the differing
reasoning_effort/max_tokensparams split the provider-side cache key, defeating that intent.Proposed fix
In
summarizeWithLlm, inherit request parameters the same waydsh-agent-loop'sbuildRequestdoes: takeagent.session.requestHeader()→header.config(provider/model/reasoningEffort/…), skip fields whereheader.adapterDefaults.reasoningEffort === true, and drop the explicitmaxTokensoverride (let the adapter default apply, same as normal turns).i.e. re-use the header config wholesale instead of cherry-picking
provider/modelonly.Impact / context
reasoning_effort/max_tokens(DeepSeek official KV cache, OpenAI-style gateways, etc.).Happy to open a PR once contributions are enabled, or provide the patch diff.
All reactions