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): read locally without device key [H10,H17]

Corey Olson15f2e7808a03
diff --git a/src/relay-key.js b/src/relay-key.js
index b32ed80c..9da44cb6 100644
--- a/src/relay-key.js
+++ b/src/relay-key.js
@@ -80,7 +80,7 @@ export function readBoardKey(boardId) {
const found = spawnSync(service, args, { encoding: 'utf8', timeout: 10000 });
if (found.status === 0) return decodeBoardKey(found.stdout.trim());
}
- throw new Refused('RELAY_KEY_MISSING', 'the board key is missing on this device; pair this device again, or run pullboard relay off then relay on to upload a new sealed snapshot');
+ throw new Refused('RELAY_KEY_MISSING', 'the board key is missing on this device; run this command where the key is available, or pair this device');
}
/** Remove the device key after a successful unlink, leaving all local board records untouched. */
diff --git a/src/relay.js b/src/relay.js
index 853fa7a3..ce0cdef5 100644
--- a/src/relay.js
+++ b/src/relay.js
@@ -18,6 +18,7 @@ import { receivePersonRequest } from './relay-requests.js';
export const DEFAULT_RELAY = 'https://app.pullboard.dev';
const LINK_FILES = new WeakMap();
const WARNED_COMMANDS = new WeakSet();
+const KEY_WARNED_COMMANDS = new WeakSet();
/** Require a trusted origin; HTTP exists only for loopback development and test relays. */
function relayOrigin(address) {
@@ -490,7 +491,12 @@ export async function syncRelay(root, io) {
}
catch (error) {
if (!(error instanceof Refused)) throw error;
- io.err(`pullboard: ${error.message}; run pullboard status to see pending uploads`);
+ if (error.code === 'RELAY_KEY_MISSING') {
+ if (!KEY_WARNED_COMMANDS.has(io)) {
+ KEY_WARNED_COMMANDS.add(io);
+ io.err(`pullboard: ${error.message}; moves are off until the key is reachable`);
+ }
+ } else io.err(`pullboard: ${error.message}; run pullboard status to see pending uploads`);
return { linked: true, board: state.board, url: state.url, sequence: state.sequence,
behind: (state.mode === 'ordered' ? Number(Boolean(state.pending)) : behind(root, state)) + Number(Boolean(state.snapshot || state.checkpoint)) };
}
@@ -539,8 +545,16 @@ export function relayRecovered(root) {
return loadLink(linkFile(root))?.recovered?.move ?? null;
}
-/** Read the local link and lag without opening a network connection or revealing its relay token. */
-export function relayStatus(root) { return summary(root, loadLink(linkFile(root))); }
+/** Read relay status without a connection or key, since its cursor is local metadata. */
+export function relayStatus(root) {
+ const state = loadLink(linkFile(root));
+ try { return summary(root, state); }
+ catch (error) {
+ if (!(error instanceof Refused) || error.code !== 'RELAY_KEY_MISSING') throw error;
+ return { linked: true, board: state.board, url: state.url, link: '', sequence: state.sequence,
+ behind: (state.mode === 'ordered' ? Number(Boolean(state.pending)) : behind(root, state)) + Number(Boolean(state.snapshot || state.checkpoint)) };
+ }
+}
/** Renew a person session through the relay without changing this device's board key or cursors. */
async function deviceSignIn(url, io) {
diff --git a/test/relay.test.js b/test/relay.test.js
index 51e11f06..7b9895c1 100644
--- a/test/relay.test.js
+++ b/test/relay.test.js
@@ -1,5 +1,6 @@
/** Relay identity, expiry, permission freshness and scoped credential isolation [H8, H1]. */
import assert from 'node:assert/strict';
+import { spawnSync } from 'node:child_process';
import { existsSync, mkdtempSync, readFileSync, rmSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { dirname, join } from 'node:path';
@@ -535,6 +536,94 @@ test('offline linked reads use the local board, moves refuse, and the same relay
}
});
+test('a linked device without its key reads locally and refuses moves with both repairs [H10,H17]', async (t) => {
+ const box = await relayClientFixture(t);
+ const staged = spawnSync('git', ['add', '-A'], { cwd: box.root, env: box.env, encoding: 'utf8' });
+ assert.equal(staged.status, 0, staged.stderr);
+ const seeded = spawnSync('git', ['commit', '-m', 'chore(test): seed fixture'], { cwd: box.root, env: box.env, encoding: 'utf8' });
+ assert.equal(seeded.status, 0, seeded.stderr);
+ const agentRoot = join(box.root, '..', 'missing-key-agent');
+ const worktree = spawnSync('git', ['worktree', 'add', '-b', 'fixture-missing-key-agent', agentRoot, 'HEAD'], {
+ cwd: box.root, env: box.env, encoding: 'utf8',
+ });
+ assert.equal(worktree.status, 0, worktree.stderr);
+ const prepare = await box.script(`
+ import { main } from ${JSON.stringify(box.mainURL)};
+ for (const name of Object.keys(process.env)) if (name.startsWith('GIT_')) delete process.env[name];
+ /** Run a real CLI command from the fixture worktree and capture its JSON result. */
+ async function command(cwd, args) {
+ let output = '';
+ const code = await main([...args, '--json'], { cwd, stdout: { isTTY: false, write: value => { output += value; } }, stderr: { write() {} }, stdin: process.stdin });
+ return { code, document: JSON.parse(output) };
+ }
+ const joined = await command(${JSON.stringify(agentRoot)}, ['join', ${JSON.stringify(box.lane)}, '--route', 'mid']);
+ const asked = await command(${JSON.stringify(agentRoot)}, ['shout', 'coordinator', 'Should this fixture continue?', '--decision']);
+ process.stdout.write(JSON.stringify({ joined, asked }));
+ `);
+ assert.equal(prepare.document.joined.code, 0, 'the real agent worktree joins its lane');
+ assert.equal(prepare.document.asked.code, 0, 'the agent creates a real open decision before its key is removed');
+ const decision = prepare.document.asked.document.id;
+ assert.ok(Number.isSafeInteger(decision));
+ await box.link();
+ const boardFile = join(box.root, '.git', 'pullboard', 'board.sqlite');
+ const beforeBytes = readFileSync(boardFile);
+ const callsBefore = box.calls.length;
+ assert.equal(existsSync(box.keyFile), true);
+ rmSync(box.keyFile);
+ assert.equal(existsSync(box.keyFile), false, 'the isolated device key is actually absent');
+
+ const reads = await box.script(`
+ import { main } from ${JSON.stringify(box.mainURL)};
+ for (const name of Object.keys(process.env)) if (name.startsWith('GIT_')) delete process.env[name];
+ /** Run one local read and capture its JSON document and diagnostics. */
+ async function command(args) {
+ let output = '';
+ const code = await main([...args, '--json'], { cwd: process.cwd(), stdout: { isTTY: false, write: value => { output += value; } }, stderr: { write() {} }, stdin: process.stdin });
+ return { code, document: JSON.parse(output) };
+ }
+ const status = await command(['status']);
+ const list = await command(['list', '--all']);
+ const show = await command(['show', '1']);
+ const decisions = await command(['decisions']);
+ process.stdout.write(JSON.stringify({ status, list, show, decisions }));
+ `);
+ const localReads = Object.values(reads.document);
+ for (const result of localReads) {
+ assert.equal(result.code, 0, JSON.stringify(result.document));
+ assert.equal(result.document.diagnostics?.length, 1, 'each read gets one missing-key line despite sync before and after the command');
+ assert.match(result.document.diagnostics[0], /RELAY_KEY_MISSING|board key is missing/);
+ assert.match(result.document.diagnostics[0], /moves are off until the key is reachable/);
+ assert.match(result.document.diagnostics[0], /run this command where the key is available, or pair this device/);
+ }
+ assert.ok(reads.document.list.document.items.some(item => item.item_title === 'private cleanup fixture item'), 'list returns the local item');
+ assert.equal(reads.document.show.document.item_title, 'private cleanup fixture item', 'show returns the local item');
+ assert.ok(reads.document.decisions.document.decisions.some(ask => ask.shout_id === decision), 'decisions returns the locally stored open question');
+ assert.equal(box.calls.length, callsBefore, 'missing key is detected before any relay request');
+
+ const moves = await box.script(`
+ import { main } from ${JSON.stringify(box.mainURL)};
+ for (const name of Object.keys(process.env)) if (name.startsWith('GIT_')) delete process.env[name];
+ /** Run one linked move and capture its refusal document. */
+ async function command(cwd, args) {
+ let output = '';
+ const code = await main([...args, '--json'], { cwd, stdout: { isTTY: false, write: value => { output += value; } }, stderr: { write() {} }, stdin: process.stdin });
+ return { code, document: JSON.parse(output) };
+ }
+ const claim = await command(${JSON.stringify(agentRoot)}, ['claim', '1']);
+ const shout = await command(${JSON.stringify(agentRoot)}, ['shout', 'coordinator', 'must not be sent']);
+ const answer = await command(${JSON.stringify(box.root)}, ['answer', ${JSON.stringify(String(decision))}, 'yes']);
+ process.stdout.write(JSON.stringify({ claim, shout, answer }));
+ `);
+ for (const result of Object.values(moves.document)) {
+ assert.equal(result.code, 1);
+ assert.equal(result.document.error.code, 'RELAY_KEY_MISSING');
+ assert.match(result.document.error.message, /board key is missing/);
+ assert.match(result.document.error.message, /run this command where the key is available, or pair this device/);
+ }
+ assert.deepEqual(readFileSync(boardFile), beforeBytes, 'reads and refused moves leave the local board unchanged');
+ assert.equal(box.calls.length, callsBefore, 'no read or refused move reaches the relay');
+});
+
test('plain relay off explains an already-deleted board without printing credentials [H1,H18]', async (t) => {
const box = await relayClientFixture(t);
await box.link();