fix(codex): stop double-billing cached input and reasoning tokens - #28
Open
lroolle wants to merge 2 commits into
Open
fix(codex): stop double-billing cached input and reasoning tokens#28lroolle wants to merge 2 commits into
lroolle wants to merge 2 commits into
Conversation
Codex usage fields are subsets, not disjoint categories: input_tokens INCLUDES cached_input_tokens (upstream codex-rs: non_cached_input = input - cached) and output_tokens includes reasoning tokens (OpenAI output_tokens_details). ccx stored the raw values and ComputeCost billed every field separately, so cached tokens were billed twice (once at full input rate) and reasoning twice at output rate. On a real 36-minute session: displayed $101.99, honest $38.54 — 2.6x overstated. The header also read "6.6m in" for ~206k of uncached input, while Claude sessions' "in" excludes cache — the same line meant different things per provider. The Codex backend now normalizes to the Anthropic-style exclusive semantics the rest of ccx assumes (input excludes cache reads), for both the session aggregate and per-message deltas; ComputeCost drops the reasoning term (subset of output, same rate); the contract is documented on MessageUsage. CacheFormatVersion bumped so upgraded binaries reparse instead of serving stale cached numbers. Closes #27 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Summary
Found by the first cross-provider field eval (claude f8e49d74 vs codex 019fa810, same workspace). Codex usage fields are subsets, not disjoint categories:
input_tokensincludescached_input_tokens— upstream codex-rs definesnon_cached_input = input - cached(protocol/src/protocol.rs)output_tokensincludes reasoning tokens — OpenAIoutput_tokens_details.reasoning_tokensccx stored the raw values and
ComputeCostbilled all five fields separately: cached tokens billed twice (once at full input rate), reasoning billed twice at output rate. Real impact on the eval session: $101.99 displayed, $38.54 honest — 2.6x overstated, and a header reading6.6m infor ~206k of uncached input while Claude'sinexcludes cache (same line, different semantics per provider).Changes:
InputTokensexcludes cache reads), for the session aggregate, the quick-parse stats, and per-message deltasComputeCostdrops the reasoning term (subset of output at the same rate); contract documented onMessageUsageCacheFormatVersion2 → 3 so upgraded binaries reparse instead of serving the old numbers from the disk cache (this is how the bug initially appeared "unfixed" during verification)Closes #27. Note: will trivially conflict with #26 on the CHANGELOG
[Unreleased]header — resolve by keeping both entries.Test plan
go test ./...green🤖 Generated with Claude Code