Repository navigation
Conversation
Prepared with AI assistance (audit + implementation: gpt-5.6-sol; review: Claude Fable 5); reviewed and tested before filing. Co-Authored-By: gpt-5.6-sol <[email protected]> Co-Authored-By: Claude Fable 5 <[email protected]>
|
This PR was auto-closed. Only contributors approved with Maintainers review auto-closed issues and reopen worthwhile ones. Issues that do not meet the quality bar in CONTRIBUTING.md may not be reopened or receive a reply. If a maintainer replies See CONTRIBUTING.md. |
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughCodex usage deserialization now excludes reasoning tokens when deriving an omitted total, while an explicit zero derives the total from input, output, and reasoning tokens. Unit tests cover both cases. ChangesCodex token derivation
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
|
Thanks — the bug is real and this is now landing in #1499 with your commit kept intact. I could not update this branch in place: Two notes on what changed on top of your commit:
For the record, the invariant was confirmed against real logs rather than fixtures. Across 170,429 Closing in favor of #1499. |
…1499) Codex reports `reasoning_output_tokens` as a subset of `output_tokens`, so `total_tokens` is `input_tokens + output_tokens`. The fallback used when a record omits `total_tokens` added reasoning on top, inflating the reported total: a saved `codex exec --json` turn with 100 input, 50 output and 20 reasoning tokens reported 170 instead of 150. Derive the total as input plus output, and treat a recorded zero the same way. A zero alongside nonzero components means the field is unusable, not that the turn spent nothing. Defer and saturate the sum so a corrupt log carrying near-`u64` components cannot panic a debug build or wrap in release. Verified against real logs rather than fixtures. Across 170,429 `token_count` records, the 21,815 carrying nonzero reasoning satisfy `total_tokens == input_tokens + output_tokens` in every case and `input_tokens + output_tokens + reasoning_output_tokens` in none. `docs/guide/codex/index.md` already documented the same rule, noting that reasoning tokens are part of the output charge rather than billed separately, so the code now matches the guide. Rollout session logs always record a usable total, so this only affects saved exec JSON usage, where OpenAI-style payloads may omit the field. Costs were never affected because pricing reads input, cached input and output directly. Supersedes #1458, whose branch could not be updated in place because `MaxGhenis/ccusage` is a fork of `jackcpku/ccusage` rather than a direct fork of this repository. Co-authored-by: Max Ghenis <[email protected]>
|
Historical audit: this pull request was auto-closed by the legacy contributor gate. That closure did not assess technical importance. Audit result: needs review. The current state does not prove resolution, but a fresh technical or product check is required before deciding whether the underlying request is still relevant. This closed PR will not be revived as-is; create a new PR only after reviewing the related issue and current |
Summary
total_tokensvalue as input plus outputThe expected invariant and fixture/oracle method follow the Logpile accounting review. The exact 2026-07-18 matrix behind this change is published as the 2026-07-18 ccusage verification.
Testing
cargo +1.96.0 test --manifest-path rust/Cargo.toml --workspace --offline(445 passed)totalTokensPrepared with AI assistance; I reviewed the implementation and test results.
Need help on this PR? Tag
/codesmithwith what you need. Autofix is disabled.Summary by cubic
Fixes Codex legacy
total_tokensfallback to compute correct totals and avoid double-counting reasoning tokens. Preserves explicit-zero behavior and adds regression tests for missing totals and explicit zero.total_tokensis missing: derive as input + output (exclude reasoning).total_tokensis 0: derive as input + output + reasoning (keep legacy semantics).Written for commit 705c85f. Summary will update on new commits.
Summary by CodeRabbit