-
Notifications
You must be signed in to change notification settings - Fork 294
[Bug] Chat context footer accumulates overlapping request totals and cannot correct inflated usage #1433
Copy link
Copy link
Open
Labels
P2Normal priority bug or improvement with limited blast radius.Normal priority bug or improvement with limited blast radius.clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.ClawSweeper found a clear likely implementation shape for this issue.clawsweeper:queueable-fixClawSweeper marked this issue as an existing queue_fix_pr work candidate.ClawSweeper marked this issue as an existing queue_fix_pr work candidate.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.ClawSweeper found a high-confidence source-level issue reproduction.impact:ux-frictionUser-facing flow adds avoidable confusion or support burden without fully blocking progress.User-facing flow adds avoidable confusion or support burden without fully blocking progress.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.Very strong issue quality with high-confidence source-level or clear reproduction.no-staleExempts this issue from stale automation.Exempts this issue from stale automation.
Description
Activity
Metadata
Metadata
Assignees
Labels
P2Normal priority bug or improvement with limited blast radius.Normal priority bug or improvement with limited blast radius.clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.ClawSweeper found a clear likely implementation shape for this issue.clawsweeper:queueable-fixClawSweeper marked this issue as an existing queue_fix_pr work candidate.ClawSweeper marked this issue as an existing queue_fix_pr work candidate.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.ClawSweeper found a high-confidence source-level issue reproduction.impact:ux-frictionUser-facing flow adds avoidable confusion or support burden without fully blocking progress.User-facing flow adds avoidable confusion or support burden without fully blocking progress.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.Very strong issue quality with high-confidence source-level or clear reproduction.no-staleExempts this issue from stale automation.Exempts this issue from stale automation.
Type
Fields
Priority
None yet
Projects
- StatusShow more project fieldsBacklog
Summary
The Windows Companion chat footer adds per-request token totals across assistant messages and displays the result as current context occupancy. A conversation with about 218K tokens can therefore show more than 1M / 100%. A subsequent authoritative session snapshot cannot correct the inflated value because the client takes Math.Max with its existing value.
Affected build
3c43751b2bace876de3febe478ebabeca172e3ac.3a9d69d), WSL2.opencode-go/glm-5.3-flash, configured context window 1,000,000.Reproduction
Use a thread with ContextTokens = 1,000,000 and successive assistant replies whose
usage.totalTokensincludes the request's existing prompt/history. In a deterministic fixture, create a separate assistant entry for each reply and feed these per-request totals:The last value is presented against the 1M window with a clamped 100% percentage. These are six replies, not necessarily six user turns; tool workflows can produce multiple assistant messages.
Then deliver an authoritative session TotalTokens = 215950. The existing client retains 1198185. Deliver a lower post-compaction total such as 50000: it still retains 1198185.
Expected behavior
The context indicator should show the current context snapshot, not the cumulative number of tokens processed over multiple requests. Reused/cached history must not be counted as newly added context on each reply. A current, matching authoritative snapshot must be able to correct an inflated value or reflect compaction.
Cumulative token consumption is useful, but should be a separately named metric.
Code path
All links are pinned to the installed build:
usage.totalTokensinto ResponseTokens.Math.Max((previousUsage ?? 0) + currentUsage.Value, existing?.ResponseTokens ?? 0).Math.Max(usedTokens, existing?.ResponseTokens ?? 0), preventing downward correction.Validation performed
This was not only a spreadsheet simulation: a local isolated PowerShell/.NET reflection harness invoked the two private methods in the original installed DLL, using synthetic in-memory timelines/metadata and the numeric inputs above. It reproduced accumulation, failure to correct the inflated snapshot, and failure to reflect a lower post-compaction snapshot.
A narrowly scoped local IL hotfix changed the two methods to use the latest usage/snapshot rather than add previous usage or retain Math.Max, and discarded stale percentages so the formatter recomputes them. The patched DLL passed 12 checks: six successive replies, duplicate update, authoritative downward correction, post-compaction decrease, stale-percentage refresh, a new response after compaction, and zero-usage handling. After installing locally, the user reported that the displayed result looked correct.
This is targeted method-level validation plus a local startup/reconnect check, not a full upstream build/test-suite run. No patched binaries are attached.
Suggested fix / acceptance criteria
There were also intermittent UI hangs/layout exceptions and provider timeouts in the environment, but their causal relationship to this counter defect has not been established. This issue reports only the reproducible counter defect.
No credentials, chat text, personal configuration, or session databases are included.