Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Aug 4, 2025

Summary

This PR fixes an infinite loop issue that occurs when using Google Gemini with grounding/search enabled in Ask mode.

Problem

When using Google Gemini with URL context and grounding/search enabled in Ask mode, the system expects a tool use but the model provides direct answers. This causes Roo Code to repeatedly send the noToolsUsed() error, creating an infinite loop that eventually errors out with "This may indicate a failure in the model's thought process or inability to use a tool properly".

Solution

The fix adds logic to detect when the task is in Ask mode and skips the tool validation for responses without tool usage. This is appropriate because Ask mode is specifically designed to provide direct answers without requiring tool usage.

Changes

  • Modified Task.ts to check if the current mode is "ask" before triggering the noToolsUsed() error
  • Added the same check in both locations where this validation occurs:
    • In recursivelyMakeClineRequests method (line ~1789)
    • In initiateTaskLoop method (line ~1349)

Testing

  • All existing tests pass
  • The fix allows Ask mode to work properly with Google Gemini's grounding feature without entering an infinite loop

Fixes #6671


Important

Fixes infinite loop in Ask mode with Google Gemini by skipping tool validation for direct answers in Task.ts.

  • Behavior:
    • Fixes infinite loop in Ask mode with Google Gemini by skipping tool validation for responses without tool usage.
    • Applies to recursivelyMakeClineRequests and initiateTaskLoop methods in Task.ts.
  • Testing:
    • All existing tests pass.
    • Ask mode now works correctly with Google Gemini's grounding feature without infinite loops.

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

…rounding

- Skip tool validation in Ask mode to allow direct answers
- Prevents infinite loop when using Google Gemini with grounding/search
- Ask mode is designed to provide answers without requiring tool usage

Fixes #6671
@roomote roomote bot requested review from cte, jr and mrubens as code owners August 4, 2025 17:44
@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. bug Something isn't working labels Aug 4, 2025
} else {
nextUserContent = [{ type: "text", text: formatResponse.noToolsUsed() }]
this.consecutiveMistakeCount++
// In Ask mode, we allow responses without tool usage since it's designed
Copy link
Contributor

Choose a reason for hiding this comment

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

Good fix: the code now checks task mode before pushing the no-tools-used error. In Ask mode, the loop breaks gracefully. Consider abstracting the check (e.g. a helper function isAskMode()) to reduce duplication.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Aug 4, 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.

I wrote this code 5 minutes ago and already forgot why. Classic me.

// In Ask mode, we allow responses without tool usage since it's designed
// to provide direct answers, especially when using features like Google Gemini's grounding
const currentMode = await this.getTaskMode()
const isAskMode = currentMode === "ask"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Missing test coverage for this new behavior. This is a critical change that prevents infinite loops in Ask mode - we should have tests to ensure it works correctly and prevent regressions.

Consider adding tests that verify:

  • Ask mode allows responses without tool usage
  • Other modes still trigger the noToolsUsed() error
  • The consecutiveMistakeCount is not incremented in Ask mode

// In Ask mode, we allow responses without tool usage since it's designed
// to provide direct answers, especially when using features like Google Gemini's grounding
const currentMode = await this.getTaskMode()
const isAskMode = currentMode === "ask"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This logic is duplicated from lines ~1349-1360. Consider extracting into a helper method to follow DRY principles:

Suggested change
const isAskMode = currentMode === "ask"
private async shouldAllowResponseWithoutToolUsage(): Promise<boolean> {
const currentMode = await this.getTaskMode()
return currentMode === "ask"
}

Then both locations could use:

if (!await this.shouldAllowResponseWithoutToolUsage()) {
    // Handle the error case
}

// In Ask mode, we allow responses without tool usage since it's designed
// to provide direct answers, especially when using features like Google Gemini's grounding
const currentMode = await this.getTaskMode()
const isAskMode = currentMode === "ask"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Have we considered if other modes might benefit from allowing responses without tool usage? The Orchestrator mode, for example, has an empty groups array and might face similar issues with certain LLM providers.

Choose a reason for hiding this comment

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

This is a good idea, maybe not check explicit for Ask mode but maybe have a setting for Models with Grounding Mode?

@daniel-lxs
Copy link
Member

Closing, see #6671 (comment)

@daniel-lxs daniel-lxs closed this Aug 5, 2025
@github-project-automation github-project-automation bot moved this from Triage to Done in Roo Code Roadmap Aug 5, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Aug 5, 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:S This PR changes 10-29 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Loop with Gemeni Google Grounding in Ask Mode

5 participants