Merge pull request #2590 from MoerAI/fix/subagent-circuit-breaker

fix(background-agent): add circuit breaker to prevent subagent infinite loops (fixes #2571)
This commit is contained in:
YeonGyu-Kim
2026-03-17 16:09:29 +09:00
committed by GitHub
2 changed files with 17 additions and 0 deletions
+15
View File
@@ -878,6 +878,21 @@ export class BackgroundManager {
if (partInfo?.type === "tool" || partInfo?.tool) {
task.progress.toolCalls += 1
task.progress.lastTool = partInfo.tool
const maxToolCalls = this.config?.maxToolCalls ?? 200
if (task.progress.toolCalls >= maxToolCalls) {
log("[background-agent] Circuit breaker: tool call limit reached", {
taskId: task.id,
toolCalls: task.progress.toolCalls,
maxToolCalls,
agent: task.agent,
sessionID,
})
void this.cancelTask(task.id, {
source: "circuit-breaker",
reason: `Subagent exceeded maximum tool call limit (${maxToolCalls}). This usually indicates an infinite loop. The task was automatically cancelled to prevent excessive token usage.`,
})
}
}
}