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(implies): every replica derives the same implied-fact ids [B29,B31]

Corey Olsone8b6808ea81f
diff --git a/src/implies.js b/src/implies.js
index f3928408..0ab71adf 100644
--- a/src/implies.js
+++ b/src/implies.js
@@ -10,7 +10,7 @@
* caller can mint a person-origin citation (P6). The only route to `by: "person"` is a real
* person answer, which keeps its own person-channel rules.
*/
-import { randomUUID } from 'node:crypto';
+import { createHash, randomUUID } from 'node:crypto';
import { mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
import { dirname, join } from 'node:path';
import { COORDINATOR } from './config.js';
@@ -108,9 +108,15 @@ export function factDecisionRef(fact, itemId) {
return { source: 'fact', id: fact.id, item: itemId, by: fact.by, line: firstLine(fact.text) };
}
-/** A fresh seed for implied-fact ids when no sealed move supplies one; replay passes the move id. */
+/**
+ * The seed for implied-fact ids: the sealed move id on replay, or a fresh one when no move supplies it.
+ * A move id may be 80 characters, but an implied id adds a suffix and must still fit a fact id, so a
+ * move id longer than 72 is replaced by a digest of itself: every replica derives the same ids.
+ */
export function impliesSeed(seed) {
- return typeof seed === 'string' && /^[A-Za-z0-9_-]{1,72}$/u.test(seed) ? seed : randomUUID();
+ if (typeof seed === 'string' && /^[A-Za-z0-9_-]{1,72}$/u.test(seed)) return seed;
+ if (typeof seed === 'string' && /^[A-Za-z0-9_-]{73,80}$/u.test(seed)) return `h${createHash('sha256').update(seed).digest('base64url').slice(0, 43)}`;
+ return randomUUID();
}
/**
@@ -268,11 +274,12 @@ export function tellAnswerImplications(board, log, answerId, { seed, implies, su
export function tellFactImplications(board, log, fact, { id, implies, supersedes }) {
const named = checkImplies(board, implies);
const decision = factDecisionRef(fact, id);
- writeImplied(log, { seed: fact.id, decision, implies: named });
+ const seed = impliesSeed(fact.id);
+ writeImplied(log, { seed, decision, implies: named });
if (supersedes !== null && tellsSupersession(board)) {
const row = board.db.prepare("SELECT event_by, event_detail FROM event WHERE event_kind = 'fact' AND item_id = ? AND json_extract(event_detail, '$.id') = ?").get(id, supersedes);
const old = factDecisionRef({ id: supersedes, by: row.event_by, text: JSON.parse(row.event_detail).text }, id);
- writeSuperseded(log, { seed: fact.id, old, next: decision, implies: impliedItems(board, old) });
+ writeSuperseded(log, { seed, old, next: decision, implies: impliedItems(board, old) });
}
return fact;
}
diff --git a/test/implies.test.js b/test/implies.test.js
index 05ce324c..1bc77090 100644
--- a/test/implies.test.js
+++ b/test/implies.test.js
@@ -219,3 +219,34 @@ test('[P6,B26,H16] --implies cannot forge a person-origin fact through the relay
{ code: 'B26_PERSON_ANSWER' }, "an agent cannot supersede the person's decision");
} finally { store.closeBoard(board); }
});
+
+test('[B29,B31] every replica derives the same implied-fact ids for every supported move id', () => {
+ /** Build one board the same way on each replica, with a fixed clock. */
+ const replica = () => {
+ let at = Date.parse('2026-10-17T00:00:00.000Z');
+ const board = store.openBoard(':memory:', { now: () => new Date(at += 1000) });
+ store.register(board, { lane: 'coordinator', path: '/repo' });
+ store.register(board, { lane: 'web', path: '/repo-web-1' });
+ const one = store.addItem(board, { by: 'coordinator', lane: 'web', title: 'One' });
+ const two = store.addItem(board, { by: 'coordinator', lane: 'web', title: 'Two' });
+ return { board, one, two };
+ };
+ for (const [path, length] of [1, 72, 73, 80].flatMap((n) => [['fact', n], ['answer', n]])) {
+ const id = 'm'.repeat(length);
+ const ids = [];
+ for (const side of [replica(), replica()]) {
+ try {
+ const ask = store.shout(side.board, { from: 'web-1', to: 'coordinator', text: 'Which way?', decision: true, lanes: ['web'] });
+ const move = path === 'fact'
+ ? prepareEngineMove(side.board, 'appendFact', [side.one, { agentId: 'coordinator', kind: 'decision', text: `Boundary ${length}`, implies: [side.two] }], { id, actor: 'coordinator' })
+ : prepareEngineMove(side.board, 'answerDecision', [ask, { agentId: 'coordinator', text: `Boundary ${length}`, lanes: ['web'], implies: [side.two] }], { id, actor: 'coordinator' });
+ const applied = applyEngineMove(side.board, move, { sequence: 1, at: '2026-10-17T00:00:30.000Z' });
+ assert.equal(applied.error, undefined, JSON.stringify(applied.error));
+ ids.push(store.itemThread(side.board, side.two).filter((entry) => entry.type === 'fact' && entry.decision).map((entry) => entry.id));
+ } finally { store.closeBoard(side.board); }
+ }
+ assert.equal(ids[0].length, 1, `a ${length}-character ${path} move id implies one fact`);
+ assert.deepEqual(ids[0], ids[1], `a ${length}-character ${path} move id gives the same implied-fact id on both replicas`);
+ assert.ok(ids[0][0].length <= 80, `the implied-fact id fits a fact id: ${ids[0][0]}`);
+ }
+});