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
feat(verify): a verdict survives an unrelated main move [V4,C7]
Corey Olson7efa13b48cb2
diff --git a/docs/api.md b/docs/api.mdindex 40678a05..db7fe9a8 100644--- a/docs/api.md+++ b/docs/api.md@@ -185,6 +185,8 @@ With `submitGate: "landing"`, `status.submitInvariantProposals` lists files thatReleasing a reserved review requires a nonempty one-line `--note` (or `--note-file`); the authenticated release action accepts the same `note` field. A refusal keeps the reservation and records no release. The same reviewer is not offered that submission again until it is resubmitted or an hour passes, while other reviewers remain eligible. Releasing a build claim keeps its existing behavior and does not require a reason.+With `verify.unrelatedTrunkMoves: true` in `pullboard.json` (off by default), an accept whose review saw main move is still recorded when every moved commit changes none of the item's files and none of the files its check and affected tests read; the verdict note names those commits. Any other move, or a check that is not an explicit test selection, refuses `VERDICT_TRUNK_MOVED` as before, naming the file that reaches the review.+When outstanding reviews reach `verify.reviewRatio` times the active reviewers (default 3, with zero reviewers counting as one), `next` first offers a review the agent may take. This creates no claim or reservation. Its additive v1 `offer` has the review's `item` id, exact `command` to reserve it, `queue` and `ratio`; `build` previews the otherwise available build or is `null`. `next --verify <id>` reserves explicitly. `next --build` claims explicitly; a fresh claim's event detail records `reviewSkipped` with the offered id (or `null`), ratio and queue snapshot. Renewing an existing claim creates no new skip.For HTTP `next`, a review offer returns success with `event: null`, `offer` and the ordinary CLI `result`. Send `args.build: true` to claim as before and receive the actual claim event. The unattended `run` command always supplies explicit build intent, records it on fresh claims, and prints the review backlog each iteration.diff --git a/src/cli.js b/src/cli.jsindex fd7449a1..1738a8bf 100644--- a/src/cli.js+++ b/src/cli.js@@ -41,6 +41,7 @@ import {refuseNextIdle,} from './next-steps.js';import { reviewerStartup } from './next-steps.js';+import { judgeTrunkMove } from './verdict-trunk.js';import * as store from './board.js';import {CONFIG_FILE,@@ -2990,6 +2991,7 @@ async function verifyHere(ctx, id, { second, values }) {let digest = 'missing';let check;let review;+ let unaffectedMove = '';try {digest = freezer(ctx, { board })(item).digest;} catch (error) {@@ -3029,7 +3031,11 @@ async function verifyHere(ctx, id, { second, values }) {const receipt = store.events(board, { itemId: id }).filter(event => event.event_kind === 'submit').map(event => JSON.parse(event.event_detail)).find(event => event.commit === commit);submissionPaths(root, item, commit, { mainCommit: receipt?.policyCommit, dependencies: dependencySnapshots(board.db, item) });const currentTrunk = requireTrunkMerge(root, checkedCommit); // Re-read after the frozen check, before accepting.- if (currentTrunk.commit !== trunk.commit) throw new Refused('VERDICT_TRUNK_MOVED', `main moved from ${trunk.commit} to ${currentTrunk.commit} during review; merge the latest main and re-review the clean composition`);+ // With verify.unrelatedTrunkMoves on, a move through commits that touch nothing this review read keeps its verdict (#928).+ const judged = currentTrunk.commit === trunk.commit || ctx.config.verify.unrelatedTrunkMoves !== true ? null+ : await judgeTrunkMove(root, { from: trunk.commit, to: currentTrunk.commit, item, checkedCommit, check: frozenCheck(item) });+ if (currentTrunk.commit !== trunk.commit && (!judged || judged.overlap)) throw new Refused('VERDICT_TRUNK_MOVED', `main moved from ${trunk.commit} to ${currentTrunk.commit} during review${judged ? `, and the move reaches this review through ${judged.overlap}` : ''}; merge the latest main and re-review the clean composition`);+ if (judged) unaffectedMove = `\nmain moved during this review through ${judged.moved.map((sha) => sha.slice(0, 12)).join(', ')}, judged unaffected: none of them changes this item's files or a file its check and affected tests read`;if (headCommit(root) !== head || (reReview && (!isClean(root) || untracked(root).length))) {throw new Refused('NOT_AT_COMMIT', 'the reviewed checkout moved during its check; restore the clean reviewed HEAD and retry verification');}@@ -3041,7 +3047,7 @@ async function verifyHere(ctx, id, { second, values }) {agentId: me.id,decision,reason: values.reason,- note: textArg(ctx.io, values, 'note') ?? '',+ note: (textArg(ctx.io, values, 'note') ?? '') + unaffectedMove,...(decision === 'REJECT' && values.cause !== undefined ? { cause: values.cause } : {}),head,digest,diff --git a/src/config.js b/src/config.jsindex 81779c58..e4e5340e 100644--- a/src/config.js+++ b/src/config.js@@ -205,6 +205,9 @@ export function configProblems(config) {if (!timeout || timeoutMs <= 0 || !Number.isFinite(timeoutMs) || timeoutMs > MAX_CHECK_TIMEOUT_MS) {problems.push('"check.timeout" is a positive duration no longer than 2,147,483,647ms, like "5m"');}+ if (config.verify?.unrelatedTrunkMoves !== undefined && typeof config.verify.unrelatedTrunkMoves !== 'boolean') {+ problems.push('"verify.unrelatedTrunkMoves" is true or false');+ }if (!Number.isFinite(config.verify?.reviewRatio) || config.verify.reviewRatio <= 0) {problems.push('"verify.reviewRatio" is a positive number, such as 3');}diff --git a/src/verdict-trunk.js b/src/verdict-trunk.jsnew file mode 100644index 00000000..ae1a6c99--- /dev/null+++ b/src/verdict-trunk.js@@ -0,0 +1,48 @@+/**+ * A verdict and a moving trunk (#928). The merge train lands every few minutes and a review takes about ten, so a+ * verdict refused whenever main moved at all is lost to landings that touch nothing it judged. With+ * `verify.unrelatedTrunkMoves` on, a move is kept when its commits change none of the item's files and none of the+ * files its check and affected tests read; anything else, or anything the selection cannot see, refuses as before.+ */+import { execFileSync } from 'node:child_process';+import { selectAffectedTests } from './affected-tests.js';+import { explicitCheckFiles } from './browser-admission.js';++/** Run git in the reviewer's checkout and return its trimmed output. */+function git(root, args) {+ return execFileSync('git', args, { cwd: root, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] }).trim();+}++/** The paths a range of commits changed, without rename pairing so both sides of a move count. */+function changedBetween(root, from, to) {+ return git(root, ['diff', '--no-renames', '--name-only', '-z', from, to]).split('\0').filter(Boolean);+}++/**+ * Judge a trunk that moved from `from` to `to` while an item was reviewed. Returns the moved commits and, when the move+ * reaches the review, the first file that overlaps and why; `overlap` is null when every moved commit is unrelated.+ *+ * @param {string} root+ * @param {{ from: string, to: string, item: { item_claim_head?: string|null }, checkedCommit: string, check: string|null }} review+ * @returns {Promise<{ moved: string[], overlap: string|null }>}+ */+export async function judgeTrunkMove(root, { from, to, item, checkedCommit, check }) {+ const moved = git(root, ['rev-list', '--reverse', `${from}..${to}`]).split('\n').filter(Boolean);+ const movedFiles = changedBetween(root, from, to);+ const base = git(root, ['merge-base', from, checkedCommit]);+ const itemFiles = new Set(changedBetween(root, base, checkedCommit));+ const touched = movedFiles.find((path) => itemFiles.has(path));+ if (touched) return { moved, overlap: `${touched}, a file this item changed` };+ const checkFiles = check ? await explicitCheckFiles(root, check, { commit: checkedCommit }) : null;+ if (check && !checkFiles) return { moved, overlap: `${movedFiles[0] ?? to}, since the check is not an explicit test selection, so what it reads cannot be bounded` };+ const affected = selectAffectedTests(root, { base: item.item_claim_head ?? base, trunk: from, commit: checkedCommit });+ if (affected.full) return { moved, overlap: `${movedFiles[0] ?? to}, since this item's affected tests are the full suite (${affected.reason})` };+ const read = new Set([...(checkFiles ?? []), ...affected.files]);+ for (const path of movedFiles) {+ const reach = selectAffectedTests(root, { base: from, commit: to, changed: [path] });+ if (reach.full) return { moved, overlap: `${path}, whose effect on tests cannot be bounded (${reach.reason})` };+ const test = reach.files.find((file) => read.has(file));+ if (test) return { moved, overlap: `${path}, which ${test} reads` };+ }+ return { moved, overlap: null };+}diff --git a/test/verdict-trunk.test.js b/test/verdict-trunk.test.jsnew file mode 100644index 00000000..2f66275d--- /dev/null+++ b/test/verdict-trunk.test.js@@ -0,0 +1,99 @@+/** @pullboard-test-input source-tree */+/** A verdict survives a main move that touches nothing the review depends on (#928) [V4,C7]. */+import assert from 'node:assert/strict';+import { cpSync } from 'node:fs';+import { existsSync } from 'node:fs';+import { mkdirSync } from 'node:fs';+import { writeFileSync } from 'node:fs';+import { join } from 'node:path';+import { resolve } from 'node:path';+import { test } from 'node:test';+import { createE2eHelpers } from './e2e-helpers.js';++/**+ * A board whose web item's check runs test/page.test.js, which imports web/lib.js and web/shared.js; a second test+ * reads only api/other.js. Arming `landing` makes the next check run land one commit on main mid-review, changing+ * the named file, exactly as the merge train would while a reviewer's check runs.+ */+function reviewWithLanding(t, { setting, landing }) {+ const helpers = createE2eHelpers();+ t.after(helpers.cleanup);+ const box = helpers.project('true');+ const armed = join(box.dir, 'landing-armed');+ const landed = join(box.dir, 'landing-done');+ cpSync(resolve(import.meta.dirname, '../bin'), join(box.repo, 'bin'), { recursive: true });+ cpSync(resolve(import.meta.dirname, '../src'), join(box.repo, 'src'), { recursive: true });+ for (const folder of ['test', 'web', 'api']) mkdirSync(join(box.repo, folder), { recursive: true });+ writeFileSync(join(box.repo, 'package.json'), JSON.stringify({ private: true, type: 'module' }) + '\n');+ writeFileSync(join(box.repo, 'web/shared.js'), 'export const shared = 1;\n');+ writeFileSync(join(box.repo, 'web/lib.js'), "export const page = 'draft';\n");+ writeFileSync(join(box.repo, 'api/other.js'), 'export const other = 1;\n');+ writeFileSync(join(box.repo, 'test/other.test.js'), "import { test } from 'node:test'; import { other } from '../api/other.js'; test('other', () => { if (!other) throw new Error('no'); });\n");+ writeFileSync(join(box.repo, 'test/page.test.js'), `import { test } from 'node:test';+import { execFileSync } from 'node:child_process';+import { existsSync, rmSync, writeFileSync } from 'node:fs';+import { page } from '../web/lib.js';+import { shared } from '../web/shared.js';+test('page is built', () => {+ if (page !== 'built' || !shared) throw new Error('page is not built');+ if (existsSync(${JSON.stringify(armed)})) {+ rmSync(${JSON.stringify(armed)});+ const repo = ${JSON.stringify(box.repo)};+ writeFileSync(repo + '/' + ${JSON.stringify(landing)}, 'export const moved = ' + Date.now() + ';\\n');+ const git = (...args) => execFileSync('git', ['-c', 'user.name=Train', '-c', '[email protected]', '-c', 'core.hooksPath=/dev/null', ...args], { cwd: repo, env: { PATH: process.env.PATH } });+ git('add', ${JSON.stringify(landing)});+ git('commit', '-q', '-m', 'feat(merge): an unrelated item lands');+ writeFileSync(${JSON.stringify(landed)}, 'landed');+ }+});+`);+ const config = JSON.parse(String(execGitShow(box)));+ writeFileSync(join(box.repo, 'pullboard.json'), JSON.stringify({ ...config, verify: { ...(config.verify ?? {}), ...(setting === undefined ? {} : { unrelatedTrunkMoves: setting }) } }, null, 2));+ box.git(box.repo, 'add', '-A');+ box.git(box.repo, 'commit', '-q', '-m', 'test: a page item with a recorded landing [G1]');+ box.git(box.web, 'merge', '-q', '--ff-only', 'main');+ /** Demand real command success and its versioned result. */+ const json = (result) => { assert.equal(result.code, 0, result.out + result.err); return JSON.parse(result.out); };+ json(box.run(box.repo, 'add', 'web', 'Build the page', '--criterion', 'the page is built', '--check', 'node bin/run-tests.js test/page.test.js', '--json'));+ json(box.run(box.web, 'claim', '1', '--json'));+ writeFileSync(join(box.web, 'web/lib.js'), "export const page = 'built';\n");+ box.git(box.web, 'add', 'web/lib.js');+ box.git(box.web, 'commit', '-q', '-m', 'feat(web): build the page [G1]');+ json(box.run(box.web, 'submit', '1', '--json'));+ const reviewer = join(box.dir, 'api-1');+ box.git(box.repo, 'worktree', 'add', '-q', '--detach', reviewer, box.git(box.web, 'rev-parse', 'HEAD'));+ json(box.run(reviewer, 'join', 'api', '--json'));+ writeFileSync(armed, 'armed');+ const verdict = box.run(reviewer, 'verify', '1', 'accept', '--note', 'the page builds', '--json');+ assert.ok(existsSync(landed), 'main really moved while the review ran');+ return { box, verdict, json };+}++/** The coordinator's committed pullboard.json at main. */+function execGitShow(box) {+ return box.git(box.repo, 'show', 'HEAD:pullboard.json');+}++test('an unrelated landing during a review keeps the verdict and names the commit it judged [V4,C7]', (t) => {+ const { box, verdict, json } = reviewWithLanding(t, { setting: true, landing: 'api/other.js' });+ assert.equal(verdict.code, 0, verdict.out + verdict.err);+ const item = json(box.run(box.repo, 'show', '1', '--json'));+ assert.equal(item.item_status, 'verified');+ const moved = box.git(box.repo, 'rev-parse', 'HEAD').slice(0, 12);+ assert.match(item.verdicts.at(-1).verdict_note, new RegExp(`main moved during this review through ${moved}, judged unaffected`, 'u'));+});++test('a landing that touches a file the affected tests read still refuses and names it [V4,C7]', (t) => {+ const { box, verdict, json } = reviewWithLanding(t, { setting: true, landing: 'web/shared.js' });+ assert.notEqual(verdict.code, 0);+ const error = JSON.parse(verdict.out).error;+ assert.equal(error.code, 'VERDICT_TRUNK_MOVED');+ assert.match(error.message, /the move reaches this review through web\/shared\.js, which test\/page\.test\.js reads/u);+ assert.equal(json(box.run(box.repo, 'show', '1', '--json')).item_status, 'submitted');+});++test('with the setting off an unrelated landing still refuses as before [V4,C7]', (t) => {+ const { verdict } = reviewWithLanding(t, { setting: undefined, landing: 'api/other.js' });+ assert.notEqual(verdict.code, 0);+ assert.equal(JSON.parse(verdict.out).error.code, 'VERDICT_TRUNK_MOVED');+});