published · 6 min read
A Long-Running Agent Needs Three Clocks
What kept an eight-day coding-agent loop alive, and which parts didn't need a model at all.

An AI agent drafted this from my projects, and another agent checked the draft claim by claim against the code and the run records or briefs that were kept. The projects and opinions are mine.
When people talk about long-running coding agents, they mostly talk about the agent: the model, the prompt, the context window. I ran an agent loop for eight days to build a font, and what kept it running was three timers, at three very different prices.
Clock 1: every two minutes, no model
The first clock was a shell script in a tmux session, and it made no LLM or API calls. Every two minutes it checked the box and did whatever was mechanical:
- Push commits that hadn't been pushed, and merge if another writer had moved
main. - Resume the agent if its process had died or the loop had stopped with an error.
- Restart it after 90 minutes with no new commit on the builder's clone (
WIP:checkpoints with failing tests and other writers' commits merged into it reset that clock), or if it sat at an empty prompt for four checks in a row. - Kill leaked Python kernels older than three hours.
- Prune old render files when the disk passed 85% and again at 93%.
- Clear idle scratch folders, because
/tmpon that box was RAM.
None of those decisions need a model, but they need care: on 27 and 29 October, by the loop's notes, the prune deleted a folder a running job was still writing into. They need to happen reliably and often and to keep happening
when the model quota runs out, which is why this clock must not depend on a model. It ran in tmux, so it died with whatever killed tmux: on 25 October an out-of-memory cascade took the tmux server down and the watchdog with it. The probe's "tmux session … missing" alerts caught it about eight minutes later, and Claude Code reran the boot script. The box had no systemd; on one that has it, a unit with Restart= brings a dead watchdog back without waiting for a probe.
Google's SRE book describes a mechanical job going wrong at scale: automation read an empty machine list as "everything" and erased the disks across its CDN, and the team then added more sanity checks, including rate limiting.
Push, resume, restart: those three were in the first version, before the loop had run at all, and all the other duties on the watchdog's list were added after something broke. After the box's 79 GB disk filled and file writes failed, the 85% rule went in on 24 October, pruning review renders older than 12 h. Restart got an exception on 30 October, for a job that ran 55 min at full CPU with no commit. A note on that change says "the stall rule would have restarted the loop, and killed the climb, at 90 min." From then on that rule logs and waits while a busy job under 6 hours old is running under the loop.
Clock 2: every twenty minutes, cheap
A probe that ran from my laptop was the second clock. It built the latest commit in a scratch
clone and printed a single line: items passed, ranks, glyph count, research cards, minutes since
the last commit, quota, memory, and the supervisor's latest verdict. Counts such as items, glyphs
and cards carried a delta against the previous probe, and the rest were current values. Below that
line came one ALERT: line per problem, if there were any.
Without an alert, I got the status line and that was all. An alert meant diagnose it (status script, debug
log, the tmux pane), fix it without asking, then report. A push notification went out only for
something that couldn't be fixed.
A probe that writes a paragraph on a 20-minute timer gets ignored by the second day. A probe that writes
a single line, and adds more only when something is wrong, gets read.
A handful of plain shell lines make up the alert half of the probe. These are the real ones, trimmed:
[ "$running" != true ] && echo "ALERT: loop not running (stop_reason=$reason)"
[ "$idle" = yes ] && [ "$running" = true ] && echo "ALERT: omp idle at the prompt while the loop is running"
[ "$commit_age" -ge 90 ] && echo "ALERT: no commit for ${commit_age}m"
[ "$mem" -ge 12000 ] && echo "ALERT: memory ${mem}MB"
for s in ralph watchdog heartbeat librarian librarian2; do
tmux has-session -t $s 2>/dev/null || echo "ALERT: tmux session $s missing"
done
An alert here is a single condition and a sentence a person can act on. Scores and models don't come into it.
Clock 3: hourly or slower, judgment
For the third clock, a supervisor agent ran at intervals of an hour or two. It had read-only tools that could read files and search the repo, and that was all. Opening the rendered specimen images was required, and what came out was a short critique that the builder read first whenever an iteration started. It was blunt, and good at naming problems the builder couldn't see from inside a task: a stall, a metric being gamed, a claim that didn't match the evidence. Because it was read-only, it couldn't edit anything; its only lever was the critique the builder read first. All it could do was talk. It flagged an item as stalled for hours and nothing changed, because a critique isn't a diagnosis. I'm still working on that part. In this run the diagnoses came from Claude Code on my laptop, as owner directives with measurements. Pairing the supervisor with an automatic diagnosis pass is the obvious next step, so a "stalled" flag turns into measurements the builder can act on.
The split by cost
| Clock | Interval | Uses a model? | Does |
|---|---|---|---|
| Watchdog | 2 min | No | push, resume, restart, prune |
| Probe | 20–30 min | Yes: Claude Code ran it and fixed alerts | one status line, alerts, fixes |
| Supervisor | 1–2 h | Yes | critique the work itself |

In my setup Claude Code ran the probe, so a model woke at 20-minute intervals, but it only did real work on an alert. A plain cron job could run that same probe without a model at all. If you collapse these clocks into a single loop, you get one of two bad outcomes: either you call a model every two minutes to decide whether to push a commit, or you check on the agent's judgment as rarely as you can afford to call the model, and the mechanical failures pile up in between.
Restarting a stuck session
At one point the builder's session log had grown to 52 MB and the agent was stuck on an item. Killing the process and resuming the loop on the same item started a fresh session at 0.19 MB. Asking the agent to wrap up early is no substitute: on day two that request was rejected six times and stopped the loop. If an agent is stuck, make that restart the watchdog's job, with a limit: mine allowed one restart per 15 minutes and three per iteration, then left it for a human. An Erlang supervisor also caps restarts, though per time window, and it restarts at once. Kubernetes gives a related warning about automatic restarts: a liveness probe has to indicate truly unrecoverable failure, and incorrect ones can lead to cascading failures.

For any job longer than an afternoon
For any agent job that runs longer than an afternoon:
- Write the dumb watchdog first: a shell loop that pushes, restarts and prunes, without a model.
- Add a probe that prints a single status line and adds lines only for alerts.
- Only then add a model-based reviewer, read-only, on a slow clock.
The whole run is written up in "I Let an Agent Loop Draw a Font for Eight Days".