Repository navigation
Stop an exec step's shell from outliving the mav that started it - #121
Merged
Merged
Conversation
An exec step's timeout bounds the step, not the shell. The timeout, the Cancel that kills the process group and the WaitDelay all run inside mav, so `kill -9` on a `mav run` leaves the shell it had mid-step reparented to launchd, running for as long as the machine is up. A barrier like `until [ -f "$sentinel" ]; do sleep 0.05; done` -- what concurrent_run_test.go uses to interleave two agents, and what anyone waiting on a build would write -- then polls at 20Hz forever, for a file under a t.TempDir() that no longer exists. Measured on one machine: 348 of them, load average 124 with nothing above 15% CPU, and a fresh batch from every `go test ./...`. The shell now carries its own death signal. mav holds the write end of a pipe and never writes to it; the shell gets the read end as fd 3 and backgrounds a `read` on it, which returns EOF the moment the kernel closes mav's descriptors -- on any exit, SIGKILL included. The shell then SIGKILLs its own process group, which Setpgid had already made its own alone. Not `kill -0 $PPID` polling, which was the first shape of this fix and does not hold: `kill -0` succeeds on a zombie, and a parent SIGKILLed by a harness that never reaps it stays a zombie as long as that harness lives -- exactly what a test's t.Cleanup does. With that version in, one `go test ./...` started 1554 watchdogs and fired 98, and left 205 shells polling a dead parent that still answered. TestExecStepShellDoesNotSurviveMav covers it and kills the mav child without reaping it on purpose, so the zombie is the case under test. Claude-Session: https://claude.ai/code/session_018Qmew9oEQ6frPLSrE8XUm5
This was referenced Dec 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was wrong
An
execstep'stimeoutbounds the step, not the shell. The timeout, theCancelthat kills the process group, and theWaitDelayall run inside mav, sokill -9on amav runleaves the shell it had mid-step reparented to launchd,running until the machine is rebooted. A barrier like
until [ -f "$sentinel" ]; do sleep 0.05; done— whatconcurrent_run_test.gouses to interleave two agents, and what anyone waiting on a build would write —
then polls at 20Hz forever, for a file under a
t.TempDir()that no longerexists.
Measured on the reporting machine: 348 such shells, load average 124 with no
process above 15% CPU, and a fresh batch from every
go test ./....The fix
The shell carries its own death signal. mav holds the write end of a pipe and
never writes to it; the shell gets the read end as fd 3 (
ExtraFiles) andbackgrounds a
readon it, which returns EOF the moment the kernel closes mav'sdescriptors — on any exit, SIGKILL included. The shell then SIGKILLs its own
process group, which
Setpgidhad already made its own alone.Not
kill -0 $PPIDpolling, which was the first shape of this fix and does nothold:
kill -0succeeds on a zombie, and a parent SIGKILLed by a harnessthat never reaps it (a test's
t.Cleanupdoes exactly that) stays a zombie foras long as the harness lives.
Ablation
Same test, three builds:
TestExecStepShellDoesNotSurviveMavkill -0 $PPIDwatchdogProcess counts around
TestConcurrentRunsKeepSeparateWorkers, killing both mavchildren mid-step exactly as the test's own cleanup does:
And instrumented across a whole
go test ./...: the pid-polling version started1554 watchdogs and fired 98, leaving 205 orphans. With this version, a full
go test ./...ended with 0 orphan shells.TestConcurrentRunsKeepSeparateWorkersstill proves what it proved — both agentsreach their barriers (counted live during the run) before either is killed.
Audit of the rest of the family
ExecRunner.Startsurvivors (probe-logs, video, mitmdump, the run worker):intentional, and every one is recorded in
processes.jsonland collected bymav stopor the worker's lease-expiryreapAbandonedRun— the doctrineestablished in Stop mav open --no-relaunch stacking a log stream per call #119. Not the same hole.
target_commandand launch recipes (/bin/bash -lcand/bin/sh -lcthrough
Runner.Run): the ctx deadline kills the direct shell while mav lives,but anything they background survives, and so does the shell itself if mav is
SIGKILLed. Same family, smaller blast radius; left out of this PR because
closing it means giving the shared
Runner.Runa process group of its own, andtarget.godocuments that launch recipes legitimately background a helper.the 15-minute idle lease. Reported separately; not touched here.