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(land): stop producers before gate cleanup [B3,R3]

Corey Olson49e646d4776d
diff --git a/src/land.js b/src/land.js
index eba64232..cf0f558c 100644
--- a/src/land.js
+++ b/src/land.js
@@ -116,8 +116,8 @@ function landingEntry(item) {
...(item.item_landing_commit !== item.item_commit ? { reviewedCommit: item.item_landing_commit } : {}) };
}
-/** Select verified, unmerged candidates in verdict order, retaining dependency order [B3,R3]. */
-function candidates(board, root, base, maximum) {
+/** Select in verdict order; a read-only preflight may stop at its first eligible item [B3,R3]. */
+function candidates(board, root, base, maximum, { firstReady = false } = {}) {
const all = store.listItems(board, { all: true });
const projector = verdictProjector(root, board, { main: base });
const pending = all.filter((item) => item.item_status === 'verified' && !item.item_merged_commit);
@@ -146,7 +146,10 @@ function candidates(board, root, base, maximum) {
blocked.push({ id: item.item_id, code: 'STACKED_UNVERIFIED', stacked: stacked.item_id });
continue;
}
- if (ready.length < maximum) ready.push(item);
+ if (ready.length < maximum) {
+ ready.push(item);
+ if (firstReady) break;
+ }
}
return { ready, blocked };
}
@@ -689,7 +692,7 @@ export async function land(options) {
// Only accepted trunk policy may inform this read-only preflight.
const config = policyAt(options.root, trunk.commit).config;
options.board.quarantineEnabled = () => config.flakes?.quarantine === true;
- const selected = candidates(options.board, options.root, trunk.commit, options.maximum ?? Infinity);
+ const selected = candidates(options.board, options.root, trunk.commit, options.maximum ?? Infinity, { firstReady: true });
invalidateGitFacts();
const current = mainCheckout(options.root);
if (!selected.ready.length && current?.commit === trunk.commit && current.branch === branch
diff --git a/src/landing-worker.js b/src/landing-worker.js
index 066d3f49..66a9c346 100644
--- a/src/landing-worker.js
+++ b/src/landing-worker.js
@@ -48,7 +48,8 @@ function stop(child, member) {
} while (changed);
const current = census();
if (!current) return; // Missing identity evidence never authorizes a process-group signal.
- for (const pid of [...owned].reverse()) if (pid !== child.pid && !current.get(pid)?.state.startsWith('Z') && current.get(pid)?.started === rows.get(pid)?.started
+ // Stop producers first: killing a held gate must not wake its worker into post-gate Git work.
+ for (const pid of owned) if (pid !== child.pid && !current.get(pid)?.state.startsWith('Z') && current.get(pid)?.started === rows.get(pid)?.started
&& current.get(pid)?.processSha256 === rows.get(pid)?.processSha256) {
try { process.kill(pid, 'SIGKILL'); } catch (error) { if (error.code !== 'ESRCH') throw error; }
}
@@ -226,7 +227,8 @@ function guardianMain() {
}
if (message.type === 'start' && !worker) {
// The worker stays in this guardian's detached group; its gates inherit that group too.
- worker = spawn(process.execPath, [FILE, 'worker'], { cwd: message.options.root, env: process.env,
+ // Worker observations must not leave an optional status-refresh index lock when interrupted.
+ worker = spawn(process.execPath, [FILE, 'worker'], { cwd: message.options.root, env: { ...process.env, GIT_OPTIONAL_LOCKS: '0' },
stdio: ['ignore', 'ignore', 'inherit', 'ipc'] });
worker.on('message', value => {
if (!process.connected) return;
diff --git a/test/land.test.js b/test/land.test.js
index 4148e375..4c06c6d9 100644
--- a/test/land.test.js
+++ b/test/land.test.js
@@ -564,9 +564,13 @@ test('land bisects a real red, blocks stale proof and refuses an unverified stac
assert.equal(box.git(box.remote, 'rev-parse', 'main'), result.batch.tip);
assert.notEqual(result.batch.tip, base);
const afterCalls = calls(box).length;
+ const beforeEmptyEvents = events(box);
+ const beforeEmptyLease = onBoard(box, board => store.landingLeaseState(board));
const again = box.run(box.repo, 'land', '--json');
assert.equal(again.code, 1, again.out + again.err);
assert.equal(JSON.parse(again.out).error.code, 'STALE_VERDICT', 'an all-blocked queue refuses instead of suggesting an empty successful land');
+ assert.deepEqual(events(box), beforeEmptyEvents, 'an idle all-blocked selection adds no lease events');
+ assert.deepEqual(onBoard(box, board => store.landingLeaseState(board)), beforeEmptyLease, 'a stale refusal takes no lease');
assert.equal(json(box, box.repo, 'show', String(entries[2].item)).item_status, 'open', 'the known red is returned to its builder and is no longer a verified landing candidate');
assert.equal(calls(box).length, afterCalls, 'known unchanged red is not retried');
});