ADR-0158: The gate holds every process it starts in a session and a cgroup
Status: Accepted Date: 2026-11-15
Context
The gate stops a process at its deadline with every process under it
(src/Core/Runner/ProcessTable.php): it freezes the process, walks ps's
parent links to freeze each process found under it, listing by listing, and
kills them all. A process whose parent ended before it is handed to the
system's first process, so no parent link leads to it, and the walk misses
it. A process that ended on its own leaves its children running unasked.
Under split streams (ADR-0117) the runner forks a child per mutant and
waits for each. A mutant that keeps the runner from waiting, such as one
that negates Children::reapAll(), ends the runner first and leaves its
children running, each in a test that may never end. Across a shard such
orphans pile up until the machine runs out of memory or processes, and the
hosted runner stops answering: shard 5 of the gate's own CI was lost at
about 49 minutes in runs 43712641293 and 43755388963 (ADR-0157).
A process leading a session of its own gives its session's id to every
process it starts that does not leave it, however deep and whoever its
parent is now; kill -- -<id> signals all of them. On Linux, a cgroup holds
every process started in it, whatever leaves its session, caps their memory,
swap and count, and cgroup.kill kills them all at once. GitHub's hosted
Linux runners run systemd on cgroup v2, and their sudo needs no password.
Decision
processes.groupstarts every process the gate starts as the leader of a session of its own:auto, the default,offorrequire.autostarts it undersetsidwhere the system has it, else under the gate's PHP with no ini of its own, which leaves the session and replaces itself with the command where it can (posix_setsid,pcntl_exec), else as before.requirerefuses to run where neither is there;offstarts it as before.- A process stopped at its deadline, or for its silence or a test's limit, has its whole session frozen before the walk and killed after it. A process that ended on its own has whatever is left of its session killed.
- The processes a mutant's test starts, and those its served children
start (ADR-0150), stay in the session: nothing the gate starts for a
mutant leaves it. The daemon of
mutation-gate serveleaves its starter's session on purpose, and is not started through it (ADR-0078). - It changes no result, only what is left running, so a change to it re-runs nothing.
processes.containruns every process the gate starts in a cgroup of its own, on Linux:auto, the default,offorrequire.- Where the cgroup the gate runs in sits in one the gate's user may
write, with the
memoryandpidscontrollers handed down, the gate makesmutation-gate-<pid>beside it, capped atprocesses.memoryof the machine's memory withmemory.swap.max0, and atprocesses.pidsprocesses. Each process it starts joinsrun-<random>under that one before it becomes its command, withmemory.oom.groupset, so an out-of-memory kill takes the whole run. The gate kills that cgroup whole withcgroup.killonce the process ends or is stopped, and removes it; it removes its own when it exits. - In CI, where none is handed to it, the gate hands itself one with
sudo -n: it makes/sys/fs/cgroup/mutation-gate, gives it to its own user, hands the two controllers down and moves its own process intogate-<pid>in it. Outside CI it never runssudo. autoruns uncontained where no cgroup can be had: off Linux, on cgroup v1, without a cgroup to write and outside CI, or on a kernel withoutcgroup.kill.requirerefuses to run there, saying why;offnever contains.- It is a backstop beside the session: a process that leaves its session stays in its cgroup, and a run that takes the machine's memory or processes is stopped before the runner that hosts the job is.
- Where the cgroup the gate runs in sits in one the gate's user may
write, with the
processes.memory, a whole number from 1 to 100, 85 by default, is the share of the machine's memory, in percent, that every process the gate starts may hold together, with no swap. The rest is the runner's, the gate's own and the system's.processes.pids, 8192 by default, is how many processes they may be together.- A contained run that goes past a cap ends as one killed by a signal.
Over its memory the kernel kills the run's cgroup whole; at its process
count a fork fails. Either way the run ends as it would where PHP's
memory_limitended it, or a fork failed, without a cap on the machine. A change toprocesses.contain,.memoryor.pidsdecides how the gate runs, so no proof is carried across it (ADR-0005), but none is in a proof's key:autoholds where the machine allows, which the key could not name. - The CI templates need nothing of their own: the GitHub action and the
reusable workflow run the gate on a hosted runner, which hands itself its
cgroup; a template of another CI does the same wherever its runner has
systemd on cgroup v2 and
sudowithout a password, and runs uncontained elsewhere.
Alternatives considered
| Alternative | Why not |
|---|---|
Find orphans by walking ps for processes of the system's first process | Every daemon of the machine is one; nothing tells the gate's apart but its session. |
systemd-run --scope per process | It needs a user manager or sudo for every process the gate starts, and passes no environment through sudo. |
| Contain only on GitHub Actions, from the action | Every CI with systemd and passwordless sudo gains the same, and a step of the action cannot move a later step's process. |
| One cgroup for all the gate's processes, without one per process | A run's cgroup is what an out-of-memory kill takes whole and what cgroup.kill empties once it ends. |
| A cap per process instead of one shared | A pool of runs, each under a cap below the machine's memory, can still take it all together. |
Contain by default only with require | A machine that cannot contain would refuse every run; auto keeps them running and contains wherever it can. |
Consequences
- A runner that ends before its children leaves nothing running: its session, and on Linux its cgroup, are killed once it ends.
- A hosted runner keeps 15% of its memory however the mutants behave, so a runaway mutant fails its run instead of losing the job.
- A process the gate starts on macOS without
setsidis started through a second PHP first, which adds a few milliseconds to each start. - The gate's CI shards run
sudo -nfour times at start-up.