-
Notifications
You must be signed in to change notification settings - Fork 2.8k
fix: filter non-Anthropic content blocks before sending to Vertex API #9618
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Review complete. One issue was flagged related to Anthropic prompt caching model coverage.
Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues. |
hannesrudolph
left a comment
There was a problem hiding this 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
reasoningandthoughtSignatureblocks 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
filterNonAnthropicBlocksto shared utilitysrc/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
db4448f to
f25c4c5
Compare
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
|
🎉 Confirmed. After upgrading to v3.34.6 I was able to resume the previously failing thread, and it properly condenses.
|

Summary
Fixes the context condensation error when using reasoning with Anthropic models on Vertex:
Root Cause
type: 'reasoning'(provider-agnostic format)type: 'thoughtSignature'Solution
Added
filterNonAnthropicBlocks()to bothanthropic-vertex.tsandanthropic.tshandlers 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,documentThis automatically filters out:
type: 'reasoning'- Internal Roo Code formattype: 'thoughtSignature'- Gemini's encrypted reasoning signatureImplementation Details
This follows established patterns in the codebase:
type: 'reasoning'messagesfilterMessagesForClaudeCode()for image blocksTesting
Related
Fixes #9583
Related to #9584