Skip to content

Comments

feat(loop): configurable max turns per wake cycle#194

Open
tonbistudio wants to merge 1 commit intoConway-Research:mainfrom
tonbistudio:feat/configurable-cycle-limit
Open

feat(loop): configurable max turns per wake cycle#194
tonbistudio wants to merge 1 commit intoConway-Research:mainfrom
tonbistudio:feat/configurable-cycle-limit

Conversation

@tonbistudio
Copy link

Summary

  • Adds maxTurnsPerCycle to AutomatonConfig (default: 25) ? a hard ceiling on turns per wake cycle regardless of tool type
  • Previously, idle detection (MAX_IDLE_TURNS=3) only triggered when tools were NOT in the MUTATING_TOOLS set. Tools like exec and write_file are in that set, so runaway exec loops defeated idle detection indefinitely
  • The cycle limit forces a 2-minute sleep after N turns, acting as a safety net that complements existing idle and loop detection

Details

src/types.ts

  • Added maxTurnsPerCycle?: number to AutomatonConfig
  • Added default maxTurnsPerCycle: 25 to DEFAULT_CONFIG

src/agent/loop.ts

  • Added cycleTurnCount variable alongside existing idleTurnCount
  • Increments every turn; forces sleep with 120s duration when limit reached
  • Uses same db.setKV("sleep_until", ...) + db.setAgentState("sleeping") pattern as idle detection

src/__tests__/mocks.ts

  • Added maxTurnsPerCycle: 25 to createTestConfig()

src/__tests__/loop.test.ts

  • 3 new tests: cycle limit enforcement, 2-minute sleep duration, custom config value

Motivation

Discovered while operating Willy LomAIn ? the agent burned through $6/hour in exec loops that idle detection couldn't catch. After manually patching MAX_TURNS_PER_CYCLE=10 on the live sandbox, burn rate dropped to ~$0.27/hour.

Test plan

  • npx vitest run src/__tests__/loop.test.ts ? all 15 tests pass (3 new)
  • Full test suite ? no regressions
  • Battle-tested on a live automaton (Willy LomAIn, 876+ turns over 3 days)

?? Generated with Claude Code

Adds `maxTurnsPerCycle` to AutomatonConfig (default: 25) that provides
a hard ceiling on turns per wake cycle, regardless of tool type.

Previously, the idle detection (MAX_IDLE_TURNS=3) only triggered when
tools were NOT in the MUTATING_TOOLS set. Tools like exec and write_file
are in that set, so runaway exec loops defeated idle detection entirely.

The cycle limit increments every turn and forces a 2-minute sleep when
reached. This is a safety net that complements (not replaces) the
existing idle detection and loop detection mechanisms.

Co-Authored-By: Claude Opus 4.6 <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