feat: include operation context in mistake_limit_reached error message

When the consecutive mistake limit is reached, users now see what operation
Roo was attempting when the failure occurred. This provides better context
for understanding the error.

Changes:
- Add mistake_limit_operation_context translation key to en/common.json
- Add getLastAttemptedOperationContext() helper method to Task class
- Modify mistake_limit_reached handling to prepend operation context

Refs #10855
This commit is contained in:
Roo Code 2026-01-21 22:12:29 +00:00
parent 9ab279ae42
commit 558ecedf6c
2 changed files with 48 additions and 4 deletions

View file

@ -2445,10 +2445,14 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
),
)
const { response, text, images } = await this.ask(
"mistake_limit_reached",
t("common:errors.mistake_limit_guidance"),
)
// Build error message with operation context for better user understanding
const operationContext = this.getLastAttemptedOperationContext()
let errorMessage = t("common:errors.mistake_limit_guidance")
if (operationContext) {
errorMessage = `${t("common:errors.mistake_limit_operation_context", { operation: operationContext })}\n\n${errorMessage}`
}
const { response, text, images } = await this.ask("mistake_limit_reached", errorMessage)
if (response === "messageResponse") {
currentUserContent.push(
@ -4557,4 +4561,43 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
console.error(`[Task] Queue processing error:`, e)
}
}
/**
* Get a human-readable description of the last attempted operation.
* This is used to provide context in the mistake_limit_reached error message
* so users can understand what operation Roo was attempting when it failed.
*
* @returns A descriptive string like "write_to_file for 'path/to/file'" or undefined if no operation found
*/
public getLastAttemptedOperationContext(): string | undefined {
// Look for the last tool_use or mcp_tool_use block in assistantMessageContent
for (let i = this.assistantMessageContent.length - 1; i >= 0; i--) {
const block = this.assistantMessageContent[i]
if (block.type === "tool_use" || block.type === "mcp_tool_use") {
const toolUse = block as import("../../shared/tools").ToolUse | import("../../shared/tools").McpToolUse
const toolName = toolUse.name
// Try to extract a file path from common tool parameters
let filePath: string | undefined
if ("params" in toolUse && toolUse.params) {
// Cast to allow accessing any parameter name
const params = toolUse.params as Record<string, string | undefined>
// Common parameter names for file paths across different tools
filePath = params.path || params.file_path
} else if ("arguments" in toolUse && toolUse.arguments) {
// MCP tools use 'arguments' instead of 'params'
const args = toolUse.arguments as Record<string, unknown>
filePath = (args.path as string) || (args.file_path as string)
}
// Format the operation context string
if (filePath) {
return `${toolName} for '${filePath}'`
}
return toolName
}
}
return undefined
}
}

View file

@ -57,6 +57,7 @@
"cannot_access_path": "Cannot access path {{path}}: {{error}}",
"settings_import_failed": "Settings import failed: {{error}}.",
"mistake_limit_guidance": "This may indicate a failure in the model's thought process or inability to use a tool properly, which can be mitigated with some user guidance (e.g. \"Try breaking down the task into smaller steps\").",
"mistake_limit_operation_context": "While attempting: {{operation}}",
"violated_organization_allowlist": "Failed to run task: the current profile isn't compatible with your organization settings",
"condense_failed": "Failed to condense context",
"condense_not_enough_messages": "Not enough messages to condense context",