Repository navigation
fix(agents): preserve Anthropic thinking-token usage - #116993
Conversation
|
Codex review: needs real behavior proof before merge. Reviewed July 31, 2026, 3:05 PM ET / 19:05 UTC. ClawSweeper reviewWhat this changesThis PR recognizes Anthropic Merge readiness⛔ Blocked until stronger real behavior proof is added - 4 items remain Keep this PR open for protected-label maintainer review and redacted real-provider evidence. Current Priority: P2 Review scores
Verification
How this fits togetherProvider and stream adapters supply raw token-usage payloads to the agent runtime. The shared usage normalizer turns those payloads into agent events, transcript data, Gateway-compatible usage, and session cost/reporting inputs. flowchart LR
A[Provider usage payload] --> B[Agent stream and subscription]
B --> C[Shared usage normalizer]
C --> D[Agent run usage events]
C --> E[Session transcript usage]
D --> F[Gateway and API consumers]
E --> G[Cost and usage reporting]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +1, Tests +19. Total +20 across 2 files. View PR surface stats
Review metricsNone. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep the provider spelling at the shared usage-normalization boundary, retaining Do we have a high-confidence way to reproduce the issue? No high-confidence live reproduction is available in this read-only checkout: current source clearly omits the fallback, but the installed Anthropic SDK type and a redacted real response were unavailable for independent verification. Is this the best way to solve the issue? Unclear pending provider-payload proof: the shared normalizer is the best owner boundary and the precedence order is correct, but the exact Anthropic wire shape still needs direct confirmation. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 38d53e324d78. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Merged via squash.
|
Co-authored-by: Peter Steinberger <[email protected]>
fix(agents): preserve Anthropic thinking token usage
What Problem This Solves
Anthropic reports thinking usage in
output_tokens_details.thinking_tokens, while OpenAI reports the same normalized concept inoutput_tokens_details.reasoning_tokens. The shared provider-agnostic usage owner understood only the OpenAI spelling, so every Claude thinking-token count silently disappeared before existing agent, session, Gateway, and accounting consumers received it.Why This Change Was Made
Recognize the official Anthropic field at the existing canonical normalization boundary. Preserve the existing OpenAI spelling as the higher-priority value and use nullish selection so explicitly reported zero thinking tokens remain observable.
The installed Anthropic SDK defines the field for both streamed message-delta usage and final response usage in
node_modules/@anthropic-ai/sdk/src/resources/messages/messages.ts:1189-1199,:1292-1303, and:2382-2395. The installed OpenAI SDK retains its existingreasoning_tokenscontract innode_modules/openai/src/resources/responses/responses.ts:7275-7282.User Impact
Claude thinking-token counts now reach the same existing reasoning-token metrics and reporting paths already used by OpenAI. Existing token totals, cache counts, OpenAI precedence, public configuration, plugin SDK, authentication, persistence, and protocol behavior do not change.
Evidence
36b80ada3ceae2de21b3d8710b883d778e4c4578.63ddaa2d1bb23131b2d0cb73ec0a8f0e83afb86d.node scripts/run-vitest.mjs src/agents/usage.test.ts: 47 tests passed.thinking_tokens: 17previously produced noreasoningTokens; the candidate reports17, preserves explicit zero, preserves OpenAI17, and retains OpenAI precedence when both fields are present.gpt-5.6-sol/ high / P3 autoreview: clean, confidence 0.95, no actionable P0/P1/P2/P3 findings; TruffleHog preflight clean.