Archilyzer · Source

archilyzer

Archilyzer
git clone https://archilyzer.pages.dev/source/archilyzer.git
Log | Files | Refs | README | LICENSE

commit ba032bfcbe5034d3856af487fc9b4ad09b52772e
parent e5fc0088a2fab451076c087dc45a84b977736e3a
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Sat, 10 Oct 2026 16:21:34 -0400

e2e: a killed run's worker-slot servers are reaped by a watchdog

A runner SIGKILLed mid-run (a `timeout`, an OOM) never reaches globalTeardown,
and a slot's servers are process groups of their own: they outlived it, and the
next run found their ports bound. Each slot now has a detached watchdog that
polls the runner and takes the groups down (TERM, then KILL) once it is gone,
and exits on its own after a clean teardown.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

Diffstat:
Meditor/e2e/servers.ts | 29+++++++++++++++++++++++++++++
1 file changed, 29 insertions(+), 0 deletions(-)

diff --git a/editor/e2e/servers.ts b/editor/e2e/servers.ts @@ -336,5 +336,34 @@ export async function startSlot(slot: number, mode: E2EMode, timeoutMs = 120_000 await stop(); throw err; } + armWatchdog(children.flatMap((c) => (c.pid ? [c.pid] : []))); return { slot, stop }; } + +// A run killed outright (SIGKILL, an OOM) never reaches globalTeardown, and a +// slot's servers are process groups of their own — they would outlive it, and +// the next run would find their ports bound. So each slot gets a watchdog, as +// detached as its servers: it polls the runner and, once the runner is gone, +// takes the groups down (TERM, then KILL) and exits. It also exits once the +// groups are gone (a clean teardown). +const WATCHDOG = ` +const [runner, ...groups] = process.argv.slice(1).map(Number); +const alive = (pid) => { try { process.kill(pid, 0); return true; } catch (e) { return e.code === "EPERM"; } }; +const kill = (sig) => { for (const g of groups) { try { process.kill(-g, sig); } catch {} } }; +const tick = setInterval(() => { + if (!groups.some((g) => alive(g))) process.exit(0); + if (alive(runner)) return; + clearInterval(tick); + kill("SIGTERM"); + setTimeout(() => { kill("SIGKILL"); process.exit(0); }, 5000); +}, 2000); +`; + +function armWatchdog(groups: number[]): void { + if (!groups.length) return; + const dog = spawn(process.execPath, ["-e", WATCHDOG, String(process.pid), ...groups.map(String)], { + stdio: "ignore", + detached: true, + }); + dog.unref(); +}