fix(pool): prune stale worktree registrations before add in get#1
Closed
e-jung wants to merge 2 commits into
Closed
fix(pool): prune stale worktree registrations before add in get#1e-jung wants to merge 2 commits into
e-jung wants to merge 2 commits into
Conversation
A crashed or forcibly removed worktree leaves prunable bookkeeping in .git/worktrees/. The next "treehouse get" then fails hard with "missing but already registered worktree" because git refuses the add, wedging every subsequent spawn until a human runs "git worktree prune" by hand. Run "git worktree prune" immediately before "git worktree add" in Acquire's create-new-worktree branch. Prune is safe by design: it only removes registrations whose target directories are already gone, so it cannot destroy live worktrees or data. Adds TestGetRecoversFromStaleWorktreeRegistration covering the recovery. Refs kunchenguid#30
Owner
Author
|
Closing in favor of the cross-repo PR to upstream: kunchenguid#31 (Refs kunchenguid#30). The cross-repo PR is the canonical surface for maintainer review and will run upstream CI (kunchenguid/treehouse has registered workflows; this fork's Actions workflows are not registered yet, so CI would never report here). The branch |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Intent
The developer tasked an autonomous crewmate agent with investigating whether the
treehouse getcommand is resilient to stale/prunable worktree registrations on current main (v1.7.0), building on real-world evidence that a stale git worktree entry causedtreehouse getto fail hard on v1.4.0 until a human manually rangit worktree prune. The initial scout task required reading the code path incmd/get.goandinternal/pool/, reproducing the bug deterministically in throwaway git repos under /tmp (never touching the live fleet pool), and filing a GitHub issue to kunchenguid/treehouse if the bug persisted, explicitly without opening a PR or pushing. The task was then promoted to ship: reset to clean main, branch asfix/get-prunes-stale-worktree-registrations, implement the prune-before-add fix (Option A from the report) plus an e2e test, fork e-jung/treehouse, run the no-mistakes pipeline, and open a PR referencing issue kunchenguid#30. Stated constraints included staying inside the worktree, no push/no PR during the scout phase, using gh-axi for GitHub operations, and reporting status via a one-line append to a status file.What Changed
pool.Acquirenow callsgit.PruneWorktreesbefore adding a worktree, sotreehouse getrecovers instead of failing hard with "missing but already registered worktree" when a previous worktree's directory was removed out-of-band.git.PruneWorktreeshelper and an e2e test (TestGetRecoversFromStaleWorktreeRegistration) that plants a prunable registration and assertsgetrecreates the worktree and exits 0.Risk Assessment
✅ Low: The fix is minimal and well-bounded: a single safe
git worktree prunebefore the onlyAddWorktreecall site, with correct lock placement, clear error wrapping, and a deterministic isolated e2e test.Testing
Built both the unfixed (v1.7.0) and fixed (target) treehouse binaries and reproduced the stale-worktree-registration crash scenario end-to-end in throwaway git repos under /tmp: base build wedges
treehouse getwith exit 1 and 'missing but already registered worktree', while the fixed build prunes the stale entry and enters the recreated worktree (exit 0). The added e2e test TestGetRecoversFromStaleWorktreeRegistration passes, and the fullgo test ./...suite is green. Working tree left clean.Evidence: Before/after reproduction log (base vs fixed)
########## BASE (unfixed v1.7.0) ########## [BASE-v1.7.0] running: treehouse get [BASE-v1.7.0] exit code: 1 [BASE-v1.7.0] RESULT: WEDGED - worktree not created [BASE-v1.7.0] relevant get output: failed to create worktree: ... fatal: '.../1/myrepo' is a missing but already registered worktree; ########## TARGET (fixed) ########## [TARGET-FIXED] running: treehouse get [TARGET-FIXED] exit code: 0 [TARGET-FIXED] RESULT: RECOVERED - worktree dir exists at .../1/myrepo [TARGET-FIXED] relevant get output: 🌳 Entered worktree at ~/.treehouse/myrepo-45755e/1/myrepo. Type 'exit' to return.Evidence: Reproduction script
Evidence: Regression test transcript
=== RUN TestGetRecoversFromStaleWorktreeRegistration --- PASS: TestGetRecoversFromStaleWorktreeRegistration (0.15s) PASS ok github.com/kunchenguid/treehouse/cmd 1.099sPipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
✅ **Review** - passed
✅ No issues found.
✅ **Test** - passed
✅ No issues found.
go build ./... (Go 1.26.4, go.mod requires 1.25.5)go test ./... (full suite passes)go test ./cmd/ -run TestGetRecoversFromStaleWorktreeRegistration -v (PASS)Manual e2e reproduction in throwaway /tmp git repo against base (unfixed v1.7.0) binary: planted prunable worktree registration, rantreehouse get-> exit 1, WEDGED, 'missing but already registered worktree'Manual e2e reproduction against target (fixed) binary: same prunable state, rantreehouse get-> exit 0, RECOVERED, 'Entered worktree at ...'✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.