ADR-0312: Processes are listed from /proc, a stop sends its signals itself, and lists at most 32 times
Status: Accepted Date: 2026-11-20
Context
The gate stops a process with every process under it (ProcessTable,
ADR-0158): it freezes the process, then lists every process and freezes
each one it finds under it, listing by listing, until a listing finds none
it has not frozen, and then kills them all. It tells the processes it spares
from a listing too (ADR-0310), and a CI shard's progress reports the
largest processes from one (ADR-0157).
Each listing ran ps through a shell, and each freeze and kill ran kill
through one: a fork and a program or two started for every listing and
every signal, in the gate, in each stream and in each warm worker.
The loop that lists had no bound. A mutant of the gate's own stopping code
that keeps the loop from ending, judged by a test that stops a process tree,
lists without pause until its test's deadline: the trace of shard 77 of run
44613843075 replayed (probe run 44812811852) showed about 190 sh -c ps -A
a second at its peak, from a few processes each starting about 470.
Shards that hold tests/Process/Adapter/Native/ProcessShellTest.php, which
stops many trees, lost their whole runner 2.5 to 4.5 minutes into their
second pass on ARM and x64 alike, with memory, signals, cgroups, disk and
network ruled out. A storm of process starts is the likeliest cause left;
it is not proven.
On Linux, /proc holds each process's parent, group, memory, start and
name in one stat file, which PHP reads without starting a process.
Decision
- One listing, one port, one implementation.
ProcessListing(core) holds every process with its parent, group, memory, age and name. The portRunningProcessesanswers it;Process\LiveProcessesis its one implementation and the one place the gate reads/procor runsps. On Linux it reads/proc/<pid>/statfor each process/procnames, the name taken up to the last), since a name may hold parentheses and spaces itself; on a system without/proc, such as macOS, or where PHP cannot ask the clock ticks and page size (posix_sysconf), it runspsonce. A process that ends between the read of/procand the read of itsstatfile is left out.ProcessTable,SparedProcesses, the warm workers and their clients, the split streams and a shard's progress take the port from their composition root: the CLI for the gate's own process and, through the Pest plugin it registers, for each split stream; the bin scripts for the warm workers and their clients; and the hunkPest\Patchwrites into Pest's runner, which watches the streams. That last root is an adapter, so A3 letsPatchnameLiveProcesses, and only that, by an exact list the architecture test holds. A split stream lists only once one of its children is past its limit, not at each look its reaping loop takes. - A stop under
processes.containlists nothing. A process held in a cgroup of its own (ADR-0158) is stopped by killing every process itscgroup.procsholds, however deep or whoever's child it became, the process last, then its session, and then the cgroup whole and removed, as before. - A stop lists at most
ProcessTable::LISTINGS(32) times. Each listing freezes every process it finds, and a frozen process starts no other, so a tree that stands still is whole after its depth plus one listings: a stop of a runner's tree (the gate, a worker, a test, a shell and a program) takes at most six. 32 leaves more than five times that for processes started between two listings, and at the most a stop costs 32 listings, about 55 ms on a machine with 300 processes. A stop that reaches the bound kills every process it found and the session it leads, and the cgroup kill follows where the process has one. - A stop sends its signals itself. Each freeze and kill goes through
SparedProcesses::signalandsignalGroup, so it refuses exactly what ADR-0310 refuses, one process at a time. What they let through is sent by the port's raw send,RunningProcesses::signalledUnspared:LiveProcessessends it byposix_killwhere PHP has posix and the signals' numbers (pcntl), and only where PHP has neither by thekillprogram, with the same outcome. A signal is named byCore\Runner\Signal, as thekillprogram names it, so the core needs no pcntl to name one.ProcessTableruns no command.
Consequences
- A stop whose listings converge signals the same processes in the same order as before; only the listing it reads them from changed. Its verdicts are unchanged.
- A mutant that keeps the stop from converging now ends after 32 listings, and its test goes on to what it asserts, instead of listing until the test's deadline. Such a mutant was a timeout before; now it is killed where its test's assertion fails, and survives where its test passes, which names a test that does not assert the stop's bound: the gate's own suite then kills it with a real assertion. Every other status is the same. This one status change was approved by the user on 2026-11-20.
- On Linux a stop starts no process: its listings read
/proc, and it sends its signals itself. In a Linux container with 300 processes, a listing takes 1.7 ms from/procagainst 5 ms throughps(584 to 627 against 198 to 203 a second). - A process started after a stop's 32nd listing, outside a session the stopped process leads and outside a cgroup, is left running, as one whose parent ended before the stop always was.