Skip to content

Conversation

@hannesrudolph
Copy link
Collaborator

@hannesrudolph hannesrudolph commented Nov 26, 2025

Summary

Fixes the context condensation error when using reasoning with Anthropic models on Vertex:

Input tag 'reasoning' found using 'type' does not match any of the expected tags

Root Cause

  1. Roo Code stores reasoning content internally with type: 'reasoning' (provider-agnostic format)
  2. Gemini stores thought signatures with type: 'thoughtSignature'
  3. When messages are replayed to Anthropic/Vertex APIs during context condensation or model switching, these non-standard types cause 400 errors

Solution

Added filterNonAnthropicBlocks() to both anthropic-vertex.ts and anthropic.ts handlers that uses an allowlist approach to only keep valid Anthropic content types.

Valid Anthropic content types (allowlist): text, image, tool_use, tool_result, thinking, redacted_thinking, document

This automatically filters out:

  • type: 'reasoning' - Internal Roo Code format
  • type: 'thoughtSignature' - Gemini's encrypted reasoning signature
  • Any other unknown/future block types

Implementation Details

This follows established patterns in the codebase:

  • Gemini handler (line 98-104): Filters type: 'reasoning' messages
  • gemini-format.ts (line 131-136): Skips unsupported blocks with console.warn
  • Claude Code handler: Uses filterMessagesForClaudeCode() for image blocks
  • Cerebras handler: Strips thinking tokens from assistant messages

Testing

  • Added tests for filtering internal reasoning blocks
  • Added tests for filtering empty messages after removing all reasoning blocks
  • Added test for filtering unknown future block types
  • All 48 tests pass

Related

Fixes #9583
Related to #9584

@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. bug Something isn't working labels Nov 26, 2025
@roomote
Copy link
Contributor

roomote bot commented Nov 26, 2025

Oroocle Clock   Follow along on Roo Cloud

Review complete. One issue was flagged related to Anthropic prompt caching model coverage.

  • Ensure claude-opus-4-5-20251101 is included in the prompt-caching switch and beta-header logic in src/api/providers/anthropic.ts so it uses the same caching behavior as the other Opus models.
Previous reviews

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 26, 2025
Copy link
Collaborator Author

@hannesrudolph hannesrudolph left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review complete! The fix correctly addresses issue #9583 by filtering out non-Anthropic content blocks before sending to the API.

What was reviewed:

  • ✅ Filters reasoning and thoughtSignature blocks that cause API 400 errors
  • ✅ Proper handling of empty messages after filtering
  • ✅ Tests cover both mixed content and edge cases
  • ✅ Follows established patterns from gemini-format.ts

Additional improvements made during review:

  • Extracted filterNonAnthropicBlocks to shared utility src/api/transform/anthropic-filter.ts
  • Added 9 unit tests for the shared utility
  • Eliminates code duplication between anthropic.ts and anthropic-vertex.ts

All 48 tests pass. Ready to merge.

Fixes context condensation error when using reasoning with Anthropic models on Vertex:
'Input tag reasoning found using type does not match any of the expected tags'

The issue occurs because:
1. Roo Code stores reasoning content internally with type: 'reasoning'
2. Gemini stores thought signatures with type: 'thoughtSignature'
3. When messages are replayed to Anthropic/Vertex APIs, these non-standard types cause 400 errors

Solution:
- Added filterNonAnthropicBlocks() to anthropic-vertex.ts and anthropic.ts
- Filters out 'reasoning' (internal Roo format) and 'thoughtSignature' (Gemini format)
- Removes empty messages after filtering

This follows the same pattern used by:
- Gemini handler (filters 'reasoning' messages)
- gemini-format.ts (skips unsupported block types)
- Claude Code handler (filterMessagesForClaudeCode for images)

Fixes #9583
Related to #9584
…code

- Add claude-opus-4-5-20251101 back to switch statements for prompt caching support
- Remove unused lastThinkingSignature property and getThinkingSignature() method
- Created src/api/transform/anthropic-filter.ts with shared filtering logic
- Updated anthropic.ts and anthropic-vertex.ts to import from shared utility
- Added tests for the shared utility (9 new tests)
- Eliminates code duplication between the two handlers
@hannesrudolph hannesrudolph force-pushed the fix/9583-filter-reasoning-blocks-vertex branch from db4448f to f25c4c5 Compare November 26, 2025 20:40
@hannesrudolph hannesrudolph moved this from Triage to PR [Needs Prelim Review] in Roo Code Roadmap Nov 26, 2025
@hannesrudolph hannesrudolph added PR - Needs Preliminary Review and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels Nov 26, 2025
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Nov 26, 2025
@hannesrudolph hannesrudolph moved this from PR [Needs Prelim Review] to PR [Needs Review] in Roo Code Roadmap Nov 26, 2025
Address review feedback from mrubens to use an allowlist approach instead
of a denylist. This is more robust as any new/unknown block types will
automatically be filtered out.

VALID_ANTHROPIC_BLOCK_TYPES now explicitly lists accepted types:
- text, image, tool_use, tool_result, thinking, redacted_thinking, document
@mrubens mrubens merged commit fb9c57e into main Nov 26, 2025
10 checks passed
@mrubens mrubens deleted the fix/9583-filter-reasoning-blocks-vertex branch November 26, 2025 22:47
@github-project-automation github-project-automation bot moved this from PR [Needs Review] to Done in Roo Code Roadmap Nov 26, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Nov 26, 2025
@cardil
Copy link

cardil commented Nov 27, 2025

🎉 Confirmed.

After upgrading to v3.34.6 I was able to resume the previously failing thread, and it properly condenses.

Screenshot From 2025-11-27 01-08-30

mini2s added a commit to zgsm-ai/costrict that referenced this pull request Nov 27, 2025