roadmap BUILT

226. qemu-bounded.sh leaves an emulator behind, and the next run blames the wrong thing

A QEMU left behind by a gate holds its images and a host core until something kills it.

Both shapes, because they answer different failures. The leak is prevented everywhere anything can prevent it, and the one case macOS cannot prevent now arrives as a sentence instead of a mystery.

The leak was reproduced before it was fixed, which is the part worth keeping. Start a bounded run, signal the wrapper and its detached killer the way pkill -f does, and the emulator is inherited by pid 1 and runs until somebody notices. helpers/qemu-bounded-selftest.sh is that reproduction as an artifact. Run against the pre-226 script it fails three of its seven cases (both orphan cases and the lock diagnostic). Against the current one it passes all seven.

What the killer does now. It had one reason to fire, the bound, which bounds a run that is allowed to finish and does nothing about a run whose wrapper is killed. It has three:

  1. the bound expired, unchanged in effect;
  2. the wrapper is gone, noticed by a kill -0 poll once a second, which is what covers a SIGKILLed wrapper, a dead session and a closed terminal, none of which run a trap anywhere;
  3. the killer itself was signaled (TERM or HUP), whose trap kills the child on the way out, so the one process that knows the child's pid never takes that knowledge with it.

SIGINT is deliberately not in that trap list. A shell puts an asynchronous subshell's SIGINT to ignore before the subshell can trap it. Listing it would be a lie that reads as coverage. Ctrl-C is covered better anyway: the wrapper dies of it, the killer survives it, and reason 2 fires within a second.

The early-reader property was verified rather than assumed, since the block named it as a real requirement. A real QEMU writing continuously into a pipe whose reader takes five lines and exits is still killed at the bound. So is the milestone 38 (filesystem throughput) property beside it. A fast child in a pipeline returns at once rather than at the end of the bound, and it now does so because the killer's output goes to /dev/null instead of into the pipe. That closes the bug at the root rather than at the cleanup.

And the macOS constraint was tested, not reasoned about. perl -e 'alarm 3; exec @ARGV' against the installed qemu-system-aarch64 still leaves it running eight seconds later.

The lock diagnostic. On a failing exit, and only then, the wrapper runs lsof over the image paths in its own command line and prints the pid, ppid, start time and command of anyone holding one for writing. The write filter is not a refinement, it is the difference between a diagnostic and noise. script/test's three legs share one read-only OVMF firmware file, so reporting readers would print a holder for every green run that overlapped another lane's x86_64 gate. It reports rather than kills, and says to walk the parent chain up first, because a QEMU whose parent is a live harness is somebody's gate rather than a leak (AGENTS.md, 2026-08-15).

In brief. helpers/qemu-bounded.sh exists because timeout(1) does not exist on macOS and perl -e 'alarm N; exec @ARGV' does not work on QEMU, which installs its own SIGALRM handler and swallows the alarm. The script uses SIGTERM, which QEMU honors, and detaches its killer so it survives a pipeline whose reader exits early.

It does not survive its target detaching. When the EL2 lane's run was killed, the emulator survived with ppid 1. It then held the write lock on nifefs-blank.img, and the next boot failed with Failed to get "write" lock, which names nothing about the real cause. The lane lost time to it twice before recognizing the shape.

Why this is worth a block rather than a habit

AGENTS.md already narrates this failure from the other direction, at length: killing a loop script does not kill its descendants, so a check honestly reporting "no qemu" is followed by a command that finds one. Its advice is to ask who holds the file (lsof target/nifefs.img) rather than whether a process matches a name, and to kill the tree at its root.

That advice is rung four, and this is the instance where rung four failed in the ordinary way. A lane that had read the file still lost time, because the symptom arrives on a later run as a lock error about a file, with nothing pointing at a leaked process.

Every lane uses this script. A leak here is not one lane's problem, it is the next lane's mysterious failure, and this project runs many lanes.

What it needs

An emulator that cannot outlive the thing that started it, or a failure that names the cause when one does. Two shapes, and the block picks neither:

These are not exclusive and the second is worth having regardless, because a lock can be held by something this project did not start.

BUGS

Follow-on

Index row

Both shapes. The killer had one reason to fire, the bound, which bounds a run allowed to finish and does nothing about a run whose wrapper is killed. The emulator was then inherited by pid 1, held a disk image's write lock, and billed a later run with QEMU's Failed to get "write" lock, which names a file and no process. It now also polls its parent once a second (covering a SIGKILLed wrapper and a dead session, neither of which runs a trap) and traps TERM and HUP. The one process knowing the child's pid does not take it along. SIGINT is deliberately absent: a shell puts an async subshell's SIGINT to ignore before it can be trapped, so listing it would read as coverage and be a lie. The leak was reproduced before and after and helpers/qemu-bounded-selftest.sh is that reproduction as an artifact: three of seven cases fail on the old script, none on the new. The early-reader property and milestone 38's fast-child property were both verified against a real QEMU, and perl's alarm is still swallowed, so the premise holds. What macOS cannot prevent (SIGKILL to the killer; no PDEATHSIG) gets the other half instead. A failing run runs lsof over its own image paths and names the holder's pid, ppid and start time, and says to walk the parent chain up first.