-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Open
Labels
area:corearea:toolsbugSomething isn't workingSomething isn't workinghas reproHas detailed reproduction stepsHas detailed reproduction stepsplatform:macosIssue specifically occurs on macOSIssue specifically occurs on macOS
Description
Description
A sub-agent (Task tool with subagent_type=general-purpose) got stuck in an infinite loop, repeatedly executing the same failing command approximately 300+ times until it timed out after ~4.6 hours.
What happened
- Launched a background sub-agent to execute multiple tasks (install npm package, create test files, etc.)
- The agent attempted to run
npm install -D @vitest/coverage-v8 - The command likely timed out or failed silently
- Instead of stopping after 2-3 retries, the agent kept retrying the exact same command 300+ times
- Agent finally timed out after consuming ~27 million tokens
Evidence
From the agent output:
[Tool: Bash] {"command":"npm install -D @vitest/coverage-v8","description":"Install vitest coverage dependency","timeout":180000}
[Tool: Bash] {"command":"npm install -D @vitest/coverage-v8","description":"Install vitest coverage dependency","timeout":180000}
[Tool: Bash] {"command":"npm install -D @vitest/coverage-v8","description":"Install vitest coverage dependency","timeout":180000}
... (repeated 300+ times)
--- RESULT ---
Request timed out
Expected behavior
- Agent should detect repeated failures of the same command
- After 2-3 failed attempts, agent should:
- Try an alternative approach, OR
- Skip the task and continue with others, OR
- Report the failure and stop
Actual behavior
- Agent retried the same command indefinitely
- No circuit breaker or retry limit
- Consumed ~27M tokens before timing out
Environment
- Claude Code CLI
- Model: claude-opus-4-5-20250101
- Date: 2025-12-31
- Platform: macOS Darwin 25.1.0
Impact
- ~27 million tokens consumed unnecessarily
- ~4.6 hours of wasted compute time
- User billed for tokens that provided no value
Suggested fix
Sub-agents should have built-in retry limits:
- Maximum 3 retries for any single command
- Detect identical consecutive commands and break the loop
- Implement exponential backoff or alternative strategies on failure
Request
Please investigate whether token reimbursement is possible for this incident, given the tokens were consumed by a bug in agent behavior rather than productive work.
Metadata
Metadata
Assignees
Labels
area:corearea:toolsbugSomething isn't workingSomething isn't workinghas reproHas detailed reproduction stepsHas detailed reproduction stepsplatform:macosIssue specifically occurs on macOSIssue specifically occurs on macOS