Repository navigation
fix(server): stop recounting resumed Claude sessions as other usage - #121
Merged
nullStack65 merged 5 commits intoNov 20, 2026
Merged
Conversation
WIP. A resumed Claude CLI process can restore the session's cumulative modelUsage, so the first result's ledger growth recounted all earlier input as otherUsage. The adapter now keeps the last ledger per native thread in provider thread nativeMetadata, and the first result of a resumed process records otherUsage only when the counter is provably fresh; otherwise otherUsage is unknown. Model: claude-opus-5-5 Task: coding Agent: T3 Claude Code (CLO-920 lane) Lane: magpie Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The resumed-session ledger is part of provider-thread metadata, so the advertised MCP tool schemas grow by that field. Record the measured size, and wrap the new usage assertion so formatting passes. Model: grok/grok-4.7 Task: coding Agent: T3 Codex (CLO-920 lane) Lane: magpie
A resumed counter that drops a model, or grows by less than this result, is not proof it restarted at zero. Using the whole current ledger still recounted the saved history as otherUsage. That charge is now omitted unless the current ledger fits inside this result. Model: grok/grok-4.7 Task: coding Agent: T3 Codex (CLO-920 lane) Lane: magpie
Owner
Author
{"reviewed_head":"e3c194b9755249db10474963596ef598150e7a4b","reviewer":"grok-4.7-build (claudeAgent, read-only)","findings":[{"id":"omitted-model-recounts-from-zero","severity":"important","summary":"On a resumed session, the first result's ledger replaces the saved baseline even when it omits a model the saved ledger had. claudeLedgerDelta then counts that model from zero when it reappears, so its earlier tokens are reported again as other usage. Example: saved sonnet 100000/10 plus haiku 20000/5, first resumed result sonnet-only 100100/12, next result adds haiku 20050/7; the haiku's prior ~20000 input tokens are counted again.","outcome":"open"}]} |
A resumed Claude process's first result can omit a model the saved ledger still has. Storing that partial ledger as the baseline made the model's return count its earlier tokens again as other usage. The baseline now keeps the omitted model's last total. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
The next result of the same resumed process diffs against the turn context's ledger, not the persisted one, so keeping the omitted model only in the persisted baseline still recounted it. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Owner
Author
{"reviewed_head":"7dca9e49bdba1e25610f966364d390a3cbc850f0","reviewer":"grok-4.7-build (claudeAgent, read-only)","findings":[]}The first re-check of 1eb34ce found omitted-model-recounts-from-zero still open: the omitted model's total was kept only in the persisted baseline, while the next result of the same resumed process diffs against the turn context's ledger. 7dca9e4 keeps it in both. The same reviewer re-read that commit and returned clean: the next delta now subtracts the omitted model, and a real reset still fails the nondecreasing check and clears the baseline. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A resumed Claude CLI process can restore the session's cumulative
modelUsage.normalizeClaudeTurnTokenUsagetreated that growth as this turn'sotherUsage, so the first result after resume recounted the thread's earlier input. On the token-burn sample that was about 85% of laptopotherUsage.The adapter now keeps the last per-model ledger on the provider thread (
nativeMetadata.claudeModelLedger), including across idle release and restart. The first result of a resumed process recordsotherUsageonly when the counter is provably fresh. A restored or ambiguous counter leavesotherUsageoff, whichProviderUsageAnalyticsalready treats as unknown. A fork does not copy the ledger, so its first resumed result stays unknown instead of recounting.This targets
release/native-0.1.10, notmain.apps/server/src/provider/ClaudeTurnTokenUsage.tsis not onmain, and the recent fork PRs land on this release branch.On the parent commit, the new
claude_idle_resume_restored_ledgerfixture fails with turn 2otherUsage{ inputTokens: 11795, outputTokens: 7 }(turn 1 recounted). With this branch it is omitted. The ledger field also grows the advertised MCP tool schemas;agentContextBudget.jsonrecords that measured size (mcpToolListJsonBytes53783 -> 55240). Paid model evals were not run.Deploy: fleet
Model: grok/grok-4.7
Task: coding