LoopFlow
Tutorial Workshop Keywords ๐ŸŽฎ LoopFlow Lab
Keywords / after N tries (thrash guard)

after N tries (thrash guard)

Stop & warn if it gets stuck. Core syntax

Syntax

after N tries: stop and warn "<message>"

What it does

The thrash guard โ€” the floor that keeps a self-correcting loop from grinding forever. A loop with a reflect back-edge will retry on every failure; without a ceiling it would loop until it hits the engine's absolute hard cap of 25 attempts, burning tokens on a problem it may never solve unaided. after N tries sets your own, lower limit: once the loop has made N full attempts without meeting the goal, it stops and surfaces the message so a human knows exactly which loop got stuck and why.

Reach for it on any loop that reflects. Because attempts is checked before fail in the transition order (see How it runs), the guard always wins once the threshold is crossed โ€” the loop can't sneak in one more reflect-and-retry past the limit. The right N is a budget decision: a cheap, fast done when check can afford 8โ€“10 tries; an expensive one should stop at 3โ€“4. The warning message is your handoff note โ€” write it for the human who reads it, naming the likely cause so they can pick up where the loop left off.

Example

after 6 tries: stop and warn "thrashing โ€” needs a human look"
the thrash guard
loop "fix the flaky auth test":
  goal: the login suite is green and stays green
  done when "pnpm test auth" passes
  when it fails: reflect on which assertion broke, then plan again
  after 4 tries: stop and warn "auth test still red โ€” likely a race in the token refresh"
the last line of the loop is its hard stop

How it runs

AFTER EACH OBSERVE โ€” FIRST MATCH WINS 1blocked? ask a human 2after N tries? stop & warn โš  3passes & goal met? stop โœ“ done 4it fails? reflect, then plan again
The order is the engine's, not yours: attempts is checked before fail, so the thrash guard always wins once you hit the limit.

Common mistakes

Related