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(verify): a review composes when its gate slot is granted [V8]
Corey Olsonb29aeeccce3a
diff --git a/src/cli.js b/src/cli.jsindex fd7449a1..ffcae56b 100644--- a/src/cli.js+++ b/src/cli.js@@ -374,6 +374,10 @@ import {trunkMerge,trunkRef,} from './trusted-policy.js';+import {+ composeReview,+ composesAtAdmission,+} from './verdict-admission.js';import {captureVerdictReview,staleVerdictRefusal,@@ -2999,20 +3003,16 @@ async function verifyHere(ctx, id, { second, values }) {if (digest !== item.item_frozen_digest) throw new Refused('CRITERIA_CHANGED', 'the criterion changed; ask the coordinator to refreeze this item before checking it');const checkedCommit = reReview ? head : commit;const checkedLabel = reReview ? 'reviewed composition' : 'submitted commit';- const trunk = requireTrunkMerge(root, checkedCommit);- if (reReview) {- if (!isClean(root)) throw new Refused('DIRTY', 'commit the reviewed composition before re-reviewing the stale verdict');- if (untracked(root).length) throw new Refused('UNTRACKED', 'commit or ignore untracked files before re-reviewing the stale verdict');- if (!contains(root, trunk.commit, head)) throw staleVerdictRefusal(item, stale);- }- review = captureVerdictReview(root, board, item, trunk.commit, checkedCommit);- refuseUnverifiedStack(root, board, item, checkedCommit, trunk);+ const composeNow = () => composeReview(root, board, item, checkedCommit, { reReview, head, stale, refuseUnverifiedStack });+ const admitted = composesAtAdmission(ctx.config) && Boolean(frozenCheck(item));+ let trunk = null;+ if (!admitted) ({ trunk, review } = composeNow());const checkedItem = reReview ? { ...item, item_commit: checkedCommit } : item;if (frozenCheck(item)) {const browser = !browserFreeChecksEnabled() || await checkNeedsBrowser(root, frozenCheck(item), { commit: checkedCommit, onFallback: browserAdmissionReporter(ctx.io, ctx.io.relayJson) });// A private checked composition needs this machine's live local gate markers [C7,V4].const shortEligible = Boolean(await explicitCheckFiles(root, frozenCheck(item), { commit: checkedCommit }));- check = await withGateSlot(root, (lease) => checkAtCommit(root, checkedItem, { waitMs: lease.waitMs, gateLease: lease }), { browser, remote: false, agent: me.id, item: String(id), kind: 'review', itemCheck: true, shortEligible, onWait: queuedItemLease(ctx, item, me.id, 'review') });+ check = await withGateSlot(root, async (lease) => { if (admitted) ({ trunk, review } = composeNow()); return checkAtCommit(root, checkedItem, { waitMs: lease.waitMs, gateLease: lease }); }, { browser, remote: false, agent: me.id, item: String(id), kind: 'review', itemCheck: true, shortEligible, onWait: queuedItemLease(ctx, item, me.id, 'review') });} else {check = checkAtCommit(root, checkedItem);}diff --git a/src/verdict-admission.js b/src/verdict-admission.jsnew file mode 100644index 00000000..58669070--- /dev/null+++ b/src/verdict-admission.js@@ -0,0 +1,54 @@+/**+ * Verify composes against main when its gate slot is granted, not when the review queues (#929). The+ * board setting is pullboard.json's verify.composeAtAdmission, off by default, so nothing changes until a+ * board turns it on. With it on, the trunk merge, the captured review and the stacked-work check run once+ * the resource queue admits the check, so a landing during the wait never voids a check that has not+ * started; a landing during the check still refuses VERDICT_TRUNK_MOVED in verifyHere.+ */+import {+ contains,+ isClean,+ untracked,+} from './git.js';+import { Refused } from './refused.js';+import {+ requireTrunkMerge,+} from './trusted-policy.js';+import {+ captureVerdictReview,+ staleVerdictRefusal,+} from './verdict-freshness.js';++/**+ * Whether the board composes a review at gate admission rather than when it queues (#929).+ *+ * @param {any} config - the committed policy for the item+ * @returns {boolean}+ */+export function composesAtAdmission(config) {+ return config?.verify?.composeAtAdmission === true;+}++/**+ * Take the trunk, refuse a dirty or stale re-review, capture the review and check the stacked work, all+ * against the trunk as it is now. Called at queue time when the setting is off, and at gate admission when+ * it is on, so the composition judged is the main at that moment and is recorded with the verdict.+ *+ * @param {string} root+ * @param {any} board+ * @param {any} item+ * @param {string} checkedCommit - the commit the check runs at+ * @param {{ reReview: boolean, head: string, stale: any, refuseUnverifiedStack: (root: string, board: any, item: any, commit: string, trunk: any) => void }} options+ * @returns {{ trunk: any, review: any }}+ */+export function composeReview(root, board, item, checkedCommit, { reReview, head, stale, refuseUnverifiedStack }) {+ const trunk = requireTrunkMerge(root, checkedCommit);+ if (reReview) {+ if (!isClean(root)) throw new Refused('DIRTY', 'commit the reviewed composition before re-reviewing the stale verdict');+ if (untracked(root).length) throw new Refused('UNTRACKED', 'commit or ignore untracked files before re-reviewing the stale verdict');+ if (!contains(root, trunk.commit, head)) throw staleVerdictRefusal(item, stale);+ }+ const review = captureVerdictReview(root, board, item, trunk.commit, checkedCommit);+ refuseUnverifiedStack(root, board, item, checkedCommit, trunk);+ return { trunk, review };+}diff --git a/test/verdict-check.test.js b/test/verdict-check.test.jsindex 4f378bd7..9091ce20 100644--- a/test/verdict-check.test.js+++ b/test/verdict-check.test.js@@ -1,7 +1,7 @@/** The frozen check outcome travels with accepts without changing the board schema [V19,V8]. */import assert from 'node:assert/strict';-import { runFixtureExecFile as execFileSync, runFixtureChild, runFixtureGit } from './fixture-child.js';-import { chmodSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';+import { runFixtureExecFile as execFileSync, runFixtureChild, runFixtureChildAsync, runFixtureGit } from './fixture-child.js';+import { chmodSync, existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';import { tmpdir } from 'node:os';import { join, resolve } from 'node:path';import { test } from 'node:test';@@ -170,3 +170,91 @@ test('historical accepts read unknown in show and unchecked accepts are marked iassert.match(succeeds(box, repo, 'ledger'), new RegExp(`\\| ${unchecked.id} \\|[^\\n]*\\| unchecked \\|`));} finally { clean(box); }});++/** Read the verdicts of one item from the repo's board, opening it read-only for the assertion. */+function verdictsOf(repo, id) {+ const board = store.openBoard(join(repo, '.git', 'pullboard', 'board.sqlite'));+ try { return store.verdictsFor(board, id); }+ finally { store.closeBoard(board); }+}++/** Poll until a condition holds, failing with what the test was waiting for. */+async function until(condition, what, timeoutMs = 20_000) {+ const started = Date.now();+ while (!condition()) {+ if (Date.now() - started > timeoutMs) throw new Error(`timed out waiting for ${what}`);+ await new Promise((resolve) => setTimeout(resolve, 50));+ }+}++test('a landing while a review waits for its gate slot leaves the verdict standing [V8,Q4]', async (t) => {+ // With verify.composeAtAdmission on, verify composes against main once the gate admits it (#929). A landing+ // while the review waits in the queue must not void it; the verdict records the main it judged.+ const box = sandbox();+ t.after(() => clean(box));+ const { repo, web } = project(box);+ const config = JSON.parse(readFileSync(join(repo, 'pullboard.json'), 'utf8'));+ writeFileSync(join(repo, 'pullboard.json'), JSON.stringify({ ...config, verify: { ...config.verify, composeAtAdmission: true } }, null, 2) + '\n');+ box.git(repo, 'add', '-A');+ box.git(repo, 'commit', '-q', '-m', 'chore: verify composes at admission');+ box.git(web, 'merge', '-q', 'main');+ succeeds(box, repo, 'settings', 'gateSlots', '1');+ const { id, commit } = submitted(box, repo, web, 'Queued review', 'true');+ const reviewer = join(box.dir, 'queued-reviewer');+ box.git(repo, 'worktree', 'add', '-q', '--detach', reviewer, commit);+ succeeds(box, reviewer, 'join', 'web');+ // A second repo holds the machine's only gate slot until its flag file says it has started.+ const holder = join(box.dir, 'holder');+ mkdirSync(holder);+ box.git(holder, 'init', '-q', '-b', 'main');+ assert.equal(box.run(holder, 'init').code, 0);+ const flag = join(box.dir, 'holder-started');+ writeFileSync(join(holder, 'hold.js'), `require('fs').writeFileSync(${JSON.stringify(flag)}, '1'); setTimeout(() => {}, 4000);\n`);+ const holderConfig = JSON.parse(readFileSync(join(holder, 'pullboard.json'), 'utf8'));+ writeFileSync(join(holder, 'pullboard.json'), JSON.stringify({ ...holderConfig, gate: 'node hold.js' }, null, 2) + '\n');+ box.git(holder, 'add', '-A');+ box.git(holder, 'commit', '-q', '-m', 'chore: holder');+ const holding = runFixtureChildAsync(process.execPath, [BIN, 'gate'], { cwd: holder, env: box.env, encoding: 'utf8' });+ await until(() => existsSync(flag), 'the holder to own the only gate slot');+ const verifying = runFixtureChildAsync(process.execPath, [BIN, 'verify', String(id), 'accept', '--note', 'Verified while queued'], {+ cwd: reviewer, env: box.env, encoding: 'utf8',+ });+ // The holder's check runs for four seconds; the review queues behind it. Land while both are still pending.+ let holderSettled = false;+ holding.then(() => { holderSettled = true; });+ await new Promise((resolve) => setTimeout(resolve, 1000));+ assert.equal(holderSettled, false, 'the holder still owns the only slot when main moves');+ box.git(repo, 'switch', '-q', 'main');+ writeFileSync(join(repo, 'landed-while-queued.txt'), 'landed\n');+ box.git(repo, 'add', '-A');+ box.git(repo, 'commit', '-q', '-m', 'feat: land while the review queues [G1]');+ const held = await holding;+ assert.equal(held.status, 0, held.failure ?? held.stderr);+ const verified = await verifying;+ assert.equal(verified.status, 0, verified.failure ?? `${verified.stdout}${verified.stderr}`);+ const verdicts = verdictsOf(repo, id);+ assert.equal(verdicts.length, 1, 'the verdict stands after the landing');+ assert.equal(verdicts[0].verdict_decision, 'ACCEPT');+});++test('a landing during the check itself still refuses the verdict [V8]', (t) => {+ // With verify.composeAtAdmission on, a main that moves while the frozen check runs still voids the verdict (#929).+ const box = sandbox();+ t.after(() => clean(box));+ const { repo, web } = project(box);+ const config = JSON.parse(readFileSync(join(repo, 'pullboard.json'), 'utf8'));+ writeFileSync(join(repo, 'pullboard.json'), JSON.stringify({ ...config, verify: { ...config.verify, composeAtAdmission: true } }, null, 2) + '\n');+ box.git(repo, 'add', '-A');+ box.git(repo, 'commit', '-q', '-m', 'chore: verify composes at admission');+ box.git(web, 'merge', '-q', 'main');+ const landing = `git -C '${repo}' -c user.name=Fixture -c [email protected] commit --allow-empty -q -m 'feat: land during the check [G1]'`;+ const { id, commit } = submitted(box, repo, web, 'Moving check', landing);+ box.git(repo, 'switch', '-q', 'main');+ const reviewer = join(box.dir, 'moving-check-reviewer');+ box.git(repo, 'worktree', 'add', '-q', '--detach', reviewer, commit);+ succeeds(box, reviewer, 'join', 'web');+ const refused = box.run(reviewer, 'verify', String(id), 'accept', '--note', 'Verified while main moves during the check');+ assert.equal(refused.code, 1, refused.out + refused.err);+ assert.match(refused.err, /VERDICT_TRUNK_MOVED/u);+ assert.deepEqual(verdictsOf(repo, id), [], 'a verdict is not recorded for a check that saw a moved main');+});