REPORT — phase6-supervisor-fixes-2-implementer
STEP: phase6-supervisor-fixes-2 (Phase 6: the sweep-to-quiescence fix — F9)
REV: 2da5a5a9a67336c1b8c9bb1d0f49e703eb32f806   FINAL: 0459c5b5577117a4116890ee0cc356edcf9214ca
CHANGED: scripts/supervise_run.py — the expiry kill is now freeze-and-sweep-to-quiescence. On `subprocess.TimeoutExpired` (`scripts/supervise_run.py:166`) it first freezes the child's process group with one `killpg(SIGSTOP)` (`:193`) and lets the freeze land (`time.sleep(SWEEP_SETTLE)`, `:200`); then it loops up to `SWEEP_PASSES` (=3, `:83`) passes, each of which captures the descendant chain with `_descendants(process.pid)` (`:87`, the same /proc parent-chain walk, which also reaches a sandboxed grandchild in its own session), kills the group with one `killpg(SIGKILL)`, SIGKILLs every surviving captured descendant individually, and re-captures; an empty capture breaks the loop (`:214`), otherwise it settles `SWEEP_SETTLE` (=0.1, `:84`) and sweeps again. The freeze is the structural half the delivered single capture lacked: a process forked between the capture and the group kill is adopted to init at the instant the group kill lands (verified empirically: an orphan's ppid becomes init's pid at its parent's death, even while that parent is an unreaped zombie), so no later walk from the child pid reaches it; SIGSTOP stops the in-group forker, so the capture is stable and the group kill cannot orphan a fork born after it. The budget bounds the loop, not the kill: every pass still signals every captured descendant. What is already adopted out of the tree before the first capture (its parent exited before the deadline) is the sweep's documented boundary. `run_child`'s docstring now states the freeze-and-loop truthfully. No other behaviour changes: the same two recorded subprocess heads, the same single JSON document, the same exit rule, exactly one recorded `--resume` after the sweep, the same misuse fail-closed set.
CHANGED: tests/test_phase6_supervisor.py — a new fixture scenario `racing-fork` (`:183`) and the pin `test_the_deadline_kill_sweeps_a_racing_forker_to_quiescence` (`:491`, F9). The fixture child runs a daemon thread that forks a session-escaped `python -c "time.sleep(60)"` sleeper every ~5ms across a short deadline and records every forked PID to `forked.pid`; the pin drives the supervisor at `--budget 0.4` (`:499`), then reads every recorded PID after the supervisor exits and asserts none is alive (`:511`, `assert not alive`). The deadline is short on purpose: the fork count is deadline-bounded (~50–80 sleepers here), which keeps the corpus module inside a sandboxed run's process budget — an earlier `--budget 2` drive forked ~250 sleepers, and those lingered as zombies in the oracle gate's cgroup, starving a later `ruff` thread spawn with `EAGAIN` and failing `tests/test_static_gates.py`. The module docstring documents the pin and its REV red (`:76`).
VERIFIED: scripts/check-tests --fast — `976 passed, 106 deselected in 106.74s (0:01:46)`, exit 0 (REV's 975 passed plus the racing-fork pin).
VERIFIED: .venv/bin/python -m pytest tests/test_phase6_supervisor.py tests/test_review_phase6_supervisor.py — `13 passed in 14.38s`, exit 0 (eleven delivered pins — the module's ten plus the racing-fork pin — plus the two unedited review probes).
VERIFIED: .venv/bin/python -m pytest tests/test_axis2_robustness.py -m "not slow" — `17 passed, 4 deselected in 4.84s`, exit 0 (the supervisor's invariant battery: the same 17/4 as REV; this step touches no committed module the spend-settle and lock pins read).
VERIFIED: .venv/bin/python -m pytest tests/test_phase3_project_oracle.py — `5 passed in 329.31s (0:05:29)`, exit 0. This is the green run of a lottery: F8 (carried) means the fixture's 60.0s per-check deadline can be exceeded by the corpus's unseeded in-sandbox draws, and before this green run the line redded four times with the F8 signatures (`calibration case 'known-good' classified 'FALSE_SUCCESS'` at `src/orchestrator/experiment_phases.py:265`, and `assert 'CANDIDATE_TIMEOUT' == 'FAIL'` at `tests/test_phase3_project_oracle.py:433`/`:449`); the same signature redded with this step's test module reverted to HEAD (so without the racing-fork pin), which shows the lottery is not this step's.
VERIFIED: scripts/check-static — exit 0. The gated `ruff check --select BLE001,S110 src/orchestrator` prints `All checks passed!`; the advisory run prints `Found 104 errors.` (104, unchanged from REV; neither edited file adds an advisory finding).
VERIFIED: scripts/check-docs — exit 0, prints `376 Total (in 744ms) 174 Unique 376 OK 0 Errors` (the gate's own printed line; counts unchanged from REV's 376/174/376/0).
VERIFIED: scripts/check-scope 2da5a5a9a67336c1b8c9bb1d0f49e703eb32f806 0459c5b5577117a4116890ee0cc356edcf9214ca docs/research/phase6-supervisor-fixes-2-brief.md — exit 0. Prints `claimed: scripts/supervise_run.py tests/test_phase6_supervisor.py`, `tripped: none`, `scope: ok (3 path(s) in 2da5a5a9a67336c1b8c9bb1d0f49e703eb32f806..0459c5b5577117a4116890ee0cc356edcf9214ca)` (the third path is the brief, added under `docs/research/` and allowed implicitly).
VERIFIED: the red evidence at REV, on a scratch tree cut from `2da5a5a` (`git archive 2da5a5a9a67336c1b8c9bb1d0f49e703eb32f806 | tar -x -C /tmp/kilo/f9rev`) with the unfixed supervisor byte-verified first (`git show 2da5a5a:scripts/supervise_run.py | diff - /tmp/kilo/f9rev/scripts/supervise_run.py` — empty) and the delivered test module copied in uncommitted: `.venv/bin/python -m pytest tests/test_phase6_supervisor.py::test_the_deadline_kill_sweeps_a_racing_forker_to_quiescence` — `1 failed in 0.85s`; the failing assertion is the named one: `AssertionError: 6 of 67 forked PIDs survive the supervisor's exit: [2755987, 2755988, 2755989, 2755990, 2755991, 2755992] — the deadline kill does not sweep the racing forker to quiescence` at `tests/test_phase6_supervisor.py:511` (the pin's post-exit forked-PID liveness line, `assert not alive`).
VERIFIED: the sweep-to-quiescence green at FINAL — the pin passes deterministically (3/3 isolated runs plus every full-suite run; the freeze makes the first capture stable, so the loop converges in one or two passes and no forked PID survives).
VERIFIED: the reparented-orphan boundary probed live at FINAL (the SHAPES entry below): the doubly-escaped orphan — a session-escaped middleman spawns a session-escaped `sleep 60` then exits, so the sleeper is adopted by init before the deadline — survives the sweep still adopted out-of-tree (`state=S ppid=3174`, 3/3 runs), so the init-adopted orphan is the documented boundary and is not pinned.
VERIFIED: sandbox safety of the pinned shape — the gate's own sandboxed `check-tests` over the frozen corpus (my modified tree, `limits processes=256, wall 60.0s`) ran the whole suite and printed `773 passed, 87 deselected in 43.47s`, exit 0, no `ruff` `EAGAIN` (the reduced deadline keeps the fork count inside the sandbox's process budget).
NOT VERIFIED: the full `scripts/check-tests` (no `--fast`): the brief's ACCEPTANCE names the `--fast` form, and the work commit's pre-commit hook re-ran the non-slow suite as its own gate before the commit landed (parallel phase `945 passed in 22.84s` over 6 workers, serial phase `31 passed in 11.41s`). The oracle acceptance's repeatability is F8 below (a committed-fixture lottery, carried); the `5 passed` line above is its green run at FINAL.
FINDINGS:
  F9 | SEVERITY: P1 | ORIGIN: CODE | STATE: fixed
  The descendant sweep could not reach a process forked between the chain capture and the group kill, nor one already reparented out of the tree: the group kill kills the forking child, and its surviving children are adopted to init at the instant of that death (a killed-but-unreaped parent's children show ppid=init), where no walk from the child pid reaches them; the review's racing forker left 3 of 331 tail forks alive.
  FIXED: tests/test_phase6_supervisor.py::test_the_deadline_kill_sweeps_a_racing_forker_to_quiescence, `.venv/bin/python -m pytest tests/test_phase6_supervisor.py::test_the_deadline_kill_sweeps_a_racing_forker_to_quiescence` at REV (scratch tree, unfixed supervisor), the named failing assertion `AssertionError: 6 of 67 forked PIDs survive the supervisor's exit` at tests/test_phase6_supervisor.py:511 (`assert not alive`); fixed by the SIGSTOP freeze at scripts/supervise_run.py:193 and the bounded capture-kill-sweep loop at `:201`–`:216`.
  F10 | SEVERITY: P2 | ORIGIN: BRIEF | STATE: fixed
  The brief's fix description is incomplete as written. It says the loop alone ("capture the descendant chain, kill the group with the one `killpg`, SIGKILL each surviving captured descendant individually, then re-capture") makes "the second pass's capture see" the racing tail. Measured by driving three structures against the review's q1d shape: the loop with the group kill in the first pass leaves 6 of 296 tail forks alive, and the loop that keeps the child alive with the group kill last leaves 3 of 362 — because in both the captured tail's parent is killed and the tail is reparented to init, so a re-capture from the child pid is empty. The only structure that both catches the tail and preserves the brief's `Reparented-orphan boundary shape` (the orphan already adopted out-of-tree before the first capture) is to freeze the in-group forker (SIGSTOP) so the capture is stable before the group kill; the subreaper alternative catches the tail but also catches the boundary orphan (measured: it kills the q1e orphan), which would contradict the brief's named boundary.
  FIXED: no regression test — a committed brief's prose has none. The reading taken is the one consistent with the brief's GOAL (the racing forker dies with the deadline) and its named boundary (the init-adopted orphan survives), it is committed at FINAL (0459c5b), and the racing-fork pin at tests/test_phase6_supervisor.py:491 exercises it. Named per the brief's own instruction ("If exactly one reading is consistent, take it and file a FINDING with ORIGIN: BRIEF that names the reading you took").
SHAPES: one shape the suite does not build, probed live at FINAL (the brief's `Reparented-orphan boundary shape`; the `Sweep-to-quiescence shape` is the pinned racing-fork pin, not an unbuilt shape):
  1. The reparented-orphan boundary — a fixture child spawns a session-escaped middleman that spawns a session-escaped `python -c "time.sleep(60)"` and exits, so the sleeper is adopted by init before the deadline. Probed against the fixed supervisor (`--budget 3`): the orphan survives the sweep still adopted out-of-tree (`state=S ppid=3174`, 3/3 runs) — no descendant walk from the child reaches a process that is already init's child at capture time. This is the sweep's documented boundary. The fix's own surface (the merged tree pin's in-group and session-escaped grandchildren, and the child-head pin) is re-driven at FINAL and green in the `13 passed` line above.
TRIPPED: none
PROPOSED ROWS: none
METHOD FRICTION: none
INHERITED:
Nothing in the received set is still open: the brief's INHERITED carried F9 (P1, carried) and F8 (P2, carried). F9 is fixed here — the racing-fork pin at tests/test_phase6_supervisor.py:491 and the sweep-to-quiescence fix at scripts/supervise_run.py:193–:216 — and F8 stays carried, its owner named below. Added by this step, each carried finding with its ID: none (F10 is fixed, not carried).
  F8 (P2, ORIGIN: CODE, carried) — the phase3 oracle fixture's gate-check grade is a hypothesis-seed lottery: the frozen corpus's unseeded in-sandbox suite (24–67s per draw) exceeds the fixture's 60.0s per-check deadline on heavy draws and flips correct grades (FAIL→CANDIDATE_TIMEOUT; CORRECT_ACCEPTANCE→FALSE_SUCCESS). Next action is the fixture's owner: raise `gate_timeout_seconds` toward the 300.0 default or fix the in-sandbox gate's hypothesis seed/profile (both files are outside this brief's scope).
