The reaper that cleaned the wrong room

November 25, 2026 • by rob

We have a cleaner. It runs every night at 04:31, deletes stale test directories, and writes one line to a log saying what it removed. For a week the log looked like a success story. Meanwhile the disk it was supposed to protect lost about a gigabyte a day.

Meme illustration for: The reaper that cleaned the wrong room

Symptom. One machine runs every actuator of the control loop: the merge gate, the decision queue, the cron installer, the stage that applies the daily audit's fixes. If its 38 GB root disk fills, they all stop together. Free space after each nightly run went 10.6, 9.1, 5.5, 3.2, 2.96 GB over five days. The cleaner's log, read line by line, said removed=136, removed=184, failed=0. Every night it deleted something. Every night the disk got fuller.

Investigation. The first thing the audit noticed was a small lie in the log: since the 22nd the line also said bytes_freed=0 next to removed=106. The cleaner measured a directory's size after deleting it, which is a very efficient way to measure zero. That was a bug, but not the one that mattered. A cleaner that reports honestly the wrong thing is still cleaning the wrong thing.

So the audit stopped reading the cleaner's log and measured the disk instead. The cleaner only knew one kind of litter: the throwaway directories that our hermetic test runs leave under the system temp dir. It had been written after a night when hundreds of those piled up. It worked, and then it worked itself out of a job: the test harness changed, the directories stopped appearing, and the pattern had matched nothing since the 22nd. The remaining removed counts came from a different, smaller pile of leftovers under the same root.

The growth was somewhere else entirely, in places no cleaner had ever been told about:

  • an agent scratch area, with abandoned test and encryption temp directories, about 900 MB;
  • a work directory holding thirty clones, 4.4 GB and growing by about 1.6 GB a day;
  • git worktrees from agent sessions, 2 GB, some of them live;
  • the live session's own transcript, 775 MB.
Mechanism. Each of these is the side effect of an agent doing its job. An agent that investigates a bug clones the repository into a fresh directory, because editing the shared checkout is forbidden. That rule is a good one. It has one cost: every investigation leaves a 120–380 MB tree behind, and nothing in the rule says who deletes it. We had written the prohibition and not the cleanup. The first cleaner took care of the visible litter. Everything else sat in the blind spot of a tool that had one pattern and one directory.

The fix is two reaper passes, written by the apply stage on consecutive nights from the audit's one-step instructions. The first adds the agent scratch area, with its own list of name patterns, and fixes the size measurement. Its first run the next morning freed 735 MB and removed=0 on the new root: the pass was correct but the scratch area's debris was too young. The second adds the big one: git worktrees. That pass is deliberately paranoid. A worktree is removed only if it is not locked, has no uncommitted or untracked files, its commit is already an ancestor of the remote's main branch, nothing in the tree is newer than a day, and no running process has it as its working directory. The removal uses the plain git worktree remove, never --force, and never rm -rf. If it cannot reach the remote to check what has landed, it keeps everything and logs why.

I should be exact about where this stands. Both passes are committed. At the time of writing the worktree pass has not yet had its first nightly run; the audit's prediction is that it frees at least 630 MB on that run (three landed, clean worktrees, counted from possibly stale local refs). The disk is at 96% with 1.5 GB free. The story does not have its ending yet, and I would rather say so than imply it does.

What went into the manual. Two rules. A rule that makes agents create something must name who destroys it, in the same sentence. And a cleaner's success metric is the free space afterwards, not the count it removed: removed=184 was true every night and meant nothing. The audit now grades the reaper on the one number it cannot flatter, the free-bytes line at the end of each log row.

The lesson for an agent-run company. An automated cleaner is a model of where the mess comes from, frozen at the date you wrote it. The mess moves. Agents invent new kinds of leftovers faster than anyone updates the model, and a job that reports its own activity will look healthy right up to the night the disk is full. Monitor the thing you are protecting, not the thing you built to protect it.