Skip to content

fix(telemetry): read plain-text token counters from the usage summary - #293

Merged
mountainowl merged 2 commits into
mainfrom
bugfix/plain-text-token-parser
Oct 22, 2026
Merged

mountainowl merged 2 commits into
mainfrom
bugfix/plain-text-token-parser

Conversation

@mountainowl

Copy link
Copy Markdown
Owner

Requested by Ajay Singh · project thread

What changed

  • Before: a custom reviewer command falls back to plain-text token counters, and that parser had three bugs.
    • It took the first match of each counter, so review prose saying "input tokens: 5" beat the real summary of 10,000 printed after it.
    • It added cached tokens on top of input when it derived a total, so 10,000 input (8,000 of them cached) plus 500 output came out as 18,500 instead of 10,500.
    • Its input pattern also matched cached input tokens: lines.
  • After:
    • The last match of each counter wins.
    • cached input isn't read as input.
    • A derived total is input plus output.
    • Codex and Claude runs are unaffected, because they report usage as JSON.

Verification

  • tests/test_plain_text_token_usage.py drives the real parse_agent_output fallback.
  • On main, the prose case read input as 5, and the cached case gave a total of 18,500. Both pass with this change.
  • Two guard tests pass on both: a cached line printed after the input line, and a reported total being kept.
  • The full suite on Python 3.14 gives 1931 passed. The only failures are the 2 container-only test_ui_export failures, which also fail on main.
  • ruff check, ruff format --check and cz check pass.

Notes

  • Output with only a cached counter, and no input or output counter, no longer gets a total equal to the cached count, because that number alone isn't a total.

Generated by Claude Code

The fallback parser for custom reviewer commands took the first match of
each counter, so numbers quoted in the review text beat the real summary
printed after it. It also added cached tokens on top of input when it
derived a total, though cached tokens are part of input, and its input
pattern matched "cached input tokens" lines.

The last match now wins, "cached input" is not read as input, and a
derived total is input plus output.
@mountainowl mountainowl self-assigned this Oct 20, 2026
@mountainowl
mountainowl merged commit 405b515 into main Oct 22, 2026
5 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