transition2.aiStart a project

AI Reliability & Operations

Watching Agent Fleets

Agents leave orphan processes, unbacked-up logs and full disks behind. A small read-only watcher and a copy-only backup with a freshness check catch them before you delete anything.

Eric MacDougall ·

Answer first

Watching a fleet of agents needs two small pieces that, by design, never delete anything. The first is a read-only watcher that runs on a timer, checks for the usual trouble (disk, crashes, leftover processes, stale checkouts, silent owners), and keeps one deduplicated alert per problem in a fixed-size ring that still works when the disk is full. The second is a copy-only backup of agent logs with a freshness marker, so that "may I delete these logs?" has a mechanical answer: only if the last successful backup is recent. Add an opt-in cleanup tool for orphan processes that needs an explicit target.

Why agents need a watcher

Agents start dev servers, browsers and test runs, then end without stopping them. Sessions accumulate transcripts and logs that later look like clutter. A person notices when the laptop swaps or a disk fills, which is late. A watcher that reports and never acts is safe to run unattended; a person or a guarded tool does the cleanup. For the guards on the stopping side, see Guard Hooks for Agent Shells.

The watcher: read-only, deduplicated

In the open-source agent harness, the watcher runs every ten minutes from a user-level timer (launchd on macOS, a systemd timer on Linux) and runs at least eight checks (the code docstring lists eight, the documentation lists more): disk, units, crashes, processes, delivery checkouts, drift, a coding-agent check and liveness. Per the documentation, it never deletes, stops or reclaims anything and its only writes are its own state, its ring and a heartbeat; we did not audit that.

How alerts stay useful:

  • One alert per problem. An alert is keyed by host, source and key. It is raised once, raised again only when its severity changes, and cleared once.
  • Downgrades wait. A downgrade must hold for two runs before it is announced; an escalation is announced at once.
  • A failing check keeps its alerts. If a check itself errors, the alerts it had raised stay; an error is not a clearance.
  • A ring on disk that cannot fill it. Events go to a preallocated file of 1,024 slots of 1,024 bytes, written in place and flushed, which by design (read from the source, not tested here) lets it work on a full disk. Old events are overwritten, and any active alert that is overwritten is raised again. The active set is injected into the context of new agent sessions.
  • Liveness reuses the owner-silence rule that the owner list uses: 30 and 60 minutes.
  • Delivery checks want the checkout on the main branch and clean, and read it without taking locks.

Any other tool can write to the same ring with an emit command that takes host, source, event, severity, key and message, and an unknown severity is refused.

Orphans

A separate small program, netwatch, lists orphaned or runaway development processes and reports network latency and talkers. Agents read netwatch orphans --json before handoff. Its cleanup option is opt-in, needs an explicit target, re-checks each process and sends only a polite terminate signal. The lesson labs did not install or run it, because its installer downloads a release archive, so we rely on the harness documentation for this part.

Backups: copy first, delete never

Logs are the evidence for everything an agent did. The backup in this harness is built so it cannot make things worse:

  • Only copies. Its commands copy and list; none delete, sync or purge on the remote (rclone copy is the primitive).
  • Changed files are moved aside under a dated versions folder on the remote instead of overwritten. Local deletions do not propagate, so a deleted transcript stays on the remote.
  • Credential-named files are excluded by a pattern file, and the script refuses to run if that file lacks required patterns. Secrets pasted into transcripts cannot be found by name; encryption at rest is the stated control, and we did not test it.
  • A success marker is written only after the important sources copied cleanly, and a skipped run never writes success.
  • Restore is a copy into an empty directory, refuses live trees and non-empty targets, and compares the result with the live files.

The freshness check turns the marker into a rule. Its exit codes are 0 fresh, 1 stale, 2 missing or invalid (a future-dated marker is invalid) and 3 for a stale bulk tier. The alert text says not to delete or prune logs until the status is fresh. A standing watcher repeats the check, because a check that only runs at session start fires too rarely: it writes an alert line only when the verdict changes, or hourly while it stays bad.

What we ran

From our lesson labs: Python 3.12.3, rclone 1.60 and rsync, a throwaway home directory, synthetic logs, and a local directory standing in for the remote. No cloud account and no network. First toys with planted bugs that must each fail the suite:

Ran 11 tests in <t>s

OK
mutant EXCLUDE: FAILED (failures=1)
mutant VERSIONS: FAILED (errors=1)
mutant SYNC: FAILED (errors=1)
mutant MARKER: FAILED (failures=1)
mutant FUTURE: FAILED (failures=1)
mutant LIVE: FAILED (failures=1)
mutant EMPTY: FAILED (failures=1)
mutant VERIFY: FAILED (failures=1)
Ran 9 tests in <t>s

OK
mutant VALIDATE: FAILED (failures=1)
mutant WRAP: FAILED (failures=2)
mutant ACTIVE: FAILED (failures=1)
mutant HYSTERESIS: FAILED (failures=1)
mutant DEDUP: FAILED (failures=2)
mutant SEVERITY: FAILED (failures=2)
mutant CLEAR: FAILED (failures=2)
mutant ERRORED: FAILED (failures=1)
mutant REASSERT: FAILED (failures=1)

Then the real backup script and checker at commit 504d930:

== run 1: copy to a local directory standing in for the remote
log-backup.sh exit: 0
credential-named file copied: no
fresh
check exit: 0
== run 2: a local file is truncated, the remote keeps the old bytes under versions/
log-backup.sh exit: 0
remote copy now: 8 bytes
old copy size: 24 bytes
== run 3: a local file is deleted, the remote copy stays (copy only, no delete or sync)
log-backup.sh exit: 0
session2 on the remote: still there
== restore into an empty scratch directory and compare with the live tree
restore exit: 0
restore into a live tree: exit 2, nothing created: yes
restore into a non-empty directory: exit 2
restore: --into must be an empty directory
== freshness: what the check says when the evidence is old, absent or from the future
stale (max age 1 second): exit 1
no marker: exit 2
future-dated marker: exit 2
== backup_watch.py: a standing alert, because the session-start check only fires at session start
fresh marker: exit 0
old marker: exit 1
BACKUP ALERT code=1 transcripts=stale bulk=fresh
same verdict again: exit 1, new stderr bytes: 0
alert log events: ['recovered', 'alert']
after a new backup: exit 0
alert log events: ['recovered', 'alert', 'recovered']

And the real watcher, with one delivery checkout in a scratch repository and no alert sink configured, so nothing was posted:

== config: the defaults that matter, and no sink
host: lab | disk warn/high/critical: 85 92 97
liveness silent/high minutes: 30 60
== run 1: a delivery checkout that is off main and dirty
ops_watch.py run exit: 0
high delivery:<T>/deliv
checkout untouched by the watcher: yes
ring events for the delivery key: ['raise']
== run 2: same condition, no new alert
exit: 0
ring events for the delivery key: ['raise']
== run 3: back on main and clean, the alert clears once
exit: 0
active delivery alerts: 0
ring events for the delivery key: ['raise', 'clear']
== emit: any other tool can write a transition to the same ring
emit exit: 0
warning lab:demo
after clear: 0 active
emit with an unknown severity: exit 2
== the ring never grows: 1100 events in, same size out
ring size before: 1048576 bytes, after: 1048576 bytes, slots: 1024
slots holding an event: 1024 | sequence numbers span: 1024 | oldest events overwritten: True
== install and uninstall: dry runs unless --apply
would write <T>/home/.config/systemd/user/ops-watch.service
would write <T>/home/.config/systemd/user/ops-watch.timer
would run systemctl --user daemon-reload
would run systemctl --user enable --now ops-watch.timer
would run systemctl --user disable --now ops-watch.timer
would run systemctl --user stop ops-watch.service

Not run: a real cloud remote with its rate limits, the scheduler units themselves, the desktop notification, the bulk tier, the other seven watcher checks (they ran, but their results depend on the machine, so we claim nothing about them), netwatch, and the alert sinks. The downgrade delay, the ring re-assertion and the errored-check rule are shown only in the toy and are read from the source.

Decision framing

The watcher costs a timer and a few kilobytes of state. The backup costs storage and a remote. Both pay for themselves the first time an agent leaves a runaway process or someone wants to prune old logs, and neither is worth much on a single short-lived sandbox. The watcher does not clean anything up; that is deliberate.

Risks and limits

  • A watcher only sees what its eight checks look at. Silence is not proof that all is well.
  • The backup is as good as its remote. We did not test a real remote, and encryption of transcripts at rest is a control we did not exercise.
  • Retention is a separate decision: the backup script never prunes versions, so the versions folder grows without bound until you decide a policy.
  • The threat model is careless agents, not adversaries. An agent that can edit the watcher or the marker can defeat them.

FAQ

What should you monitor when many AI agents run on one machine?
Leftover or runaway processes, disk space, crashes, stale checkouts that are off the main branch or dirty, services that should be running, and whether anyone has gone silent. Start with checks that only read, and make the alert path work even when the disk is full.
Why should an agent log backup be copy-only?
Because a backup that can delete or sync deletions can destroy the evidence it protects. A copy-only backup keeps files that were later deleted locally and moves changed files aside under a dated folder instead of overwriting them.
How do you know a backup is fresh enough to delete the originals?
Write a success marker only after every important source was copied cleanly, and check its age before any cleanup. A missing, old or future-dated marker should mean the logs are not backed up.
How do you avoid alert floods from a watcher?
Key each problem by host, source and key. Raise it once, raise again only when severity changes, and clear it once. Require a downgrade to hold for two runs before announcing it, so a flapping condition does not alternate.

Sources