Skip to content

fix(token-spy): record cumulative Anthropic usage counters - #4561

Merged
gabsprogrammer merged 1 commit into
Osmantic:public-betafrom
0xacee:fix/token-spy-record-cumulative-anthropic-usage
Sep 13, 2026
Merged

gabsprogrammer merged 1 commit into
Osmantic:public-betafrom
0xacee:fix/token-spy-record-cumulative-anthropic-usage

Conversation

@0xacee

@0xacee 0xacee commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Why this matters

Anthropic message deltas can carry cumulative input and cache counters, in addition to output tokens. Token Spy currently retains the initial input/cache values and only updates output, under-reporting a response whose final counters differ.

Normalize the present cumulative counters in one helper used by the deployed Messages proxy and provider adapter. Replace previous values rather than adding them; retain prior observations for omitted/null fields and honor explicit zero values. Stream content and event framing are unchanged.

Contract references: Anthropic streaming usage is cumulative and MessageDeltaUsage fields.

Overlap check

Searched open/closed titles and changed files. #2511 changes Claude model pricing; #2519 fixes OpenAI cached-token accounting; #3595 prices routed telemetry. Inspected #3806: it handles nullable usage containers but does not record cumulative input/cache deltas. This changes counter extraction, not rates or nullable-container policy.

Validation

  • Authenticated POST /v1/messages regressions on public-beta: 2 fail, 2 controls pass.
  • Full Token Spy suite: 26 passed, 1 skipped (PostgreSQL integration unavailable).
  • Same scenarios exercise the provider adapter after the HTTP assertions.
  • Multiple deltas, revised input/cache totals, explicit zeros, omitted/null individual fields, exact passthrough text, one logged entry, and stop reason are checked.
  • Changed-file Ruff with CI rules and diff whitespace checks pass.
  • Mock upstream transport; no live provider calls or billing charges.

Review / risk

Review required before merge: independent review of proxy telemetry behavior and the live proxy validation lane. Pricing tables and requests are unchanged.

AI assistance: implemented and validated with Codex.

Combined validation: c08b6695ff14 on public-beta base 9fc9f61. Token Spy: 64 passed, 1 skipped.

Merge guidance: tested Token Spy main.py order is #4561, #4569, #4583, #4634, #4640. The #4583/#4634 poller conflict must retain await asyncio.to_thread for status and reset, include_session_id=True on assessment, session_id=status["_reset_session_id"] on deletion, and cooldown updates only after action == "killed".

Exact PR-head CI remains red: Windows dashboard compact-draft assertion in RemoteProvider. See run 34709252447. #4570 addresses the overwrite; the combined dashboard suite passes all 906 tests. The contributing account lacks repository rerun permission (HTTP 403 on the same workflow).

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.

2 participants