Skip to content

fix: validate Gemini thinkingLevel against model capabilities and handle empty streams#11303

Merged
hannesrudolph merged 3 commits intomainfrom
fix/gemini-thinking-level-validation
Feb 8, 2026
Merged

fix: validate Gemini thinkingLevel against model capabilities and handle empty streams#11303
hannesrudolph merged 3 commits intomainfrom
fix/gemini-thinking-level-validation

Conversation

@hannesrudolph
Copy link
Collaborator

@hannesrudolph hannesrudolph commented Feb 8, 2026

Summary

Fixes the "Provider ended the request: Gemini generate context stream error: No output generated" error when using gemini-3-pro-preview (and similar effort-based Gemini models).

Two bugs were identified and fixed:

  1. getGeminiReasoning() sent unsupported thinkingLevel values to the API — It read settings.reasoningEffort directly without validating against the model's supportsReasoningEffort array. A stale setting like "medium" from a different model would be forwarded to gemini-3-pro-preview which only supports ["low", "high"], causing the API to return an empty stream.

  2. GeminiHandler.createMessage() had no guard against empty streams — When the AI SDK threw NoOutputGeneratedError (from await result.usage), it was caught by the generic error handler and surfaced as the cryptic "No output generated" error with no actionable guidance.

Changes

  • src/api/transform/reasoning.ts: getGeminiReasoning() now validates selectedEffort against the model's supportsReasoningEffort array; falls back to model.reasoningEffort when the user's stored effort isn't in the supported set
  • src/api/providers/gemini.ts: GeminiHandler.createMessage() tracks whether text content was yielded (hasContent flag); yields an informative message on empty streams; wraps await result.usage in try-catch to handle NoOutputGeneratedError gracefully
  • src/api/transform/__tests__/reasoning.spec.ts: 5 new test cases covering array validation, fallback behavior, and edge cases
  • src/api/providers/__tests__/gemini.spec.ts: 3 new test cases covering empty stream handling, NoOutputGeneratedError suppression, and re-throw when content exists

Important

Fixes unsupported thinking levels and empty stream errors in Gemini models by validating efforts and improving error handling.

  • Behavior:
    • getGeminiReasoning() in reasoning.ts now validates selectedEffort against supportsReasoningEffort and defaults to model.reasoningEffort if unsupported.
    • GeminiHandler.createMessage() in gemini.ts tracks content with hasContent flag and handles NoOutputGeneratedError by yielding an informative message.
  • Tests:
    • Added 5 test cases in reasoning.spec.ts for effort validation and fallback behavior.
    • Added 3 test cases in gemini.spec.ts for empty stream handling and error suppression.

This description was created by Ellipsis for 63425e0. You can customize this summary. It will automatically update as commits are pushed.

…dle empty streams

getGeminiReasoning() now validates the selected effort against the model's
supportsReasoningEffort array before sending it as thinkingLevel. When a
stale settings value (e.g. 'medium' from a different model) is not in the
supported set, it falls back to the model's default reasoningEffort.

GeminiHandler.createMessage() now tracks whether any text content was
yielded during streaming and handles NoOutputGeneratedError gracefully
instead of surfacing the cryptic 'No output generated' error.
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. bug Something isn't working labels Feb 8, 2026
@roomote
Copy link
Contributor

roomote bot commented Feb 8, 2026

Rooviewer Clock   See task

All previously flagged issues have been addressed. No new issues found.

  • hasContent flag in GeminiHandler.createMessage() only tracks "text" chunks, missing tool-call responses -- a tool-call-only response would incorrectly trigger the "empty response" warning
Previous reviews

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

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Feb 8, 2026
…TODO

The array validation fallback in getGeminiReasoning() now only triggers
when the selected effort IS a valid Gemini thinking level but not in
the model's supported set. Values like 'none' (explicit no-reasoning
signal) are no longer overridden by the model default.

Also adds a TODO for moving the empty-stream message to i18n.
…warning

Tool-only responses (no text) are valid content. Without this,
agentic tool-call responses would incorrectly trigger the empty
response warning message.
@hannesrudolph hannesrudolph merged commit 12cddc9 into main Feb 8, 2026
10 checks passed
@hannesrudolph hannesrudolph deleted the fix/gemini-thinking-level-validation branch February 8, 2026 05:25
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Feb 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working lgtm This PR has been approved by a maintainer size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants