Skip to content

feat: failure caps to prevent runaway replan loops#9

Open
Savolent wants to merge 1 commit intovcarl:mainfrom
Savolent:stability-failure-caps-upstream
Open

feat: failure caps to prevent runaway replan loops#9
Savolent wants to merge 1 commit intovcarl:mainfrom
Savolent:stability-failure-caps-upstream

Conversation

@Savolent
Copy link
Copy Markdown
Contributor

Summary

When subagent steps fail repeatedly, the state machine now blocks replanning with exponential backoff to prevent burning tokens on the same failing approach.

Changes

  • state-machine.ts: Add consecutiveFailuresRef and replanBlockedUntilTickRef
  • After each subagent evaluation, track whether the plan was cleared (failure) or succeeded
  • After 5+ consecutive failures, block replanning for failures × 4 ticks (max 60)
  • Reset counter on success or lifecycle reset (e.g. character death)
  • Applied in both state-change handler and tick handler

Motivation

Without this, a stuck agent replans every tick, generating a new plan that hits the same wall, burning API tokens on a loop that never resolves. The failure cap gives the agent a cooldown period, and the escalating backoff prevents rapid cycling.

Test plan

  • npx nx run @roci/core:build passes (verified)
  • Agent with a repeating failure stops replanning after 5 failures
  • Counter resets when a step succeeds
  • Lifecycle reset clears the failure state

🤖 Generated with Claude Code

When a subagent step fails, the state machine now tracks consecutive
failures. After 5+ consecutive failures, replanning is blocked for an
increasing number of ticks (failures × 4, max 60 ticks). This prevents
stuck agents from burning tokens replanning the same failing approach
every tick.

The failure counter resets on any successful step or lifecycle reset.
Applied in both the state-change handler and tick handler.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant