opencode
opencode copied to clipboard
fix: strip incompatible thinking blocks when switching to Anthropic models
Problem
When switching from a model like minimax to Claude/Opus mid-session, the API returns:
messages.9.content.0: Invalid 'signature' in 'thinking' block
This happens because the session contains cached messages with thinking blocks that have signatures from the previous model (minimax), which Anthropic's API rejects.
Solution
In normalizeMessages(), when the target model is Claude:
- Filter out
thinkingblocks that have signatures (from other providers) - Convert
reasoningparts to text wrapped in<thinking>tags to preserve content
Testing
- Start a session with minimax or another model that generates thinking blocks
- Switch to Claude Opus mid-session
- Should no longer get the 'Invalid signature' error