fix(antigravity): preserve thinking blocks in message converter#253
fix(antigravity): preserve thinking blocks in message converter#253codewithkenzo wants to merge 6 commits into
Conversation
When using Claude extended thinking models (e.g., claude-opus-4-5-thinking) through Antigravity, thinking and redacted_thinking blocks in assistant message content arrays were being stripped during OpenAI→Gemini conversion. This caused 'messages.X.content.0.type: Expected thinking or redacted_thinking, but found text' errors when the API expected thinking blocks to be preserved. Changes: - Add thought property to GeminiPart interface - Handle thinking/redacted_thinking content types in convertContentToParts - Convert to Gemini thought format with thought=true flag
|
All contributors have signed the CLA. Thank you! ✅ |
Greptile SummaryThis PR fixes a critical bug in the Antigravity message converter that caused API errors when using Claude extended thinking models through the proxy. Key Changes:
Root Cause Fixed: The fix properly extracts thinking content from Confidence Score: 5/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Client
participant Antigravity
participant MessageConverter
participant AnthropicAPI
Client->>Antigravity: POST /chat (OpenAI format)
Note over Client: model: claude-opus-4-5-thinking<br/>messages with thinking blocks
Antigravity->>MessageConverter: convertOpenAIToGemini(messages)
Note over MessageConverter: Process each message
loop For each message
alt Message role: assistant
MessageConverter->>MessageConverter: convertContentToParts(content)
loop For each content part
alt part.type === "text"
MessageConverter->>MessageConverter: Add {text: part.text}
else part.type === "thinking" or "redacted_thinking"
MessageConverter->>MessageConverter: Add {thought: true, text: part.thinking || part.text}
else part.type === "image_url"
MessageConverter->>MessageConverter: Add {inlineData: {...}}
end
end
end
end
MessageConverter-->>Antigravity: Gemini contents format
Note over Antigravity: contents with thought parts
Antigravity->>AnthropicAPI: POST /messages (Anthropic format)
Note over AnthropicAPI: Validates thinking blocks present<br/>in assistant message
AnthropicAPI-->>Antigravity: Success response
Antigravity-->>Client: OpenAI-compatible response
|
Greptile found no issues!From now on, if a review finishes and we haven't found any issues, we will not post anything, but you can confirm that we reviewed your changes in the status check section. This feature can be toggled off in your Code Review Settings by deselecting "Create a status check for each PR". |
|
I have read the CLA Document and I hereby sign the CLA |
When converting thinking blocks from OpenAI to Gemini format: - Extract and preserve signature from various field names (signature, thoughtSignature, thought_signature) - Skip unsigned thinking blocks from history to avoid Claude API error: 'assistant message must start with a thinking block' - Claude requires valid signatures on all thinking blocks in multi-turn conversations, unsigned blocks cause 400 errors
When Claude thinking models are used with conversation history, OpenCode doesn't preserve thinking block signatures. This causes Claude API to reject requests with error: 'assistant message must start with a thinking block' This fix detects Claude thinking models with history and strips the thinking configuration to prevent the error. Relates to: anomalyco/opencode#6176
This reverts commit bbff83c.
This reverts commit 0e96d01.
|
Closing in favor of a more comprehensive fix that addresses the complete signature flow issue. |
Summary
Fix thinking block handling in Antigravity message converter.
Problem
When using Claude models with extended thinking through Antigravity, thinking blocks (
type: "thinking"ortype: "redacted_thinking") were being dropped during OpenAI→Gemini message conversion.Fix
thought?: booleanto GeminiPart interfacethinkingandredacted_thinkingcontent types inconvertContentToParts()thought: trueformat with text contentNote
There's a separate upstream issue where OpenCode doesn't preserve thinking block signatures in message history, causing multi-turn conversations to fail. That's tracked in anomalyco/opencode#6176 and needs to be fixed in OpenCode itself.