My quality test passed PID 1 to a kill helper. 87 SIGKILL in 74 ms.
On December 1st my screen went black with the PC still on. Not a crash, not OOM: every process in my user session took SIGKILL inside a 74 ms window. The kernel tracepoint counted 87 signal_generate sig=9 events leaving the pytest process. The root-owned ones failed with EPERM. The rest did not.
What died: systemd --user, kwin_wayland, plasmashell, hermes-gateway. My gateway restarted 5 times per hour and the session went down 14 to 17 times that day.
The line
_kill_proc_tree(1)
The helper exists to kill a process plus its descendants. Its reason to exist: subprocess.run with a timeout only kills the direct child, so a hung ssh -t -t grandchild survives and holds the captured pipes. The internal communicate() never returns and the TimeoutExpired never fires. The helper walks psutil.Process(pid).children(recursive=True) and kills every node.
PID 1's descendants are every process on the host. One call, whole session.
The call came from the containment test of the D9 gate in my Roger loop. The test had no real target process, so it passed 1 as a placeholder target. The helper accepted any int. It did exactly what it was written to do.
Why it stayed green
The helper worked. Idempotent, honest return values (gone only after wait_procs, never killed without proof). The unit test asserted the happy-path return string. It never asked what happens when the target is a PID that can never be a containment target. Green test, dead session.
The fix: refuse the target before any signal exists
Target validation now runs before any signal and returns the reason instead of a boolean:
pid <= 1 -> refused:pid_invalido
pid == os.getpid() -> refused:proprio_processo
pid in ancestors() -> refused:ancestral
comm in {systemd, init} -> refused:gerenciador_de_sessao
_kill_proc_tree and _escalate_kill call that check first and return refused:<reason>. Fail closed before any signal exists. The killpg path refuses the same way: a PGID of 0 or 1 is not a containment target either.
Three things that matter more than the code:
A containment helper must refuse, not sanitize. The helper already refused to lie about its result. Same principle for the target: if a kill helper accepts any int, the caller's placeholder becomes an incident.
The test that catches this asserts the refusal, not the happy path. The regression is parametrized over [0, 1] and asserts the return starts with refused:pid_invalido. It fails if someone deletes the guard, which is the only kind of test that keeps a guard alive. It runs green today: 4 passed in 0.33s.
Static scan before the code runs. A second layer greps the repo for the anti-pattern itself (_kill_proc_tree(1), os.kill(-1,, killpg(0,, pkill -9 -f '') with an allowlist so it does not flag its own guard code. The execution guard fails closed. The scanner catches the next variant before it ever runs.
The rule
A process-containment helper is a loaded gun pointed at the machine the test runs on. It cannot trust its caller: validate the target, fail closed, and make the refusal the thing your test asserts.
Next question: if a helper is one int away from killing your session, what else in your test suite does nobody refuse? The gate I run is the ai-test-loop skill, the loop that fails closed before it claims "done". See all skills.
Top comments (0)