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(tests): report later spawn snapshot uncertainty [C7,V4]

Corey Olson0ae700dbea64
diff --git a/bin/run-tests.js b/bin/run-tests.js
index dd6c1ce7..2facab04 100644
--- a/bin/run-tests.js
+++ b/bin/run-tests.js
@@ -563,8 +563,8 @@ function landingChildCommandMatchesSpawn(processInfo, receipt) {
});
}
-/** Keep the established healthy-worker path: snapshot only detached children at spawn time. */
-function watchLandingChildSpawns(startsPath, attempt) {
+/** Snapshot detached children at spawn time, retaining worker uncertainty when that snapshot fails. */
+function watchLandingChildSpawns(startsPath, attempt, file = null) {
let recording = false;
channel('child_process').subscribe(({ process: child }) => {
if (recording || !child || typeof child.once !== 'function') return;
@@ -579,7 +579,18 @@ function watchLandingChildSpawns(startsPath, attempt) {
appendFileSync(startsPath, `${JSON.stringify({ type: 'child', attempt, parentPid: process.pid,
pid: spawned.pid, pgid: spawned.pgid, started: spawned.started })}\n`);
}
- } catch { /* The ancestry monitor remains the fallback if a receipt cannot be written. */ }
+ } catch (error) {
+ // A worker can exit before the next ancestry census; absence then cannot prove its children drained.
+ if (!file) return;
+ const code = String(error?.code ?? 'snapshot-error').replace(/[\u0000-\u001f\u007f]/gu, ' ').slice(0, 80);
+ const reason = String(error?.message ?? error).replace(/[\u0000-\u001f\u007f]/gu, ' ').slice(0, 256);
+ try {
+ appendFileSync(startsPath, `${JSON.stringify({ type: 'child-snapshot-unavailable', attempt,
+ file, parentPid: process.pid, pid: child.pid, code, reason })}\n`);
+ } catch {
+ process.stderr.write(`run-tests: cleanup for ${basename(file)} UNVERIFIED: ${code}: ${reason}; no unverified process was signaled\n`);
+ }
+ }
finally { recording = false; }
});
});
@@ -908,7 +919,8 @@ async function runLandingTests(args, env, concurrency) {
const workerByPid = new Map(workerRoots.map(root => [root.pid, root]));
let unsettledChild = false;
for (const receipt of receipts) {
- if (receipt.type !== 'child-announcement-unavailable' || !selectedFileSet.has(receipt.file)) continue;
+ if (!['child-announcement-unavailable', 'child-snapshot-unavailable'].includes(receipt.type)
+ || !selectedFileSet.has(receipt.file)) continue;
unsettledChild = true;
cleanupUnverifiedFiles.add(receipt.file);
lastCleanupSnapshotError = { code: receipt.code, message: receipt.reason };
@@ -1360,7 +1372,7 @@ if (process.argv[1] && resolve(process.argv[1]) === runner) {
pid: process.pid, parentPid: process.ppid, code, reason })}\n`);
process.stderr.write(`run-tests: worker identity unavailable (${code}): ${reason}\n`);
}
- if (identityAvailable) watchLandingChildSpawns(startsPath, attempt);
+ if (identityAvailable) watchLandingChildSpawns(startsPath, attempt, file);
else watchLandingChildCustody(startsPath, attempt);
}
if (process.env.PULLBOARD_TEST_BROWSER_RESOURCE && process.env.NODE_TEST_CONTEXT === 'child-v8'
diff --git a/test/run-tests.test.js b/test/run-tests.test.js
index 40427445..aee70bfd 100644
--- a/test/run-tests.test.js
+++ b/test/run-tests.test.js
@@ -564,6 +564,70 @@ if (process.argv[1]?.endsWith('/worker-start.test.js')) {
assert.ok(await waitForFixtureIdentityDrain(childIdentity), 'the owned child stopped before the fixture returned');
});
+test('a later spawn-time ps failure names unverified cleanup [C7,V4]', t => {
+ const fixture = makeShardFixture(t);
+ const workerTest = join(fixture.root, 'test/spawn-snapshot.test.js');
+ const injected = join(fixture.root, 'spawn-snapshot-injected.json');
+ const journal = join(fixture.root, 'spawn-snapshot-journal.json');
+ const preload = join(fixture.root, 'spawn-snapshot-failure.mjs');
+ writeFileSync(workerTest, `import assert from 'node:assert/strict';
+import { spawn } from 'node:child_process';
+import { once } from 'node:events';
+import { readFileSync, writeFileSync } from 'node:fs';
+import { test } from 'node:test';
+test('a healthy worker completes after its spawn snapshot fails', async () => {
+ const starts = process.env.PULLBOARD_LANDING_WORKER_STARTS;
+ const before = readFileSync(starts, 'utf8').trim().split(/\\r?\\n/u).map(line => JSON.parse(line));
+ assert.ok(before.some(row => row.type === 'worker' && row.pid === process.pid), 'startup identity succeeded before the injected failure');
+ const child = spawn(process.execPath, ['-e', 'process.exit(0)'], { detached: true, stdio: 'ignore' });
+ const [code] = await once(child, 'exit');
+ assert.equal(code, 0, 'the fixture child drains itself without runner cleanup');
+ writeFileSync(${JSON.stringify(journal)}, JSON.stringify({ pid: process.pid, childPid: child.pid,
+ rows: readFileSync(starts, 'utf8').trim().split(/\\r?\\n/u).map(line => JSON.parse(line)) }));
+});
+`);
+ writeFileSync(preload, `import childProcess from 'node:child_process';
+import { syncBuiltinESMExports } from 'node:module';
+import { writeFileSync } from 'node:fs';
+if (process.argv[1] === ${JSON.stringify(workerTest)}) {
+ const original = childProcess.execFileSync;
+ let injected = false;
+ childProcess.execFileSync = (command, args, options) => {
+ if (!injected && command === 'ps' && args?.[0] === '-axo') {
+ injected = true;
+ writeFileSync(${JSON.stringify(injected)}, JSON.stringify({ stack: new Error().stack }));
+ const error = new Error('injected later spawn snapshot failure');
+ error.code = 'EIO';
+ throw error;
+ }
+ return original(command, args, options);
+ };
+ syncBuiltinESMExports();
+}
+`);
+ const env = { ...process.env, PULLBOARD_LANDING_RUN: '1',
+ PULLBOARD_MACHINE_HOME: join(fixture.root, 'machine'),
+ NODE_OPTIONS: [process.env.NODE_OPTIONS, '--import=' + pathToFileURL(preload).href].filter(Boolean).join(' ') };
+ 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/spawn-snapshot.test.js'], {
+ cwd: fixture.root, env, encoding: 'utf8', timeout: 25000,
+ });
+ const output = `${result.stdout ?? ''}\n${result.stderr ?? ''}`;
+ assert.equal(result.status, 0, `${result.context}\n${output}`);
+ assert.match(output, /# fail 0/u, 'cleanup uncertainty does not change the passing test outcome');
+ assert.match(JSON.parse(readFileSync(injected, 'utf8')).stack, /landingProcessTable/u,
+ 'the injected failure came from the synchronous spawn census after healthy startup');
+ const receipt = JSON.parse(readFileSync(journal, 'utf8'));
+ const unavailable = receipt.rows.find(row => row.type === 'child-snapshot-unavailable'
+ && row.parentPid === receipt.pid && row.pid === receipt.childPid && row.file === workerTest);
+ assert.ok(unavailable, 'the worker publishes cleanup uncertainty before it can exit');
+ assert.equal(unavailable.code, 'EIO');
+ assert.equal(unavailable.reason, 'injected later spawn snapshot failure');
+ assert.match(output, /cleanup for spawn-snapshot\.test\.js UNVERIFIED: EIO: injected later spawn snapshot failure; no unverified process was signaled/u,
+ 'the parent retains the worker failure and names the affected file and reason');
+ assert.equal((output.match(/cleanup for .* UNVERIFIED/gu) ?? []).length, 1, 'cleanup uncertainty is reported once');
+});
+
test('tests continue when worker and parent identity censuses stay unavailable [C7,V4]', async t => {
const fixture = makeShardFixture(t);
const workerTest = join(fixture.root, 'test/worker-unverified.test.js');