Skip to content

Autonomous development for real products. Governed agents build from specs you approve, follow the rules you set, and nothing merges until another agent proves it. Your decisions, judgement and taste are the bar that work must clear. Declare your vision and let agents build it.

fix(runner): a kill of a process no longer ours counts as gone [C7]

Corey Olsoncaad2b61b4b2
diff --git a/bin/run-tests.js b/bin/run-tests.js
index 1ba66703..347c084f 100644
--- a/bin/run-tests.js
+++ b/bin/run-tests.js
@@ -712,6 +712,25 @@ function landingWorkerReceipts(path) {
return complete.split(/\r?\n/u).filter(Boolean).map(line => JSON.parse(line));
}
+/**
+ * True when a kill that failed with ESRCH or EPERM hit a process this run no longer owns: it is gone,
+ * a zombie, or its pid now belongs to another process. Under load a process can exit, or its pid be
+ * reused, between the census and the signal, and macOS answers EPERM for some of those (#850). Each
+ * such answer is logged; an EPERM for a process that is still ours is a real permission error.
+ */
+export function killAnsweredGone(error, owned, snapshot) {
+ if (error.code !== 'ESRCH' && error.code !== 'EPERM') return false;
+ if (error.code === 'EPERM') {
+ const fresh = snapshot();
+ // No census, no verdict: keep the identity and let the next sweep decide.
+ if (!fresh) return true;
+ const live = fresh.get(owned.pid);
+ if (sameProcessIdentity(live, owned) && !live.state.startsWith('Z')) return false;
+ }
+ process.stderr.write(`run-tests: kill ${owned.pid} answered ${error.code}; that process is gone or no longer ours, so it counts as gone\n`);
+ return true;
+}
+
/** Terminate owned descendants as the live receipt set grows, then wait for the run and every identity to drain. */
async function drainLandingWorkerDescendants(ownedDescendants, refreshOwnedDescendants, runFinished, reportUnverified, cleanupDeadline) {
let firstError = null;
@@ -747,7 +766,7 @@ async function drainLandingWorkerDescendants(ownedDescendants, refreshOwnedDesce
if (signal === 'SIGTERM') state.termAt = now;
else state.killSent = true;
} catch (error) {
- if (error.code === 'ESRCH') continue;
+ if (killAnsweredGone(error, owned, snapshot)) continue;
rememberError(error);
}
signalState.set(key, state);
diff --git a/src/runner-worker.js b/src/runner-worker.js
index 19d93d68..7db359ac 100644
--- a/src/runner-worker.js
+++ b/src/runner-worker.js
@@ -653,8 +653,11 @@ function createDescendantTracker(directory) {
catch (error) {
if (error.code === 'ESRCH') return false;
// macOS answers EPERM for a group whose members exited but are not yet reaped. Throwing here escaped cleanup and
- // skipped the lease release (#888); retry on a fresh census instead, as for any other ambiguity.
- if (error.code === 'EPERM') return null;
+ // skipped the lease release (#888, and the load flake in #850); retry on a fresh census instead, and say so.
+ if (error.code === 'EPERM') {
+ process.stderr.write(`runner: signal to process group ${pgid} answered EPERM; its members have exited, so the next census decides\n`);
+ return null;
+ }
throw error;
}
return true;
diff --git a/test/run-tests-kill.test.js b/test/run-tests-kill.test.js
new file mode 100644
index 00000000..15e047a0
--- /dev/null
+++ b/test/run-tests-kill.test.js
@@ -0,0 +1,52 @@
+/** A landing cleanup kill that hits a process the run no longer owns counts as gone, and says so [C7,#850]. */
+import assert from 'node:assert/strict';
+import { test } from 'node:test';
+import { killAnsweredGone } from '../bin/run-tests.js';
+
+const OWNED = { pid: 4242, pgid: 4240, started: 'Mon Oct 20 03:00:00 2026', state: 'S' };
+
+/** A kill failure with the errno code the kernel answered. */
+function killError(code) { return Object.assign(new Error(`kill ${code}`), { code }); }
+
+/** Run the decision while capturing what it writes to stderr. */
+function decide(code, census) {
+ const lines = [];
+ const write = process.stderr.write;
+ process.stderr.write = (chunk) => { lines.push(String(chunk)); return true; };
+ try { return { gone: killAnsweredGone(killError(code), OWNED, () => census), lines }; }
+ finally { process.stderr.write = write; }
+}
+
+test('an EPERM for a pid that exited or was reused counts as gone and is logged [C7]', () => {
+ for (const [why, census] of [
+ ['exited', new Map()],
+ ['reused by another process', new Map([[OWNED.pid, { ...OWNED, started: 'Mon Oct 20 03:00:07 2026' }]])],
+ ['left as a zombie', new Map([[OWNED.pid, { ...OWNED, state: 'Z' }]])],
+ ]) {
+ const { gone, lines } = decide('EPERM', census);
+ assert.equal(gone, true, `a process that ${why} is gone`);
+ assert.match(lines.join(''), /run-tests: kill 4242 answered EPERM; that process is gone or no longer ours, so it counts as gone/u, why);
+ }
+});
+
+test('an ESRCH counts as gone and is logged [C7]', () => {
+ const { gone, lines } = decide('ESRCH', new Map([[OWNED.pid, OWNED]]));
+ assert.equal(gone, true);
+ assert.match(lines.join(''), /kill 4242 answered ESRCH/u);
+});
+
+test('an EPERM for a process that is still ours is a real permission error [C7]', () => {
+ const { gone, lines } = decide('EPERM', new Map([[OWNED.pid, { ...OWNED }]]));
+ assert.equal(gone, false, 'the caller keeps it as a cleanup error');
+ assert.deepEqual(lines, [], 'and nothing claims it is gone');
+});
+
+test('an EPERM with no census leaves the verdict to the next sweep, without claiming it is gone [C7]', () => {
+ const { gone, lines } = decide('EPERM', null);
+ assert.equal(gone, true, 'the sweep retries rather than failing the run');
+ assert.deepEqual(lines, []);
+});
+
+test('any other kill failure is never counted as gone [C7]', () => {
+ assert.equal(decide('EINVAL', new Map()).gone, false);
+});