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(runners): the runner census skips Linux kernel threads [C7]

Corey Olsonbbe6c4b79b7f
diff --git a/src/process-census.js b/src/process-census.js
new file mode 100644
index 00000000..a3df00ec
--- /dev/null
+++ b/src/process-census.js
@@ -0,0 +1,30 @@
+/** Parse one all-process POSIX census for the runner worker's cleanup checks [C7]. */
+import { createHash } from 'node:crypto';
+
+/**
+ * Parse `ps -axo pid=,ppid=,pgid=,lstart=,stat=,comm=` output into rows keyed by pid.
+ * A malformed census is never read as an empty machine, so any row it cannot trust returns null.
+ * Rows with no process group (pgid 0) are skipped: Linux lists its kernel threads that way, and
+ * they can never belong to a worker's process groups. Rejecting them made every census on a real
+ * Linux host null, so runner cleanup could never be verified.
+ *
+ * @param {string} stdout - The census text.
+ * @returns {Map<number, {pid:number, ppid:number, pgid:number, started:string, state:string, processSha256:string}>|null}
+ */
+export function parseProcessCensus(stdout) {
+ const rows = new Map();
+ for (const line of stdout.split(/\r?\n/u)) {
+ if (!line.trim()) continue;
+ const match = /^\s*(\d+)\s+(\d+)\s+(\d+)\s+([A-Z][a-z]{2})\s+([A-Z][a-z]{2})\s+(\d{1,2})\s+(\d{2}:\d{2}:\d{2})\s+(\d{4})\s+(\S+)\s+(.+?)\s*$/u.exec(line);
+ if (!match) return null;
+ const pid = Number(match[1]);
+ const ppid = Number(match[2]);
+ const pgid = Number(match[3]);
+ if (![pid, ppid, pgid].every(Number.isSafeInteger) || pid < 1 || ppid < 0 || pgid < 0 || rows.has(pid)) return null;
+ if (pgid === 0) continue;
+ const started = `${match[4]} ${match[5]} ${match[6]} ${match[7]} ${match[8]}`;
+ const processSha256 = createHash('sha256').update(match[10]).digest('hex');
+ rows.set(pid, { pid, ppid, pgid, started, state: match[9], processSha256 });
+ }
+ return rows.size ? rows : null;
+}
diff --git a/src/runner-worker.js b/src/runner-worker.js
index 7e01c2ef..78d5a1e9 100644
--- a/src/runner-worker.js
+++ b/src/runner-worker.js
@@ -6,6 +6,7 @@ import { userInfo } from 'node:os';
import { delimiter, dirname, isAbsolute, join } from 'node:path';
import { fileURLToPath, pathToFileURL } from 'node:url';
import * as resourceApi from './resources.js';
+import { parseProcessCensus } from './process-census.js';
import { once } from 'node:events';
import { pipeline } from 'node:stream/promises';
@@ -130,7 +131,7 @@ async function readSpec() {
tagNames.add(tag.name);
if (tag.chain.length ? tag.chain[0] !== tag.object : tag.object !== tag.peeledCommit) throw new Error('invalid tag manifest');
}
- const runtimeNames = ['resources.js', 'git.js', 'machine-home.js', 'refused.js'];
+ const runtimeNames = ['resources.js', 'git.js', 'machine-home.js', 'refused.js', 'process-census.js'];
if (Object.keys(value.runtime.files).length !== runtimeNames.length
|| runtimeNames.some(name => typeof value.runtime.files[name] !== 'string')) throw new Error('invalid work specification');
if (createHash('sha256').update(JSON.stringify(value.runtime.files)).digest('hex') !== value.runtime.sha256) throw new Error('invalid trusted runtime');
@@ -212,20 +213,7 @@ function processCensus() {
env: { PATH: safePath, LANG: 'C', LC_ALL: 'C', TZ: 'UTC' },
});
if (result.error || result.status !== 0 || typeof result.stdout !== 'string') return null;
- const rows = new Map();
- for (const line of result.stdout.split(/\r?\n/u)) {
- if (!line.trim()) continue;
- const match = /^\s*(\d+)\s+(\d+)\s+(\d+)\s+([A-Z][a-z]{2})\s+([A-Z][a-z]{2})\s+(\d{1,2})\s+(\d{2}:\d{2}:\d{2})\s+(\d{4})\s+(\S+)\s+(.+?)\s*$/u.exec(line);
- if (!match) return null;
- const pid = Number(match[1]);
- const ppid = Number(match[2]);
- const pgid = Number(match[3]);
- if (![pid, ppid, pgid].every(Number.isSafeInteger) || pid < 1 || ppid < 0 || pgid < 1 || rows.has(pid)) return null;
- const started = `${match[4]} ${match[5]} ${match[6]} ${match[7]} ${match[8]}`;
- const processSha256 = createHash('sha256').update(match[10]).digest('hex');
- rows.set(pid, { pid, ppid, pgid, started, state: match[9], processSha256 });
- }
- return rows.size ? rows : null;
+ return parseProcessCensus(result.stdout);
}
/** Add a kernel start-time identity when procfs is available; otherwise retain a conservative census tuple. */
diff --git a/src/runners.js b/src/runners.js
index fb169328..48919ed8 100644
--- a/src/runners.js
+++ b/src/runners.js
@@ -18,7 +18,7 @@ const MAX_BLOB_BYTES = 8 * 1024 ** 2;
const MAX_HISTORY_TAGS = 1_024;
const MAX_TAG_CHAIN = 8;
const TOOL_ROOT = fileURLToPath(new URL('../', import.meta.url));
-const RUNTIME_NAMES = ['resources.js', 'git.js', 'machine-home.js', 'refused.js'];
+const RUNTIME_NAMES = ['resources.js', 'git.js', 'machine-home.js', 'refused.js', 'process-census.js'];
/** Validate an SSH destination as one argument, never a command or an SSH option. */
export function validateRunner(value) {
diff --git a/test/runners.test.js b/test/runners.test.js
index bd391f13..6a57c644 100644
--- a/test/runners.test.js
+++ b/test/runners.test.js
@@ -9,6 +9,7 @@ import { tmpdir } from 'node:os';
import { pathToFileURL } from 'node:url';
import { after, test } from 'node:test';
import { listResources, takeResource } from '../src/resources.js';
+import { parseProcessCensus } from '../src/process-census.js';
import { listResources as listPreRunnerResources, takeResource as takePreRunnerResource } from './fixtures/resources-pre-runners.js';
import { runFixtureChild, runFixtureChildAsync, startFixtureChild } from './fixture-child.js';
@@ -832,6 +833,19 @@ function processesUnder(dir) {
}
test('a queued runner run finishes or fails by name within its deadline [C7]', { timeout: 120_000 }, async (t) => { // budget: one real round trip plus three held phases, each stopped by its own deadline.
+ // Linux lists kernel threads with process group 0. A census holding them must still parse, or
+ // runner cleanup can never be verified on a real Linux host and every round trip waits forever.
+ const linuxCensus = [
+ ' 1 0 1 Fri Oct 16 19:03:32 2026 Ss systemd',
+ ' 2 0 0 Fri Oct 16 19:03:32 2026 S kthreadd',
+ ' 3 2 0 Fri Oct 16 19:03:32 2026 I< kworker/R-rcu_g',
+ ' 812 1 812 Fri Oct 16 19:05:01 2026 Ss node',
+ ].join('\n');
+ const parsed = parseProcessCensus(linuxCensus);
+ assert.ok(parsed, 'a census with kernel threads in process group 0 still parses');
+ assert.deepEqual([...parsed.keys()], [1, 812], 'kernel threads are skipped; real processes are kept');
+ assert.equal(parseProcessCensus(' 5 1 5 Fri Oct 16 19:03:32 2026 S node\nnot a census row'), null, 'a malformed row still voids the census');
+
const dir = realpathSync(mkdtempSync(join(tmpdir(), 'pullboard-runner-deadline-')));
t.after(() => rmSync(dir, { recursive: true, force: true }));
const home = join(dir, 'home');