# Every run in its own worktree (2026-11-10) ## Why Code-change runs almost never shipped. Most failures were delivery mechanics, not code: runs started from the shared checkout edited it directly, so - only one run could use a repository at a time; - the delivery gate refused because the operator's checkout had unrelated modified or untracked files (runs 257, 260), or found no linked item worktree at all (256); - the land stage, a model committing from an incomplete changed-file list, committed part of the work or stopped as blocked (268, 291, 298). ## What changed - `internal/server/run_worktree.go`: a fresh run whose workspace is a repository's main checkout gets `-runs/` on branch `pipelines/run-` from `HEAD` (a subdirectory maps to the same subdirectory). Linked worktrees and retries are used as they are. A refused or duplicate admission discards the new tree. After a successful run, a clean tree whose branch is on `main` is removed with its branch. - `internal/server/delivery_gate.go`: in a run worktree the gate commits what the land stage left uncommitted (`\n\nPipelines run N.`), so a partial file list can no longer drop work. The main checkout no longer has to be clean; `git merge --ff-only` refuses on its own, changing nothing, when a local change would be overwritten (the error says the item is checked and ready on its branch). - Tests: `run_worktree_test.go`; two diff-capture tests now start from a linked worktree, since their fake stages edit the original directory. ## Not changed - Untracked environment files (`.envrc`, `.tool-versions`) are not copied into run trees; this repository has none. - Merge conflicts with a moved main still fail the gate with the branch kept.