-
Notifications
You must be signed in to change notification settings - Fork 2.2k
fix: prevent token burning when Roo gets stuck in error loops #8150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- 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
There was a problem hiding this 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 |
There was a problem hiding this comment.
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`, |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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() | ||
}) | ||
}) | ||
}) |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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.
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
consecutiveMistakeGuidanceCount
to track how many times guidance has been requestedmaxConsecutiveMistakeGuidance
limit to 3 attempts2. Progressive Feedback
3. Automatic Abort
4. Proper Reset Mechanism
resetConsecutiveMistakeCounts()
method5. Enhanced Debugging
Testing
Task.tokenBurning.spec.ts
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 inTask.tokenBurning.spec.ts
.consecutiveMistakeGuidanceCount
andmaxConsecutiveMistakeGuidance
toTask
to limit guidance requests to 3.resetConsecutiveMistakeCounts()
.Task.ts
.Task.tokenBurning.spec.ts
for counter initialization, reset, guidance increment, and abort conditions.This description was created by
for edde377. You can customize this summary. It will automatically update as commits are pushed.