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(relay): omit absent replacement on deleted-copy relink [H5,H17]
Corey Olson4f106e2363db
diff --git a/src/relay-relink.js b/src/relay-relink.jsindex 70970891..2b237d37 100644--- a/src/relay-relink.js+++ b/src/relay-relink.js@@ -81,3 +81,13 @@ export function archiveRelinkOutbox(root, state) {export function finishRelink(root) {rmSync(markerFile(root), { force: true });}++/** A confirmed deleted copy has no active link to retire; retained OFF intents still name theirs. */+export function relinkReplacement(state, relink, deletedBoard) {+ const previous = state?.replaces ?? relink?.previous;+ if (previous && previous === deletedBoard) {+ if (state) { delete state.replaces; delete state.previousBoardNotice; }+ return null;+ }+ return previous;+}diff --git a/src/relay.js b/src/relay.jsindex b54b7822..0aab05ce 100644--- a/src/relay.js+++ b/src/relay.js@@ -1,3 +1,4 @@+import { relinkReplacement } from './relay-relink.js';import { relayExclusion } from './relay-exclusion-state.js';import { excludeRelayByPerson } from './relay-exclusion-state.js';import { clearRelayExclusion } from './relay-exclusion-state.js';@@ -1583,7 +1584,8 @@ export async function relayOn(root, address, io, { session, credential, quiet =if (state && (state.url !== url || state.repository !== repository)) throw new Refused('RELAY_LINKED', 'this board is linked to another relay or repository; run relay off before changing its link');const key = state ? readBoardKey(state.board) : await generateBoardKey();const nextBoard = state?.board ?? plannedRelayBoard(root, localRecords(root, store.boardId));- const relink = state ? null : relayRelink(root), replacement = state?.replaces ?? relink?.previous;+ const relink = state ? null : relayRelink(root);+ const replacement = relinkReplacement(state, relink, deletedLink(root)?.board);const intent = remoteShell ? { board: nextBoard, repository,host: hostname(), boardName: basename(root), ...(replacement ? { replaces: replacement } : {}) } : undefined;const signed = remoteShell ? await deviceSignIn(url, io, { intent }) : reusableCredential ?? reusableSession ?? await deviceSignIn(url, io);@@ -1603,7 +1605,7 @@ export async function relayOn(root, address, io, { session, credential, quiet =cursor: snapshot.document.tables.event.at(-1)?.event_id ?? 0, baselineCursor: snapshot.document.tables.event.at(-1)?.event_id ?? 0,baselineAccepted: false, linkPending: true };state.snapshot = { sequence: 0, sealed: await sealedRecord(key, snapshot.document, state, 'snapshot', 0) };- if (relink) { state.previousBoardNotice = relink.previous; state.replaces = relink.previous; }+ if (relink && replacement) { state.previousBoardNotice = relink.previous; state.replaces = replacement; }}const account = signed.account ?? signed.user?.id;// Persist the exact sealed snapshot and a recoverable link intent before making the remote link.diff --git a/test/relay-exclusion-fixture.js b/test/relay-exclusion-fixture.jsindex 014f4729..c20ec432 100644--- a/test/relay-exclusion-fixture.js+++ b/test/relay-exclusion-fixture.js@@ -30,7 +30,7 @@ export async function deletedCopyRelinks(t) {});assert.equal(stale.status, 410, 'deleted credentials remain tombstoned and cannot recreate their board');const linked = await box.cli('relay', 'on', '--url', box.origin);- assert.equal(linked.code, 0, 'the existing genuine sign-in flow grants the replacement link');+ assert.equal(linked.code, 0, 'the existing genuine sign-in flow grants the replacement link: ' + (linked.document?.error?.code ?? 'no refusal code'));const fresh = JSON.parse(readFileSync(box.linkFile, 'utf8'));assert.notEqual(fresh.board, old.board, 'the deleted remote epoch is replaced rather than resurrected');assert.notEqual(fresh.token, old.token, 'recovery obtains newly authorized machine credentials');