From 1e088fa8a6a5c529699db2d05fc9c4b056f503cc Mon Sep 17 00:00:00 2001 From: Relayflow Lead Date: Fri, 30 Oct 2026 15:19:34 -0700 Subject: [PATCH 1/3] fix(land): deepen a shallow clone before comparing against the base Hosted runs clone the land ref shallow, so after fetching the base branch git merge-base found no common ancestor and the next git diff got an empty revision (first production land run, lr_18053aba, stage A, step run-12). Unshallow first when the checkout is shallow. Co-Authored-By: Claude Opus 5.5 --- examples/land/land.flow.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/examples/land/land.flow.ts b/examples/land/land.flow.ts index 31f54b0f8..3bb59c3d6 100644 --- a/examples/land/land.flow.ts +++ b/examples/land/land.flow.ts @@ -644,6 +644,9 @@ 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'); const base = `origin/${config.baseBranch}`; + // Hosted runs clone the land ref shallow; merge-base against the base + // needs the shared history, so a shallow checkout is deepened first. + await f.run('if [ "$(git rev-parse --is-shallow-repository)" = true ]; then git fetch --no-tags --quiet --unshallow origin; fi', { timeout: '10m' }); await f.run(`git fetch --no-tags --quiet origin ${shellWord(`+refs/heads/${config.baseBranch}:refs/remotes/${base}`)}`, { timeout: '5m' }); if (!state) { From 44d3891d955cd5c7c3b240159e5fa6ed6b6587fc Mon Sep 17 00:00:00 2001 From: Relayflow Lead Date: Fri, 30 Oct 2026 15:26:57 -0700 Subject: [PATCH 2/3] fix(land): quote the node -p expression for /bin/sh The timestamp helper ran `node -p Date.now()`; dash parses the parentheses as shell syntax ("(" unexpected), which failed the second production land run (lr_014b8872) in stage A. Co-Authored-By: Claude Opus 5.5 --- examples/land/land.flow.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/land/land.flow.ts b/examples/land/land.flow.ts index 3bb59c3d6..017d710f4 100644 --- a/examples/land/land.flow.ts +++ b/examples/land/land.flow.ts @@ -483,7 +483,7 @@ const POLL_SECONDS = 300; const LOCAL = 'git -c user.name=relay-land -c user.email=relay-land@localhost'; // sandbox-only commits; never pushed const now = async (f: Ctx): Promise => { - const raw = (await f.run('node -p Date.now()', { timeout: '5s' })).trim(); + const raw = (await f.run('node -p "Date.now()"', { timeout: '5s' })).trim(); if (!/^\d+$/.test(raw)) throw new Error('invalid journaled clock'); return Number(raw); }; From 4c8e2622ce21df78fd6c706a8eaa9ec55f13a28d Mon Sep 17 00:00:00 2001 From: Relayflow Lead Date: Fri, 30 Oct 2026 15:38:38 -0700 Subject: [PATCH 3/3] fix(land): deepen on the base fetch; update the test fake Fold the unshallow into the explicit base-refspec fetch, so a deleted land ref cannot fail a bare `git fetch origin` before the supersession check (Devin). Teach the flow test fake the new fetch and the quoted node -p (Greptile, CodeRabbit, Codex), and test the shallow switch against real clones. npm test: 59/59. Co-Authored-By: Claude Opus 5.5 --- examples/land/land.flow.ts | 12 ++++++++---- examples/land/tests/flow.test.ts | 22 +++++++++++++++++++--- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/examples/land/land.flow.ts b/examples/land/land.flow.ts index 017d710f4..da979117f 100644 --- a/examples/land/land.flow.ts +++ b/examples/land/land.flow.ts @@ -489,6 +489,9 @@ const now = async (f: Ctx): Promise => { }; /** Written to a temporary name and renamed, so a reaped run never leaves half a file. */ +/** `--unshallow` when the checkout is shallow, else nothing (POSIX sh). */ +export const UNSHALLOW_IF_SHALLOW = '$([ "$(git rev-parse --is-shallow-repository)" = true ] && echo --unshallow)'; + const writeFile = (path: string, content: string): string => `printf %s ${shellWord(Buffer.from(content, 'utf8').toString('base64'))} | base64 -d > ${shellWord(`${path}.tmp`)} && mv ${shellWord(`${path}.tmp`)} ${shellWord(path)}`; @@ -644,10 +647,11 @@ 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'); const base = `origin/${config.baseBranch}`; - // Hosted runs clone the land ref shallow; merge-base against the base - // needs the shared history, so a shallow checkout is deepened first. - await f.run('if [ "$(git rev-parse --is-shallow-repository)" = true ]; then git fetch --no-tags --quiet --unshallow origin; fi', { timeout: '10m' }); - await f.run(`git fetch --no-tags --quiet origin ${shellWord(`+refs/heads/${config.baseBranch}:refs/remotes/${base}`)}`, { timeout: '5m' }); + // Hosted runs clone the land ref shallow, and merge-base against the base + // needs the shared history: the base fetch also deepens a shallow + // checkout. It names only the base refspec, so a deleted land ref cannot + // fail it before the supersession check below. + await f.run(`git fetch --no-tags --quiet ${UNSHALLOW_IF_SHALLOW} origin ${shellWord(`+refs/heads/${config.baseBranch}:refs/remotes/${base}`)}`, { timeout: '10m' }); if (!state) { const runUrl = input.runUrl ?? `file://${stateFile}`; diff --git a/examples/land/tests/flow.test.ts b/examples/land/tests/flow.test.ts index 87dbca686..8221e4e72 100644 --- a/examples/land/tests/flow.test.ts +++ b/examples/land/tests/flow.test.ts @@ -1,7 +1,7 @@ import assert from 'node:assert/strict'; import test from 'node:test'; import type { Ctx, AgentOptions } from '@relayflows/surface'; -import { land, type LandInput } from '../land.flow.ts'; +import { land, UNSHALLOW_IF_SHALLOW, type LandInput } from '../land.flow.ts'; const sha = 'a'.repeat(40); const root = '/runs/run-1/repo'; @@ -45,12 +45,12 @@ function world(over: { if (command === "git rev-parse 'origin/main'") return baseRef; if (command === 'git status --porcelain') return ''; if (command === 'uname -sm') return 'Linux x86_64'; - if (command === 'node -p Date.now()') return String(tick += 60_000); + if (command === 'node -p "Date.now()"') return String(tick += 60_000); if (command === `printf '%s' "\${HOME:-}"`) return over.home ?? ''; if (command.startsWith('cat ') && command.includes('land-state.json')) return files.get(/^cat '([^']*)'/.exec(command)![1]!) ?? 'null'; 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 origin')) { const list = over.baseShas ?? ['b'.repeat(40)]; baseRef = list[Math.min(fetches++, list.length - 1)]!; return ''; } + 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 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 ''; } @@ -420,3 +420,19 @@ test('absolute paths: a . or .. in any segment is refused, including the first ( const w = world(); assert.match((await w.invoke('A-adversarial', { intentFile: '/../intent.md' })).detail.detail as string, /intentFile must match/); }); + +test('the base fetch deepens a shallow checkout and names only the base refspec', async () => { + // A deleted land ref must not fail the fetch before supersession: no bare + // `git fetch origin`, and the unshallow rides on the explicit base refspec. + assert.equal(UNSHALLOW_IF_SHALLOW, '$([ "$(git rev-parse --is-shallow-repository)" = true ] && echo --unshallow)'); + const { execFileSync } = await import('node:child_process'); + const { mkdtempSync } = await import('node:fs'); + const { tmpdir } = await import('node:os'); + const { join } = await import('node:path'); + const sh = (cwd: string, script: string) => execFileSync('sh', ['-c', script], { cwd, encoding: 'utf8' }).trim(); + const root = mkdtempSync(join(tmpdir(), 'land-unshallow-')); + sh(root, 'git init -q -b main src && cd src && git -c user.email=t@t -c user.name=t commit -q --allow-empty -m a && git -c user.email=t@t -c user.name=t commit -q --allow-empty -m b'); + sh(root, `git clone -q --depth 1 file://${root}/src shallow && git clone -q file://${root}/src full`); + assert.equal(sh(join(root, 'shallow'), `echo ${UNSHALLOW_IF_SHALLOW}`), '--unshallow'); + assert.equal(sh(join(root, 'full'), `echo ${UNSHALLOW_IF_SHALLOW}`), ''); +});