sandcastle: worker worktrees and branches are never cleaned up — sweep them post-run #187
Labels
No labels
agent-blocked
agent-working
autopilot
bug
deferred
deploy-pending
enhancement
landing-pr
model-haiku
model-opus
model-sonnet
needs-design
needs-info
needs-triage
no-triage
out-of-scope
priority
ready-for-agent
ready-for-human
ready-for-session
rehearsal-183
snapshot-pending
standing-drive
wayfinder:grilling
wayfinder:map
wayfinder:prototype
wayfinder:research
wayfinder:task
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Matou/idss#187
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
What happens
Sandcastle's
branchStrategy: merge-to-head+copyToWorktree(.sandcastle/main.mts) creates a git worktree.sandcastle/worktrees/sandcastle-worker-<ts>-<id>and a branchsandcastle/worker/<ts>-<id>per iteration — and nothing ever removes them. By 2026-07-30 the swarm workdir on matou-workstation had accumulated 18 stale worktrees (2.9 GB, oldest 07-24) and 198 orphanedsandcastle/worker/*branches (every one already merged to main).Why it matters
go test ./...breaks in the workdir root:TestWireTags_AreSnakeCase(internal/wireconvention) walks the tree and skips onlynode_modules/vendor/.git— the stale checkouts contributed 1867 phantom camelCase findings. This poisoned the healer's own seam repro on 2026-07-30 (itsrepro-seam.logshowed a wireconvention FAIL that CI never sees) and will mislead any human debugging in the workdir.Manual cleanup already done (2026-07-30)
git worktree remove --forceon all 18 +git worktree prune; all 198 branches deleted with merged-only-d(none refused — no committed work dangled). Uncommitted scraps archived to~/swarm/worktree-prune-20260730.tar.gzon the workstation (superseded drafts only).wireconventiongreen in the workdir again. It will regrow from the next swarm run.The ask
run-swarm.sh(exit trap, after the harness returns): for every.sandcastle/worktrees/*not owned by the current run — the global/tmp/matou-swarm.lockflock means anything else is dead —git worktree remove --forceit,git worktree prune, and delete mergedsandcastle/worker/*branches (git branch -d, never-D: an unmerged branch is evidence of lost work and should be left + surfaced, not destroyed).TestWireTags_AreSnakeCaseto skip.sandcastle/the way it skipsnode_modules, so a future leak can't poison test runs or healer repros again.Acceptance: after a swarm run completes on the workstation,
.sandcastle/worktrees/contains no dead worktrees, no mergedsandcastle/worker/*branches remain, andnix develop -c go test ./internal/wireconvention/...passes in the workdir root.Triage result:
bug+ready-for-agentVerification: Confirmed against the current tree.
.sandcastle/run-swarm.shhas notrap/cleanup logic of any kind, and no other script in.sandcastle/removes worktrees or branches — the leak is real, not already handled.internal/wireconvention/convention_test.go's directory walk currently skips onlynode_modules,vendor, and.git— it does not skip.sandcastle/, confirming the phantom-finding mechanism described in the report. The worktrees directory and worker branches are currently clean (the reporter's manual sweep), so this is a regrowth-prevention fix, not an active-incident cleanup.This issue already carries its own acceptance criteria and a precise, scoped ask from the maintainer (numbered items 1–2, plus the
git branch -d-never--Dsafety constraint). No ambiguity requiring a human judgement call was found, so it's routed straight toready-for-agentrather thanready-for-human.Agent Brief
Category: bug
Summary: Sandcastle's per-iteration worker worktrees and branches are never cleaned up, leaking disk and poisoning
wireconvention's repo-wide scan.Current behavior:
Every Sandcastle iteration using
branchStrategy: merge-to-head+copyToWorktreecreates a git worktree under.sandcastle/worktrees/and asandcastle/worker/<ts>-<id>branch. Nothing removes either after the run. Over time this leaks disk (each worktree is a full checkout) and, becauseinternal/wireconvention's snake-case-wire-tag test walks the whole tree skipping onlynode_modules/vendor/.git, stale worktree checkouts get scanned too and can produce large numbers of phantom findings — corrupting both CI-adjacent local runs and the healer's own repro logs.Desired behavior:
After a swarm run completes (success or failure), a post-run sweep removes every worktree under
.sandcastle/worktrees/that isn't owned by the run currently holding the global swarm lock (/tmp/matou-swarm.lock), viagit worktree remove --forcefollowed bygit worktree prune. It then deletes everysandcastle/worker/*branch that is fully merged, usinggit branch -d(never-D) — an unmerged branch indicates undelivered work and must be left in place and surfaced (e.g. logged), not destroyed. The sweep must run via an exit trap (or equivalent) so it fires whether the run's harness step succeeds or fails.As defense in depth,
internal/wireconvention's tree-walking test should skip.sandcastle/the same way it already skipsnode_modules/vendor/.git, so a future leak (from this or any other tool) can't reintroduce phantom findings into that test.Key interfaces:
/tmp/matou-swarm.lockflock check) — the sweep's ownership test should reuse that same signal rather than inventing a new one.internal/wireconvention's directory-walk skip list (currentlynode_modules,vendor,.git) — add.sandcastle(or the specific.sandcastle/worktreespath, whichever keeps the test's intent — skipping non-source trees — clearest).Acceptance criteria:
.sandcastle/worktrees/contains no worktrees left over from that run.sandcastle/worker/*branch that was merged during the run remains.sandcastle/worker/*branch that is not fully merged is left untouched by the sweep (verify with a deliberately unmerged test branch) and its presence is surfaced (e.g. a log line), not silently dropped.nix develop -c go test ./internal/wireconvention/...passes in a workdir root that has a stray.sandcastle/worktrees/*checkout present (simulating a not-yet-swept leftover).Out of scope:
branchStrategy/copyToWorktreesemantics themselves./tmp/matou-swarm.lockis acquired.Done — landed as
a19b521onmain.The ask:
run-swarm.shvia an EXIT trap (new.sandcastle/sweep-lib.sh). With the global/tmp/matou-swarm.lockheld for the whole run, no other swarm is live at sweep time, so every leftover.sandcastle/worktrees/*is dead:git worktree remove --force(with anrm -rffallback for locked/odd worktrees) →git worktree prune→git branch -devery mergedsandcastle/worker/*. Unmerged branches are never-Dd — left intact and surfaced to Mattermost as possible lost work. Fires on every exit path (limit-pause, push-fail, normal).TestWireTags_AreSnakeCasenow skips.sandcastle/the way it skipsnode_modules/vendor, so a future leak cannot poison test runs or healer repros again.Evidence: offline test
.sandcastle/tests/sweep-lib-test.sh(7 groups) proves merged worktree+branch removed, unmerged branch left + surfaced, non-worker branch untouched, idempotent re-run, and non-git no-op.bash -nclean onrun-swarm.sh. (Go toolchain is unavailable in the swarm sandbox, so the wireconvention test change — a one-token.sandcastlecase addition + comment — is verified by CI in the workdir; the acceptancenix develop -c go test ./internal/wireconvention/...runs there.)grampsweb-adminswallows its own failure with|| true, sowhakapapa-brand403s on every token POST and reds the switch at exit 4 #1311grampsweb-adminswallows its own failure with|| true, sowhakapapa-brand403s on every token POST and reds the switch at exit 4 #1311grampsweb-adminswallows its own failure with|| true, sowhakapapa-brand403s on every token POST and reds the switch at exit 4 #1311whakapapa-wears-kitred on first contact: the brand PUT answered 200 with the applied keys, but the Gramps Web door serves the DEFAULT title *and* default palette — the frontend's read offrontend.*was never verified (the "deferred clan-lab driv… #1317