{"slug": "kill-the-loop-why-while-true-is-not-reliability", "title": "Kill the Loop: Why `while true` Is Not Reliability", "summary": "A developer building agentproto argues that while-true loops give agents persistence but not correctness, and that unsupervised loops self-reinforce errors rather than self-correct. The post warns that terminal exit conditions are fragile and that the most dangerous failures are invisible to any single moment, requiring trajectory-level checks instead.", "body_md": "Disclosure up front: I build\n\n[agentproto], which runs\n\nchecksinsidean agent's loop rather than only at the end. Everything about\n\nwhy that matters you can verify without me — the sources are named and dated,\n\nand I'll concede where the plain loop is exactly right. Corrections welcome,\n\nfile an issue.\n\nYou gave your agent a loop, closed the laptop, and went to bed.\n\nThe whole pitch of the overnight loop is that it keeps going. `while true; do`\n\n— it wakes back up every time it stalls,\n\ncat prompt.md | claude -p; done\n\nre-reads the plan, and grinds on until a checklist is green. You come back to a\n\nfinished feature and a clean exit code. Sometimes that's a miracle. Sometimes\n\nit's a very tidy way to have built the wrong thing four hundred times.\n\nThe one idea, if you remember nothing else:\n\nA loop gives your agentpersistence, not correctness.And a wrong turn, held\n\nwith conviction and looped, is just a faster way to be wrong.\n\nA loop is a liveness guarantee. It promises the process will keep running; it\n\npromises nothing about whether the process is pointed the right way. Those are\n\ntwo different properties, and the whole overnight-autonomy genre quietly conflates\n\nthem. \"It's still going\" feels like \"it's still on track\" at 2am. It isn't.\n\nGeoffrey Huntley named the mechanism precisely when he described the Ralph\n\ntechnique as *a deterministic loop wrapped around a non-deterministic model* —\n\nthe bet being that repeated attempts converge on a working solution. That bet is\n\nreal, and often it pays. But convergence has a direction, and the loop doesn't\n\nsupply it. The loop supplies fuel.\n\nWhy the direction can be wrong.Each Ralph iteration starts with a fresh\n\ncontext window but inherits all prior work from the filesystem — code, commits,\n\nnotes — which it treats as ground truth and builds on (Sid Bharath,\"the2026). That's the strength on a good\n\ndumbest smart way to run coding agents,\"\n\nrun. On a bad one, iteration two builds on iteration one's mistake, iteration\n\nthree trusts both, and the error stops looking like a bug and starts looking\n\nlike the codebase.\n\nSo an unsupervised loop doesn't *self-correct*. It *self-reinforces*. It pays\n\ncompound interest on your first wrong turn — confidently, on a timer, with every\n\npass making the mistake more load-bearing and more expensive to unwind. **The\nscariest output of a runaway loop isn't a crash. It's a green checkmark on top of\na bad foundation.**\n\n\"Fine,\" you say, \"I gated it — the loop only exits when the tests pass and it\n\nprints `COMPLETE`\n\n.\" Good instinct, wrong position. A terminal gate fires after\n\nthe loop has already burned the budget and stacked the tower. By the time your\n\nend-of-run check has an opinion, the wrong thing is built, tall, and load-bearing.\n\nAnd the completion signal you're trusting is more fragile than it looks.\n\nThe exit condition is a suggestion, not a safety mechanism.A completion\n\npromise is typically a static exact-match string with no OR conditions — so it\n\ncan silently never fire if the wording drifts. The thing that actually bounds a\n\nrunaway loop is theiteration cap; long loops can plausibly cost $30–150 in\n\nAPI spend, so you never run one without one (The AI Agent Factory, 2026).\n\nRead that again: the mechanism keeping your loop from running forever is a\n\ncounter, not a judgment. It stops the spend. It doesn't check the work.\n\nThe deeper problem is that the failures that matter most are *invisible to any\nsingle moment* — including the last one. Apollo Research, whose Watcher tool\n\nTwo failure shapes, two different checks.Some failures live in a single\n\naction — deleting files, leaking a secret, a force-push — and must be blocked\n\nsynchronously, before execution.Others only emerge over many turns — scope\n\ncreep, a confidently wrong diagnosis, premature \"done\" claims — and no single\n\naction reveals them; they have to be judged over thetrajectory\n\n([Apollo Research],\n\n2026). A terminal gate sees exactly one moment. The drift that sinks you lives\n\nin the shape it can't see.\n\nHere's the one question that sorts every autonomous setup. **When does your loop\ncheck its work — only at the very end, or partway through?** If the only\n\nRun the honest audit on your own harness. Between kickoff and the final green\n\ncheck, how many times does something *other than the agent* look at where it's\n\ngoing? For most overnight loops the answer is zero — the agent grades its own\n\nprogress every iteration, and a generator grading itself is the plateau the whole\n\n[supervision ladder](https://dev.to/agentiknet/your-agent-says-the-tests-passed-it-didnt-run-them-15j) is built to escape.\n\nReceipt from the trajectory list.Apollo's rubric of multi-turn failure\n\nmodes reads like a confession of every bad overnight run: premature completion\n\nclaims without verification, ignoring user corrections, confidently wrong\n\ndiagnoses, scope overreach, fabricated APIs, and — my favorite —repeating aA loop is a machine for\n\nfailing command 3+ times without changing strategy.\n\ndoing that last one at scale.\n\nIf your check lives only at the finish line, the loop's superpower — never giving\n\nup — becomes its failure mode. It will never give up on the wrong path, either.\n\nThe reflex, when a loop misbehaves, is to make it *more* persistent: auto-restart\n\non stall, replay the last message in a fresh session, keep it alive through\n\ncontext overflow and API errors. That's a watchdog, and it's genuinely necessary\n\nplumbing for unattended runs — but it is the exact wrong tool for this problem.\n\nA watchdog keeps the process breathing and says nothing about whether the process\n\nis right. **It will cheerfully restart a wrong loop into producing the same wrong\nanswer until sunrise** — the\n\nAlive ≠ on-track.Health-monitoring harnesses track context usage, idle\n\ntime, and error counts, then act: clear context below a threshold, restart\n\nagents that stall, disable them after N consecutive errors (Claude Code Agent\n\nFarm, 2026). Every one of those signals is aboutliveness. None of them asks\n\nthe only question that matters mid-flight: is this still the right thing to be\n\nbuilding?\n\nSo the fix can't be \"keep it going better.\" It has to be something that can make\n\nit *stop going the wrong way* — partway through, before the tower is tall.\n\nThe check has to move two places at once: *outside* the agent (a different\n\ncontext, ideally a different model — a generator can't be its own skeptic) and\n\n*inside* the timeline (running alongside the loop, not waiting at the exit).\n\nThat's the [ladder's](https://dev.to/agentiknet/your-agent-says-the-tests-passed-it-didnt-run-them-15j) L3/L4 external-judge idea, but\n\napplied *continuously* instead of only at turn-end.\n\nThis is precisely what a trailing monitor does, and Apollo measured the payoff\n\nand its limit in the same breath.\n\nCatch the drift early or don't bother.When a trailing monitor scores a\n\nsession over threshold on scope-overreach or premature-completion, injecting a\n\nshort`system-reminder`\n\n-style nudge —\"you were asked to fix the login bug but— generally steers the agent back.\n\nare now refactoring the session module\"\n\nButeffectiveness drops the further the agent has already committed to the, so the monitor must run frequently enough to catch drift early\n\nwrong path\n\n([Apollo Research],\n\n2026). That sentence is the entire argument for killing the terminal-only gate:\n\nthe redirect that works cheaply at turn three is nearly useless at turn thirty.\n\nThe redirect gets weaker exactly as fast as the loop's confidence gets stronger.\n\nCompound interest, running the other way. **A check that only fires at the end\nisn't a safety net; it's an autopsy.**\n\nAnd because the monitor is a separate context, it can be a separate *provider* —\n\nwhich is a feature, not an accident.\n\nDon't let the agent pick its own referee.Models share blind spots with\n\nthemselves: a monitor from the same family tends to trust the agent's reasoning\n\npatterns — Apollo observed Claude models being too trusting of their own\n\nreasoning, GPT models over-suspicious as graders. Mixing providers across the\n\nmonitoring pipeline yields oversight that doesn't inherit the supervised\n\nagent's biases. The skeptic works best when it isn't the defendant's cousin.\n\nConcretely, the difference is one structural move. Here's the naive loop\n\neveryone starts with — one check, at the very end:\n\n```\n# The terminal-gate loop: blind between iterations\nwhile true; do\n  cat prompt.md | claude -p --dangerously-skip-permissions\n  grep -q \"COMPLETE\" progress.md && break   # the ONLY check, and it's last\n  [ $((i++)) -ge 50 ] && break              # the counter, not a judgment\ndone\n```\n\nEverything between kickoff and `COMPLETE`\n\nis unsupervised. Now put a skeptic\n\n*inside* the timeline — an external monitor that reads the trajectory at every\n\nturn boundary and can halt-and-redirect partway through, even mid-way through a\n\nsub-agent's run:\n\n```\n// A mid-flight monitor: runs alongside, can interrupt — not a watchdog\n{\n  \"sessionId\": \"sess_…\",\n  \"cadence\": \"every-turn\",              // not \"on-exit\"\n  \"monitor\": { \"judge\": {\n    \"adapter\": \"gemini\",                // a DIFFERENT provider than the executor\n    \"prompt\": \"Score scope-overreach, wrong-diagnosis, premature-completion 0–1. Quote the turn.\"\n  }},\n  \"onDrift\": {                          // trajectory failure → steer, early\n    \"above\": 0.6,\n    \"action\": \"nudge\",\n    \"text\": \"You were asked to fix the retry test, not rewrite the queue. Return to the task.\"\n  },\n  \"onIrreversible\": { \"action\": \"block\" } // single dangerous action → stop, synchronously\n}\n```\n\nThat's the reversibility split in config: single dangerous actions get blocked\n\n*before* they run; multi-turn drift gets caught early, while the redirect still\n\nworks. The monitor lives in a daemon, so it keeps checking after your screen\n\nlocks — and because it's an external adapter, it runs on any executor: Claude\n\nCode, Codex, or a cheap GLM/DeepSeek model via Hermes. **The loop keeps its\npersistence; you just stop letting it persist unsupervised.**\n\nThis matters most where the money is. A mixed fleet — frontier model plans, cheap\n\nmodel executes in a loop, [the routing math its own post](https://dev.to/agentiknet/cheaper-per-token-is-not-cheaper-per-outcome-3b9b) —\n\nis where self-reinforcement is cheapest to trigger and most expensive to catch\n\nlate. The $0.10 executor will loop confidently into a wall; something external has\n\nto notice before iteration thirty.\n\nTo be fair to the loop, because fairness is the point: for a low-stakes,\n\ndisposable, sandboxed project, the plain overnight loop is *the right tool.*\n\nSomeone shipped a full prompt-history feature to a React Native app from an\n\n11-task list for about $1, exiting early at iteration 8 on the completion\n\nsentinel — it compiled and worked ([demo talk, 2026](https://www.youtube.com/watch?v=nwbl9tk8vY4)).\n\nWell-scoped, throwaway, checked by real tests: loop away. The trouble starts the\n\nmoment it's code you're accountable for — *\"the loop wrote it\"* has never once\n\nbeen a defense.\n\nSo \"kill the loop\" doesn't mean kill iteration — iteration is how these agents\n\nconverge at all. It means kill the *unsupervised* loop: the one whose only check\n\nsits at the finish line, refueled by a watchdog, grading its own homework every\n\npass. Keep the `while true`\n\n. Just put a skeptic inside it, running alongside,\n\nallowed to interrupt.\n\nBecause a loop, on its own, is confidence with an exit code. Persistence isn't the\n\nsame as being right, and this whole series turns on one question first asked in\n\n[the hub piece](https://dev.to/agentiknet/you-can-parallelize-the-typing-you-cant-parallelize-the-trust-2fkd): when your agent says\n\n\"done,\" what — other than the agent — decided that was true? A loop answers\n\n\"nothing, but enthusiastically.\" The only real answer is to have something that\n\nisn't the agent look at where it's going *before* it gets there.\n\nIf your loop already checks itself mid-flight, or I've mis-drawn where the\n\nterminal gate fails you, tell me where — I'll fix the piece.\n\nTen pieces, one argument. Start anywhere; each one cross-links the rest.\n\n| Piece | The one idea | |\n|---|---|---|\n| 1 |\n|\n\n*Written by the maintainer of agentproto (Apache-2.0, source). Same contract as our /compare page — dated facts, named strengths, corrections by issue. Got something wrong? File an issue.*\n\n*Building agentproto in the open — follow @theagentproto and @agentik_ai on X.*", "url": "https://wpnews.pro/news/kill-the-loop-why-while-true-is-not-reliability", "canonical_source": "https://dev.to/agentiknet/kill-the-loop-why-while-true-is-not-reliability-59fk", "published_at": "2026-07-14 01:36:30+00:00", "updated_at": "2026-07-14 01:57:29.171743+00:00", "lang": "en", "topics": ["ai-agents", "ai-safety", "ai-research", "developer-tools"], "entities": ["agentproto", "Geoffrey Huntley", "Sid Bharath", "Apollo Research", "The AI Agent Factory"], "alternates": {"html": "https://wpnews.pro/news/kill-the-loop-why-while-true-is-not-reliability", "markdown": "https://wpnews.pro/news/kill-the-loop-why-while-true-is-not-reliability.md", "text": "https://wpnews.pro/news/kill-the-loop-why-while-true-is-not-reliability.txt", "jsonld": "https://wpnews.pro/news/kill-the-loop-why-while-true-is-not-reliability.jsonld"}}