Skip to content

fix: stop re-counting Claude usage on resume - #1175

Merged
sox8502 merged 4 commits into
mainfrom
daniel/orx-813-claude-token-usage-re-counts-the-whole-chat
Nov 22, 2026
Merged

sox8502 merged 4 commits into
mainfrom
daniel/orx-813-claude-token-usage-re-counts-the-whole-chat

Conversation

@sox8502

@sox8502 sox8502 commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Fixes ORX-813.

Since 0.2.29, the first turn after orx starts a new Claude process for an existing chat reports the chat's entire history as that turn's tokens. Daily Claude Code usage in telemetry roughly doubled on Nov 21 (12.5B → 26.9B) while installs fell; Codex and the other harnesses did not move.

Why: Claude's result.modelUsage is a running total for the session, and --resume restores it (checked with Claude Code 2.1.330: a resumed process reports the old totals plus the new turn, exact to the token). #1031 made the first attempt of each new Claude process start from a zero baseline, on the assumption that the totals restart with the process. Processes restart routinely (15-minute idle reaper, orx restart or update, config change, retry), so long chats got re-counted again and again.

Fix:

  • Every attempt subtracts the totals saved for the chat's Claude session again, as in 0.2.28. The per-process zero baseline (usage_started) is gone.
  • When the reported totals drop below the saved ones (a Claude that didn't restore them), the attempt counts from zero for the rest of its snapshots instead of being dropped. 0.2.28 dropped these turns, which is what feat: experiment progress monitoring + visualization #1031 was working around.

Load-bearing choice: a total below the saved one is read as "started from zero". A fresh process whose first turn alone exceeds the session's old total would be under-counted by that old total; current Claude versions restore totals, so this only affects older ones.

Chat reference in usage reports: each chat_model_usage report now carries chatRef, a hash of the install ID and the chat ID shaped as a UUID. It's the same for every turn of a chat and doesn't reveal the chat ID, so a chat whose reported usage jumps by its whole history can be found with one query. This is new data leaving the machine, recorded in arc/storage.md.

⚠️ Merge order: openresearch.sh rejects unknown usage properties, so alphaXiv/openresearch.sh#719 (accepting chatRef) must deploy before this merges. Until then every usage report from this build would be rejected. The release workflow's contract gate (production_contract_is_accepted) now sends chatRef and would catch it.

Telemetry already sent by 0.2.29 stays inflated; that's handled on the openresearch.sh side.

Test plan

  • a_resumed_claude_counts_only_its_new_usage: restored totals count only the new turn; totals that restart from zero count in full, including a later snapshot past the old totals (Greptile finding)
  • Updated the reset case in cumulative_baselines_exclude_resume_history_and_replace_repeated_snapshots
  • a_chat_ref_is_stable_per_chat_and_hides_the_chat_id
  • cargo fmt --all --check, cargo clippy --all-targets -- -D warnings, cargo build --locked, cargo test --locked. Four orx-host wrapper tests (tests/wrapper.rs) fail locally, and fail the same way on a clean origin/main
  • End to end in the dev app, Claude Haiku 5.5 on Claude Code 2.1.330: two turns recorded 62,734 and 63,088 input tokens; after node dev.ts restart, the resumed process reported a running total of 191,128 and the turn recorded 65,306. 0.2.29 would have recorded the full 191,128
  • openresearch.sh#719 deployed before merge
  • A real usage report with chatRef accepted by production
  • Same check with an older Claude Code that doesn't restore totals on resume

Claude restores its running modelUsage totals when a session is resumed,
so a new process's first turn must subtract the session's saved totals,
not zero. A total below the saved one now counts from zero instead of
being dropped, for Claude versions that don't restore.

Fixes ORX-813
@sox8502

sox8502 commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

@greptileai review

@greptile-apps

greptile-apps Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The reviewed changes appear safe to merge once the documented backend deployment is complete.

Summary

The PR stops resumed Claude processes from counting earlier usage again and adds a stable, hashed chatRef to usage reports.

  • Claude turns count only usage added since their saved session totals.
  • Usage reports include a stable reference for each chat’s turns.

Reviews (4) · Last reviewed commit: "fix: send no chat reference with telemet..." · Reviewed by Greptile

Comment thread src/store/telemetry.rs Resolved
A reset was only applied to the result event that saw it, so a later
snapshot in the same attempt reloaded the old totals and under-counted.
@sox8502

sox8502 commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

@greptileai review

A stable hash of the install and chat ids lets reports from one chat be
told apart, so a turn that re-counts its chat's history shows up in one
query. openresearch.sh must accept chatRef before this ships.

Refs ORX-813
@sox8502

sox8502 commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

@greptileai review

Comment thread src/store/telemetry.rs Resolved
chat_ref ran before the suppressed check and minted an install id on an
opted-out or source build that had none.
@sox8502

sox8502 commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

@greptileai review

@sox8502 sox8502 mentioned this pull request Nov 22, 2026
3 of 6 tasks
@sox8502
sox8502 merged commit e66745c into main Nov 22, 2026
26 checks passed
@sox8502
sox8502 deleted the daniel/orx-813-claude-token-usage-re-counts-the-whole-chat branch November 22, 2026 21:01
small-angel added a commit that referenced this pull request Nov 23, 2026
main stopped persisting whether a Claude process had counted usage (#1175), so the keeper record drops its usage_started field. Forgetting a remote host now reports a saved session it could not remove.

Fixes ORX-834

Assisted-by: claude-opus-5.5
small-angel added a commit that referenced this pull request Nov 23, 2026
main stopped persisting whether a Claude process had counted usage (#1175), so the keeper record drops its usage_started field. Forgetting a remote host now reports a saved session it could not remove.

Fixes https://linear.app/alphaxiv/issue/ORX-834/keep-agents-and-terminals-alive-across-orx-up-restarts

Assisted-by: claude-opus-5.5
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.

1 participant