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.
JavaScript agentic-codingai-agentsai-governanceautonomous-agentsclaude-codeclicode-reviewcodexcoding-agentsdeveloper-toolsgit-hooksllmlocal-firstmulti-agentsoftware-factoryspec-driven-developmentverificationvibe-coding
fix(runner): avoid oversized worker census [C7]
Corey Olsonc25e0cd6f360
diff --git a/bin/run-tests.js b/bin/run-tests.jsindex c4b5bfd0..479cb0b2 100644--- a/bin/run-tests.js+++ b/bin/run-tests.js@@ -14,6 +14,7 @@ import { Worker } from 'node:worker_threads';import { randomUUID } from 'node:crypto';import { channel } from 'node:diagnostics_channel';import { AGENT_SHELL_MARKERS, SSH_SHELL_MARKERS } from '../src/person.js';+import { isLandingWorkerIdentityTimeout, landingWorkerIdentityQuery, parseLandingWorkerIdentity } from '../src/landing-worker-identity.js';import { foreignNodeOptions, isolateTestMachine } from '../src/test-isolation.js';const runner = fileURLToPath(import.meta.url);const LANDING_RUN_ENV = 'PULLBOARD_LANDING_RUN';@@ -479,6 +480,7 @@ function landingWorkerCancellationError(cause) {/** Retry a worker's initial process-identity receipt without blocking its event loop or exceeding the file-start ceiling. */async function landingWorkerIdentity(pid, timeoutMs = LANDING_WORKER_IDENTITY_TIMEOUT_MS) {if (process.platform === 'win32') return null;+ const { args: snapshotArgs } = landingWorkerIdentityQuery(pid);const deadline = Date.now() + timeoutMs;let lastError = null;let retryNoticeReported = false;@@ -496,8 +498,8 @@ async function landingWorkerIdentity(pid, timeoutMs = LANDING_WORKER_IDENTITY_TIif (remaining <= 0) break;try {const output = await new Promise((resolveOutput, rejectOutput) => {- const child = execFile('ps', ['-axo', 'pid=,ppid=,pgid=,stat=,lstart=,command='], {- encoding: 'utf8', timeout: Math.min(2000, Math.max(1, remaining)), maxBuffer: 64 << 20,+ const child = execFile('ps', snapshotArgs, {+ encoding: 'utf8', timeout: Math.min(2000, Math.max(1, remaining)),}, (error, stdout) => {if (snapshotChild === child) snapshotChild = null;error ? rejectOutput(error) : resolveOutput(stdout);@@ -506,8 +508,8 @@ async function landingWorkerIdentity(pid, timeoutMs = LANDING_WORKER_IDENTITY_TIif (stopping) child.kill('SIGTERM');});if (stopping) throw landingWorkerCancellationError();- const identity = parseLandingProcessTable(output).find(processInfo => processInfo.pid === pid);- if (identity) {+ const identity = parseLandingWorkerIdentity(output);+ if (identity?.pid === pid) {if (stopping) throw landingWorkerCancellationError();return identity;}@@ -516,8 +518,7 @@ async function landingWorkerIdentity(pid, timeoutMs = LANDING_WORKER_IDENTITY_TIlastError = error;if (!retryNoticeReported) {retryNoticeReported = true;- const timedOut = error.code === 'ETIMEDOUT' || (error.killed === true && error.signal === 'SIGTERM'- && error.cmd === 'ps -axo pid=,ppid=,pgid=,stat=,lstart=,command=');+ const timedOut = isLandingWorkerIdentityTimeout(error, pid);process.stderr.write(timedOut? 'run-tests: worker identity snapshot timed out; retrying before file execution\n': `run-tests: worker identity snapshot failed (${error.code ?? 'unknown'}); retrying before file execution\n`);diff --git a/src/landing-worker-identity.js b/src/landing-worker-identity.jsnew file mode 100644index 00000000..93c23dc5--- /dev/null+++ b/src/landing-worker-identity.js@@ -0,0 +1,21 @@+/** Parse the compact process row used to bind one announced landing worker PID [C7,V4]. */+export function parseLandingWorkerIdentity(output) {+ const match = output.trim().match(/^(\d+)\s+(\d+)\s+(\d+)\s+(\S+)\s+(.+)$/u);+ if (!match) return null;+ const startedFields = match[5].trim().split(/\s+/u);+ if (startedFields.length !== 5) return null;+ return { pid: Number(match[1]), ppid: Number(match[2]), pgid: Number(match[3]),+ state: match[4], started: startedFields.join(' ') };+}++/** Build the PID-only process query and its error-reporting command string [C7,V4]. */+export function landingWorkerIdentityQuery(pid) {+ const args = ['-p', String(pid), '-o', 'pid=,ppid=,pgid=,stat=,lstart='];+ return { args, command: `ps ${args.join(' ')}` };+}++/** Recognize only timeout failures from this worker's exact process query [C7,V4]. */+export function isLandingWorkerIdentityTimeout(error, pid) {+ const { command } = landingWorkerIdentityQuery(pid);+ return error.code === 'ETIMEDOUT' || (error.killed === true && error.signal === 'SIGTERM' && error.cmd === command);+}diff --git a/test/run-tests-fixture.js b/test/run-tests-fixture.jsnew file mode 100644index 00000000..ca0a6b86--- /dev/null+++ b/test/run-tests-fixture.js@@ -0,0 +1,7 @@+import { execFileSync } from 'node:child_process';++/** Initialize a private fixture repository and stage exactly its intended files. */+export function stageFixtureTests(root, paths) {+ execFileSync('git', ['init', '-q'], { cwd: root, stdio: 'ignore' });+ execFileSync('git', ['add', '--', ...paths], { cwd: root, stdio: 'ignore' });+}diff --git a/test/run-tests-worker-identity.test.js b/test/run-tests-worker-identity.test.jsnew file mode 100644index 00000000..2699631a--- /dev/null+++ b/test/run-tests-worker-identity.test.js@@ -0,0 +1,110 @@+/** @pullboard-test-input source-tree */+/** Prove a landing worker obtains a bounded identity receipt before its body [C7,V4]. */+import assert from 'node:assert/strict';+import { cpSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from 'node:fs';+import { tmpdir } from 'node:os';+import { join } from 'node:path';+import { fileURLToPath, pathToFileURL } from 'node:url';+import { test } from 'node:test';+import { runFixtureChild } from './fixture-child.js';+import { stageFixtureTests } from './run-tests-fixture.js';++const runner = fileURLToPath(new URL('../bin/run-tests.js', import.meta.url));++/** Create an isolated runner tree with one tracked test file, so the regression exercises its own worker. */+function makeIdentityFixture(t) {+ const root = realpathSync(mkdtempSync(join(tmpdir(), 'pullboard-worker-identity-overflow-')));+ mkdirSync(join(root, 'bin'));+ mkdirSync(join(root, 'test'));+ writeFileSync(join(root, 'package.json'), JSON.stringify({ type: 'module' }));+ writeFileSync(join(root, 'bin/run-tests.js'), readFileSync(runner));+ const fixtureRunner = join(root, 'bin/run-tests.js');+ assert.equal(realpathSync(fixtureRunner), fixtureRunner, 'the copied runner uses its physical path');+ cpSync(fileURLToPath(new URL('../src', import.meta.url)), join(root, 'src'), { recursive: true });+ t.after(() => rmSync(root, { recursive: true, force: true }));+ return { root, runner: fixtureRunner, workerTest: join(root, 'test/worker-start.test.js') };+}++test('a landing worker gets its identity without the oversized process census [C7,V4]', t => {+ const fixture = makeIdentityFixture(t);+ const preload = join(fixture.root, 'worker-snapshot-overflow.mjs');+ const calls = join(fixture.root, 'worker-snapshot-calls.jsonl');+ writeFileSync(fixture.workerTest, `import assert from 'node:assert/strict';+import { readFileSync } from 'node:fs';+import { test } from 'node:test';+test('worker identity is recorded before the file body', () => {+ const receipts = readFileSync(process.env.PULLBOARD_LANDING_WORKER_STARTS, 'utf8').trim().split(/\\r?\\n/u).map(line => JSON.parse(line));+ const receipt = receipts.find(row => row.type === 'worker' && row.pid === process.pid);+ assert.ok(receipt?.pgid && receipt.started, 'the compact PID query produced a usable worker identity');+ const controls = readFileSync(process.env.PULLBOARD_C7_SNAPSHOT_CALLS, 'utf8').trim().split(/\\r?\\n/u).map(line => JSON.parse(line));+ const realPs = controls.find(row => row.type === 'real-ps-control' && row.pid === process.pid);+ assert.ok(realPs, 'the accepted identity came from a real ps response');+ assert.notEqual(realPs.widenedStarted, realPs.canonicalStarted, 'the successful ps row widened only legal whitespace');+ assert.equal(receipt.started, realPs.canonicalStarted, 'the accepted identity uses normalized real lstart fields');+ assert.equal(receipts.some(row => row.type === 'worker-identity-unavailable' && row.pid === process.pid), false);+});+`);+ stageFixtureTests(fixture.root, ['test/worker-start.test.js']);+ writeFileSync(preload, `import childProcess from 'node:child_process';+import { syncBuiltinESMExports } from 'node:module';+import { appendFileSync } from 'node:fs';+if (process.argv[1] !== ${JSON.stringify(fixture.runner)}) {+ const originalExec = childProcess.execFile;+ let pidQueries = 0;+ childProcess.execFile = (command, args, options, callback) => {+ if (command === 'ps' && args?.[0] === '-axo') {+ const error = new Error('simulated full process census exceeded execFile maxBuffer');+ error.code = 'ERR_CHILD_PROCESS_STDIO_MAXBUFFER';+ setImmediate(() => callback(error, '', ''));+ return undefined;+ }+ if (command === 'ps' && args?.[0] === '-p') {+ pidQueries += 1;+ appendFileSync(${JSON.stringify(calls)}, JSON.stringify({ type: 'pid-query', pid: process.pid, args }) + '\\n');+ if (pidQueries === 1) {+ const wrongPid = process.pid + 1;+ const row = [wrongPid, process.ppid, process.pid, 'S', 'Thu Oct 2 12:34:56 2026'].join(' ');+ appendFileSync(${JSON.stringify(calls)}, JSON.stringify({ type: 'wrong-pid-control', pid: process.pid, row }) + '\\n');+ setImmediate(() => callback(null, row + '\\n', ''));+ return undefined;+ }+ return originalExec(command, args, options, (error, stdout, stderr) => {+ if (error) { callback(error, stdout, stderr); return; }+ const match = stdout.trim().match(/^(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\S+)\\s+(.+)$/u);+ if (!match) { callback(new Error('real ps returned an unexpected PID identity row'), stdout, stderr); return; }+ const canonicalStarted = match[5].trim().split(/\\s+/u).join(' ');+ const widenedStarted = match[5].trim().replace(/\\s+/gu, ' ');+ appendFileSync(${JSON.stringify(calls)}, JSON.stringify({ type: 'real-ps-control', pid: Number(match[1]),+ canonicalStarted, widenedStarted }) + '\\n');+ callback(null, [match[1], match[2], match[3], match[4], widenedStarted].join(' ') + '\\n', stderr);+ });+ }+ return originalExec(command, args, options, callback);+ };+ syncBuiltinESMExports();+}+`);+ const env = { ...process.env, PULLBOARD_LANDING_RUN: '1', PULLBOARD_C7_SNAPSHOT_CALLS: calls,+ PULLBOARD_MACHINE_HOME: join(fixture.root, 'machine'),+ NODE_OPTIONS: [process.env.NODE_OPTIONS, '--import=' + pathToFileURL(preload).href].filter(Boolean).join(' ') };+ // The copied CLI is standalone; inherited test-worker context selects Node's binary event reporter.+ delete env.NODE_TEST_CONTEXT;+ for (const key of ['PULLBOARD_GATE_SLOT_HELD', 'PULLBOARD_GATE_SLOT_POOL', 'PULLBOARD_GATE_SLOT_TOKEN', 'PULLBOARD_BROWSER_SLOT_HELD']) delete env[key];+ const result = runFixtureChild(process.execPath, [fixture.runner, 'test/worker-start.test.js'], {+ cwd: fixture.root, env, encoding: 'utf8', timeout: 25_000,+ });+ assert.equal(result.status, 0, `${result.context}\n${result.stdout ?? ''}\n${result.stderr ?? ''}`);+ assert.match(result.stdout, /# fail 0/u);+ assert.match(result.stdout, /^ok \d+ - worker identity is recorded before the file body$/mu,+ 'the nested worker test ran and recorded identity before its body');+ const queries = readFileSync(calls, 'utf8').trim().split(/\r?\n/u).filter(Boolean).map(line => JSON.parse(line));+ const compactQueries = queries.filter(row => row.type === 'pid-query');+ const workerPid = compactQueries[0]?.pid;+ assert.ok(workerPid && compactQueries.length >= 2, 'a mismatched first row caused another compact identity query');+ assert.ok(compactQueries.every(row => row.args[1] === String(workerPid)+ && row.args[3] === 'pid=,ppid=,pgid=,stat=,lstart='),+ 'the worker requested only its own compact process identity row');+ assert.ok(queries.some(row => row.type === 'wrong-pid-control'+ && row.row.startsWith(`${workerPid + 1} `) && row.row.includes('Oct 2 ')),+ 'the fixture supplied a parseable row with legal single-digit-day spacing for the wrong PID');+});diff --git a/test/run-tests.test.js b/test/run-tests.test.jsindex efabffe9..3889c6e2 100644--- a/test/run-tests.test.js+++ b/test/run-tests.test.js@@ -7,6 +7,7 @@ import { basename, delimiter, dirname, join } from 'node:path';import { fileURLToPath, pathToFileURL } from 'node:url';import { test } from 'node:test';import { startFixtureChild, runFixtureChild, runFixtureGit } from './fixture-child.js';+import { stageFixtureTests } from './run-tests-fixture.js';import { listResources } from '../src/resources.js';const runner = fileURLToPath(new URL('../bin/run-tests.js', import.meta.url));@@ -14,12 +15,6 @@ const shardFileCount = 9;const fixtureExitCeilingMs = '500';const fixtureCleanupMs = '100';-/** Initialize a private fixture repository and stage exactly its intended tests. */-function stageFixtureTests(root, paths) {- execFileSync('git', ['init', '-q'], { cwd: root, stdio: 'ignore' });- execFileSync('git', ['add', '--', ...paths], { cwd: root, stdio: 'ignore' });-}-/** Treat a reaped or zombie fixture PID as drained while waiting for it to stop executing. */async function waitForFixtureProcessDrain(pid, timeoutMs = 2000) {const deadline = Date.now() + timeoutMs;@@ -386,7 +381,7 @@ if (process.argv[1] !== ${JSON.stringify(fixture.runner)}) {const originalExec = childProcess.execFile;let injected = false;function shouldTimeout(command, args) {- if (injected || command !== 'ps' || args?.[0] !== '-axo') return false;+ if (injected || command !== 'ps' || args?.[0] !== '-p' || args?.[1] !== String(process.pid)) return false;injected = true;writeFileSync(${JSON.stringify(injected)}, JSON.stringify({ pid: process.pid, stack: new Error().stack }));return true;@@ -476,7 +471,7 @@ if (process.argv[1]?.endsWith('/worker-start.test.js')) {const originalExec = childProcess.execFile;let injections = 0;function failWorkerSnapshot(command, args) {- if (command !== 'ps' || args?.[0] !== '-axo') return false;+ if (command !== 'ps' || args?.[0] !== '-p' || args?.[1] !== String(process.pid)) return false;injections += 1;writeFileSync(${JSON.stringify(injected)}, JSON.stringify({ pid: process.pid, args, injections }));return true;@@ -680,7 +675,8 @@ if (process.argv[1] === runner) {} else if (process.argv[1] === workerTest) {const original = childProcess.execFile;childProcess.execFile = (command, args, options, callback) => {- if (command === 'ps' && args?.[0] === '-axo') {+ if (command === 'ps' && args?.[0] === '-p' && args?.[1] === String(process.pid)+ && args?.[3] === 'pid=,ppid=,pgid=,stat=,lstart=') {writeFileSync(${JSON.stringify(workerInjected)}, 'injected');const error = new Error('injected persistent worker census failure'); error.code = 'ETIMEDOUT';setImmediate(() => callback(error, '', ''));