fix: resolve Google Gemini 3 'Invalid Input' error on tool calls#35
fix: resolve Google Gemini 3 'Invalid Input' error on tool calls#35sichengchen merged 3 commits intomainfrom
Conversation
Gemini 3 models require thoughtSignature on all functionCall parts in conversation history. Without explicit thinking config, signatures may be missing, causing 400 "Invalid Input" on replay. - Enable thinking for Gemini 3 in ModelRouter.getStreamOptions() - Add retry logic (max 2) with exponential backoff for transient errors (429, 500, 503, thought_signature) - Log error metadata (model, messages, tools) on stream failures - Sanitize message history before retry to remove corrupted entries Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1d2acc96f3
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (attempt <= MAX_STREAM_RETRIES && isRetryableError(errorMsg) && !ac?.signal.aborted) { | ||
| // Don't push the error message into history — it would corrupt the conversation | ||
| // Sanitize history in case the error was caused by malformed messages | ||
| this.messages = sanitizeHistoryForRetry(this.messages); |
There was a problem hiding this comment.
Rebuild stream context after sanitizing retry history
When a retryable provider error occurs, sanitizeHistoryForRetry assigns a new array to this.messages, but the retry loop keeps reusing the context object that was created before the loop. Because context.messages still points to the old array, retries resend the unsanitized history, so failures like Gemini thought_signature errors can repeat on every attempt instead of recovering. This affects any path that relies on history sanitization before retry.
Useful? React with 👍 / 👎.
Summary
thinking: { enabled: true }for Gemini 3 models ingetStreamOptions()so thought signatures are reliably generated on function calls — fixes the400 Invalid Input/thought_signatureerrorTest plan
bun run typecheck— clean (only pre-existing@chat-adapter/telegrammodule error)bun run lint— cleanbun test— 709 pass, 9 skip, 1 fail + 1 error (both pre-existing)gemini-3-flash-preview🤖 Generated with Claude Code