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(core): refuse repairs before branch mutation [Q1,Q3,B3]

Corey Olsondf339209dac6
diff --git a/src/land.js b/src/land.js
index 742d3eec..ca62e8e6 100644
--- a/src/land.js
+++ b/src/land.js
@@ -706,7 +706,10 @@ export async function land(options) {
export async function runLandingBatch({ root, board, config, write, say, owner, maximum = Infinity, dryRun = false, adopt = false, onWait, checkLease, checkLeaseNow, fence }) {
let trunk = mainCheckout(root);
if (fence && trunk?.branch !== fence.branch) throw new Refused('LAND_LEASE_LOST', 'the trunk branch changed while landing waited; start a new land command for its current branch');
+ const unfinished = store.landingBatches(board).findLast((batch) => batch.state !== 'landed' && batch.state !== 'blocked');
+ if (fence && unfinished && unfinished.branch !== fence.branch) throw new Refused('LAND_LEASE_LOST', 'the interrupted batch belongs to another trunk branch; restore that branch and start a fresh land --adopt');
const recorded = store.landingBatches(board).findLast((batch) => batch.state === 'landed' && batch.base === trunk?.commit);
+ if (fence && recorded && recorded.branch !== fence.branch) throw new Refused('LAND_LEASE_LOST', 'the recorded Git repair belongs to another trunk branch; restore that branch before landing');
if (!dryRun && recorded && isClean(root) && !untracked(root).length) {
await checkLease();
git(root, ['merge', '--ff-only', recorded.tip]);
@@ -716,8 +719,6 @@ export async function runLandingBatch({ root, board, config, write, say, owner,
// Pin accepted policy after any recorded-landed repair, never before admission or from candidate files.
config ??= policyAt(root, trunk.commit).config;
board.quarantineEnabled = () => config.flakes?.quarantine === true;
- const unfinished = store.landingBatches(board).findLast((batch) => batch.state !== 'landed' && batch.state !== 'blocked');
- if (fence && unfinished && unfinished.branch !== fence.branch) throw new Refused('LAND_LEASE_LOST', 'the interrupted batch belongs to another trunk branch; restore that branch and start a fresh land --adopt');
const selected = candidates(board, root, trunk.commit, maximum);
const stale = selected.blocked.find(item => item.code === 'STALE_VERDICT');
if (!selected.ready.length && stale) throw staleVerdictRefusal({ item_id: stale.id }, stale);
diff --git a/src/landing-worker.js b/src/landing-worker.js
index c5b3f27f..5b0759a6 100644
--- a/src/landing-worker.js
+++ b/src/landing-worker.js
@@ -40,10 +40,13 @@ function stop(child, member) {
for (const row of rows.values()) if (owned.has(row.ppid) && !owned.has(row.pid)) { owned.add(row.pid); changed = true; }
} while (changed);
const current = census();
- for (const pid of [...owned].reverse()) if (pid !== child.pid && current?.get(pid)?.started === rows.get(pid)?.started
+ 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
&& current.get(pid)?.processSha256 === rows.get(pid)?.processSha256) {
try { process.kill(pid, 'SIGKILL'); } catch (error) { if (error.code !== 'ESRCH') throw error; }
}
+ // A SIGSTOP parent can retain its guardian as an unreaped zombie after the whole group exited.
+ if (![...current.values()].some(row => row.pgid === child.pid && !row.state.startsWith('Z'))) return;
try { process.kill(-child.pid, 'SIGKILL'); }
catch (error) { if (error.code !== 'ESRCH') throw error; }
}
diff --git a/test/landing-queue-fixture.js b/test/landing-queue-fixture.js
index 66cb2a20..4774bbaa 100644
--- a/test/landing-queue-fixture.js
+++ b/test/landing-queue-fixture.js
@@ -116,6 +116,13 @@ async function interruptedBranchControls(box) {
/** Resolve absent config from the repaired accepted tip; explicit direct-call config remains supported. */
async function repairedPolicyControls(box, batch) {
box.git(box.repo, 'reset', '--hard', batch.base); // Only this private fixture simulates receipts preceding local Git repair.
+ try {
+ box.git(box.repo, 'switch', '-q', '-c', 'alternate-repair');
+ await withFixtureLease(box, 'refs/heads/alternate-repair', async options => {
+ await assert.rejects(runLandingBatch(options), error => error.code === 'LAND_LEASE_LOST');
+ assert.equal(box.git(box.repo, 'rev-parse', 'HEAD'), batch.base, 'a foreign-branch recorded repair never moves Git before refusing');
+ });
+ } finally { box.git(box.repo, 'switch', '-q', 'main'); invalidateGitFacts(); }
await withFixtureLease(box, 'refs/heads/main', async options => {
const count = store.landingBatches(options.board).length;
const result = await runLandingBatch(options);
@@ -225,6 +232,8 @@ export async function landingQueueCase(t, helpers, { staleAfterFirst = false, ki
assert.equal(readBoard(box, board => store.landingBatches(board).at(-1).state), 'landed');
first.kill('SIGCONT');
assert.equal((await first.closed).code, 1, 'the resumed old holder cannot use its expired generation');
+ assert.match(first.stderrText, /\[LAND_LEASE_LOST\]/u, 'the resumed owner reports its typed authority refusal');
+ assert.doesNotMatch(first.stderrText, /Error: kill EPERM|internal\/event_target/u, 'an uncaught cleanup error is not lease fencing');
run(box, box.repo, 'land', '--max', '1');
assert.equal(readBoard(box, board => store.landingBatches(board).length), 2);
return;