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(core): preserve versioned reopen authority [E21,V2]
Corey Olson3819b6fe7af8
diff --git a/docs/formats.md b/docs/formats.mdindex e008267e..d1adf19b 100644--- a/docs/formats.md+++ b/docs/formats.md@@ -406,7 +406,7 @@ Each connection also has a temporary `moving(token INTEGER)` table and `status_tThe `event` table is a SQLite schema object governed by `SCHEMA_VERSION`; its append-only record format has the independent `EVENT_LOG_VERSION`. Each event has an increasing integer id, an ISO timestamp, the actor, the event kind, an optional item id, and a JSON object in `event_detail`. Board moves append their event inside the same immediate transaction as the move. Events are append-only; board triggers reject updates and deletes. The actor column is the acting agent id, except guard-repair events, which use `board`. Under engine 8 and later, each event by a registered agent also carries a `model` string snapshot in `event_detail`; legacy agents without a declaration use `unknown`. Declared models live under `agent_model:<agent id>` in `board_meta`, without changing the agent table or stable ids. Rejoining with another model appends a `model` event whose common snapshot holds the new declaration. This common snapshot is separate from the per-kind payload fields listed below. The following rows name the emitted kinds and the union of their operation-specific detail keys; CLI accept events additionally carry the frozen-check result described below:-The computed-grant engine adds `grantEngine` to new join, claim and renewal events as a version marker only. It stores no grant or scope: permission is computed from the seat lane, current claim and lease, or the current review reservation. Older event bytes remain unchanged. A new marker prevents an older engine from reinterpreting a narrowed claim; communication and review administration keep their existing engine floors.+The computed-grant engine adds `grantEngine` to new join, claim and renewal events as a version marker only. It stores no grant or scope: permission is computed from the seat lane, current claim and lease, or the current review reservation. Older event bytes remain unchanged. A new marker prevents an older engine from reinterpreting a narrowed claim; shout, release and review reservation keep their existing engine floors. Reopen still checks the marked seat and target version floor, while its own authority guards decide permission: current conflict returns are coordinator-only, and the exact accepting reviewer can withdraw its current verdict independently of a build claim. Older recorded submitted-conflict moves retain their joined-seat authority.<!-- events:start -->| Kind | Actor | Detail fields |diff --git a/docs/lifecycle.md b/docs/lifecycle.mdindex d66e0f45..f2ac9487 100644--- a/docs/lifecycle.md+++ b/docs/lifecycle.md@@ -97,9 +97,9 @@ Each move checks its guards in this order and refuses with the first one that do| AGENT_REPLACED | the caller is the main checkout, or an unreplaced worktree seat that joined a lane; an agent session's claims, submits and verdicts can be checked against its local ledger | read the takeover and only shout on its exact hand-off item; continue work from the incoming agent worktree || SESSION_LEDGER | the caller is the main checkout, or an unreplaced worktree seat that joined a lane; an agent session's claims, submits and verdicts can be checked against its local ledger | make the agent-session ledger named in the message readable and writable by this user, then run the command again || NO_ITEM | the item exists | pullboard list --all |-| COORDINATOR_ONLY | the coordinator reopens, a joined seat reports a submitted trunk conflict, or the exact accepting reviewer withdraws its verdict | ask the coordinator or the reviewer who recorded the accept |-| VERDICT_WITHDRAW_FORBIDDEN | the coordinator reopens, a joined seat reports a submitted trunk conflict, or the exact accepting reviewer withdraws its verdict | ask the accepting reviewer or coordinator to withdraw the verdict |-| VERDICT_WITHDRAW_STATE | the coordinator reopens, a joined seat reports a submitted trunk conflict, or the exact accepting reviewer withdraws its verdict | refresh the item; only a current acceptance before landing can be withdrawn |+| COORDINATOR_ONLY | the coordinator reopens, or the exact accepting reviewer withdraws its verdict; older recorded submitted-conflict moves keep their joined-seat authority | ask the coordinator or the reviewer who recorded the accept |+| VERDICT_WITHDRAW_FORBIDDEN | the coordinator reopens, or the exact accepting reviewer withdraws its verdict; older recorded submitted-conflict moves keep their joined-seat authority | ask the accepting reviewer or coordinator to withdraw the verdict |+| VERDICT_WITHDRAW_STATE | the coordinator reopens, or the exact accepting reviewer withdraws its verdict; older recorded submitted-conflict moves keep their joined-seat authority | refresh the item; only a current acceptance before landing can be withdrawn || COORDINATOR_ONLY | the caller is the coordinator | run it from the main checkout || MILESTONES_CORRUPT | the recorded queue policy and roadmap are readable when selecting the next review, only next --verify selection; a review reserved by id does not consult the roadmap | restore board metadata from a known-good board export || LINE_SETTING_RANGE | the recorded queue policy and roadmap are readable when selecting the next review, only next --verify selection; a review reserved by id does not consult the roadmap | restore the recorded board line setting from its ordered event history, then retry next --verify |diff --git a/src/agent-grant.js b/src/agent-grant.jsindex e2f11b30..7479356e 100644--- a/src/agent-grant.js+++ b/src/agent-grant.js@@ -36,6 +36,8 @@ export function agentGrantMinimum(board, move) {/** Refuse out-of-grant item changes at the same ordered instant on every replica. */export function requireAgentGrant(board, move, at = board.clock.now()) {if (move.engine < AGENT_GRANT_ENGINE || ADMINISTRATIVE.has(move.operation)) return;+ // Reopen owns coordinator/reviewer authority; agentGrantMinimum retains the marked-seat/target floor.+ if (move.operation === 'reopen') return;const actor = MOVE_REGISTRY[move.operation]?.actor(move);if (typeof actor !== 'string' || ['person', 'coordinator', 'machine'].includes(actor)) return;const seat = board.db.prepare('SELECT agent_lane FROM agent WHERE agent_id=?').get(actor);@@ -44,10 +46,6 @@ export function requireAgentGrant(board, move, at = board.clock.now()) {if (!scope) return;const item = existingItem(board, scope.item);if (!scope.creating && !item) return; // Preserve the operation's own malformed/missing-item refusal.- // Correcting the seat's own current acceptance is review administration, independent of its build claim.- // The normal withdrawal path still validates options, immutable verdict identity and unmerged state.- if (move.operation === 'reopen' && move.args?.[1]?.withdrawVerdict === true- && item?.item_status === 'verified' && item.item_verified_by === actor) return;// The seat's immutable handoff-open event grants only its own channel facts, not other item work.// Replacement fencing runs before this guard, so a taken-over seat keeps only its existing shout path.if (move.operation === 'appendFact' && board.db.prepare(diff --git a/src/board.js b/src/board.jsindex 6d7a4ed3..c823b0f9 100644--- a/src/board.js+++ b/src/board.js@@ -1452,10 +1452,11 @@ export function reopen(board, id, { agentId, note = '', conflict, cause, reopenFchecks: {joined: null,[IN_STATE]: (found) => new Refused('NOT_SUBMITTED', `item #${id} is ${current(board, found).item_status}, not submitted`),- // Any joined seat returns a submitted head that no longer merges, with Git's files and trunk (#807).+ // Historic joined-seat conflict reports keep their authority; current conflicts belong to the coordinator.reopenAuthority: (found) => {if (forWithdrawal) { withdrawnVerdict = verdictWithdrawal.verdictWithdrawalTarget(board, found, agentId); return null; }- return (forMerge && found.item_status === 'submitted' && currentEngine >= SUBMITTED_CONFLICT_ENGINE && listAgents(board).some((agent) => agent.agent_id === agentId)+ return (forMerge && found.item_status === 'submitted' && currentEngine >= SUBMITTED_CONFLICT_ENGINE+ && currentEngine < AGENT_GRANT_ENGINE && listAgents(board).some((agent) => agent.agent_id === agentId)? null : onlyCoordinator(agentId, 'reopens submissions'));},noteGiven: () => (forMerge || note.trim() ? null : new Refused('NOTE_REQUIRED', 'say why the criterion needs correction: --note "why"')),diff --git a/src/machine.js b/src/machine.jsindex 7bcd6771..2b8f5160 100644--- a/src/machine.js+++ b/src/machine.js@@ -99,7 +99,7 @@ export const GUARDS = [{ id: IN_STATE, refuse: '', rule: "the move can start from the item's current state", next: 'pullboard show <id>', source: 'board' },{ id: 'joined', refuse: 'NOT_JOINED', alsoRefuses: [{ code: 'AGENT_REPLACED', next: 'read the takeover and only shout on its exact hand-off item; continue work from the incoming agent worktree' }, { code: 'SESSION_LEDGER', next: 'make the agent-session ledger named in the message readable and writable by this user, then run the command again' }], rule: 'the caller is the main checkout, or an unreplaced worktree seat that joined a lane; an agent session\'s claims, submits and verdicts can be checked against its local ledger', next: 'pullboard join <lane> --model "<model name>" (see: pullboard lanes)', source: 'cli' },{ id: 'itemExists', refuse: 'NO_ITEM', rule: 'the item exists', next: 'pullboard list --all', source: 'board' },- { id: 'reopenAuthority', refuse: 'COORDINATOR_ONLY', rule: 'the coordinator reopens, a joined seat reports a submitted trunk conflict, or the exact accepting reviewer withdraws its verdict', next: 'ask the coordinator or the reviewer who recorded the accept', source: 'board', alsoRefuses: [{ code: 'VERDICT_WITHDRAW_FORBIDDEN', next: 'ask the accepting reviewer or coordinator to withdraw the verdict' }, { code: 'VERDICT_WITHDRAW_STATE', next: 'refresh the item; only a current acceptance before landing can be withdrawn' }] },+ { id: 'reopenAuthority', refuse: 'COORDINATOR_ONLY', rule: 'the coordinator reopens, or the exact accepting reviewer withdraws its verdict; older recorded submitted-conflict moves keep their joined-seat authority', next: 'ask the coordinator or the reviewer who recorded the accept', source: 'board', alsoRefuses: [{ code: 'VERDICT_WITHDRAW_FORBIDDEN', next: 'ask the accepting reviewer or coordinator to withdraw the verdict' }, { code: 'VERDICT_WITHDRAW_STATE', next: 'refresh the item; only a current acceptance before landing can be withdrawn' }] },{ id: 'coordinatorOnly', refuse: 'COORDINATOR_ONLY', rule: 'the caller is the coordinator', next: 'run it from the main checkout', source: 'board' },{ id: 'roadmapReadable', refuse: 'MILESTONES_CORRUPT', alsoRefuses: [{ code: 'LINE_SETTING_RANGE', rule: 'the recorded board line-order setting has a valid registry value', next: 'restore the recorded board line setting from its ordered event history, then retry next --verify' }], rule: 'the recorded queue policy and roadmap are readable when selecting the next review', next: 'restore board metadata from a known-good board export', source: 'board', when: 'only next --verify selection; a review reserved by id does not consult the roadmap' },{ id: 'coordinatorSaysAs', refuse: 'MAIN_IS_COORDINATOR', rule: 'in the main checkout, the caller says it is the coordinator', next: 'verify from your own worktree; the coordinator adds --as coordinator', source: 'cli' },diff --git a/test/reopen.test.js b/test/reopen.test.jsindex ceddd284..530d887f 100644--- a/test/reopen.test.js+++ b/test/reopen.test.js@@ -147,7 +147,6 @@ const engine9Source = '314ef28751c44c96186b337cc4ace0fd8bf33d42';/** Compare verified-item reopen behavior across engines 8 through 10 and the current receiver. */async function assertLegacyVerifiedReopen(t, box, item, note) {- let engine10Store, engine10Exchange;for (const [version, reference] of [[8, 'v0.8.6'], [9, engine9Source], [10, 'v0.8.23']]) {const directory = mkdtempSync(join(tmpdir(), `pullboard-engine-${version}-verified-reopen-`));t.after(() => rmSync(directory, { recursive: true, force: true }));@@ -637,6 +636,7 @@ test('manual reopen records a timestamp-prefixed failing test after an unrecorde});test('a reopened bar takes the same commit again [V2,V6,H16]', async (t) => {+ let engine10Store, engine10Exchange;const box = project();const submitted = submitFixture(box);const reviewPath = reserveFixtureReview(box);diff --git a/test/review-queue.test.js b/test/review-queue.test.jsindex f96b7aa0..a30cf31c 100644--- a/test/review-queue.test.js+++ b/test/review-queue.test.js@@ -5,6 +5,11 @@ import { createHash } from 'node:crypto';import { test } from 'node:test';import * as store from '../src/board.js';import { mkdirSync } from 'node:fs';+import { mkdtempSync } from 'node:fs';+import { rmSync } from 'node:fs';+import { tmpdir } from 'node:os';+import { pathToFileURL } from 'node:url';+import { unpackRelease } from './release-archive.js';import { writeFileSync } from 'node:fs';import { join } from 'node:path';import { createE2eHelpers } from './e2e-helpers.js';@@ -193,7 +198,10 @@ function staleHeadFixture(t) {test('a submitted head that no longer merges is returned to its builder [C7,V4]', (t) => {const { box, json, conflicted, reviewer } = staleHeadFixture(t);assert.equal(json(box.run(box.repo, 'show', String(conflicted), '--json')).item_status, 'submitted', 'the head waits for review before the trunk check');- const next = box.run(reviewer, 'next', '--verify', '--json');+ const refused = box.run(reviewer, 'next', '--verify', '--json');+ assert.equal(JSON.parse(refused.out).error.code, 'COORDINATOR_ONLY', 'a reviewer cannot return a conflicting submission');+ assert.equal(json(box.run(box.repo, 'show', String(conflicted), '--json')).item_status, 'submitted');+ const next = box.run(box.repo, 'next', '--verify', '--as', 'coordinator', '--json');assert.match(next.err, new RegExp(`returned #${conflicted} to its builder unreviewed: it no longer merges onto the trunk \\(web/list\\.html\\)`, 'u'), next.out + next.err);const item = json(box.run(box.repo, 'show', String(conflicted), '--json'));assert.equal(item.item_status, 'open', 'the head that no longer merges goes back, unreviewed');@@ -214,6 +222,9 @@ test('next --verify skips a head that does not merge [C7,V4]', (t) => {box.git(box.repo, 'worktree', 'add', '-q', second, '-b', 'web/two', 'main');json(box.run(second, 'join', 'web', '--json'));const clean = build('Show the footer', 'web/footer.html', '<footer>clean</footer>\n', second);+ // The coordinator returns the conflicting head; the explicit id avoids reserving the clean one.+ const returned = box.run(box.repo, 'next', '--verify', String(conflicted), '--as', 'coordinator', '--json');+ assert.equal(JSON.parse(returned.out).error.code, 'NOT_SUBMITTED', 'the returned head cannot receive a review reservation');const next = json(box.run(reviewer, 'next', '--verify', '--json'));assert.equal(next.item.item_id, clean, 'the reviewer gets the head that merges, though the conflicting one is older');assert.equal(json(box.run(box.repo, 'show', String(conflicted), '--json')).item_status, 'open');@@ -290,3 +301,41 @@ test('a fresh same-lane seat cannot reopen submitted conflicts under its grant [assert.equal(store.getItem(board, conflicted).item_review_by, null, 'the refused agent move reserves no review');}});+++test('recorded pre-grant submitted-conflict moves retain joined-seat authority [V2,H16]', async t => {+ const directory = mkdtempSync(join(tmpdir(), 'pullboard-legacy-submitted-conflict-'));+ t.after(() => rmSync(directory, { recursive: true, force: true }));+ // Accepted pre-grant source writes its own historical events; no future marker is removed or fabricated.+ unpackRelease('e4b7c30d674cde73803f8e8cb3f53fb2f9f62621', directory);+ const legacyStore = await import(pathToFileURL(join(directory, 'src/board.js')).href);+ const legacyExchange = await import(pathToFileURL(join(directory, 'src/exchange.js')).href);+ const legacyEngine = await import(pathToFileURL(join(directory, 'src/engine.js')).href);+ const legacy = legacyStore.openBoard(':memory:');+ const copies = [store.openBoard(':memory:'), store.openBoard(':memory:')];+ t.after(() => { legacyStore.closeBoard(legacy); copies.forEach(board => store.closeBoard(board)); });+ legacyStore.register(legacy, { lane: 'coordinator', path: join(directory, 'main') });+ const builder = legacyStore.register(legacy, { lane: 'web', path: join(directory, 'builder') });+ const reporter = legacyStore.register(legacy, { lane: 'web', path: join(directory, 'reporter') });+ const id = legacyStore.addItem(legacy, { by: 'coordinator', lane: 'web', title: 'Historical conflict', criterion: 'Retain the submitted conflict.' });+ legacyStore.claim(legacy, id, { agentId: builder, lane: 'web', leaseMs: HOUR, freeze });+ // Synthetic board-state receipt only; this test makes no gate-execution claim.+ legacyStore.submit(legacy, id, { agentId: builder, commit: 'a'.repeat(40), tree: 'b'.repeat(40),+ submissionProof: { version: 1, files: [], full: false, deferred: true, reason: 'synthetic board-state fixture; no gate execution' } });+ const snapshot = legacyExchange.exportBoard(legacy);+ assert.ok(snapshot.tables.event.filter(row => ['join', 'claim'].includes(row.event_kind))+ .every(row => JSON.parse(row.event_detail).grantEngine === undefined), 'the accepted old writer emits no future grant marker');+ for (const board of copies) importBoard(board, snapshot);+ const move = legacyEngine.prepareEngineMove(legacy, 'reopen', [id, {+ agentId: reporter, conflict: { files: ['web/list.html'], trunk: 'c'.repeat(40) },+ }]);+ assert.ok(move.engine < AGENT_GRANT_ENGINE, 'the genuine writer predates the new authority fence');+ const receipt = { sequence: 1, at: new Date().toISOString() };+ const historical = legacyEngine.applyEngineMove(legacy, move, receipt);+ assert.equal(historical.error, undefined, 'the accepted historical engine permits its joined-seat report');+ for (const board of copies) {+ assert.deepEqual(applyEngineMove(board, move, receipt), historical, 'each current replica preserves the recorded outcome');+ assert.equal(store.getItem(board, id).item_status, 'open');+ assert.deepEqual(store.events(board), legacyStore.events(legacy), 'replay preserves historical event bytes');+ }+});