Skip to content

fix(pool): let prune and destroy reclaim worktrees from other clones in a shared pool - #146

Merged
kunchenguid merged 17 commits into
kunchenguid:mainfrom
MrGTV-love:fm/treehouse-shared-pool-reclaim-foreign-slots-v2
Sep 24, 2026
Merged

kunchenguid merged 17 commits into
kunchenguid:mainfrom
MrGTV-love:fm/treehouse-shared-pool-reclaim-foreign-slots-v2

Conversation

@MrGTV-love

@MrGTV-love MrGTV-love commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Intent

The captain said, "Proceed with the fix for item 6." Item 6 was this: a shared worktree pool can hold slots belonging to two different clones, and neither clone can clean up the slots owned by the other. treehouse destroy and treehouse prune both fail on those foreign slots, leaking pool capacity so no operator can reclaim it from either clone. The captain accepted the recommended small remedy, scored R4 Q4 A5 E4 S4 at high confidence, because the code already has the per-path fallback needed and the current failure mode safely refuses and deletes nothing. The accepted boundary is a small separate fix scoped to reclaiming foreign slots, not a pool redesign. The evidence was that resolvePoolRepoRoot in internal/pool/destroy.go chose the repository root of the first non-orphaned target and applied it to every worktree, while the clone-identity change makes a shared pool containing slots from two clones routine. With one slot from clone A and one from clone B, destroy used root A to remove the B slot and Git refused it; prune had the same pool-wide-root shape through singleRepoPruneContextResolver and RemoveCleanWorktree. Both paths refused rather than deleting, so the defect was unreclaimable capacity rather than corruption. The existing per-path vcs.FindMainRepoRootFrom fallback in destroy was the intended small remedy. The separate clone-identity change published elsewhere was explicitly not part of this work. The captain later said, "push, pr, merge, pull, reap," and then "rebase."

What Changed

  • destroy now finds the owning repository and default ref for each worktree from that worktree's own VCS metadata. It no longer uses one root, taken from the first target, for the whole pool. This applies to planning, to the re-check under the state lock, and to removal (resolvePoolRepoRoot now takes one WorktreeEntry; removeManagedWorktree loses its repoRoot parameter). A markerless slot (a slot whose .git/.jj marker is gone) gets an empty context. So destroy never resolves or fetches a repository that encloses the pool, and the slot stays unverified.
  • Repo-scoped prune now uses the same per-worktree resolver as global prune, so singleRepoPruneContextResolver no longer applies the caller's root to every slot. worktreePruneContextResolver now keeps the resolved root when the fetch or default-ref lookup fails. The empty default ref keeps that slot unverified.
  • Tests: new tests show that destroy and prune remove worktrees from two different clones in one shared pool. Other new tests cover a per-path refusal for a worktree whose repository cannot be found, a root kept after a failed fetch, and a markerless destroy target that does not fetch the enclosing repository. AGENTS.md and README.md now say that prune and destroy resolve each worktree's own repository, so either clone can reclaim the other clone's slots.

Risk Assessment

✅ Low: The change is small and matches the reclaim-only intent: prune and destroy now find the repository root per worktree (with a cache per root), removal no longer reuses one pool-wide root, markerless and failed-resolution slots still fail closed, the clone-identity acquire code is absent from the diff, and the new tests check real behavior.

Testing

I built the real treehouse binary at c42ced0 and at base 1185dc6. I ran six CLI scenarios in isolated temp HOMEs. Each scenario used a local bare remote and two same-origin clones that share one pool. On the base build, destroy and prune reproduced the bug: git refused to remove clone B's clean slot. On the new build, both commands remove the clean slots from both clones, from inside a repo and in global prune. The fail-closed guards still work on the new build. Dirty, unmerged, and leased foreign slots are kept until the user gives the opt-in flag. A slot whose origin cannot be reached is refused. A markerless slot is refused, and destroy runs no fetch for it. Every scenario passed. The transcripts and the driver scripts are in the evidence directory. The real-jj paths are not tested, because jj is not installed on this machine.

  • Live validation: ✅ go - 7 of 8 scenarios driven live against the product
Scenario Result Live Evidence
From clone A, destroy <shared-pool> --all --yes removes clean slots from clone A and clone B ✅ pass live s1-destroy-all-two-clones-NEW.txt reports 'Destroyed 2 worktrees', the pool is empty, and clone B's git worktree list shows no slot. On the base build (s1-...-BASE.txt), clone B's slot was skipped w…
From clone A, repo-scoped prune --yes removes clean merged slots from both clones ✅ pass live s2-prune-two-clones-NEW.txt reports 'Pruned 2 stale worktrees' (slots 1 and 2). On the base build (s2-...-BASE.txt), it pruned 1 slot and reported 'remove failed: VCS refused to remove worktree' for c…
Prune from clone A keeps clone B's dirty, unmerged, and leased slots ✅ pass live s2-prune-two-clones-NEW.txt: the dirty slot is kept and dirty.txt is still there. The unmerged slot is kept, and its commit is judged against clone B's origin/main. The leased slot is kept.
Destroy from clone A refuses clone B's unsafe slots until the user gives the opt-in flag, and then removes them through clone B's own repo ✅ pass live s3-destroy-guards-foreign-clone-NEW.txt: a bare --all --yes destroyed 0 and skipped the dirty, unmerged, and leased slots with the correct hints. --include-unlanded removed the dirty and unmerged…
Global prune --all --yes from outside any repository removes slots from both clones ✅ pass live s4-global-prune-two-clones-NEW.txt reports 'Pruned 2 stale worktrees across 1 pool'. Neither clone lists a slot after the run.
Adversarial: clone B's origin cannot be reached and one slot has no marker. Prune and destroy delete neither slot. ✅ pass live s5-failclosed-unreachable-origin-and-markerless-NEW.txt: prune removed only clone A's clean slot. It skipped B's slot ('cannot fetch origin') and the damaged slot. destroy --all --yes destroyed 0 an…
Adversarial: a markerless slot in an in-project pool does not use the enclosing clone. It is reported unverified, and the user can remove it only with --include-unlanded. ✅ pass live s6-inproject-markerless-destroy-NEW.txt: --all --yes skipped the slot as [unverified] and made 0 git fetch calls (GIT_TRACE). --include-unlanded removed only the slot directory, and clone A stayed…
A jj-flavored slot in a shared pool, with the fetch failing, shows the 'destroy it and migrate the pool' hint ⏸️ untested no The jj binary is not on PATH on this machine, and workspace rules do not allow me to install it. Install jj (for example brew install jj) and re-run the pipeline to drive this path live.
Evidence: Destroy --all --yes, two clones, new build (both slots destroyed)
clone A slot: /tmp/th-e2e.Khgj/s1new/home/.treehouse/repo-4d7bde/1/repo
clone B slot: /tmp/th-e2e.Khgj/s1new/home/.treehouse/repo-4d7bde/2/repo
A slot common dir: /private/tmp/th-e2e.Khgj/s1new/a/repo/.git
B slot common dir: /private/tmp/th-e2e.Khgj/s1new/b/repo/.git
$ /tmp/th-e2e.Khgj/treehouse-new return /tmp/th-e2e.Khgj/s1new/home/.treehouse/repo-4d7bde/1/repo
🌳 Worktree returned to pool.
[exit 0]
$ /tmp/th-e2e.Khgj/treehouse-new return /tmp/th-e2e.Khgj/s1new/home/.treehouse/repo-4d7bde/2/repo
🌳 Worktree returned to pool.
[exit 0]
$ /tmp/th-e2e.Khgj/treehouse-new status
base  main  (repository default)
1     available    ~/.treehouse/repo-4d7bde/1/repo  (detached)
2     available    ~/.treehouse/repo-4d7bde/2/repo  (detached)
[exit 0]
$ /tmp/th-e2e.Khgj/treehouse-new destroy /tmp/th-e2e.Khgj/s1new/home/.treehouse/repo-4d7bde --all
🌳 Dry run: would destroy 2 worktrees in ~/.treehouse/repo-4d7bde and reclaim 586 B.
  1     [disposable]  293 B  ~/.treehouse/repo-4d7bde/1/repo
  2     [disposable]  293 B  ~/.treehouse/repo-4d7bde/2/repo
🌳 Re-run with --yes to destroy this worktrees.
[exit 0]
$ /tmp/th-e2e.Khgj/treehouse-new destroy /tmp/th-e2e.Khgj/s1new/home/.treehouse/repo-4d7bde --all --yes
🌳 Destroyed 2 worktrees in ~/.treehouse/repo-4d7bde and freed 586 B.
  1     [disposable]  293 B  ~/.treehouse/repo-4d7bde/1/repo
  2     [disposable]  293 B  ~/.treehouse/repo-4d7bde/2/repo
[exit 0]
--- after destroy, run from clone A ---
$ /tmp/th-e2e.Khgj/treehouse-new status
base  main  (repository default)
🌳 No worktrees in pool.
[exit 0]
slot dirs on disk:
treehouse-state.json
treehouse-state.key
treehouse-state.lock
clone B worktree list:
/private/tmp/th-e2e.Khgj/s1new/b/repo  4477615 [main]
clone A worktree list:
/private/tmp/th-e2e.Khgj/s1new/a/repo  4477615 [main]
Evidence: Destroy --all --yes, two clones, base build (bug reproduced: 'is not a working tree')
clone A slot: /tmp/th-e2e.Khgj/s1base/home/.treehouse/repo-dc64c9/1/repo
clone B slot: /tmp/th-e2e.Khgj/s1base/home/.treehouse/repo-dc64c9/2/repo
A slot common dir: /private/tmp/th-e2e.Khgj/s1base/a/repo/.git
B slot common dir: /private/tmp/th-e2e.Khgj/s1base/b/repo/.git
$ /tmp/th-e2e.Khgj/treehouse-base return /tmp/th-e2e.Khgj/s1base/home/.treehouse/repo-dc64c9/1/repo
🌳 Worktree returned to pool.
[exit 0]
$ /tmp/th-e2e.Khgj/treehouse-base return /tmp/th-e2e.Khgj/s1base/home/.treehouse/repo-dc64c9/2/repo
🌳 Worktree returned to pool.
[exit 0]
$ /tmp/th-e2e.Khgj/treehouse-base status
base  main  (repository default)
1     available    ~/.treehouse/repo-dc64c9/1/repo  (detached)
2     available    ~/.treehouse/repo-dc64c9/2/repo  (detached)
[exit 0]
$ /tmp/th-e2e.Khgj/treehouse-base destroy /tmp/th-e2e.Khgj/s1base/home/.treehouse/repo-dc64c9 --all
🌳 Dry run: would destroy 2 worktrees in ~/.treehouse/repo-dc64c9 and reclaim 588 B.
  1     [disposable]  294 B  ~/.treehouse/repo-dc64c9/1/repo
  2     [disposable]  294 B  ~/.treehouse/repo-dc64c9/2/repo
🌳 Re-run with --yes to destroy this worktrees.
[exit 0]
$ /tmp/th-e2e.Khgj/treehouse-base destroy /tmp/th-e2e.Khgj/s1base/home/.treehouse/repo-dc64c9 --all --yes
🌳 Destroyed 1 worktree in ~/.treehouse/repo-dc64c9 and freed 294 B.
  1     [disposable]  294 B  ~/.treehouse/repo-dc64c9/1/repo
🌳 Skipped 1 worktree:
  2     [disposable]  ~/.treehouse/repo-dc64c9/2/repo  VCS refused to remove worktree: git worktree remove --force /tmp/th-e2e.Khgj/s1base/home/.treehouse/repo-dc64c9/2/repo: fatal: '/tmp/th-e2e.Khgj/s1base/home/.treehouse/repo-dc64c9/2/repo' is not a working tree
[exit 0]
--- after destroy, run from clone A ---
$ /tmp/th-e2e.Khgj/treehouse-base status
base  main  (repository default)
2     available    ~/.treehouse/repo-dc64c9/2/repo  (detached)
[exit 0]
slot dirs on disk:
2
treehouse-state.json
treehouse-state.key
treehouse-state.lock
clone B worktree list:
/private/tmp/th-e2e.Khgj/s1base/b/repo                              a3ce255 [main]
/private/tmp/th-e2e.Khgj/s1base/home/.treehouse/repo-dc64c9/2/repo  a3ce255 (detached HEAD)
clone A worktree list:
/private/tmp/th-e2e.Khgj/s1base/a/repo  a3ce255 [main]
Evidence: Repo-scoped prune --yes, two clones, new build
A clean: /tmp/th-e2e.Khgj/s2new/home/.treehouse/repo-3afcf3/1/repo
B clean: /tmp/th-e2e.Khgj/s2new/home/.treehouse/repo-3afcf3/2/repo
B dirty: /tmp/th-e2e.Khgj/s2new/home/.treehouse/repo-3afcf3/3/repo
B unmerged: /tmp/th-e2e.Khgj/s2new/home/.treehouse/repo-3afcf3/4/repo
B still leased: /tmp/th-e2e.Khgj/s2new/home/.treehouse/repo-3afcf3/5/repo
$ /tmp/th-e2e.Khgj/treehouse-new status
base  main  (repository default)
1     available    ~/.treehouse/repo-3afcf3/1/repo  (detached)
2     available    ~/.treehouse/repo-3afcf3/2/repo  (detached)
3     dirty        ~/.treehouse/repo-3afcf3/3/repo  (detached)
4     available    ~/.treehouse/repo-3afcf3/4/repo  (detached)
5     leased       ~/.treehouse/repo-3afcf3/5/repo  (detached)
[exit 0]
$ /tmp/th-e2e.Khgj/treehouse-new prune
🌳 Dry run: would prune 2 stale worktrees and reclaim 586 B.
1     293 B  ~/.treehouse/repo-3afcf3/1/repo
2     293 B  ~/.treehouse/repo-3afcf3/2/repo
🌳 Skipped 2 unsafe idle worktrees:
  uncommitted changes:
  3     ~/.treehouse/repo-3afcf3/3/repo
  unmerged:
  4     HEAD not merged into refs/remotes/origin/main  ~/.treehouse/repo-3afcf3/4/repo
🌳 Re-run with --yes to delete these worktrees.
[exit 0]
$ /tmp/th-e2e.Khgj/treehouse-new prune --yes
🌳 Pruned 2 stale worktrees and freed 586 B.
1     293 B  ~/.treehouse/repo-3afcf3/1/repo
2     293 B  ~/.treehouse/repo-3afcf3/2/repo
🌳 Skipped 2 unsafe idle worktrees:
  uncommitted changes:
  3     ~/.treehouse/repo-3afcf3/3/repo
  unmerged:
  4     HEAD not merged into refs/remotes/origin/main  ~/.treehouse/repo-3afcf3/4/repo
[exit 0]
--- after prune ---
$ /tmp/th-e2e.Khgj/treehouse-new status
base  main  (repository default)
3     dirty        ~/.treehouse/repo-3afcf3/3/repo  (detached)
4     available    ~/.treehouse/repo-3afcf3/4/repo  (detached)
5     leased       ~/.treehouse/repo-3afcf3/5/repo  (detached)
[exit 0]
B dirty file kept: dirty work
B unmerged commit kept: unmerged work
clone B worktree list:
/private/tmp/th-e2e.Khgj/s2new/b/repo                              9ecafef [main]
/private/tmp/th-e2e.Khgj/s2new/home/.treehouse/repo-3afcf3/3/repo  9ecafef (detached HEAD)
/private/tmp/th-e2e.Khgj/s2new/home/.treehouse/repo-3afcf3/4/repo  14024be (detached HEAD)
/private/tmp/th-e2e.Khgj/s2new/home/.treehouse/repo-3afcf3/5/repo  9ecafef (detached HEAD)
clone A worktree list:
/private/tmp/th-e2e.Khgj/s2new/a/repo  9ecafef [main]
Evidence: Repo-scoped prune --yes, two clones, base build (bug reproduced: 'VCS refused to remove worktree')
A clean: /tmp/th-e2e.Khgj/s2base/home/.treehouse/repo-4fe8f3/1/repo
B clean: /tmp/th-e2e.Khgj/s2base/home/.treehouse/repo-4fe8f3/2/repo
B dirty: /tmp/th-e2e.Khgj/s2base/home/.treehouse/repo-4fe8f3/3/repo
B unmerged: /tmp/th-e2e.Khgj/s2base/home/.treehouse/repo-4fe8f3/4/repo
B still leased: /tmp/th-e2e.Khgj/s2base/home/.treehouse/repo-4fe8f3/5/repo
$ /tmp/th-e2e.Khgj/treehouse-base status
base  main  (repository default)
1     available    ~/.treehouse/repo-4fe8f3/1/repo  (detached)
2     available    ~/.treehouse/repo-4fe8f3/2/repo  (detached)
3     dirty        ~/.treehouse/repo-4fe8f3/3/repo  (detached)
4     available    ~/.treehouse/repo-4fe8f3/4/repo  (detached)
5     leased       ~/.treehouse/repo-4fe8f3/5/repo  (detached)
[exit 0]
$ /tmp/th-e2e.Khgj/treehouse-base prune
🌳 Dry run: would prune 2 stale worktrees and reclaim 588 B.
1     294 B  ~/.treehouse/repo-4fe8f3/1/repo
2     294 B  ~/.treehouse/repo-4fe8f3/2/repo
🌳 Skipped 2 unsafe idle worktrees:
  uncommitted changes:
  3     ~/.treehouse/repo-4fe8f3/3/repo
  unmerged:
  4     HEAD not merged into refs/remotes/origin/main  ~/.treehouse/repo-4fe8f3/4/repo
🌳 Re-run with --yes to delete these worktrees.
[exit 0]
$ /tmp/th-e2e.Khgj/treehouse-base prune --yes
🌳 Pruned 1 stale worktree and freed 294 B.
1     294 B  ~/.treehouse/repo-4fe8f3/1/repo
🌳 Skipped 3 unsafe idle worktrees:
  uncommitted changes:
  3     ~/.treehouse/repo-4fe8f3/3/repo
  unmerged:
  4     HEAD not merged into refs/remotes/origin/main  ~/.treehouse/repo-4fe8f3/4/repo
  remove failed:
  2     VCS refused to remove worktree  ~/.treehouse/repo-4fe8f3/2/repo
[exit 0]
--- after prune ---
$ /tmp/th-e2e.Khgj/treehouse-base status
base  main  (repository default)
2     available    ~/.treehouse/repo-4fe8f3/2/repo  (detached)
3     dirty        ~/.treehouse/repo-4fe8f3/3/repo  (detached)
4     available    ~/.treehouse/repo-4fe8f3/4/repo  (detached)
5     leased       ~/.treehouse/repo-4fe8f3/5/repo  (detached)
[exit 0]
B dirty file kept: dirty work
B unmerged commit kept: unmerged work
clone B worktree list:
/private/tmp/th-e2e.Khgj/s2base/b/repo                              13f928c [main]
/private/tmp/th-e2e.Khgj/s2base/home/.treehouse/repo-4fe8f3/2/repo  13f928c (detached HEAD)
/private/tmp/th-e2e.Khgj/s2base/home/.treehouse/repo-4fe8f3/3/repo  13f928c (detached HEAD)
/private/tmp/th-e2e.Khgj/s2base/home/.treehouse/repo-4fe8f3/4/repo  d7dd792 (detached HEAD)
/private/tmp/th-e2e.Khgj/s2base/home/.treehouse/repo-4fe8f3/5/repo  13f928c (detached HEAD)
clone A worktree list:
/private/tmp/th-e2e.Khgj/s2base/a/repo  13f928c [main]
Evidence: Destroy guards on foreign dirty/unmerged/leased slots
$ /tmp/th-e2e.Khgj/treehouse-new status
base  main  (repository default)
1     dirty        ~/.treehouse/repo-5641e2/1/repo  (detached)
2     available    ~/.treehouse/repo-5641e2/2/repo  (detached)
3     leased       ~/.treehouse/repo-5641e2/3/repo  (detached)
[exit 0]
$ /tmp/th-e2e.Khgj/treehouse-new destroy /tmp/th-e2e.Khgj/s3new/home/.treehouse/repo-5641e2 --all --yes
🌳 Destroyed 0 worktrees in ~/.treehouse/repo-5641e2.
🌳 Skipped 3 worktrees:
  1     [dirty]     ~/.treehouse/repo-5641e2/1/repo  re-run with --include-unlanded to include
  3     [leased]    ~/.treehouse/repo-5641e2/3/repo  leased: name the exact path with --include-leased (never removed by --all)
  2     [unmerged]  ~/.treehouse/repo-5641e2/2/repo  re-run with --include-unlanded to include
[exit 0]
B dirty file kept: dirty work
B unmerged commit kept: unmerged work
$ /tmp/th-e2e.Khgj/treehouse-new destroy /tmp/th-e2e.Khgj/s3new/home/.treehouse/repo-5641e2 --all --include-unlanded --yes
🌳 Destroyed 2 worktrees in ~/.treehouse/repo-5641e2 and freed 664 B.
  1     [dirty]     336 B  ~/.treehouse/repo-5641e2/1/repo  (uncommitted changes)
  2     [unmerged]  328 B  ~/.treehouse/repo-5641e2/2/repo  (HEAD not merged into refs/remotes/origin/main)
🌳 Skipped 1 worktree:
  3     [leased]  ~/.treehouse/repo-5641e2/3/repo  leased: name the exact path with --include-leased (never removed by --all)
[exit 0]
$ /tmp/th-e2e.Khgj/treehouse-new destroy /tmp/th-e2e.Khgj/s3new/home/.treehouse/repo-5641e2/3/repo --include-leased --yes
🌳 Destroyed 1 worktree in ~/.treehouse/repo-5641e2/3/repo and freed 294 B.
  3     [leased]  294 B  ~/.treehouse/repo-5641e2/3/repo
[exit 0]
--- after opt-in destroys ---
$ /tmp/th-e2e.Khgj/treehouse-new status
base  main  (repository default)
🌳 No worktrees in pool.
[exit 0]
clone B worktree list:
/private/tmp/th-e2e.Khgj/s3new/b/repo  59bd86c [main]
Evidence: Global prune --all --yes outside any repo
cwd: /tmp/th-e2e.Khgj/s4new/elsewhere (not a repository: fatal: not a git repository (or any of the parent directories): .git)
$ /tmp/th-e2e.Khgj/treehouse-new prune --all --yes
🌳 Pruned 2 stale worktrees across 1 pool and freed 586 B.
1     293 B  ~/.treehouse/repo-e262bf/1/repo
2     293 B  ~/.treehouse/repo-e262bf/2/repo
[exit 0]
clone A worktree list:
/private/tmp/th-e2e.Khgj/s4new/a/repo  0cb18df [main]
clone B worktree list:
/private/tmp/th-e2e.Khgj/s4new/b/repo  0cb18df [main]
Evidence: Fail-closed: unreachable foreign origin + markerless slot
damaged slot has marker: 0
$ /tmp/th-e2e.Khgj/treehouse-new status
base  main  (repository default)
1     available    ~/.treehouse/repo-62d406/1/repo  (detached)
2     damaged      ~/.treehouse/repo-62d406/2/repo  (no .git or .jj marker — 'treehouse destroy ~/.treehouse/repo-62d406/2/repo --include-unlanded' to remove)
3     available    ~/.treehouse/repo-62d406/3/repo  (detached)
[exit 0]
$ /tmp/th-e2e.Khgj/treehouse-new prune --yes
🌳 Pruned 1 stale worktree and freed 293 B.
1     293 B  ~/.treehouse/repo-62d406/1/repo
🌳 Skipped 2 unsafe idle worktrees:
  origin unreachable (cannot verify):
  3     cannot fetch origin  ~/.treehouse/repo-62d406/3/repo
  cannot verify worktree:
  2     no .git or .jj marker  ~/.treehouse/repo-62d406/2/repo
[exit 0]
$ /tmp/th-e2e.Khgj/treehouse-new destroy /tmp/th-e2e.Khgj/s5new/home/.treehouse/repo-62d406 --all --yes
🌳 Destroyed 0 worktrees in ~/.treehouse/repo-62d406.
🌳 Skipped 2 worktrees:
  2     [unverified]  ~/.treehouse/repo-62d406/2/repo  re-run with --include-unlanded to include
  3     [unverified]  ~/.treehouse/repo-62d406/3/repo  re-run with --include-unlanded to include
[exit 0]
--- after ---
$ /tmp/th-e2e.Khgj/treehouse-new status
base  main  (repository default)
2     damaged      ~/.treehouse/repo-62d406/2/repo  (no .git or .jj marker — 'treehouse destroy ~/.treehouse/repo-62d406/2/repo --include-unlanded' to remove)
3     available    ~/.treehouse/repo-62d406/3/repo  (detached)
[exit 0]
clone B slot still on disk: yes
damaged slot still on disk: yes
clone B worktree list:
/private/tmp/th-e2e.Khgj/s5new/b/repo                              782e729 [main]
/private/tmp/th-e2e.Khgj/s5new/home/.treehouse/repo-62d406/3/repo  782e729 (detached HEAD)
Evidence: In-project pool markerless slot: no fetch, unverified, opt-in removal
damaged slot: /private/tmp/th-e2e.Khgj/s6new/a/repo/.treehouse/repo-6a498f/1/repo
$ /tmp/th-e2e.Khgj/treehouse-new --root . destroy /private/tmp/th-e2e.Khgj/s6new/a/repo/.treehouse/repo-6a498f --all --yes
🌳 Destroyed 0 worktrees in /private/tmp/th-e2e.Khgj/s6new/a/repo/.treehouse/repo-6a498f.
🌳 Skipped 1 worktree:
  1     [unverified]  /private/tmp/th-e2e.Khgj/s6new/a/repo/.treehouse/repo-6a498f/1/repo  re-run with --include-unlanded to include
[exit 0]
git fetch calls during destroy: 0
$ /tmp/th-e2e.Khgj/treehouse-new --root . destroy /private/tmp/th-e2e.Khgj/s6new/a/repo/.treehouse/repo-6a498f/1/repo --include-unlanded --yes
🌳 Destroyed 1 worktree in /private/tmp/th-e2e.Khgj/s6new/a/repo/.treehouse/repo-6a498f/1/repo and freed 195 B.
  1     [unverified]  195 B  /private/tmp/th-e2e.Khgj/s6new/a/repo/.treehouse/repo-6a498f/1/repo  (no .git or .jj marker: contents cannot be verified)
[exit 0]
damaged slot still on disk: no
clone A README intact: hi
!! .treehouse/
Evidence: Scenario driver scripts
#!/bin/bash
# usage: setup.sh <scenario-dir>  -> creates remote.git, a/repo, b/repo, isolated HOME
set -e
S=$1; rm -rf "$S"; mkdir -p "$S/home"
export HOME="$S/home" GIT_CONFIG_NOSYSTEM=1
git config --global user.email [email protected]; git config --global user.name T; git config --global init.defaultBranch main
git init -q --bare "$S/remote.git"
git clone -q "$S/remote.git" "$S/seed" 2>/dev/null
( cd "$S/seed" && echo hi > README && git add README && git commit -qm init && git push -q origin main )
mkdir -p "$S/a" "$S/b"
git clone -q "$S/remote.git" "$S/a/repo"
git clone -q "$S/remote.git" "$S/b/repo"

Pipeline

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.

  • Live validation: ✅ go - 7 of 8 scenarios driven live against the product
Scenario Result Live Evidence
From clone A, destroy &lt;shared-pool&gt; --all --yes removes clean slots from clone A and clone B ✅ pass live s1-destroy-all-two-clones-NEW.txt reports 'Destroyed 2 worktrees', the pool is empty, and clone B's git worktree list shows no slot. On the base build (s1-...-BASE.txt), clone B's slot was skipped w…
From clone A, repo-scoped prune --yes removes clean merged slots from both clones ✅ pass live s2-prune-two-clones-NEW.txt reports 'Pruned 2 stale worktrees' (slots 1 and 2). On the base build (s2-...-BASE.txt), it pruned 1 slot and reported 'remove failed: VCS refused to remove worktree' for c…
Prune from clone A keeps clone B's dirty, unmerged, and leased slots ✅ pass live s2-prune-two-clones-NEW.txt: the dirty slot is kept and dirty.txt is still there. The unmerged slot is kept, and its commit is judged against clone B's origin/main. The leased slot is kept.
Destroy from clone A refuses clone B's unsafe slots until the user gives the opt-in flag, and then removes them through clone B's own repo ✅ pass live s3-destroy-guards-foreign-clone-NEW.txt: a bare --all --yes destroyed 0 and skipped the dirty, unmerged, and leased slots with the correct hints. --include-unlanded removed the dirty and unmerged…
Global prune --all --yes from outside any repository removes slots from both clones ✅ pass live s4-global-prune-two-clones-NEW.txt reports 'Pruned 2 stale worktrees across 1 pool'. Neither clone lists a slot after the run.
Adversarial: clone B's origin cannot be reached and one slot has no marker. Prune and destroy delete neither slot. ✅ pass live s5-failclosed-unreachable-origin-and-markerless-NEW.txt: prune removed only clone A's clean slot. It skipped B's slot ('cannot fetch origin') and the damaged slot. destroy --all --yes destroyed 0 an…
Adversarial: a markerless slot in an in-project pool does not use the enclosing clone. It is reported unverified, and the user can remove it only with --include-unlanded. ✅ pass live s6-inproject-markerless-destroy-NEW.txt: --all --yes skipped the slot as [unverified] and made 0 git fetch calls (GIT_TRACE). --include-unlanded removed only the slot directory, and clone A stayed…
A jj-flavored slot in a shared pool, with the fetch failing, shows the 'destroy it and migrate the pool' hint ⏸️ untested no The jj binary is not on PATH on this machine, and workspace rules do not allow me to install it. Install jj (for example brew install jj) and re-run the pipeline to drive this path live.
  • Built go build -o treehouse-new . at c42ced0 and treehouse-base from git archive 1185dc6. Both went to a temp dir that I deleted after the run.
  • s1_destroy.sh: two same-origin clones. Each clone ran get --lease and then return. Then destroy &lt;pool&gt; --all and destroy &lt;pool&gt; --all --yes ran from clone A. I did this with the new build and with the base build.
  • s2_prune.sh: from clone A, prune and prune --yes ran on a pool with these slots: clean slot from A, clean slot from B, dirty slot from B, unmerged slot from B, leased slot from B. I did this with the new build and with the base build.
  • s3_destroy_guard.sh: from clone A, destroy &lt;pool&gt; --all --yes ran on B's dirty, unmerged, and leased slots. Then --all --include-unlanded --yes ran. Then destroy &lt;path&gt; --include-leased --yes ran.
  • s4_global.sh: prune --all --yes ran from a directory that is not a repository.
  • s5_failclosed.sh: clone B's origin was set to a missing path, and one slot had no .git marker. Then prune --yes and destroy &lt;pool&gt; --all --yes ran from clone A.
  • s6_inproject_markerless.sh: an in-project pool (--root .) held a markerless slot. destroy --all --yes ran with GIT_TRACE on, to count fetch calls. Then destroy &lt;path&gt; --include-unlanded --yes ran.
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

Compare physical Git common directories before resetting or acquiring a
shared-pool slot. Resolve the requester once, normalize symlinks, and
leave foreign or unreadable candidates intact. Explain foreign-clone
capacity exhaustion without misreporting clean slots as dirty or busy.

Apply the comparison symmetrically: an unsupported empty identity only
matches another empty identity. Preserve non-colocated JJ reuse, including
its existing unidentified-clone sharing, without adding a JJ identity
mechanism. Git and colocated JJ require matching physical identities.

Keep pool locations, state, trust checks, and cleanup behavior unchanged.
Cover both acquire modes, capacity, symlinks, unreadable candidates,
existing-state return, and colocated/non-colocated JJ combinations.
Compare physical Git common directories before resetting or acquiring a
shared-pool slot. Resolve the requester once, normalize symlinks, and
leave foreign or unreadable candidates intact. Explain foreign-clone
capacity exhaustion without misreporting clean slots as dirty or busy.

Apply the comparison symmetrically: an unsupported empty identity only
matches another empty identity. Preserve non-colocated JJ reuse, including
its existing unidentified-clone sharing, without adding a JJ identity
mechanism. Git and colocated JJ require matching physical identities.

Keep pool locations, state, trust checks, and cleanup behavior unchanged.
Cover both acquire modes, capacity, symlinks, unreadable candidates,
existing-state return, and colocated/non-colocated JJ combinations.
Resolve cleanup context and VCS removal ownership from each managed
worktree path so shared pools can prune and destroy slots from multiple
clones while unresolved paths remain untouched and reported.
@greptile-apps

greptile-apps Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

The PR appears safe to merge; the cleanup paths resolve ownership per worktree and continue to preserve unverifiable targets.

Reviews (7) · Last reviewed commit: "fix(pool): avoid resolving markerless de..."

Comment thread internal/pool/pool.go Resolved
Comment thread internal/pool/destroy.go Resolved
…. What I changed: 1. internal/pool/prune.go, `worktreePruneContextResolver`: when fetch or default-ref resolution fails, it now returns `pruneContext{RepoRoot: repoRoot}` with the error. It used to return an empty context. The cached-error path does the same thing now. DefaultRef stays empty. 2. internal/pool/destroy.go:214: I updated the comment. It now says that a failure leaves the default ref empty. 3. internal/pool/pool_test.go: I added `TestWorktreePruneContextResolverKeepsRootWhenFetchFails`. It points origin at a missing path and calls the resolver two times. The second call reads the cached error. Each call must return an error, the resolved root, and an empty DefaultRef. Effect: `classifyForDestroy` gets the root again, so it can set `OtherFlavor` and show the "destroy it and migrate the pool" hint. With an empty DefaultRef the slot is still `DestroyUnverified`, so deletion is still refused. Prune does not change: at prune.go:704 it throws away the context when there is an error. No new resolver or abstraction was added. Checks I ran: - Without the fix, the new test fails (`got RepoRoot:""`). With the fix, it passes. - `go test ./... -count=1`: all packages pass. - `go vet ./internal/pool/` passes. `gofmt -l` finds nothing. `GOOS=windows go build ./...` passes. I did not commit the changes. They are in the working tree

@kunchenguid kunchenguid left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Speaking as Kun's firstmate: first-time fork review — no security risk in the diff (per-worktree prune/destroy reclaim stays fail-closed; dirty/unmerged/orphan guards remain). Approving so required checks can run. Not a merge vote.

Greptile still blocks merge: P1 says this branch also carries the out-of-scope clone-identity acquire change (Intent was reclaim-only). Please either land clone-identity via #145 first and rebase this to reclaim-only, or get an explicit captain word that the combined form is accepted. Waiting on that and green CI — this is waiting on the author, not a captain-decision hold.

Note: #145 overlaps the acquire half of this branch; we will not merge both.

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: triage stamp.

VISION per-rule (tip d230166 vs main 02d9f5c):

  • Isolation and reuse: aligns for the acquire half (same clone-identity as fix(pool): reuse a pooled worktree only for the clone that owns it #145). The reclaim half does not change acquire isolation further.
  • Safe lifecycle operations: aligns. destroy/prune now resolve each slot's owning repo from that slot's path (worktreePruneContextResolver), so a shared pool's foreign slots can be reclaimed instead of leaking on Git refusal. Dirty, unmerged, orphan, and unverifiable slots still refuse delete (live transcripts in the PR body). Dry-run / --yes unchanged. Broad cleanup stays pool-scoped.
  • Ownership and interface: aligns. Per-path skip reasons remain; OtherFlavor hint preserved when root is known but fetch fails (Greptile P2 addressed in d230166).
  • Scope and evaluation: aligns. Same CLI primitive; two-clone pool tests cover reuse, prune, destroy.

contract-class=restore for reclaim (destroy/prune of a named pool already promised those slots; the broken path was a Git refusal that leaked capacity). The bundled acquire change is the same restore as #145. Combined form is still blocked by Greptile P1 (Intent was reclaim-only) — not auto-merge ready.

Fork CI approved this pass. Waiting on the author to split or get captain word on the combined form, plus green CI. Overlaps #145; we will not merge both. This is waiting on the author, not a captain-decision hold.

…mitted for the executor. I did not push, and I did not touch the PR. 1. Windows CI failure (TestAcquire_CloneIdentityCapacity, pool_test.go:128). The cause was in the test only. Git on Windows checks README out as "hi\r\n", and the test compared it with the literal "hi\n". The test now reads the README bytes BEFORE the rejected foreign acquisition and compares them AFTER. The two new jj tests that compared with the same literal get the same snapshot change: TestAcquireSkipsUnresolvableColocatedJJIdentity and TestAcquireSecondNonColocatedJJCloneRefusedForeignWorkspace. Product behaviour does not change. Proof: with core.autocrlf=true (set through the GIT_CONFIG_COUNT env), the old test fails with the exact CI message ("hi\r\n") for leased=false and leased=true. The new test passes under the same setting. 2. Greptile finding at pool.go:461 (it is a real finding, not a service failure). The code compared clone identity as path strings (candidateDir != commonDir). On a case-insensitive filesystem, one physical clone spelled with different letter case read as "another clone", so the clone could not reuse its own slot. Fix: acquisitionCommonGitDir now returns os.Stat(vcs.CommonGitDir(dir)), and the selector compares with os.SameFile. os.Stat follows symlinks, so symlink aliases still resolve to one identity. The filepath.Abs and EvalSymlinks steps are now redundant, so I removed them. The requester identity is still computed once, outside the loop. Any identity error on either side still means skip (unverifiedClone). Capacity messages are the same. Non-colocated jj still gets no reuse. Nothing is lowercased. The jj test failure messages now print the identity with %v. New regression: TestAcquire_CloneIdentityCaseAlias covers ordinary and durable (lease) acquisition. It rewrites the slot's commondir to an upper-cased spelling and asks as both repo and REPO. It skips only when os.Stat plus os.SameFile shows the filesystem is case-sensitive. Before the fix, both subtests failed on macOS with "1 belong to another clone". After the fix, both pass. The symlink alias, distinct-clone and unreadable-candidate tests still pass. Docs: I made one-line accuracy updates to AGENTS.md (the identity uses os.SameFile, not a string compare) and to the README Clone-correct reuse line (differently cased paths on a case-insensitive filesystem count as one clone). Validation, all local on macOS: - Native go build ./... and go vet ./... pass. - GOOS=windows go build ./... and go vet ./... pass. - Full go test ./... -count=1 passes with the real jj on PATH. All jj clone-identity tests ran; none skipped. No prune/destroy/trust-check changes. No cleanup changes. No new jj identity mechanism
… no-mistakes" (run 35838744065) ended as action_required with zero jobs, so no step ran and nothing failed. The other runs on the same PR head 2a00a9a are in the same state: "CI" (35838743988) and "Nix flake" (35838744043) are both action_required with no jobs. That is GitHub holding workflow runs on a PR from a fork until a maintainer approves them. The new pipeline push created these runs, and none has been approved yet. The local HEAD equals the PR head, so the runs point at the current code but have not executed it. This failure is outside the code under review. Action for the outer executor or owner: a kunchenguid/treehouse maintainer must click "Approve and run workflows" on PR kunchenguid#145. The .gitignore and .ignore changes in the working tree are local graft-cache artifacts and must not be committed
…gnore to base content and deleted .ignore, which does not exist on base. PR diff vs base is now exactly AGENTS.md, README.md, internal/pool/clone_identity_jj_test.go, internal/pool/pool.go, internal/pool/pool_test.go. graft/ stays ignored by the repo-local info/exclude. No product or test changes. go build and internal/pool tests pass. CI, Nix flake and Require no-mistakes are action_required with 0 jobs: they wait for a maintainer to approve fork workflow runs on kunchenguid#145. No code fault
# Conflicts:
#	AGENTS.md
#	README.md
#	internal/pool/clone_identity_jj_test.go
#	internal/pool/pool.go
#	internal/pool/pool_test.go
…. The changes are left uncommitted in the working tree so the executor can make one forward commit. I did no rebase, reset, amend or force-push, and I did not push. What I removed (clone-identity work from PR 145): 1. internal/pool/pool.go: restored to the base version (38f8192). This removes acquisitionCommonGitDir, the otherClone/unverifiedClone skip in acquire, and the clone-identity capacity error. The reclaim commits never changed pool.go. 2. internal/pool/clone_identity_jj_test.go: deleted (git rm). It held only clone-identity jj acquire tests. 3. internal/pool/pool_test.go: removed assertCloneCommonDir, TestAcquire_CloneIdentity, TestAcquire_CloneIdentityCapacity, TestAcquire_CloneIdentitySymlinkAlias, TestAcquire_CloneIdentityCaseAlias, TestAcquire_CloneIdentityUnreadableCandidate and TestRelease_CloneIdentityExistingState. Also removed the vcs import, which nothing else uses. 4. AGENTS.md: the "Acquire reuses a slot only when..." line is back to the base text. 5. README.md: the reuse flow diagram is back to the base text, and the "Clone-correct reuse" bullet is gone. What I kept (reclaim work): - The per-worktree root resolution in destroy.go and prune.go, and the fix that keeps the root when fetch fails. - Their tests: TestDestroyPoolRemovesWorktreesOwnedByDifferentClones, TestDestroyPoolRefusesUnattributableWorktreePerPath, TestPruneRemovesWorktreesOwnedByDifferentClones, TestWorktreePruneContextResolverKeepsRootWhenFetchFails, and the updated executeDestroy tests. - Their docs: the AGENTS.md prune/destroy line and the README prune/destroy paragraphs. - The shared test helper setupSharedClonePool, because the reclaim tests need it. I changed only its comment. acquireDisposableFromEachClone does not need clone identity: clone B gets a new slot because clone A's slot is still reserved. The diff against base 38f8192 now touches only AGENTS.md, README.md, internal/pool/destroy.go, internal/pool/prune.go, internal/pool/pool_test.go and internal/pool/worktree_path_test.go. .gitignore and .ignore are not in it. The separation was clean, with no conflicts. Checks run on macOS: - go build ./... passed. - go vet ./... passed. - GOOS=windows go build ./... and GOOS=windows go vet ./... passed. - gofmt -l printed nothing. - go test ./... -count=1 passed in every package. - All reclaim tests ran and passed (verbose run). Gap: I could not run the real-jj tests. jj is not on PATH on this machine, and the workspace rules do not let me install it, so 23 jj tests skipped. The jj tests I deleted covered clone identity only. No jj code path changed in this round

@kunchenguid kunchenguid left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Speaking as Kun's firstmate: re-review on tip 4b3dec9 (not a merge vote).

VISION per-rule (vs main 02d9f5c):

  • Isolation and reuse: aligns. This tip no longer changes acquire; reclaim only.
  • Safe lifecycle operations: aligns. destroy/prune resolve each managed path's owning repo via worktreePruneContextResolver; foreign clean/merged/idle slots in a shared pool can be reclaimed instead of leaking on Git refusal. Dirty/unmerged/orphan/unattributable stay refused. Dry-run/--yes unchanged. Greptile P2 (keep root when fetch fails for OtherFlavor hint) is in this tip.
  • Ownership and interface: aligns. Per-path skip reasons retained.
  • Scope and evaluation: aligns. Local CLI pool correctness; two-clone reclaim tests retained; clone-identity acquire removed from this PR (lives in #145).

contract-class=restore (named-pool destroy/prune already promised reclaim of those slots; broken path was unreclaimable capacity).

Newer activity since last stamp: author split clone-identity out. Greptile now 5/5 / "safe to merge" with the Intent P1 cleared. Fork CI re-approved this pass. Still waiting on green CI; tip is behind main by 1 — will update-branch / rebase only once otherwise auto-merge-ready. Prefer merging #145 separately; this PR no longer bundles acquire.

Keep reclaim helpers from this branch and clone-identity tests from main.
Leave fork workflow files unchanged.

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: conflict resolve after #145 merged.

Merged origin/main into this branch on tip dbc6cb8 (maintainer push). Only conflict was internal/pool/pool_test.go — kept reclaim helpers here and clone-identity tests from main. Fork .github/workflows/* left unchanged. Local go test ./internal/pool passed. Waiting on green CI, then auto-merge (contract=restore, Greptile was 5/5 pre-resolve; will re-check).

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: conflict resolve tip dbc6cb8 is blocked on Require no-mistakes — attestation still binds to 4b3dec9, not the new head. Please re-drive git push no-mistakes / no-mistakes rerun so the PR-body attestation matches dbc6cb8 (or the tip after your re-run). Product conflict resolve is done; this is the attestation gate only. Waiting on that — not a captain-decision hold.

Keep the PR diff scoped to foreign-slot reclaim by restoring the
kunchenguid exemption already present on upstream main.
Keep damaged slots out of per-path repository resolution so destroy cannot
fetch an unrelated repository enclosing the pool. Restore real Git removal
refusal coverage for state and owner-reservation recovery.

@kunchenguid kunchenguid left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Speaking as Kun's firstmate: re-approve on tip c42ced0e (merge vote).

VISION per-rule (tip c42ced0e vs main 1185dc6):

  • Isolation and reuse: aligns — reclaim only; no acquire/reuse change (clone-identity already on main via #145).
  • Safe lifecycle operations: aligns — destroy/prune resolve each managed path via worktreePruneContextResolver / per-slot resolvePoolRepoRoot; markerless slots stay out of configured-backend resolution (resolveDestroyContext); dirty/unmerged/orphan/unattributable still refused; dry-run/--yes unchanged.
  • Ownership and interface: aligns — per-path skip reasons retained; foreign clean slots reclaimable instead of silent capacity leak.
  • Scope and evaluation: aligns — local CLI pool reclaim correctness; two-clone live transcripts in the PR body.

contract-class=restore (named-pool destroy/prune already promised reclaim of those slots; broken path was unreclaimable capacity from pool-wide root). Greptile 5/5 on this tip; CI + no-mistakes green; CLEAN vs main. Proceeding to squash-merge.

@kunchenguid
kunchenguid merged commit 94c092f into kunchenguid:main Sep 24, 2026
7 checks passed
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: this is merged. Thank you @MrGTV-love — really appreciate you taking the time on this.

MrGTV-love added a commit to MrGTV-love/treehouse that referenced this pull request Oct 6, 2026
* ci: pin require-no-mistakes to v1.80.1 for live PR lookup (kunchenguid#144)

* ci: pin require-no-mistakes to v1.80.1 for live PR lookup

The v1.80.1 verifier reads body and head from one API response and
fails closed without pull-requests: read, so drop the Fetch current
PR body step and its cached event-payload inputs.

* test: lock v1.80.1 live PR lookup on the required-check caller

A pin-only assertion stayed green if the workflow restored cached
PR inputs, restored the fetch step, or dropped pull-requests: read.

* ci: exempt kunchenguid from no-mistakes-required gate (kunchenguid#147)

* fix(pool): reuse a pooled worktree only for the clone that owns it (kunchenguid#145)

* fix(pool): enforce clone identity when reusing Git worktrees

Compare physical Git common directories before resetting or acquiring a
shared-pool slot. Resolve the requester once, normalize symlinks, and
leave foreign or unreadable candidates intact. Explain foreign-clone
capacity exhaustion without misreporting clean slots as dirty or busy.

Apply the comparison symmetrically: an unsupported empty identity only
matches another empty identity. Preserve non-colocated JJ reuse, including
its existing unidentified-clone sharing, without adding a JJ identity
mechanism. Git and colocated JJ require matching physical identities.

Keep pool locations, state, trust checks, and cleanup behavior unchanged.
Cover both acquire modes, capacity, symlinks, unreadable candidates,
existing-state return, and colocated/non-colocated JJ combinations.

* no-mistakes(review): Refuse worktree reuse when clone identity cannot be verified

* no-mistakes(document): Document clone-correct worktree reuse in README and AGENTS

* no-mistakes(ci): Fixed both real failures. The changes are left uncommitted for the executor. I did not push, and I did not touch the PR. 1. Windows CI failure (TestAcquire_CloneIdentityCapacity, pool_test.go:128). The cause was in the test only. Git on Windows checks README out as "hi\r\n", and the test compared it with the literal "hi\n". The test now reads the README bytes BEFORE the rejected foreign acquisition and compares them AFTER. The two new jj tests that compared with the same literal get the same snapshot change: TestAcquireSkipsUnresolvableColocatedJJIdentity and TestAcquireSecondNonColocatedJJCloneRefusedForeignWorkspace. Product behaviour does not change. Proof: with core.autocrlf=true (set through the GIT_CONFIG_COUNT env), the old test fails with the exact CI message ("hi\r\n") for leased=false and leased=true. The new test passes under the same setting. 2. Greptile finding at pool.go:461 (it is a real finding, not a service failure). The code compared clone identity as path strings (candidateDir != commonDir). On a case-insensitive filesystem, one physical clone spelled with different letter case read as "another clone", so the clone could not reuse its own slot. Fix: acquisitionCommonGitDir now returns os.Stat(vcs.CommonGitDir(dir)), and the selector compares with os.SameFile. os.Stat follows symlinks, so symlink aliases still resolve to one identity. The filepath.Abs and EvalSymlinks steps are now redundant, so I removed them. The requester identity is still computed once, outside the loop. Any identity error on either side still means skip (unverifiedClone). Capacity messages are the same. Non-colocated jj still gets no reuse. Nothing is lowercased. The jj test failure messages now print the identity with %v. New regression: TestAcquire_CloneIdentityCaseAlias covers ordinary and durable (lease) acquisition. It rewrites the slot's commondir to an upper-cased spelling and asks as both repo and REPO. It skips only when os.Stat plus os.SameFile shows the filesystem is case-sensitive. Before the fix, both subtests failed on macOS with "1 belong to another clone". After the fix, both pass. The symlink alias, distinct-clone and unreadable-candidate tests still pass. Docs: I made one-line accuracy updates to AGENTS.md (the identity uses os.SameFile, not a string compare) and to the README Clone-correct reuse line (differently cased paths on a case-insensitive filesystem count as one clone). Validation, all local on macOS: - Native go build ./... and go vet ./... pass. - GOOS=windows go build ./... and go vet ./... pass. - Full go test ./... -count=1 passes with the real jj on PATH. All jj clone-identity tests ran; none skipped. No prune/destroy/trust-check changes. No cleanup changes. No new jj identity mechanism

* no-mistakes(ci): No code change is needed. The failing check "Require no-mistakes" (run 35838744065) ended as action_required with zero jobs, so no step ran and nothing failed. The other runs on the same PR head 2a00a9a are in the same state: "CI" (35838743988) and "Nix flake" (35838744043) are both action_required with no jobs. That is GitHub holding workflow runs on a PR from a fork until a maintainer approves them. The new pipeline push created these runs, and none has been approved yet. The local HEAD equals the PR head, so the runs point at the current code but have not executed it. This failure is outside the code under review. Action for the outer executor or owner: a kunchenguid/treehouse maintainer must click "Approve and run workflows" on PR kunchenguid#145. The .gitignore and .ignore changes in the working tree are local graft-cache artifacts and must not be committed

* no-mistakes(ci): Removed stray graft ignore artifacts: restored .gitignore to base content and deleted .ignore, which does not exist on base. PR diff vs base is now exactly AGENTS.md, README.md, internal/pool/clone_identity_jj_test.go, internal/pool/pool.go, internal/pool/pool_test.go. graft/ stays ignored by the repo-local info/exclude. No product or test changes. go build and internal/pool tests pass. CI, Nix flake and Require no-mistakes are action_required with 0 jobs: they wait for a maintainer to approve fork workflow runs on kunchenguid#145. No code fault

* fix(pool): let prune and destroy reclaim worktrees from other clones in a shared pool (kunchenguid#146)

* fix(pool): enforce clone identity when reusing Git worktrees

Compare physical Git common directories before resetting or acquiring a
shared-pool slot. Resolve the requester once, normalize symlinks, and
leave foreign or unreadable candidates intact. Explain foreign-clone
capacity exhaustion without misreporting clean slots as dirty or busy.

Apply the comparison symmetrically: an unsupported empty identity only
matches another empty identity. Preserve non-colocated JJ reuse, including
its existing unidentified-clone sharing, without adding a JJ identity
mechanism. Git and colocated JJ require matching physical identities.

Keep pool locations, state, trust checks, and cleanup behavior unchanged.
Cover both acquire modes, capacity, symlinks, unreadable candidates,
existing-state return, and colocated/non-colocated JJ combinations.

* no-mistakes(review): Refuse worktree reuse when clone identity cannot be verified

* no-mistakes(document): Document clone-correct worktree reuse in README and AGENTS

* fix(pool): enforce clone identity when reusing Git worktrees

Compare physical Git common directories before resetting or acquiring a
shared-pool slot. Resolve the requester once, normalize symlinks, and
leave foreign or unreadable candidates intact. Explain foreign-clone
capacity exhaustion without misreporting clean slots as dirty or busy.

Apply the comparison symmetrically: an unsupported empty identity only
matches another empty identity. Preserve non-colocated JJ reuse, including
its existing unidentified-clone sharing, without adding a JJ identity
mechanism. Git and colocated JJ require matching physical identities.

Keep pool locations, state, trust checks, and cleanup behavior unchanged.
Cover both acquire modes, capacity, symlinks, unreadable candidates,
existing-state return, and colocated/non-colocated JJ combinations.

* no-mistakes(review): Refuse worktree reuse when clone identity cannot be verified

* no-mistakes(document): Document clone-correct worktree reuse in README and AGENTS

* fix(pool): reclaim foreign-clone worktrees

Resolve cleanup context and VCS removal ownership from each managed
worktree path so shared pools can prune and destroy slots from multiple
clones while unresolved paths remain untouched and reported.

* no-mistakes(document): Document per-worktree repository resolution for prune and destroy

* no-mistakes(ci): Fixed Greptile finding ci-5 with the smallest change. What I changed: 1. internal/pool/prune.go, `worktreePruneContextResolver`: when fetch or default-ref resolution fails, it now returns `pruneContext{RepoRoot: repoRoot}` with the error. It used to return an empty context. The cached-error path does the same thing now. DefaultRef stays empty. 2. internal/pool/destroy.go:214: I updated the comment. It now says that a failure leaves the default ref empty. 3. internal/pool/pool_test.go: I added `TestWorktreePruneContextResolverKeepsRootWhenFetchFails`. It points origin at a missing path and calls the resolver two times. The second call reads the cached error. Each call must return an error, the resolved root, and an empty DefaultRef. Effect: `classifyForDestroy` gets the root again, so it can set `OtherFlavor` and show the "destroy it and migrate the pool" hint. With an empty DefaultRef the slot is still `DestroyUnverified`, so deletion is still refused. Prune does not change: at prune.go:704 it throws away the context when there is an error. No new resolver or abstraction was added. Checks I ran: - Without the fix, the new test fails (`got RepoRoot:""`). With the fix, it passes. - `go test ./... -count=1`: all packages pass. - `go vet ./internal/pool/` passes. `gofmt -l` finds nothing. `GOOS=windows go build ./...` passes. I did not commit the changes. They are in the working tree

* no-mistakes(ci): Fixed both real failures. The changes are left uncommitted for the executor. I did not push, and I did not touch the PR. 1. Windows CI failure (TestAcquire_CloneIdentityCapacity, pool_test.go:128). The cause was in the test only. Git on Windows checks README out as "hi\r\n", and the test compared it with the literal "hi\n". The test now reads the README bytes BEFORE the rejected foreign acquisition and compares them AFTER. The two new jj tests that compared with the same literal get the same snapshot change: TestAcquireSkipsUnresolvableColocatedJJIdentity and TestAcquireSecondNonColocatedJJCloneRefusedForeignWorkspace. Product behaviour does not change. Proof: with core.autocrlf=true (set through the GIT_CONFIG_COUNT env), the old test fails with the exact CI message ("hi\r\n") for leased=false and leased=true. The new test passes under the same setting. 2. Greptile finding at pool.go:461 (it is a real finding, not a service failure). The code compared clone identity as path strings (candidateDir != commonDir). On a case-insensitive filesystem, one physical clone spelled with different letter case read as "another clone", so the clone could not reuse its own slot. Fix: acquisitionCommonGitDir now returns os.Stat(vcs.CommonGitDir(dir)), and the selector compares with os.SameFile. os.Stat follows symlinks, so symlink aliases still resolve to one identity. The filepath.Abs and EvalSymlinks steps are now redundant, so I removed them. The requester identity is still computed once, outside the loop. Any identity error on either side still means skip (unverifiedClone). Capacity messages are the same. Non-colocated jj still gets no reuse. Nothing is lowercased. The jj test failure messages now print the identity with %v. New regression: TestAcquire_CloneIdentityCaseAlias covers ordinary and durable (lease) acquisition. It rewrites the slot's commondir to an upper-cased spelling and asks as both repo and REPO. It skips only when os.Stat plus os.SameFile shows the filesystem is case-sensitive. Before the fix, both subtests failed on macOS with "1 belong to another clone". After the fix, both pass. The symlink alias, distinct-clone and unreadable-candidate tests still pass. Docs: I made one-line accuracy updates to AGENTS.md (the identity uses os.SameFile, not a string compare) and to the README Clone-correct reuse line (differently cased paths on a case-insensitive filesystem count as one clone). Validation, all local on macOS: - Native go build ./... and go vet ./... pass. - GOOS=windows go build ./... and go vet ./... pass. - Full go test ./... -count=1 passes with the real jj on PATH. All jj clone-identity tests ran; none skipped. No prune/destroy/trust-check changes. No cleanup changes. No new jj identity mechanism

* no-mistakes(ci): No code change is needed. The failing check "Require no-mistakes" (run 35838744065) ended as action_required with zero jobs, so no step ran and nothing failed. The other runs on the same PR head 2a00a9a are in the same state: "CI" (35838743988) and "Nix flake" (35838744043) are both action_required with no jobs. That is GitHub holding workflow runs on a PR from a fork until a maintainer approves them. The new pipeline push created these runs, and none has been approved yet. The local HEAD equals the PR head, so the runs point at the current code but have not executed it. This failure is outside the code under review. Action for the outer executor or owner: a kunchenguid/treehouse maintainer must click "Approve and run workflows" on PR kunchenguid#145. The .gitignore and .ignore changes in the working tree are local graft-cache artifacts and must not be committed

* no-mistakes(ci): Removed stray graft ignore artifacts: restored .gitignore to base content and deleted .ignore, which does not exist on base. PR diff vs base is now exactly AGENTS.md, README.md, internal/pool/clone_identity_jj_test.go, internal/pool/pool.go, internal/pool/pool_test.go. graft/ stays ignored by the repo-local info/exclude. No product or test changes. go build and internal/pool tests pass. CI, Nix flake and Require no-mistakes are action_required with 0 jobs: they wait for a maintainer to approve fork workflow runs on kunchenguid#145. No code fault

* no-mistakes(ci): Fixed Greptile ci-4 (clone identity is out of scope). The changes are left uncommitted in the working tree so the executor can make one forward commit. I did no rebase, reset, amend or force-push, and I did not push. What I removed (clone-identity work from PR 145): 1. internal/pool/pool.go: restored to the base version (38f8192). This removes acquisitionCommonGitDir, the otherClone/unverifiedClone skip in acquire, and the clone-identity capacity error. The reclaim commits never changed pool.go. 2. internal/pool/clone_identity_jj_test.go: deleted (git rm). It held only clone-identity jj acquire tests. 3. internal/pool/pool_test.go: removed assertCloneCommonDir, TestAcquire_CloneIdentity, TestAcquire_CloneIdentityCapacity, TestAcquire_CloneIdentitySymlinkAlias, TestAcquire_CloneIdentityCaseAlias, TestAcquire_CloneIdentityUnreadableCandidate and TestRelease_CloneIdentityExistingState. Also removed the vcs import, which nothing else uses. 4. AGENTS.md: the "Acquire reuses a slot only when..." line is back to the base text. 5. README.md: the reuse flow diagram is back to the base text, and the "Clone-correct reuse" bullet is gone. What I kept (reclaim work): - The per-worktree root resolution in destroy.go and prune.go, and the fix that keeps the root when fetch fails. - Their tests: TestDestroyPoolRemovesWorktreesOwnedByDifferentClones, TestDestroyPoolRefusesUnattributableWorktreePerPath, TestPruneRemovesWorktreesOwnedByDifferentClones, TestWorktreePruneContextResolverKeepsRootWhenFetchFails, and the updated executeDestroy tests. - Their docs: the AGENTS.md prune/destroy line and the README prune/destroy paragraphs. - The shared test helper setupSharedClonePool, because the reclaim tests need it. I changed only its comment. acquireDisposableFromEachClone does not need clone identity: clone B gets a new slot because clone A's slot is still reserved. The diff against base 38f8192 now touches only AGENTS.md, README.md, internal/pool/destroy.go, internal/pool/prune.go, internal/pool/pool_test.go and internal/pool/worktree_path_test.go. .gitignore and .ignore are not in it. The separation was clean, with no conflicts. Checks run on macOS: - go build ./... passed. - go vet ./... passed. - GOOS=windows go build ./... and GOOS=windows go vet ./... passed. - gofmt -l printed nothing. - go test ./... -count=1 passed in every package. - All reclaim tests ran and passed (verbose run). Gap: I could not run the real-jj tests. jj is not on PATH on this machine, and the workspace rules do not let me install it, so 23 jj tests skipped. The jj tests I deleted covered clone identity only. No jj code path changed in this round

* Restore upstream workflow exemption after merge

Keep the PR diff scoped to foreign-slot reclaim by restoring the
kunchenguid exemption already present on upstream main.

* fix(pool): avoid resolving markerless destroy targets

Keep damaged slots out of per-path repository resolution so destroy cannot
fetch an unrelated repository enclosing the pool. Restore real Git removal
refusal coverage for state and owner-reservation recovery.

---------

Co-authored-by: Kun Chen <[email protected]>

* feat: add opt-in branch creation to treehouse get (kunchenguid#150)

* feat(get): create branches on acquisition

Add an opt-in branch flag so agents can commit on a named branch immediately. Preserve hook output and quarantine unsafe slots when branch creation fails.

* fix(get): quarantine failed branch hook output

Inspect recycled slots after branch creation fails so ignored hook files cannot leak into the next acquisition. Keep clean branch-name collisions reusable and cover the rejecting hook path.

* no-mistakes(review): Preserve branch-failure diagnostics and hook-modified seeds

* no-mistakes(review): Keep recycled slots reusable and limit checkout diagnostics

* no-mistakes(review): Preserve checkout diagnostics and validate branch base before handoff

* no-mistakes(review): Report checkout hook diagnostics without changing lease output

* no-mistakes(review): Remove hook-bypassing detach retry

* no-mistakes(review): Restore ordinary detach hook failure reporting

* no-mistakes(document): Clarify branch acquisition and return documentation

* no-mistakes(ci): The Windows test failure came from hook detection relying on Unix executable permission bits. Git for Windows can run the reference-transaction hook even though those bits are not exposed, so the failed branch creation removed a slot that should have been quarantined. Hook detection now treats a regular hook file as runnable on Windows. The two targeted reference-transaction tests pass locally, and the project cross-compiles for Windows. The failing scenario has not been rerun on Windows

* no-mistakes(ci): Fixed the branch-name collision race: when branch creation fails before checkout, a post-checkout hook’s presence no longer quarantines an otherwise clean slot. Reference-transaction hook output remains protected. Added a regression that creates the collision after the initial check and confirms a max_trees=1 pool remains usable. Gated Unix-shell hook fixtures on Windows; non-hook branch coverage remains enabled. Relevant Go packages passed locally, and their tests cross-compiled for Windows. The tests were not executed on Windows

* feat(get): create branches on acquisition

Add an opt-in branch flag so agents can commit on a named branch immediately. Preserve hook output and quarantine unsafe slots when branch creation fails.

* no-mistakes(review): Restore detach errors and remove unused output inspection

* no-mistakes(review): Preserve checkout hook stderr in branch failure diagnostics

* no-mistakes(review): Restore failed Git command output behavior

* no-mistakes(document): Clarify branch collision and base-name guidance

* docs: trim agent guide and preserve design notes (kunchenguid#152)

* docs: trim AGENTS.md to every-session rules, move design notes to docs/design.md

AGENTS.md: 123 lines / 5177 words / 35817 bytes -> 48 lines / 469 words / 3305 bytes.
The Key Design Decisions and Contribution Gate maintainer detail moved verbatim
(em dashes normalized, README links re-rooted) to docs/design.md.

* no-mistakes(document): Correct pruning documentation and pass lint

* no-mistakes(ci): Updated AGENTS.md to distinguish confirmed dirty returns from fail-closed reuse and cleanup, and to document the inspected, named-destroy path for recovered quarantined slots. git diff --check and go test ./... passed

* feat(fileclone): add opt-in APFS sharing for fresh Git worktrees (kunchenguid#153)

* feat: add opt-in APFS sharing for fresh Git slots

* no-mistakes(document): Correct APFS metadata guidance and consolidate config documentation

* no-mistakes(ci): Fixed the Windows test failure by making the tracked test asset binary, preventing Git CRLF conversion from changing its checkout bytes. Reproduced the failure before the fix and passed the APFS CLI tests with CRLF conversion enabled afterward. Related package tests and the Windows build passed

* no-mistakes(ci): Made APFS sharing check configured Git hook paths explicitly for both checkout and reference-transaction hooks, and replaced the hardcoded hook separator with filepath.Join. Added end-to-end tests for absolute and relative hooksPath settings. The configured-hook test also passed before the change because Git’s existing path resolution respected hooksPath. Relevant tests and the Windows build pass

* fix: resolve effective Git hooks before APFS sharing

* no-mistakes(document): Clarify APFS sharing documentation and verify lint

* chore(main): release 3.0.0 (kunchenguid#117)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* fix(pool): adopt pre-3.0 state instead of quarantining it as recovered (kunchenguid#156)

* fix(pool): adopt pre-3.0 state on upgrade and free slots 3.0.0 wrongly quarantined

treehouse 3.0.0 treated every valid pre-3.0 state file as untrusted: its
first run leased every worktree in every pool as "recovered: state file was
corrupt or truncated; verify before reuse", so idle slots were never reused
and each new get created a fresh slot instead. The regression came from the
seed-inventory integrity check added in 0e87c62 (kunchenguid#129), which quarantined any
state without the new version and HMAC key.

Pre-3.0 releases never seeded ignored files, so unversioned state with no
treehouse-state.key beside it is now adopted as is on the first run: idle
slots stay available and leases keep their holders. Unversioned state beside
a key was rewritten by an older binary after 3.0 ran and stays quarantined.

Pools that 3.0.0 already rewrote recover on their own. A slot that was idle
or in use before the upgrade is relabeled "quarantined by the 3.0.0 upgrade"
and returns to the pool as soon as the next status or get proves it detached,
clean, merged into its base, and free of running processes; until then it
stays leased. A slot that was leased before the upgrade is relabeled "leased
before the 3.0.0 upgrade" and is never released automatically. Both can be
returned with `treehouse return`. Genuinely corrupt or truncated state is
still quarantined as before.

State is now written as version 5 so a version-4 file is known to come from
3.0.0; treehouse 3.0.0 refuses to read version-5 state rather than
misreading it.

* no-mistakes(review): Keep 3.0.0-quarantined slots leased until explicitly returned

* no-mistakes(review): Treat all 3.0.0-relabeled slots alike; skip them in return --all

* no-mistakes(review): Return recovered slots only by name, never automatically

* no-mistakes(review): Refuse recovered slots under lock in return --all

* no-mistakes(review): Adopt unversioned 2.x rewrites beside key; fix stale return docs

* no-mistakes(review): Document adoption of 2.x rewrites beside key in README

* no-mistakes(review): Rewrite stale return --all recovered-slot skip bullet in README

* no-mistakes(document): Fix stale recovered-slot release doc comments

* no-mistakes(ci): The only failing check is Greptile Review, which raised two findings. Both are fixed with documentation edits only; no Go code changed. - **ci-1 (lost seed inventory after a 2.x rewrite):** Per your decision, I made no code change and documented this as a known limitation. README.md (Recovering missing pool state) and docs/design.md already described the case. Both now label it "known limitation" and state the outcome plainly: if a still-running 2.x binary rewrites the state after 3.x seeded `.worktreeinclude` files into a slot, the record of those files is lost. A later reset won't remove them, so they stay in the slot when it is reused. - **ci-2 (AGENTS.md out of date on recovered slots):** AGENTS.md said to remove a recovered slot with `destroy <path> --include-leased --yes`. I replaced that invariant line with one matching docs/design.md: only a named `return <path>` releases a recovered slot (it warns that seeded files may remain), `destroy <path> --include-leased --yes` removes it instead, and `return --all` skips it. I kept it to one line. I didn't run tests or the linter because the change only touches three Markdown files (one line each)

* chore(main): release 3.0.1 (kunchenguid#157)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* feat(pool): automatically free safe recovered slots (kunchenguid#159)

* fix: auto-recover provably safe quarantined slots

Treehouse 3.0.2 recovers idle, clean, landed Git slots automatically. Untracked files are moved to retained backups; unsafe recoveries remain quarantined with status guidance.

* no-mistakes(review): Run safe recovery on every locked pool command

* no-mistakes(review): Block recovery on submodule edits; name partial backup path

* no-mistakes(review): Reuse one derived backup folder per recovered slot

* no-mistakes(review): Refuse symlinked backups; name backups on state-write failure

* no-mistakes(review): Drop backup naming from state-write errors; document backup path

* no-mistakes(document): Correct stale recovery guidance and verify lint

* no-mistakes(document): Clarify recovered lease guidance and stale return comments

* no-mistakes(review): Keep recovery backup folders owner-only before moving files

* no-mistakes(review): Keep recovered Windows slots with untracked files leased

* no-mistakes(document): Clarify recovery backup guidance and stale comments

* no-mistakes(review): Keep recovered slots with index-hidden tracked edits leased

* no-mistakes(review): Check index-hidden edits inside submodules before freeing slots

* no-mistakes(document): Clarify recovered-slot guidance and pass lint checks

* no-mistakes(document): Clarify recovered-slot documentation and backup comment

* no-mistakes(document): Clarify ordinary lease behavior in README

* no-mistakes(ci): Fixed all three Greptile findings: recovery Git operations now go through internal/vcs; modified or untracked initialized submodules keep recovered slots leased with a specific status reason; backup moves cannot overwrite an occupied destination. Added behavioral tests, passed go test ./... and the Windows build, and replied to each Greptile comment

* chore(main): release 3.1.0 (kunchenguid#160)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* fix(vcs): check recovered HEAD containment with a single rev-list walk (kunchenguid#164)

* fix(pool): check recovered HEAD containment with one rev-list walk

Recovery runs under the state lock before every pool command, and 3.1.0
checked HEAD against each remote-tracking ref with its own merge-base call.
With thousands of remote refs and an unpushed slot HEAD, status/get/return
took ~40 minutes and blocked every other treehouse command (kunchenguid#163).

Ask one question instead: is any commit reachable from HEAD but from no
remote-tracking ref and not from the verified base branch? HEAD is contained
exactly when rev-list succeeds and prints nothing, so the containment answer
is unchanged and git errors still keep the slot quarantined.

* no-mistakes(ci): Added the regression test from the Greptile finding. It lives in internal/vcs/gitvcs/recovery_test.go and is called TestRecoveryHeadContainedGitCallsDoNotGrowWithRemoteRefs. Production code was not changed. The test builds two repos where HEAD has a commit that isn't pushed: one repo has 1 remote-tracking ref and the other has 200, all pointing at main. It creates the 200 refs with a single `git update-ref --stdin` call. It then puts a fake `git` shell script first on PATH, which writes one log line per call and then runs the real git, and calls RecoveryHeadContained(repo, "main") in each repo. The test fails if HEAD is reported as contained, or if the number of git processes differs between the two repos. There are no timing checks, and the test is skipped on Windows because the wrapper is a POSIX shell script. Verification: `go test ./internal/vcs/gitvcs/ -count=1` passes, and so do all the existing RecoveryHeadContained tests. `gofmt -l` reports nothing and `GOOS=windows go vet` is clean. I also swapped in the old per-ref recovery.go from base commit c099281 for one run, then restored it: the new test failed with 'git processes: 5 with 1 remote ref, 204 with 200; want the same count'. So the test catches the old per-ref slowdown

* chore(main): release 3.1.1 (kunchenguid#166)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* fix: add /v3 major version suffix to module path (kunchenguid#167)

Restore Go module path to github.com/kunchenguid/treehouse/v3 so go install @latest delivers the current major (fixes kunchenguid#62).

Mechanical rename across go.mod, all in-repo imports, and the README install line.

* chore(main): release 3.1.2 (kunchenguid#168)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Document shared clone allocation cap and clarify regression coverage

* fix(pool): reclaim safe idle foreign slots at the shared cap

* fix(pool): preserve paused Git operations during reclamation

* no-mistakes(review): Correct foreign-slot reclamation safety and remote containment

* no-mistakes(review): Preserve replacement trees and unseeded ignored data during reclamation

* no-mistakes(document): Consolidate clone allocation and reclamation documentation

* no-mistakes(ci): Fixed ci-1’s two observed failures. The fresh-checkout assertion now uses the existing CRLF-aware assertFileContents helper; sibling checkout assertions already used it, and byte-preservation checks remain unchanged. CI and make test now use an explicit 20-minute per-package timeout instead of Go’s default 10 minutes, retaining all coverage and OS targets. Documented the test budget in CONTRIBUTING.md. No production reclamation behavior changed. Verification passed: all foreign-reclamation tests with core.autocrlf=true (486.829s); go test -timeout 20m ./... (pool package: 874.940s); and GOOS=windows GOARCH=amd64 go build ./.... A real CLI smoke also confirmed foreign feature reclamation, removal of the old checkout, caller ownership of the replacement, and exact base-file bytes hi\r\n. Smoke artifacts were removed. Native Windows test execution remains for the outer CI executor

---------

Co-authored-by: Kun Chen <[email protected]>
Co-authored-by: Kun Chen <[email protected]>
Co-authored-by: Niko Lehtovirta <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Andrew Smith <[email protected]>
MrGTV-love added a commit to MrGTV-love/treehouse that referenced this pull request Oct 8, 2026
* ci: pin require-no-mistakes to v1.80.1 for live PR lookup (kunchenguid#144)

* ci: pin require-no-mistakes to v1.80.1 for live PR lookup

The v1.80.1 verifier reads body and head from one API response and
fails closed without pull-requests: read, so drop the Fetch current
PR body step and its cached event-payload inputs.

* test: lock v1.80.1 live PR lookup on the required-check caller

A pin-only assertion stayed green if the workflow restored cached
PR inputs, restored the fetch step, or dropped pull-requests: read.

* ci: exempt kunchenguid from no-mistakes-required gate (kunchenguid#147)

* fix(pool): reuse a pooled worktree only for the clone that owns it (kunchenguid#145)

* fix(pool): enforce clone identity when reusing Git worktrees

Compare physical Git common directories before resetting or acquiring a
shared-pool slot. Resolve the requester once, normalize symlinks, and
leave foreign or unreadable candidates intact. Explain foreign-clone
capacity exhaustion without misreporting clean slots as dirty or busy.

Apply the comparison symmetrically: an unsupported empty identity only
matches another empty identity. Preserve non-colocated JJ reuse, including
its existing unidentified-clone sharing, without adding a JJ identity
mechanism. Git and colocated JJ require matching physical identities.

Keep pool locations, state, trust checks, and cleanup behavior unchanged.
Cover both acquire modes, capacity, symlinks, unreadable candidates,
existing-state return, and colocated/non-colocated JJ combinations.

* no-mistakes(review): Refuse worktree reuse when clone identity cannot be verified

* no-mistakes(document): Document clone-correct worktree reuse in README and AGENTS

* no-mistakes(ci): Fixed both real failures. The changes are left uncommitted for the executor. I did not push, and I did not touch the PR. 1. Windows CI failure (TestAcquire_CloneIdentityCapacity, pool_test.go:128). The cause was in the test only. Git on Windows checks README out as "hi\r\n", and the test compared it with the literal "hi\n". The test now reads the README bytes BEFORE the rejected foreign acquisition and compares them AFTER. The two new jj tests that compared with the same literal get the same snapshot change: TestAcquireSkipsUnresolvableColocatedJJIdentity and TestAcquireSecondNonColocatedJJCloneRefusedForeignWorkspace. Product behaviour does not change. Proof: with core.autocrlf=true (set through the GIT_CONFIG_COUNT env), the old test fails with the exact CI message ("hi\r\n") for leased=false and leased=true. The new test passes under the same setting. 2. Greptile finding at pool.go:461 (it is a real finding, not a service failure). The code compared clone identity as path strings (candidateDir != commonDir). On a case-insensitive filesystem, one physical clone spelled with different letter case read as "another clone", so the clone could not reuse its own slot. Fix: acquisitionCommonGitDir now returns os.Stat(vcs.CommonGitDir(dir)), and the selector compares with os.SameFile. os.Stat follows symlinks, so symlink aliases still resolve to one identity. The filepath.Abs and EvalSymlinks steps are now redundant, so I removed them. The requester identity is still computed once, outside the loop. Any identity error on either side still means skip (unverifiedClone). Capacity messages are the same. Non-colocated jj still gets no reuse. Nothing is lowercased. The jj test failure messages now print the identity with %v. New regression: TestAcquire_CloneIdentityCaseAlias covers ordinary and durable (lease) acquisition. It rewrites the slot's commondir to an upper-cased spelling and asks as both repo and REPO. It skips only when os.Stat plus os.SameFile shows the filesystem is case-sensitive. Before the fix, both subtests failed on macOS with "1 belong to another clone". After the fix, both pass. The symlink alias, distinct-clone and unreadable-candidate tests still pass. Docs: I made one-line accuracy updates to AGENTS.md (the identity uses os.SameFile, not a string compare) and to the README Clone-correct reuse line (differently cased paths on a case-insensitive filesystem count as one clone). Validation, all local on macOS: - Native go build ./... and go vet ./... pass. - GOOS=windows go build ./... and go vet ./... pass. - Full go test ./... -count=1 passes with the real jj on PATH. All jj clone-identity tests ran; none skipped. No prune/destroy/trust-check changes. No cleanup changes. No new jj identity mechanism

* no-mistakes(ci): No code change is needed. The failing check "Require no-mistakes" (run 35838744065) ended as action_required with zero jobs, so no step ran and nothing failed. The other runs on the same PR head 2a00a9a are in the same state: "CI" (35838743988) and "Nix flake" (35838744043) are both action_required with no jobs. That is GitHub holding workflow runs on a PR from a fork until a maintainer approves them. The new pipeline push created these runs, and none has been approved yet. The local HEAD equals the PR head, so the runs point at the current code but have not executed it. This failure is outside the code under review. Action for the outer executor or owner: a kunchenguid/treehouse maintainer must click "Approve and run workflows" on PR kunchenguid#145. The .gitignore and .ignore changes in the working tree are local graft-cache artifacts and must not be committed

* no-mistakes(ci): Removed stray graft ignore artifacts: restored .gitignore to base content and deleted .ignore, which does not exist on base. PR diff vs base is now exactly AGENTS.md, README.md, internal/pool/clone_identity_jj_test.go, internal/pool/pool.go, internal/pool/pool_test.go. graft/ stays ignored by the repo-local info/exclude. No product or test changes. go build and internal/pool tests pass. CI, Nix flake and Require no-mistakes are action_required with 0 jobs: they wait for a maintainer to approve fork workflow runs on kunchenguid#145. No code fault

* fix(pool): let prune and destroy reclaim worktrees from other clones in a shared pool (kunchenguid#146)

* fix(pool): enforce clone identity when reusing Git worktrees

Compare physical Git common directories before resetting or acquiring a
shared-pool slot. Resolve the requester once, normalize symlinks, and
leave foreign or unreadable candidates intact. Explain foreign-clone
capacity exhaustion without misreporting clean slots as dirty or busy.

Apply the comparison symmetrically: an unsupported empty identity only
matches another empty identity. Preserve non-colocated JJ reuse, including
its existing unidentified-clone sharing, without adding a JJ identity
mechanism. Git and colocated JJ require matching physical identities.

Keep pool locations, state, trust checks, and cleanup behavior unchanged.
Cover both acquire modes, capacity, symlinks, unreadable candidates,
existing-state return, and colocated/non-colocated JJ combinations.

* no-mistakes(review): Refuse worktree reuse when clone identity cannot be verified

* no-mistakes(document): Document clone-correct worktree reuse in README and AGENTS

* fix(pool): enforce clone identity when reusing Git worktrees

Compare physical Git common directories before resetting or acquiring a
shared-pool slot. Resolve the requester once, normalize symlinks, and
leave foreign or unreadable candidates intact. Explain foreign-clone
capacity exhaustion without misreporting clean slots as dirty or busy.

Apply the comparison symmetrically: an unsupported empty identity only
matches another empty identity. Preserve non-colocated JJ reuse, including
its existing unidentified-clone sharing, without adding a JJ identity
mechanism. Git and colocated JJ require matching physical identities.

Keep pool locations, state, trust checks, and cleanup behavior unchanged.
Cover both acquire modes, capacity, symlinks, unreadable candidates,
existing-state return, and colocated/non-colocated JJ combinations.

* no-mistakes(review): Refuse worktree reuse when clone identity cannot be verified

* no-mistakes(document): Document clone-correct worktree reuse in README and AGENTS

* fix(pool): reclaim foreign-clone worktrees

Resolve cleanup context and VCS removal ownership from each managed
worktree path so shared pools can prune and destroy slots from multiple
clones while unresolved paths remain untouched and reported.

* no-mistakes(document): Document per-worktree repository resolution for prune and destroy

* no-mistakes(ci): Fixed Greptile finding ci-5 with the smallest change. What I changed: 1. internal/pool/prune.go, `worktreePruneContextResolver`: when fetch or default-ref resolution fails, it now returns `pruneContext{RepoRoot: repoRoot}` with the error. It used to return an empty context. The cached-error path does the same thing now. DefaultRef stays empty. 2. internal/pool/destroy.go:214: I updated the comment. It now says that a failure leaves the default ref empty. 3. internal/pool/pool_test.go: I added `TestWorktreePruneContextResolverKeepsRootWhenFetchFails`. It points origin at a missing path and calls the resolver two times. The second call reads the cached error. Each call must return an error, the resolved root, and an empty DefaultRef. Effect: `classifyForDestroy` gets the root again, so it can set `OtherFlavor` and show the "destroy it and migrate the pool" hint. With an empty DefaultRef the slot is still `DestroyUnverified`, so deletion is still refused. Prune does not change: at prune.go:704 it throws away the context when there is an error. No new resolver or abstraction was added. Checks I ran: - Without the fix, the new test fails (`got RepoRoot:""`). With the fix, it passes. - `go test ./... -count=1`: all packages pass. - `go vet ./internal/pool/` passes. `gofmt -l` finds nothing. `GOOS=windows go build ./...` passes. I did not commit the changes. They are in the working tree

* no-mistakes(ci): Fixed both real failures. The changes are left uncommitted for the executor. I did not push, and I did not touch the PR. 1. Windows CI failure (TestAcquire_CloneIdentityCapacity, pool_test.go:128). The cause was in the test only. Git on Windows checks README out as "hi\r\n", and the test compared it with the literal "hi\n". The test now reads the README bytes BEFORE the rejected foreign acquisition and compares them AFTER. The two new jj tests that compared with the same literal get the same snapshot change: TestAcquireSkipsUnresolvableColocatedJJIdentity and TestAcquireSecondNonColocatedJJCloneRefusedForeignWorkspace. Product behaviour does not change. Proof: with core.autocrlf=true (set through the GIT_CONFIG_COUNT env), the old test fails with the exact CI message ("hi\r\n") for leased=false and leased=true. The new test passes under the same setting. 2. Greptile finding at pool.go:461 (it is a real finding, not a service failure). The code compared clone identity as path strings (candidateDir != commonDir). On a case-insensitive filesystem, one physical clone spelled with different letter case read as "another clone", so the clone could not reuse its own slot. Fix: acquisitionCommonGitDir now returns os.Stat(vcs.CommonGitDir(dir)), and the selector compares with os.SameFile. os.Stat follows symlinks, so symlink aliases still resolve to one identity. The filepath.Abs and EvalSymlinks steps are now redundant, so I removed them. The requester identity is still computed once, outside the loop. Any identity error on either side still means skip (unverifiedClone). Capacity messages are the same. Non-colocated jj still gets no reuse. Nothing is lowercased. The jj test failure messages now print the identity with %v. New regression: TestAcquire_CloneIdentityCaseAlias covers ordinary and durable (lease) acquisition. It rewrites the slot's commondir to an upper-cased spelling and asks as both repo and REPO. It skips only when os.Stat plus os.SameFile shows the filesystem is case-sensitive. Before the fix, both subtests failed on macOS with "1 belong to another clone". After the fix, both pass. The symlink alias, distinct-clone and unreadable-candidate tests still pass. Docs: I made one-line accuracy updates to AGENTS.md (the identity uses os.SameFile, not a string compare) and to the README Clone-correct reuse line (differently cased paths on a case-insensitive filesystem count as one clone). Validation, all local on macOS: - Native go build ./... and go vet ./... pass. - GOOS=windows go build ./... and go vet ./... pass. - Full go test ./... -count=1 passes with the real jj on PATH. All jj clone-identity tests ran; none skipped. No prune/destroy/trust-check changes. No cleanup changes. No new jj identity mechanism

* no-mistakes(ci): No code change is needed. The failing check "Require no-mistakes" (run 35838744065) ended as action_required with zero jobs, so no step ran and nothing failed. The other runs on the same PR head 2a00a9a are in the same state: "CI" (35838743988) and "Nix flake" (35838744043) are both action_required with no jobs. That is GitHub holding workflow runs on a PR from a fork until a maintainer approves them. The new pipeline push created these runs, and none has been approved yet. The local HEAD equals the PR head, so the runs point at the current code but have not executed it. This failure is outside the code under review. Action for the outer executor or owner: a kunchenguid/treehouse maintainer must click "Approve and run workflows" on PR kunchenguid#145. The .gitignore and .ignore changes in the working tree are local graft-cache artifacts and must not be committed

* no-mistakes(ci): Removed stray graft ignore artifacts: restored .gitignore to base content and deleted .ignore, which does not exist on base. PR diff vs base is now exactly AGENTS.md, README.md, internal/pool/clone_identity_jj_test.go, internal/pool/pool.go, internal/pool/pool_test.go. graft/ stays ignored by the repo-local info/exclude. No product or test changes. go build and internal/pool tests pass. CI, Nix flake and Require no-mistakes are action_required with 0 jobs: they wait for a maintainer to approve fork workflow runs on kunchenguid#145. No code fault

* no-mistakes(ci): Fixed Greptile ci-4 (clone identity is out of scope). The changes are left uncommitted in the working tree so the executor can make one forward commit. I did no rebase, reset, amend or force-push, and I did not push. What I removed (clone-identity work from PR 145): 1. internal/pool/pool.go: restored to the base version (38f8192). This removes acquisitionCommonGitDir, the otherClone/unverifiedClone skip in acquire, and the clone-identity capacity error. The reclaim commits never changed pool.go. 2. internal/pool/clone_identity_jj_test.go: deleted (git rm). It held only clone-identity jj acquire tests. 3. internal/pool/pool_test.go: removed assertCloneCommonDir, TestAcquire_CloneIdentity, TestAcquire_CloneIdentityCapacity, TestAcquire_CloneIdentitySymlinkAlias, TestAcquire_CloneIdentityCaseAlias, TestAcquire_CloneIdentityUnreadableCandidate and TestRelease_CloneIdentityExistingState. Also removed the vcs import, which nothing else uses. 4. AGENTS.md: the "Acquire reuses a slot only when..." line is back to the base text. 5. README.md: the reuse flow diagram is back to the base text, and the "Clone-correct reuse" bullet is gone. What I kept (reclaim work): - The per-worktree root resolution in destroy.go and prune.go, and the fix that keeps the root when fetch fails. - Their tests: TestDestroyPoolRemovesWorktreesOwnedByDifferentClones, TestDestroyPoolRefusesUnattributableWorktreePerPath, TestPruneRemovesWorktreesOwnedByDifferentClones, TestWorktreePruneContextResolverKeepsRootWhenFetchFails, and the updated executeDestroy tests. - Their docs: the AGENTS.md prune/destroy line and the README prune/destroy paragraphs. - The shared test helper setupSharedClonePool, because the reclaim tests need it. I changed only its comment. acquireDisposableFromEachClone does not need clone identity: clone B gets a new slot because clone A's slot is still reserved. The diff against base 38f8192 now touches only AGENTS.md, README.md, internal/pool/destroy.go, internal/pool/prune.go, internal/pool/pool_test.go and internal/pool/worktree_path_test.go. .gitignore and .ignore are not in it. The separation was clean, with no conflicts. Checks run on macOS: - go build ./... passed. - go vet ./... passed. - GOOS=windows go build ./... and GOOS=windows go vet ./... passed. - gofmt -l printed nothing. - go test ./... -count=1 passed in every package. - All reclaim tests ran and passed (verbose run). Gap: I could not run the real-jj tests. jj is not on PATH on this machine, and the workspace rules do not let me install it, so 23 jj tests skipped. The jj tests I deleted covered clone identity only. No jj code path changed in this round

* Restore upstream workflow exemption after merge

Keep the PR diff scoped to foreign-slot reclaim by restoring the
kunchenguid exemption already present on upstream main.

* fix(pool): avoid resolving markerless destroy targets

Keep damaged slots out of per-path repository resolution so destroy cannot
fetch an unrelated repository enclosing the pool. Restore real Git removal
refusal coverage for state and owner-reservation recovery.

---------

Co-authored-by: Kun Chen <[email protected]>

* feat: add opt-in branch creation to treehouse get (kunchenguid#150)

* feat(get): create branches on acquisition

Add an opt-in branch flag so agents can commit on a named branch immediately. Preserve hook output and quarantine unsafe slots when branch creation fails.

* fix(get): quarantine failed branch hook output

Inspect recycled slots after branch creation fails so ignored hook files cannot leak into the next acquisition. Keep clean branch-name collisions reusable and cover the rejecting hook path.

* no-mistakes(review): Preserve branch-failure diagnostics and hook-modified seeds

* no-mistakes(review): Keep recycled slots reusable and limit checkout diagnostics

* no-mistakes(review): Preserve checkout diagnostics and validate branch base before handoff

* no-mistakes(review): Report checkout hook diagnostics without changing lease output

* no-mistakes(review): Remove hook-bypassing detach retry

* no-mistakes(review): Restore ordinary detach hook failure reporting

* no-mistakes(document): Clarify branch acquisition and return documentation

* no-mistakes(ci): The Windows test failure came from hook detection relying on Unix executable permission bits. Git for Windows can run the reference-transaction hook even though those bits are not exposed, so the failed branch creation removed a slot that should have been quarantined. Hook detection now treats a regular hook file as runnable on Windows. The two targeted reference-transaction tests pass locally, and the project cross-compiles for Windows. The failing scenario has not been rerun on Windows

* no-mistakes(ci): Fixed the branch-name collision race: when branch creation fails before checkout, a post-checkout hook’s presence no longer quarantines an otherwise clean slot. Reference-transaction hook output remains protected. Added a regression that creates the collision after the initial check and confirms a max_trees=1 pool remains usable. Gated Unix-shell hook fixtures on Windows; non-hook branch coverage remains enabled. Relevant Go packages passed locally, and their tests cross-compiled for Windows. The tests were not executed on Windows

* feat(get): create branches on acquisition

Add an opt-in branch flag so agents can commit on a named branch immediately. Preserve hook output and quarantine unsafe slots when branch creation fails.

* no-mistakes(review): Restore detach errors and remove unused output inspection

* no-mistakes(review): Preserve checkout hook stderr in branch failure diagnostics

* no-mistakes(review): Restore failed Git command output behavior

* no-mistakes(document): Clarify branch collision and base-name guidance

* docs: trim agent guide and preserve design notes (kunchenguid#152)

* docs: trim AGENTS.md to every-session rules, move design notes to docs/design.md

AGENTS.md: 123 lines / 5177 words / 35817 bytes -> 48 lines / 469 words / 3305 bytes.
The Key Design Decisions and Contribution Gate maintainer detail moved verbatim
(em dashes normalized, README links re-rooted) to docs/design.md.

* no-mistakes(document): Correct pruning documentation and pass lint

* no-mistakes(ci): Updated AGENTS.md to distinguish confirmed dirty returns from fail-closed reuse and cleanup, and to document the inspected, named-destroy path for recovered quarantined slots. git diff --check and go test ./... passed

* feat(fileclone): add opt-in APFS sharing for fresh Git worktrees (kunchenguid#153)

* feat: add opt-in APFS sharing for fresh Git slots

* no-mistakes(document): Correct APFS metadata guidance and consolidate config documentation

* no-mistakes(ci): Fixed the Windows test failure by making the tracked test asset binary, preventing Git CRLF conversion from changing its checkout bytes. Reproduced the failure before the fix and passed the APFS CLI tests with CRLF conversion enabled afterward. Related package tests and the Windows build passed

* no-mistakes(ci): Made APFS sharing check configured Git hook paths explicitly for both checkout and reference-transaction hooks, and replaced the hardcoded hook separator with filepath.Join. Added end-to-end tests for absolute and relative hooksPath settings. The configured-hook test also passed before the change because Git’s existing path resolution respected hooksPath. Relevant tests and the Windows build pass

* fix: resolve effective Git hooks before APFS sharing

* no-mistakes(document): Clarify APFS sharing documentation and verify lint

* chore(main): release 3.0.0 (kunchenguid#117)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* fix(pool): adopt pre-3.0 state instead of quarantining it as recovered (kunchenguid#156)

* fix(pool): adopt pre-3.0 state on upgrade and free slots 3.0.0 wrongly quarantined

treehouse 3.0.0 treated every valid pre-3.0 state file as untrusted: its
first run leased every worktree in every pool as "recovered: state file was
corrupt or truncated; verify before reuse", so idle slots were never reused
and each new get created a fresh slot instead. The regression came from the
seed-inventory integrity check added in 0e87c62 (kunchenguid#129), which quarantined any
state without the new version and HMAC key.

Pre-3.0 releases never seeded ignored files, so unversioned state with no
treehouse-state.key beside it is now adopted as is on the first run: idle
slots stay available and leases keep their holders. Unversioned state beside
a key was rewritten by an older binary after 3.0 ran and stays quarantined.

Pools that 3.0.0 already rewrote recover on their own. A slot that was idle
or in use before the upgrade is relabeled "quarantined by the 3.0.0 upgrade"
and returns to the pool as soon as the next status or get proves it detached,
clean, merged into its base, and free of running processes; until then it
stays leased. A slot that was leased before the upgrade is relabeled "leased
before the 3.0.0 upgrade" and is never released automatically. Both can be
returned with `treehouse return`. Genuinely corrupt or truncated state is
still quarantined as before.

State is now written as version 5 so a version-4 file is known to come from
3.0.0; treehouse 3.0.0 refuses to read version-5 state rather than
misreading it.

* no-mistakes(review): Keep 3.0.0-quarantined slots leased until explicitly returned

* no-mistakes(review): Treat all 3.0.0-relabeled slots alike; skip them in return --all

* no-mistakes(review): Return recovered slots only by name, never automatically

* no-mistakes(review): Refuse recovered slots under lock in return --all

* no-mistakes(review): Adopt unversioned 2.x rewrites beside key; fix stale return docs

* no-mistakes(review): Document adoption of 2.x rewrites beside key in README

* no-mistakes(review): Rewrite stale return --all recovered-slot skip bullet in README

* no-mistakes(document): Fix stale recovered-slot release doc comments

* no-mistakes(ci): The only failing check is Greptile Review, which raised two findings. Both are fixed with documentation edits only; no Go code changed. - **ci-1 (lost seed inventory after a 2.x rewrite):** Per your decision, I made no code change and documented this as a known limitation. README.md (Recovering missing pool state) and docs/design.md already described the case. Both now label it "known limitation" and state the outcome plainly: if a still-running 2.x binary rewrites the state after 3.x seeded `.worktreeinclude` files into a slot, the record of those files is lost. A later reset won't remove them, so they stay in the slot when it is reused. - **ci-2 (AGENTS.md out of date on recovered slots):** AGENTS.md said to remove a recovered slot with `destroy <path> --include-leased --yes`. I replaced that invariant line with one matching docs/design.md: only a named `return <path>` releases a recovered slot (it warns that seeded files may remain), `destroy <path> --include-leased --yes` removes it instead, and `return --all` skips it. I kept it to one line. I didn't run tests or the linter because the change only touches three Markdown files (one line each)

* chore(main): release 3.0.1 (kunchenguid#157)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* feat(pool): automatically free safe recovered slots (kunchenguid#159)

* fix: auto-recover provably safe quarantined slots

Treehouse 3.0.2 recovers idle, clean, landed Git slots automatically. Untracked files are moved to retained backups; unsafe recoveries remain quarantined with status guidance.

* no-mistakes(review): Run safe recovery on every locked pool command

* no-mistakes(review): Block recovery on submodule edits; name partial backup path

* no-mistakes(review): Reuse one derived backup folder per recovered slot

* no-mistakes(review): Refuse symlinked backups; name backups on state-write failure

* no-mistakes(review): Drop backup naming from state-write errors; document backup path

* no-mistakes(document): Correct stale recovery guidance and verify lint

* no-mistakes(document): Clarify recovered lease guidance and stale return comments

* no-mistakes(review): Keep recovery backup folders owner-only before moving files

* no-mistakes(review): Keep recovered Windows slots with untracked files leased

* no-mistakes(document): Clarify recovery backup guidance and stale comments

* no-mistakes(review): Keep recovered slots with index-hidden tracked edits leased

* no-mistakes(review): Check index-hidden edits inside submodules before freeing slots

* no-mistakes(document): Clarify recovered-slot guidance and pass lint checks

* no-mistakes(document): Clarify recovered-slot documentation and backup comment

* no-mistakes(document): Clarify ordinary lease behavior in README

* no-mistakes(ci): Fixed all three Greptile findings: recovery Git operations now go through internal/vcs; modified or untracked initialized submodules keep recovered slots leased with a specific status reason; backup moves cannot overwrite an occupied destination. Added behavioral tests, passed go test ./... and the Windows build, and replied to each Greptile comment

* chore(main): release 3.1.0 (kunchenguid#160)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* fix(vcs): check recovered HEAD containment with a single rev-list walk (kunchenguid#164)

* fix(pool): check recovered HEAD containment with one rev-list walk

Recovery runs under the state lock before every pool command, and 3.1.0
checked HEAD against each remote-tracking ref with its own merge-base call.
With thousands of remote refs and an unpushed slot HEAD, status/get/return
took ~40 minutes and blocked every other treehouse command (kunchenguid#163).

Ask one question instead: is any commit reachable from HEAD but from no
remote-tracking ref and not from the verified base branch? HEAD is contained
exactly when rev-list succeeds and prints nothing, so the containment answer
is unchanged and git errors still keep the slot quarantined.

* no-mistakes(ci): Added the regression test from the Greptile finding. It lives in internal/vcs/gitvcs/recovery_test.go and is called TestRecoveryHeadContainedGitCallsDoNotGrowWithRemoteRefs. Production code was not changed. The test builds two repos where HEAD has a commit that isn't pushed: one repo has 1 remote-tracking ref and the other has 200, all pointing at main. It creates the 200 refs with a single `git update-ref --stdin` call. It then puts a fake `git` shell script first on PATH, which writes one log line per call and then runs the real git, and calls RecoveryHeadContained(repo, "main") in each repo. The test fails if HEAD is reported as contained, or if the number of git processes differs between the two repos. There are no timing checks, and the test is skipped on Windows because the wrapper is a POSIX shell script. Verification: `go test ./internal/vcs/gitvcs/ -count=1` passes, and so do all the existing RecoveryHeadContained tests. `gofmt -l` reports nothing and `GOOS=windows go vet` is clean. I also swapped in the old per-ref recovery.go from base commit c099281 for one run, then restored it: the new test failed with 'git processes: 5 with 1 remote ref, 204 with 200; want the same count'. So the test catches the old per-ref slowdown

* chore(main): release 3.1.1 (kunchenguid#166)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* fix: add /v3 major version suffix to module path (kunchenguid#167)

Restore Go module path to github.com/kunchenguid/treehouse/v3 so go install @latest delivers the current major (fixes kunchenguid#62).

Mechanical rename across go.mod, all in-repo imports, and the README install line.

* chore(main): release 3.1.2 (kunchenguid#168)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

---------

Co-authored-by: Kun Chen <[email protected]>
Co-authored-by: Kun Chen <[email protected]>
Co-authored-by: Niko Lehtovirta <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Andrew Smith <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants