Skip to content

fix(server): stop recounting resumed Claude sessions as other usage - #121

Merged
nullStack65 merged 5 commits into
release/native-0.1.10from
fix/clo-920-otherusage-recount
Nov 20, 2026
Merged

nullStack65 merged 5 commits into
release/native-0.1.10from
fix/clo-920-otherusage-recount

Conversation

@nullStack65

@nullStack65 nullStack65 commented Nov 20, 2026 •

Copy link
Copy Markdown
Owner

A resumed Claude CLI process can restore the session's cumulative modelUsage. normalizeClaudeTurnTokenUsage treated that growth as this turn's otherUsage, so the first result after resume recounted the thread's earlier input. On the token-burn sample that was about 85% of laptop otherUsage.

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 records otherUsage only when the counter is provably fresh. A restored or ambiguous counter leaves otherUsage off, which ProviderUsageAnalytics already 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, not main. apps/server/src/provider/ClaudeTurnTokenUsage.ts is not on main, and the recent fork PRs land on this release branch.

On the parent commit, the new claude_idle_resume_restored_ledger fixture fails with turn 2 otherUsage { inputTokens: 11795, outputTokens: 7 } (turn 1 recounted). With this branch it is omitted. The ledger field also grows the advertised MCP tool schemas; agentContextBudget.json records that measured size (mcpToolListJsonBytes 53783 -> 55240). Paid model evals were not run.

Deploy: fleet

Model: grok/grok-4.7
Task: coding

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
@nullStack65

Copy link
Copy Markdown
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>
@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

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>
@nullStack65

Copy link
Copy Markdown
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.

@nullStack65
nullStack65 merged commit 70e91f5 into release/native-0.1.10 Nov 20, 2026
3 checks passed
@nullStack65
nullStack65 deleted the fix/clo-920-otherusage-recount branch November 20, 2026 20:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants