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.

Merge main into core/921-claude; a session ledger that cannot be written refuses

Corey Olson792be6baca08
diff --cc src/cli.js
index 25c8e1e0,ecaf27ff..4f50d1d6
--- a/src/cli.js
+++ b/src/cli.js
@@@ -41,8 -41,7 +41,8 @@@ import
refuseNextIdle,
} from './next-steps.js';
import { reviewerStartup } from './next-steps.js';
- import { recordItemSession } from './item-sessions.js';
- import { refuseSelfSession } from './item-sessions.js';
++import * as itemSessions from './item-sessions.js';
+ import { submitPreflight } from './submit-preflight.js';
import * as store from './board.js';
import {
CONFIG_FILE,
@@@ -966,9 -965,6 +966,9 @@@ async function reserveRow(ctx, row, wri
}
/** Dispatch a board mutation locally, or seal it before any linked replica applies it. */
- /** Note the session behind a claim or submit (#921), then hand back the move's result unchanged. */
- function tapItemSession(info, operation, args, result) { if (operation === 'claim' || operation === 'submit') recordItemSession(info, args[0], operation); return result; }
++/** Note the session behind a claim or submit (#921): its ledger must be writable before the move, and record after it. */
++async function withItemSession(info, operation, args, move) { const noted = operation === 'claim' || operation === 'submit'; if (noted) itemSessions.requireLedger(info); const result = await move(); if (noted) itemSessions.recordItemSession(info, args[0], operation); return result; }
+
async function ordered(ctx, board, operation, args) {
// Every engine-27 registration records the seat that made it: the coordinator from the main
// checkout, the joined agent from its worktree, or `machine` for a join no seat made (#579).
@@@ -978,8 -974,8 +978,8 @@@
}
const command = ['add', 'edit', 'merged'].includes(ctx.io.relayCommand?.cliOperation) ? ctx.io.relayCommand : undefined;
/** Dispatch while this session holds the checkout, including long-running next/run loops. */
- const execute = async () => tapItemSession(ctx.info, operation, args, await (relayLinked(ctx.info.root) || relayRecovered(ctx.info.root)
- ? relayOperation(ctx.info.root, operation, args, ctx.io, command, () => store[operation](board, ...args)) : store[operation](board, ...args)));
- const execute = () => relayLinked(ctx.info.root) || relayRecovered(ctx.info.root)
- ? relayOperation(ctx.info.root, operation, args, ctx.io, command, () => store[operation](board, ...args)) : store[operation](board, ...args);
++ const execute = () => withItemSession(ctx.info, operation, args, () => relayLinked(ctx.info.root) || relayRecovered(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');
@@@ -2978,7 -2975,6 +2979,7 @@@ async function verifyHere(ctx, id, { se
return await ordered(ctx, board, 'verify', recovered.args);
}
const item = store.getItem(board, id);
- refuseSelfSession(ctx.info, item);
++ itemSessions.refuseSelfSession(ctx.info, item);
const reReview = item.item_status === 'verified' && !item.item_merged_commit;
const stale = reReview ? verdictProjector(root, board).state(item) : null;
if (item.item_status !== 'submitted' && !stale) {
diff --cc src/item-sessions.js
index cd63f7f6,00000000..cedc8db9
mode 100644,000000..100644
--- a/src/item-sessions.js
+++ b/src/item-sessions.js
@@@ -1,75 -1,0 +1,100 @@@
+/**
+ * Which agent session built an item (#921). A seat name is not a session: one session can hold the coordinator's
+ * checkout and a review worktree at once, and then "never verify your own work" holds only by name. Claims and submits
+ * record the session's digest beside the board, in this repository's own Git directory, never on the shared board or
+ * the relay, and a verdict from a session that built or submitted the item is refused.
+ */
++import { accessSync } from 'node:fs';
+import { appendFileSync } from 'node:fs';
++import { constants } from 'node:fs';
+import { existsSync } from 'node:fs';
+import { mkdirSync } from 'node:fs';
+import { readFileSync } from 'node:fs';
+import { readdirSync } from 'node:fs';
+import { join } from 'node:path';
+import { agentSessionDigest } from './person.js';
+import { Refused } from './refused.js';
+
+/** The local ledger of item moves by session digest, shared by every worktree of this repository. */
+function ledgerFile(info) {
+ return join(info.commonDir, 'pullboard', 'item-sessions.jsonl');
+}
+
- /** Record that this session claimed or submitted an item. A ledger that cannot be written never fails the move. */
++/** The refusal when the ledger cannot keep a session's claims and submits; a lost entry would let that session judge its own work. */
++function ledgerRefusal(info, error) {
++ return new Refused('SESSION_LEDGER', `this agent session's claim or submit cannot be recorded in ${ledgerFile(info)} (${error.code ?? error.message}), so a later verdict could not be checked against it`,
++ `make that file writable by this user (chmod u+rw ${ledgerFile(info)}), then run the command again`);
++}
++
++/**
++ * Refuse a claim or submit from an agent session before it moves when the ledger cannot be written (#921). A shell
++ * with no agent session records nothing and is never refused.
++ */
++export function requireLedger(info, digest = agentSessionDigest()) {
++ if (!digest) return;
++ try {
++ mkdirSync(join(info.commonDir, 'pullboard'), { recursive: true, mode: 0o700 });
++ accessSync(existsSync(ledgerFile(info)) ? ledgerFile(info) : join(info.commonDir, 'pullboard'), constants.W_OK);
++ } catch (error) { throw ledgerRefusal(info, error); }
++}
++
++/** Record that this session claimed or submitted an item; a write that fails after the move is reported, never dropped. */
+export function recordItemSession(info, item, move, digest = agentSessionDigest()) {
+ if (!digest || !Number.isInteger(Number(item))) return;
+ try {
- mkdirSync(join(info.commonDir, 'pullboard'), { recursive: true, mode: 0o700 });
+ appendFileSync(ledgerFile(info), JSON.stringify({ item: Number(item), move, digest, at: new Date().toISOString() }) + '\n', { mode: 0o600 });
- } catch { /* The binding scan below still covers a session that holds the builder's checkout. */ }
++ } catch (error) { throw ledgerRefusal(info, error); }
+}
+
+/** The digests recorded for one item's claims and submits. */
+function ledgerDigests(info, item) {
+ const file = ledgerFile(info);
+ if (!existsSync(file)) return new Set();
- return new Set(readFileSync(file, 'utf8').split('\n').flatMap((line) => {
++ let text;
++ try { text = readFileSync(file, 'utf8'); }
++ catch (error) {
++ throw new Refused('SESSION_LEDGER', `the agent-session ledger ${file} cannot be read (${error.code ?? error.message}), so this verdict's independence from the builder cannot be checked`,
++ `make it readable by this user (chmod u+r ${file}), then verify again`);
++ }
++ return new Set(text.split('\n').flatMap((line) => {
+ try {
+ const row = JSON.parse(line);
+ return row.item === item && typeof row.digest === 'string' ? [row.digest] : [];
+ } catch { return []; }
+ }));
+}
+
+/** The seats this session's digest is bound to now, in the main checkout and every worktree. */
+function boundSeats(info, digest) {
+ const files = [join(info.commonDir, 'pullboard-checkout-session.json')];
+ const worktrees = join(info.commonDir, 'worktrees');
+ if (existsSync(worktrees)) {
+ for (const entry of readdirSync(worktrees, { withFileTypes: true })) {
+ if (entry.isDirectory()) files.push(join(worktrees, entry.name, 'pullboard-checkout-session.json'));
+ }
+ }
+ const seats = new Set();
+ for (const file of files) {
+ try {
+ const binding = JSON.parse(readFileSync(file, 'utf8'));
+ if (binding.digest === digest && typeof binding.agent === 'string') seats.add(binding.agent);
+ } catch { /* A missing or damaged peer binding names no seat. */ }
+ }
+ return seats;
+}
+
+/**
+ * Refuse a verdict from the agent session that built or submitted the item: its digest is on the item's ledger, or it
+ * is bound right now to the seat that built it. A shell with no agent session (the person's terminal) is never refused.
+ *
+ * @param {{ commonDir: string }} info
+ * @param {{ item_id: number, item_built_by?: string|null, item_owner?: string|null }} item
+ */
+export function refuseSelfSession(info, item, digest = agentSessionDigest()) {
+ if (!digest) return;
+ const builders = [item.item_built_by, item.item_owner].filter(Boolean);
+ const seats = boundSeats(info, digest);
+ if (!ledgerDigests(info, item.item_id).has(digest) && !builders.some((builder) => seats.has(builder))) return;
+ throw new Refused('SELF_SESSION_VERIFY', `this agent session built or submitted #${item.item_id}, so its verdict would be its own work under another seat's name`,
+ 'ask another agent session to verify it: pullboard next --verify from that session\'s own worktree');
+}
diff --cc src/next-steps.js
index 89a245a4,fa5403c1..f09db78e
--- a/src/next-steps.js
+++ b/src/next-steps.js
@@@ -506,7 -506,6 +506,8 @@@ export const NEXT_STEPS = Object.freeze
SEAL_VERSION: 'upgrade Pullboard on this device: npm install -g pullboard@latest',
SELF_SHOUT: 'name another agent, a lane or all: pullboard shout all "<text>"',
SELF_VERIFY: 'ask a different agent to verify it; from main create its worktree with pullboard worktree <lane> --model "<model name>"',
++ SESSION_LEDGER: 'make the agent-session ledger named in the message writable by this user, then run the command again',
+ SELF_SESSION_VERIFY: 'ask another agent session to verify it: pullboard next --verify from that session\'s own worktree',
SERVICE_ERROR: 'retry the call; if it repeats, restart pullboard serve',
SHALLOW_BEFORE_OPT_IN: 'git fetch --unshallow, then pullboard spec signers add',
SHOUT_NOT_AVAILABLE: 'read shouts with pullboard inbox, or refresh the snapshot with a current CLI',
diff --cc test/agent-session.test.js
index 9accf728,1fcb47f3..354d6e62
--- a/test/agent-session.test.js
+++ b/test/agent-session.test.js
@@@ -347,35 -347,3 +347,52 @@@ test('a remote shell is recognized by a
assert.equal(relayError?.code, 'RELAY_UNAVAILABLE', 'relay on over SSH reaches the relay');
assert.match(relayError.message, /\/auth\/device\/start/u, 'relay on over SSH starts its device sign-in (#615)');
});
+
+test('a verdict from the agent session that built the item is refused under any seat [V1,B3]', () => {
+ const box = project();
+ const builder = 'codex-thread-secret-builder-921';
+ const build = (args) => box.run(box.web, args, { session: builder, sessionKey: 'CODEX_THREAD_ID' });
+ assert.equal(build(['claim', '1', '--json']).status, 0);
+ writeFileSync(join(box.web, 'web', 'page.txt'), 'built\n');
+ box.git(box.web, 'commit', '-qam', 'feat(web): build the fixture item [G1]');
+ const submitted = build(['submit', '1', '--json']);
+ assert.equal(submitted.status, 0, `${submitted.stdout}${submitted.stderr}`);
+ // The same session opens a review seat of its own: a different seat name, the same session.
+ const review = join(box.dir, 'review-seat');
+ box.git(box.repo, 'worktree', 'add', '-q', '--detach', review, box.git(box.web, 'rev-parse', 'HEAD'));
+ const reviewAs = (session, args) => box.run(review, args, { session, sessionKey: 'CODEX_THREAD_ID' });
+ assert.equal(reviewAs(builder, ['join', 'web', '--json']).status, 0);
+ const before = boardSnapshot(box.boardFile);
+ const own = reviewAs(builder, ['verify', '1', 'accept', '--note', 'checked the page', '--json']);
+ assert.notEqual(own.status, 0, 'the building session cannot accept its own item from another seat');
+ const error = JSON.parse(own.stdout).error;
+ assert.equal(error.code, 'SELF_SESSION_VERIFY');
+ assert.match(error.message, /this agent session built or submitted #1/u);
+ assert.match(error.next, /another agent session/u);
+ assert.deepEqual(boardSnapshot(box.boardFile), before, 'the refused verdict records nothing');
+ assertNoRawSession(box, box.web, [builder], 'CODEX_THREAD_ID');
+ const ledger = readFileSync(resolve(box.repo, box.git(box.repo, 'rev-parse', '--git-common-dir'), 'pullboard', 'item-sessions.jsonl'), 'utf8');
+ assert.equal(ledger.includes(builder), false, 'the local item ledger keeps only the session digest');
+ // Another session takes over that review seat and gives the verdict.
+ const other = 'codex-thread-secret-reviewer-921';
+ assert.equal(reviewAs(other, ['takeover', '--json']).status, 0);
+ const accepted = reviewAs(other, ['verify', '1', 'accept', '--note', 'checked the page', '--json']);
+ assert.equal(accepted.status, 0, `${accepted.stdout}${accepted.stderr}`);
+});
++
++test('a session whose claims cannot be recorded is refused before it moves, never let through [V1,B3]', () => {
++ const box = project();
++ const ledger = resolve(box.repo, box.git(box.repo, 'rev-parse', '--git-common-dir'), 'pullboard', 'item-sessions.jsonl');
++ writeFileSync(ledger, '', { mode: 0o400 });
++ chmodSync(ledger, 0o400);
++ const before = boardSnapshot(box.boardFile);
++ const claim = box.run(box.web, ['claim', '1', '--json'], { session: 'codex-thread-secret-unrecorded-921', sessionKey: 'CODEX_THREAD_ID' });
++ assert.notEqual(claim.status, 0, 'an unrecordable claim is refused');
++ const error = JSON.parse(claim.stdout).error;
++ assert.equal(error.code, 'SESSION_LEDGER');
++ assert.match(error.next, /chmod u\+rw/u);
++ assert.deepEqual(boardSnapshot(box.boardFile), before, 'the refused claim moved nothing');
++ chmodSync(ledger, 0o600);
++ assert.equal(box.run(box.web, ['claim', '1', '--json'], { session: 'codex-thread-secret-unrecorded-921', sessionKey: 'CODEX_THREAD_ID' }).status, 0, 'a writable ledger lets it through');
++ assert.match(readFileSync(ledger, 'utf8'), /"move":"claim"/u);
++});