Fixes #616
Problem and behavior
A resumed rollout can start with the logical session's historical total_token_usage. The local scanner currently subtracts zero for each new file, charging that history to the continuation date. On the reported dataset, the existing algorithm produces 199,153,495 tokens for a day containing 29,044,867 tokens in unique request records.
This updates the shared local usage core used by both the app and daemon:
- Read
token_usage_record.payload.usageand deduplicateresponse_idacross files and session roots. - Treat request records as authoritative in files containing that format. Buffer legacy counters until the file's format is known, so preceding or delayed display events cannot duplicate a request.
- Keep legacy-only files supported: prefer
last_token_usage, suppress repeated totals, establish a baseline for the first cumulative-only snapshot and after counter resets, and deduplicate copied events using session ID, timestamp and usage. - Count input plus output, keep cached input within input, and avoid adding reasoning output or a stale
total_tokensfield again.
No IPC payload changes or new dependencies are required.
Compatibility boundary
The legacy fallback deliberately does not infer consumption from an initial cumulative-only snapshot, including the first total after standalone last-usage events. That snapshot can contain inherited history; only subsequent increments are attributable. Request records are authoritative at the file level when present. These remain local request-usage statistics, not provider invoice or account-quota data.
Validation
cargo test --lib shared::local_usage_core::tests --locked: 16 passed, including seven new regressions covering continuations, copied records, cross-root request deduplication, mixed display/request ordering, cached/reasoning tokens, counter resets, aliases and workspace filtering.npm run typecheck: passed.cargo check --locked: passed (existing upstream warnings remain).rustfmt --edition 2021 --check src-tauri/src/shared/local_usage_core.rsandgit diff --check: passed.- A temporary harness executing the modified Rust scanner against sanitized local usage events at the issue's cutoff produced input 28,898,641, cached input 26,920,192, output 146,226, total 29,044,867, matching the independent deduplicated request calculation. This is scanner verification, not live application UI or billing verification. Personal rollout records are not included in the PR.
Activity
3Codex Review Summary
This comment shows the latest Codex review activity on this pull request.
| Review | Status | Commit | Review trigger |
|---|---|---|---|
| 📝 Code Review | ✅ Completed 2026-10-09T13:30:28.836190Z | 826bce4 | PR opened |
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review" or "@codex security review".
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit:
826bce473bℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".