fix: preserve reasoning.text type in consolidateReasoningDetails for Gemini models#11650
Draft
roomote[bot] wants to merge 1 commit intomainfrom
Draft
fix: preserve reasoning.text type in consolidateReasoningDetails for Gemini models#11650roomote[bot] wants to merge 1 commit intomainfrom
roomote[bot] wants to merge 1 commit intomainfrom
Conversation
…Gemini models Fixes two bugs causing assistant content[] to be stripped on Turn 2 for google/gemini-3.1-pro-preview via OpenRouter: 1. consolidateReasoningDetails() used a shared type variable across all entries in a group. When reasoning.text and reasoning.encrypted entries shared the same index, the text entry type was overwritten to "reasoning.encrypted". Now tracks types separately for text vs encrypted entries. 2. The corrupted block filter dropped any reasoning.encrypted entry without a data field, including mislabeled text entries that had a text field. Now only drops entries that have neither data nor text. Closes #11629
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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: #11629
Description
This PR attempts to address Issue #11629. Feedback and guidance are welcome.
Two bugs in
consolidateReasoningDetails()insrc/api/transform/openai-format.tscause assistantcontent[]to be stripped on Turn 2 forgoogle/gemini-3.1-pro-previewvia OpenRouter:Bug 1 (secondary, root cause): Shared
typevariable mislabelsreasoning.textasreasoning.encryptedWhen a group contains both a
reasoning.textentry and areasoning.encryptedentry at the same index, the consolidation loop used a single sharedtypevariable. The last entry's type overwrote earlier ones, so the text entry was emitted withtype: "reasoning.encrypted"instead oftype: "reasoning.text".Fix: Track
textTypeseparately from encrypted entry types. When emitting the consolidated text entry, use the type derived from text-bearing entries only, and correct any mislabeledreasoning.encryptedback toreasoning.text.Bug 2 (primary, cascading): Corrupted block filter drops mislabeled text entries
The filter at line 53 dropped any entry with
type === "reasoning.encrypted" && !detail.data. This caught the mislabeled text entries from Bug 1, which had atextfield but nodatafield. With all reasoning_details dropped,sanitizeGeminiMessages()sawhasReasoningDetails=falseand dropped all tool_calls, producing the emptycontent[]that triggers the "no assistant messages" error.Fix: Only drop entries that have neither
datanortext-- truly corrupted blocks with no usable content.Test Procedure
consolidateReasoningDetailscovering:reasoning.text+reasoning.encryptedat same index preserves correct typessanitizeGeminiMessagesreproducing the exact issue scenariocd src && pnpm vitest run api/transform/__tests__/openai-format.spec.tsPre-Submission Checklist
Documentation Updates
Additional Notes
Files modified:
src/api/transform/openai-format.ts-- fixconsolidateReasoningDetails()type tracking and corrupted block filtersrc/api/transform/__tests__/openai-format.spec.ts-- 4 new regression testsInteractively review PR in Roo Code Cloud