IMPLEMENTER BRIEF — phase6-supervisor-fixes-2 (Phase 6: the sweep-to-quiescence fix — F9)

GOAL: F9 is disposed and the supervisor's "kills the whole process tree" sentence holds over the capture window, not only the captured snapshot. The expiry kill re-walks-and-sweeps to quiescence — capture the descendant chain, kill the group, SIGKILL each surviving descendant, then re-capture and sweep again until the chain is empty or a bounded retry budget expires — so a process forked between the first capture and the group kill (the review's racing forker: 3 of 331 tail forks surviving) dies with the deadline instead of outliving it. The doubly-escaped orphan (reparented to init before the deadline) is closed the same way the review leaves it closable: the re-walk finds it while it is still a descendant, and whatever is already adopted out-of-tree at the first capture is named in `SHAPES` as the sweep's documented boundary, not hidden. F8 stays carried (the oracle fixture's hypothesis-seed lottery names an owner outside this brief's scope).

CONTEXT: The fixes review (`docs/research/phase6-supervisor-fixes-review.md`) re-drove every kill face live at FINAL `5ce423e97f45688d6808af40fdee8a506c816a98` and confirmed F4–F6 fixed on their faces (session-escaped fixture shape dead at the exit and 15s after; in-group grandchild dead at the fixed point; real-head `--budget 8` with five peak descendants all dead at the exit; all four named mutants red on the right members). Its two capture-window probes are hand-driven scratch fixtures, not committed pins: `/tmp/kilo/q1d_window2.py` (a racing fixture child forking session-escaped `sleep 60` grandchildren every ~5ms across a 2s deadline — 3 of 331 forked PIDs alive after the exit, always the final three forks, born after `_descendants` walked /proc) and `/tmp/kilo/q1e_rerun.py` (a doubly-escaped orphan adopted by init before the deadline, surviving `state=S ppid=3174`). The delivered sweep is capture-then-signal over numeric PIDs with no re-walk and no container boundary, so anything born-or-reparented after the snapshot is outside the surface by construction. Per rule 13 the next brief makes the claim structurally true over the whole surface (this brief: the sweep loops to quiescence) — the PID-reuse corner needs no action (capture-to-kill adjacent statements, pid_max 4194304, no I/O between). Red at this brief's `REV`: the suite is green — red evidence is written first (see the Red evidence section). `REV` names the step's base — the parent of this brief commit — and is not claimed to be `FINAL`'s parent (F4's lesson).

INHERITED:

From `docs/research/phase6-supervisor-fixes-implementer.md`, its `INHERITED` block verbatim:

  Nothing in the received set is still open: the brief's INHERITED carried F4, F5 and F6 (each `carried`), all three are fixed here — F4 fixed by the descendant-chasing kill over the supervisor's whole surface (its falsified absolute made structurally true, post-exit liveness of a session-escaped grandchild pinned at `tests/test_phase6_supervisor.py:432`), F5 fixed by absorbing the review's discriminating member into the merged tree pin (fixed-time assertion at `:416`), F6 fixed by absorbing the review's child-head observation as `tests/test_phase6_supervisor.py::test_the_child_head_receives_the_whole_environment_and_runs_once` (`:450`) — and F7 stays `fixed` as recorded in the review that filed it, unchanged. Added by this step, each carried finding with its ID:
    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).

From `docs/research/phase6-supervisor-fixes-review.md` — its `INHERITED` block, then each carried finding's block from its `FINDINGS` section, moved verbatim (rule 2 governs the planner's copy of this block; the review's received set is the fixes brief's carried F4/F5/F6, all three fixed at FINAL, F7 fixed as recorded):

  Nothing in the received set is still open: the fixes brief carried F4, F5 and F6 (each `carried`), and all three are fixed at FINAL — F4 fixed by the descendant-chasing kill over the captured surface (session-escaped grandchild dead after the exit, pinned at tests/test_phase6_supervisor.py:432; real-head `--budget 8` leaves no descendant at the exit or 15s after), F5 fixed by the absorbed discriminating member (fixed-time assertion at :416, red under the lone-child-kill mutant), F6 fixed by the absorbed child-head observation (tests/test_phase6_supervisor.py:450, red under the double-launch, dropped-secret, and added-variable mutants) — and F7 stays `fixed` as recorded in the review that filed it, unchanged. Added by this review, each carried finding with its ID:
    F9 (P1, ORIGIN: CODE, carried) — the descendant sweep cannot reach what is born or reparented after the chain capture: tail forks of a racing forker (3 of 331) and a doubly-escaped orphan adopted by init survive the deadline kill by construction. Next action is the planner's per rule 13: re-walk-and-sweep to quiescence or an OWNER ruling narrowing the whole-tree sentence to the captured-at-deadline surface.
    F8 (P2, ORIGIN: CODE, carried) — the phase3 oracle fixture's gate-check grade is a hypothesis-seed lottery (60.0s fixture deadline vs unseeded in-sandbox draws, green at FINAL). Next action is the fixture's owner: raise `gate_timeout_seconds` toward the 300.0 default or pin the in-sandbox gate's hypothesis seed/profile.

  F9 | SEVERITY: P1 | ORIGIN: CODE | STATE: carried
  The descendant sweep cannot reach a process forked between the chain capture and the group kill, nor one already reparented out of the chain: a racing fixture child that forks session-escaped `sleep 60` grandchildren every ~5ms across the 2s deadline leaves 3 of 331 forked PIDs alive after the exit — always the final three forks (2495117, 2495118, 2495119 of 331), i.e. born after `_descendants` walked /proc; and a doubly-escaped orphan (a session-escaped middleman that spawns a session-escaped sleeper then exits, so the sleeper is adopted by PID 3174/systemd before the deadline) survives the kill still adopted out-of-tree (`state=S ppid=3174` after exit 1). The delivered sweep is capture-then-signal over numeric PIDs with no re-walk and no container boundary, so anything born-or-reparented after the snapshot is outside the surface by construction.
  FIXED: no regression test — both reds are this review's hand-driven probes on scratch fixture children (`/tmp/kilo/q1d_window2.py`, `/tmp/kilo/q1e_rerun.py`), not committed pins; no committed module was edited by this review. Next action is the planner's per rule 13: re-walk-and-sweep to quiescence (capture, kill, re-capture until the chain is empty or a bounded retry budget expires), or an OWNER ruling narrowing the whole-tree sentence to the captured-at-deadline surface; the PID-reuse corner needs no action (capture-to-kill is adjacent statements, pid_max 4194304, no I/O between — recycle inside the window is not a live shape).

Expected dispositions (rule 8 forms): F9 fixed with red evidence (named below — the racing-fork tail pinned dead, the sweep looping to quiescence under a bounded budget). F8 stays carried (the lottery is real, outside this brief's scope, its owner named; the oracle line rides green at FINAL).

IN SCOPE: scripts/supervise_run.py, tests/test_phase6_supervisor.py

RESIDUALS:

none — rule 3 selection for this brief's `IN SCOPE`: no `docs/residuals.md` trigger glob matches `scripts/supervise_run.py` or `tests/test_phase6_supervisor.py` (the `PILOT-R*` triggers name `planning_pilot.py`, `controller.py`, `reducer.py`, `decomposition.py`, `model.py`, and `derive_obligations.py`; the store is byte-verified against `docs/residuals.md` before this brief's commit, rule 2). No residual row rides, so the residual half of `scripts/check-scope` has nothing to carry here and it prints `tripped: none` — the line your report's `TRIPPED` field copies.

OUT OF SCOPE:
- Editing this brief file (`docs/research/phase6-supervisor-fixes-2-brief.md`). A committed brief is never modified; a re-cut is a new file.
- `scripts/smoke_run.py` in full: the run and `--resume` recovery it drives are delivered and pinned; the supervisor calls them as subprocesses and edits neither. If recovery needs a code change, stop and report `IN SCOPE` as insufficient.
- `scripts/stress_run.py` in full: its child discipline is the pattern the supervisor follows, not a seam the supervisor edits. If the discipline needs a change, stop and report `IN SCOPE` as insufficient.
- `src/orchestrator/sandbox.py` in full: the descendant-chasing technique is the pattern the supervisor follows, not a seam this brief edits. Read it, do not touch it; if the technique needs a change, stop and report `IN SCOPE` as insufficient.
- `src/orchestrator/controller.py`, the store, the experiment harness, `src/orchestrator/secrets.py`, `src/orchestrator/spend.py`: no controller, store, credential, or ledger change rides here. No new event type, no `docs/tables/*` change and no table regeneration, no `docs/event-catalogue.md` change.
- `docs/self-host.md`, `docs/residuals.md`, `docs/record.md`, `docs/method.md`, `docs/templates/`: the status edit, if any is owed, rides a later step; this step delivers the sweep-to-quiescence fix.
- Every committed test module except the IN SCOPE pin module — `tests/test_run_entry.py`, `tests/test_axis2_robustness.py`, `tests/test_smoke_run_client.py`, `tests/test_review_phase6_supervisor.py`, and every other committed module are read-only here. No committed test file outside IN SCOPE is edited. If a pin would have to change for acceptance to pass, stop and report `IN SCOPE` as insufficient.
- `tests/open_defects.yaml` and the registry's meta-tests: no registration rides (F9 is the open finding whose next brief is this one; no `test_bug_*` name — the open-defect registry would then own it).
- The controller stack, `experiment_target.build_target`, `schemas.py`.
- Registry and control files: `tests/counterexamples.yaml`, `tests/guard_mutation_matrix.yaml`, `tests/fixture_fidelity.yaml`, `tests/verifier_registry.yaml`, `tests/spend_paths.yaml`, `tests/invariants.py`, `tests/helpers.py`, `pytest.ini`, tool configuration.
- No new dependencies, no tooling configuration, no reformatting. No new exception class and no `*Executor`/`*ModelClient` class or provider-registry registration.

ACCEPTANCE: Commands (run every one and paste what each prints into `VERIFIED`; expected result is green, exit 0, for each):

    scripts/check-tests --fast
    .venv/bin/python -m pytest tests/test_phase6_supervisor.py tests/test_review_phase6_supervisor.py
    .venv/bin/python -m pytest tests/test_axis2_robustness.py -m "not slow"
    .venv/bin/python -m pytest tests/test_phase3_project_oracle.py
    scripts/check-static
    scripts/check-docs
    scripts/check-scope 2da5a5a9a67336c1b8c9bb1d0f49e703eb32f806 <FINAL> docs/research/phase6-supervisor-fixes-2-brief.md

Every `pytest` line names `.venv/bin/python -m pytest` deliberately (F17's carried correction: the bare `pytest` on PATH has no `pytest-timeout` and `pytest.ini`'s `strict_config = true` rejects it on this host — run these lines exactly as written and claim them under these names). The supervisor-plus-review line names the review file although it is OUT OF SCOPE here: its two probes stand unedited beside the delivered module and must stay green. The axis2 non-slow line is the supervisor's invariant battery (`17 passed, 4 deselected` at this brief's REV — the spend-settle and lock pins it must not regress). The oracle line rides because this brief's IN SCOPE touches files under `scripts/` and `tests/` (rule: a brief that adds a file under `tests/` or `scripts/` also names `pytest tests/test_phase3_project_oracle.py`; this brief edits under both). The docs gate is expected green with 0 errors — and every count figure you write in `VERIFIED` is the gate's own printed line, never the REV line quoted in this brief's CONTEXT and never recomputed from memory (rule 14, the F41 class). The scope line is expected green, exit 0, printing `tripped: none` (and the `claimed:` line the parser prints). `REV` below names the step's base — the parent of this brief commit — and is not claimed to be `FINAL`'s parent (F4's lesson).

The sweep-to-quiescence fix (`scripts/supervise_run.py`, in place): the expiry kill loops capture-kill-sweep to quiescence under a bounded retry budget — capture the descendant chain, kill the group with the one `killpg`, SIGKILL each surviving captured descendant individually, then re-capture: if the chain is empty the tree is dead; if it is not, sweep again, up to a small bounded number of passes (three is enough: the racing forker's tail is born inside one pass's window, and the second pass's capture sees it). A short settle (a tenth of a second) between passes lets forked children appear in /proc before the re-capture. The budget bounds the loop, not the kill: every pass still signals every captured descendant, and the loop never waits for the recovery — the recorded `--resume` still runs exactly once after the sweep, unchanged. The recovery path is otherwise unchanged: exactly one recorded `--resume` after a killed/lost/nonzero child, none after a clean child, same environment, same single-document stdout with narration on stderr, same exit rules, same fail-closed misuse.

The pins (`tests/test_phase6_supervisor.py`, in place): a racing-fork pin joins the merged tree pin's drive — a fixture child forking session-escaped sleepers every ~5ms across a short deadline, every forked PID recorded, none alive after the supervisor's exit (red at REV: the review's measured shape, 3 of 331 tail forks surviving). The doubly-escaped orphan is not pinned (already adopted by init at the first capture it is outside any descendant walk's surface — the sweep's documented boundary, named in `SHAPES`, not hidden). No committed test file outside IN SCOPE is edited.

Red evidence at `REV` `2da5a5a9a67336c1b8c9bb1d0f49e703eb32f806` (each unit must be replayable; the suite is green at REV, so each red is written by this step and demonstrated at REV against the unfixed code on a scratch copy diff-verified against `git show 2da5a5a:…` before use). `FIXED` names the pin's node id, the command, the named failing assertion, and the delivered file's line numbers or none (F22). Named reds to produce: F9's racing-fork red — the new pin at REV, with the review's forker shape (session-escaped sleepers every ~5ms across the deadline), leaves tail forks alive after the exit (a named failing assertion on forked-PID liveness after the supervisor's exit — an error or a hang is not red, the assertion must be the thing that failed).

Named shapes to build — the list of shapes, not the number of tests. One shape needs at least one test, and every named shape needs one:

- `Sweep-to-quiescence shape` (F9): a racing forker's every forked PID dead after the supervisor's exit — the sweep's second pass captures what the first pass's window missed.
- `Reparented-orphan boundary shape` (F9): the doubly-escaped orphan adopted by init before the first capture survives — named in `SHAPES` as the sweep's documented boundary (no descendant walk reaches what is already out-of-tree at capture time), not pinned and not hidden.

REV: 2da5a5a9a67336c1b8c9bb1d0f49e703eb32f806
CLOSE OUT: yes
DIVERGENCES: none
REVIEW: one session — the sweep-to-quiescence fix above all: does the sweep loop capture-kill-sweep under a bounded budget with a settle between passes, does the racing-fork pin leave no forked PID alive after the exit, is the reparented-orphan boundary named in `SHAPES` rather than hidden, is the `IN SCOPE` line plain with scope green, are the docs figures the gate's own printed lines (rule 14), and does the step touch only the IN SCOPE files with every committed battery green and no committed test edit outside them. Whether anything remains open after this step is the loop's exit input — report findings and let the planner decide (cycle step 5).

You implement one brief. You do not plan, re-scope, or decide what the work is. Read every file
in IN SCOPE before editing it; if what you find contradicts the brief, report that instead of
guessing. Modify only what IN SCOPE names. If you find uncommitted changes in the tree, stop and say
so. Stop and report rather than improvise when IN SCOPE is
insufficient, the brief contradicts the code, you have already failed twice at this goal, or the
requirement is ambiguous and no single reading is consistent with the rest of the brief. If exactly
one reading is consistent, take it and file a FINDING with ORIGIN: BRIEF that names the reading you
took. No new dependencies, no tooling configuration, no reformatting. Run every ACCEPTANCE command;
fix what is in scope and report what is not.

A defect in the brief is a FINDING, never METHOD FRICTION. METHOD FRICTION is only for the method and
its templates: any place you deviated from them, found them ambiguous, or found them silent. Report
friction you worked around — that is the section the method learns from.

Commit your own work. When ACCEPTANCE passes, commit the files you changed, and only those, in one
commit whose message ends with the trailer `Actor: IMPLEMENTER`. That commit's full sha is FINAL.
Then append docs/templates/report.txt verbatim, fill it in, write it to
docs/research/<phase>-<subject>-implementer.md, and commit it in a second commit with the same
trailer. Do not amend the first commit to add the report: FINAL must not change after the report
names it. If you cannot commit, stop and say so; do not leave work uncommitted for someone else to
commit.
