[Bug] Compaction request misses provider prefix cache entirely — summarizer doesn't inherit reasoningEffort / adds maxTokens #1944
Replies: 5 comments 1 reply
|
Confirmed at source level and implemented as a cherry-pick-ready branch. Source audit (master 47f9438)
Patch: fix/compaction-inherit-header-confighttps://github.com/zoahdev/deepseek-harness/tree/fix/compaction-inherit-header-config
Verification
Your session numbers tell the story: 122,558 input tokens / 0 cache on the old path vs 402 new input tokens + 220,928 Thanks for the reproducible writeup - this one saves real money on every long session. Happy to open the PR once contributions are enabled. |
|
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. |
|
Thanks - and nice catch on your side. Your session numbers (122,558 input tokens / 0 cache -> 402 new input tokens + 220,928 |
|
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. |
|
Reproduction note added - reviewers can now verify without a long session: https://github.com/zoahdev/dsh-docs/blob/main/docs/specs/repro-compaction-cache-miss.md Key contents:
Also folded into the branch description on the fix branch. Thanks again for the session numbers - they turned a code-level fix into a cost story reviewers can check in one step. |
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