fix(land): prove push access only on E/F, and fence F's push on the land ref

Merged
KH
1mo ago
+216-18

Companion to cloud#5944, which fixes S1 on Cloud merge train #5941: an auto run's contents:write grant now goes to stages E (the gate's snapshot branch) and F (the squash to the base) only. A–D, where an agent reviews and fixes untrusted change content, run on a read grant.

land.flow.ts dry-ran a push on every auto stage, so with that grant every auto run would stop needs_human at A-adversarial.

  • The push dry-run now runs only when input.stage is in WRITE_STAGES (E, F). The gh auth status check stays on every auto stage (a read grant authenticates gh too).
  • The refusal names the stage: needs a push-capable git credential at stage E.

Tests

  • auto: review and fix stages run on a read-only credential; a push-denied credential stops at E before any push (replaces the old "fails preflight before any stage runs").
  • auto: the push dry-run runs only on stages E and F.
  • Mutation check: with the stage condition removed, both fail.

examples/land: npm test 91/91, npm run typecheck clean. Land-only; nothing in packages/ changes, so no release is needed. The land deployment is redeployed from the merge commit.

Fence stage F's push on the land ref

Answers the cloud#5944 review (Devin, Codex, Greptile, kjgbot) that a cancelled stage F can outlive its cancellation: Cloud writes cancelled before teardown, a provider stop failure can still return 200, and RelayAuth revocation does not revoke the GitHub credential inside the sandbox.

Superseding a land run means a newer push to its land ref. F now pushes git push --atomic --force-with-lease=refs/heads/<ref>:<pinnedSha> origin <squash>:refs/heads/<base> <pinnedSha>:refs/heads/<ref>. If the ref moved, GitHub rejects the lease and the atomic push lands nothing on the base, whatever the old sandbox still holds. The run then re-reads the ref and ends cancelled (superseded) instead of retrying through D.

Test: auto: F fences its push on the land ref, and a superseded run lands nothing (fails with the fence removed). examples/land: 92/92, typecheck clean.

🤖 Generated with Claude Code


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.


Summary by cubic

Fixes the land auto preflight and fences stage F's push so read-only review stages work and a superseded run can never land stale work.

Cloud now grants contents:write only to auto stages E (gate snapshot branch) and F (squash to base); stages A–D run on a read grant. The preflight previously dry-ran a push on every auto stage, so every auto run would stop at A-adversarial. Separately, stage F's push was unsafe: a cancelled run's sandbox can outlive the cancel and still hold its credential, so it could land after being superseded.

  • The push dry-run now runs only on WRITE_STAGES (E, F); the gh auth status check stays on every auto stage.
  • Stage F pushes atomically with --force-with-lease on the land ref, deleting the ref in the same transaction (pushing it to its own value would be dropped as up to date and check nothing), and ends the run cancelled as superseded if the ref moved instead of retrying through D.
  • If the push fails only on the client (GitHub accepted it but the connection dropped), F fetches the base and records the landed commit before considering supersession.
  • A replayed F that finds its own Land-Run trailer on the base reconciles as landed even though its land ref is gone or recreated by a newer submission.
  • The write grant must allow deleting land/* branches; a dry-run push cannot prove branch rules, so this is documented rather than preflighted.
  • The refusal message now names the stage, e.g. needs a push-capable git credential at stage E.

Tests

  • New tests assert the push dry-run runs only on E and F, that A–D (including a fix round) proceed on a read-only credential, and that a moved land ref cancels F without landing anything.
  • Additional tests cover a push that landed but failed on the client, and replayed Fs reconciling as landed with the ref gone or recreated.
  • examples/land/evidence/push-fence provides real-Git evidence that the delete-based fence blocks a moved land ref where the previous lease did not, and captures the server's ref updates on every trial.

Agent Relay sessions

  • codex session 01a19dbc · contributor · ran gh pr commands · last active 2026-11-03