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(relay): follow all created items through outbox replay [B26,H16,H17]

Corey Olson04400936f68b
diff --git a/src/relay-created-items.js b/src/relay-created-items.js
new file mode 100644
index 00000000..ac854256
--- /dev/null
+++ b/src/relay-created-items.js
@@ -0,0 +1,37 @@
+/** Explicit result bindings for item-creating moves; input item fields never become created-item identities [B26,H16]. */
+const SINGLE = Object.freeze({ addItem: [], intakeOutside: [], openHandoff: ['item'],
+ recordLandingFlake: ['item'], recordLandingTestDefect: ['item'], recordFlakeObservation: ['item'],
+ recordPublishFinding: ['repair'] });
+
+/** Whether this operation can return new item identities, including an empty or refused result. */
+export function createsItems(operation) {
+ return Object.hasOwn(SINGLE, operation) || operation === 'recordGateRun';
+}
+
+/** Read a declared result path; multi-repair identities follow their file/name rather than a changing array index. */
+export function createdItemAt(result, path) {
+ return path.reduce((value, key) => typeof key === 'object'
+ ? Array.isArray(value) ? value.find(row => row.file === key.file && row.name === key.name) : undefined
+ : value?.[key], result);
+}
+
+/** Project only declared created results; publication's original item is deliberately not its repair. */
+export function createdItems(operation, result) {
+ const paths = Object.hasOwn(SINGLE, operation) ? [SINGLE[operation]] : operation === 'recordGateRun'
+ ? (result?.quarantined ?? []).map(row => ['quarantined', { file: row.file, name: row.name }, 'item']) : [];
+ return paths.map(resultPath => ({ resultPath, item: createdItemAt(result, resultPath) }))
+ .filter(row => Number.isSafeInteger(row.item) && row.item > 0);
+}
+
+/** Read new per-result bindings or the original single numeric addItem entry without rewriting stored history. */
+export function entryCreatedItems(entry) {
+ return Array.isArray(entry.created) ? entry.created
+ : Number.isSafeInteger(entry.visible) ? [{ resultPath: [], item: entry.visible }] : [];
+}
+
+/** Remember the local result after both initial application and a partial replay's rebase. */
+export function rememberCreatedItems(entry, result) {
+ if (!createsItems(entry.move.operation)) return;
+ entry.created = createdItems(entry.move.operation, result);
+ if (entry.move.operation === 'addItem' && Number.isSafeInteger(result)) entry.visible = result;
+}
diff --git a/src/relay-outbox.js b/src/relay-outbox.js
index 6fc35d50..953304bd 100644
--- a/src/relay-outbox.js
+++ b/src/relay-outbox.js
@@ -47,6 +47,7 @@ import {
} from './seal.js';
import { stampCoordinatorHolder } from './coordinator-hold.js';
import { Refused } from './refused.js';
+import { createdItemAt, createsItems, entryCreatedItems, rememberCreatedItems } from './relay-created-items.js';
/** How many replay refusals the link keeps for pullboard status; older ones stay in the relay's own receipts. */
const KEPT_REFUSALS = 20;
@@ -227,7 +228,7 @@ const ITEM_KEYS = /^(id|ids|item|items|itemId|parentId|after|implies|add|remove|
* queued, because the outbox could not follow the item if the relay renumbers it (#922).
*/
export function strayItemRefs(outbox, move) {
- const pending = new Set(outbox.moves.filter((entry) => Number.isSafeInteger(entry.visible)).map((entry) => entry.visible));
+ const pending = new Set(outbox.moves.flatMap(entryCreatedItems).map(row => row.item));
if (!pending.size) return [];
const declared = new Set(itemSlots(move).map((path) => JSON.stringify(path)));
const found = [];
@@ -248,8 +249,10 @@ export function strayItemRefs(outbox, move) {
* that number, and a replay part way through renumbers it here, so only the add itself names the item (#922).
*/
export function bindRefs(outbox, move) {
- const pending = new Map(outbox.moves.filter((entry) => Number.isSafeInteger(entry.visible)).map((entry) => [entry.visible, entry.move.id]));
- return itemSlots(move).filter((path) => pending.has(itemNumber(slot(move, path)))).map((path) => ({ path, add: pending.get(itemNumber(slot(move, path))) }));
+ const pending = new Map(outbox.moves.flatMap(entry => entryCreatedItems(entry).map(row => [row.item,
+ { add: entry.move.id, ...(row.resultPath.length ? { resultPath: row.resultPath } : {}) }])));
+ return itemSlots(move).filter((path) => pending.has(itemNumber(slot(move, path))))
+ .map(path => ({ path, ...pending.get(itemNumber(slot(move, path))) }));
}
/**
@@ -259,10 +262,12 @@ export function bindRefs(outbox, move) {
export function resolveMove(entry, outbox, { local = false } = {}) {
const move = structuredClone(entry.move);
const lost = [];
- for (const { path, add } of entry.refs ?? []) {
+ for (const { path, add, resultPath = [] } of entry.refs ?? []) {
const waiting = local ? outbox.moves.find((other) => other.move.id === add) : null;
- const value = waiting ? waiting.visible : outbox.results?.[add];
- if (value === null) lost.push(itemNumber(slot(entry.move, path)));
+ const result = outbox.results?.[add];
+ const value = waiting ? entryCreatedItems(waiting).find(row => JSON.stringify(row.resultPath) === JSON.stringify(resultPath))?.item
+ : createdItemAt(result, resultPath);
+ if (result === null && !waiting || value === undefined) lost.push(itemNumber(slot(entry.move, path)));
else if (Number.isSafeInteger(value)) slot(move, path, sameForm(slot(entry.move, path), value));
}
return { move, lost };
@@ -349,8 +354,8 @@ export async function queueMove(link, { operation, args, command, move, error, a
saveOutboxSummary(link, outbox);
throw refusal;
}
- if (move.operation === 'addItem' && Number.isSafeInteger(result)) {
- entry.visible = result;
+ if (createsItems(move.operation)) {
+ rememberCreatedItems(entry, result);
await writeOutbox(where, key, state.board, outbox);
}
if (!OUTBOX_NOTICES.has(io)) {
@@ -380,7 +385,7 @@ async function rebaseOutbox(link, outbox, key) {
catch (error) { if (!(error instanceof Refused)) throw error; return null; }
});
// A re-applied add may get another number here; later moves reach it through their bound add, not the number.
- if (move.operation === 'addItem' && Number.isSafeInteger(result)) entry.visible = result;
+ rememberCreatedItems(entry, result);
}
await writeOutbox(outboxFile(file), key, state.board, outbox);
}
@@ -457,12 +462,14 @@ export async function flushOutbox(link) {
const earlier = localRecords(root, (board) => earlierMoves(board, { ...entry, move: resolveMove(entry, outbox).move }, sequence));
io.err(`pullboard: ${keepRefusal(state, entry, receipt.outcome.error, earlier)}`);
}
- if (entry.move.operation === 'addItem') {
+ if (createsItems(entry.move.operation)) {
outbox.results[entry.move.id] = receipt.outcome.error ? null : receipt.outcome.result;
- const is = receipt.outcome.result;
- if (!receipt.outcome.error && Number.isSafeInteger(entry.visible) && Number.isSafeInteger(is) && is !== entry.visible) {
- state.outboxRenumbered = [...(state.outboxRenumbered ?? []), { was: entry.visible, is }].slice(-KEPT_REFUSALS);
- io.err(`pullboard: the item this machine showed as #${entry.visible} while the relay was down is #${is} on the board; its queued moves follow it`);
+ for (const { item: was, resultPath } of entryCreatedItems(entry)) {
+ const is = createdItemAt(receipt.outcome.result, resultPath);
+ if (!receipt.outcome.error && Number.isSafeInteger(is) && is !== was) {
+ state.outboxRenumbered = [...(state.outboxRenumbered ?? []), { was, is }].slice(-KEPT_REFUSALS);
+ io.err(`pullboard: the item this machine showed as #${was} while the relay was down is #${is} on the board; its queued moves follow it`);
+ }
}
}
await finishEntry(link, outbox, where, key);
diff --git a/test/relay-outbox.test.js b/test/relay-outbox.test.js
index 6e675637..1739dc1b 100644
--- a/test/relay-outbox.test.js
+++ b/test/relay-outbox.test.js
@@ -6,6 +6,7 @@ import { join } from 'node:path';
import test from 'node:test';
import { fileURLToPath } from 'node:url';
import { ENGINE_OPERATIONS } from '../src/engine.js';
+import { rememberCreatedItems } from '../src/relay-created-items.js';
import {
ITEM_SLOTS,
bindRefs,
@@ -307,3 +308,31 @@ test('a milestone edit naming an offline item follows that item when another mac
});
test('a relay refusal after a recorded move says it was recorded [C6,N26,H16]', recordedRelayRefusal);
+
+
+test('created-item bindings distinguish repair outputs and survive reordered multi-repair results [B26,H16,H17]', () => {
+ const publication = { move: { id: 'publication', operation: 'recordPublishFinding' } };
+ rememberCreatedItems(publication, { item: 9, repair: 12 });
+ const gate = { move: { id: 'gate', operation: 'recordGateRun' } };
+ rememberCreatedItems(gate, { quarantined: [{ file: 'test/a.test.js', name: 'a', item: 13 },
+ { file: 'test/b.test.js', name: 'b', item: 14 }] });
+ const outbox = { moves: [publication, gate], results: {} };
+ const move = { operation: 'addItem', args: [{ parentId: 12, after: [13, 14, 9] }] };
+ const entry = { move, refs: bindRefs(outbox, move) };
+ assert.equal(entry.refs.length, 3, 'the original publication item is not a newly created repair');
+ outbox.results.publication = { item: 9, repair: 22 };
+ outbox.results.gate = { quarantined: [{ file: 'test/b.test.js', name: 'b', item: 24 },
+ { file: 'test/a.test.js', name: 'a', item: 23 }] };
+ const resolved = resolveMove(entry, outbox);
+ assert.deepEqual(resolved.move.args, [{ parentId: 22, after: [23, 24, 9] }]);
+ assert.deepEqual(resolved.lost, []);
+ outbox.results.gate.quarantined.shift();
+ assert.deepEqual(resolveMove(entry, outbox).lost, [14], 'a missing repair is lost rather than bound to a different array member');
+ outbox.results.publication = null;
+ assert.deepEqual(resolveMove(entry, outbox).lost, [12, 14], 'a refused creator cannot redirect its dependent move');
+ rememberCreatedItems(gate, { quarantined: [{ file: 'test/a.test.js', name: 'a', item: 33 },
+ { file: 'test/b.test.js', name: 'b', item: 34 }] });
+ rememberCreatedItems(publication, { item: 9, repair: 32 });
+ assert.deepEqual(resolveMove(entry, outbox, { local: true }).move.args, [{ parentId: 32, after: [33, 34, 9] }],
+ 'partial replay uses each newly shown local repair identity');
+});