Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Dec 23, 2025

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.encrypted blocks) to be preserved and linked to their respective tool calls via the id field.

The Problem:
In src/api/transform/openai-format.ts, ALL id fields were being stripped from reasoning_details:

baseMessage.reasoning_details = messageWithDetails.reasoning_details.map((detail: any) => {
    const { id, ...rest } = detail
    return rest
})

However:

  • For reasoning.text and reasoning.summary types, the id is only used internally for accumulation and should be stripped
  • For reasoning.encrypted types, the id is the tool call ID that links the thought signature to the function call and must be preserved

The Fix:
The reasoning_details mapping now only strips the id field for non-encrypted types, preserving it for reasoning.encrypted blocks:

if (detail.type === 'reasoning.encrypted') {
    return detail
}
const { id, ...rest } = detail
return rest

This fix was tested locally by @leonardas103 and confirmed to solve the issue.

Test Procedure

  1. Added unit tests in src/api/transform/__tests__/openai-format.spec.ts covering:

    • reasoning.text blocks have their id stripped
    • reasoning.encrypted blocks preserve their id
    • reasoning_details without id field are handled correctly
    • Messages without reasoning_details work as expected
  2. Run tests:

    cd src && npx vitest run api/transform/__tests__/openai-format.spec.ts
  3. All 17 tests pass including the 4 new reasoning_details tests.

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
  • Scope: My changes are focused on the linked issue (one major feature/fix per PR).
  • Self-Review: I have performed a thorough self-review of my code.
  • Testing: New and/or updated tests have been added to cover my changes (if applicable).
  • Documentation Impact: I have considered if my changes require documentation updates (see "Documentation Updates" section below).
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Documentation Updates

  • No documentation updates are required.

Additional Notes

Feedback and guidance are welcome.

…nsform

Gemini 3 models require the id field to be preserved for reasoning.encrypted
blocks to link thought signatures to function calls. Without this id, the API
returns an error about missing thought_signature in functionCall parts.

The id field is now only stripped for non-encrypted reasoning types (like
reasoning.text and reasoning.summary), which are used internally for accumulation.
@roomote
Copy link
Contributor Author

roomote bot commented Dec 23, 2025

Rooviewer Clock   See task on Roo Cloud

Review complete. No issues found.

The fix correctly preserves the id field for reasoning.encrypted blocks (required by Gemini 3 for linking thought signatures to tool calls) while stripping it for other reasoning types. All 17 tests pass, including 4 new tests that comprehensively cover the change.

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Dec 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels.

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

[BUG] Gemini 3 on OpenRouter API tool result error - All Tools Broken

3 participants