Skip to content

fix(usage): Count Codex cached tokens once in token totals - #110

Merged
4ndreello merged 1 commit into
mainfrom
fix/codex-cached-token-total
Sep 23, 2026
Merged

4ndreello merged 1 commit into
mainfrom
fix/codex-cached-token-total

Conversation

@4ndreello

Copy link
Copy Markdown
Owner

Summary

Codex reports cached_input_tokens as part of input_tokens. Pricing already handled that (cachedInInputFor), but token totals did not: queryUsage and the statusline tok field computed input + output + cached, so Codex cache was counted twice. On the rollout cited in the orchestrator-usage spec (input 8.36M, cached 8.12M) that shows about 16.5M tokens instead of about 8.4M.

  • add totalTokensFor(agent, usage) next to cachedInInputFor: cached is added only when the harness keeps it outside input
  • queryUsage totals and every bucket use it
  • RunUsageSummary exposes totalTokens for workers and for orchestrator
  • the statusline renders runUsage.totalTokens when valid and falls back to the old sum for an older daemon

Orchestrator tokens on the statusline are a separate feature (spec in progress).

Test plan

  • npx vitest run tests/pricing.test.ts tests/usage.test.ts tests/usage-query.test.ts tests/usage-daemon.test.ts tests/usage-cli.test.ts tests/statusline.test.ts: 6 files, 74 tests passed
  • npx tsc --noEmit -p .: clean
  • mutation: helper changed to always add cached, tests/pricing.test.ts fails (1 of 21)

Use harness-aware totals in run usage and query buckets.
Expose worker and orchestrator totals while keeping the statusline fallback for older daemons.

Co-Authored-By: Codex <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

@4ndreello
4ndreello merged commit e6d7553 into main Sep 23, 2026
4 checks passed
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