You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
V2: compaction usage becomes phantom system overhead and negative context budgets #421
Dual-runtime fork drexb-ops/opencode-acp@1fe36e0, official OpenCode v2.0.3.
Reproduction
Normalize a completed local compaction record with a short summary/recent and token usage { input: 653137, output: 955, reasoning: 723, cache: { read: 0, write: 0 } }, followed by user text continue. Call cacheSystemPromptTokens with a fresh state.
Actual system estimate: 653136. For a 400000 context limit and 32768 output reserve the subsequent hard-guard budget becomes -285904. A replay of settled real context produced 653133. Live logs also show negative budgets while recent provider usage is far smaller.
Root cause
lib/v2/projection/normalize.ts:137-141 represents compaction as an assistant summary.
lib/v2/projection/shared.ts:204-238 copies compaction-request token usage onto that normalized assistant.
lib/ui/utils.ts:56-100 treats the first assistant input usage minus first user text as system overhead, without excluding compaction summaries or anchoring usage to the current request. It then permanently retains any positive estimate.
lib/v2/context.ts receives the actual outgoing event.system but does not use it to supply measured system overhead to the shared transform.
lib/messages/transform.ts:218-227 subtracts the estimate from the model limit. Other usage/fallback paths inherit the inflated system count.
Impact / fix direction
Misleading 600K+ system usage, negative budgets, false over-budget diagnostics and potentially excessive fallback pruning/nudges after compaction/reload. A previous compaction model request's input is not the current system prompt.
Use current V2 system parts/tool-schema overhead and a coherent wire estimate; explicitly exclude compaction-request usage from conversational calibration. Invalidate or recalibrate on native compaction/model changes. Retain V1 compatibility.
Acceptance: first request after compaction and after reload, before a post-compaction assistant has usage; verify current-wire accounting, nonnegative usable budget, and no unnecessary tool clearing. Distinguish heuristic estimates from actual provider usage in status output.
Activity
ranxianglei commentedon Sep 17, 2026
继续
ranxianglei commentedon Sep 17, 2026
收到,继续处理中。当前进展(清库后补做):
2026-09-17_v2-compaction-phantom-system分支(fork master1fe36e0)上核实根因链与 OP 描述一致:normalize.ts:137-141把 compaction 记录映射为 assistant summary →shared.ts:204-238原样复制 compaction 请求的 usage(input=653137)→ui/utils.ts:56-100的cacheSystemPromptTokens不排除 summary assistant,把 653136 永久缓存为 system 估计值 →transform.ts:218-227硬护栏预算变负(-285904)。fix(v2): pass lastCompaction through estimateContextComposition live …
ranxianglei commentedon Sep 19, 2026
opencodeV2 use https://github.com/ranxianglei/billion-context