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.
JavaScript agentic-codingai-agentsai-governanceautonomous-agentsclaude-codeclicode-reviewcodexcoding-agentsdeveloper-toolsgit-hooksllmlocal-firstmulti-agentsoftware-factoryspec-driven-developmentverificationvibe-coding
fix(review): a refused return never reserves a conflicting head [C7,V4]
Corey Olson7a27c6727dba
diff --git a/src/next-review.js b/src/next-review.jsindex 9f1bcaac..1b906f13 100644--- a/src/next-review.js+++ b/src/next-review.js@@ -9,6 +9,7 @@ import { shownPath } from './trunk-conflict.js';/*** Return each submitted head that conflicts with the trunk to its builder, recorded as a conflict reopen (#807).* Git decides, in memory, exactly as landing does; a board with no recorded trunk keeps today's offers.+ * A refused return throws unless the head already left review, so a known conflict is never offered.** @param {string} root* @param {any} board@@ -25,7 +26,12 @@ export async function returnUnmergeable(root, board, me, { ordered, trunkMerge }try {await ordered('reopen', [item.item_id, { agentId: me.id, conflict: { files: merge.files, trunk: merge.commit } }]);returned.push({ id: item.item_id, files: merge.files });- } catch (error) { if (!(error instanceof Refused)) throw error; }+ } catch (error) {+ // Only a race is forgiven: another move already took the head out of review. A head still waiting+ // when its return was refused would otherwise be the next one offered.+ const now = store.itemById(board, item.item_id);+ if (!(error instanceof Refused) || (now.item_status === 'submitted' && now.item_commit === item.item_commit)) throw error;+ }}return returned;}diff --git a/test/review-queue.test.js b/test/review-queue.test.jsindex 9f47289a..cc0e73fe 100644--- a/test/review-queue.test.js+++ b/test/review-queue.test.js@@ -8,6 +8,8 @@ import { mkdirSync } from 'node:fs';import { writeFileSync } from 'node:fs';import { join } from 'node:path';import { createE2eHelpers } from './e2e-helpers.js';+import { nextReview } from '../src/next-review.js';+import { Refused } from '../src/refused.js';const HOUR = 60 * 60 * 1000;const REVIEW_LEASE = 1_000;@@ -208,3 +210,37 @@ test('next --verify skips a head that does not merge [C7,V4]', (t) => {assert.equal(json(box.run(box.repo, 'show', String(conflicted), '--json')).item_status, 'open');assert.equal(json(box.run(box.repo, 'show', String(clean), '--json')).item_review_by !== null, true, 'the clean head is reserved for review');});++/** Drive nextReview over a board with one submitted head that conflicts, recording each ordered operation. */+async function refusedReturn(t, reopen) {+ const { board, agents } = fixture(t);+ const id = submitted(board, { builder: agents.alphaBuilder, title: 'Conflicting head' });+ const operations = [];+ const ordered = async (operation, args) => {+ operations.push(operation);+ if (operation === 'reopen') return await reopen(board, id);+ return store.reserveNextReview(board, args[0]);+ };+ const ctx = { info: { root: '/fixture' }, io: { err: () => {} }, config: { reviewLeaseMs: REVIEW_LEASE, verify: { policy: 'any' } } };+ const me = { id: agents.betaReviewer, lane: 'review' };+ const trunkMerge = () => ({ commit: 'a'.repeat(40), files: ['web/list.html'] });+ const run = () => nextReview(ctx, board, me, {}, { ordered, idArg: Number, trunkMerge });+ return { board, id, operations, run };+}++test('a refused return of a conflicting head is never followed by reserving it [C7,V4]', async (t) => {+ const { board, id, operations, run } = await refusedReturn(t, () => { throw new Refused('RELAY_BUSY', 'the relay is busy'); });+ await assert.rejects(run, (error) => error.code === 'RELAY_BUSY', 'the refusal reaches the reviewer');+ assert.deepEqual(operations, ['reopen'], 'nothing is reserved after the return failed');+ assert.equal(store.itemById(board, id).item_review_by, null, 'the conflicting head is not reserved');+});++test('a return refused because the head already left review is a race, not a stop [C7,V4]', async (t) => {+ const { board, id, operations, run } = await refusedReturn(t, (raced, item) => {+ store.reopen(raced, item, { agentId: 'coordinator', note: 'another seat returned it first' });+ throw new Refused('NOT_SUBMITTED', `item #${item} is open, not submitted`);+ });+ await run();+ assert.deepEqual(operations, ['reopen', 'reserveNextReview'], 'the loop goes on to the next review');+ assert.equal(store.itemById(board, id).item_status, 'open');+});