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.
JavaScript agentic-codingai-agentsai-governanceautonomous-agentsclaude-codeclicode-reviewcodexcoding-agentsdeveloper-toolsgit-hooksllmlocal-firstmulti-agentsoftware-factoryspec-driven-developmentverificationvibe-coding
fix: pair acknowledged boards and refuse local races [H17,H5]
Corey Olson262fa191013c
diff --git a/src/relay-pairing-client.js b/src/relay-pairing-client.jsindex 70821a0f..2c04672f 100644--- a/src/relay-pairing-client.js+++ b/src/relay-pairing-client.js@@ -106,8 +106,11 @@ function localSnapshot(root) {/** Create a one-use code and publish only an encrypted board package to the relay. */export async function relayPair(root, io) {- await syncRelay(root, io);const file = linkFile(root);+ loadState(file);+ // Freeze the native event boundary before asynchronous sync; retry if it changes during pairing.+ const initialCursor = localSnapshot(root).snapshot.tables.event.at(-1)?.event_id ?? 0;+ await syncRelay(root, io);const state = loadState(file);if (state.unlinking) throw new Refused('RELAY_UNLINK_PENDING', 'finish unlinking this board before creating a pairing code');if (originRepository(root) !== state.repository) throw new Refused('RELAY_ORIGIN', 'the origin repository no longer matches this relay link; restore the linked GitHub origin first');@@ -119,7 +122,7 @@ export async function relayPair(root, io) {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 (cursor !== initialCursor || (!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');}diff --git a/test/pairing.test.js b/test/pairing.test.jsindex a425b633..d10c66be 100644--- a/test/pairing.test.js+++ b/test/pairing.test.js@@ -350,7 +350,7 @@ test('[H15,H17] a paired clone synchronizes without a key file from PULLBOARD_REassert.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 => {+test('pairing again after a device joined and a move was added succeeds [H15,H17,H16]', async t => {const box = await relayClientFixture(t);await box.link();const first = await box.cli('relay', 'pair');@@ -387,3 +387,35 @@ test('a newly paired device imports the acknowledged moved board [H15,H17,H16]',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);});+++test('a move made during pairing is still refused as busy [H15,H17]', async t => {+ const box = await relayClientFixture(t);+ await box.link();+ const result = await box.script(`+ const store = await import(${JSON.stringify(new URL('../src/board.js', import.meta.url).href)});+ const {relayPair} = await import(${JSON.stringify(new URL('../src/relay-pairing-client.js', import.meta.url).href)});+ const root = process.cwd();+ const originalFetch = globalThis.fetch;+ let injected = false;+ globalThis.fetch = async (...args) => {+ if (!injected && String(args[0]).includes('/events?after=')) {+ injected = true;+ const board = store.openBoard(root + '/.git/pullboard/board.sqlite');+ try { store.addItem(board, {by:'coordinator',lane:${JSON.stringify(box.lane)},title:'A real local move during pairing',criterion:'The pending pairing must refuse'}); }+ finally { store.closeBoard(board); }+ }+ return originalFetch(...args);+ };+ const sink = {isTTY:false,write(){}};+ let code = null, issued = false;+ try { await relayPair(root,{cwd:root,stdout:sink,stderr:sink,say(){},err(){},result(){issued=true;}}); }+ catch(error) { code=error.code; }+ finally { globalThis.fetch=originalFetch; }+ process.stdout.write(JSON.stringify({injected,code,issued}));+ `);+ assert.equal(result.code,0,result.stderr);+ assert.equal(result.document.injected,true,'the real local store move occurred while the pairing sync awaited actual HTTP');+ assert.equal(result.document.code,'PAIR_BUSY','pairing must refuse a native move during its async sync: '+JSON.stringify(result.document));+ assert.equal(result.document.issued,false,'a changed native prefix never prints a usable pairing code');+});