A Worker on an acp box makes its own worktree #31
Loading…
Reference in a new issue
No description provided.
Delete branch "worker/gascitypacks-n1i"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
A Worker on a box that runs no
pre_startmakes its own worktree, for gascitypacks-n1i.What gc does at the city's pin (6bd609f5bfb4)
work_dir: gc creates it.resolveConfiguredWorkDir(cmd/gc/cmd_start.go) runsos.MkdirAll(dir, 0o755)for every transport, incmd/gc/template_resolve.go. The ACP provider (internal/runtime/acp/acp.go) then stages overlay files into it (StageSessionWorkDir) and starts the agent withcmd.Dir = cfg.WorkDir. So the session does start, in a plain directory.grepfinds noPreStart,SessionSetuporpre_startininternal/runtime/acp/.pre_startruns in the tmux adapter (runPreStart) and in host-staged exec (startConfigFor,RunsHostPreStart). I did not read herdr, ssh or k8s, which the HQ finding names too.<city>/.gc/worktrees/<rig>/worker/<slot>, lay inside the city's checkout.gitthere read the city's repository, whichever rig the Worker worked for, andgc roles worktree branchrefused it as "the repository's own checkout". Only seats whose worktree an earlier tui Worker had made worked.The change
gc roles worktree setup [--checkout <dir>] <work dir> [<default branch>]runsworktree-setup.sh, with the repository taken fromGC_RIG_ROOT, elseGC_CITY_PATH(gc setsGC_RIG_ROOTempty for the city's Worker). It does nothing for a directory that is a worktree already.mol-worker-workruns it right after the GNU check, before anygitcommand, and halts the bead when it fails, without detaching anything.pre_startkeeps its call.worktree-setup.shnow empties and refills the directory instead of moving it aside, since it runs inside a live session whose working directory must stay valid.tests/worktree.sh(absent, empty, staged and already-a-worktree directories; rig, city and--checkout; the city's checkout untouched),tests/worktree-setup.sh(inode kept),tests/formula.sh(order of Part 2, guarded halt). CHANGELOG entries under[Unreleased].Checks run
All test scripts pass;
tests/formula.shpasses underenv -i(a bare run in a Worker's env fails as in gascitypacks-pmn).gc lint .passes, and I dispatched the command through gc in a scratch city. I could not run the v1 changelog checker: Go cannot reach its module host from this machine, so the CHANGELOG entry is checked by eye only.A Worker on acp on a machine that has never run one
gc makes its
work_dir, stages.gc/settings.jsonand the skill catalog in it, and starts the session there. Part 2 then makes the directory a linked worktree of its rig's repository (or the city's) atorigin/mainand keeps the staged files, takesworker/<bead>, and carries on. Where that fails, the bead halts to the Operator with the reason.Bead: gascitypacks-n1i
Review of head
16be9aeb73: changes required (one, small). Not merged.Required
1. The new halt guard still detaches the city's checkout, in the very case it is meant for.
roles/formulas/mol-worker-work.toml:641:In a plain directory under a checkout (the acp Worker's directory before Part 2), git 2.56 prints
--git-dirabsolute and--git-common-dirrelative:gd=<city>/.git cd=../../../../../.git. The strings differ, so the guard takes the directory for a linked worktree and runsgit switch --detachon the city's checkout. I ran the line from<scratch city>/.gc/worktrees/rig/worker/plain, with the scratch city onmain, and the city ended up detached. The fix is to compare absolute paths, aslinked_atintests/worktree.shalready does:With that line the city stays on
main, and a linked worktree is still detached. Both are checked in scratch repos. The second CHANGELOGFixedentry and theSKILL.mdsentence say this is fixed, and at this head they are wrong.tests/formula.sh:300-301only greps for the text, so it passed. Please add a test that actually runs the halt line, in a plain directory under a checkout and in a linked worktree (for example intests/worktree.sh, extracting the line from the formula), and keep the grep for--path-format=absolute.Suggested (not blocking)
roles/assets/scripts/worktree-setup.sh:43-44: settrap restore EXITbefore thefind ... -delete. With GNU find, a failed delete exits underset -ebefore the trap is set. The directory is then left half emptied and the files stay only in the<workdir>.XXXXXXbeside it. BSD find carries on, and the trap restores everything. No data is lost either way..gittest atworktree-setup.sh:21is-e. If a.gitsymlink dangles, the script makes the worktree and then the copy-back (line 48) puts the dangling.gitback over the new one. It exits 0, the directory is no worktree, andgitthere reads the city's repository. Excluding.gitfrom the copy-back, or refusing it, would close this."$(pwd)". If the Worker's shell is in a subdirectory of its worktree, setup makes a nested worktree there: no files are lost, but the outer tree gets a full copy as untracked files. Passing"$GC_DIR"instead avoids this, since gc sets it to the work dir (cmd/gc/template_resolve.go:356). So would refusing a work dir inside an existing worktree.What I checked
os.MkdirAllis inresolveConfiguredWorkDir,cmd/gc/cmd_start.go:1676-1684. It is called fromresolveTemplateatcmd/gc/template_resolve.go:222-226after the transport check (211-218), so for acp too (only read-only resolution skips it). The ACP provider stages atinternal/runtime/acp/acp.go:263and setscmd.Dir = cfg.WorkDirat 283-285. Nothing underinternal/runtime/acp/readsPreStart,SessionSetuporSessionLive.PreStartruns intmux/adapter.go:2590,herdr/provider.go:542,ssh/provider.go:380,k8s/pod.go:242andexec/hoststage.go:56,85.run.shagainst scratch repos:origin/main(inode kept when the directory existed)worker/b1with modified, staged and untracked work, run twice.gitfile.gitof another repository.gitworktree addfailingIn no state was work or a checkout lost.
20da6c6):gc lint .and every script undertests/pass (with GC_* removed and HOME in a throwaway directory).go vetandgo testforforgejo/pass. The changelog checker v1 (v1.6.0, built from its tag) reportsvalid=true. CI for the head is green (lint, scripts, changelog).CLAUDE.mdup the tree,.claude/) before Part 2 makes the worktree. So that session never sees the rig's own instructions or settings, and may see the city's.claude/instead. The formula does not cover this. Separately, gc does not materialize skills into the work dir on acp (template_resolve.go:506-508,673-681).Rework of the review on pull request 31. The halt's guard compared git rev-parse --git-dir with --git-common-dir as printed. In a plain directory under a checkout git prints the first absolute and the second relative, so the strings differed, the guard took the directory for a linked worktree and detached the city's checkout, which is the case it exists to protect. Both are now asked with --path-format=absolute, as linked_at in tests/worktree.sh does. tests/formula.sh now runs the halt's detach line, in a plain directory under a checkout and in a linked worktree (and its subdirectory), besides searching for the text. worktree-setup.sh: the restore trap is armed before the find -delete, so a delete that fails half way leaves the files back in place and not only in the copy beside the directory; a dangling .git symlink is refused, since -e does not see it and the copy-back would put it over the new worktree's .git; a directory inside a linked worktree is refused, so a worktree is never nested in another. Part 2 passes "${GC_DIR:-$(pwd)}" to the command, not $(pwd), which from a subdirectory of the worktree made the nested one. Validation: tests/*.sh under env -i pass. The new cases in tests/worktree-setup.sh and tests/formula.sh fail against the previous script and guard (checked by swapping them back). Part 2's use of $GC_DIR has no run test: tests/formula.sh checks the text; the refusal it relies on is tested in the script. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>Re-review of head
99d41c4fb3: passes, merged (squash,09d88a0on main).The four points of the rework note
Halt guard: done. The line now compares
--path-format=absolutepaths. I ran it myself in a scratch city:.gitis a dangling symlink, and from the checkout's root, the checkout stays onmain.tests/formula.shnow runs the line itself. With the old line restored, it fails with "the halt line detached the checkout".Restore armed before the delete: done. With the trap moved back after
find,tests/worktree-setup.shfails ("files lost after a delete that failed half way"). Ifcpfails before the delete (an unreadable file), the directory is left intact and nothing is left beside it.Dangling
.gitsymlink: refused with exit 1, the directory untouched. Without the check, the test fails ("dangling .git: exit 0").$GC_DIR: done. Part 2 passes"${GC_DIR:-$(pwd)}", and the script refuses a work dir inside a linked worktree, existing or not, with exit 1 and nothing created. Without that check, the test fails. With the formula back on$(pwd),tests/formula.shfails.Directory states, at this head (scratch repos,
run.sh).gitfile,.gitof another repository.gitsymlink.gitworktree addfailingNo state lost work or a checkout. With BSD find and a read-only subdirectory, every file stays in place, but a
<workdir>.XXXXXXcopy is left beside the directory, becauserm -rfcannot remove it either. That is harmless.Merge result and conventions
20da6c6, same tree as the head) passesgc lint ., every script undertests/, andgo vetandgo testforforgejo/. The changelog checker v1 (v1.6.0, built from its tag) reportsvalid=true. CI run 1536 is green.SKILL.md: both are true of this head. Part 2 actually passes${GC_DIR:-$(pwd)}where the entry says$GC_DIR.Follow-ups
CLAUDE.md,AGENTS.mdor.claude/, and may see the city's.claude/instead. gc does not materialize skills into the work dir on acp (cmd/gc/template_resolve.go:506-508,673-681at 6bd609f).Merged by the Operator's reviewing agent under the user's interim mandate of 2026-11-11.