fix: surface Gemini blocked/empty response reasons instead of generic error#12046
Draft
roomote-v0[bot] wants to merge 1 commit intomainfrom
Draft
fix: surface Gemini blocked/empty response reasons instead of generic error#12046roomote-v0[bot] wants to merge 1 commit intomainfrom
roomote-v0[bot] wants to merge 1 commit intomainfrom
Conversation
… error When the Gemini API returns a non-STOP finishReason (SAFETY, RECITATION, PROHIBITED_CONTENT) and no content was produced, throw a descriptive error with the actual finish reason instead of silently yielding nothing and falling into the generic "no assistant messages" error path. Also handle reasoning-only responses (thinking models like gemini-3.1-pro-preview that return only reasoning without actionable text/tool calls) by yielding a placeholder text so downstream retry logic can re-prompt the model. Closes #12045
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.
Summary
This PR attempts to address Issue #12045. Feedback and guidance are welcome.
Problem
When the Gemini API returns an empty or blocked response (e.g., due to safety filters, recitation checks, or reasoning-only output), the handler silently produces no output. This causes
Task.tsto fall into the generic "The language model did not provide any assistant messages" error path, giving no useful information about what actually went wrong.Changes
1. Surface non-STOP finishReason in
src/api/providers/gemini.tsAfter the stream completes, if the Gemini API returned a non-STOP/non-MAX_TOKENS
finishReason(such asSAFETY,RECITATION,PROHIBITED_CONTENT) and no content was produced, throw a descriptive error with the actual finish reason instead of silently yielding nothing.2. Handle reasoning-only responses in
src/api/providers/gemini.tsWhen a thinking/reasoning model (like gemini-3.1-pro-preview) returns only reasoning content without actionable text or tool calls, yield a placeholder text chunk so that the downstream "no assistant messages" check is not triggered, allowing the retry logic to re-prompt the model.
Tests
Added 7 new test cases covering:
All existing tests continue to pass.
Interactively review PR in Roo Code Cloud