Skip to content

fix: reconcile OpenCode's totalTokens against its component sum - #7

Merged
BrickerP merged 1 commit into
mainfrom
codex/opencode-total-reconcile
Aug 11, 2026
Merged

fix: reconcile OpenCode's totalTokens against its component sum#7
BrickerP merged 1 commit into
mainfrom
codex/opencode-total-reconcile

Conversation

@BrickerP

Copy link
Copy Markdown
Owner

Summary

Follow-up to #6. ccusage's OpenCode collector reports totalTokens independently of its own input/cache/output component fields, and on real data the two disagreed by a small residual (589,483,361 vs 589,471,183 — about 2 in 10,000). That mismatch tripped the component_mismatch regression guard in machine_fragments._tool_regression_reason, so every OpenCode row was rejected as an unresolvable regression and never written to the local machine fragment — confirmed live on mac-m4-local during today's manual publish run.

  • Recompute OpenCode's reported tokens from the sum of its own input/cache_create/cache_read/output fields (the authoritative per-request counts), instead of trusting ccusage's independently-derived total.
  • Scoped to opencode_daily_points only; Codex and Claude Code parsing are unchanged.

Testing

  • node --test tests/*.test.mjs: 80/80 pass.
  • Targeted python3 -m unittest on daily reconciliation / oneapi / ccusage-pricing / codex-jsonl suites: all pass.
  • Manually verified against live ccusage opencode daily --json output for 2026-08-11 (real Claude/DeepSeek/grok mix): fixed row now yields snapshot_complete: true and per-model breakdown token sums matching the corrected total exactly.

ccusage's OpenCode collector derives totalTokens independently of the
per-request input/cache/output fields it also reports, and the two can
disagree by a small residual (observed: 2/10,000 on real data). That
mismatch tripped snapshot-completeness and regression-guard checks in
the local fragment merge, so OpenCode's historical rows were silently
kept out of frozen fragments.

Trust the component sum (the authoritative per-request counts) and
recompute the reported total from it for OpenCode only; Codex/Claude
Code totals are untouched.
@BrickerP
BrickerP merged commit 58ded76 into main Aug 11, 2026
3 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