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): pair ordered boards after moves [H15,H17]

Corey Olsonce88b80c5a72
diff --git a/src/relay-pairing-client.js b/src/relay-pairing-client.js
index 6d2b885d..70821a0f 100644
--- a/src/relay-pairing-client.js
+++ b/src/relay-pairing-client.js
@@ -114,14 +114,15 @@ export async function relayPair(root, io) {
const local = localSnapshot(root);
if (local.board !== state.board) throw new Refused('RELAY_STORAGE', 'the local board identity differs from its relay link; restore the matching board before pairing');
const cursor = local.snapshot.tables.event.at(-1)?.event_id ?? 0;
- if (cursor !== state.cursor) throw new Refused('PAIR_BUSY', 'a local move changed during pairing; run pullboard relay pair again after sync completes');
- if (state.pending || state.pendingMove || state.snapshot || state.linkPending) {
- throw new Refused('PAIR_PENDING', 'finish the pending relay acknowledgement or snapshot before creating a pairing code; retry relay sync first');
- }
const metadata = new Map(local.snapshot.tables.board_meta.map((row) => [row.meta_key, row.meta_value]));
const applied = metadata.get('relay_applied_sequence');
const engine = metadata.get('relay_engine_version');
const ordered = state.mode === 'ordered' || (applied !== undefined && engine !== undefined);
+ // Mirror cursors count native events; ordered packages are guarded by their acknowledged relay prefix below.
+ if (!ordered && cursor !== state.cursor) throw new Refused('PAIR_BUSY', 'a local move changed during pairing; run pullboard relay pair again after sync completes');
+ if (state.pending || state.pendingMove || state.snapshot || state.linkPending) {
+ throw new Refused('PAIR_PENDING', 'finish the pending relay acknowledgement or snapshot before creating a pairing code; retry relay sync first');
+ }
let sequence = state.sequence;
if (ordered) {
const value = Number(applied);
diff --git a/test/pairing.test.js b/test/pairing.test.js
index 9e033a19..a425b633 100644
--- a/test/pairing.test.js
+++ b/test/pairing.test.js
@@ -349,3 +349,41 @@ test('[H15,H17] a paired clone synchronizes without a key file from PULLBOARD_RE
assert.equal(output.includes(encodedKey), false, 'the environment key is not echoed in the clone command result');
assert.equal(output.includes(secretText), false, 'the pairing secret is not echoed in the clone command result');
});
+
+test('an acknowledged ordinary move cannot leave relay pair permanently busy [H15,H17,H16]', async t => {
+ const box = await relayClientFixture(t);
+ await box.link();
+ const first = await box.cli('relay', 'pair');
+ assert.equal(first.code, 0, 'the unchanged linked board can issue a pairing package');
+ const joined = await box.otherDeviceJoin(first.document.code);
+ assert.equal(joined.joined.board, box.before.tables.board_meta.find(row => row.meta_key === 'board_id').meta_value,
+ 'the baseline one-use package is consumed by a genuine second private native device');
+ const added = await box.cli('add', box.lane, 'An acknowledged move before pairing', '--criterion', 'The next device can join');
+ assert.equal(added.code, 0, JSON.stringify(added.document));
+ const snapshot = await box.cli('export');
+ assert.equal(snapshot.code, 0);
+ const state = JSON.parse(readFileSync(box.linkFile, 'utf8'));
+ const meta = new Map(snapshot.document.tables.board_meta.map(row => [row.meta_key, row.meta_value]));
+ assert.equal(state.mode, 'ordered');
+ assert.equal(state.sequence, Number(meta.get('relay_applied_sequence')), 'the real sync has acknowledged this native prefix');
+ const nativeCursor = snapshot.document.tables.event.at(-1)?.event_id ?? 0;
+ const second = await box.cli('relay', 'pair');
+ assert.equal(second.code, 0, 'an acknowledged board must pair after ordinary moves: ' + JSON.stringify({
+ error: second.document.error, savedNativeCursor: state.cursor, actualNativeCursor: nativeCursor,
+ relaySequence: state.sequence, appliedSequence: Number(meta.get('relay_applied_sequence')),
+ }));
+});
+
+test('a newly paired device imports the acknowledged moved board [H15,H17,H16]', async t => {
+ const box = await relayClientFixture(t);
+ await box.link();
+ const added = await box.cli('add', box.lane, 'The next computer sees this acknowledged move', '--criterion', 'The native checkpoint and move agree');
+ assert.equal(added.code, 0);
+ const current = await box.cli('export');
+ assert.equal(current.code, 0);
+ const printed = await box.cli('relay', 'pair');
+ assert.equal(printed.code, 0, JSON.stringify(printed.document.error));
+ const paired = await box.otherDeviceJoin(printed.document.code);
+ assert.deepEqual(paired.exported, current.document, 'a real independent native join imports the complete moved checkpoint');
+ assert.equal(paired.exported.tables.item.some(row => row.item_title === 'The next computer sees this acknowledged move'), true);
+});