fix: always replace reasoning.encrypted with skip_thought_signature_validator for Gemini #10759
+322
−17
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.
Summary
Fix "Thought signature is not valid" error for Gemini 3 models via OpenRouter.
PostHog Error: https://us.posthog.com/project/135196/error_tracking/019bc2a3-6975-7fb2-b140-c06babfb57ae
Problem
Users were encountering
ApiProviderError: "Unable to submit request because Thought signature is not valid"when using Gemini 3 models (likegoogle/gemini-3-flash-preview) via OpenRouter with native tool protocol.Root Cause
The OpenRouter handler was only injecting
skip_thought_signature_validatorwhen NO existingreasoning.encryptedblocks were present. However, signatures from previous API sessions are always invalid - they're tied to the specific session that generated them.When conversation history contained old
reasoning.encryptedblocks from a previous Gemini response, the code skipped injection and sent the old (invalid) signature to Gemini, causing the 400 error.Solution
Changed the logic in
openrouter.tsto always replace existingreasoning.encryptedblocks withskip_thought_signature_validatorinstead of only injecting when missing:Related
Tests Added
4 new tests covering:
skip_thought_signature_validatorfor Gemini with tool_calls historyreasoning_detailswhile replacing encrypted onesCloses COM-493
Important
Fixes invalid thought signature errors in Gemini 3 models by replacing
reasoning.encryptedwithskip_thought_signature_validator.openrouter.ts, always replacereasoning.encryptedwithskip_thought_signature_validatorfor Gemini models to prevent invalid signature errors.reasoning.encryptedblocks, ensuring they are replaced.reasoning_detailswhile replacing encrypted ones.openrouter.spec.tsfor injectingskip_thought_signature_validatorwith tool_calls history.This description was created by
for 7059bdb. You can customize this summary. It will automatically update as commits are pushed.