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): share the return timestamp with its window [B13,B5]

Corey Olson6f917ecdf9c5
diff --git a/src/board.js b/src/board.js
index 4d5b71d6..e498b2df 100644
--- a/src/board.js
+++ b/src/board.js
@@ -513,15 +513,16 @@ export function atomic(board, work) {
* @param {string} kind
* @param {number | null} itemId
* @param {object} [detail]
+ * @param {Date} [at] An enabled move may share one instant with its deadline.
*/
-export function logEvent(board, by, kind, itemId, detail = {}) {
+export function logEvent(board, by, kind, itemId, detail = {}, at) {
const model = agentModel(board, by);
const isAgent = Boolean(board.db.prepare('SELECT 1 FROM agent WHERE agent_id = ?').get(by));
const recorded = (board.executionEngineVersion ?? ENGINE_VERSION) >= 8 && isAgent
? { ...detail, model: model ?? 'unknown' } : detail;
const inserted = board.db
.prepare('INSERT INTO event (event_at, event_by, event_kind, item_id, event_detail) VALUES (?, ?, ?, ?, ?)')
- .run(now(board), by, kind, itemId, JSON.stringify(recorded));
+ .run(at ? at.toISOString() : now(board), by, kind, itemId, JSON.stringify(recorded));
board.lastEvent = board.db.prepare('SELECT * FROM event WHERE event_id = ?').get(inserted.lastInsertRowid);
(board.emittedEvents ??= []).push(board.lastEvent);
}
@@ -1609,11 +1610,12 @@ export function verify(board, id, { agentId, decision, reason, note = '', cause,
},
set: (found) => ({ item_verdict: decision, item_verified_by: isAccept ? agentId : null, item_owner: isAccept ? found.item_owner : null }),
});
- const reservation = !isAccept && engine >= REOPEN_FIRST_REFUSAL_ENGINE ? firstRefusalDetail(board, item, reopenFirstRefusalMinutes) : {};
+ const returnedAt = !isAccept && engine >= REOPEN_FIRST_REFUSAL_ENGINE && reopenFirstRefusalMinutes > 0 && item.item_built_by ? board.clock.now() : undefined;
+ const reservation = !isAccept && engine >= REOPEN_FIRST_REFUSAL_ENGINE ? firstRefusalDetail(board, item, reopenFirstRefusalMinutes, returnedAt) : {};
const detail = { ...reservation, reason: code, commit: item.item_commit, ...(!isAccept && cause !== undefined && cause !== null ? { cause } : {}) };
if (isAccept && check !== undefined) detail.check = check;
if (newReview) detail.review = { commit: review.commit, ...(Object.hasOwn(review, 'head') ? { head: review.head } : {}), trunk: review.trunk, paths: [...review.paths] };
- logEvent(board, agentId, verb, id, implies?.length ? { ...detail, implies } : detail);
+ logEvent(board, agentId, verb, id, implies?.length ? { ...detail, implies } : detail, returnedAt);
const trigger = board.lastEvent;
tellFirstRefusal(board, item, reservation, persistShout);
if (!isAccept) recordRejectedItemRoute(board, id, engine, item, { escalate, shout, logEvent });
@@ -1687,10 +1689,11 @@ export function reopen(board, id, { agentId, note = '', conflict, cause, reopenF
};
},
});
- const reservation = (forMerge || landingFailure) && currentEngine >= REOPEN_FIRST_REFUSAL_ENGINE ? firstRefusalDetail(board, item, reopenFirstRefusalMinutes) : {};
+ const returnedAt = (forMerge || landingFailure) && currentEngine >= REOPEN_FIRST_REFUSAL_ENGINE && reopenFirstRefusalMinutes > 0 && item.item_built_by ? board.clock.now() : undefined;
+ const reservation = (forMerge || landingFailure) && currentEngine >= REOPEN_FIRST_REFUSAL_ENGINE ? firstRefusalDetail(board, item, reopenFirstRefusalMinutes, returnedAt) : {};
const returned = forMerge ? { supersedes, ...conflictDetail(conflict) } : supersedes ? { supersedes, landingFailure } : {};
logEvent(board, agentId, 'reopen', id, { commit: submittedCommit, note: note.trim() || conflictNote(conflict), judgment: null, ...reservation,
- ...(cause !== undefined && cause !== null ? { cause } : {}), ...returned });
+ ...(cause !== undefined && cause !== null ? { cause } : {}), ...returned }, returnedAt);
const trigger = board.lastEvent;
tellFirstRefusal(board, item, reservation, persistShout);
if (!reservation.reopenFirstRefusal && forMerge && supersedes === undefined && item.item_built_by) persistShout(board, { from: agentId, to: item.item_built_by, text: returnedHeadNotice(id, submittedCommit, conflict) });
diff --git a/src/claims.js b/src/claims.js
index 71e06b85..0c7b88ef 100644
--- a/src/claims.js
+++ b/src/claims.js
@@ -32,9 +32,9 @@ export function firstRefusalReason(board, id, agentId) {
}
/** Freeze an enabled reservation into the return event so replicas need no local configuration. */
-export function firstRefusalDetail(board, item, minutes) {
+export function firstRefusalDetail(board, item, minutes, at) {
if (minutes === undefined || minutes === 0 || !item.item_built_by) return {};
- const until = board.clock.now().getTime() + minutes * 60_000;
+ const until = (at ?? board.clock.now()).getTime() + minutes * 60_000;
if (!Number.isSafeInteger(minutes) || minutes < 0 || !Number.isFinite(until) || Math.abs(until) > 8_640_000_000_000_000) {
throw new Refused('BAD_CONFIG', 'claim.reopenFirstRefusalMinutes must be a non-negative whole number within the supported date range; set it to 0 to disable');
}
diff --git a/test/claim-reopen-clock.test.js b/test/claim-reopen-clock.test.js
new file mode 100644
index 00000000..e0fc1662
--- /dev/null
+++ b/test/claim-reopen-clock.test.js
@@ -0,0 +1,64 @@
+/** @pullboard-test-loads src/board.js src/claims.js */
+/** Advancing clocks preserve the entire opt-in builder window [B13,B5]. */
+import assert from 'node:assert/strict';
+import { mkdtempSync, rmSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
+import { test } from 'node:test';
+import * as store from '../src/board.js';
+import { submitFixture } from './board-submit-fixture.js';
+
+const COMMIT = 'a'.repeat(40);
+const TRUNK = 'b'.repeat(40);
+/** Open a real SQLite board with a clock advanced independently of the host. */
+function fixture(t) {
+ const directory = mkdtempSync(join(tmpdir(), 'pullboard-reopen-'));
+ let at = Date.parse('2026-01-01T00:00:00Z');
+ const board = store.openBoard(join(directory, 'board.sqlite'), { now: () => new Date(at) });
+ t.after(() => { store.closeBoard(board); rmSync(directory, { recursive: true, force: true }); });
+ store.register(board, { lane: 'coordinator', path: '/repo' });
+ const builder = store.register(board, { lane: 'core', path: '/builder', route: 'mid' });
+ const other = store.register(board, { lane: 'core', path: '/other', route: 'mid' });
+ return { board, directory, builder, other, advance: (minutes) => { at += minutes * 60_000; } };
+}
+/** Claim the item with a frozen bar and a bounded lease. */
+function claim(f, id, agentId) {
+ return store.claim(f.board, id, { agentId, lane: 'core', leaseMs: 7_200_000,
+ freeze: () => ({ text: JSON.stringify({ policy: { version: 1, commit: COMMIT, verify: { policy: 'any', family: 'off' } } }), digest: 'digest:bar' }) });
+}
+/** Submit and return an item through the real rejection, landing-failure or conflict path. */
+function returned(f, cause, minutes, causeKey) {
+ const id = store.addItem(f.board, { by: 'coordinator', lane: 'core', title: 'fix', criterion: 'prove', specIds: ['B13'], route: 'mid', check: 'true', brief: 'Files: src/a.js\nTest: proves the fix' });
+ claim(f, id, f.builder);
+ submitFixture(f.board, id, { agentId: f.builder, commit: COMMIT, tree: COMMIT });
+ const verdict = { agentId: f.other, head: COMMIT, digest: 'digest:bar', policy: 'any', note: 'proof', ...(causeKey ? { cause: causeKey } : {}) };
+ if (cause === 'reject') store.verify(f.board, id, { ...verdict, decision: 'REJECT', reason: 'OTHER', reopenFirstRefusalMinutes: minutes });
+ else {
+ store.verify(f.board, id, { ...verdict, decision: 'ACCEPT' });
+ store.reopen(f.board, id, { agentId: 'coordinator', reopenFirstRefusalMinutes: minutes, ...(causeKey ? { cause: causeKey } : {}),
+ ...(cause === 'conflict' ? { conflict: { files: ['src/a.js'], trunk: TRUNK } }
+ : { note: `test/a.test.js: failed case; merge commit ${TRUNK}` }) });
+ }
+ return id;
+}
+
+test('[B13,B5] every return anchors its full builder window to one advancing-clock instant', t => {
+ for (const cause of ['reject', 'landing', 'conflict']) {
+ for (const stepMs of [1, 1000]) {
+ const f = fixture(t);
+ let instant = Date.parse('2026-01-01T00:00:00Z');
+ f.board.clock = { now: () => { const at = new Date(instant); instant += stepMs; return at; } };
+ const id = returned(f, cause, 30);
+ const event = store.events(f.board, { itemId: id }).findLast(row => row.event_kind === (cause === 'reject' ? 'reject' : 'reopen'));
+ const window = JSON.parse(event.event_detail).reopenFirstRefusal;
+ assert.equal(Date.parse(window.until) - Date.parse(event.event_at), 30 * 60_000, `${cause}/${stepMs}`);
+ assert.equal(store.recentShouts(f.board).filter(row => row.shout_to === f.builder && row.shout_text.includes('waits for you')).length, 1);
+ instant = Date.parse(window.until) - 1;
+ f.board.clock = { now: () => new Date(instant) };
+ assert.throws(() => claim(f, id, f.other), error => error.code === 'REOPEN_HELD_FOR_BUILDER');
+ instant += 1;
+ claim(f, id, f.other);
+ assert.equal(store.getItem(f.board, id).item_owner, f.other);
+ }
+ }
+});