Skip to content

Conversation

roomote[bot]
Copy link

@roomote roomote bot commented Sep 18, 2025

Summary

This PR fixes issue #8148 where Roo would stop working and continue burning tokens when encountering repeated errors.

Problem

When Roo makes consecutive mistakes (e.g., not using tools properly), it asks for user guidance. However, if it continues to fail even after receiving guidance, it could get stuck in an infinite loop, continuously consuming API tokens without making progress.

Solution

Implemented a multi-layered token burning prevention mechanism:

1. Dual Counter System

  • Added consecutiveMistakeGuidanceCount to track how many times guidance has been requested
  • Set maxConsecutiveMistakeGuidance limit to 3 attempts

2. Progressive Feedback

  • Shows attempt count in guidance messages (e.g., "Attempt 2/3")
  • Provides clear indication when the system is struggling

3. Automatic Abort

  • Stops execution after 3 failed guidance attempts
  • Provides helpful error message with actionable suggestions:
    • Providing more specific instructions
    • Breaking down the task into smaller steps
    • Checking for environmental issues

4. Proper Reset Mechanism

  • Added resetConsecutiveMistakeCounts() method
  • Called by successful tool executions to reset both counters
  • Ensures counters reset when progress is made

5. Enhanced Debugging

  • Added logging for mistake and guidance counts
  • Helps track when the system is approaching limits
  • Captures telemetry for token burning events

Testing

  • Added comprehensive test suite in Task.tokenBurning.spec.ts
  • Tests cover initialization, counter resets, guidance increments, and abort conditions
  • Existing tests continue to pass

Impact

This change prevents infinite token consumption while maintaining system functionality. Users will receive clear feedback when Roo is struggling and the system will gracefully abort rather than burning tokens indefinitely.

Fixes #8148


Important

Introduces a mechanism in Task.ts to prevent infinite token consumption by limiting guidance requests and aborting tasks after repeated failures, with tests added in Task.tokenBurning.spec.ts.

  • Behavior:
    • Adds consecutiveMistakeGuidanceCount and maxConsecutiveMistakeGuidance to Task to limit guidance requests to 3.
    • Aborts task after 3 failed guidance attempts with a message suggesting user actions.
    • Resets mistake counters on successful tool execution using resetConsecutiveMistakeCounts().
  • Logging and Telemetry:
    • Logs mistake and guidance counts in Task.ts.
    • Captures telemetry for token burning events.
  • Testing:
    • Adds tests in Task.tokenBurning.spec.ts for counter initialization, reset, guidance increment, and abort conditions.

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

- Add maximum guidance request limit (3 attempts) to prevent infinite loops
- Track guidance count separately from mistake count
- Abort task when guidance limit is exceeded with clear error message
- Add resetConsecutiveMistakeCounts() method to reset both counters
- Update tools to use the new reset method
- Add logging for debugging token burning issues

Fixes #8148
@roomote roomote bot requested review from mrubens, cte and jr as code owners September 18, 2025 14:41
@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Sep 18, 2025
@dosubot dosubot bot added the bug Something isn't working label Sep 18, 2025
@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Sep 18, 2025
Copy link
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.

Reviewed my own code. Found it surprisingly coherent for something I wrote while preventing infinite loops.

consecutiveMistakeCount: number = 0
consecutiveMistakeLimit: number
consecutiveMistakeGuidanceCount: number = 0 // Track how many times we've asked for guidance
maxConsecutiveMistakeGuidance: number = 3 // Maximum times to ask for guidance before aborting
Copy link
Author

Choose a reason for hiding this comment

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

Could this hardcoded limit of 3 guidance attempts be made configurable? Some complex tasks might legitimately need more attempts before we should give up. Consider making it similar to consecutiveMistakeLimit - perhaps maxConsecutiveMistakeGuidance could be passed in TaskOptions?

// We've asked for guidance too many times, abort to prevent token burning
await this.say(
"error",
`I've been unable to proceed despite multiple attempts and guidance. The task appears to be stuck in a loop. To prevent excessive token usage, I'm stopping here. Please review the conversation and consider:\n\n1. Providing more specific instructions\n2. Breaking down the task into smaller steps\n3. Checking if there are any environmental issues preventing progress`,
Copy link
Author

Choose a reason for hiding this comment

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

The error message mentions "environmental issues" but doesn't provide examples. Could we be more specific? For instance: "3. Checking if there are any environmental issues preventing progress (e.g., missing dependencies, file permissions, network connectivity)"

this.consecutiveMistakeGuidanceCount++

// Add exponential backoff message if we've asked before
let guidanceMessage = t("common:errors.mistake_limit_guidance")
Copy link
Author

Choose a reason for hiding this comment

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

Consider extracting this guidance message generation logic into a separate method like generateGuidanceMessage(attemptNumber: number, maxAttempts: number) for better maintainability and testability.

this.consecutiveMistakeCount++

// Log when we're incrementing mistake count for debugging
console.log(
Copy link
Author

Choose a reason for hiding this comment

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

Good addition of debug logging here! Consider including the task mode in the log for better debugging context: [Task#${this.taskId}] Mode: ${this._taskMode}, Consecutive mistake count: ...

consoleErrorSpy.mockRestore()
})
})
})
Copy link
Author

Choose a reason for hiding this comment

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

Consider adding an integration test that simulates the full flow: mistakes → guidance request → user provides guidance → more mistakes → multiple guidance attempts → final abort. This would help ensure the entire mechanism works end-to-end.

}

task.consecutiveMistakeCount = 0
task.resetConsecutiveMistakeCounts()
Copy link
Author

Choose a reason for hiding this comment

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

Good integration point! The reset is called at the right time - after validation but before the actual tool execution. This ensures we only reset when the tool is actually going to do something useful.

@github-project-automation github-project-automation bot moved this from Triage to Done in Roo Code Roadmap Sep 23, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Sep 23, 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
Status: Done
Development

Successfully merging this pull request may close these issues.

roo stops working and burns tokens
2 participants