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(relay): explain refused checkpoints once [H16,B26]

Corey Olson988578cf1427
diff --git a/src/cli.js b/src/cli.js
index c1f4d6ee..be1d99c7 100644
--- a/src/cli.js
+++ b/src/cli.js
@@ -67,7 +67,7 @@ import { proofStats } from './stats.js';
import { exportBoard, importBoard } from './exchange.js';
import { addSigner, assertRequiredSigners, defaultPrincipal, hasSignerFile } from './signature.js';
import { loadMachineSettings, setGateSlots } from './settings.js';
-import { formatSnapshotLimit, pendingSnapshotSize, relayCommandReceipt, relayCommandReceiptReported, relayLinked, relayOff, relayOn, relayOperation, relayRecovered, relayRevoke, relayStatus, relayTokens, syncRelay } from './relay.js';
+import { formatSnapshotLimit, pendingSnapshotSize, pendingCheckpointProblem, relayCommandReceipt, relayCommandReceiptReported, relayLinked, relayOff, relayOn, relayOperation, relayRecovered, relayRevoke, relayStatus, relayTokens, syncRelay } from './relay.js';
import { relayOnAll, revokeRelayDevice, unlinkedRelayProjects } from './relay-setup.js';
import { readRelayMachine } from './relay-machine.js';
import { relayJoin, relayPair } from './relay-pairing-client.js';
@@ -1565,7 +1565,7 @@ function readCommands(io, { first, second, rest, values }) {
return 0;
}
if (summary.relay.linked) io.say(`relay: sequence ${summary.relay.sequence}; ${summary.relay.behind} pending uploads`);
- if (summary.relay.oversizedSnapshot) io.say(formatSnapshotLimit(summary.relay.oversizedSnapshot));
+ if (summary.relay.oversizedSnapshot && !summary.relay.refusedCheckpoint) io.say(formatSnapshotLimit(summary.relay.oversizedSnapshot));
const { items, accepted, rejected } = summary.stats;
io.say(`${summary.me.id}: ${summary.unread} unread shouts; holding ${summary.mine.map((item) => `#${item.item_id}`).join(', ') || 'nothing'}`);
io.say(`board: ${items.open} open, ${items.claimed} claimed, ${items.submitted} awaiting verification, ${items.verified} verified, ${items.withdrawn} withdrawn`);
@@ -1587,7 +1587,9 @@ function readCommands(io, { first, second, rest, values }) {
}
const ctx = context(io);
const problems = [...doctorProblems(ctx.file, ctx.info.root, tryGit, ctx.config), ...doctrineProblems(ctx.info.root, ctx.config), ...unlinkedRelayProjects()];
- const oversizedSnapshot = pendingSnapshotSize(ctx.info.root);
+ const checkpointProblem = pendingCheckpointProblem(ctx.info.root);
+ if (checkpointProblem) problems.push(checkpointProblem);
+ const oversizedSnapshot = checkpointProblem ? null : pendingSnapshotSize(ctx.info.root);
if (oversizedSnapshot) problems.push({ code: 'RELAY_SNAPSHOT_LIMIT',
message: formatSnapshotLimit(oversizedSnapshot),
next: 'reduce the sealed board snapshot below the relay limit, then run pullboard status' });
@@ -1596,7 +1598,7 @@ function readCommands(io, { first, second, rest, values }) {
io.say('board is clean');
return 0;
}
- for (const problem of problems) io.say(`problem: ${problem.message}; repair: ${problem.next}`);
+ for (const problem of problems) if (problem.code !== 'RELAY_CHECKPOINT_REFUSED') io.say(`problem: ${problem.message}; repair: ${problem.next}`);
return 1;
},
inbox: () => {
diff --git a/src/relay.js b/src/relay.js
index 4fad5ec9..67783d99 100644
--- a/src/relay.js
+++ b/src/relay.js
@@ -25,6 +25,7 @@ const WARNED_COMMANDS = new WeakSet();
const KEY_WARNED_COMMANDS = new WeakSet();
const BASELINE_ATTEMPTS = new WeakMap();
const BASELINE_NOTICES = new WeakSet();
+const CHECKPOINT_NOTICES = new WeakMap();
const BASELINE_LOCAL_MOVES = new WeakSet();
const BASELINE_FAILURES = new WeakMap();
@@ -180,7 +181,8 @@ function summary(root, state, { pairing = false } = {}) {
link: 'https://app.pullboard.dev/#board=' + state.board + fragment,
sequence: state.sequence, behind: (state.baselinePause ? behind(root, state) : state.mode === 'ordered' ? Number(Boolean(state.pending)) : behind(root, state)) + Number(Boolean(state.snapshot || state.checkpoint)),
...(oversizedSnapshot ? { oversizedSnapshot } : {}),
- ...(state.baselinePause ? { pausedUpload: structuredClone(state.baselinePause) } : {}) };
+ ...(state.baselinePause ? { pausedUpload: structuredClone(state.baselinePause) } : {}),
+ ...(state.checkpointRefusal ? { refusedCheckpoint: checkpointProblem(state) } : {}) };
}
/** Measure a pending sealed snapshot against the relay's decoded journal limit. */
@@ -221,6 +223,34 @@ function permanentBaselineRefusal(error) {
![408, 425, 429].includes(error.httpStatus);
}
+/** Explain a refused later checkpoint without changing the ordered-move recovery policy. */
+function checkpointProblem(state) {
+ const refusal = state.checkpointRefusal;
+ const code = safePauseCode(refusal);
+ const reason = safePauseMessage(refusal);
+ const size = snapshotSize(state);
+ const next = 'upgrade pullboard (npm i -g pullboard) or run pullboard relay off then relay on --all';
+ const message = `relay checkpoint refused for ${state.board}: ${code} ${reason}`
+ + (size ? '; ' + formatSnapshotLimit(size) : '')
+ + '; moves still sync in order; a fresh checkpoint goes up on the next change; if it keeps failing, ' + next;
+ return { code: 'RELAY_CHECKPOINT_REFUSED', message, next };
+}
+
+/** Project the current checkpoint repair for doctor without making another network request. */
+export function pendingCheckpointProblem(root) {
+ const state = loadLink(linkFile(root));
+ return state?.checkpointRefusal ? checkpointProblem(state) : null;
+}
+
+/** Deduplicate permanent checkpoint diagnostics across the same command's preflight and retries. */
+function reportCheckpointRefusal(state, io) {
+ let boards = CHECKPOINT_NOTICES.get(io);
+ if (!boards) { boards = new Set(); CHECKPOINT_NOTICES.set(io, boards); }
+ if (boards.has(state.board)) return;
+ boards.add(state.board);
+ io.err('pullboard: ' + checkpointProblem(state).message);
+}
+
/** Name the safe next step for the saved permanent refusal. */
function pauseFix(state) {
const pause = state.baselinePause;
@@ -485,11 +515,22 @@ async function publishCheckpoint(root, file, state, io) {
const sequence = Number(document.tables.board_meta.find((row) => row.meta_key === 'relay_applied_sequence')?.meta_value ?? 0);
const digest = presentationDigest(document.presentation);
if (!state.checkpoint || state.checkpoint.sequence !== sequence || state.checkpointPresentationDigest !== digest) {
+ delete state.checkpointRefusal;
state.checkpointPresentationDigest = digest;
state.checkpoint = { sequence, sealed: await sealedRecord(readBoardKey(state.board), document, state, 'snapshot', sequence) };
saveLink(file, state);
}
- const reply = await request(state, '/api/v1/boards/' + state.board + '/state', { method: 'PUT', body: state.checkpoint }, io);
+ // A definitive rejection retries only a fresh image after the board changes.
+ if (state.checkpointRefusal) { reportCheckpointRefusal(state, io); return; }
+ let reply;
+ try { reply = await request(state, '/api/v1/boards/' + state.board + '/state', { method: 'PUT', body: state.checkpoint }, io); }
+ catch (error) {
+ if (!(error instanceof Refused) || !permanentBaselineRefusal(error)) throw error;
+ state.checkpointRefusal = { code: safePauseCode(error), message: safePauseMessage(error), status: error.httpStatus };
+ saveLink(file, state);
+ reportCheckpointRefusal(state, io);
+ return;
+ }
if (reply.state?.sequence !== state.checkpoint.sequence || reply.state.sealed !== state.checkpoint.sealed) throw new Refused('RELAY_RESPONSE', 'the relay did not acknowledge this checkpoint; retry the configured relay');
state.presentationDigest = state.checkpointPresentationDigest;
delete state.checkpoint;
diff --git a/test/relay-stuck-upload.test.js b/test/relay-stuck-upload.test.js
index a05bb32b..b7077499 100644
--- a/test/relay-stuck-upload.test.js
+++ b/test/relay-stuck-upload.test.js
@@ -410,3 +410,92 @@ async function privatePersonSession(box) {
const cookie = signed.headers.getSetCookie().find(value => value.startsWith('pb_session='));
return cookie.split(';')[0].slice('pb_session='.length);
}
+
+/** The accepted-baseline path stays ordered while one actionable line survives internal retries. */
+test('a refused later checkpoint names its repair once on every native agent command [H16,B26]', async t => {
+ const box = await relayClientFixture(t);
+ const configPath = join(box.root, 'pullboard.json');
+ const config = JSON.parse(readFileSync(configPath, 'utf8'));
+ const lane = 'fixture-build';
+ const gate = 'node --check src/relay-checkpoint-fixture.js';
+ config.gate = gate;
+ config.lanes[lane] = { owns: ['src/'], specs: ['G'] };
+ writeFileSync(configPath, JSON.stringify(config, null, 2) + '\n');
+ const specPath = join(box.root, 'SPEC.md');
+ writeFileSync(specPath, readFileSync(specPath, 'utf8').replace('\n## K · Constraints',
+ `\n- G1 [approved, must] The checkpoint fixture parses. | gate: ${gate}\n\n## K · Constraints`));
+ const added = await box.cli('add', lane, 'accepted baseline work', '--specs', 'G1', '--criterion', 'the fixture source parses', '--check', gate);
+ assert.equal(added.code, 0);
+ const item = added.document.item.item_id;
+ symlinkSync(resolve(import.meta.dirname, '../bin/pullboard.js'), join(box.env.PATH, 'pullboard'));
+ assert.equal(spawnSync('git', ['add', '-A'], { cwd: box.root, env: box.env }).status, 0);
+ assert.equal(spawnSync('git', ['commit', '-q', '-m', 'chore(test): prepare checkpoint fixture'], { cwd: box.root, env: box.env }).status, 0);
+ const agentRoot = join(box.root, '..', 'later-checkpoint-agent');
+ assert.equal(spawnSync('git', ['worktree', 'add', '-q', '-b', 'fixture-later-checkpoint-agent', agentRoot, 'HEAD'], { cwd: box.root, env: box.env }).status, 0);
+ await box.link();
+ assert.equal((await box.cliAt(agentRoot, 'join', lane)).code, 0);
+ assert.ok(JSON.parse(readFileSync(box.linkFile, 'utf8')).baselineAccepted);
+ box.rejectSnapshots({ status: 503, code: 'RELAY_UNAVAILABLE', message: 'temporary checkpoint refusal' });
+ assert.equal((await box.cli('shout', 'all', 'private transient checkpoint change')).code, 0);
+ const transient = JSON.parse(readFileSync(box.linkFile, 'utf8'));
+ assert.ok(transient.checkpoint, 'a transient checkpoint keeps its exact queued ciphertext');
+ assert.equal(transient.checkpointRefusal, undefined, 'a retryable response never becomes a permanent checkpoint diagnostic');
+ box.rejectSnapshots(null);
+ assert.equal((await box.cli('status')).code, 0);
+ assert.equal(JSON.parse(readFileSync(box.linkFile, 'utf8')).checkpoint, undefined, 'a later read retries the transient checkpoint without requiring another change');
+ const baselineSequence = (await uploadedState(box)).sequence;
+ box.rejectSnapshots({ status: 400, code: 'BAD_UPLOAD', message: 'malformed sealed snapshot' });
+
+ /** Leave a genuinely refused checkpoint pending before each measured command. */
+ async function seed() {
+ assert.equal((await box.cli('shout', 'all', 'private checkpoint seeding change')).code, 0);
+ assert.ok(JSON.parse(readFileSync(box.linkFile, 'utf8')).checkpoint);
+ }
+ /** Demand one bounded diagnostic with upload, reason and the coordinator's concrete repair. */
+ function diagnostic(result, name) {
+ const lines = result.document.diagnostics ?? [];
+ assert.equal(lines.length, 1, name + ' prints one diagnostic across preflight, move and postflight');
+ assert.match(lines[0], /relay checkpoint refused for [0-9a-f]{32}: BAD_UPLOAD malformed sealed snapshot/u);
+ assert.match(lines[0], /moves still sync in order; a fresh checkpoint goes up on the next change/u);
+ assert.match(lines[0], /upgrade pullboard \(npm i -g pullboard\) or run pullboard relay off then relay on --all/u);
+ assert.doesNotMatch(lines[0], /\n|run pullboard status to see pending uploads|relay paused/u);
+ }
+ await seed();
+ const claimed = await box.cliAt(agentRoot, 'claim', String(item));
+ assert.equal(claimed.code, 0); diagnostic(claimed, 'claim');
+ mkdirSync(join(agentRoot, 'src'), { recursive: true });
+ writeFileSync(join(agentRoot, 'src/relay-checkpoint-fixture.js'), 'export const checkpoint = true;\n');
+ assert.equal(spawnSync('git', ['add', 'src/relay-checkpoint-fixture.js'], { cwd: agentRoot, env: box.env }).status, 0);
+ assert.equal(spawnSync('git', ['commit', '-q', '-m', 'feat(fixture-build): complete checkpoint work [G1]'], { cwd: agentRoot, env: box.env }).status, 0);
+ await seed();
+ const submitted = await box.cliAt(agentRoot, 'submit', String(item));
+ assert.equal(submitted.code, 0); diagnostic(submitted, 'submit');
+ await seed();
+ const shouted = await box.cliAt(agentRoot, 'shout', 'coordinator', 'ordered agent with refused checkpoint');
+ assert.equal(shouted.code, 0); diagnostic(shouted, 'shout');
+ for (const command of ['status', 'doctor']) {
+ await seed();
+ const result = await box.cliAt(agentRoot, command);
+ assert.ok([0, 1].includes(result.code)); diagnostic(result, command);
+ if (command === 'doctor') {
+ const finding = result.document.problems.find(problem => problem.code === 'RELAY_CHECKPOINT_REFUSED');
+ assert.ok(finding, 'doctor exposes a repair finding as well as its single diagnostic');
+ assert.match(finding.next, /npm i -g pullboard.*relay off.*relay on --all/u);
+ }
+ }
+ const refused = JSON.parse(readFileSync(box.linkFile, 'utf8'));
+ assert.equal(refused.baselinePause, undefined);
+ const remote = await fetch(box.origin + '/api/v1/boards/' + refused.board + '/events?after=' + baselineSequence, {
+ headers: { authorization: 'Bearer ' + refused.token, 'x-pullboard-engine': String(ENGINE_VERSION) },
+ });
+ assert.equal(remote.status, 200);
+ const records = (await remote.json()).events;
+ assert.deepEqual(records.map(record => record.event_id), records.map((_, index) => baselineSequence + index + 1));
+ assert.ok(records.some(record => record.sender.kind === 'agent'), 'agent effects stay in authenticated relay order');
+ box.rejectSnapshots(null);
+ assert.equal((await box.cliAt(agentRoot, 'shout', 'coordinator', 'fresh checkpoint after repair')).code, 0);
+ const recovered = await box.cliAt(agentRoot, 'status');
+ assert.equal((recovered.document.diagnostics ?? []).length, 0, 'fresh accepted checkpoint clears the refusal');
+ assert.equal(JSON.parse(readFileSync(box.linkFile, 'utf8')).checkpointRefusal, undefined);
+ assert.equal((await uploadedState(box)).sequence, baselineSequence + records.length + 1);
+});