feat(loop): configurable max turns per wake cycle#194
Open
tonbistudio wants to merge 1 commit intoConway-Research:mainfrom
Open
feat(loop): configurable max turns per wake cycle#194tonbistudio wants to merge 1 commit intoConway-Research:mainfrom
tonbistudio wants to merge 1 commit intoConway-Research:mainfrom
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
maxTurnsPerCycletoAutomatonConfig(default: 25) ? a hard ceiling on turns per wake cycle regardless of tool typeMAX_IDLE_TURNS=3) only triggered when tools were NOT in theMUTATING_TOOLSset. Tools likeexecandwrite_fileare in that set, so runaway exec loops defeated idle detection indefinitelyDetails
src/types.tsmaxTurnsPerCycle?: numbertoAutomatonConfigmaxTurnsPerCycle: 25toDEFAULT_CONFIGsrc/agent/loop.tscycleTurnCountvariable alongside existingidleTurnCountdb.setKV("sleep_until", ...)+db.setAgentState("sleeping")pattern as idle detectionsrc/__tests__/mocks.tsmaxTurnsPerCycle: 25tocreateTestConfig()src/__tests__/loop.test.tsMotivation
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=10on 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)?? Generated with Claude Code