fix: inject thought signatures for Gemini 3 when switching models via LiteLLM #10742
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
When users switch mid-task from Claude (or other models) to Gemini 3/2.5 via LiteLLM, they encounter "Corrupted thought signature" errors. This happens because Gemini 3 validates thought signatures for tool/function calling steps, and conversation history from other models lacks these signatures.
Solution
Implemented thought signature injection using
provider_specific_fields.thought_signatureon tool calls, following LiteLLM's official documentation:provider_specific_fields.thought_signatureof tool callsbase64("skip_thought_signature_validator")- this bypasses validationChanges
isGeminiModel()method to detect Gemini 3.x and 2.5.x models (including provider-prefixed variants)injectThoughtSignatureForGemini()method to inject dummy signaturescreateMessage()to apply injection when targeting Gemini with native tool protocolTest Results
All tests pass (5246 passed).
Fixes: COM-489
Important
Injects thought signatures for Gemini models in LiteLLM to prevent errors when switching models, with new detection and injection methods and comprehensive tests.
isGeminiModel()to detect Gemini 3.x and 2.5.x models inlite-llm.ts.injectThoughtSignatureForGemini()to inject dummy thought signatures for Gemini models.createMessage()to apply thought signature injection for Gemini models with native tool protocol.lite-llm.spec.tsfor Gemini model detection and thought signature injection.createMessage().createMessage()to handle tool protocol resolution and Gemini-specific processing.This description was created by
for d705365. You can customize this summary. It will automatically update as commits are pushed.