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.

fix: distinguish recorded moves in relay refusals [C6,N26]

Corey Olsona5385faacb60
diff --git a/src/cli-main.js b/src/cli-main.js
index 91a5b5c3..d2cff48b 100644
--- a/src/cli-main.js
+++ b/src/cli-main.js
@@ -1,3 +1,4 @@
+import { recordedMoveRefusal } from './recorded-move.js';
/**
* The command line's entry: parse the arguments, bind the checkout, run the relay and baseline work around the
* command when there is any, and dispatch through the lazy command table. It loads a module only when the command
@@ -187,6 +188,7 @@ async function runCommand(argv, io) {
if (!load) return (await import('./cli-help.js')).unknownCommand(io, command);
return await (await load()).run(io, args);
} catch (error) {
+ error = recordedMoveRefusal(io, error);
if (error instanceof Refused) {
io.refusal?.(error);
io.err(`pullboard: ${await displayedRefusal(io, error)}\nnext: ${io.refusalDocument(error).error.next}`);
diff --git a/src/cli-sync.js b/src/cli-sync.js
index d69213ef..e516e0b1 100644
--- a/src/cli-sync.js
+++ b/src/cli-sync.js
@@ -1,3 +1,4 @@
+import { recordedMoveRefusal } from './recorded-move.js';
/**
* The relay and baseline work around a command: link a new project, sync the relay, deliver finished baselines and
* run the person's waiting requests. The command line loads it only when one of them could act [C7].
@@ -15,6 +16,7 @@ const QUIET = ['NOT_A_REPO', 'NO_REPO', 'NO_CONFIG', 'CORE_BARE'];
/** Report a refusal from the work around a command without stopping the command. */
function reportQuietly(io, error) {
+ error = recordedMoveRefusal(io, error);
if (!(error instanceof Refused)) throw error;
if (!QUIET.includes(error.code)) io.err(`pullboard: ${displayedRefusal(io, error)}\nnext: ${io.refusalDocument(error).error.next}`);
}
diff --git a/src/cli.js b/src/cli.js
index d25ac89e..ad160fd9 100644
--- a/src/cli.js
+++ b/src/cli.js
@@ -594,8 +594,17 @@ export async function ordered(ctx, board, operation, args) {
ensureSpecApprovalCoordinator(ctx, board, initialBaseline);
const actor = ctx.info.isMain ? COORDINATOR : store.agentAt(board, ctx.info.root)?.agent_id;
if (initialBaseline && actor) await recordBaseline(actor);
+ /** Called only for this requested operation, after its store transaction commits, never for bootstrap. */
+ const applyRequested = () => {
+ const before = board.db.prepare('SELECT MAX(event_id) AS id FROM event').get().id ?? 0;
+ const result = store[operation](board, ...args);
+ const after = board.db.prepare('SELECT MAX(event_id) AS id FROM event').get().id ?? 0;
+ if (after > before) ctx.io.recordedMove = true;
+ return result;
+ };
const result = await 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));
+ ? relayOperation(ctx.info.root, operation, args, ctx.io, command, applyRequested,
+ () => { ctx.io.recordedMove = true; }) : applyRequested());
return result;
};
const digest = agentSessionDigest();
diff --git a/src/json.js b/src/json.js
index 04270de5..841b9400 100644
--- a/src/json.js
+++ b/src/json.js
@@ -187,6 +187,7 @@ export function commandOutput(argv, streams) {
};
return {
...streams,
+ recordedMove: false,
physicalStdoutIsTTY: Boolean(streams.stdout.isTTY),
stdout: { get isTTY() { return enabled ? false : streams.stdout.isTTY; }, write: (text) => streams.stdout.write(text) },
say: (line) => emit(streams.stdout, messages, line),
diff --git a/src/recorded-move.js b/src/recorded-move.js
new file mode 100644
index 00000000..14d990ea
--- /dev/null
+++ b/src/recorded-move.js
@@ -0,0 +1,10 @@
+/** A completed durable move must never be repeated because later command work refused [C6,N26]. */
+import { Refused } from './refused.js';
+
+/** Preserve the refusal code while distinguishing a partial recorded command from an unrecorded attempt. */
+export function recordedMoveRefusal(io, error) {
+ if (!io.recordedMove || !(error instanceof Refused)) return error;
+ return new Refused(error.code,
+ 'a move from this command was already recorded; any pending relay work remains queued locally. Do not repeat the command',
+ 'run pullboard status to inspect the recorded work and pending relay sync; do not repeat the original command');
+}
diff --git a/src/relay-lock.js b/src/relay-lock.js
index 04fc620d..d3ef8a7d 100644
--- a/src/relay-lock.js
+++ b/src/relay-lock.js
@@ -107,7 +107,7 @@ export async function locked(file, work, io) {
const token = randomUUID();
try {
while (!(takeLease(lease, token) && takeDirectory(lock))) {
- if (Date.now() >= deadline) throw new Refused('RELAY_BUSY', `another worktree was still sending this board after ${Math.round((Date.now() - startedAt) / 1000)} s; nothing was lost, so run the command again`);
+ if (Date.now() >= deadline) throw new Refused('RELAY_BUSY', `another worktree was still sending this board after ${Math.round((Date.now() - startedAt) / 1000)} s; this attempt was not recorded; run the command again`);
if (io?.err && Date.now() >= nextProgress) {
nextProgress = Date.now() + progressEvery;
io.err(`pullboard: waiting for another worktree to finish sending this board (${Math.round((Date.now() - startedAt) / 1000)} s of ${Math.round((deadline - startedAt) / 1000)} s)`);
diff --git a/src/relay.js b/src/relay.js
index 440d1d2a..34a43c68 100644
--- a/src/relay.js
+++ b/src/relay.js
@@ -1114,7 +1114,7 @@ function outboxLink(root, file, state, io) {
}
/** Send one board operation before executing it locally, and report its canonical engine result. */
-export async function relayOperation(root, operation, args, io, command, applyLocally) {
+export async function relayOperation(root, operation, args, io, command, applyLocally, onRecorded) {
const file = linkFile(root);
return locked(file, async () => {
const state = loadLink(file);
@@ -1133,6 +1133,7 @@ export async function relayOperation(root, operation, args, io, command, applyLo
if (!moves) { moves = new Set(); CHECKPOINT_MOVES.set(io, moves); }
if (moves.has(state.board)) CHECKPOINT_NOTICES.get(io)?.delete(state.board);
moves.add(state.board);
+ let requestedMove;
try {
let ordered;
const queue = guarded.queue;
@@ -1162,6 +1163,7 @@ export async function relayOperation(root, operation, args, io, command, applyLo
}
const previousReceipt = io.personRequestMoveId && localRecords(root, board => engineReceipt(board, io.personRequestMoveId));
if (previousReceipt) {
+ if (!previousReceipt.outcome.error) onRecorded?.();
if (state.recovered?.move?.id === io.personRequestMoveId) {
delete state.recovered;
saveLink(file, state);
@@ -1171,10 +1173,12 @@ export async function relayOperation(root, operation, args, io, command, applyLo
return previousReceipt.outcome.result;
}
let move = recoveredMove(root, state, operation, args, command);
+ requestedMove = move;
try {
if (!move) {
const sent = withSeatName(root, operation, args);
move = stampCoordinatorHolder(localRecords(root, (board) => prepareEngineMove(board, operation, sent, io.personRequestMoveId ? { id: io.personRequestMoveId } : {})), state.machine);
+ requestedMove = move;
if (io.personRequest) move.personRequest = structuredClone(io.personRequest);
const problem = move.personRequest && localRecords(root, board => requestMoveProblem(board, move, { checkExecutorLease: false }));
if (problem) throw problem;
@@ -1202,6 +1206,7 @@ export async function relayOperation(root, operation, args, io, command, applyLo
}
const receipt = localRecords(root, (board) => engineReceipt(board, move.id));
if (!receipt) throw new Refused('RELAY_RESPONSE', 'the acknowledged operation has no replay receipt; fetch a consistent relay snapshot');
+ if (!receipt.outcome.error) onRecorded?.();
delete state.recovered;
saveLink(file, state);
// A phone can read a compacted checkpoint; failed presentation uploads do not undo the move.
@@ -1217,6 +1222,13 @@ export async function relayOperation(root, operation, args, io, command, applyLo
for (const event of receipt.outcome.events ?? []) io.onEvent?.(event);
return receipt.outcome.result;
} catch (error) {
+ // Catch-up may commit the requested receipt before a later link write refuses. A refused receipt counts as nothing.
+ if (requestedMove && onRecorded) {
+ try {
+ const committed = localRecords(root, board => engineReceipt(board, requestedMove.id));
+ if (committed && !committed.outcome.error) onRecorded();
+ } catch { /* No readable durable receipt means no recorded-outcome claim. */ }
+ }
if (confirmedDeletion(state, error)) {
forgetDeletedCopy(root, file, state, io);
return deletedMoveResult(root, operation, args, command, io, applyPausedMoveLocally);