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(replay): bind recorded conflict execution to transport [V4,H16]
Corey Olson14d23b3ff80c
diff --git a/src/computed-conflict-receipt.js b/src/computed-conflict-receipt.jsindex bb250327..3206d75b 100644--- a/src/computed-conflict-receipt.js+++ b/src/computed-conflict-receipt.js@@ -1,3 +1,4 @@+import { isRecordedConflictContext } from './recorded-conflict-context.js';/** Board-bound computed conflict evidence is verified against immutable Git commits before sealing and on replay [V4,H16]. */import { createHash } from 'node:crypto';import { existsSync } from 'node:fs';@@ -91,7 +92,8 @@ export function preflightComputedConflict(board, id, actor, receipt) {export function computedConflictProblem(board, item, actor, receipt) {const problem = bindingProblem(board, item, actor, receipt);if (problem) return problem;- requireCurrentConflict(board, requireComputedConflict(board, receipt));+ const fields = requireComputedConflict(board, receipt);+ if (!isRecordedConflictContext(board, item, actor, receipt)) requireCurrentConflict(board, fields);return null;}diff --git a/src/recorded-conflict-context.js b/src/recorded-conflict-context.jsnew file mode 100644index 00000000..5f33a543--- /dev/null+++ b/src/recorded-conflict-context.js@@ -0,0 +1,27 @@+/** Internal execution scope for transport-validated recorded moves, never a serialized authority flag [V4,H16]. */+const SCOPES = new WeakMap();++/** Enter only after the transport validates its immutable Git prefix or authenticates its sealed relay record.+ * The callback is synchronous: the scope cannot escape into another queued operation on this board.+ */+export function withRecordedConflictContext(board, move, position, execute) {+ const previous = SCOPES.get(board);+ const scope = { move, bytes: JSON.stringify(move), sequence: position.sequence, at: position.at };+ SCOPES.set(board, scope);+ try { return execute(); }+ finally {+ if (previous) SCOPES.set(board, previous);+ else SCOPES.delete(board);+ }+}++/** Match the exact current recorded position and computed evidence, not caller-supplied labels or hashes. */+export function isRecordedConflictContext(board, item, actor, receipt) {+ const scope = SCOPES.get(board);+ if (!scope || scope.move.operation !== 'reopen' || JSON.stringify(scope.move) !== scope.bytes ||+ !Number.isSafeInteger(scope.sequence) || !Number.isFinite(Date.parse(scope.at))) return false;+ const cursor = Number(board.db.prepare("SELECT meta_value FROM board_meta WHERE meta_key='relay_applied_sequence'").get()?.meta_value ?? 0);+ const [id, options] = scope.move.args;+ return scope.sequence === cursor + 1 && id === item.item_id && options?.agentId === actor &&+ JSON.stringify(options.computedConflict) === JSON.stringify(receipt);+}diff --git a/src/relay.js b/src/relay.jsindex 23b1e2c1..c40bf1b5 100644--- a/src/relay.js+++ b/src/relay.js@@ -1,3 +1,5 @@+import { requirePreparedComputedConflict } from './computed-conflict-receipt.js';+import { withRecordedConflictContext } from './recorded-conflict-context.js';import {formatSnapshotLimit,reportedSnapshotSize,@@ -846,8 +848,9 @@ async function replayRelayRecord(board, key, state, record) {move = await decoded(key, record, state, record.kind, record.event_id);requireSupportedEngine(move);if (record.kind === 'request') return receivePersonRequest(board, move, { sequence: record.event_id, at: record.event_at, sender: record.sender });- return applyRelayMove(board, move, { sequence: record.event_id, at: record.event_at, sender: record.sender, kind: record.kind,- digest: createHash('sha256').update(record.sealed).digest('hex'), registration: record.registration });+ const position = { sequence: record.event_id, at: record.event_at, sender: record.sender, kind: record.kind,+ digest: createHash('sha256').update(record.sealed).digest('hex'), registration: record.registration };+ return withRecordedConflictContext(board, move, position, () => applyRelayMove(board, move, position));} catch (error) { // A seal no key opens, from an engine no newer than this one, is junk: set aside, never a stop [E20].if (!(error instanceof Refused) || !(['RELAY_MOVE', 'RELAY_RESPONSE', 'SEAL_FORMAT', 'SEAL_AUTH_FAILED'].includes(error.code) || error.code === 'SEAL_VERSION' && record.sender?.engine <= ENGINE_VERSION)) throw error;return refuseRelayMove(board, move, { sequence: record.event_id, at: record.event_at, sender: record.sender, kind: record.kind, code: ['SEAL_AUTH_FAILED', 'SEAL_VERSION'].includes(error.code) ? 'RELAY_SEAL' : error.code,@@ -1007,6 +1010,9 @@ async function sendPending(root, file, state, io) {const pending = state.pending;const actor = credentialActor(pending.move);try {+ if (pending.move.operation === 'reopen' && pending.move.args[1]?.computedConflict !== undefined) {+ localRecords(root, board => requirePreparedComputedConflict(board, pending.move.args[0], pending.move.args[1].agentId, pending.move.args[1].computedConflict));+ }const transport = await actorTransport(root, file, state, actor, io);const reply = await request(transport, '/api/v1/boards/' + state.board + '/moves', { method: 'POST',body: { sequence: pending.sequence, sealed: pending.sealed, ...(pending.registration ? { registration: pending.registration } : {}) } }, io);diff --git a/src/sync.js b/src/sync.jsindex 9beff6dc..78e0e5c8 100644--- a/src/sync.js+++ b/src/sync.js@@ -1,3 +1,5 @@+import { requirePreparedComputedConflict } from './computed-conflict-receipt.js';+import { withRecordedConflictContext } from './recorded-conflict-context.js';/** Account-free ordered moves on the repository's own Git remote [H11,H10]. */import { spawn } from 'node:child_process';import {@@ -150,7 +152,8 @@ async function reconcile(root, board) {if (offset < 0) throw new Refused('GIT_SYNC_LOG', 'the remote rewrote this machine\'s acknowledged board prefix; local state was preserved', 'restore the append-only refs/pullboard/board history before syncing');for (const { hash, payload } of records.slice(offset + 1)) {store.atomic(board, () => {- applyEngineMove(board, payload.move, { sequence: payload.sequence, at: payload.at });+ const position = { sequence: payload.sequence, at: payload.at };+ withRecordedConflictContext(board, payload.move, position, () => applyEngineMove(board, payload.move, position));remember(board, hash);});}@@ -185,6 +188,9 @@ async function settle(root, board, pending) {rmSync(paths(root).pending, { force: true });return previous.outcome;}+ if (pending.move.operation === 'reopen' && pending.move.args[1]?.computedConflict !== undefined) {+ requirePreparedComputedConflict(board, pending.move.args[0], pending.move.args[1].agentId, pending.move.args[1].computedConflict);+ }const payload = { version: 1, kind: 'move', sequence: appliedSequence(board) + 1, at: new Date().toISOString(), move: pending.move };const head = await commit(root, payload, tip);if (await publish(root, head, tip)) {diff --git a/test/review-queue.test.js b/test/review-queue.test.jsindex dae65f13..dd7750c5 100644--- a/test/review-queue.test.js+++ b/test/review-queue.test.js@@ -523,6 +523,21 @@ test('a recorded automatic conflict return first replays after the replica trunkbox.git(replica, 'fetch', box.repo, 'main');box.git(replica, 'merge', '-q', '--ff-only', 'FETCH_HEAD');assert.notEqual(box.git(replica, 'rev-parse', 'HEAD'), JSON.parse(record.move).args[1].computedConflict.trunk);+ const fresh = store.openBoard(join(box.dir, 'fresh-stale-return.sqlite'));+ try {+ importBoard(fresh, before);+ const wire = JSON.parse(record.move);+ const options = wire.args[1];+ assert.throws(() => prepareEngineMove(fresh, 'reopen', wire.args), error => error.code === 'COORDINATOR_ONLY',+ 'preparing the same now-stale evidence remains a fresh author request');+ assert.throws(() => store.reopen(fresh, conflicted, options), error => error.code === 'COORDINATOR_ONLY',+ 'the direct board API cannot borrow recorded transport authority');+ const forged = applyEngineMove(fresh, { ...wire, args: [conflicted, { ...options,+ recorded: true, recordedConflictContext: { sequence: record.sequence, move: record.move } }] },+ { sequence: record.sequence, at: new Date().toISOString(), recorded: true });+ assert.equal(forged.error?.code, 'COORDINATOR_ONLY', 'caller-shaped context and generic engine replay grant no authority');+ assert.equal(store.getItem(fresh, conflicted).item_status, 'submitted');+ } finally { store.closeBoard(fresh); }json(box.run(replica, 'sync', '--json'));const replayed = json(box.run(replica, 'export'));assert.equal(replayed.tables.item.find(item => item.item_id === conflicted).item_status, 'open',