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.

refactor(relay): isolate computed conflict boundaries [V4,H16]

Corey Olson09782cea2366
diff --git a/src/relay-conflict-record.js b/src/relay-conflict-record.js
new file mode 100644
index 00000000..68cd6dbe
--- /dev/null
+++ b/src/relay-conflict-record.js
@@ -0,0 +1,19 @@
+/** Computed-conflict evidence at the authenticated relay replay and sending boundaries [V4,H16]. */
+import { createHash } from 'node:crypto';
+import { requirePreparedComputedConflict } from './computed-conflict-receipt.js';
+import { withRecordedConflictContext } from './recorded-conflict-context.js';
+
+/** Apply an already decrypted, engine-checked relay record inside its exact synchronous position. */
+export function replay(board, move, record, apply) {
+ 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, () => apply(board, move, position));
+}
+
+/** Recheck a fresh computed return before opening its unchanged authenticated actor transport. */
+export function transport(root, move, localRecords, open) {
+ if (move.operation === 'reopen' && move.args[1]?.computedConflict !== undefined) {
+ localRecords(root, board => requirePreparedComputedConflict(board, move.args[0], move.args[1].agentId, move.args[1].computedConflict));
+ }
+ return open();
+}
diff --git a/src/relay.js b/src/relay.js
index e3866395..9f833ebe 100644
--- a/src/relay.js
+++ b/src/relay.js
@@ -1,5 +1,4 @@
-import { requirePreparedComputedConflict } from './computed-conflict-receipt.js';
-import { withRecordedConflictContext } from './recorded-conflict-context.js';
+import * as conflictRecords from './relay-conflict-record.js';
import {
formatSnapshotLimit,
reportedSnapshotSize,
@@ -850,9 +849,7 @@ 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 });
- 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));
+ return conflictRecords.replay(board, move, record, applyRelayMove);
} 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,
@@ -1012,10 +1009,7 @@ 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 transport = await conflictRecords.transport(root, pending.move, localRecords, () => 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);
if (reply.event?.event_id !== pending.sequence || reply.event.sealed !== pending.sealed) throw new Refused('RELAY_RESPONSE', 'the relay acknowledgement differs from this executable send; fetch the configured relay');