Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Aug 12, 2025

Fixes #6986

Problem

When using Gemini 2.5 Pro, approximately every 2nd response was being interrupted with the error:

"Unexpected API Response: The language model did not provide any assistant messages"

This occurred when Gemini was in "thinking" mode but didn't produce any actual response content, only reasoning/thinking content.

Solution

  1. Track content yielding: Added hasYieldedContent flag in the Gemini handler to track whether any actual text content (not just reasoning) was yielded
  2. Ensure non-empty response: If only reasoning content was provided, yield an empty text chunk to ensure assistantMessage is not empty
  3. Improve error messaging: Enhanced the error message in Task.ts to be more informative for Gemini-specific issues

Testing

  • Added comprehensive test suite for thinking-only response scenarios
  • All existing Gemini tests continue to pass
  • New tests cover:
    • Thinking-only responses
    • Mixed thinking and content responses
    • Empty stream handling

Impact

This fix ensures that Gemini 2.5 Pro users won't experience interruptions when the model is in thinking mode, providing a smoother experience when using tool functions.


Important

Fixes Gemini 2.5 Pro thinking-only response issue by ensuring non-empty assistant messages and improving error handling.

  • Behavior:
    • Adds hasYieldedContent flag in GeminiHandler in gemini.ts to track if actual content is yielded.
    • Yields empty text chunk if only reasoning content is provided to prevent empty assistantMessage.
    • Enhances error message in Task.ts for Gemini-specific issues.
  • Testing:
    • Adds gemini-thinking-only.spec.ts to test thinking-only, mixed content, and empty stream scenarios.
    • Ensures all existing Gemini tests pass.
  • Impact:
    • Prevents interruptions for Gemini 2.5 Pro users during thinking mode, ensuring smoother tool function usage.

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

… message error

- Add tracking for whether any actual content (not just reasoning) was yielded in Gemini handler
- Yield empty text chunk if only reasoning content was provided to ensure assistantMessage is not empty
- Improve error message in Task.ts to be more informative for Gemini-specific issues
- Add comprehensive tests for thinking-only response scenarios

Fixes #6986
@roomote roomote bot requested review from cte, jr and mrubens as code owners August 12, 2025 13:21
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. bug Something isn't working labels Aug 12, 2025
Copy link
Contributor Author

@roomote roomote bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewing my own code is like debugging in a mirror - everything looks backwards but the bugs are still mine.


// If we only got reasoning content and no actual text, yield an empty text chunk
// This ensures the assistant message won't be empty
if (!hasYieldedContent) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add a comment here explaining why we yield an empty text chunk? Something like:

Suggested change
if (!hasYieldedContent) {
// If we only got reasoning content and no actual text, yield an empty text chunk
// This ensures the assistant message won't be empty and prevents the
// "language model did not provide any assistant messages" error
if (!hasYieldedContent) {
yield { type: "text", text: "" }
}

This would help future maintainers understand the reasoning behind this fix.

@@ -0,0 +1,244 @@
// npx vitest run src/api/providers/__tests__/gemini-thinking-only.spec.ts
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice comprehensive test coverage for the thinking-only scenarios! Consider whether these tests should be integrated into the main gemini.spec.ts file for better organization, or if keeping them separate is intentional for clarity. Both approaches have merit - separate files make the specific issue easier to find, while integration keeps all Gemini tests together.

let errorMessage = "Unexpected API Response: The language model did not provide any assistant messages."

if (isGeminiModel) {
errorMessage +=
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The enhanced error message is helpful! Could we make it even more specific by mentioning this often happens with tool function calls? Something like:

Suggested change
errorMessage +=
if (isGeminiModel) {
errorMessage +=
" This can occur with Gemini models when they are in 'thinking' mode but don't produce any actual response content, often during tool function calls. The model may need to be prompted again or the request may need to be retried."
} else {

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Aug 12, 2025
@daniel-lxs
Copy link
Member

Closing for now until we get more information about this issue

@daniel-lxs daniel-lxs closed this Aug 13, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Aug 13, 2025
@github-project-automation github-project-automation bot moved this from Triage to Done in Roo Code Roadmap Aug 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Frequent "Error: unexpected API Response" Google Gemini

4 participants