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
test(runners): time paired dispatch after accepted receipt [C7]
Corey Olsona64f3115719c
diff --git a/test/runner-paired-rerun-fixture.js b/test/runner-paired-rerun-fixture.jsindex 9072ab24..80caebb1 100644--- a/test/runner-paired-rerun-fixture.js+++ b/test/runner-paired-rerun-fixture.js@@ -46,13 +46,18 @@ test('remote flaky case', () => { const n = existsSync(${JSON.stringify(runs)})agent: 'flake-local-holder', item: 'flake-local-holder', kind: 'force-registered-runner' });try {const requests = join(box.dir, 'requests.jsonl');+ const evidence = join(repo, '.git', 'pullboard', 'flake-evidence');+ // Native diagnostics writes this only after the controller has validated and consumed the+ // first result, before preparing the required pair. A held SSH result never creates it.+ const firstReceiptAccepted = mode === 'no-load' ? null : () => existsSync(evidence)+ && readdirSync(evidence).some(id => existsSync(join(evidence, id, 'original.log')));const before = { dispatched: 0, returned: 0 };const cpuStartedAt = Date.now();const run = observe(startToolingCli(repo, env, ['gate', '--json'], { detached: true }));if (hold) {const startedAt = Date.now();let failure;- try { await awaitRoundTrip(run.child, run.closed, requests + '.phases', before); }+ try { await awaitRoundTrip(run.child, run.closed, requests + '.phases', before, ROUND_TRIP_DEADLINES, firstReceiptAccepted); }catch (error) { failure = error; }assert.ok(failure, 'a runner that withholds the result stays a named deadline failure');assert.match(failure.message, /runner round trip stuck in phase "result return"/u,@@ -74,13 +79,12 @@ test('remote flaky case', () => { const n = existsSync(${JSON.stringify(runs)})assert.deepEqual(processesUnder(box.dir), [], 'nothing from the held result-return phase keeps running');return { held: true };}- const finished = await awaitRoundTrip(run.child, run.closed, requests + '.phases', before);+ const finished = await awaitRoundTrip(run.child, run.closed, requests + '.phases', before, ROUND_TRIP_DEADLINES, firstReceiptAccepted);if (cpuLoad) await cpuLoad.assertProgress(cpuStartedAt, Date.now());assert.equal(finished.status, 1, 'the original red stays the gate result');const pairedCalls = mode === 'no-load' ? 1 : 2;assert.deepEqual(phaseCounts(requests + '.phases'), { dispatched: pairedCalls, returned: pairedCalls },'the red check and required paired rerun each complete their runner round trip');- const evidence = join(repo, '.git', 'pullboard', 'flake-evidence');const [observation] = readdirSync(evidence).map(id => JSON.parse(readFileSync(join(evidence, id, 'observation.json'), 'utf8')));assert.equal(observation.main, box.git(repo, 'rev-parse', 'HEAD'), 'the pinned main is recorded');if (mode === 'remote-load') {@@ -129,6 +133,36 @@ setTimeout(() => {rmSync(root, { recursive: true, force: true });}}++/** A consumed first receipt starts the next dispatch clock, while an undelivered receipt never does. */+export async function assertRedispatchDeadlineAccounting({ phaseCounts, awaitRoundTrip, stopGroup }) {+ const root = realpathSync(mkdtempSync(join(tmpdir(), 'pullboard-redispatch-')));+ const phases = join(root, 'phases');+ const accepted = join(root, 'accepted-receipt');+ const before = phaseCounts(phases);+ const script = `const { appendFileSync, writeFileSync } = require('node:fs');+const phases = ${JSON.stringify(phases)};+appendFileSync(phases, 'dispatched\\n');+setTimeout(() => {+ appendFileSync(phases, 'returned\\n');+ writeFileSync(${JSON.stringify(accepted)}, 'controller accepted first receipt');+ setTimeout(() => {+ appendFileSync(phases, 'dispatched\\n');+ setTimeout(() => appendFileSync(phases, 'returned\\n'), 100);+ }, 900);+}, 100);`;+ const run = runFixtureChildAsync(process.execPath, ['-e', script], { cwd: root, detached: true });+ try {+ const result = await awaitRoundTrip(run.child, run, phases, before,+ { dispatch: 1_500, 'remote run': 1_500, 'result return': 400 },+ () => existsSync(accepted));+ assert.equal(result.status, 0, result.context);+ assert.deepEqual(phaseCounts(phases), { dispatched: 2, returned: 2 });+ } finally {+ if (run.child.pid && run.child.exitCode === null && run.child.signalCode === null) await stopGroup(run.child, run);+ rmSync(root, { recursive: true, force: true });+ }+}const READY_TIMEOUT_MS = 10_000;const PROGRESS_TIMEOUT_MS = 15_000;const TERM_DRAIN_MS = 1_000;diff --git a/test/runner-process-group.js b/test/runner-process-group.jsnew file mode 100644index 00000000..b5a5eb6d--- /dev/null+++ b/test/runner-process-group.js@@ -0,0 +1,63 @@+/** Bounded cleanup of the round-trip fixture's owned process group [C7]. */+import assert from 'node:assert/strict';+import { parseProcessCensus } from '../src/process-census.js';+import { runFixtureChild } from './fixture-child.js';++/** Read a complete census; failed or malformed output never proves a group empty. */+function readCensus() {+ const listed = runFixtureChild('/bin/ps', ['-axo', 'pid=,ppid=,pgid=,lstart=,stat=,comm='], { encoding: 'utf8' });+ assert.equal(listed.status, 0, listed.context);+ const rows = parseProcessCensus(listed.stdout);+ assert.ok(rows, 'fixture cleanup needs a complete process census');+ return rows;+}++/** Zombies have finished; any other member still requires cleanup even after the leader closes. */+function liveMembers(census, group) {+ const rows = census();+ assert.ok(rows instanceof Map && rows.size > 0, 'fixture cleanup cannot trust an unavailable census');+ return [...rows.values()].filter(row => row.pgid === group && !/^Z/u.test(row.state));+}++/** An EPERM is harmless only when a fresh census proves no live group member remains. */+export function signalFixtureGroup(group, signal, { kill = process.kill, census = readCensus } = {}) {+ try { kill(-group, signal); }+ catch (error) {+ if (error.code === 'ESRCH') return;+ if (error.code !== 'EPERM' || liveMembers(census, group).length) throw error;+ }+}++/** TERM, then KILL if needed, await close, and prove that the owned group has drained. */+export async function stopGroup(child, closed, { kill = process.kill, census = readCensus } = {}) {+ if (!child.pid) return;+ const options = { kill, census };+ signalFixtureGroup(child.pid, 'SIGTERM', options);+ let timer;+ try {+ await Promise.race([closed, new Promise(resolve => { timer = setTimeout(resolve, 5_000); })]);+ } finally { clearTimeout(timer); }+ if (liveMembers(census, child.pid).length) signalFixtureGroup(child.pid, 'SIGKILL', options);+ try {+ await Promise.race([closed, new Promise((resolve, reject) => {+ timer = setTimeout(() => reject(new Error('fixture group did not close after KILL')), 2_000); // budget: bounded child-close handshake after escalation.+ })]);+ } finally { clearTimeout(timer); }+ const deadline = Date.now() + 2_000;+ while (liveMembers(census, child.pid).length) {+ assert.ok(Date.now() < deadline, `fixture group ${child.pid} retains live members after KILL`);+ await new Promise(resolve => setTimeout(resolve, 50));+ }+}++/** Exercise the observed zombie-only EPERM and refuse both live and unknown group states. */+export function assertFixtureGroupEpermControls() {+ /** Reproduce the operating system's denied process-group signal. */+ const kill = () => { throw Object.assign(new Error('kill EPERM'), { code: 'EPERM' }); };+ /** Keep each census concrete while varying only whether the owned member is live. */+ const row = state => new Map([[41, { pid: 41, pgid: 40, state }]]);+ assert.doesNotThrow(() => signalFixtureGroup(40, 'SIGKILL', { kill, census: () => row('Z') }));+ assert.throws(() => signalFixtureGroup(40, 'SIGKILL', { kill, census: () => row('S') }), /kill EPERM/u);+ assert.throws(() => signalFixtureGroup(40, 'SIGKILL', { kill, census: () => null }), /unavailable census/u);+ assert.throws(() => signalFixtureGroup(40, 'SIGKILL', { kill, census: () => { throw new Error('ps failed'); } }), /ps failed/u);+}diff --git a/test/runners.test.js b/test/runners.test.jsindex ce2c2e07..a06bb6af 100644--- a/test/runners.test.js+++ b/test/runners.test.js@@ -13,7 +13,8 @@ import { parseProcessCensus } from '../src/process-census.js';import { listResources as listPreRunnerResources, takeResource as takePreRunnerResource } from './fixtures/resources-pre-runners.js';import { cleanupFixtureChildren, runFixtureChild, runFixtureChildAsync, startFixtureChild } from './fixture-child.js';import { readRemoteGateHolders, waitForCondition } from './runner-fixture-state.js';-import { assertAttemptDeadlineReset, runPairedRerun, startRunnerCpuStandIn } from './runner-paired-rerun-fixture.js';+import { assertAttemptDeadlineReset, assertRedispatchDeadlineAccounting, runPairedRerun, startRunnerCpuStandIn } from './runner-paired-rerun-fixture.js';+import { assertFixtureGroupEpermControls, stopGroup } from './runner-process-group.js';import { parentDeathDrainFixture } from './runner-parent-death-fixture.js';import { createE2eHelpers } from './e2e-helpers.js';import { refuseSandboxBlocked } from '../src/gate.js';@@ -226,15 +227,6 @@ function phaseCounts(file) {return { dispatched: lines.filter(line => line === 'dispatched').length, returned: lines.filter(line => line === 'returned').length };}-/** Stop a detached fixture child's whole process group, escalating if TERM is ignored. */-async function stopGroup(child, closed) {- const signal = name => { try { process.kill(-child.pid, name); } catch (error) { if (error.code !== 'ESRCH') throw error; } };- signal('SIGTERM');- const settled = await Promise.race([closed.then(() => true), new Promise(resolve => setTimeout(() => resolve(false), 5_000))]); // budget: TERM grace before KILL.- signal('SIGKILL');- if (!settled) await closed;-}-/*** Wait for a runner round trip phase by phase: dispatch (until the stand-in is reached), remote run* (until the worker returns) and result return (until the controller exits). A phase past its@@ -243,7 +235,7 @@ async function stopGroup(child, closed) {* passes the marker counts it read before spawning the child: a fast child can dispatch before this* function first runs, and a baseline read here would swallow that dispatch.*/-async function awaitRoundTrip(child, closed, phasesFile, before, deadlines = ROUND_TRIP_DEADLINES) {+async function awaitRoundTrip(child, closed, phasesFile, before, deadlines = ROUND_TRIP_DEADLINES, firstReceiptAccepted = null) {const limits = { ...ROUND_TRIP_DEADLINES, ...deadlines };let done = null;closed.then(result => { done = result; });@@ -256,7 +248,10 @@ async function awaitRoundTrip(child, closed, phasesFile, before, deadlines = ROUwhile (!done) {const total = phasesFile ? phaseCounts(phasesFile) : { dispatched: 0, returned: 0 };const counts = phasesFile ? { dispatched: total.dispatched - before.dispatched, returned: total.returned - before.returned } : total;- const next = counts.dispatched > counts.returned ? 'remote run' : counts.dispatched > 0 ? 'result return' : 'dispatch';+ // The observer saves the accepted first receipt before preparing its paired dispatch. That real+ // controller-side witness ends result delivery; a worker's "returned" marker alone cannot do so.+ const redispatch = counts.dispatched === 1 && counts.returned === 1 && firstReceiptAccepted?.();+ const next = redispatch ? 'dispatch' : counts.dispatched > counts.returned ? 'remote run' : counts.dispatched > 0 ? 'result return' : 'dispatch';// A returned attempt and its paired dispatch can arrive in one poll without changing the phase's name.// Each real marker advance starts a fresh clock, while a phase with no new marker remains bounded.if (next !== phase || counts.dispatched > observed.dispatched || counts.returned > observed.returned) {@@ -1936,6 +1931,8 @@ test('a red on a registered runner gets its paired rerun and ledger entry, or sttest('the runner round trip deadline holds under a loaded test machine and still catches a stuck phase [C7]',{ timeout: 660_000 }, async t => { // budget: five real paired attempts plus a bounded held phase, below the file hang ceiling.await assertAttemptDeadlineReset(PAIRED_RERUN_FIXTURE);+ await assertRedispatchDeadlineAccounting(PAIRED_RERUN_FIXTURE);+ assertFixtureGroupEpermControls();const busy = await startRunnerCpuStandIn();t.after(busy.stop);assert.equal(busy.count, Math.max(1, Math.floor(busy.cores / 2)), 'the fixture owns one busy child for each half-core slot');