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.

feat(core): the outbox notes renumbering at rebuild [H21,H16]

Corey Olson7d44252a56fc
diff --git a/src/relay-outbox.js b/src/relay-outbox.js
index 0e33fa80..b8f80bc7 100644
--- a/src/relay-outbox.js
+++ b/src/relay-outbox.js
@@ -178,6 +178,7 @@ export const ITEM_SLOTS = Object.freeze({
recordLandingBatch: [], recordLandingWaiver: [], recordLandingFlake: [], recordLandingTestDefect: [], finishLandingBatch: [],
recordHealthFindings: [], decideSentinel: [], beginSentinelRun: [], finishSentinelRun: [],
recordFlakeObservation: [], recordGateRun: [], declareJob: [], recordJobRun: [], takeCoordinator: [], openHandoff: [], landingLeaseMove: [],
+ recordActivityDelivery: [], actOnActivity: [], recordRowVerification: [], setBoardMembers: [],
...Object.fromEntries(FIRST_ITEM.map((operation) => [operation, [[0]]])),
intakeOutside: [[0, 'item', 'parentId'], [0, 'item', 'after', '*']],
addItem: [[0, 'parentId'], [0, 'after', '*']],
@@ -486,13 +487,17 @@ function settle(link, outbox, entry, receipt) {
outbox.results[entry.move.id] = receipt.outcome.error ? null : receipt.outcome.result;
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`);
- }
+ if (!receipt.outcome.error) noteRenumbered(link, was, is);
}
}
+/** Say once that an item this machine showed under one number now has another, and keep it for status. */
+function noteRenumbered({ state, io }, was, is) {
+ if (!Number.isSafeInteger(was) || !Number.isSafeInteger(is) || is === was) return;
+ 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`);
+}
+
/**
* Leave a refusal found at replay for the agent whose move it was, so its next command says it (#1013).
* Why: the background sender has no terminal; the agent that made the move is the one that must hear it lost.
@@ -565,7 +570,11 @@ async function rebuild(link, key, pulled) {
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.
+ const shown = entryCreatedItems(entry);
rememberCreatedItems(entry, result);
+ for (const { item: was, resultPath } of shown) {
+ noteRenumbered(link, was, entryCreatedItems(entry).find((row) => JSON.stringify(row.resultPath) === JSON.stringify(resultPath))?.item);
+ }
}
await writeOutbox(where, key, state.board, outbox);
saveOutboxSummary(link, outbox);
diff --git a/test/relay-client-fixture.js b/test/relay-client-fixture.js
index 2446b5cb..09f19956 100644
--- a/test/relay-client-fixture.js
+++ b/test/relay-client-fixture.js
@@ -227,6 +227,7 @@ globalThis.fetch = function tracedFetch(input, init) {
let override = null;
let mintFailures = 0;
let refuseEventReads = false;
+ let refuseMoveSends = false;
let revokeOnNextListing = false;
const boardsWithoutSnapshots = new Map();
const injectedSnapshotWriteDelayMs = Number(process.env.PULLBOARD_TEST_SNAPSHOT_WRITE_DELAY_MS ?? 0);
@@ -496,6 +497,12 @@ globalThis.fetch = function tracedFetch(input, init) {
if (stateReadHold) await stateReadHold;
else await new Promise(resolveDelay => setTimeout(resolveDelay, stateReadDelayMs));
}
+ // Checked before the move hook, so a hook that turns refusal on lets its own move through (#1013).
+ if (refuseMoveSends && req.method === 'POST' && /\/api\/v1\/boards\/[0-9a-f]{32}\/moves$/.test(req.url ?? '')) {
+ res.writeHead(503, { 'content-type': 'application/json' });
+ res.end(JSON.stringify({ version: 1, error: { code: 'RELAY_UNAVAILABLE', message: 'fixture move outage' } }));
+ request.resume(); return;
+ }
if (beforeMove && req.method === 'POST' && /\/api\/v1\/boards\/[0-9a-f]{32}\/moves$/.test(req.url ?? '')) {
const action = beforeMove; beforeMove = null; await action();
}
@@ -890,6 +897,8 @@ globalThis.fetch = function tracedFetch(input, init) {
/** Revoke the real session when the next listing arrives so its HTTP authorization refusal is exercised. */
revokeSessionOnNextListing() { revokeOnNextListing = true; },
refuseReads(value) { refuseEventReads = value; },
+ /** Answer every move send with a temporary outage, as a relay that stops taking moves part way (#1013). */
+ refuseMoves(value) { refuseMoveSends = value; },
/** Return a selected listed-board read's missing-snapshot refusal over real HTTP. */
noBoardOnReads(id, paths = ['state']) {
boardsWithoutSnapshots.set(id, new Set(paths));
diff --git a/test/relay-outbox.test.js b/test/relay-outbox.test.js
index 1739dc1b..4b3bd924 100644
--- a/test/relay-outbox.test.js
+++ b/test/relay-outbox.test.js
@@ -194,14 +194,15 @@ test('an offline item stays bound to its queued moves through a replay that stop
await box.restartRelay();
const agent = await otherAgent(box, other);
assert.equal((await agent('add', box.lane, 'Remote item takes the first number')).document.item.item_id, first);
- // The relay takes the first replayed add, then stops answering reads, so the replay stops part way.
- box.beforeNextMove(() => { box.refuseReads(true); });
+ // The relay takes the first replayed add, then stops answering reads and moves, so the replay stops part way.
+ box.beforeNextMove(() => { box.refuseReads(true); box.refuseMoves(true); });
await box.cli('status');
const shown = (await box.cli('export')).document.tables.item.find((row) => row.item_title === 'Second item added here offline').item_id;
assert.notEqual(shown, second, 'the part-way replay shows the second item under a new number here');
const withdrawn = await box.cli('withdraw', String(shown), 'withdrawn here at the number this machine shows');
assert.equal(withdrawn.code, 0, withdrawn.failure);
box.refuseReads(false);
+ box.refuseMoves(false);
assert.equal((await agent('add', box.lane, 'Remote item takes the shown number')).document.item.item_id, shown,
'the other machine takes the number this machine showed');