Skip to content

Conversation

@hannesrudolph
Copy link
Collaborator

@hannesrudolph hannesrudolph commented Nov 13, 2025

Summary

  • Normalize usage in Roo provider so Anthropic-protocol models report non-cached input tokens while non-Anthropic models keep total prompt_tokens.

Changes

  • Roo provider: determine protocol and normalize input tokens:
    • Anthropic models: inputTokens = prompt_tokens − cache_write − cache_read
    • Non-Anthropic models: inputTokens = prompt_tokens
    • Implementation: roo.ts, protocol via getApiProtocol()
  • Core (Task): revert prior heuristic to keep provider-agnostic logic:

Why

  • Roo backend usage reports prompt_tokens in OpenAI-like shape. For Anthropic-prefixed models, treating prompt_tokens as “non-cached” would double count cached tokens when totals are derived. Normalizing at the provider ensures consistent semantics and prevents double counting.

Verification

  • Unit tests pass (vitest).
  • Manual: run a Roo Anthropic model; confirm api_req_started tokensIn equals non-cached input (not including cacheWrites/cacheReads), and contextTokens = tokensIn + tokensOut once.

References


Important

Normalizes input token usage in RooHandler for Anthropic models to report non-cached tokens, maintaining provider-agnostic core logic.

  • Behavior:
    • Normalizes input token usage in RooHandler for Anthropic models to report non-cached tokens (prompt_tokens - cache_write - cache_read).
    • Non-Anthropic models continue to report total prompt_tokens.
    • Reverts Task-level heuristic to keep core provider-agnostic.
  • Functions:
    • Uses getApiProtocol() in RooHandler to determine protocol and adjust token reporting.
  • Misc:
    • All tests pass using vitest.

This description was created by Ellipsis for 0c4ca55. You can customize this summary. It will automatically update as commits are pushed.

…d double-counting cached tokens; revert core-level heuristic to keep Task provider-agnostic
@hannesrudolph hannesrudolph marked this pull request as ready for review November 13, 2025 06:26
@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. bug Something isn't working labels Nov 13, 2025
@roomote
Copy link
Contributor

roomote bot commented Nov 13, 2025

Rooviewer Clock   See task on Roo Cloud

Review complete. No issues found.

The implementation correctly normalizes input token reporting based on API protocol:

  • Anthropic models report non-cached tokens (prompt_tokens - cache_write - cache_read)
  • OpenAI models report total prompt_tokens
  • Protocol detection and token calculation are implemented correctly
  • Changes maintain backward compatibility and consistency with core logic

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Nov 13, 2025
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Nov 13, 2025
@mrubens mrubens merged commit 4e6cdad into main Nov 13, 2025
31 checks passed
@mrubens mrubens deleted the fix/roo-anthropic-input-tokens-normalization branch November 13, 2025 06:46
@github-project-automation github-project-automation bot moved this from Triage to Done in Roo Code Roadmap Nov 13, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Nov 13, 2025
mini2s added a commit to zgsm-ai/costrict that referenced this pull request Nov 13, 2025
* Add Intercom as a subprocessor (RooCodeInc#8718)

* web: Leftover white bg (RooCodeInc#8719)

Leftover white bg

* feat(zgsm): add supportsMaxTokens flag and adjust max token handling

* docs: update Configuring Profiles video link (RooCodeInc#8189)

Co-authored-by: Roo Code <[email protected]>

* Fix link text for Roomote Control in README (RooCodeInc#8742)

* Try a 5s status mutation timeout (RooCodeInc#8734)

* web: Landing page for the reviewerFirst pass (RooCodeInc#8740)

* First pass

* SEO

* Update apps/web-roo-code/src/app/reviewer/page.tsx

Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>

---------

Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>

* Remove GPT‑5 instructions/reasoning_summary from UI message metadata to prevent ui_messages.json bloat (RooCodeInc#8756)

chore(gpt5): stop persisting instructions/reasoning_summary in UI message metadata

Problem: ui_messages.json was getting bloated with unused or duplicated content (system 'instructions' and 'reasoning_summary') that we do not read back. Root cause: earlier OpenAI Responses API implementation persisted these fields to per-message metadata; however, 'instructions' are already sent as top-level request instructions and 'reasoning_summary' is surfaced live via streaming events. Neither field is consumed from storage. Changes: (1) Task.persistGpt5Metadata now stores only previous_response_id; (2) removed instructions and reasoning_summary from types; (3) updated Zod schema; (4) persistence layer writes messages as-is (no sanitizer); (5) tests green. Impact: smaller ui_messages.json, no runtime behavior change for requests. Migration: old metadata fields will be ignored by schema.

* Z.ai: add GLM-4.5-X, AirX, Flash (expand model coverage) (RooCodeInc#8745)

* feat(zai): add GLM-4.5-X, AirX, Flash; sync with Z.ai docs; keep canonical api line keys

* feat(zai): add GLM-4.5V vision model (supportsImages, pricing, 16K max output); add tests

* feat(types,zai): sync Z.AI international model map and tests
- Update pricing, context window, and capabilities for:
  glm-4.5-x, glm-4.5-airx, glm-4.5-flash, glm-4.5v, glm-4.6
- Add glm-4-32b-0414-128k
- Align tests with new model specs

* fix(zai): align handler generics with expanded model ids to satisfy CI compile step

* chore(zai): remove tier pricing blocks for Z.ai models

* fix(zai): simplify names in zaiApiLineConfigs for clarity

* chore(zai): set default temperature to 0.6

---------

Co-authored-by: Roo Code <[email protected]>

* Enable browser-use tool for all image-capable models (RooCodeInc#8121)

Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>
Co-authored-by: Hannes Rudolph <[email protected]>
Co-authored-by: Matt Rubens <[email protected]>

* Skip failing tools tests (RooCodeInc#8767)

* Update text for clarity in reviewer page (RooCodeInc#8753)

* feat: add GLM-4.6-turbo model to chutes ai provider (RooCodeInc#8502)

Co-authored-by: roomote[bot] <219738659+roomote[bot]@users.noreply.github.com>

* web: Dynamic OpenGraph images (RooCodeInc#8773)

Co-authored-by: Roo Code <[email protected]>

* web: Updates CTA link in /reviewer to send people to /cloud-agents/welcome (RooCodeInc#8774)

* feat: add 'anthropic/claude-haiku-4.5' to prompt caching models (RooCodeInc#8764)

Co-authored-by: daniel-lxs <[email protected]>

* refactor(core): consolidate global custom instructions and improve shell handling

* fix: update X/Twitter username from roo_code to roocode (RooCodeInc#8780)

Co-authored-by: Roo Code <[email protected]>

* fix(zgsm): safely pass optional language metadata to avoid runtime errors

* test: update test expectations for shell handling and prompt enhancement

* fix: always show checkpoint restore options regardless of change detection (RooCodeInc#8758)

* feat: add token-budget based file reading with intelligent preview (