-
Notifications
You must be signed in to change notification settings - Fork 51
fix(gemini): resolve thought_signature errors and duplicate timeout messages #193
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
…ture errors Gemini 3 with thinking mode requires thought_signature to be passed back with tool calls. Since we don't store thought signatures, this fix strips reasoning parts from messages before sending to Gemini models. This is a safeguard for old messages saved without thought signatures.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughAdds Gemini-specific helpers to strip assistant "reasoning" parts from messages and applies them in the chat handler before model streaming and after summarization; also conditionally hides error UI for preemptive timeouts in the Messages component. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
When preemptive timeout triggers, the abort causes both: 1. FinishReasonNotice to show "I had to stop due to time limit" 2. MessageErrorState to show "network error" This fix hides the error state when finishReason is "timeout" since it's a graceful abort, not a real error.
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.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
lib/utils/message-processor.ts (1)
253-262: Docstring separated from its function.The new code was inserted between the docstring at lines 253-256 (for
completeIncompleteToolCalls) and the function itself at line 306. This breaks the documentation association.Proposed fix: Move new functions before the docstring
Move
isReasoningPart,stripReasoningForGemini, andstripReasoningFromMessagesForGeminiabove line 253 so the existing docstring remains adjacent tocompleteIncompleteToolCalls.+/** + * Checks if a part is a reasoning/thinking part. + */ +const isReasoningPart = (part: Record<string, any>): boolean => { + return part.type === "reasoning" || part.type === "thinking"; +}; + +/** + * Strips reasoning parts from messages for Gemini models. + * ... + */ +export const stripReasoningForGemini = ... + +/** + * Strips reasoning parts from all messages for Gemini models. + * ... + */ +export const stripReasoningFromMessagesForGemini = ... + /** * Completes any incomplete tool calls in messages with a timeout result. * This prevents "Tool result is missing" errors when resuming after a preemptive timeout. */ export const completeIncompleteToolCalls = ...
🧹 Nitpick comments (1)
lib/api/chat-handler.ts (1)
437-446: Remove the overly broad "google" model check.The
includes("google")check is unnecessary and misleading. Thethought_signaturerequirement is specific to Gemini models, not all Google models. Since the function being called isstripReasoningFromMessagesForGemini, the model detection should reflect this:Suggested fix
const isGeminiModel = - configuredModelId.includes("gemini") || - configuredModelId.includes("google"); + configuredModelId.includes("gemini");
Problem
Two related issues when using Gemini 3 with thinking mode:
1.
thought_signatureError on RetryWhen retrying a conversation that had tool calls, Gemini rejects with:
Root Cause: Gemini 3 with thinking mode requires
thought_signatureto be passed back with tool calls. We don't store these signatures in the database, so old messages cause this error.2. Duplicate Messages on Preemptive Timeout
When preemptive timeout triggers, users see both:
Root Cause:
abortController.abort()triggers both the graceful finish reason AND a network error in the useChat hook.Solution
Fix 1: Strip reasoning for Gemini (
lib/utils/message-processor.ts,lib/api/chat-handler.ts)stripReasoningFromMessagesForGemini()functionreasoningandthinkingparts from assistant messages with tool callsmodelId.includes("gemini"))Fix 2: Hide error on graceful timeout (
app/components/Messages.tsx)MessageErrorStatewhenfinishReason === "timeout"Test Plan
thought_signatureerrorFiles Changed
lib/utils/message-processor.ts- Added reasoning stripping functionslib/api/chat-handler.ts- Apply stripping for Gemini modelsapp/components/Messages.tsx- Hide error state on graceful timeout