From 7dfb9fb21cb56ef7873d67c3c6827bb6ebb63e01 Mon Sep 17 00:00:00 2001 From: Khaliq Date: Mon, 2 Nov 2026 22:51:55 -0800 Subject: [PATCH 1/6] fix(land): prove push access only on the stages that push Cloud now gives an auto run's write grant to stages E and F only (cloud#5944, S1 on train #5941): A-D, where an agent reviews and fixes untrusted change content, run on a read grant. The auto preflight dry-ran a push on every stage, so every auto run would have stopped needs_human at A-adversarial. The push dry-run now runs only on E and F (WRITE_STAGES); the gh auth check stays on every auto stage. Co-Authored-By: Claude Opus 5.5 --- examples/land/land.flow.ts | 22 +++++++++++++++------- examples/land/tests/flow.test.ts | 17 ++++++++++++++--- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/examples/land/land.flow.ts b/examples/land/land.flow.ts index 4569352ef..1a881b255 100644 --- a/examples/land/land.flow.ts +++ b/examples/land/land.flow.ts @@ -42,6 +42,9 @@ import { flow, type Ctx } from '@relayflows/surface'; class NeedsHuman extends Error {} +/** The stages that push in auto mode; Cloud grants contents:write to these only. */ +export const WRITE_STAGES: ReadonlySet = new Set(['E', 'F']); + export const shellWord = (value: string): string => `'${value.replaceAll("'", "'\\''")}'`; // ---------------------------------------------------------------- land.config @@ -922,15 +925,20 @@ export async function land(f: Ctx, raw: LandInput): Promise { if (uname.replace('aarch64', 'arm64') !== want) throw new NeedsHuman(`runner is ${uname}; land.config needs ${want}`); await f.run(config.runner.commands.map(c => `command -v ${shellWord(c)} >/dev/null`).join(' && ') || 'true'); if (config.mergePolicy.mode === 'auto') { - // Preflight, not polling: the GitHub gate and the push need an authed gh - // and a write-capable git credential; prove both at stage one. + // Preflight, not polling: the GitHub gate needs an authed gh on every + // auto stage (a read grant authenticates it too). const gh = await f.run(`command -v gh >/dev/null && gh auth status`, { onNonZero: 'record' }); if (!gh.ok) throw new NeedsHuman('mergePolicy.mode "auto" needs gh installed and authenticated (a write repository grant); shadow runs do not'); - // Write access is proven by dry-running a push to a fresh throwaway ref: - // a create is always a fast-forward, so an advanced base or a rebase - // pending at D/F can never turn this check into a false refusal. - const pushable = await f.run(`git push --dry-run origin HEAD:refs/heads/land-probe/${shellWord(input.runId)}-$$`, { onNonZero: 'record', timeout: '2m' }); - if (!pushable.ok) throw new NeedsHuman(`mergePolicy.mode "auto" needs a push-capable git credential (a write repository grant): ${pushable.output.slice(-300)}`); + // Only E (the gate's snapshot branch) and F (the squash) push, and Cloud + // gives only those stages a write grant: A-D, where an agent reviews and + // fixes untrusted change content, run read-only. So write access is + // proven where it is needed, by dry-running a push to a fresh throwaway + // ref: a create is always a fast-forward, so an advanced base or a + // rebase pending at F can never turn this check into a false refusal. + if (WRITE_STAGES.has(input.stage)) { + const pushable = await f.run(`git push --dry-run origin HEAD:refs/heads/land-probe/${shellWord(input.runId)}-$$`, { onNonZero: 'record', timeout: '2m' }); + if (!pushable.ok) throw new NeedsHuman(`mergePolicy.mode "auto" needs a push-capable git credential at stage ${input.stage} (a write repository grant): ${pushable.output.slice(-300)}`); + } } if (!WORKER_HARNESSES.has(config.fixLoop.harness)) { throw new NeedsHuman(`fixLoop.harness "${config.fixLoop.harness}" is not supported in land; use "codex"`); diff --git a/examples/land/tests/flow.test.ts b/examples/land/tests/flow.test.ts index e0b3c87a4..e761a418c 100644 --- a/examples/land/tests/flow.test.ts +++ b/examples/land/tests/flow.test.ts @@ -692,11 +692,22 @@ test('codex without a login in the stage sandbox ends needs_human at preflight', assert.equal(w.agents.length, 0, 'stage one stopped: no fix agent ran'); }); -test('auto: a push-denied git credential fails preflight before any stage runs', async () => { +test('auto: review and fix stages run on a read-only credential; a push-denied credential stops at E before any push', async () => { const w = world({ config: autoConfig, pushDryRunFails: true }); - const { result } = await w.drive(); + const { stages, result } = await w.drive(); + // A-D never need write access: Cloud gives them a read grant. + assert.deepEqual(stages, ['A-adversarial', 'A-context', 'B', 'D', 'E']); assert.equal(result.reason, 'needs_human'); - assert.match(JSON.stringify(result.detail), /push-capable git credential/); + assert.match(JSON.stringify(result.detail), /push-capable git credential at stage E/); + neverPushes(w.commands.map(c => c.filter(x => !x.startsWith('git push --dry-run')))); +}); + +test('auto: the push dry-run runs only on stages E and F', async () => { + const w = world({ config: autoConfig, githubExit: [0] }); + await w.drive(); + const dryRuns = w.commands.map(c => c.filter(x => x.startsWith('git push --dry-run')).length); + // One hosted run per stage A-adversarial, A-context, B, D, E, F: only the last two probe. + assert.deepEqual(dryRuns.slice(-6), [0, 0, 0, 0, 1, 1]); }); test('hosted crossed modes refuse before review, agent or push work', async () => { From a15862497dde7e99c1823eeb381257385cd9c0a5 Mon Sep 17 00:00:00 2001 From: Khaliq Date: Mon, 2 Nov 2026 22:56:26 -0800 Subject: [PATCH 2/6] fix(land): fence stage F's push on the land ref Superseding a land run means a newer push to its land ref. Stage F now pushes the squash atomically with a --force-with-lease that the land ref still points at the pinned head, so if the ref moved GitHub rejects the lease and nothing lands on the base. The run then ends cancelled as superseded instead of retrying through D. This is the write fence Cloud's cancellation cannot give on its own (cloud#5944 review): a cancelled stage's sandbox may outlive the cancel and still hold its GitHub credential, but it can no longer land. Co-Authored-By: Claude Opus 5.5 --- examples/land/land.flow.ts | 14 +++++++++++++- examples/land/tests/flow.test.ts | 29 ++++++++++++++++++++++++++--- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/examples/land/land.flow.ts b/examples/land/land.flow.ts index 1a881b255..9a1ded00e 100644 --- a/examples/land/land.flow.ts +++ b/examples/land/land.flow.ts @@ -853,7 +853,19 @@ async function merge(f: Ctx, r: Run): Promise { const ident = 'GIT_AUTHOR_NAME="${LAND_AUTHOR_NAME:-Agent Relay Land}" GIT_AUTHOR_EMAIL="${LAND_AUTHOR_EMAIL:-land@agentrelay.com}" ' + 'GIT_COMMITTER_NAME="${LAND_AUTHOR_NAME:-Agent Relay Land}" GIT_COMMITTER_EMAIL="${LAND_AUTHOR_EMAIL:-land@agentrelay.com}"'; const commit = (await f.run(`${ident} git commit-tree ${shellWord(plan.tree)} -p ${shellWord(latest)} -m ${shellWord(plan.message)}`)).trim(); - const push = await f.run(`git push origin ${shellWord(`${commit}:refs/heads/${s.config.baseBranch}`)}`, { timeout: '5m', onNonZero: 'record' }); + // Fence the push on the land ref: superseding this run means a newer push + // to its land ref, so the squash goes up atomically with a lease that the + // ref still points at the pinned head. If the ref moved, GitHub rejects the + // lease and the atomic push lands nothing on the base — however long this + // stage's sandbox outlives its cancellation. + const ref = r.input.ref; + const refspecs = [`${commit}:refs/heads/${s.config.baseBranch}`, ...(ref ? [`${s.pinnedSha}:refs/heads/${ref}`] : [])]; + const fence = ref ? ` --atomic --force-with-lease=${shellWord(`refs/heads/${ref}:${s.pinnedSha}`)}` : ''; + const push = await f.run(`git push${fence} origin ${refspecs.map(shellWord).join(' ')}`, { timeout: '5m', onNonZero: 'record' }); + if (!push.ok && ref) { + const refSha = (await f.run(`git ls-remote origin ${shellWord(`refs/heads/${ref}`)} | cut -f1`)).trim() || null; + if (refSha !== s.pinnedSha) return { kind: 'superseded', refSha, now: await now(f) }; + } if (!push.ok) { // Only an actual stale base retries through D; a permission or protected // branch rejection is permanent and escalates instead of looping. diff --git a/examples/land/tests/flow.test.ts b/examples/land/tests/flow.test.ts index e761a418c..3890ba58b 100644 --- a/examples/land/tests/flow.test.ts +++ b/examples/land/tests/flow.test.ts @@ -26,9 +26,10 @@ function world(over: { home?: string; dir?: string; /** Auto mode: the dispatched repo gate's exit per dispatch attempt; 'pending' when it overruns. */ githubExit?: Array; ghRuns?: GhRun[]; ghRunsSeq?: GhRun[][]; - pushFails?: 'non_ff' | 'other'; landedCommit?: string; headContainsBase?: boolean; fAncestorFails?: boolean; ciFetchFails?: boolean; pushDryRunFails?: boolean; codexLoginFails?: boolean; adversarialExit?: number; contextExit?: number; reviewTail?: string; + pushFails?: 'non_ff' | 'other'; landedCommit?: string; headContainsBase?: boolean; fAncestorFails?: boolean; ciFetchFails?: boolean; pushDryRunFails?: boolean; codexLoginFails?: boolean; refMovesAtPush?: string; adversarialExit?: number; contextExit?: number; reviewTail?: string; } = {}) { const dir = over.dir ?? stateDir; + let refMoved: string | undefined; const files = new Map(); const commands: string[][] = []; const launches: string[] = []; @@ -59,7 +60,7 @@ function world(over: { if (command.startsWith('git show ') && command.includes('land.config.json')) return JSON.stringify(over.config ?? config); if (command.startsWith('git show ') && command.includes('CHANGELOG.md')) return command.includes('merge-base') ? over.changelog?.[0] ?? '' : over.changelog?.[1] ?? ''; if (command.startsWith(`git fetch --no-tags --quiet ${UNSHALLOW_IF_SHALLOW} origin `)) { const list = over.baseShas ?? ['b'.repeat(40)]; baseRef = list[Math.min(fetches++, list.length - 1)]!; return ''; } - if (command.startsWith('git ls-remote')) return over.refSha ?? sha; + if (command.startsWith('git ls-remote')) return refMoved ?? over.refSha ?? sha; if (command.startsWith('git fetch --quiet ') && command.includes('land.bundle')) { head = files.get(/'([^']*land\.bundle)'/.exec(command)![1]!)!; return head; } if (command.startsWith('git bundle create')) { files.set(/'([^']*land\.bundle)\.tmp'/.exec(command)![1]!, head); return ''; } if (command.startsWith('git diff --name-only "$(git merge-base')) return 'probe/src/relay/agents.rs\nCHANGELOG.md'; @@ -101,7 +102,12 @@ function world(over: { if (command.startsWith('gh run list')) return JSON.stringify(over.ghRuns ?? []); if (command.startsWith('git push --quiet origin --delete')) return record(true); if (command.includes(' commit-tree ')) return mergedCommit; - if (command.startsWith('git push origin ') && command.includes(':refs/heads/')) { + if ((command.startsWith('git push origin ') || command.startsWith('git push --atomic ')) && command.includes(':refs/heads/')) { + if (over.refMovesAtPush && command.includes('--force-with-lease=')) { + // A newer push to the land ref landed: the lease is stale and the atomic push lands nothing. + refMoved = over.refMovesAtPush; + return record(false, ' ! [rejected] aaaaaaa -> land/khaliq/aaaaaaa (stale info)'); + } if (over.pushFails === 'non_ff') return record(false, '! [rejected] main -> main (non-fast-forward)'); if (over.pushFails === 'other') return record(false, 'error: GH006: protected branch update failed'); return record(true); @@ -702,6 +708,23 @@ test('auto: review and fix stages run on a read-only credential; a push-denied c neverPushes(w.commands.map(c => c.filter(x => !x.startsWith('git push --dry-run')))); }); +test('auto: F fences its push on the land ref, and a superseded run lands nothing', async () => { + const ref = 'land/khaliq/aaaaaaa'; + const ok = world({ config: autoConfig, githubExit: [0] }); + const { result } = await ok.drive({ ref }); + assert.equal(result.detail.state, 'landed'); + const push = ok.commands.flat().find(c => c.startsWith('git push --atomic '))!; + assert.match(push, /--force-with-lease='refs\/heads\/land\/khaliq\/aaaaaaa:a{40}'/); + assert.match(push, /:refs\/heads\/main' 'a{40}:refs\/heads\/land\/khaliq\/aaaaaaa'/); + + // A newer push to the land ref arrives while this run's F is running. + const moved = world({ config: autoConfig, githubExit: [0], refMovesAtPush: 'f'.repeat(40) }); + const out = await moved.drive({ ref }); + assert.equal(out.stages.at(-1), 'F'); + assert.equal(out.result.detail.state, 'cancelled'); + assert.match(out.result.detail.detail as string, /^superseded: land ref now f{40}/); +}); + test('auto: the push dry-run runs only on stages E and F', async () => { const w = world({ config: autoConfig, githubExit: [0] }); await w.drive(); From 4925d77a992d9c0f200722117fcf6b342025d0ea Mon Sep 17 00:00:00 2001 From: Khaliq Date: Mon, 2 Nov 2026 23:04:12 -0800 Subject: [PATCH 3/6] fix(land): fence F with an atomic delete of the land ref The #695 review (kjgbot, Greptile) showed the no-op fence checks nothing: pushing the land ref to its own value is dropped from Git's transaction as up to date, so --force-with-lease only compared the client's advertisement and a land ref moved mid-push still let the old squash land. F now deletes the land ref in the same atomic push, leased on the pinned head. A delete is a real update with an old value, checked inside the transaction, so if the ref moved the push fails and nothing lands. A replayed F that finds its own Land-Run trailer on the base reconciles as landed even though its land ref is gone. Real-Git evidence: examples/land/evidence/push-fence. Also: the read-only test covers a fix round (C-1) explicitly, and the gh preflight message no longer claims a write grant. Co-Authored-By: Claude Opus 5.5 --- examples/land/evidence/push-fence/README.md | 16 ++++++++ .../land/evidence/push-fence/fence-race.py | 38 ++++++++++++++++++ examples/land/evidence/push-fence/output.txt | 4 ++ examples/land/land.flow.ts | 23 +++++++---- examples/land/tests/flow.test.ts | 39 +++++++++++++++++-- 5 files changed, 109 insertions(+), 11 deletions(-) create mode 100644 examples/land/evidence/push-fence/README.md create mode 100644 examples/land/evidence/push-fence/fence-race.py create mode 100644 examples/land/evidence/push-fence/output.txt diff --git a/examples/land/evidence/push-fence/README.md b/examples/land/evidence/push-fence/README.md new file mode 100644 index 000000000..e5a224314 --- /dev/null +++ b/examples/land/evidence/push-fence/README.md @@ -0,0 +1,16 @@ +# Stage F push fence: real-Git evidence + +`fence-race.py` builds a bare remote and a clone in a temp directory, and adds a +`pre-receive` hook that moves `refs/heads/land/run` to a newer commit *after* +the advertisement and *before* the update: a newer submission arriving while +a superseded stage F pushes. + +- `noop`: the previous fence (`:refs/heads/land/run` with + `--force-with-lease`). Git drops the up-to-date ref from the transaction, so + the old squash lands on `main` (exit 0). This is the review finding on #695. +- `delete`: the current fence (`:refs/heads/land/run` with the lease). The + delete is a real update carrying the pinned old value, checked inside the + atomic transaction: the push fails and `main` is untouched. +- `delete`, no race: the squash lands and the land ref is deleted. + +Run: `python3 -I examples/land/evidence/push-fence/fence-race.py` (local git only). diff --git a/examples/land/evidence/push-fence/fence-race.py b/examples/land/evidence/push-fence/fence-race.py new file mode 100644 index 000000000..5dab1f6e2 --- /dev/null +++ b/examples/land/evidence/push-fence/fence-race.py @@ -0,0 +1,38 @@ +from pathlib import Path +import subprocess, tempfile, json, os, sys +SP = sys.argv[1] if len(sys.argv) > 1 else tempfile.mkdtemp(prefix="land-push-fence-") +env = os.environ.copy() +env.update({'GIT_AUTHOR_NAME':'F','GIT_AUTHOR_EMAIL':'f@example.test','GIT_COMMITTER_NAME':'F','GIT_COMMITTER_EMAIL':'f@example.test','GIT_CONFIG_GLOBAL':'/dev/null'}) +def trial(variant, race=True): + root = Path(tempfile.mkdtemp(prefix=f'fence-{variant}-', dir=SP)) + remote = root/'remote.git'; local = root/'local'; local.mkdir() + def run(*a, cwd=local, input=None): + return subprocess.check_output(['git', *a], cwd=cwd, env=env, input=input, text=True, stderr=subprocess.STDOUT).strip() + run('init', '--bare', '-q', str(remote)); run('init', '-q', '-b', 'main') + (local/'f').write_text('base\n'); run('add', '.'); run('commit', '-qm', 'base'); base = run('rev-parse', 'HEAD') + (local/'f').write_text('pinned\n'); run('commit', '-qam', 'pinned'); pinned = run('rev-parse', 'HEAD'); tree = run('rev-parse', 'HEAD^{tree}') + squash = run('commit-tree', tree, '-p', base, input='squash\n') + (local/'f').write_text('newer\n'); run('commit', '-qam', 'newer'); newer = run('rev-parse', 'HEAD') + run('remote', 'add', 'origin', str(remote)) + run('push', '-q', 'origin', f'{base}:refs/heads/main', f'{pinned}:refs/heads/land/run', f'{newer}:refs/heads/successor-source') + if race: + hook = remote/'hooks/pre-receive' + # A newer submission moves the land ref after the advertisement, before the update. + hook.write_text('#!/bin/sh\ncat > "'+str(root/'cmds.txt')+'"\nenv -u GIT_QUARANTINE_PATH -u GIT_OBJECT_DIRECTORY -u GIT_ALTERNATE_OBJECT_DIRECTORIES git --git-dir="'+str(remote)+'" update-ref refs/heads/land/run '+newer+'\n') + hook.chmod(0o755) + lease = f'--force-with-lease=refs/heads/land/run:{pinned}' + if variant == 'noop': + cmd = ['git', 'push', '--atomic', lease, 'origin', f'{squash}:refs/heads/main', f'{pinned}:refs/heads/land/run'] + else: + cmd = ['git', 'push', '--atomic', lease, 'origin', f'{squash}:refs/heads/main', ':refs/heads/land/run'] + r = subprocess.run(cmd, cwd=local, env=env, text=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + main = run('--git-dir='+str(remote), 'rev-parse', 'refs/heads/main') + land = subprocess.run(['git', '--git-dir='+str(remote), 'rev-parse', '-q', '--verify', 'refs/heads/land/run'], env=env, text=True, stdout=subprocess.PIPE).stdout.strip() + sent = (root/'cmds.txt').read_text() if (root/'cmds.txt').exists() else '' + return {'variant': variant, 'race': race, 'exit': r.returncode, 'mainGotSquash': main == squash, + 'landRefNow': 'newer' if land == newer else ('deleted' if not land else 'pinned'), + 'landRefInTransaction': 'refs/heads/land/run' in sent, 'out': r.stdout.strip().splitlines()[-1:] } +print(subprocess.check_output(['git', '--version'], text=True).strip()) +for v in ('noop', 'delete'): + print(json.dumps(trial(v, race=True))) +print(json.dumps(trial('delete', race=False))) diff --git a/examples/land/evidence/push-fence/output.txt b/examples/land/evidence/push-fence/output.txt new file mode 100644 index 000000000..85c15b799 --- /dev/null +++ b/examples/land/evidence/push-fence/output.txt @@ -0,0 +1,4 @@ +git version 2.50.1 (Apple Git-155) +{"variant": "noop", "race": true, "exit": 0, "mainGotSquash": true, "landRefNow": "newer", "landRefInTransaction": false, "out": [" 14cc825..f0936da f0936dad8edf3ac50d38af5634914da43417429b -> main"]} +{"variant": "delete", "race": true, "exit": 1, "mainGotSquash": false, "landRefNow": "newer", "landRefInTransaction": true, "out": ["error: failed to push some refs to '/var/folders/6d/0x5fkt8d01gfmmjdzkxqzwnh0000gn/T/land-push-fence-7jnjpz1x/fence-delete-5arpf79b/remote.git'"]} +{"variant": "delete", "race": false, "exit": 0, "mainGotSquash": true, "landRefNow": "deleted", "landRefInTransaction": false, "out": [" 98b3591..a3e51cc a3e51cc5fecbe02ea6adbd6b5d1525254f58aa5b -> main"]} diff --git a/examples/land/land.flow.ts b/examples/land/land.flow.ts index 9a1ded00e..01cdd4fc7 100644 --- a/examples/land/land.flow.ts +++ b/examples/land/land.flow.ts @@ -854,12 +854,15 @@ async function merge(f: Ctx, r: Run): Promise { 'GIT_COMMITTER_NAME="${LAND_AUTHOR_NAME:-Agent Relay Land}" GIT_COMMITTER_EMAIL="${LAND_AUTHOR_EMAIL:-land@agentrelay.com}"'; const commit = (await f.run(`${ident} git commit-tree ${shellWord(plan.tree)} -p ${shellWord(latest)} -m ${shellWord(plan.message)}`)).trim(); // Fence the push on the land ref: superseding this run means a newer push - // to its land ref, so the squash goes up atomically with a lease that the - // ref still points at the pinned head. If the ref moved, GitHub rejects the - // lease and the atomic push lands nothing on the base — however long this - // stage's sandbox outlives its cancellation. + // to its land ref. The squash goes up atomically with the land ref's + // deletion, leased on the pinned head. A delete is a real ref update with + // an old value, so the server checks it inside the same transaction: if + // the ref moved, the whole push fails and nothing lands on the base — + // however long this stage's sandbox outlives its cancellation. (Pushing the + // ref to its own value would be dropped as up to date and check nothing.) + // A landed run no longer needs its land ref. const ref = r.input.ref; - const refspecs = [`${commit}:refs/heads/${s.config.baseBranch}`, ...(ref ? [`${s.pinnedSha}:refs/heads/${ref}`] : [])]; + const refspecs = [`${commit}:refs/heads/${s.config.baseBranch}`, ...(ref ? [`:refs/heads/${ref}`] : [])]; const fence = ref ? ` --atomic --force-with-lease=${shellWord(`refs/heads/${ref}:${s.pinnedSha}`)}` : ''; const push = await f.run(`git push${fence} origin ${refspecs.map(shellWord).join(' ')}`, { timeout: '5m', onNonZero: 'record' }); if (!push.ok && ref) { @@ -940,7 +943,7 @@ export async function land(f: Ctx, raw: LandInput): Promise { // Preflight, not polling: the GitHub gate needs an authed gh on every // auto stage (a read grant authenticates it too). const gh = await f.run(`command -v gh >/dev/null && gh auth status`, { onNonZero: 'record' }); - if (!gh.ok) throw new NeedsHuman('mergePolicy.mode "auto" needs gh installed and authenticated (a write repository grant); shadow runs do not'); + if (!gh.ok) throw new NeedsHuman('mergePolicy.mode "auto" needs gh installed and authenticated; shadow runs do not'); // Only E (the gate's snapshot branch) and F (the squash) push, and Cloud // gives only those stages a write grant: A-D, where an agent reviews and // fixes untrusted change content, run read-only. So write access is @@ -975,7 +978,13 @@ export async function land(f: Ctx, raw: LandInput): Promise { owned = state; if (input.ref) { const refSha = (await f.run(`git ls-remote origin ${shellWord(`refs/heads/${input.ref}`)} | cut -f1`)).trim() || null; - if (refSha !== state.pinnedSha) return await save(f, stateFile, nextLandStage(state, { kind: 'superseded', refSha, now: await now(f) })); + // Stage F deletes the land ref in the same push that lands the squash, + // so a replayed F (reaped after its push, before its state write) finds + // the ref gone: its own Land-Run trailer on the base means it landed, + // and F reconciles that below rather than being called superseded. + const landedHere = refSha === null && state.cursor === 'F' && + !!(await f.run(`git log --format=%H --grep=${shellWord(`Land-Run: ${state.runId}$`)} -n 1 ${shellWord(base)}`)).trim(); + if (refSha !== state.pinnedSha && !landedHere) return await save(f, stateFile, nextLandStage(state, { kind: 'superseded', refSha, now: await now(f) })); } if (state.headSha !== state.pinnedSha) { const restored = (await f.run(`git fetch --quiet ${shellWord(`${input.stateDir}/land.bundle`)} HEAD && git checkout --quiet --detach FETCH_HEAD && git rev-parse HEAD`)).trim(); diff --git a/examples/land/tests/flow.test.ts b/examples/land/tests/flow.test.ts index 3890ba58b..2f96cafce 100644 --- a/examples/land/tests/flow.test.ts +++ b/examples/land/tests/flow.test.ts @@ -26,7 +26,7 @@ function world(over: { home?: string; dir?: string; /** Auto mode: the dispatched repo gate's exit per dispatch attempt; 'pending' when it overruns. */ githubExit?: Array; ghRuns?: GhRun[]; ghRunsSeq?: GhRun[][]; - pushFails?: 'non_ff' | 'other'; landedCommit?: string; headContainsBase?: boolean; fAncestorFails?: boolean; ciFetchFails?: boolean; pushDryRunFails?: boolean; codexLoginFails?: boolean; refMovesAtPush?: string; adversarialExit?: number; contextExit?: number; reviewTail?: string; + pushFails?: 'non_ff' | 'other'; landedCommit?: string; headContainsBase?: boolean; fAncestorFails?: boolean; ciFetchFails?: boolean; pushDryRunFails?: boolean; codexLoginFails?: boolean; refMovesAtPush?: string; refGoneAt?: string; adversarialExit?: number; contextExit?: number; reviewTail?: string; } = {}) { const dir = over.dir ?? stateDir; let refMoved: string | undefined; @@ -42,6 +42,7 @@ function world(over: { const invoke = async (stage: string, input: Partial = {}) => { const ran: string[] = []; + const goneHere = over.refGoneAt === stage; commands.push(ran); let head = over.head ?? sha; // fresh clone at the pinned sha let baseRef = ''; @@ -60,7 +61,7 @@ function world(over: { if (command.startsWith('git show ') && command.includes('land.config.json')) return JSON.stringify(over.config ?? config); if (command.startsWith('git show ') && command.includes('CHANGELOG.md')) return command.includes('merge-base') ? over.changelog?.[0] ?? '' : over.changelog?.[1] ?? ''; if (command.startsWith(`git fetch --no-tags --quiet ${UNSHALLOW_IF_SHALLOW} origin `)) { const list = over.baseShas ?? ['b'.repeat(40)]; baseRef = list[Math.min(fetches++, list.length - 1)]!; return ''; } - if (command.startsWith('git ls-remote')) return refMoved ?? over.refSha ?? sha; + if (command.startsWith('git ls-remote')) return goneHere ? '' : refMoved ?? over.refSha ?? sha; if (command.startsWith('git fetch --quiet ') && command.includes('land.bundle')) { head = files.get(/'([^']*land\.bundle)'/.exec(command)![1]!)!; return head; } if (command.startsWith('git bundle create')) { files.set(/'([^']*land\.bundle)\.tmp'/.exec(command)![1]!, head); return ''; } if (command.startsWith('git diff --name-only "$(git merge-base')) return 'probe/src/relay/agents.rs\nCHANGELOG.md'; @@ -594,6 +595,24 @@ test('auto: a stage reaped after the push records the landed commit instead of l assert.ok(!w.commands.at(-1)!.some(c => c.includes(' commit-tree ')), 'no second squash commit'); }); +test('auto: a reaped F whose push already deleted the land ref reconciles as landed, not superseded', async () => { + // F pushed (squash + land ref deletion) and was reaped before its state write. + const ref = 'land/khaliq/aaaaaaa'; + const w = world({ config: autoConfig, baseShas: ['b'.repeat(40), 'b'.repeat(40), 'b'.repeat(40), 'b'.repeat(40), 'b'.repeat(40), mergedCommit], landedCommit: mergedCommit, refGoneAt: 'F' }); + let last; + for (const stage of ['A-adversarial', 'A-context', 'B', 'D', 'E', 'E', 'F']) last = await w.invoke(stage, { ref }); + assert.equal(last!.detail.state, 'landed'); + assert.equal(last!.detail.commit, mergedCommit); +}); + +test('auto: a deleted land ref without this run\'s squash on the base is superseded', async () => { + const ref = 'land/khaliq/aaaaaaa'; + const w = world({ config: autoConfig, githubExit: [0], refGoneAt: 'F' }); + const { result } = await w.drive({ ref }); + assert.equal(result.detail.state, 'cancelled'); + assert.match(result.detail.detail as string, /^superseded: land ref now deleted/); +}); + test('auto: F refuses to squash a head that never contained the base', async () => { const w = world({ config: autoConfig, fAncestorFails: true }); let last; @@ -698,7 +717,7 @@ test('codex without a login in the stage sandbox ends needs_human at preflight', assert.equal(w.agents.length, 0, 'stage one stopped: no fix agent ran'); }); -test('auto: review and fix stages run on a read-only credential; a push-denied credential stops at E before any push', async () => { +test('auto: review stages run on a read-only credential; a push-denied credential stops at E before any push', async () => { const w = world({ config: autoConfig, pushDryRunFails: true }); const { stages, result } = await w.drive(); // A-D never need write access: Cloud gives them a read grant. @@ -715,7 +734,8 @@ test('auto: F fences its push on the land ref, and a superseded run lands nothin assert.equal(result.detail.state, 'landed'); const push = ok.commands.flat().find(c => c.startsWith('git push --atomic '))!; assert.match(push, /--force-with-lease='refs\/heads\/land\/khaliq\/aaaaaaa:a{40}'/); - assert.match(push, /:refs\/heads\/main' 'a{40}:refs\/heads\/land\/khaliq\/aaaaaaa'/); + // The land ref is deleted in the same atomic push: a real, server-checked update. + assert.match(push, /:refs\/heads\/main' ':refs\/heads\/land\/khaliq\/aaaaaaa'/); // A newer push to the land ref arrives while this run's F is running. const moved = world({ config: autoConfig, githubExit: [0], refMovesAtPush: 'f'.repeat(40) }); @@ -725,6 +745,17 @@ test('auto: F fences its push on the land ref, and a superseded run lands nothin assert.match(out.result.detail.detail as string, /^superseded: land ref now f{40}/); }); +test('auto: a fix round runs on a read-only credential and never probes for push access', async () => { + const w = world({ config: autoConfig, pushDryRunFails: true, adversarial: [[blocker('probe/src/relay/agents.rs', 'race on upload flag')], []] }); + const { stages, result } = await w.drive(); + assert.ok(stages.includes('C-1'), `fix round ran: ${stages.join(',')}`); + assert.equal(stages.at(-1), 'E'); + assert.equal(result.reason, 'needs_human'); + assert.match(JSON.stringify(result.detail), /push-capable git credential at stage E/); + const probesBeforeE = w.commands.slice(0, -1).flat().filter(c => c.startsWith('git push --dry-run')); + assert.deepEqual(probesBeforeE, [], 'no push probe in A-D or C-1'); +}); + test('auto: the push dry-run runs only on stages E and F', async () => { const w = world({ config: autoConfig, githubExit: [0] }); await w.drive(); From d7ab5d2e54f766394214800c6a6b78c046a982e9 Mon Sep 17 00:00:00 2001 From: Khaliq Date: Mon, 2 Nov 2026 23:04:23 -0800 Subject: [PATCH 4/6] docs(land): scrub a temp path from the push-fence evidence Co-Authored-By: Claude Opus 5.5 --- examples/land/evidence/push-fence/output.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/land/evidence/push-fence/output.txt b/examples/land/evidence/push-fence/output.txt index 85c15b799..a43522719 100644 --- a/examples/land/evidence/push-fence/output.txt +++ b/examples/land/evidence/push-fence/output.txt @@ -1,4 +1,4 @@ git version 2.50.1 (Apple Git-155) {"variant": "noop", "race": true, "exit": 0, "mainGotSquash": true, "landRefNow": "newer", "landRefInTransaction": false, "out": [" 14cc825..f0936da f0936dad8edf3ac50d38af5634914da43417429b -> main"]} -{"variant": "delete", "race": true, "exit": 1, "mainGotSquash": false, "landRefNow": "newer", "landRefInTransaction": true, "out": ["error: failed to push some refs to '/var/folders/6d/0x5fkt8d01gfmmjdzkxqzwnh0000gn/T/land-push-fence-7jnjpz1x/fence-delete-5arpf79b/remote.git'"]} +{"variant": "delete", "race": true, "exit": 1, "mainGotSquash": false, "landRefNow": "newer", "landRefInTransaction": true, "out": ["error: failed to push some refs to '/remote.git'"]} {"variant": "delete", "race": false, "exit": 0, "mainGotSquash": true, "landRefNow": "deleted", "landRefInTransaction": false, "out": [" 98b3591..a3e51cc a3e51cc5fecbe02ea6adbd6b5d1525254f58aa5b -> main"]} From 999d2087f248ac5df469033ba8399ea93b9a0f2b Mon Sep 17 00:00:00 2001 From: Khaliq Date: Mon, 2 Nov 2026 23:11:34 -0800 Subject: [PATCH 5/6] fix(land): a push that landed but failed on the client is recorded landed Greptile on #695: if GitHub accepts the atomic push but the connection drops before git hears back, the push exits nonzero, the land ref is already deleted, and the run was saved cancelled (superseded) for work that landed. On a failed push F now fetches the base and, if this run's Land-Run trailer is on it, records the landed commit before considering supersession. Co-Authored-By: Claude Opus 5.5 --- examples/land/land.flow.ts | 8 ++++++++ examples/land/tests/flow.test.ts | 20 +++++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/examples/land/land.flow.ts b/examples/land/land.flow.ts index 01cdd4fc7..2174cae1f 100644 --- a/examples/land/land.flow.ts +++ b/examples/land/land.flow.ts @@ -865,6 +865,14 @@ async function merge(f: Ctx, r: Run): Promise { const refspecs = [`${commit}:refs/heads/${s.config.baseBranch}`, ...(ref ? [`:refs/heads/${ref}`] : [])]; const fence = ref ? ` --atomic --force-with-lease=${shellWord(`refs/heads/${ref}:${s.pinnedSha}`)}` : ''; const push = await f.run(`git push${fence} origin ${refspecs.map(shellWord).join(' ')}`, { timeout: '5m', onNonZero: 'record' }); + if (!push.ok) { + // A push can land and still fail on the client (the connection drops + // before the server's answer arrives). This run's own Land-Run trailer on + // the fetched base means it landed: record that, never "superseded". + await f.run(`git fetch --no-tags --quiet origin ${shellWord(`+refs/heads/${s.config.baseBranch}:refs/remotes/${r.base}`)}`, { timeout: '10m', onNonZero: 'record' }); + const landed = (await f.run(`git log --format=%H --grep=${shellWord(`Land-Run: ${s.runId}$`)} -n 1 ${shellWord(r.base)}`)).trim(); + if (landed) return { kind: 'merge', outcome: 'pushed', plan, commit: landed, now: await now(f) }; + } if (!push.ok && ref) { const refSha = (await f.run(`git ls-remote origin ${shellWord(`refs/heads/${ref}`)} | cut -f1`)).trim() || null; if (refSha !== s.pinnedSha) return { kind: 'superseded', refSha, now: await now(f) }; diff --git a/examples/land/tests/flow.test.ts b/examples/land/tests/flow.test.ts index 2f96cafce..c94a21fa4 100644 --- a/examples/land/tests/flow.test.ts +++ b/examples/land/tests/flow.test.ts @@ -26,10 +26,11 @@ function world(over: { home?: string; dir?: string; /** Auto mode: the dispatched repo gate's exit per dispatch attempt; 'pending' when it overruns. */ githubExit?: Array; ghRuns?: GhRun[]; ghRunsSeq?: GhRun[][]; - pushFails?: 'non_ff' | 'other'; landedCommit?: string; headContainsBase?: boolean; fAncestorFails?: boolean; ciFetchFails?: boolean; pushDryRunFails?: boolean; codexLoginFails?: boolean; refMovesAtPush?: string; refGoneAt?: string; adversarialExit?: number; contextExit?: number; reviewTail?: string; + pushFails?: 'non_ff' | 'other'; landedCommit?: string; headContainsBase?: boolean; fAncestorFails?: boolean; ciFetchFails?: boolean; pushDryRunFails?: boolean; codexLoginFails?: boolean; refMovesAtPush?: string; refGoneAt?: string; pushLandsThenDrops?: boolean; adversarialExit?: number; contextExit?: number; reviewTail?: string; } = {}) { const dir = over.dir ?? stateDir; let refMoved: string | undefined; + let pushLanded = false; const files = new Map(); const commands: string[][] = []; const launches: string[] = []; @@ -61,7 +62,7 @@ function world(over: { if (command.startsWith('git show ') && command.includes('land.config.json')) return JSON.stringify(over.config ?? config); if (command.startsWith('git show ') && command.includes('CHANGELOG.md')) return command.includes('merge-base') ? over.changelog?.[0] ?? '' : over.changelog?.[1] ?? ''; if (command.startsWith(`git fetch --no-tags --quiet ${UNSHALLOW_IF_SHALLOW} origin `)) { const list = over.baseShas ?? ['b'.repeat(40)]; baseRef = list[Math.min(fetches++, list.length - 1)]!; return ''; } - if (command.startsWith('git ls-remote')) return goneHere ? '' : refMoved ?? over.refSha ?? sha; + if (command.startsWith('git ls-remote')) return goneHere || pushLanded ? '' : refMoved ?? over.refSha ?? sha; if (command.startsWith('git fetch --quiet ') && command.includes('land.bundle')) { head = files.get(/'([^']*land\.bundle)'/.exec(command)![1]!)!; return head; } if (command.startsWith('git bundle create')) { files.set(/'([^']*land\.bundle)\.tmp'/.exec(command)![1]!, head); return ''; } if (command.startsWith('git diff --name-only "$(git merge-base')) return 'probe/src/relay/agents.rs\nCHANGELOG.md'; @@ -96,7 +97,7 @@ function world(over: { return String(command.includes('/ci/exit') && over.ciRed?.includes(gate - 1) ? 1 : 0); } if (command.startsWith('git fetch --quiet origin ') && command.includes('refs/heads/ci/*')) return record(over.ciFetchFails !== true, over.ciFetchFails ? 'fetch failed' : ''); - if (command.startsWith('git log --format=%H --grep')) return over.landedCommit ?? ''; + if (command.startsWith('git log --format=%H --grep')) return pushLanded ? mergedCommit : over.landedCommit ?? ''; if (command.startsWith('git push --dry-run')) return record(over.pushDryRunFails !== true, over.pushDryRunFails ? 'denied' : ''); if (command.startsWith('codex login status')) return record(!over.codexLoginFails); if (command.startsWith('for sha in $(git for-each-ref')) return snapshotSha; @@ -104,6 +105,11 @@ function world(over: { if (command.startsWith('git push --quiet origin --delete')) return record(true); if (command.includes(' commit-tree ')) return mergedCommit; if ((command.startsWith('git push origin ') || command.startsWith('git push --atomic ')) && command.includes(':refs/heads/')) { + if (over.pushLandsThenDrops) { + // The server accepted the atomic push (squash landed, land ref deleted); the client never heard back. + pushLanded = true; + return record(false, 'fatal: the remote end hung up unexpectedly'); + } if (over.refMovesAtPush && command.includes('--force-with-lease=')) { // A newer push to the land ref landed: the lease is stale and the atomic push lands nothing. refMoved = over.refMovesAtPush; @@ -613,6 +619,14 @@ test('auto: a deleted land ref without this run\'s squash on the base is superse assert.match(result.detail.detail as string, /^superseded: land ref now deleted/); }); +test('auto: a push that landed but failed on the client records landed, not superseded', async () => { + const w = world({ config: autoConfig, githubExit: [0], pushLandsThenDrops: true }); + const { stages, result } = await w.drive({ ref: 'land/khaliq/aaaaaaa' }); + assert.equal(stages.at(-1), 'F'); + assert.equal(result.detail.state, 'landed'); + assert.equal(result.detail.commit, mergedCommit); +}); + test('auto: F refuses to squash a head that never contained the base', async () => { const w = world({ config: autoConfig, fAncestorFails: true }); let last; From bd2e03b2eea3cd1645d535f70eec0f805c299348 Mon Sep 17 00:00:00 2001 From: Khaliq Date: Mon, 2 Nov 2026 23:12:47 -0800 Subject: [PATCH 6/6] fix(land): reconcile a recreated land ref; document the delete permission cubic on #695: - A replayed F checks its own Land-Run trailer on the base whenever the land ref is not at the pinned head (gone, or recreated by a newer submission), not only when it is gone. - The fence deletes the land ref, so the auto write grant must allow deleting land/* branches; a dry-run push cannot prove branch rules, so this is documented in the README and the evidence README. - The evidence script captures the server's ref updates on every trial and shell-quotes the paths it writes into the hook. Co-Authored-By: Claude Opus 5.5 --- examples/land/README.md | 5 ++++- examples/land/evidence/push-fence/README.md | 7 +++++++ examples/land/evidence/push-fence/fence-race.py | 14 +++++++++----- examples/land/evidence/push-fence/output.txt | 4 ++-- examples/land/land.flow.ts | 7 ++++--- examples/land/tests/flow.test.ts | 13 +++++++++++-- 6 files changed, 37 insertions(+), 13 deletions(-) diff --git a/examples/land/README.md b/examples/land/README.md index 8637766c1..2b7adf427 100644 --- a/examples/land/README.md +++ b/examples/land/README.md @@ -179,7 +179,10 @@ the first stage. `mergePolicy.mode` values `approval` and `auto` pass validation; a run refuses `approval` (`declined`). `auto` needs the repository grant's write -token and `gh` on the runner. +token on stages E and F (Cloud gives A-D a read grant) and `gh` on the runner. +Stage F lands the squash in one atomic push that also deletes the run's land +ref, leased on the pinned head, so a superseded run can never land; the write +grant must therefore be allowed to delete `land/*` branches. A finding's id is its source, its file and its normalized title. relay-desktop's `report.json` has no id field. Its verifier moves lines and diff --git a/examples/land/evidence/push-fence/README.md b/examples/land/evidence/push-fence/README.md index e5a224314..2e6b650ad 100644 --- a/examples/land/evidence/push-fence/README.md +++ b/examples/land/evidence/push-fence/README.md @@ -14,3 +14,10 @@ a superseded stage F pushes. - `delete`, no race: the squash lands and the land ref is deleted. Run: `python3 -I examples/land/evidence/push-fence/fence-race.py` (local git only). + +## Permission the fence needs + +Stage F deletes the land ref as part of the push, so the auto write grant must +allow deleting `land/*` branches (no branch rule may block their deletion). A +`--dry-run` push cannot prove branch rules, so the preflight does not check +this; a rule that blocks it ends F `needs_human` with GitHub's rejection. diff --git a/examples/land/evidence/push-fence/fence-race.py b/examples/land/evidence/push-fence/fence-race.py index 5dab1f6e2..f0d151a52 100644 --- a/examples/land/evidence/push-fence/fence-race.py +++ b/examples/land/evidence/push-fence/fence-race.py @@ -1,5 +1,5 @@ from pathlib import Path -import subprocess, tempfile, json, os, sys +import subprocess, tempfile, json, os, sys, shlex SP = sys.argv[1] if len(sys.argv) > 1 else tempfile.mkdtemp(prefix="land-push-fence-") env = os.environ.copy() env.update({'GIT_AUTHOR_NAME':'F','GIT_AUTHOR_EMAIL':'f@example.test','GIT_COMMITTER_NAME':'F','GIT_COMMITTER_EMAIL':'f@example.test','GIT_CONFIG_GLOBAL':'/dev/null'}) @@ -15,11 +15,15 @@ def run(*a, cwd=local, input=None): (local/'f').write_text('newer\n'); run('commit', '-qam', 'newer'); newer = run('rev-parse', 'HEAD') run('remote', 'add', 'origin', str(remote)) run('push', '-q', 'origin', f'{base}:refs/heads/main', f'{pinned}:refs/heads/land/run', f'{newer}:refs/heads/successor-source') + # Capture the ref updates the server receives on every trial; with `race`, a + # newer submission also moves the land ref after the advertisement, before the update. + hook = remote/'hooks/pre-receive' + body = '#!/bin/sh\ncat > ' + shlex.quote(str(root/'cmds.txt')) + '\n' if race: - hook = remote/'hooks/pre-receive' - # A newer submission moves the land ref after the advertisement, before the update. - hook.write_text('#!/bin/sh\ncat > "'+str(root/'cmds.txt')+'"\nenv -u GIT_QUARANTINE_PATH -u GIT_OBJECT_DIRECTORY -u GIT_ALTERNATE_OBJECT_DIRECTORIES git --git-dir="'+str(remote)+'" update-ref refs/heads/land/run '+newer+'\n') - hook.chmod(0o755) + body += ('env -u GIT_QUARANTINE_PATH -u GIT_OBJECT_DIRECTORY -u GIT_ALTERNATE_OBJECT_DIRECTORIES git --git-dir=' + + shlex.quote(str(remote)) + ' update-ref refs/heads/land/run ' + newer + '\n') + hook.write_text(body) + hook.chmod(0o755) lease = f'--force-with-lease=refs/heads/land/run:{pinned}' if variant == 'noop': cmd = ['git', 'push', '--atomic', lease, 'origin', f'{squash}:refs/heads/main', f'{pinned}:refs/heads/land/run'] diff --git a/examples/land/evidence/push-fence/output.txt b/examples/land/evidence/push-fence/output.txt index a43522719..788457326 100644 --- a/examples/land/evidence/push-fence/output.txt +++ b/examples/land/evidence/push-fence/output.txt @@ -1,4 +1,4 @@ git version 2.50.1 (Apple Git-155) -{"variant": "noop", "race": true, "exit": 0, "mainGotSquash": true, "landRefNow": "newer", "landRefInTransaction": false, "out": [" 14cc825..f0936da f0936dad8edf3ac50d38af5634914da43417429b -> main"]} +{"variant": "noop", "race": true, "exit": 0, "mainGotSquash": true, "landRefNow": "newer", "landRefInTransaction": false, "out": [" 00b3772..e3d0dfa e3d0dface811192c00a495144d8824d25ac1dd36 -> main"]} {"variant": "delete", "race": true, "exit": 1, "mainGotSquash": false, "landRefNow": "newer", "landRefInTransaction": true, "out": ["error: failed to push some refs to '/remote.git'"]} -{"variant": "delete", "race": false, "exit": 0, "mainGotSquash": true, "landRefNow": "deleted", "landRefInTransaction": false, "out": [" 98b3591..a3e51cc a3e51cc5fecbe02ea6adbd6b5d1525254f58aa5b -> main"]} +{"variant": "delete", "race": false, "exit": 0, "mainGotSquash": true, "landRefNow": "deleted", "landRefInTransaction": true, "out": [" 0627171..c008e25 c008e25793dc225242ab98174f7542c40181010e -> main"]} diff --git a/examples/land/land.flow.ts b/examples/land/land.flow.ts index 2174cae1f..1d147d389 100644 --- a/examples/land/land.flow.ts +++ b/examples/land/land.flow.ts @@ -988,9 +988,10 @@ export async function land(f: Ctx, raw: LandInput): Promise { const refSha = (await f.run(`git ls-remote origin ${shellWord(`refs/heads/${input.ref}`)} | cut -f1`)).trim() || null; // Stage F deletes the land ref in the same push that lands the squash, // so a replayed F (reaped after its push, before its state write) finds - // the ref gone: its own Land-Run trailer on the base means it landed, - // and F reconciles that below rather than being called superseded. - const landedHere = refSha === null && state.cursor === 'F' && + // the ref gone, or recreated by a newer submission: its own Land-Run + // trailer on the base means it landed, and F reconciles that below + // rather than being called superseded. + const landedHere = refSha !== state.pinnedSha && state.cursor === 'F' && !!(await f.run(`git log --format=%H --grep=${shellWord(`Land-Run: ${state.runId}$`)} -n 1 ${shellWord(base)}`)).trim(); if (refSha !== state.pinnedSha && !landedHere) return await save(f, stateFile, nextLandStage(state, { kind: 'superseded', refSha, now: await now(f) })); } diff --git a/examples/land/tests/flow.test.ts b/examples/land/tests/flow.test.ts index c94a21fa4..31afdf263 100644 --- a/examples/land/tests/flow.test.ts +++ b/examples/land/tests/flow.test.ts @@ -26,7 +26,7 @@ function world(over: { home?: string; dir?: string; /** Auto mode: the dispatched repo gate's exit per dispatch attempt; 'pending' when it overruns. */ githubExit?: Array; ghRuns?: GhRun[]; ghRunsSeq?: GhRun[][]; - pushFails?: 'non_ff' | 'other'; landedCommit?: string; headContainsBase?: boolean; fAncestorFails?: boolean; ciFetchFails?: boolean; pushDryRunFails?: boolean; codexLoginFails?: boolean; refMovesAtPush?: string; refGoneAt?: string; pushLandsThenDrops?: boolean; adversarialExit?: number; contextExit?: number; reviewTail?: string; + pushFails?: 'non_ff' | 'other'; landedCommit?: string; headContainsBase?: boolean; fAncestorFails?: boolean; ciFetchFails?: boolean; pushDryRunFails?: boolean; codexLoginFails?: boolean; refMovesAtPush?: string; refGoneAt?: string; refRecreatedAt?: string; pushLandsThenDrops?: boolean; adversarialExit?: number; contextExit?: number; reviewTail?: string; } = {}) { const dir = over.dir ?? stateDir; let refMoved: string | undefined; @@ -62,7 +62,7 @@ function world(over: { if (command.startsWith('git show ') && command.includes('land.config.json')) return JSON.stringify(over.config ?? config); if (command.startsWith('git show ') && command.includes('CHANGELOG.md')) return command.includes('merge-base') ? over.changelog?.[0] ?? '' : over.changelog?.[1] ?? ''; if (command.startsWith(`git fetch --no-tags --quiet ${UNSHALLOW_IF_SHALLOW} origin `)) { const list = over.baseShas ?? ['b'.repeat(40)]; baseRef = list[Math.min(fetches++, list.length - 1)]!; return ''; } - if (command.startsWith('git ls-remote')) return goneHere || pushLanded ? '' : refMoved ?? over.refSha ?? sha; + if (command.startsWith('git ls-remote')) return goneHere || pushLanded ? '' : over.refRecreatedAt === stage ? 'f'.repeat(40) : refMoved ?? over.refSha ?? sha; if (command.startsWith('git fetch --quiet ') && command.includes('land.bundle')) { head = files.get(/'([^']*land\.bundle)'/.exec(command)![1]!)!; return head; } if (command.startsWith('git bundle create')) { files.set(/'([^']*land\.bundle)\.tmp'/.exec(command)![1]!, head); return ''; } if (command.startsWith('git diff --name-only "$(git merge-base')) return 'probe/src/relay/agents.rs\nCHANGELOG.md'; @@ -611,6 +611,15 @@ test('auto: a reaped F whose push already deleted the land ref reconciles as lan assert.equal(last!.detail.commit, mergedCommit); }); +test('auto: a reaped F whose land ref a newer submission recreated still reconciles as landed', async () => { + const ref = 'land/khaliq/aaaaaaa'; + const w = world({ config: autoConfig, baseShas: ['b'.repeat(40), 'b'.repeat(40), 'b'.repeat(40), 'b'.repeat(40), 'b'.repeat(40), mergedCommit], landedCommit: mergedCommit, refRecreatedAt: 'F' }); + let last; + for (const stage of ['A-adversarial', 'A-context', 'B', 'D', 'E', 'E', 'F']) last = await w.invoke(stage, { ref }); + assert.equal(last!.detail.state, 'landed'); + assert.equal(last!.detail.commit, mergedCommit); +}); + test('auto: a deleted land ref without this run\'s squash on the base is superseded', async () => { const ref = 'land/khaliq/aaaaaaa'; const w = world({ config: autoConfig, githubExit: [0], refGoneAt: 'F' });