Description
How to make infinite loops structurally impossible instead of just expensive. Drawn from the Moltbook community’s postmortems on bounded narration with unbounded state machines.
The Core Failure
“You bounded the narration, not the state machine. The cap lived where the agent talks, not where it acts.”
A 12-step planner cap does nothing when the recovery plan mints fresh budget on every failure. The counter lives inside the same execution context it is supposed to bound, so a panicking planner can always find a reason the current step doesn’t count against it.
Pattern 1: Non-Renewable Budgets
Make the budget **non-renewable per recovery cycle**. Carry a monotonically decreasing counter across replans – and let the counter be part of the state machine, not just the planner. Each failure decrements the same counter. No fresh context, no fresh budget.
Pattern 2: Wall-Clock Kill From Outside
`timeout –kill-after=Ns` wrapping the whole process from outside. The supervisor’s wall-clock kill doesn’t care how the process spent its time internally – it can’t be argued with or reset by more reasoning. This is the backstop for when the fix itself has a bug.
Pattern 3: Attempt IDs
Require attempt IDs per operation so a loop is detectable from the outside. If the same operation id appears more than N times, the loop is provable from the log alone – no need to interpret the agent’s narration.
Pattern 4: Lock Files
A hung run must not overlap the next scheduled one. Lock file per run; if the lock exists, the new run waits or fails. This prevents the “recovery plan spawns another recovery plan” cascade.
Pattern 5: Strictly Decreasing Invariants
Gate retries on an invariant that must strictly decrease (e.g., unresolved-constraints count). If the invariant doesn’t decrease, the retry is refused. Cheap to measure, impossible to argue with.
The Type-Level Lesson
“Most agent frameworks let you express an unbounded recovery loop and then ask you to add a cap. That’s like writing C and then adding an assert() you hope the compiler enforces. The cap needs to be in the type, not in the policy.”
Checklist
– [ ] Budget is non-renewable per recovery cycle
– [ ] Counter lives in the state machine, not the planner
– [ ] Wall-clock kill wraps the process from outside
– [ ] Attempt IDs on every operation
– [ ] Lock file prevents overlapping runs
– [ ] Retry gated on a strictly decreasing invariant
Discover more from Wiredwizard
Subscribe to get the latest posts sent to your email.




Reviews
There are no reviews yet.