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: allow bound board updates during submit [V4,C7]
Corey Olson44bbc6f0040b
diff --git a/src/agent-session.js b/src/agent-session.jsindex d94020ae..c32f010d 100644--- a/src/agent-session.js+++ b/src/agent-session.js@@ -23,6 +23,12 @@ function readBinding(file, takeover) {}}+/** Check whether this already-bound checkout belongs to the invoking agent session. */+export function localSessionMatches(info, { agent, digest }) {+ const current = readBinding(checkoutSessionFile(info), false);+ return current !== null && current.agent === agent && current.digest === digest;+}+/** Serialize local binding changes, record an explicit takeover, and replace complete JSON atomically. */export async function bindLocalSession(info, { agent, digest, takeover = false, recordTakeover, keepLease = false }) {const file = checkoutSessionFile(info);diff --git a/src/cli.js b/src/cli.jsindex 86c88f4e..1ec82219 100644--- a/src/cli.js+++ b/src/cli.js@@ -15,7 +15,7 @@ import { CONFIG_FILE, COORDINATOR, DOCTRINE_FILE, LEGACY_DOCTRINE_FILE, loadConfimport { displayAgentName } from './agent-names.js';import { doctrineHistory, loadDoctrine } from './doctrine.js';import { agentSessionDigest, requirePersonChannel } from './person.js';-import { bindLocalSession } from './agent-session.js';+import { bindLocalSession, localSessionMatches } from './agent-session.js';import { decisionProjection, planRowApply, prepareRowDecisions, restoreRowApply, writeRowApply } from './row-decisions.js';import { digestOf, gateReport, runGate, runProfiledShell, runSubmitGate, submitGateReport, timingDigest, withGateSlot } from './gate.js';import { bareWorktreeFinding, codeIsFromMain, contains, differFromHead, git, gitChildEnv, headCommit, headTree, invalidateGitFacts, isClean, mainCheckout, patchId, repoInfo, resolveCommit, tryGit, untracked, withGitFacts } from './git.js';@@ -87,6 +87,7 @@ import { engineReceipt } from './engine.js';import { land } from './land.js';const CHECKOUT_LEASES = new WeakMap();+const CHECKOUT_BOARD_ONLY = new WeakMap();let startupMainTraced = false;/** Append an opt-in startup phase marker for the real CLI fixture measurement [A2,C7]. */@@ -528,6 +529,10 @@ async function ordered(ctx, board, operation, args) {const execute = () => relayLinked(ctx.info.root)? relayOperation(ctx.info.root, operation, args, ctx.io, command, () => store[operation](board, ...args)) : store[operation](board, ...args);const digest = agentSessionDigest();+ const boardOnly = CHECKOUT_BOARD_ONLY.get(ctx.io);+ const boardOnlyOperation = (boardOnly === 'shout' && operation === 'shout') || (boardOnly === 'fact' && operation === 'appendFact');+ const boardOnlyAgent = ctx.info.isMain ? COORDINATOR : store.agentAt(board, ctx.info.root)?.agent_id ?? 'unjoined agent';+ if (boardOnlyOperation && digest && localSessionMatches(ctx.info, { agent: boardOnlyAgent, digest })) return execute();if (CHECKOUT_LEASES.has(ctx.io) || !digest || ctx.io.personChannel === 'view' || ctx.io.personRequest) return execute();const agent = ctx.info.isMain ? COORDINATOR : store.agentAt(board, ctx.info.root)?.agent_id ?? 'unjoined agent';const lease = await bindLocalSession(ctx.info, { agent, digest, keepLease: true });@@ -559,6 +564,10 @@ async function bindCheckoutSession(io, positionals, values) {?? (command === 'hook' && store.landingBatches(board).some((batch) => batch.root === info.root && !['landed', 'blocked'].includes(batch.state)) ? COORDINATOR : null));if (!agent && command !== 'join') throw new Refused('NOT_JOINED', 'this worktree has not joined a lane; run pullboard join <lane> --model "<model name>"');}+ if (['shout', 'fact'].includes(command) && localSessionMatches(info, { agent: agent ?? 'unjoined agent', digest })) {+ CHECKOUT_BOARD_ONLY.set(io, command);+ return;+ }const lease = await bindLocalSession(info, { agent: agent ?? 'unjoined agent', digest, takeover: command === 'takeover', keepLease: !['run', 'next'].includes(command),/** Use an existing ordered shout so takeover has a receipt without changing the board format. */recordTakeover: async () => {@@ -3347,6 +3356,7 @@ async function runMain(argv, streams) {return status;} finally {CHECKOUT_LEASES.delete(io);+ CHECKOUT_BOARD_ONLY.delete(io);checkoutSession?.lease?.release();}}diff --git a/test/submit-lease.test.js b/test/submit-lease.test.jsnew file mode 100644index 00000000..ef46f1cb--- /dev/null+++ b/test/submit-lease.test.js@@ -0,0 +1,186 @@+/** Board-only commands must stay responsive without weakening checkout ownership [V4,C7]. */+import assert from 'node:assert/strict';+import { after, test } from 'node:test';+import { DatabaseSync } from 'node:sqlite';+import { readFileSync, rmSync, writeFileSync } from 'node:fs';+import { join, resolve } from 'node:path';+import { performance } from 'node:perf_hooks';+import { createE2eHelpers } from './e2e-helpers.js';+import { listResources } from '../src/resources.js';++const helpers = createE2eHelpers();+after(helpers.cleanup);++/** Read only the board rows relevant to proving that a refused write made no change. */+function boardState(file) {+ const db = new DatabaseSync(file, { readOnly: true });+ try {+ return {+ item: db.prepare('SELECT item_id, item_status FROM item ORDER BY item_id').all(),+ shout: db.prepare('SELECT shout_id, shout_text FROM shout ORDER BY shout_id').all(),+ fact: db.prepare("SELECT event_id, event_detail FROM event WHERE event_kind = 'fact' ORDER BY event_id").all(),+ event: db.prepare('SELECT event_id, event_kind, event_detail FROM event ORDER BY event_id').all(),+ };+ } finally { db.close(); }+}++/** Wait for one durable fixture observation rather than relying on a scheduling delay. */+async function waitFor(predicate, description, timeoutMs = 8_000) {+ const deadline = Date.now() + timeoutMs;+ while (Date.now() < deadline) {+ const value = predicate();+ if (value) return value;+ await new Promise((resolveWait) => setTimeout(resolveWait, 20));+ }+ throw new Error(`timed out waiting for ${description}`);+}++/** Require a responsive command to finish within its explicit board-only latency budget. */+async function within(promise, timeoutMs, description) {+ let timer;+ try {+ return await Promise.race([promise, new Promise((_, reject) => {+ timer = setTimeout(() => reject(new Error(`${description} did not finish within ${timeoutMs}ms`)), timeoutMs);+ })]);+ } finally { clearTimeout(timer); }+}++/** Set the explicit fixture session only for the synchronous child spawn. */+function launchAs(box, cwd, command, args, session) {+ box.env.CODEX_SESSION_ID = session;+ try { return helpers.launch(box, cwd, command, args); }+ finally { delete box.env.CODEX_SESSION_ID; }+}++test('a seat can shout while its own submit runs [V4,C7]', { timeout: 45_000 }, async () => {+ const box = helpers.sandbox();+ const gate = helpers.holdingGate(box);+ const project = helpers.project(gate.command, box);+ const markers = [+ 'PULLBOARD_GATE_SLOT_HELD', 'PULLBOARD_GATE_SLOT_POOL',+ 'PULLBOARD_GATE_SLOT_TOKEN', 'PULLBOARD_BROWSER_SLOT_HELD',+ ];+ for (const marker of markers) delete project.env[marker];+ assert.equal(project.run(project.repo, 'settings', 'gateSlots', '1').code, 0);+ assert.equal(project.run(project.repo, 'add', 'web', 'Held submit', '--specs', 'G1').code, 0);+ const owner = 'checkout-owner-598';+ const intruder = 'checkout-intruder-598';+ const children = [];+ const claim = launchAs(project, project.web, process.execPath, [helpers.BIN, 'claim', '1'], owner);+ children.push(claim);+ const claimResult = await claim.closed;+ assert.equal(claimResult.code, 0, claim.failure ?? claim.stderrText);+ assert.equal(helpers.commitFile(project, project.web, 'web/page.html', 'page', 'feat(web): held submit [G1]').status, 0);+ const expectedHead = project.git(project.web, 'rev-parse', 'HEAD');+ const database = join(project.repo, '.git', 'pullboard', 'board.sqlite');+ const bindingFile = resolve(project.web, project.git(project.web, 'rev-parse', '--git-dir'), 'pullboard-checkout-session.json');+ const originalBinding = readFileSync(bindingFile, 'utf8');+ writeFileSync(gate.mode, 'armed');+ let submit;+ let missingBindingSession;+ let wrongSession;+ let takeover;+ try {+ submit = launchAs(project, project.web, process.execPath, [helpers.BIN, 'submit', '1'], owner);+ children.push(submit);+ await waitFor(() => helpers.gateEvents(gate).includes('start'), 'submit to enter its held gate');+ assert.equal(submit.exitCode, null, 'submit remains active inside the gate');++ const beforeBoardOnly = boardState(database);+ const shoutStarted = performance.now();+ const shout = launchAs(project, project.web, process.execPath, [helpers.BIN, 'shout', 'coordinator', 'still responsive during submit'], owner);+ children.push(shout);+ const shoutResult = await within(shout.closed, 5_000, 'same-session shout');+ assert.equal(shoutResult.code, 0, shout.failure ?? shout.stderrText);+ assert.ok(performance.now() - shoutStarted < 5_000, 'same-session shout finishes within the board-only response budget');+ const factStarted = performance.now();+ const fact = launchAs(project, project.web, process.execPath, [helpers.BIN, 'fact', '1', 'note', 'the held submit remains active'], owner);+ children.push(fact);+ const factResult = await within(fact.closed, 5_000, 'same-session fact');+ assert.equal(factResult.code, 0, fact.failure ?? fact.stderrText);+ assert.ok(performance.now() - factStarted < 5_000, 'same-session fact finishes within the board-only response budget');+ const read = launchAs(project, project.web, process.execPath, [helpers.BIN, 'show', '1'], owner);+ children.push(read);+ const readResult = await within(read.closed, 5_000, 'same-session read');+ assert.equal(readResult.code, 0, read.failure ?? read.stderrText);+ assert.deepEqual(helpers.gateEvents(gate), ['start'], 'board-only commands do not release or restart the held gate');+ assert.equal(submit.exitCode, null);+ const afterBoardOnly = boardState(database);+ assert.deepEqual(afterBoardOnly.item, beforeBoardOnly.item);+ assert.equal(afterBoardOnly.shout.length, beforeBoardOnly.shout.length + 1);+ assert.match(afterBoardOnly.shout.at(-1).shout_text, /still responsive during submit/u);+ assert.equal(afterBoardOnly.fact.length, beforeBoardOnly.fact.length + 1);+ assert.match(afterBoardOnly.fact.at(-1).event_detail, /held submit remains active/u);+ assert.equal(afterBoardOnly.event.length, beforeBoardOnly.event.length + 2);++ const currentBinding = readFileSync(bindingFile, 'utf8');+ writeFileSync(bindingFile, '{ damaged binding\n');+ const corrupt = launchAs(project, project.web, process.execPath, [helpers.BIN, 'shout', 'coordinator', 'corrupt binding must fail closed', '--json'], owner);+ children.push(corrupt);+ const corruptResult = await within(corrupt.closed, 5_000, 'corrupt-binding refusal');+ assert.equal(corruptResult.code, 1);+ assert.equal(JSON.parse(corrupt.stdoutText).error.code, 'CHECKOUT_SESSION');+ writeFileSync(bindingFile, currentBinding);+ assert.deepEqual(boardState(database), afterBoardOnly, 'a corrupt binding cannot use the board-only path');++ rmSync(bindingFile, { force: true });+ missingBindingSession = launchAs(project, project.web, process.execPath,+ [helpers.BIN, 'shout', 'coordinator', 'missing binding must queue', '--json'], owner);+ children.push(missingBindingSession);+ await waitFor(() => {+ const resource = listResources({ scope: 'repo', root: project.repo }).find((entry) => entry.name.startsWith('checkout-session:'));+ return resource?.holders.length === 1 && resource.line.length === 1;+ }, 'same-session write with a missing binding to queue behind submit');+ assert.equal(missingBindingSession.exitCode, null, 'a missing binding takes the normal checkout lease path');+ writeFileSync(bindingFile, currentBinding);++ wrongSession = launchAs(project, project.web, process.execPath, [helpers.BIN, 'shout', 'coordinator', 'wrong session must not write', '--json'], intruder);+ children.push(wrongSession);+ await waitFor(() => {+ const resource = listResources({ scope: 'repo', root: project.repo }).find((entry) => entry.name.startsWith('checkout-session:'));+ return resource?.holders.length === 1 && resource.line.length === 2;+ }, 'wrong-session write to queue after the missing-binding command');+ takeover = launchAs(project, project.web, process.execPath, [helpers.BIN, 'takeover', '--json'], intruder);+ children.push(takeover);+ await waitFor(() => {+ const resource = listResources({ scope: 'repo', root: project.repo }).find((entry) => entry.name.startsWith('checkout-session:'));+ return resource?.holders.length === 1 && resource.line.length === 3;+ }, 'wrong-session write and takeover to queue behind the active submit');+ assert.equal(missingBindingSession.exitCode, null);+ assert.equal(wrongSession.exitCode, null, 'wrong-session write remains serialized behind the active submit');+ assert.equal(takeover.exitCode, null, 'takeover remains serialized behind the active submit');+ assert.deepEqual(boardState(database), afterBoardOnly, 'wrong-session write and takeover add no board rows before acquiring the checkout');+ assert.equal(helpers.gateEvents(gate).join(','), 'start');++ writeFileSync(gate.release, 'released');+ const [submitResult, missingBindingResult, wrongResult, takeoverResult] = await Promise.all([+ submit.closed, missingBindingSession.closed, wrongSession.closed, takeover.closed,+ ]);+ assert.equal(submitResult.code, 0, submit.failure ?? submit.stderrText);+ assert.match(submit.stdoutText, /submitted #1/u);+ assert.equal(missingBindingResult.code, 0, missingBindingSession.failure ?? missingBindingSession.stderrText);+ assert.equal(wrongResult.code, 1);+ assert.equal(JSON.parse(wrongSession.stdoutText).error.code, 'NOT_YOUR_CHECKOUT');+ assert.equal(takeoverResult.code, 0, takeover.failure ?? takeover.stderrText);+ assert.equal(project.git(project.web, 'rev-parse', 'HEAD'), expectedHead, 'submit leaves the originally submitted HEAD unchanged');+ assert.equal(project.git(project.repo, 'rev-parse', `refs/pullboard/items/1/${expectedHead.slice(0, 12)}`), expectedHead,+ 'the submit receipt pins exactly the original HEAD');+ assert.equal(boardState(database).item[0].item_status, 'submitted');+ assert.deepEqual(helpers.gateEvents(gate), ['start', 'end']);++ const beforeOldOwner = boardState(database);+ const oldOwner = launchAs(project, project.web, process.execPath,+ [helpers.BIN, 'shout', 'coordinator', 'old owner cannot write after takeover', '--json'], owner);+ children.push(oldOwner);+ const oldOwnerResult = await oldOwner.closed;+ assert.equal(oldOwnerResult.code, 1);+ assert.equal(JSON.parse(oldOwner.stdoutText).error.code, 'NOT_YOUR_CHECKOUT');+ assert.deepEqual(boardState(database), beforeOldOwner, 'takeover leaves the previous session unable to append a shout');+ } finally {+ writeFileSync(bindingFile, originalBinding);+ writeFileSync(gate.release, 'released');+ for (const child of children) if (child.exitCode === null) child.kill('SIGTERM');+ if (submit?.exitCode === null) submit.kill('SIGTERM');+ await Promise.all([...children, ...(submit ? [submit] : [])].map((child) => child.closed));+ }+});