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.

feat(board): next --verify reserves the review under a lease [V15]

Corey Olsonb7a7f6c5cd98
diff --git a/docs/lifecycle.md b/docs/lifecycle.md
index f428daea..e0d1898d 100644
--- a/docs/lifecycle.md
+++ b/docs/lifecycle.md
@@ -12,6 +12,7 @@ stateDiagram-v2
claimed --> open: release
claimed --> open: lapse (clock)
claimed --> submitted: submit
+ submitted --> submitted: reserve
submitted --> verified: accept
submitted --> open: reject
open --> open: escalate
@@ -46,8 +47,9 @@ Each move checks its guards in this order and refuses with the first one that do
| release | claimed | open | agent, coordinator | joined (NOT_JOINED), itemExists (NO_ITEM), inState (NOT_YOURS), isHolder (NOT_YOURS) |
| lapse | claimed | open | clock, when its lease runs out | none |
| submit | claimed | submitted | agent, coordinator | joined (NOT_JOINED), itemExists (NO_ITEM), inState (NOT_YOURS), isHolder (NOT_YOURS), criterionUnchanged (CRITERIA_CHANGED), treeClean (DIRTY), nothingUntracked (UNTRACKED), hasCommit (NO_COMMIT), gateConfigured (NO_GATE), gateGreen (GATE_RED), childrenDone (CHILDREN_OPEN), headIsNew (HEAD_NOT_NEW) |
-| accept | submitted | verified | agent, coordinator | coordinatorSaysAs (MAIN_IS_COORDINATOR), joined (NOT_JOINED), itemExists (NO_ITEM), inState (NOT_SUBMITTED), atSubmittedCommit (NOT_AT_COMMIT), notBuilder (SELF_VERIFY), routeAllows (ROUTE), policyAllows (COORDINATOR_VERIFIES), criterionUnchanged (CRITERIA_CHANGED), reasonIsMet (BAD_REASON), proofNoted (PROOF_REQUIRED) |
-| reject | submitted | open | agent, coordinator | coordinatorSaysAs (MAIN_IS_COORDINATOR), joined (NOT_JOINED), itemExists (NO_ITEM), inState (NOT_SUBMITTED), atSubmittedCommit (NOT_AT_COMMIT), notBuilder (SELF_VERIFY), routeAllows (ROUTE), policyAllows (COORDINATOR_VERIFIES), criterionUnchanged (CRITERIA_CHANGED), reasonCoded (BAD_REASON), noteGiven (NOTE_REQUIRED) |
+| reserve | submitted | submitted | agent, coordinator | coordinatorSaysAs (MAIN_IS_COORDINATOR), joined (NOT_JOINED), itemExists (NO_ITEM), inState (NOT_SUBMITTED), notBuilder (SELF_VERIFY), routeAllows (ROUTE), policyAllows (COORDINATOR_VERIFIES), reviewFree (REVIEW_HELD) |
+| accept | submitted | verified | agent, coordinator | coordinatorSaysAs (MAIN_IS_COORDINATOR), joined (NOT_JOINED), itemExists (NO_ITEM), inState (NOT_SUBMITTED), atSubmittedCommit (NOT_AT_COMMIT), notBuilder (SELF_VERIFY), routeAllows (ROUTE), policyAllows (COORDINATOR_VERIFIES), reviewFree (REVIEW_HELD), criterionUnchanged (CRITERIA_CHANGED), reasonIsMet (BAD_REASON), proofNoted (PROOF_REQUIRED) |
+| reject | submitted | open | agent, coordinator | coordinatorSaysAs (MAIN_IS_COORDINATOR), joined (NOT_JOINED), itemExists (NO_ITEM), inState (NOT_SUBMITTED), atSubmittedCommit (NOT_AT_COMMIT), notBuilder (SELF_VERIFY), routeAllows (ROUTE), policyAllows (COORDINATOR_VERIFIES), reviewFree (REVIEW_HELD), criterionUnchanged (CRITERIA_CHANGED), reasonCoded (BAD_REASON), noteGiven (NOTE_REQUIRED) |
| escalate | open, claimed | open | agent, coordinator | joined (NOT_JOINED), noteGiven (NOTE_REQUIRED), itemExists (NO_ITEM), holderOrCoordinator (NOT_YOURS), inState (CLOSED) |
| refreeze | open, claimed, submitted | open | coordinator | joined (NOT_JOINED), coordinatorOnly (COORDINATOR_ONLY), itemExists (NO_ITEM), inState (CLOSED), rowsInForce (UNKNOWN_SPEC) |
| withdraw | open, claimed, submitted | withdrawn | coordinator | joined (NOT_JOINED), coordinatorOnly (COORDINATOR_ONLY), noteGiven (NOTE_REQUIRED), itemExists (NO_ITEM), inState (CLOSED) |
@@ -66,6 +68,7 @@ Each move checks its guards in this order and refuses with the first one that do
| NOT_CLAIMABLE | claim: the item is in open, claimed | pullboard show <id> |
| NOT_YOURS | release: the item is in claimed | pullboard show <id> |
| NOT_YOURS | submit: the item is in claimed | pullboard show <id> |
+| NOT_SUBMITTED | reserve: the item is in submitted | pullboard show <id> |
| NOT_SUBMITTED | accept: the item is in submitted | pullboard show <id> |
| NOT_SUBMITTED | reject: the item is in submitted | pullboard show <id> |
| CLOSED | escalate: the item is in open, claimed | pullboard show <id> |
@@ -95,6 +98,7 @@ Each move checks its guards in this order and refuses with the first one that do
| NOT_AT_COMMIT | the caller's checkout contains the submitted commit | git switch --detach <commit> |
| SELF_VERIFY | the caller did not build it | another agent verifies it: pullboard next --verify |
| COORDINATOR_VERIFIES | the repo's verify policy lets the caller verify this lane's work | the coordinator verifies it |
+| REVIEW_HELD | no other agent holds its review under a live lease | pullboard next --verify, which passes over reviews another agent holds |
| BAD_REASON | an accept gives CRITERION_MET as its reason | a failed criterion is a reject: pullboard verify <id> reject --reason CODE |
| PROOF_REQUIRED | an accept notes how it was proved | --note "what you broke or which edge you tried, and what happened" |
| BAD_REASON | a reject names one of the reject reasons | --reason TEST_FAILURE, BEHAVIOR_MISMATCH, INSUFFICIENT_EVIDENCE, STALE_HEAD or OTHER |
diff --git a/src/board.js b/src/board.js
index ebffc218..2da4750e 100644
--- a/src/board.js
+++ b/src/board.js
@@ -211,6 +211,8 @@ function migrate(db) {
['agent', 'agent_route', "TEXT NOT NULL DEFAULT 'strong'"],
['item', 'item_claim_head', 'TEXT'],
['item', 'item_files', "TEXT NOT NULL DEFAULT ''"],
+ ['item', 'item_review_by', 'TEXT'],
+ ['item', 'item_review_until', 'TEXT'],
];
for (const [table, column, type] of added) {
const columns = db.prepare(`PRAGMA table_info(${table})`).all().map((entry) => entry.name);
@@ -822,6 +824,8 @@ export function submit(board, id, { agentId, commit, tree, files = [] }) {
item_commit: commit,
item_tree: tree,
item_lease_until: null,
+ item_review_by: null,
+ item_review_until: null,
item_files: [...new Set([...(found.item_files ?? '').split('\n').filter(Boolean), ...files])].join('\n'),
}),
});
@@ -829,6 +833,97 @@ export function submit(board, id, { agentId, commit, tree, files = [] }) {
});
}
+/**
+ * Who holds an item's review under a live lease (V15), or null. A reservation counts only while the
+ * item is submitted and its lease has not run out, and a new submission starts with none.
+ *
+ * @param {any} board
+ * @param {any} item
+ * @returns {string | null}
+ */
+export function reviewHolder(board, item) {
+ return item.item_status === 'submitted' && item.item_review_by && (item.item_review_until ?? '') > now(board) ? item.item_review_by : null;
+}
+
+/**
+ * What a verifier must pass before it reviews an item, alike when it reserves the review and when
+ * it gives its verdict: it did not build the item, its route covers the item's, the repo's verify
+ * policy lets it, and no other agent holds the review (V15). A reservation that lapsed holds
+ * nothing, so the agent that made it can still give its verdict unless another reserved it since.
+ *
+ * @param {any} board
+ * @param {{ agentId: string, policy: string }} who
+ * @returns {Record<string, (found: any) => Refused | null>}
+ */
+function reviewerChecks(board, { agentId, policy }) {
+ return {
+ notBuilder: (found) => (found.item_built_by === agentId ? new Refused('SELF_VERIFY', 'the builder never verifies its own work; another agent must') : null),
+ routeAllows: (found) => {
+ const route = routeOf(board, agentId);
+ return canTake(route, found.item_route) ? null : new Refused('ROUTE', `item #${found.item_id} needs a ${found.item_route} verifier; you joined on the ${route} route`);
+ },
+ policyAllows: (found) =>
+ policy === COORDINATOR && found.item_lane !== COORDINATOR && agentId !== COORDINATOR ? new Refused('COORDINATOR_VERIFIES', 'this repo has the coordinator verify lane work') : null,
+ reviewFree: (found) => {
+ const holder = reviewHolder(board, found);
+ return holder && holder !== agentId
+ ? new Refused('REVIEW_HELD', `${holder} holds the review of #${found.item_id} until ${found.item_review_until}; take another: pullboard next --verify`)
+ : null;
+ },
+ };
+}
+
+/**
+ * Reserve an item's review for an agent under a lease (V15): until it runs out, another agent's
+ * verdict on the item, or reservation of it, is refused. Reserving again renews the lease.
+ *
+ * @param {any} board
+ * @param {number} id
+ * @param {{ agentId: string, leaseMs: number, policy: string }} who
+ * @returns {any} The item, reserved.
+ */
+export function reserveReview(board, id, who) {
+ return atomic(board, () => reserveWithin(board, id, who));
+}
+
+/**
+ * `next --verify` (V15): find the next review the agent may take and reserve it in one
+ * transaction, so no other verifier can take it between the look and the reservation.
+ *
+ * @param {any} board
+ * @param {{ agentId: string, lane: string, leaseMs: number, policy: string, runnable?: boolean, routes?: string[] }} who
+ * @returns {{ item: any | null, reasons: string[] }}
+ */
+export function reserveNextReview(board, { agentId, lane, leaseMs, policy, runnable, routes }) {
+ return atomic(board, () => {
+ const { item, reasons } = nextFor(board, { agentId, lane, verify: true, runnable, routes });
+ return item ? { item: reserveWithin(board, item.item_id, { agentId, leaseMs, policy }), reasons: [] } : { item: null, reasons };
+ });
+}
+
+/**
+ * The reserve move, inside a transaction the caller holds.
+ *
+ * @param {any} board
+ * @param {number} id
+ * @param {{ agentId: string, leaseMs: number, policy: string }} who
+ * @returns {any}
+ */
+function reserveWithin(board, id, { agentId, leaseMs, policy }) {
+ const until = new Date(board.clock.now().getTime() + leaseMs).toISOString();
+ moveItem(board, id, 'reserve', {
+ checks: {
+ coordinatorSaysAs: null,
+ joined: null,
+ [IN_STATE]: (found) => new Refused('NOT_SUBMITTED', `item #${id} is ${current(board, found).item_status}, not submitted`),
+ ...reviewerChecks(board, { agentId, policy }),
+ },
+ set: () => ({ item_review_by: agentId, item_review_until: until }),
+ });
+ logEvent(board, agentId, 'reserve', id, { until });
+ return getItem(board, id);
+}
+
/**
* Record a verdict on a submitted item (V1, V3, V5, V6, V8): an accept verifies it, a reject
* reopens it for rework.
@@ -836,9 +931,9 @@ export function submit(board, id, { agentId, commit, tree, files = [] }) {
* The verdict binds the submitted commit and the digest frozen at claim. If the criterion's text
* has moved since, there is no verdict to give: the coordinator refreezes it and the work is
* claimed again. The builder never verifies; under `verify: "coordinator"`, lane work is the
- * coordinator's to verify; an agent verifies items at its tier or below. An accept means
- * CRITERION_MET and says how it was proved; a reject names one of the reject reasons and says what
- * failed.
+ * coordinator's to verify; an agent verifies items at its tier or below, and not while another
+ * agent holds the review (V15). An accept means CRITERION_MET and says how it was proved; a reject
+ * names one of the reject reasons and says what failed.
*
* @param {any} board
* @param {number} id
@@ -857,13 +952,7 @@ export function verify(board, id, { agentId, decision, reason, note = '', head,
joined: null,
[IN_STATE]: (found) => new Refused('NOT_SUBMITTED', `item #${id} is ${current(board, found).item_status}, not submitted`),
atSubmittedCommit: null,
- notBuilder: (found) => (found.item_built_by === agentId ? new Refused('SELF_VERIFY', 'the builder never verifies its own work; another agent must') : null),
- routeAllows: (found) => {
- const route = routeOf(board, agentId);
- return canTake(route, found.item_route) ? null : new Refused('ROUTE', `item #${found.item_id} needs a ${found.item_route} verifier; you joined on the ${route} route`);
- },
- policyAllows: (found) =>
- policy === COORDINATOR && found.item_lane !== COORDINATOR && agentId !== COORDINATOR ? new Refused('COORDINATOR_VERIFIES', 'this repo has the coordinator verify lane work') : null,
+ ...reviewerChecks(board, { agentId, policy }),
criterionUnchanged: (found) =>
digest === found.item_frozen_digest
? null
@@ -1114,8 +1203,12 @@ export function nextFor(board, { agentId, lane, verify = false, runnable = false
const tiers = route === 'strong' ? '' : `${ROUTES.slice(0, ROUTES.indexOf(route) + 1).reverse().join(' or ')} `;
const routed = `${tiers}${runnable ? 'runnable ' : ''}`;
if (verify) {
- const item = items.find((entry) => entry.item_status === 'submitted' && entry.item_built_by !== agentId) ?? null;
- return { item, reasons: item ? [] : [`nothing ${routed}submitted that you did not build`] };
+ const reviewable = items.filter((entry) => entry.item_status === 'submitted' && entry.item_built_by !== agentId);
+ const holder = (entry) => reviewHolder(board, entry);
+ const item = reviewable.find((entry) => holder(entry) === agentId) ?? reviewable.find((entry) => !holder(entry));
+ if (item) return { item, reasons: [] };
+ const held = reviewable.map((entry) => `${holder(entry)} holds the review of #${entry.item_id} until ${entry.item_review_until}`);
+ return { item: null, reasons: [`nothing ${routed}submitted that you did not build${held.length ? ' and no other agent is reviewing' : ''}`, ...held] };
}
const held = items.find((entry) => entry.item_status === 'claimed' && entry.item_owner === agentId && entry.item_parent_id === null);
if (held) return { item: held, reasons: [] };
diff --git a/src/cli.js b/src/cli.js
index 96ff9b38..3d5a940c 100644
--- a/src/cli.js
+++ b/src/cli.js
@@ -81,9 +81,9 @@ Work
pullboard show <id> [--history] an item, the criterion frozen at claim, its verdicts: the latest in full,
earlier ones as one line; --history prints every note in full
pullboard next [--wait <minutes>] claim the next item in your lane that is free to start
- pullboard next --verify name the next submitted item you can check
- pullboard check [id] run your item's check, the command that proves it (the project gate is pullboard gate)
+ pullboard next --verify reserve the next submitted item you can check;
in the main checkout, verifying needs --as coordinator
+ pullboard check [id] run your item's check, the command that proves it (the project gate is pullboard gate)
pullboard claim <id> take or renew a lease; the first claim freezes the criterion
pullboard release <id> hand it back
pullboard submit <id> needs a clean tree and the gate green at HEAD (alias: done)
@@ -671,11 +671,12 @@ function readCommands(io, { first, values }) {
show: () => {
const ctx = context(io);
const id = idArg(first);
- const { item, verdicts, moves, related } = withBoard(ctx, (board) => ({
+ const { item, verdicts, moves, related, reviewer } = withBoard(ctx, (board) => ({
item: store.getItem(board, id),
verdicts: store.verdictsFor(board, id),
moves: store.events(board, { itemId: id }).filter((event) => ['attempt', 'escalate'].includes(event.event_kind)),
related: store.relatedItems(board, store.getItem(board, id)),
+ reviewer: store.reviewHolder(board, store.getItem(board, id)),
}));
if (values.json) {
io.say(JSON.stringify({ ...item, verdicts }, null, 2));
@@ -700,6 +701,7 @@ function readCommands(io, { first, values }) {
frozen.rows.forEach((row) => io.say(` ${row.id}: ${row.text}${row.gate ? ` | gate: ${row.gate}` : ''}`));
}
if (item.item_commit) io.say(`submitted by ${item.item_built_by} at ${item.item_commit}`);
+ if (reviewer) io.say(`under review by ${reviewer} until ${item.item_review_until}`);
// Earlier verdicts as one line each, so an item sent back several times stays short to read
// (N30); --history prints every note in full.
const verdictLine = (verdict) => `${verdict.verdict_decision} ${verdict.verdict_reason} by ${verdict.verdict_by} at ${verdict.verdict_commit.slice(0, 12)}`;
@@ -864,8 +866,9 @@ function verifyHere(ctx, id, { second, values }) {
}
/**
- * One loop of `next`: claim the next free item, or name the next one to verify. A claim that loses a
- * race to another agent is not an error; the caller looks again.
+ * One loop of `next`: claim the next free item, or reserve the next review (V15). A claim that loses
+ * a race to another agent is not an error; the caller looks again. A review is looked for and
+ * reserved in one transaction, so it cannot lose that race.
*
* @param {any} ctx
* @param {any} values
@@ -875,10 +878,12 @@ function nextOnce(ctx, values) {
return withBoard(ctx, (board) => {
if (values.verify) checkMainVerifier(ctx, board, values);
const me = whoAmI(ctx, board);
- const warm = values.verify ? [] : warmFiles(ctx, board, me);
- const { item, reasons, shared } = store.nextFor(board, { agentId: me.id, lane: me.lane, verify: values.verify, runnable: values.runnable, routes: values.routes, warm });
+ if (values.verify) {
+ return store.reserveNextReview(board, { agentId: me.id, lane: me.lane, leaseMs: ctx.config.reviewLeaseMs, policy: ctx.config.verify, runnable: values.runnable, routes: values.routes });
+ }
+ const warm = warmFiles(ctx, board, me);
+ const { item, reasons, shared } = store.nextFor(board, { agentId: me.id, lane: me.lane, runnable: values.runnable, routes: values.routes, warm });
if (!item) return { reasons };
- if (values.verify) return { item };
if (item.item_status === 'claimed') return { item, held: true };
try {
store.claim(board, item.item_id, { agentId: me.id, lane: me.lane, leaseMs: ctx.config.leaseMs, freeze: freezer(ctx), head: headCommit(ctx.info.root) });
@@ -913,6 +918,7 @@ async function nextHere(io, values) {
const as = ctx.info.isMain ? ' --as coordinator' : '';
if (values.verify) {
io.say(`next to verify: #${item.item_id} ${item.item_title}, built by ${item.item_built_by} at ${item.item_commit.slice(0, 12)}`);
+ io.say(`reserved for you until ${item.item_review_until}: another agent's verdict on it is refused until then; pullboard next --verify again renews it`);
io.say(`check out exactly that commit, here: ${here} git switch --detach ${item.item_commit}`);
io.say(`then: ${here} pullboard verify ${item.item_id} accept${as} --note "how you proved it", or reject${as} --reason CODE --note "what failed"`);
} else {
diff --git a/src/config.js b/src/config.js
index 83e62e24..c5057f04 100644
--- a/src/config.js
+++ b/src/config.js
@@ -37,6 +37,7 @@ export function defaults() {
practice: 'PRACTICE.md',
gate: '',
lease: '2h',
+ reviewLease: '30m',
verify: 'any',
lanes: {},
products: {},
@@ -62,11 +63,12 @@ export function defaults() {
* Milliseconds in a duration like `90m`, `2h` or `1d`.
*
* @param {string} text
+ * @param {string} [setting] - The setting it came from, for the refusal.
* @returns {number}
*/
-export function durationMs(text) {
+export function durationMs(text, setting = 'lease') {
const match = DURATION_RE.exec(String(text));
- if (!match) throw new Refused('BAD_CONFIG', `lease "${text}" is not a duration like 90m, 2h or 1d`);
+ if (!match) throw new Refused('BAD_CONFIG', `${setting} "${text}" is not a duration like 90m, 2h or 1d`);
return Number(match[1]) * UNIT_MS[/** @type {'m'|'h'|'d'} */ (match[2])];
}
@@ -179,5 +181,5 @@ export function loadConfig(root) {
const config = merge(defaults(), raw);
const problems = configProblems(config);
if (problems.length) throw new Refused('BAD_CONFIG', `${CONFIG_FILE}: ${problems.join('; ')}`);
- return { ...config, leaseMs: durationMs(config.lease) };
+ return { ...config, leaseMs: durationMs(config.lease), reviewLeaseMs: durationMs(config.reviewLease, 'reviewLease') };
}
diff --git a/src/machine.js b/src/machine.js
index 4dc9c8ec..5e62ca97 100644
--- a/src/machine.js
+++ b/src/machine.js
@@ -116,6 +116,7 @@ export const GUARDS = [
{ id: 'atSubmittedCommit', refuse: 'NOT_AT_COMMIT', rule: "the caller's checkout contains the submitted commit", next: 'git switch --detach <commit>', source: 'cli' },
{ id: 'notBuilder', refuse: 'SELF_VERIFY', rule: 'the caller did not build it', next: 'another agent verifies it: pullboard next --verify', source: 'board' },
{ id: 'policyAllows', refuse: 'COORDINATOR_VERIFIES', rule: "the repo's verify policy lets the caller verify this lane's work", next: 'the coordinator verifies it', source: 'board' },
+ { id: 'reviewFree', refuse: 'REVIEW_HELD', rule: 'no other agent holds its review under a live lease', next: 'pullboard next --verify, which passes over reviews another agent holds', source: 'board' },
{ id: 'reasonIsMet', refuse: 'BAD_REASON', rule: 'an accept gives CRITERION_MET as its reason', next: 'a failed criterion is a reject: pullboard verify <id> reject --reason CODE', source: 'board' },
{ id: 'proofNoted', refuse: 'PROOF_REQUIRED', rule: 'an accept notes how it was proved', next: '--note "what you broke or which edge you tried, and what happened"', source: 'board' },
{ id: 'reasonCoded', refuse: 'BAD_REASON', rule: 'a reject names one of the reject reasons', next: '--reason TEST_FAILURE, BEHAVIOR_MISMATCH, INSUFFICIENT_EVIDENCE, STALE_HEAD or OTHER', source: 'board' },
@@ -139,14 +140,19 @@ export const MOVES = [
guards: ['joined', 'itemExists', IN_STATE, 'isHolder', 'criterionUnchanged', 'treeClean', 'nothingUntracked', 'hasCommit', 'gateConfigured', 'gateGreen', 'childrenDone', 'headIsNew'],
sets: ['item_built_by', 'item_commit'], command: 'pullboard submit <id>',
},
+ {
+ verb: 'reserve', from: ['submitted'], to: 'submitted', by: ['agent', 'coordinator'], refuse: 'NOT_SUBMITTED',
+ guards: ['coordinatorSaysAs', 'joined', 'itemExists', IN_STATE, 'notBuilder', 'routeAllows', 'policyAllows', 'reviewFree'],
+ sets: ['item_review_by', 'item_review_until'], command: 'pullboard next --verify',
+ },
{
verb: 'accept', from: ['submitted'], to: 'verified', by: ['agent', 'coordinator'], refuse: 'NOT_SUBMITTED',
- guards: ['coordinatorSaysAs', 'joined', 'itemExists', IN_STATE, 'atSubmittedCommit', 'notBuilder', 'routeAllows', 'policyAllows', 'criterionUnchanged', 'reasonIsMet', 'proofNoted'],
+ guards: ['coordinatorSaysAs', 'joined', 'itemExists', IN_STATE, 'atSubmittedCommit', 'notBuilder', 'routeAllows', 'policyAllows', 'reviewFree', 'criterionUnchanged', 'reasonIsMet', 'proofNoted'],
sets: ['item_verified_by'], command: 'pullboard verify <id> accept --note "..."',
},
{
verb: 'reject', from: ['submitted'], to: 'open', by: ['agent', 'coordinator'], refuse: 'NOT_SUBMITTED',
- guards: ['coordinatorSaysAs', 'joined', 'itemExists', IN_STATE, 'atSubmittedCommit', 'notBuilder', 'routeAllows', 'policyAllows', 'criterionUnchanged', 'reasonCoded', 'noteGiven'],
+ guards: ['coordinatorSaysAs', 'joined', 'itemExists', IN_STATE, 'atSubmittedCommit', 'notBuilder', 'routeAllows', 'policyAllows', 'reviewFree', 'criterionUnchanged', 'reasonCoded', 'noteGiven'],
command: 'pullboard verify <id> reject --reason CODE --note "..."',
},
{
diff --git a/test/cockpit.test.js b/test/cockpit.test.js
index 22628982..a04b342c 100644
--- a/test/cockpit.test.js
+++ b/test/cockpit.test.js
@@ -635,6 +635,7 @@ test('the activity tab draws the lifecycle from the declaration, with live count
'claimed>claimed': 'claim 1',
'claimed>open': 'release · lapse · escalate · refreeze (none yet)',
'claimed>submitted': 'submit 3',
+ 'submitted>submitted': 'reserve (none yet)',
'submitted>verified': 'accept 1',
'submitted>open': 'reject 1',
'open>open': 'escalate · refreeze (none yet)',
diff --git a/test/machine.test.js b/test/machine.test.js
index 2007f7de..66628a34 100644
--- a/test/machine.test.js
+++ b/test/machine.test.js
@@ -3,7 +3,7 @@
* failing on a broken copy, and in step with the refusals board.js and cli.js raise today.
*/
import assert from 'node:assert/strict';
-import { mkdtempSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
+import { mkdirSync, mkdtempSync, readdirSync, readFileSync, realpathSync, rmSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { pathToFileURL } from 'node:url';
@@ -11,9 +11,10 @@ import { DatabaseSync } from 'node:sqlite';
import { test } from 'node:test';
import * as store from '../src/board.js';
import { HELP } from '../src/cli.js';
+import { loadConfig } from '../src/config.js';
import { Refused } from '../src/refused.js';
import { BLANKS, IN_STATE, MACHINE, effectiveGuards, lifecycleHelp, lifecycleMarkdown, machineProblems, storeTriggers } from '../src/machine.js';
-import { spawnSync } from 'node:child_process';
+import { execFileSync, spawnSync } from 'node:child_process';
/**
* Refusals that are not about an item's lifecycle, so no move declares them: how a command was
@@ -35,6 +36,7 @@ const ENTRY_POINTS = [
{ verbs: ['claim'], at: ['board.js#claim'] },
{ verbs: ['release'], at: ['board.js#release'] },
{ verbs: ['submit'], at: ['board.js#submit', 'cli.js#submitHere'] },
+ { verbs: ['reserve'], at: ['board.js#reserveReview', 'board.js#reserveNextReview'] },
{ verbs: ['accept', 'reject'], at: ['board.js#verify', 'cli.js#verifyHere'] },
{ verbs: ['escalate'], at: ['board.js#escalate'] },
{ verbs: ['withdraw'], at: ['board.js#withdraw'] },
@@ -115,7 +117,7 @@ function codeWalk(read) {
const body = bodies.get(name) ?? '';
const codes = new Set([...body.matchAll(/new Refused\(\s*(['"])([A-Z_]+)\1/g)].map((match) => match[2]));
const callees = [
- ...[...body.matchAll(/(?<![.\w])(\w+)\(/g)].map(([, callee]) => (bodies.has(callee) ? `${file}#${callee}` : named.get(callee) ?? CALLBACKS[file]?.[callee])),
+ ...[...body.matchAll(/(?<!\w)(?<!(?<!\.\.)\.)(\w+)\(/g)].map(([, callee]) => (bodies.has(callee) ? `${file}#${callee}` : named.get(callee) ?? CALLBACKS[file]?.[callee])),
...[...body.matchAll(/\b(\w+)\.(\w+)\(/g)].map(([, space, callee]) => (spaces.has(space) ? `${spaces.get(space)}#${callee}` : undefined)),
];
for (const callee of callees.filter(Boolean)) for (const code of refusalsOf(callee, skip, seen)) codes.add(code);
@@ -342,7 +344,7 @@ test('the declared lifecycle is sound: reachable, no traps, no second door, ever
assert.deepEqual(machineProblems(), []);
assert.deepEqual(MACHINE.states.map((state) => state.id), ['open', 'claimed', 'submitted', 'verified', 'withdrawn']);
assert.deepEqual(MACHINE.states.filter((state) => state.final).map((state) => state.id), ['verified', 'withdrawn']);
- assert.deepEqual(MACHINE.moves.map((move) => move.verb), ['claim', 'release', 'lapse', 'submit', 'accept', 'reject', 'escalate', 'refreeze', 'withdraw']);
+ assert.deepEqual(MACHINE.moves.map((move) => move.verb), ['claim', 'release', 'lapse', 'submit', 'reserve', 'accept', 'reject', 'escalate', 'refreeze', 'withdraw']);
});
for (const broken of BROKEN) {
@@ -433,7 +435,8 @@ test('a broken copy of the code fails the check: a refusal added wherever a move
assert.deepEqual(codeProblems(MACHINE, inArrow).sort(), [
'NO_ROUTE is raised by accept and reject but not declared there',
'NO_ROUTE is raised by claim but not declared there',
- ]);
+ 'NO_ROUTE is raised by reserve but not declared there',
+ ], 'reserve reaches the route check through the reviewer checks it shares with a verdict');
const doubleQuoted = editedSource('cli.js', /^const cdTo = .*$/m, "const cdTo = (root) => { if (!root) throw new Refused(\"NO_ROOT\", 'no root'); return 'cd ' + root + ' &&'; };");
assert.deepEqual(codeProblems(MACHINE, doubleQuoted), ['NO_ROOT is raised by accept and reject but not declared there']);
@@ -454,12 +457,13 @@ const freeze = (item) => ({ text: item.item_title, digest: `digest:${item.item_t
* A board file on disk with a coordinator and two web agents, opened the way the CLI opens it,
* and a way to open the same file raw, as any agent with a shell could.
*
+ * @param {{ now: () => Date }} [clock] - The board's clock; the system's when left out.
* @returns {{ file: string, board: any, raw: () => DatabaseSync, done: () => void }}
*/
-function boardOnDisk() {
+function boardOnDisk(clock) {
const dir = mkdtempSync(join(tmpdir(), 'pullboard-machine-'));
const file = join(dir, 'board.sqlite');
- const board = store.openBoard(file);
+ const board = store.openBoard(file, clock);
store.register(board, { lane: 'coordinator', path: '/repo' });
store.register(board, { lane: 'web', path: '/repo-web-1' });
store.register(board, { lane: 'web', path: '/repo-web-2' });
@@ -744,6 +748,7 @@ test('pullboard help lists each role\'s moves from the declaration, and pullboar
const CLI_CHECKED = {
claim: ['joined'],
submit: ['joined', 'criterionUnchanged', 'treeClean', 'nothingUntracked', 'hasCommit', 'gateConfigured', 'gateGreen'],
+ reserve: ['coordinatorSaysAs', 'joined'],
accept: ['coordinatorSaysAs', 'joined', 'atSubmittedCommit'],
reject: ['coordinatorSaysAs', 'joined', 'atSubmittedCommit'],
};
@@ -848,10 +853,12 @@ test('submit, accept and reject refuse in the declared order, one failure peeled
submits.push(submitAs(piece, 'web-1', SHA_A), submitAs(piece, 'web-1', SHA_B));
assert.deepEqual(submits, [...declaredBoardOrder('submit'), 'ok']);
+ const other = store.register(board, { lane: 'web', path: '/repo-web-other' });
for (const verb of ['accept', 'reject']) {
const decision = verb === 'accept' ? 'ACCEPT' : 'REJECT';
const built = submittedItem(board);
const open = store.addItem(board, { by: 'coordinator', lane: 'web', title: 'Page' });
+ store.reserveReview(board, built, { agentId: 'web-2', leaseMs: 3_600_000, policy: 'any' });
const judge = (id, agentId, fields) =>
outcome(() => store.verify(board, id, { agentId, decision, head: SHA_A, digest: 'wrong', policy: 'coordinator', note: '', ...fields }));
const bad = verb === 'accept' ? 'TEST_FAILURE' : 'NOPE';
@@ -862,6 +869,7 @@ test('submit, accept and reject refuse in the declared order, one failure peeled
judge(built, 'web-1', { reason: bad }),
judge(built, light, { reason: bad }),
judge(built, 'web-2', { reason: bad }),
+ judge(built, other, { reason: bad, policy: 'any' }),
judge(built, 'web-2', { reason: bad, policy: 'any' }),
judge(built, 'web-2', { reason: bad, policy: 'any', digest: 'digest:Page' }),
judge(built, 'web-2', { reason: good, policy: 'any', digest: 'digest:Page' }),
@@ -874,6 +882,236 @@ test('submit, accept and reject refuse in the declared order, one failure peeled
}
});
+test('reserve refuses in the declared order, one failure peeled at a time [V15, M1, M2]', () => {
+ const lab = boardOnDisk();
+ try {
+ const { board } = lab;
+ const light = store.register(board, { lane: 'web', path: '/repo-web-light', route: 'light' });
+ const other = store.register(board, { lane: 'web', path: '/repo-web-other' });
+ const built = submittedItem(board);
+ const open = store.addItem(board, { by: 'coordinator', lane: 'web', title: 'Page' });
+ const reserveAs = (id, agentId, policy = 'coordinator') => outcome(() => store.reserveReview(board, id, { agentId, leaseMs: 3_600_000, policy }));
+ const fired = [reserveAs(999, 'web-2'), reserveAs(open, 'web-2'), reserveAs(built, 'web-1'), reserveAs(built, light), reserveAs(built, 'web-2')];
+ store.reserveReview(board, built, { agentId: other, leaseMs: 3_600_000, policy: 'any' });
+ fired.push(reserveAs(built, 'web-2', 'any'), reserveAs(built, other, 'any'));
+ assert.deepEqual(fired, [...declaredBoardOrder('reserve'), 'ok']);
+ assert.deepEqual(fired, ['NO_ITEM', 'NOT_SUBMITTED', 'SELF_VERIFY', 'ROUTE', 'COORDINATOR_VERIFIES', 'REVIEW_HELD', 'ok']);
+ } finally {
+ lab.done();
+ }
+});
+
+test('a reserved review refuses every other verdict while its lease lives, and only then; a new submission starts free [V15]', () => {
+ let at = Date.parse('2026-10-06T12:00:00.000Z');
+ const lab = boardOnDisk({ now: () => new Date(at) });
+ try {
+ const { board } = lab;
+ const third = store.register(board, { lane: 'web', path: '/repo-web-3' });
+ const id = submittedItem(board);
+ const minutes = (count) => {
+ at += count * 60_000;
+ };
+ const reserve = (agentId) => store.reserveReview(board, id, { agentId, leaseMs: 30 * 60_000, policy: 'any' });
+ const judge = (agentId, decision) =>
+ outcome(() =>
+ store.verify(board, id, {
+ agentId,
+ decision,
+ reason: decision === 'REJECT' ? 'TEST_FAILURE' : undefined,
+ note: 'reverted the fix; its test went red',
+ head: store.getItem(board, id).item_commit,
+ digest: 'digest:Page',
+ policy: 'any',
+ }),
+ );
+ const holder = () => store.reviewHolder(board, store.getItem(board, id));
+ const offered = (agentId) => store.nextFor(board, { agentId, lane: 'web', verify: true });
+
+ assert.equal(reserve('web-2').item_review_until, '2026-10-06T12:30:00.000Z');
+ assert.equal(holder(), 'web-2');
+ assert.equal(offered(third).item ?? null, null, 'another agent is passed over');
+ assert.match(offered(third).reasons.join('; '), /web-2 holds the review of #1 until 2026-10-06T12:30:00\.000Z/);
+ assert.equal(outcome(() => reserve(third)), 'REVIEW_HELD');
+ assert.equal(judge(third, 'ACCEPT'), 'REVIEW_HELD');
+ assert.equal(judge(third, 'REJECT'), 'REVIEW_HELD');
+ assert.equal(offered('web-2').item.item_id, id, 'the holder is offered its own review');
+
+ minutes(20);
+ assert.equal(reserve('web-2').item_review_until, '2026-10-06T12:50:00.000Z', 'reserving again renews the lease');
+ minutes(25);
+ assert.equal(judge(third, 'ACCEPT'), 'REVIEW_HELD', 'at 12:45 the renewed lease still holds');
+
+ minutes(6);
+ assert.equal(holder(), null, 'at 12:51 the lease has run out');
+ assert.equal(offered(third).item.item_id, id);
+ assert.equal(reserve(third).item_review_until, '2026-10-06T13:21:00.000Z');
+ assert.equal(judge('web-2', 'ACCEPT'), 'REVIEW_HELD', 'a lapsed lease gives nothing over the agent that reserved since');
+ assert.equal(judge(third, 'REJECT'), 'ok');
+ assert.equal(store.getItem(board, id).item_review_by, third, 'the reservation stays on the record');
+ assert.equal(holder(), null, 'but holds nothing once the item leaves submitted, though its lease lives until 13:21');
+
+ store.claim(board, id, { agentId: 'web-1', lane: 'web', leaseMs: 7_200_000, freeze });
+ store.submit(board, id, { agentId: 'web-1', commit: SHA_B, tree: 'tree' });
+ assert.equal(store.getItem(board, id).item_review_by, null, 'a new submission starts with no reservation');
+ assert.equal(offered('web-2').item.item_id, id, 'though the last lease would live until 13:21');
+
+ reserve('web-2');
+ minutes(60);
+ assert.equal(holder(), null);
+ assert.equal(judge('web-2', 'ACCEPT'), 'ok', "the holder's own verdict is never refused for its lease having lapsed");
+ assert.equal(store.getItem(board, id).item_status, 'verified');
+ const reserved = store
+ .events(board, { itemId: id })
+ .filter((event) => event.event_kind === 'reserve')
+ .map((event) => [event.event_by, JSON.parse(event.event_detail).until]);
+ assert.deepEqual(reserved, [
+ ['web-2', '2026-10-06T12:30:00.000Z'],
+ ['web-2', '2026-10-06T12:50:00.000Z'],
+ [third, '2026-10-06T13:21:00.000Z'],
+ ['web-2', '2026-10-06T13:21:00.000Z'],
+ ]);
+ } finally {
+ lab.done();
+ }
+});
+
+test('next --verify reserves the review for the reviewLease and says until when; show names the holder; another verifier is passed over and refused [V15]', () => {
+ const dir = realpathSync(mkdtempSync(join(tmpdir(), 'pullboard-reserve-')));
+ try {
+ const env = {
+ ...process.env,
+ GIT_CONFIG_GLOBAL: '/dev/null',
+ GIT_CONFIG_NOSYSTEM: '1',
+ GIT_AUTHOR_NAME: 'Test Agent',
+ GIT_AUTHOR_EMAIL: '[email protected]',
+ GIT_COMMITTER_NAME: 'Test Agent',
+ GIT_COMMITTER_EMAIL: '[email protected]',
+ PULLBOARD_HOME: join(dir, 'home'),
+ };
+ const git = (cwd, ...args) => execFileSync('git', args, { cwd, env, encoding: 'utf8', stdio: 'pipe' }).trim();
+ // A command that never returns fails the test after a minute instead of holding the gate open.
+ const run = (cwd, ...args) => spawnSync(process.execPath, [BIN, ...args], { cwd, env, encoding: 'utf8', timeout: 60_000 });
+ const repo = join(dir, 'repo');
+ mkdirSync(repo);
+ git(repo, 'init', '-q', '-b', 'main');
+ writeFileSync(join(repo, 'pullboard.json'), JSON.stringify({ gate: 'true', reviewLease: '45m', lanes: { web: { owns: ['web/'] } } }));
+ writeFileSync(join(repo, 'SPEC.md'), '# Demo\n\n## G · Goals\n- G1 [approved, must] It greets. | gate: test\n');
+ git(repo, 'add', '-A');
+ git(repo, 'commit', '-q', '-m', 'chore: a spec');
+ const [builder, holder, other] = ['web-1', 'web-2', 'web-3'].map((name) => {
+ const path = join(dir, name);
+ git(repo, 'worktree', 'add', '-q', '--detach', path);
+ const joined = run(path, 'join', 'web');
+ assert.match(joined.stdout, new RegExp(`joined as ${name}`), joined.stderr);
+ return path;
+ });
+ const added = run(repo, 'add', 'web', 'Greet', '--specs', 'G1', '--criterion', 'It greets.');
+ assert.equal(added.status, 0, added.stderr);
+ assert.equal(run(builder, 'claim', '1').status, 0);
+ mkdirSync(join(builder, 'web'));
+ writeFileSync(join(builder, 'web', 'greet.txt'), 'hello\n');
+ git(builder, 'add', '-A');
+ git(builder, 'commit', '-q', '-m', 'feat(web): greet [G1]');
+ const commit = git(builder, 'rev-parse', 'HEAD');
+ const submitted = run(builder, 'submit', '1');
+ assert.equal(submitted.status, 0, submitted.stderr);
+
+ const before = Date.now();
+ const first = run(holder, 'next', '--verify');
+ const after = Date.now();
+ assert.equal(first.status, 0, first.stderr);
+ const until = /reserved for you until (\S+): another agent's verdict on it is refused until then/.exec(first.stdout)?.[1];
+ assert.ok(until, first.stdout);
+ const lease = 45 * 60_000;
+ assert.ok(Date.parse(until) >= before + lease && Date.parse(until) <= after + lease, `${until} is 45 minutes on, the repo's reviewLease`);
+ assert.ok(run(repo, 'show', '1').stdout.includes(`under review by web-2 until ${until}`), 'show names the holder and the time');
+
+ const passed = run(other, 'next', '--verify');
+ assert.equal(passed.status, 1, passed.stdout);
+ assert.match(passed.stderr, /NOTHING_FREE/);
+ assert.ok(passed.stderr.includes(`web-2 holds the review of #1 until ${until}`), passed.stderr);
+ git(other, 'switch', '-q', '--detach', commit);
+ const refused = run(other, 'verify', '1', 'accept', '--note', 'it greets');
+ assert.equal(refused.status, 1, refused.stdout);
+ assert.match(refused.stderr, /REVIEW_HELD/);
+ assert.ok(refused.stderr.includes(`web-2 holds the review of #1 until ${until}`), refused.stderr);
+
+ const renewed = run(holder, 'next', '--verify');
+ const again = /reserved for you until (\S+):/.exec(renewed.stdout)?.[1];
+ assert.ok(again && Date.parse(again) > Date.parse(until), `running next --verify again renews the lease: ${renewed.stdout}${renewed.stderr}`);
+ git(holder, 'switch', '-q', '--detach', commit);
+ const accepted = run(holder, 'verify', '1', 'accept', '--note', 'checked out the commit; web/greet.txt says hello');
+ assert.equal(accepted.status, 0, accepted.stderr);
+ } finally {
+ rmSync(dir, { recursive: true, force: true });
+ }
+});
+
+test('next --verify looks and reserves in one transaction, so no other verifier takes the review in between [V15]', () => {
+ const lab = boardOnDisk();
+ const others = [];
+ try {
+ const id = submittedItem(lab.board);
+ const third = store.register(lab.board, { lane: 'web', path: '/repo-web-3' });
+ const fourth = store.register(lab.board, { lane: 'web', path: '/repo-web-4' });
+ // A reservation that has already lapsed, so the look has a lease to read the clock for.
+ store.reserveReview(lab.board, id, { agentId: fourth, leaseMs: 1, policy: 'any' });
+ const rival = store.openBoard(lab.file);
+ rival.db.exec('PRAGMA busy_timeout = 0');
+ let armed = false;
+ let rivalSaw = null;
+ // web-2's own connection. Its clock runs a minute ahead, so the lapsed lease is plainly lapsed,
+ // and the first time the look reads it, a rival verifier on another connection tries to
+ // reserve the same review.
+ const looking = store.openBoard(lab.file, {
+ now: () => {
+ if (armed && rivalSaw === null) {
+ try {
+ store.reserveReview(rival, id, { agentId: third, leaseMs: 60_000, policy: 'any' });
+ rivalSaw = 'reserved';
+ } catch (error) {
+ rivalSaw = error.message;
+ }
+ }
+ return new Date(Date.now() + 60_000);
+ },
+ });
+ others.push(rival, looking);
+ armed = true;
+ const found = store.reserveNextReview(looking, { agentId: 'web-2', lane: 'web', leaseMs: 60_000, policy: 'any' });
+ assert.equal(found.item?.item_review_by, 'web-2');
+ assert.ok(rivalSaw !== null, 'the look read the clock, so the rival had its chance mid-look');
+ assert.match(rivalSaw, /locked/, 'the rival could not write while the look held the board');
+ } finally {
+ for (const board of others) store.closeBoard(board);
+ lab.done();
+ }
+});
+
+test('the review lease is reviewLease in pullboard.json, 30 minutes unless the repo says otherwise [V15]', () => {
+ const dir = mkdtempSync(join(tmpdir(), 'pullboard-review-lease-'));
+ try {
+ const leaseOf = (config) => {
+ writeFileSync(join(dir, 'pullboard.json'), JSON.stringify({ gate: 'true', ...config }));
+ return loadConfig(dir).reviewLeaseMs;
+ };
+ assert.equal(leaseOf({}), 30 * 60_000);
+ assert.equal(leaseOf({ reviewLease: '2h' }), 2 * 3_600_000);
+ assert.throws(() => leaseOf({ reviewLease: 'soon' }), { code: 'BAD_CONFIG', message: /reviewLease "soon" is not a duration/ });
+ } finally {
+ rmSync(dir, { recursive: true, force: true });
+ }
+});
+
+test('the lifecycle page and the help show the reservation: reserve, and reviewFree on every verdict [V15, M1]', () => {
+ const page = lifecycleMarkdown();
+ assert.match(page, /^\| reserve \| submitted \| submitted \| agent, coordinator \| .*reviewFree \(REVIEW_HELD\) \|$/m);
+ for (const verb of ['accept', 'reject']) assert.match(page, new RegExp(`^\\| ${verb} \\| submitted \\| .*policyAllows \\(COORDINATOR_VERIFIES\\), reviewFree \\(REVIEW_HELD\\), criterionUnchanged`, 'm'));
+ assert.match(page, /^\| REVIEW_HELD \| no other agent holds its review under a live lease \| pullboard next --verify/m);
+ assert.match(HELP, /^ {2}agent +claim, release, submit, reserve, accept, reject, escalate$/m);
+ assert.match(HELP, /pullboard next --verify +reserve the next submitted item you can check/);
+});
+
test('the two conditional guards behave as declared: a renewal passes a held lane, and only a freeze checks the rows [M1, M2]', () => {
const lab = boardOnDisk();
try {