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(gate): local shards run only the landing's pinned source [C7,V4]
Corey Olsonc23f323b415d
diff --git a/docs/api.md b/docs/api.mdindex b3474563..e574df6a 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 saThe 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. 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`.+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 landing pins its source (HEAD, tracked changes and untracked files) before the first shard. A local shard, first run or rerun, checks that source before and after it runs and refuses as `LANDING_SOURCE_CHANGED` if the checkout moved, so a result never comes from other code. 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/landing-shards.js b/src/landing-shards.jsindex f5388fd4..a75fa957 100644--- a/src/landing-shards.js+++ b/src/landing-shards.js@@ -3,11 +3,11 @@* a free local gate slot or a registered runner, and report one result. One red shard stops the rest,* and a shard whose runner fails mid-run reruns locally.*/-import { spawn } from 'node:child_process';+import { spawn, spawnSync } from 'node:child_process';import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';import { dirname, join } from 'node:path';-import { randomUUID } from 'node:crypto';-import { repoInfo } from './git.js';+import { createHash, randomUUID } from 'node:crypto';+import { gitChildEnv, repoInfo } from './git.js';import {BROWSER_SLOT_HELD_ENV,GATE_SLOT_HELD_ENV,@@ -162,6 +162,26 @@ async function runLocalShard({ root, runner, files, label, lease, stop }) {return { isGreen: status === 0 && !signal, output: chunks.join('') };}+/**+ * A fingerprint of exactly what a local shard would run: HEAD, every tracked change against it and+ * the untracked files Git does not ignore. A landing pins it before its first shard.+ *+ * @param {string} root+ * @returns {{ commit: string, fingerprint: string }}+ */+export function landingSource(root) {+ const git = args => {+ const result = spawnSync('git', args, { cwd: root, env: gitChildEnv(root), encoding: 'buffer', maxBuffer: 1024 ** 3 });+ if (result.status !== 0) throw new Error(`git ${args[0]} failed while pinning the landing source`);+ return result.stdout;+ };+ const commit = git(['rev-parse', 'HEAD']).toString('utf8').trim();+ const hash = createHash('sha256').update(commit).update('\0')+ .update(git(['diff', 'HEAD', '--binary', '--no-ext-diff'])).update('\0')+ .update(git(['ls-files', '--others', '--exclude-standard', '-z']));+ return { commit, fingerprint: hash.digest('hex') };+}+/** 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']);@@ -211,6 +231,8 @@ export async function runLandingShards({ root, runner, files, count, inherited =// 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();+ // Every local shard, first run or rerun, must run exactly this source or refuse by name.+ const pinned = landingSource(root);const { Refused } = await import('./refused.js');const history = readFileTimes(root);const plan = planLandingShards(files, count, history);@@ -239,7 +261,15 @@ export async function runLandingShards({ root, runner, files, count, inherited =const started = Date.now();const number = entry.attempts.length + 1;if (!lease.runner) {+ const drifted = () => landingSource(root).fingerprint !== pinned.fingerprint;+ /** A local result on other source than the landing pinned is never a result for this landing. */+ const sourceChanged = when => {+ write(`landing shard ${entry.label}: [LANDING_SOURCE_CHANGED] the checkout changed from the landing's pinned source ${pinned.commit.slice(0, 12)} ${when} this shard ran; restore that commit with no other changes and run the landing again\n`);+ return { attempt: number, host: 'local', outcome: 'refused', reason: 'landing refused: LANDING_SOURCE_CHANGED', output: '', wallMs: Date.now() - started };+ };+ if (drifted()) return sourceChanged('before');const run = await runLocalShard({ root, runner, files: entry.shard.files, label: entry.label, lease, stop });+ if (!stop.aborted && drifted()) return sourceChanged('while');return { attempt: number, host: 'local', outcome: run.isGreen ? 'green' : 'red', output: run.output, wallMs: Date.now() - started };}const command = `${LANDING_SHARD_ENV}=${word(entry.label)} ${['node', './bin/run-tests.js', ...entry.shard.files].map(word).join(' ')}`;diff --git a/test/landing-shards.test.js b/test/landing-shards.test.jsindex 97bf6968..0a278b31 100644--- a/test/landing-shards.test.js+++ b/test/landing-shards.test.js@@ -278,11 +278,17 @@ async function landingWithRunnerAnswer(box, answer, count, deadlineMs) {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 { appendFileSync } = await import('node:fs');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);+ if (answer === 'DROPPED_AFTER_EDIT') {+ // The checkout moves on while the landing runs: a rerun must not test this source instead.+ appendFileSync(${JSON.stringify(join(box.repo, 'test', 'f.test.js'))}, '\\n// edited while the landing ran\\n');+ 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 = [];@@ -335,6 +341,9 @@ test('a runner refusal in a sharded landing is handled by its class [C7,V4]', {const unverified = await landingWithRunnerAnswer(box, 'RUNNER_CLEANUP_TIMEOUT', 4, 150_000);assert.equal(unverified.isGreen, true, unverified.output);assert.match(unverified.output, rerunLine);+ // The quarantine and its inspect instruction come before the shard is retried anywhere.+ assert.ok(unverified.output.indexOf('quarantined for the rest of this landing') < unverified.output.search(rerunLine),+ `the host is quarantined before the retry\n${unverified.output}`);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']);@@ -352,4 +361,16 @@ test('a runner refusal in a sharded landing is handled by its class [C7,V4]', {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);++ // 6. A transport-loss rerun runs only the landing's pinned source: when the checkout changed+ // under the landing, the rerun refuses by name instead of testing other code.+ const edited = join(box.repo, 'test', 'f.test.js');+ const original = readFileSync(edited, 'utf8');+ try {+ const moved = await landingWithRunnerAnswer(box, 'DROPPED_AFTER_EDIT', 3, 120_000);+ assert.equal(moved.isGreen, false, moved.output);+ assert.match(moved.output, /^landing shard \d\/3: \[LANDING_SOURCE_CHANGED\] the checkout changed from the landing's pinned source [0-9a-f]{12} /mu);+ assert.match(moved.output, /: refused \(landing refused: LANDING_SOURCE_CHANGED\) in \d+ ms$/mu);+ assert.doesNotMatch(moved.output, /attempt 2 on local: green/u, 'no green result comes from the changed checkout');+ } finally { writeFileSync(edited, original); }});