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(inbox): retain reads when the relay key is unavailable [E9,E18,N26]

Corey Olson8dec1827e4ac
diff --git a/src/activity-delivery-cli.js b/src/activity-delivery-cli.js
index 003f01b3..caf7433f 100644
--- a/src/activity-delivery-cli.js
+++ b/src/activity-delivery-cli.js
@@ -68,14 +68,14 @@ export async function deliverActivity(ctx, { actedIds = [], afterSubmit = false,
else {
try { await recordIncluded(ctx, board, me.id, observation); }
catch (error) {
- if (!(error instanceof Refused) || error.code !== 'RELAY_RECOVERY_PENDING') throw error;
- // Recovery keeps canonical writes fenced; unread obligations replay until their delivery is recorded.
+ if (!(error instanceof Refused) || !['RELAY_RECOVERY_PENDING', 'RELAY_KEY_MISSING'].includes(error.code)) throw error;
+ // A read remains available while canonical writes are fenced; its obligations remain unrecorded.
activity.receipt = { recorded: false, code: error.code, message: error.message };
}
}
return { shouts, agents: store.listAgents(board), activity, local };
});
- if (!saveActivityCursor(delivered.local, delivered.activity.cursor)) {
+ if (delivered.activity.receipt?.recorded !== false && !saveActivityCursor(delivered.local, delivered.activity.cursor)) {
ctx.io.err('activity cursor could not be saved; activity may repeat when you read inbox again');
}
const { local, ...result } = delivered;
diff --git a/test/inbox-key-fixture.js b/test/inbox-key-fixture.js
new file mode 100644
index 00000000..296245a2
--- /dev/null
+++ b/test/inbox-key-fixture.js
@@ -0,0 +1,61 @@
+/** A real relay inbox read must not turn an unavailable key into a forged receipt [E9,E18,N26]. */
+import assert from 'node:assert/strict';
+import {
+ existsSync,
+ readFileSync,
+} from 'node:fs';
+import { join } from 'node:path';
+import { openBoardForRead } from '../src/board.js';
+
+/** Observe only the private fixture's canonical delivery projection. */
+function receipts(box) {
+ const board = openBoardForRead(join(box.root, '.git', 'pullboard', 'board.sqlite'));
+ try { return board.db.prepare("SELECT * FROM board_meta WHERE meta_key LIKE 'activity:%' ORDER BY meta_key").all(); }
+ finally { board.db.close(); }
+}
+
+/** Read an optional local cursor without creating it. */
+function cursor(box) {
+ const file = join(box.root, '.git', 'pullboard-activity.json');
+ return existsSync(file) ? readFileSync(file, 'utf8') : null;
+}
+
+/** Create a genuine answered decision through the authenticated public CLI before hiding its key. */
+export async function prepareKeylessInbox(box) {
+ const asked = await box.cli('shout', 'person', 'May this session read without recording delivery?', '--decision');
+ assert.equal(asked.code, 0, 'the fixture asks a real decision');
+ const answer = await box.cli('answer', String(asked.document.id), 'Read without acknowledging until the key returns.', '--as', 'person');
+ assert.equal(answer.code, 0, 'the fixture person answers through ordinary authentication');
+ return { answer: answer.document.id };
+}
+
+/** Preserve both cursors while displaying a real obligation and refusing explicit acknowledgement. */
+export async function readKeylessInbox(box, state) {
+ const beforeCursor = cursor(box), beforeReceipts = receipts(box);
+ const read = await box.cli('inbox');
+ assert.equal(read.code, 0, `inbox reads without the key: ${JSON.stringify(read.document?.error ?? null)}`);
+ assert.equal(read.document.activity.receipt.recorded, false, 'an unavailable canonical receipt is never claimed');
+ assert.equal(read.document.activity.receipt.code, 'RELAY_KEY_MISSING', 'delivery reports why it remains unrecorded');
+ const interrupt = read.document.activity.interrupts.find(entry => entry.shout === state.answer);
+ assert.ok(interrupt, 'the answered decision remains visible despite the missing key');
+ state.interrupt = interrupt.id;
+ assert.equal(cursor(box), beforeCursor, 'unrecorded delivery never advances the local cursor');
+ assert.deepEqual(receipts(box), beforeReceipts, 'the read cannot forge a canonical delivery');
+ const acted = await box.cli('inbox', '--acted-on', state.interrupt);
+ assert.equal(acted.document?.error?.code, 'RELAY_KEY_MISSING', 'explicit acknowledgement stays an authenticated write');
+ assert.deepEqual(receipts(box), beforeReceipts, 'a refused acknowledgement changes no receipt');
+ return read;
+}
+
+/** Restored credentials deliver the same obligation, which disappears only after explicit acknowledgement. */
+export async function finishKeylessInbox(box, state) {
+ const delivered = await box.cli('inbox');
+ assert.equal(delivered.code, 0, 'restoring the key permits canonical delivery');
+ assert.notEqual(delivered.document.activity.receipt?.recorded, false, 'delivery is recorded rather than silently skipped');
+ assert.ok(delivered.document.activity.interrupts.some(entry => entry.id === state.interrupt), 'the unrecorded obligation survives key recovery');
+ assert.notEqual(cursor(box), null, 'only successful delivery advances the local cursor');
+ assert.ok(receipts(box).some(row => row.meta_key.endsWith(`pending:${state.interrupt}`)), 'the native board retains the delivered obligation');
+ const acted = await box.cli('inbox', '--acted-on', state.interrupt);
+ assert.equal(acted.code, 0, 'the recipient can acknowledge after credentials return');
+ assert.equal(acted.document.activity.interrupts.some(entry => entry.id === state.interrupt), false, 'explicit acknowledgement retires only the delivered obligation');
+}
diff --git a/test/team.test.js b/test/team.test.js
index a9fe9198..16ed3037 100644
--- a/test/team.test.js
+++ b/test/team.test.js
@@ -29,6 +29,11 @@ import { handOverBoardKeys, statementBytes } from '../src/relay-handover.js';
import { signSshVouch } from '../src/relay-ssh-proof.js';
import { assertMatchingLandingHost, assertNoCulpritTrunkHold } from './landing-environment-fixture.js';
import { landingQueueCase } from './landing-queue-fixture.js';
+import {
+ prepareKeylessInbox,
+ readKeylessInbox,
+ finishKeylessInbox,
+} from './inbox-key-fixture.js';
const CLI = join(import.meta.dirname, '..', 'bin', 'pullboard.js');
@@ -841,15 +846,17 @@ test('every session reads and moves: terminal, SSH, agent, job or CI [E9,E18]',
// S6b: a session that cannot read the key (SSH, a scheduled job, a locked keychain) still reads the whole board.
assert.equal((await box.cli('add', box.lane, 'Read from any session')).code, 0);
+ const inbox = await prepareKeylessInbox(box);
renameSync(keys, keys + '.parked');
try {
for (const command of [['list'], ['show', '1'], ['inbox'], ['whoami'], ['status'], ['resume'], ['log']]) {
- const read = await box.cli(...command);
+ const read = command[0] === 'inbox' ? await readKeylessInbox(box, inbox) : await box.cli(...command);
assert.equal(read.code, 0, `${command[0]} reads without the key: ${JSON.stringify(read.document?.error ?? null)}`);
}
const move = await box.cli('add', box.lane, 'Needs the key');
assert.equal(move.document?.error?.code, 'RELAY_KEY_MISSING', 'a move without the key is refused, never sent or lost');
} finally { renameSync(keys + '.parked', keys); }
+ await finishKeylessInbox(box, inbox);
// S6c: a CI or cloud session, with an agent token and the board key in its environment and no key file, reads and moves.
// The project's committed setup is what every checkout, CI's included, gets.