fix(ai-gemini): read/write thoughtSignature at Part level for Gemini 3.x#459
fix(ai-gemini): read/write thoughtSignature at Part level for Gemini 3.x#459pemontto wants to merge 3 commits intoTanStack:mainfrom
Conversation
Gemini 3.x models emit thoughtSignature as a Part-level sibling of functionCall (per @google/genai Part type), not nested inside functionCall. The adapter was reading from functionCall.thoughtSignature (which does not exist in the SDK types) and writing it back nested, causing the API to reject subsequent tool-call turns with 400 INVALID_ARGUMENT: "Function call is missing a thought_signature". Read side: check part.thoughtSignature first, fall back to functionCall.thoughtSignature for Gemini 2.x compatibility. Write side: emit thoughtSignature as a Part-level sibling of functionCall instead of nesting it inside. Closes TanStack#403 Related: TanStack#218, TanStack#401, TanStack#404
|
Caution Review failedAn error occurred during the review process. Please try again later. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughUpdates Gemini adapter and tests to read Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
|
Re: the pre-merge check about #403 scope. This PR fixes the server-side adapter (the The client-side |
|
Can confirm this also fixes the issue we were experiencing missing thought signature |
| (part as any).thoughtSignature || | ||
| (functionCall as any).thoughtSignature || |
There was a problem hiding this comment.
why are these cast to any? can we update the sdk or whatever else is required to make this typesafe (I'm aware it was cast before as well below)
|
View your CI Pipeline Execution ↗ for commit 48cf4a2
☁️ Nx Cloud last updated this comment at |
|
View your CI Pipeline Execution ↗ for commit 48cf4a2
☁️ Nx Cloud last updated this comment at |
Summary
Gemini 3.x models emit
thoughtSignatureas a Part-level sibling offunctionCall(per the@google/genaiParttype definition), not nested insidefunctionCall. TheFunctionCallinterface has nothoughtSignatureproperty at all.The adapter was:
functionCall.thoughtSignature(wrong location, doesn't exist in SDK types)functionCall(wrong location, API ignores it there)This causes Gemini 3.x to reject subsequent tool-call turns with:
The
@google/genaiPart type (for reference)Changes
processStreamChunks): readspart.thoughtSignaturefirst, falls back tofunctionCall.thoughtSignaturefor Gemini 2.x compatibilityformatMessages): emitsthoughtSignatureas a Part-level sibling offunctionCallinstead of nesting it insideTest plan
thoughtSignaturefrom Gemini 3.x streaming response and round-trips it at the Part levelfunctionCall.thoughtSignaturefor Gemini 2.x wire formatgemini-3.1-pro-previewandgemini-3.1-flash-lite-previewsessions (multi-turn tool calling with thinking enabled)Closes #403
Related: #218, #401, #404
Summary by CodeRabbit