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(gate): sharded landings class runner refusals by code [C7,V4]

Corey Olson0c9e8dab12ef
diff --git a/docs/api.md b/docs/api.md
index afe84616..b3474563 100644
--- a/docs/api.md
+++ b/docs/api.md
@@ -334,7 +334,7 @@ Row approval and decline first record the person's exact decision through the sa
The landing gate sets `PULLBOARD_LANDING_RUN=1` only for its test runner. In that mode, the runner requires process isolation and POSIX process identities; it stops scheduling files after the first test-file failure, interrupts files already running, and reports the failure, interrupted files, and selected files not run. Landing early-stop fails before starting tests on Windows because the runner cannot safely identify and drain owned worker descendants there. It uses Node's execution-ordered test completion events; ordinary focused runs and all non-landing gates keep normal scheduling. The runner clears this marker for test workers and nested commands. If a process-identity census stays unavailable, tests still determine the gate result; the runner reports cleanup as `UNVERIFIED` and does not signal processes whose identity it could not establish. A `UNVERIFIED` cleanup report means descendant cleanup was not confirmed.
-With `landingShards: N` in `pullboard.json` (a whole number from 1 to 64; absent or 1 keeps one run), the landing run of `bin/run-tests.js` splits the tracked test files into N shards. It balances them by each file's wall time from the last sharded landing, kept in the repository's `pullboard/landing-file-times.json`; with no times it balances by file count. The first shard uses the gate's own slot. Each other shard takes a landing-priority gate slot, locally or on a registered runner. The run is green only if every shard is green. The first red shard stops the others, which are reported as `stopped`. A shard whose runner fails mid-run prints `landing shard <i>/<n>: runner <host> failed mid-shard; rerunning shard <i>/<n> locally` and reruns on a local slot. The merged log prints one `# landing shard <i>/<n> on <host>: <green|red|stopped> in <ms> ms` line per shard and one `# landing file <i>/<n> <host> <ms|-> <path>` line per file. It also names how the plan was balanced (`history`, `history and average` or `file count`) and, once history exists, the slowest recorded file as `# landing floor: <ms> ms <path>`, since no shard count can finish sooner. The gate profile carries the same fields as `landingShards.balance`, `landingShards.floor`, `landingShards.shards` and `landingShards.files`. Every shard takes any free gate slot, so a runner with two slots can run two shards, and each local shard needing Chrome still waits for the machine's `browserSlots`.
+With `landingShards: N` in `pullboard.json` (a whole number from 1 to 64; absent or 1 keeps one run), the landing run of `bin/run-tests.js` splits the tracked test files into N shards. It balances them by each file's wall time from the last sharded landing, kept in the repository's `pullboard/landing-file-times.json`; with no times it balances by file count. The first shard uses the gate's own slot. Each other shard takes a landing-priority gate slot, locally or on a registered runner. The run is green only if every shard is green. The first red shard stops the others, which are reported as `stopped`. A shard whose runner fails mid-run prints `landing shard <i>/<n>: runner <host> failed mid-shard; rerunning shard <i>/<n> locally` and reruns on a local slot. Runner refusals are classed by code. `RUNNER_SETUP_REFUSED` and `RESOURCE_LEASE_LOST` rerun locally, with the code and host in the log. `RUNNER_CLEANUP_TIMEOUT` reruns locally and also quarantines that host for the rest of the landing, printing `landing runner <host> quarantined for the rest of this landing: <message>`. `RUNNER_SOURCE_CHANGED` and any unknown code fail the landing red as `refused`, with no retry. The merged log prints one `# landing shard <i>/<n> on <host>: <green|red|stopped> in <ms> ms` line per shard and one `# landing file <i>/<n> <host> <ms|-> <path>` line per file. It also names how the plan was balanced (`history`, `history and average` or `file count`) and, once history exists, the slowest recorded file as `# landing floor: <ms> ms <path>`, since no shard count can finish sooner. The gate profile carries the same fields as `landingShards.balance`, `landingShards.floor`, `landingShards.shards` and `landingShards.files`. Every shard takes any free gate slot, so a runner with two slots can run two shards, and each local shard needing Chrome still waits for the machine's `browserSlots`.
Only the person can run `pullboard land --waive <test> --until <date> --reason "why"`. A waiver retains every test in the full gate. The batch records its exact tree and each failing test with its covering live waiver; pre-push validates that distinct proof and creates no ordinary green stamp. Expired waivers cannot authorize a push. Existing gate-stamped pushes and `pullboard merged` remain available.
diff --git a/src/gate.js b/src/gate.js
index 60e794fc..07324c44 100644
--- a/src/gate.js
+++ b/src/gate.js
@@ -310,6 +310,8 @@ export function writeTimingProfile(path, profile) {
...(profile.executionRunner ? { executionRunner: sanitize(profile.executionRunner, 'execution runner') } : {}),
...(profile.landingShards ? { landingShards: {
balance: sanitize(String(profile.landingShards.balance ?? 'unknown'), 'landing balance'),
+ quarantined: (profile.landingShards.quarantined ?? []).map(entry => ({ host: sanitize(String(entry.host), 'landing quarantine host'),
+ message: sanitize(String(entry.message), 'landing quarantine message') })),
floor: profile.landingShards.floor && validDuration(profile.landingShards.floor.ms)
? { path: sanitize(String(profile.landingShards.floor.path), 'landing floor path'), ms: profile.landingShards.floor.ms } : null,
// One entry per attempt, so a failed runner attempt stays beside its local rerun.
diff --git a/src/landing-shards.js b/src/landing-shards.js
index e15a7442..f5388fd4 100644
--- a/src/landing-shards.js
+++ b/src/landing-shards.js
@@ -162,6 +162,27 @@ async function runLocalShard({ root, runner, files, label, lease, stop }) {
return { isGreen: status === 0 && !signal, output: chunks.join('') };
}
+/** Runner refusals that mean the host could not run the shard right now, so a local rerun is sound. */
+const RERUN_REFUSALS = new Set(['RUNNER_SETUP_REFUSED', 'RESOURCE_LEASE_LOST']);
+
+/**
+ * How a sharded landing answers a runner that gave no test result. A lost host or transport, or a
+ * setup the runner's own pool refused (#690), reruns the shard locally. An unverified cleanup also
+ * reruns locally, but takes that host out of this landing. Changed source means the code under test
+ * drifted, so the landing fails; so does any refusal this does not know, with no silent retry.
+ *
+ * @param {unknown} error
+ * @param {{ RunnerDropped: Function, Refused: Function }} kinds
+ * @returns {{ action: 'rerun'|'quarantine'|'fail', reason: string, code: string|null }|null} null when it is not a runner answer at all.
+ */
+export function runnerFailureClass(error, { RunnerDropped, Refused }) {
+ if (error instanceof RunnerDropped) return { action: 'rerun', reason: 'runner transport lost', code: null };
+ if (!(error instanceof Refused)) return null;
+ if (RERUN_REFUSALS.has(error.code)) return { action: 'rerun', reason: `runner refused: ${error.code}`, code: error.code };
+ if (error.code === 'RUNNER_CLEANUP_TIMEOUT') return { action: 'quarantine', reason: `runner refused: ${error.code}`, code: error.code };
+ return { action: 'fail', reason: `runner refused: ${error.code}`, code: error.code };
+}
+
/** A shard's acquisition stopped waiting because the shard ran elsewhere or the landing stopped. */
class NotNeeded extends Error {}
@@ -183,9 +204,13 @@ class NotNeeded extends Error {}
* holds; `write` receives the merged log.
* @returns {Promise<{ isGreen: boolean, balance: string, shards: object[], files: object[] }>}
*/
-export async function runLandingShards({ root, runner, files, count, inherited = null, needsBrowser = async () => true, write = text => process.stdout.write(text) }) {
+export async function runLandingShards({ root, runner, files, count, inherited = null, needsBrowser = async () => true, write = text => process.stdout.write(text), remoteRun }) {
const { withGateSlot } = await import('./gate.js');
- const { RunnerDropped, runOnRunnerAsync } = await import('./runners.js');
+ const runners = await import('./runners.js');
+ const { RunnerDropped } = runners;
+ // A test may stand in for the SSH round trip to make a runner answer with a given refusal.
+ const runOnRunnerAsync = remoteRun ?? runners.runOnRunnerAsync;
+ const quarantined = new Map();
const { Refused } = await import('./refused.js');
const history = readFileTimes(root);
const plan = planLandingShards(files, count, history);
@@ -225,12 +250,18 @@ export async function runLandingShards({ root, runner, files, count, inherited =
} catch (error) {
// A stop ends the runner's transport on purpose; that shard was stopped, not dropped.
if (stop.aborted) return { attempt: number, host: lease.runner.host, outcome: 'stopped', output: '', wallMs: Date.now() - started };
- // Infrastructure, not a test result: the runner could not give this shard a complete answer.
- if (error instanceof RunnerDropped || error instanceof Refused) {
- const reason = error instanceof RunnerDropped ? 'runner transport lost' : `runner refused: ${error.code}`;
- return { attempt: number, host: lease.runner.host, outcome: 'infrastructure', reason, output: '', wallMs: Date.now() - started };
+ const failure = runnerFailureClass(error, { RunnerDropped, Refused });
+ if (!failure) throw error;
+ const host = lease.runner.host;
+ const message = error instanceof Refused ? error.message : '';
+ if (message) write(`landing shard ${entry.label}: runner ${host} refused it: ${message}\n`);
+ if (failure.action === 'quarantine' && !quarantined.has(host)) {
+ quarantined.set(host, message);
+ write(`landing runner ${host} quarantined for the rest of this landing: ${message}\n`);
}
- throw error;
+ // Infrastructure, not a test result: the runner could not give this shard a complete answer.
+ return { attempt: number, host, outcome: failure.action === 'fail' ? 'refused' : 'infrastructure', reason: failure.reason,
+ output: '', wallMs: Date.now() - started };
}
};
@@ -249,7 +280,7 @@ export async function runLandingShards({ root, runner, files, count, inherited =
} else {
entry.done = true;
entry.status = status;
- if (status === 'red') {
+ if (status === 'red' || status === 'refused') {
firstFailure = entry.label;
stopper.abort();
}
@@ -279,10 +310,17 @@ export async function runLandingShards({ root, runner, files, count, inherited =
const localOnly = entry.localOnly;
const running = withGateSlot(root, async lease => {
if (entry.claimed || entry.done) return;
+ // A host quarantined in this landing gets no more shards; queue again for a local slot.
+ if (lease.runner && quarantined.has(lease.runner.host)) return 'divert';
entry.claimed = true;
await runOnLease(entry, lease);
}, { landing: true, browser: entry.browser, remote: !localOnly, kind: 'landing', item: `shard ${entry.label}`,
onWait: () => { if (entry.claimed || entry.done || stop.aborted) throw new NotNeeded(); } });
+ running.then(result => {
+ if (result !== 'divert' || entry.claimed || entry.done) return;
+ entry.localOnly = true;
+ acquire(entry);
+ }, () => {});
running.catch(error => {
if (error instanceof NotNeeded) {
// A stopped shard that was only waiting for a slot is recorded as stopped here.
@@ -344,17 +382,20 @@ export function landingShardProfile(output) {
const files = [];
let balance = null;
let floor = null;
+ const quarantined = [];
for (const line of String(output).split(/\r?\n/u)) {
const plan = /^# landing shards: \d+ balanced by (history|history and average|file count) \(/u.exec(line);
if (plan) balance = plan[1];
+ const held = /^landing runner (\S+) quarantined for the rest of this landing: (.*)$/u.exec(line);
+ if (held) quarantined.push({ host: held[1], message: held[2] });
const slowest = /^# landing floor: (\d+) ms (.+)$/u.exec(line);
if (slowest) floor = { path: slowest[2], ms: Number(slowest[1]) };
- const shard = /^# landing shard (\d+\/\d+) attempt (\d+) on (\S+): (green|red|stopped|infrastructure)(?: \(([^)]*)\))? in (\d+) ms$/u.exec(line);
+ const shard = /^# landing shard (\d+\/\d+) attempt (\d+) on (\S+): (green|red|stopped|infrastructure|refused)(?: \(([^)]*)\))? in (\d+) ms$/u.exec(line);
if (shard) shards.push({ shard: shard[1], attempt: Number(shard[2]), host: shard[3], status: shard[4], reason: shard[5] ?? null, wallMs: Number(shard[6]) });
const file = /^# landing file (\d+\/\d+) (\S+) (\d+|-) (.+)$/u.exec(line);
if (file) files.push({ path: file[4], shard: file[1], host: file[2], durationMs: file[3] === '-' ? null : Number(file[3]) });
}
- return shards.length ? { balance, floor, shards, files } : null;
+ return shards.length ? { balance, floor, quarantined, shards, files } : null;
}
/** Print this shard's per-file wall times for its orchestrator; a missing record prints nothing. */
diff --git a/test/landing-shards.test.js b/test/landing-shards.test.js
index 3f2068ed..97bf6968 100644
--- a/test/landing-shards.test.js
+++ b/test/landing-shards.test.js
@@ -267,3 +267,89 @@ test('a landing gate split into shards reports one result [C7,V4]', { timeout: 3
assert.equal(Object.keys(mergedFiles(landing.output)).length, 6);
}
});
+
+/**
+ * Run a sharded landing in a child process where the SSH round trip is replaced by one that answers
+ * every runner call with `answer` (a refusal code, or DROPPED for a lost transport).
+ */
+async function landingWithRunnerAnswer(box, answer, count, deadlineMs) {
+ const url = name => JSON.stringify(pathToFileURL(join(SOURCE, 'src', name)).href);
+ const files = NAMES.map(name => `./test/${name}.test.js`);
+ const script = `const { runLandingShards, landingShardProfile } = await import(${url('landing-shards.js')});
+const { Refused } = await import(${url('refused.js')});
+const { RunnerDropped } = await import(${url('runners.js')});
+const answer = ${JSON.stringify(answer)};
+const calls = [];
+const remoteRun = async (_root, _command, options) => {
+ calls.push(options.runner.host);
+ if (answer === 'DROPPED') throw new RunnerDropped(options.runner.host);
+ throw new Refused(answer, 'runner ' + options.runner.host + ' answered ' + answer + '; inspect job fixture-job under its runner namespace before another run');
+};
+const chunks = [];
+const result = await runLandingShards({ root: ${JSON.stringify(box.repo)}, runner: ${JSON.stringify(join(box.repo, 'bin', 'run-tests.js'))},
+ files: ${JSON.stringify(files)}, count: ${count}, remoteRun, write: text => chunks.push(text) });
+const output = chunks.join('');
+process.stdout.write(JSON.stringify({ isGreen: result.isGreen, output, calls, profile: landingShardProfile(output) }));`;
+ const env = { ...box.env };
+ delete env.NODE_TEST_CONTEXT;
+ const child = spawn(process.execPath, ['--input-type=module', '-e', script], { cwd: box.repo, env, detached: true, stdio: ['ignore', 'pipe', 'pipe'] });
+ let stdout = '';
+ let stderr = '';
+ child.stdout.setEncoding('utf8').on('data', part => { stdout += part; });
+ child.stderr.setEncoding('utf8').on('data', part => { stderr += part; });
+ const closed = new Promise(resolveClose => child.once('close', status => resolveClose({ status })));
+ let timer;
+ const ended = await Promise.race([closed, new Promise(resolveDeadline => { timer = setTimeout(() => resolveDeadline(null), deadlineMs); })]);
+ clearTimeout(timer);
+ if (!ended) {
+ for (const signal of ['SIGTERM', 'SIGKILL']) { try { process.kill(-child.pid, signal); } catch { /* already gone */ } }
+ await closed;
+ throw new Error(`runner answer "${answer}" passed its ${deadlineMs} ms deadline\n${stderr.slice(-4_000)}`);
+ }
+ assert.equal(ended.status, 0, `runner answer "${answer}": the landing process failed\n${stderr.slice(-4_000)}`);
+ return JSON.parse(stdout);
+}
+
+test('a runner refusal in a sharded landing is handled by its class [C7,V4]', { timeout: 300_000 }, async (t) => { // budget: five bounded landings on one fixture.
+ const box = fixture();
+ t.after(() => rmSync(box.dir, { recursive: true, force: true }));
+ scenario(box, 'green');
+ const rerunLine = /^landing shard (\d\/\d): runner fixture-host failed mid-shard; rerunning shard \1 locally$/mu;
+
+ // 1. A lost host or transport reruns the shard locally, named.
+ const dropped = await landingWithRunnerAnswer(box, 'DROPPED', 3, 120_000);
+ assert.equal(dropped.isGreen, true, dropped.output);
+ assert.match(dropped.output, rerunLine);
+ assert.match(dropped.output, /attempt 1 on fixture-host: infrastructure \(runner transport lost\)/u);
+
+ // 2. Changed source: the code under test drifted, so the landing fails by name with no retry.
+ const drifted = await landingWithRunnerAnswer(box, 'RUNNER_SOURCE_CHANGED', 3, 120_000);
+ assert.equal(drifted.isGreen, false, drifted.output);
+ assert.match(drifted.output, /attempt 1 on fixture-host: refused \(runner refused: RUNNER_SOURCE_CHANGED\) in \d+ ms$/mu);
+ assert.match(drifted.output, /^landing shard \d\/3: runner fixture-host refused it: \[RUNNER_SOURCE_CHANGED\] runner fixture-host answered/mu);
+ assert.doesNotMatch(drifted.output, rerunLine, 'changed source is never retried');
+ assert.equal(drifted.calls.length, 1);
+ assert.equal(drifted.profile.shards.filter(shard => shard.status === 'stopped').length, 2, 'the other shards stop');
+
+ // 3. Unverified cleanup reruns locally but takes the host out of this landing: no more shards go to it.
+ const unverified = await landingWithRunnerAnswer(box, 'RUNNER_CLEANUP_TIMEOUT', 4, 150_000);
+ assert.equal(unverified.isGreen, true, unverified.output);
+ assert.match(unverified.output, rerunLine);
+ assert.match(unverified.output, /^landing runner fixture-host quarantined for the rest of this landing: \[RUNNER_CLEANUP_TIMEOUT\] .*inspect job fixture-job under its runner namespace before another run$/mu);
+ assert.deepEqual(unverified.calls, ['fixture-host'], 'the quarantined host gets no second shard');
+ assert.deepEqual(unverified.profile.quarantined.map(entry => entry.host), ['fixture-host']);
+ assert.ok(unverified.profile.shards.filter(shard => shard.status === 'green').every(shard => shard.host === 'local'));
+
+ // 4. A setup the runner's own pool refused (#690) reruns locally, with the code and host in the log.
+ const setup = await landingWithRunnerAnswer(box, 'RUNNER_SETUP_REFUSED', 3, 120_000);
+ assert.equal(setup.isGreen, true, setup.output);
+ assert.match(setup.output, rerunLine);
+ assert.match(setup.output, /attempt 1 on fixture-host: infrastructure \(runner refused: RUNNER_SETUP_REFUSED\)/u);
+ assert.match(setup.output, /^landing shard \d\/3: runner fixture-host refused it: \[RUNNER_SETUP_REFUSED\]/mu);
+
+ // 5. A refusal this landing does not know fails closed: red, named, and never silently retried.
+ const unknown = await landingWithRunnerAnswer(box, 'RUNNER_SOMETHING_NEW', 3, 120_000);
+ assert.equal(unknown.isGreen, false, unknown.output);
+ assert.match(unknown.output, /attempt 1 on fixture-host: refused \(runner refused: RUNNER_SOMETHING_NEW\)/u);
+ assert.doesNotMatch(unknown.output, rerunLine);
+});