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(claim): replay builder windows at the receipt time [B13,B5]

Corey Olson024a219bbcf2
diff --git a/src/claims.js b/src/claims.js
index 05319a31..71e06b85 100644
--- a/src/claims.js
+++ b/src/claims.js
@@ -2,7 +2,7 @@
import { Refused } from './refused.js';
/** Read the latest return's window, ignoring review releases and earlier submissions. */
-export function firstRefusal(board, id) {
+export function firstRefusal(board, id, at = board.clock.now()) {
const history = board.db.prepare("SELECT event_kind, event_detail, event_by FROM event WHERE item_id = ? AND event_kind IN ('reject', 'reopen', 'submit', 'release') ORDER BY event_id DESC").all(id);
const releases = [];
for (const event of history) {
@@ -12,7 +12,7 @@ export function firstRefusal(board, id) {
const window = detail.reopenFirstRefusal;
if (!window || !window.builder || !Number.isFinite(Date.parse(window.until))) return null;
if (releases.some(release => release.event_by === window.builder && JSON.parse(release.event_detail).review !== true)) return null;
- return board.clock.now().getTime() < Date.parse(window.until) ? window : null;
+ return at.getTime() < Date.parse(window.until) ? window : null;
}
return null;
}
diff --git a/src/cli.js b/src/cli.js
index 29d5f73a..7b0fd7c5 100644
--- a/src/cli.js
+++ b/src/cli.js
@@ -57,6 +57,7 @@ import {
DOCTRINE_FILE,
LEGACY_DOCTRINE_FILE,
loadConfig,
+ configFromSource,
} from './config.js';
import { displayAgentName } from './agent-names.js';
import {
@@ -976,7 +977,7 @@ async function reserveRow(ctx, row, written) {
async function withItemSession(info, operation, args, move) { const noted = operation === 'claim' || operation === 'submit'; if (noted) itemSessions.requireLedger(info); const result = await move(); if (noted) itemSessions.recordItemSession(info, args[0], operation); return result; }
async function ordered(ctx, board, operation, args) {
- if (['verify', 'reopen'].includes(operation)) args = firstRefusalArgs(operation, args, mainPolicy(ctx.info.root).config);
+ if (['verify', 'reopen'].includes(operation)) args = firstRefusalArgs(operation, args, configFromSource(coordinatorFile(ctx.info.root, CONFIG_FILE).stdout));
// Every engine-27 registration records the seat that made it: the coordinator from the main
// checkout, the joined agent from its worktree, or `machine` for a join no seat made (#579).
if (operation === 'register' && args[0] && args[0].createdBy === undefined) {
diff --git a/src/engine.js b/src/engine.js
index 6ba45b1f..4fff6e4c 100644
--- a/src/engine.js
+++ b/src/engine.js
@@ -74,9 +74,9 @@ const OPERATION_ENGINE = Object.freeze({ draftSpecRow: ROW_DRAFT_ENGINE, orderMi
shipMilestone: MILESTONE_SHIP_ENGINE });
/** Dependency edits, causes, sealed reviews, submission proofs, trunk conflicts, health observations and milestone targets retain distinct recorded engine meanings. */
-function minimumOperationEngine(operation, args, board) {
+function minimumOperationEngine(operation, args, board, at) {
if (['verify', 'reopen'].includes(operation) && args[1]?.reopenFirstRefusalMinutes !== undefined
- || ['claim', 'release'].includes(operation) && board && firstRefusal(board, args[0])) return REOPEN_FIRST_REFUSAL_ENGINE;
+ || ['claim', 'release'].includes(operation) && board && firstRefusal(board, args[0], at)) return REOPEN_FIRST_REFUSAL_ENGINE;
if (operation === 'recordFlakeObservation') return NATIVE_FLAKE_ENGINE;
if (operation === 'recordLandingBatch' && carriesFlakeDiagnostics(args[0]?.batch)) return NATIVE_FLAKE_ENGINE;
if (['proposeSentinel', 'decideSentinel', 'beginSentinelRun', 'finishSentinelRun'].includes(operation) || typeof args[1]?.cause === 'string' && args[1].cause.startsWith('sentinel:')) return BOARD_SENTINEL_ENGINE;
@@ -325,7 +325,7 @@ export function applyEngineMove(board, move, { sequence, at, standing = null, en
let outcome = previous?.outcome;
if (!outcome) {
// Existing receipts replay before consulting newer snapshot semantics.
- const minimumEngine = minimumOperationEngine(move.operation, move.args, board);
+ const minimumEngine = minimumOperationEngine(move.operation, move.args, board, new Date(at));
if (move.engine < minimumEngine) throw new Refused('RELAY_MOVE', `${move.operation} cannot act on a checked-composition snapshot from engine ${move.engine}; use engine ${minimumEngine} or newer`);
const clock = board.clock;
const engineVersion = board.executionEngineVersion;
diff --git a/test/claim-reopen.test.js b/test/claim-reopen.test.js
index 92b07851..00284368 100644
--- a/test/claim-reopen.test.js
+++ b/test/claim-reopen.test.js
@@ -176,6 +176,7 @@ test('[B13,B5,D1] a builder notice preserves the reopen cause that triggers rigo
returned(f, 'landing', 30, 'refusal:CHECK_RED');
returned(f, 'landing', 30, 'refusal:CHECK_RED');
const notices = store.recentShouts(f.board);
- assert.equal(notices.filter(row => row.shout_from === 'rigor' && row.shout_to === 'coordinator').length, 1);
+ assert.equal(notices.filter(row => row.shout_from === 'rigor' && row.shout_to === 'coordinator' && row.shout_text.includes('CHECK_RED')).length, 1);
+ assert.equal(store.events(f.board).filter(row => row.event_kind === 'rigor-notice' && JSON.parse(row.event_detail).cause === 'refusal:CHECK_RED').length, 1);
assert.equal(notices.filter(row => row.shout_to === f.builder && row.shout_text.includes('waits for you')).length, 2);
});
diff --git a/test/engine.test.js b/test/engine.test.js
index fab5aa34..eaca73ed 100644
--- a/test/engine.test.js
+++ b/test/engine.test.js
@@ -7,6 +7,7 @@ import { join } from 'node:path';
import { pathToFileURL } from 'node:url';
import { test } from 'node:test';
import * as store from '../src/board.js';
+import { submitFixture } from './board-submit-fixture.js';
import { exportBoard, importBoard, restoreRelaySnapshot } from '../src/exchange.js';
import { applyEngineMove, applyRelayMove, prepareEngineMove, appliedSequence, engineReceipt, refuseRelayMove, startRelayEpoch, checkpointSequence, ENGINE_OPERATIONS } from '../src/engine.js';
import { ENGINE_VERSION } from '../src/machine.js';
@@ -623,3 +624,33 @@ test('a failed durable receipt rolls back an otherwise successful move and its c
assert.deepEqual(exportBoard(board), before, 'receipt failure cannot leave a committed claim without its replay position');
assert.equal(replayCursor(board), 0);
});
+
+
+test('engine 65 keeps an ordinary claim available without a return window [B13,H16]', t => {
+ const { copies: [board], item } = engineCopies(t);
+ const move = { ...claimMove(board, item, 'web-2'), engine: 65 };
+ const result = applyEngineMove(board, move, { sequence: 1, at: CLAIM_AT });
+ assert.equal(result.error, undefined);
+ assert.equal(store.getItem(board, item).item_owner, 'web-2');
+});
+
+test('return-window engine admission uses the receipt time rather than replica clocks [B13,H16]', t => {
+ const { copies: [insideClock, expiredClock], item } = engineCopies(t, board => {
+ board.clock = { now: () => new Date('2026-10-07T16:00:00.000Z') };
+ const id = store.listItems(board)[0].item_id;
+ store.claim(board, id, { agentId: 'web-1', lane: 'web', leaseMs: 2 * HOUR,
+ freeze: () => ({ text: '{"rows":[]}', digest: 'f'.repeat(64) }) });
+ submitFixture(board, id, { agentId: 'web-1', commit: 'a'.repeat(40), tree: 'a'.repeat(40) });
+ store.verify(board, id, { agentId: 'web-2', decision: 'REJECT', reason: 'OTHER', note: 'proof',
+ head: 'a'.repeat(40), digest: 'f'.repeat(64), policy: 'any', reopenFirstRefusalMinutes: 30 });
+ });
+ const before = boardRows(expiredClock, item);
+ const old = { ...claimMove(expiredClock, item, 'web-2'), engine: 65 };
+ assert.throws(() => applyEngineMove(expiredClock, old, { sequence: 1, at: '2026-10-07T16:05:00.000Z' }), /engine/);
+ assert.deepEqual(boardRows(expiredClock, item), before);
+ assert.equal(appliedSequence(expiredClock), 0);
+ const atExpiry = { ...claimMove(insideClock, item, 'web-2'), engine: 65 };
+ const result = applyEngineMove(insideClock, atExpiry, { sequence: 1, at: '2026-10-07T16:30:00.000Z' });
+ assert.equal(result.error, undefined);
+ assert.equal(store.getItem(insideClock, item).item_owner, 'web-2');
+});