fix: handle Gemini 3 Pro reasoning-only and blocked empty responses#11497
fix: handle Gemini 3 Pro reasoning-only and blocked empty responses#11497roomote[bot] wants to merge 1 commit intomainfrom
Conversation
- Surface non-STOP finishReason (SAFETY, RECITATION, etc.) as descriptive errors instead of generic "no assistant messages" when Gemini returns no content - Treat reasoning-only responses (thinking content but no text/tool calls) as transient issues with free retry (no consecutive failure increment) - Auto-retry reasoning-only responses even without autoApproval enabled - Add tests for empty response, reasoning-only, and blocked response scenarios Closes #11492
Reviewed the Gemini handler and Task.ts changes. One issue flagged:
Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues. |
| @@ -3657,12 +3668,18 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike { | |||
|
|
|||
| // Check if we should auto-retry or prompt the user | |||
| // Reuse the state variable from above | |||
| if (state?.autoApprovalEnabled) { | |||
| // For reasoning-only responses, always auto-retry silently since the | |||
| // model clearly attempted to respond (produced thinking content) but | |||
| // just didn't generate actionable output. This avoids bothering the | |||
| // user with retry prompts for transient Gemini 3 Pro behavior. | |||
| if (state?.autoApprovalEnabled || hasReasoningOnly) { | |||
There was a problem hiding this comment.
When hasReasoningOnly is true, consecutiveNoAssistantMessagesCount is never incremented (line 3646) and the auto-retry fires unconditionally (line 3675, || hasReasoningOnly). This means reasoning-only responses bypass both the failure counter and the user-consent prompt, retrying indefinitely with no upper bound. If the model persistently returns reasoning-only responses (the issue reports ~33% failure rate), several consecutive reasoning-only responses would silently consume API credits and spin with exponential backoff but no termination condition. Consider either (a) capping reasoning-only retries to a small fixed count (e.g. 3) before falling through to the user prompt, or (b) still incrementing consecutiveNoAssistantMessagesCount but raising the threshold before showing the error UI.
Fix it with Roo Code or mention @roomote and request a fix.
Related GitHub Issue
Closes: #11492
Description
This PR attempts to address Issue #11492 where Gemini 3 Pro Preview causes provider errors roughly every 2-3 requests. Feedback and guidance are welcome.
Root cause:
gemini-3-pro-previewsometimes returns reasoning/thinking content but no actionable text or tool calls. The existing empty-response detection in Task.ts only checks for text and tool_use content, treating reasoning-only responses as failures. Additionally, non-STOP finish reasons (SAFETY, RECITATION) from Gemini are silently swallowed, giving users no diagnostic information.Changes made:
src/api/providers/gemini.ts: Surface non-STOPfinishReasonas descriptive errors when no content is produced. This gives Task.ts retry logic (and users) a meaningful error message instead of the generic "no assistant messages" error.src/core/task/Task.ts: Handle reasoning-only responses (thinking content present but no text/tool calls) as transient issues:consecutiveNoAssistantMessagesCount(free retry without triggering error UI)autoApprovalEnabled, since the model clearly attempted to respondsrc/api/providers/__tests__/gemini-handler.spec.ts: Added 5 test cases covering:Test Procedure
cd src && npx vitest run api/providers/__tests__/gemini-handler.spec.ts-- all 15 tests passcd src && npx vitest run api/providers/__tests__/gemini.spec.ts-- all 17 existing tests still passPre-Submission Checklist
Documentation Updates
No documentation updates needed. This is an internal behavior fix for Gemini provider error handling.
Start a new Roo Code Cloud session on this branch