fix: preserve id for reasoning.encrypted blocks in OpenAI message transform #10310
+152
−1
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.
Related GitHub Issue
Closes: #10307
Description
This PR attempts to address Issue #10307 where Gemini 3 models on OpenRouter fail with a 400 error when using tools. The error occurs because Gemini models require thought signatures (
reasoning.encryptedblocks) to be preserved and linked to their respective tool calls via theidfield.The Problem:
In
src/api/transform/openai-format.ts, ALLidfields were being stripped fromreasoning_details:However:
reasoning.textandreasoning.summarytypes, theidis only used internally for accumulation and should be strippedreasoning.encryptedtypes, theidis the tool call ID that links the thought signature to the function call and must be preservedThe Fix:
The
reasoning_detailsmapping now only strips theidfield for non-encrypted types, preserving it forreasoning.encryptedblocks:This fix was tested locally by @leonardas103 and confirmed to solve the issue.
Test Procedure
Added unit tests in
src/api/transform/__tests__/openai-format.spec.tscovering:reasoning.textblocks have theiridstrippedreasoning.encryptedblocks preserve theiridreasoning_detailswithoutidfield are handled correctlyreasoning_detailswork as expectedRun tests:
All 17 tests pass including the 4 new reasoning_details tests.
Pre-Submission Checklist
Documentation Updates
Additional Notes
Feedback and guidance are welcome.