Skip to content

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

Merged
kunchenguid merged 10 commits into
mainfrom
fm/treehouse-v3-state-upgrade-r1
Sep 26, 2026
Merged

kunchenguid merged 10 commits into
mainfrom
fm/treehouse-v3-state-upgrade-r1

Conversation

@kunchenguid

@kunchenguid kunchenguid commented Sep 25, 2026 •

Copy link
Copy Markdown
Owner

Intent

yes do treehouse release and dogfood

Context: treehouse v3.0.0 was released today and both of the captain's machines were upgraded from v2.0.1 through his Nix config. At the first 3.0.0 run (2026-09-25 12:01 PDT) every existing pool on both machines had all of its worktrees rewritten as leased with lease_holder "recovered: state file was corrupt or truncated; verify before reuse" (for example ~/.treehouse/firstmate-7bab20/treehouse-state.json, version 4), and a new treehouse-state.key file (32 bytes) appeared beside each state file at the same moment. The 2.0.1 state files were not actually corrupt: the upgrade treats valid pre-3.0 state as corrupt, so idle slots are quarantined and never reused, and new work creates fresh slots instead. Any public user upgrading from 2.x will hit the same thing.

What Changed

  • ReadState now adopts unversioned (pre-3.0) state with an empty seed inventory rather than quarantining every entry as RecoveredLeaseHolder. This also applies when a treehouse-state.key already sits beside the state file, which happens when a still-running 2.x binary rewrites 3.0 state without its version and seed fields (Upgrade from v2.3.0 while a treehouse get is live marks pool slots "recovered: state file was corrupt or truncated" although the file is valid #151). Upgrading from 2.x no longer takes the pool out of service.
  • Entries that are already recovered, including the ones 3.0.0 wrongly quarantined, can now be freed with a treehouse return <path> that names the slot. That return warns that any seeded ignored files were not recorded, so they are not cleaned up and stay in the worktree. ErrSeedInventoryUntrusted is removed. treehouse status prints the return command next to each recovered slot.
  • return --all never releases a recovered slot. It counts the slot as skipped and prints the slot's return <path> command. Every bulk release also sets the new ReleasePreconditions.RefuseRecovered, so a slot that becomes recovered after the listing is skipped under the state lock (ErrRecoveredEntry).
  • Also includes pool unit tests and e2e tests for upgrading from 2.x state and for recovered-slot returns, plus matching updates to README and docs/design.md.

🤖 Generated with Claude Code

Known Limitation

Accepted and documented (README "Recovering missing pool state", docs/design.md): a slot can keep copied ignored files when it is reused. This needs a 3.x acquisition to seed ignored files into the slot from .worktreeinclude, and a 2.x binary still running across the upgrade to rewrite the state afterwards. The rewrite has no seed inventory, so it is adopted as empty and a later reset does not remove those files. The alternative, quarantining every unversioned state that sits beside a key, puts the whole pool out of service on any upgrade that happens during a live 2.x session (#151).

Risk Assessment

✅ Low: The change is bounded to state adoption and the gating of recovered-slot release, and every behavior matches the recorded human decisions. I traced: clean 2.x adoption; a 2.x rewrite beside a key; 3.0.0-relabeled entries; seeding-failure quarantines, which ReadState relabels as recovered on the next read, so the bulk guard covers them; and slots recovered after listing in return --all. None produced a wrong result, and each is covered by behavioral pool and e2e tests.

Testing

I ran the real v2.0.1, v2.3.0, 3.0.0 and fixed binaries against throwaway HOMEs and repos. The 3.0.0 binary reproduces the reported quarantine on valid 2.0.1 state. The fixed binary takes over 2.0.1 state cleanly and reuses idle slots, and it survives a 2.3.0 subshell rewriting state next to an existing key (#151). Pools 3.0.0 already quarantined are handled correctly: status shows the named-return hint, return --all skips them, and a named return frees one with a seeded-file warning. Tampered, deleted and truncated key or state still quarantine. return --all refuses a slot recovered mid-run. The targeted Go e2e and upgrade tests pass. All scenarios passed. Note: an early script bug briefly created a pool for this worktree's repo under the real ~/.treehouse. I found it within a minute, removed it with git worktree remove plus rm of that pool dir only, and re-ran everything behind a HOME-isolation guard. All temporary binaries, worktrees and /tmp fixtures are torn down. This is a CLI-only change with no GUI surface, so the evidence is CLI transcripts rather than screenshots.

  • Live validation: ✅ go - 6 of 6 scenarios driven live against the product
Scenario Result Live Evidence
Baseline repro: 3.0.0 (fd5927e) run on a valid 2.0.1 pool relabels every slot 'recovered' and writes v4 plus a key ✅ pass live s0-s1-upgrade-from-2.0.1.txt (S0 section)
User upgrades from 2.0.1 to the fixed build: idle slots stay available, the live lease keeps holder 'live-agent', and get --lease reuses slot 1 instead of creating slot 4 ✅ pass live s0-s1-upgrade-from-2.0.1.txt (S1 section)
Issue #151: 3.x runs inside a live 2.3.0 get subshell (writes v4 and key), then 2.3.0 exits and rewrites the state without a version; the next 3.x status shows no recovered slots and get --lease r… ✅ pass live s2-live-2.3.0-rewrite-beside-key.txt
Pool 3.0.0 already quarantined: fixed build keeps those slots leased, status shows treehouse return &lt;path&gt;, get --lease creates a fresh slot, return --all skips them (1 of 4 returned, 3 skippe… ✅ pass live s3-s4-recovered-and-adversarial.txt (S3 section)
Adversarial: v4 state next to a tampered key, v4 state with the key deleted, and a truncated state file are all still quarantined, not taken over ✅ pass live s3-s4-recovered-and-adversarial.txt (S4a/S4b/S4c sections)
Adversarial race: return --all blocked at a dirty-worktree prompt, key rotated before answering y; both slots skipped as recovered, none released, dirty file kept ✅ pass live s5-return-all-recovered-after-listing.txt; also go test ./cmd -run TestReturnAllSkipsSlotsRecoveredAfterListing
Evidence: S0+S1: 3.0.0 reproduces the quarantine; the fixed build adopts the 2.0.1 pool and reuses an idle slot

Source: S0+S1: 3.0.0 reproduces the quarantine; the fixed build adopts the 2.0.1 pool and reuses an idle slot

=================== S0: baseline 3.0.0 (fd5927e) reproduces the bug on a 2.0.1 pool

$ /tmp/th-e2e.hpn9/bin/th-v2.0.1 --version
v1.8.1-0.20260719222411-5b8ecdec4903
[exit 0]

$ /tmp/th-e2e.hpn9/bin/th-v2.0.1 status
A new version of treehouse is available: v1.8.1-0.20260719222411-5b8ecdec4903 → v3.0.0
Run "treehouse update" to update

1     available    ~/.treehouse/work-3a9d8e/1/work
2     available    ~/.treehouse/work-3a9d8e/2/work
3     leased       ~/.treehouse/work-3a9d8e/3/work  (held by live-agent)
[exit 0]

$ cat treehouse-state.json (version, leased, holder)
version= None
1 leased= None holder= None seed_known= None
2 leased= None holder= None seed_known= None
3 leased= True holder= live-agent seed_known= None
treehouse-state.json

$ /tmp/th-e2e.hpn9/bin/th-fd5927e status
A new version of treehouse is available: v1.8.1-0.20260925171829-fd5927e10174 → v3.0.0
Run "treehouse update" to update

base  main  (repository default)
1     leased       ~/.treehouse/work-3a9d8e/1/work  (detached)  (held by recovered: state file was corrupt or truncated; verify before reuse)
2     leased       ~/.treehouse/work-3a9d8e/2/work  (detached)  (held by recovered: state file was corrupt or truncated; verify before reuse)
3     leased       ~/.treehouse/work-3a9d8e/3/work  (detached)  (held by recovered: state file was corrupt or truncated; verify before reuse)
[exit 0]

$ cat treehouse-state.json (version, leased, holder)
version= 4
1 leased= True holder= recovered: state file was corrupt or truncated; verify before reuse seed_known= None
2 leased= True holder= recovered: state file was corrupt or truncated; verify before reuse seed_known= None
3 leased= True holder= recovered: state file was corrupt or truncated; verify before reuse seed_known= None
treehouse-state.json
treehouse-state.key
=================== S1: fixed build adopts a clean 2.0.1 pool

$ /tmp/th-e2e.hpn9/bin/th-v2.0.1 --version
v1.8.1-0.20260719222411-5b8ecdec4903
[exit 0]

$ /tmp/th-e2e.hpn9/bin/th-v2.0.1 status
A new version of treehouse is available: v1.8.1-0.20260719222411-5b8ecdec4903 → v3.0.0
Run "treehouse update" to update

1     available    ~/.treehouse/work-4ec16c/1/work
2     available    ~/.treehouse/work-4ec16c/2/work
3     leased       ~/.treehouse/work-4ec16c/3/work  (held by live-agent)
[exit 0]

$ cat treehouse-state.json (version, leased, holder)
version= None
1 leased= None holder= None seed_known= None
2 leased= None holder= None seed_known= None
3 leased= True holder= live-agent seed_known= None
treehouse-state.json

$ /tmp/th-e2e.hpn9/bin/th-new status
A new version of treehouse is available: v1.8.1-0.20260925232316-e1d773e4da30 → v3.0.0
Run "treehouse update" to update

base  main  (repository default)
1     available    ~/.treehouse/work-4ec16c/1/work  (detached)
2     available    ~/.treehouse/work-4ec16c/2/work  (detached)
3     leased       ~/.treehouse/work-4ec16c/3/work  (detached)  (held by live-agent)
[exit 0]

$ cat treehouse-state.json (version, leased, holder)
version= 4
1 leased= None holder= None seed_known= True
2 leased= None holder= None seed_known= True
3 leased= True holder= live-agent seed_known= True
treehouse-state.json
treehouse-state.key

$ get --lease (should reuse an idle slot, not create slot 4)
A new version of treehouse is available: v1.8.1-0.20260925232316-e1d773e4da30 → v3.0.0
Run "treehouse update" to update

🌳 Setting up worktree...
🌳 Leased worktree at ~/.treehouse/work-4ec16c/1/work. Run 'treehouse return ~/.treehouse/work-4ec16c/1/work' to release it.
got: /tmp/th-e2e.hpn9/home-s1/.treehouse/work-4ec16c/1/work

$ /tmp/th-e2e.hpn9/bin/th-new status
A new version of treehouse is available: v1.8.1-0.20260925232316-e1d773e4da30 → v3.0.0
Run "treehouse update" to update

base  main  (repository default)
1     leased       ~/.treehouse/work-4ec16c/1/work  (detached)  (held by new-work)
2     available    ~/.treehouse/work-4ec16c/2/work  (detached)
3     leased       ~/.treehouse/work-4ec16c/3/work  (detached)  (held by live-agent)
[exit 0]

$ /tmp/th-e2e.hpn9/bin/th-new return --all
A new version of treehouse is available: v1.8.1-0.20260925232316-e1d773e4da30 → v3.0.0
Run "treehouse update" to update

🌳 Returning 1 (leased) at ~/.treehouse/work-4ec16c/1/work
🌳 Returning 3 (leased) at ~/.treehouse/work-4ec16c/3/work
🌳 Returned 2 of 2 held worktree(s); 0 skipped; 1 not held.
[exit 0]

$ /tmp/th-e2e.hpn9/bin/th-new status
A new version of treehouse is available: v1.8.1-0.20260925232316-e1d773e4da30 → v3.0.0
Run "treehouse update" to update

base  main  (repository default)
1     available    ~/.treehouse/work-4ec16c/1/work  (detached)
2     available    ~/.treehouse/work-4ec16c/2/work  (detached)
3     available    ~/.treehouse/work-4ec16c/3/work  (detached)
[exit 0]
Evidence: S2: live 2.3.0 get subshell across the upgrade rewrites state next to the key; 3.x takes it over

Source: S2: live 2.3.0 get subshell across the upgrade rewrites state next to the key; 3.x takes it over

=================== S2: issue #151 - 3.x runs while a 2.3.0 'get' subshell is live, then 2.3.0 rewrites state

$ /tmp/th-e2e.hpn9/bin/th-v2.3.0 status

1     leased       ~/.treehouse/work-da83b4/1/work  (held by agent-b)
[exit 0]

$ cat treehouse-state.json (version, leased, holder)
version= None
1 leased= True holder= agent-b seed_known= None
treehouse-state.json

$ SHELL=sub.sh th-v2.3.0 get   (interactive 2.3.0 session; 3.x runs inside it)
  
  🌳 Setting up worktree...
  🌳 Entered worktree at ~/.treehouse/work-da83b4/2/work. Type 'exit' to return.
  --- inside 2.3.0 subshell at /private/tmp/th-e2e.hpn9/home-s2/.treehouse/work-da83b4/2/work; binary upgraded to 3.x; running 3.x status ---
  
  base  main  (repository default)
  1     leased       ~/.treehouse/work-da83b4/1/work  (detached)  (held by agent-b)
  2     in-use       ~/.treehouse/work-da83b4/2/work  (detached)
  --- state now:
  version= 4 [('1', True, 'agent-b'), ('2', None, None)]
  treehouse-state.key
  --- exiting subshell; 2.3.0 now releases the slot and rewrites state ---
  🌳 Worktree returned to pool.
--- after 2.3.0 subshell exit:

$ cat treehouse-state.json (version, leased, holder)
version= None
1 leased= True holder= agent-b seed_known= None
2 leased= None holder= None seed_known= None
treehouse-state.json
treehouse-state.key

$ /tmp/th-e2e.hpn9/bin/th-new status

base  main  (repository default)
1     leased       ~/.treehouse/work-da83b4/1/work  (detached)  (held by agent-b)
2     available    ~/.treehouse/work-da83b4/2/work  (detached)
[exit 0]

$ cat treehouse-state.json (version, leased, holder)
version= 4
1 leased= True holder= agent-b seed_known= True
2 leased= None holder= None seed_known= True
treehouse-state.json
treehouse-state.key

$ get --lease with 3.x (must reuse slot 1, not create slot 3)
got: /tmp/th-e2e.hpn9/home-s2/.treehouse/work-da83b4/2/work

$ /tmp/th-e2e.hpn9/bin/th-new status

base  main  (repository default)
1     leased       ~/.treehouse/work-da83b4/1/work  (detached)  (held by agent-b)
2     leased       ~/.treehouse/work-da83b4/2/work  (detached)  (held by new-work)
[exit 0]
Evidence: S3+S4: recovering a 3.0.0-quarantined pool; tampered/deleted key and truncated state stay quarantined

Source: S3+S4: recovering a 3.0.0-quarantined pool; tampered/deleted key and truncated state stay quarantined

=================== S3: pool already quarantined by 3.0.0 (fd5927e), then upgraded to the fixed build

$ /tmp/th-e2e.hpn9/bin/th-fd5927e status

base  main  (repository default)
1     leased       ~/.treehouse/work-f6afd1/1/work  (detached)  (held by recovered: state file was corrupt or truncated; verify before reuse)
2     leased       ~/.treehouse/work-f6afd1/2/work  (detached)  (held by recovered: state file was corrupt or truncated; verify before reuse)
3     leased       ~/.treehouse/work-f6afd1/3/work  (detached)  (held by recovered: state file was corrupt or truncated; verify before reuse)
[exit 0]

$ /tmp/th-e2e.hpn9/bin/th-new status

base  main  (repository default)
1     leased       ~/.treehouse/work-f6afd1/1/work  (detached)  (held by recovered: state file was corrupt or truncated; verify before reuse)  (check it, then free it with: treehouse return '/tmp/th-e2e.hpn9/home-s3/.treehouse/work-f6afd1/1/work')
2     leased       ~/.treehouse/work-f6afd1/2/work  (detached)  (held by recovered: state file was corrupt or truncated; verify before reuse)  (check it, then free it with: treehouse return '/tmp/th-e2e.hpn9/home-s3/.treehouse/work-f6afd1/2/work')
3     leased       ~/.treehouse/work-f6afd1/3/work  (detached)  (held by recovered: state file was corrupt or truncated; verify before reuse)  (check it, then free it with: treehouse return '/tmp/th-e2e.hpn9/home-s3/.treehouse/work-f6afd1/3/work')
[exit 0]

$ get --lease (fixed build must NOT reuse a recovered slot)
got: /tmp/th-e2e.hpn9/home-s3/.treehouse/work-f6afd1/4/work

$ /tmp/th-e2e.hpn9/bin/th-new return --all

🌳 Leaving 1 at ~/.treehouse/work-f6afd1/1/work leased: it was recovered, so nothing proves it idle and it is only returned by name. Check it, then run: treehouse return '/tmp/th-e2e.hpn9/home-s3/.treehouse/work-f6afd1/1/work'
🌳 Leaving 2 at ~/.treehouse/work-f6afd1/2/work leased: it was recovered, so nothing proves it idle and it is only returned by name. Check it, then run: treehouse return '/tmp/th-e2e.hpn9/home-s3/.treehouse/work-f6afd1/2/work'
🌳 Leaving 3 at ~/.treehouse/work-f6afd1/3/work leased: it was recovered, so nothing proves it idle and it is only returned by name. Check it, then run: treehouse return '/tmp/th-e2e.hpn9/home-s3/.treehouse/work-f6afd1/3/work'
🌳 Returning 4 (leased) at ~/.treehouse/work-f6afd1/4/work
🌳 Returned 1 of 4 held worktree(s); 3 skipped; 0 not held.
[exit 0]

$ /tmp/th-e2e.hpn9/bin/th-new status

base  main  (repository default)
1     leased       ~/.treehouse/work-f6afd1/1/work  (detached)  (held by recovered: state file was corrupt or truncated; verify before reuse)  (check it, then free it with: treehouse return '/tmp/th-e2e.hpn9/home-s3/.treehouse/work-f6afd1/1/work')
2     leased       ~/.treehouse/work-f6afd1/2/work  (detached)  (held by recovered: state file was corrupt or truncated; verify before reuse)  (check it, then free it with: treehouse return '/tmp/th-e2e.hpn9/home-s3/.treehouse/work-f6afd1/2/work')
3     leased       ~/.treehouse/work-f6afd1/3/work  (detached)  (held by recovered: state file was corrupt or truncated; verify before reuse)  (check it, then free it with: treehouse return '/tmp/th-e2e.hpn9/home-s3/.treehouse/work-f6afd1/3/work')
4     available    ~/.treehouse/work-f6afd1/4/work  (detached)
[exit 0]

$ /tmp/th-e2e.hpn9/bin/th-new return /tmp/th-e2e.hpn9/home-s3/.treehouse/work-f6afd1/1/work

🌳 Warning: /tmp/th-e2e.hpn9/home-s3/.treehouse/work-f6afd1/1/work was recovered without a trusted record of the ignored files treehouse seeded into it; any such files are not cleaned up and remain in the worktree.
🌳 Worktree returned to pool.
[exit 0]

$ /tmp/th-e2e.hpn9/bin/th-new status

base  main  (repository default)
1     available    ~/.treehouse/work-f6afd1/1/work  (detached)
2     leased       ~/.treehouse/work-f6afd1/2/work  (detached)  (held by recovered: state file was corrupt or truncated; verify before reuse)  (check it, then free it with: treehouse return '/tmp/th-e2e.hpn9/home-s3/.treehouse/work-f6afd1/2/work')
3     leased       ~/.treehouse/work-f6afd1/3/work  (detached)  (held by recovered: state file was corrupt or truncated; verify before reuse)  (check it, then free it with: treehouse return '/tmp/th-e2e.hpn9/home-s3/.treehouse/work-f6afd1/3/work')
4     available    ~/.treehouse/work-f6afd1/4/work  (detached)
[exit 0]
=================== S4a: adversarial - v4 state beside a tampered key is still quarantined

$ overwrite treehouse-state.key with different 32 bytes

$ /tmp/th-e2e.hpn9/bin/th-new status

base  main  (repository default)
1     leased       ~/.treehouse/work-dfe698/1/work  (detached)  (held by recovered: state file was corrupt or truncated; verify before reuse)  (check it, then free it with: treehouse return '/tmp/th-e2e.hpn9/home-s4a/.treehouse/work-dfe698/1/work')
2     leased       ~/.treehouse/work-dfe698/2/work  (detached)  (held by recovered: state file was corrupt or truncated; verify before reuse)  (check it, then free it with: treehouse return '/tmp/th-e2e.hpn9/home-s4a/.treehouse/work-dfe698/2/work')
3     leased       ~/.treehouse/work-dfe698/3/work  (detached)  (held by recovered: state file was corrupt or truncated; verify before reuse)  (check it, then free it with: treehouse return '/tmp/th-e2e.hpn9/home-s4a/.treehouse/work-dfe698/3/work')
[exit 0]

$ cat treehouse-state.json (version, leased, holder)
version= 4
1 leased= True holder= recovered: state file was corrupt or truncated; verify before reuse seed_known= None
2 leased= True holder= recovered: state file was corrupt or truncated; verify before reuse seed_known= None
3 leased= True holder= recovered: state file was corrupt or truncated; verify before reuse seed_known= None
treehouse-state.json
treehouse-state.key
=================== S4b: adversarial - v4 state whose key was deleted is still quarantined

$ rm treehouse-state.key

$ /tmp/th-e2e.hpn9/bin/th-new status

base  main  (repository default)
1     leased       ~/.treehouse/work-f7f8e1/1/work  (detached)  (held by recovered: state file was corrupt or truncated; verify before reuse)  (check it, then free it with: treehouse return '/tmp/th-e2e.hpn9/home-s4b/.treehouse/work-f7f8e1/1/work')
2     leased       ~/.treehouse/work-f7f8e1/2/work  (detached)  (held by recovered: state file was corrupt or truncated; verify before reuse)  (check it, then free it with: treehouse return '/tmp/th-e2e.hpn9/home-s4b/.treehouse/work-f7f8e1/2/work')
3     leased       ~/.treehouse/work-f7f8e1/3/work  (detached)  (held by recovered: state file was corrupt or truncated; verify before reuse)  (check it, then free it with: treehouse return '/tmp/th-e2e.hpn9/home-s4b/.treehouse/work-f7f8e1/3/work')
[exit 0]
=================== S4c: adversarial - truncated state file is still quarantined

$ truncate treehouse-state.json to 40 bytes

$ /tmp/th-e2e.hpn9/bin/th-new status

treehouse: WARNING: state file /tmp/th-e2e.hpn9/home-s4c/.treehouse/work-031bf0/treehouse-state.json is corrupt or truncated (unexpected end of JSON input); recovering from worktrees found on disk. They are marked leased because their seeded-file inventory is unknown - see `treehouse status`, then remove one with `treehouse destroy <path> --include-leased --yes`.
base  main  (repository default)
1     leased       ~/.treehouse/work-031bf0/1/work  (detached)  (held by recovered: state file was corrupt or truncated; verify before reuse)  (check it, then free it with: treehouse return '/tmp/th-e2e.hpn9/home-s4c/.treehouse/work-031bf0/1/work')
2     leased       ~/.treehouse/work-031bf0/2/work  (detached)  (held by recovered: state file was corrupt or truncated; verify before reuse)  (check it, then free it with: treehouse return '/tmp/th-e2e.hpn9/home-s4c/.treehouse/work-031bf0/2/work')
3     leased       ~/.treehouse/work-031bf0/3/work  (detached)  (held by recovered: state file was corrupt or truncated; verify before reuse)  (check it, then free it with: treehouse return '/tmp/th-e2e.hpn9/home-s4c/.treehouse/work-031bf0/3/work')
[exit 0]
Evidence: S5: return --all skips slots that become recovered while its dirty prompt is open

Source: S5: return --all skips slots that become recovered while its dirty prompt is open

=================== S5: return --all never releases a slot that becomes recovered after listing

$ /tmp/th-e2e.hpn9/bin/th-new status
base  main  (repository default)
1     leased       ~/.treehouse/work-c5fb60/1/work  (detached)  (held by dirty-agent)
2     leased       ~/.treehouse/work-c5fb60/2/work  (detached)  (held by later-agent)
[exit 0]

$ th-new return --all < fifo   (blocks at the dirty-worktree confirmation)

🌳 Returning 1 (leased) at ~/.treehouse/work-c5fb60/1/work
Worktree has uncommitted changes. Clean and return? [Y/n] 
$ while prompt is open: rotate treehouse-state.key

$ answer y
[exit 0]

🌳 Returning 1 (leased) at ~/.treehouse/work-c5fb60/1/work
Worktree has uncommitted changes. Clean and return? [Y/n]    1 skipped: it was recovered since this run listed it, so it is only returned by name. Check it, then run: treehouse return '/tmp/th-e2e.hpn9/home-s5/.treehouse/work-c5fb60/1/work'
🌳 Returning 2 (leased) at ~/.treehouse/work-c5fb60/2/work
   2 skipped: it was recovered since this run listed it, so it is only returned by name. Check it, then run: treehouse return '/tmp/th-e2e.hpn9/home-s5/.treehouse/work-c5fb60/2/work'
🌳 Returned 0 of 2 held worktree(s); 2 skipped; 0 not held.

$ /tmp/th-e2e.hpn9/bin/th-new status

base  main  (repository default)
1     leased       ~/.treehouse/work-c5fb60/1/work  (detached)  (held by recovered: state file was corrupt or truncated; verify before reuse)  (check it, then free it with: treehouse return '/tmp/th-e2e.hpn9/home-s5/.treehouse/work-c5fb60/1/work')
2     leased       ~/.treehouse/work-c5fb60/2/work  (detached)  (held by recovered: state file was corrupt or truncated; verify before reuse)  (check it, then free it with: treehouse return '/tmp/th-e2e.hpn9/home-s5/.treehouse/work-c5fb60/2/work')
[exit 0]

$ dirty file still present in /tmp/th-e2e.hpn9/home-s5/.treehouse/work-c5fb60/1/work ?
dirty
- Outcome: ⚠️ 1 info across 2 runs (4m43s)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 2 issues found → auto-fixed (3) ✅
  • ⚠️ internal/pool/state.go:311 - The fix covers a clean upgrade. It does not cover an upgrade that happens while a 2.x process is still running, which is the scenario in open issue Upgrade from v2.3.0 while a treehouse get is live marks pool slots "recovered: state file was corrupt or truncated" although the file is valid #151 and likely on machines that run agents continuously. Failing sequence: (1) Nix swaps the binary while an agent is inside a 2.x treehouse get subshell. (2) The first 3.x command (even status, since List calls WriteState) adopts the legacy state and writes version 4 plus treehouse-state.key. (3) The subshell exits and the still-running 2.x binary releases the slot. v2.3.0's State struct has no Version or seed fields, so it rewrites the file unversioned. (4) The next 3.x ReadState sees Version==0 next to a key, so legacy is false. Every entry fails validSeedInventoryDigest, and the whole pool is relabeled RecoveredLeaseHolder again. That is the same symptom the intent reports (idle slots quarantined, new work creating fresh slots). It is now recoverable only by a named return per slot. docs/design.md documents this as deliberate, because a 2.x rewrite may have dropped a real 3.x inventory. Telling these cases apart would need new durable state, for example a sidecar recording which slots ever had a non-empty inventory, so that the rewrite could be adopted when none did. Because the remedy adds persistence, it needs the user's decision rather than an auto-fix.
  • ℹ️ cmd/return_cmd.go:183 - Two docs still describe the old behavior. The comment on bulkReturnPreconditions says a leased slot with an empty ID 'keeps the unconditional release it has today', and docs/design.md (the return --all entry) says such a slot gets 'no precondition at all'. Both are wrong now: that branch returns ReleasePreconditions{RefuseRecovered: true} (cmd/return_cmd.go:193). Also, the releaseWorktree doc comment (cmd/return_cmd.go:152-153) was left with one unwrapped overlong line after the edit. Update the wording in both places so they match the code.

🔧 Fix applied.
1 warning still open:

  • ⚠️ README.md:407 - The latest fix round (review round 1 of this run, 'Adopt unversioned 2.x rewrites beside key') changed internal/pool/state.go:140 to adopt unversioned state even when treehouse-state.key exists, and it updated docs/design.md:39 to match. It left the user-facing README behind. README.md:407 still says state 'that lacks inventory integrity data is handled the same way [recovered/quarantined], including state rewritten by an older release after a newer one ran'. That is exactly the 2.x-rewrites-3.x-state case (issue Upgrade from v2.3.0 while a treehouse get is live marks pool slots "recovered: state file was corrupt or truncated" although the file is valid #151), and it is now adopted instead. README.md:408 also says pre-3.0 state is adopted only 'on the first run after upgrading', but an unversioned rewrite is now adopted on every later run too. A user following the recovery section would expect a live 2.x session's rewrite to quarantine their pool and would go looking for recovered entries that do not exist. Fix: drop the 'including state rewritten by an older release after a newer one ran' clause from line 407 (the quarantine still applies to a v4 file whose key is missing or invalid, or whose integrity data fails to verify). Reword line 408 so that any unversioned state written by a pre-3.0 release, including one a still-running 2.x binary writes after the upgrade, is adopted with an empty seed inventory, and note that files 3.0 seeded before such a rewrite are not cleaned up. Same stale claim to recheck: the comment on internal/pool/state_test.go:71-72 ('unversioned state with no state key, which only a pre-3.0 release writes') is still accurate but is now only one of the adopted shapes.

🔧 Fix applied.
2 warnings still open:

  • ⚠️ README.md:407 - The latest fix round (review round 1 of this run, 'Adopt unversioned 2.x rewrites beside key') changed internal/pool/state.go:140 to adopt unversioned state even when treehouse-state.key exists, and it updated docs/design.md:39 to match. It left the user-facing README behind. README.md:407 still says state 'that lacks inventory integrity data is handled the same way [recovered/quarantined], including state rewritten by an older release after a newer one ran'. That is exactly the 2.x-rewrites-3.x-state case (issue Upgrade from v2.3.0 while a treehouse get is live marks pool slots "recovered: state file was corrupt or truncated" although the file is valid #151), and it is now adopted instead. README.md:408 also says pre-3.0 state is adopted only 'on the first run after upgrading', but an unversioned rewrite is now adopted on every later run too. A user following the recovery section would expect a live 2.x session's rewrite to quarantine their pool and would go looking for recovered entries that do not exist. Fix: drop the 'including state rewritten by an older release after a newer one ran' clause from line 407 (the quarantine still applies to a v4 file whose key is missing or invalid, or whose integrity data fails to verify). Reword line 408 so that any unversioned state written by a pre-3.0 release, including one a still-running 2.x binary writes after the upgrade, is adopted with an empty seed inventory, and note that files 3.0 seeded before such a rewrite are not cleaned up. Same stale claim to recheck: the comment on internal/pool/state_test.go:71-72 ('unversioned state with no state key, which only a pre-3.0 release writes') is still accurate but is now only one of the adopted shapes.
  • ⚠️ README.md:366 - The return --all section's "Quarantined" skip bullet still describes the policy that this branch's fix rounds removed. It says an entry whose seed inventory cannot be authenticated leaves a state "no return may clear", and that the run "points at treehouse destroy --include-leased". The code no longer works that way. Commit 2b0bc3e removed ErrSeedInventoryUntrusted from releasableWorktree (internal/pool/pool.go:1077-1093), so a named treehouse return &lt;path&gt; now releases such an entry and prints a warning (pool.go:1046). return --all skips recovered entries and prints treehouse return &lt;path&gt;, not destroy (cmd/return_cmd.go:272 at listing and :306 after listing). The bullet also names a "state version bump" as a cause, but unversioned pre-3.0 state is now adopted rather than quarantined (internal/pool/state.go:140). A user reading this section is told the slot can only be destroyed, which is the opposite of the recovery path documented in README.md:413-417. The later fix rounds updated README.md:159, :279 and :407-417 and the cmd test comment (cmd/return_target_e2e_test.go:350-354) but left this sibling behind. Fix: rename the bullet "Recovered". Say that a slot status reports as recovered (a rotated or invalid key, an unverifiable inventory, a recovery scan, or 3.0.0's upgrade relabeling) is never released by --all, whether it was recovered before or after the listing. The run names treehouse return &lt;path&gt; for each one, and the slot is refused before the dirty confirmation.

🔧 Fix applied.
✅ Re-checked - no issues remain.

✅ No issues found.

⚠️ **Test** - 1 info

✅ No issues found.

  • Live validation: ✅ go - 7 of 7 scenarios driven live against the product
Scenario Result Live Evidence
Bug repro: a valid 2.0.1 pool first run by 3.0.0 has every slot relabeled recovered, and a new get creates a fresh slot ✅ pass live s1-upgrade-2.0.1-with-3.0.0-repro.log
Upgrading a 2.0.1 pool with the fixed build keeps the idle slot available, keeps the agent-b durable lease, and get --lease reuses slot 1 ✅ pass live s1-upgrade-2.0.1-with-fix.log
A still-running 2.3.0 binary rewrites the state unversioned after 3.x wrote v4 plus key; the next 3.x run adopts it (no recovered slots) and reuses idle slots ✅ pass live s2-live-2.3.0-rewrite-after-3x.log
On a pool 3.0.0 already quarantined, status prints the per-slot 'treehouse return <path>' hint and return --all leaves every recovered slot leased with that command, returning only the ordinary lease… ✅ pass live s3-recover-3.0.0-quarantined-pool.log
A named return frees a recovered slot and warns that seeded files are not cleaned up; a dirty one with no TTY is refused (exit 3) and its changes are kept; --force frees it; get then reuses the freed… ✅ pass live s3-recover-3.0.0-quarantined-pool.log
Tamper checks: v4 state with an invalid or deleted key, unversioned state beside an invalid key, unversioned state with a forged seed inventory, and a truncated state file all stay quarantined ✅ pass live s4-adversarial-key-state-guards.log
return --all never releases a slot that becomes recovered after listing: key invalidated while the dirty prompt waits; both slots skipped with the named command and the dirty file kept ✅ pass live s5-return-all-recovered-mid-run-pty.log; also go test ./cmd -run TestReturnAllSkipsSlotsRecoveredAfterListing
  • Built th-v2.0.1, th-v2.3.0, th-fd5927e (3.0.0) and th-new (branch) from git archive into a temp dir; each scenario ran with a throwaway HOME and a local bare-remote repo

  • S1: v2.0.1 pool (one idle slot, one durable lease by agent-b), then status and get --lease with 3.0.0 (reproduces the bug) and with the branch binary

  • S2: v2.3.0 pool, then branch status (writes v4 plus key), then v2.3.0 return rewrites the state unversioned, then branch status and get --lease

  • S3: v2.0.1 pool quarantined by a 3.0.0 run, then branch status hint, return --all, a named return on a clean slot, a named return on a dirty slot with no TTY, return --force, then get --lease reuse

  • S4: tamper cases on a v4 pool: invalid key, deleted key, unversioned state beside an invalid key, unversioned state carrying a forged seed inventory, truncated state file

  • S5: Python pty with a 120x40 window: return --all over two leased slots; the key was invalidated while the dirty prompt was waiting, then answered y

  • go test ./cmd -run 'TestReturnAllSkipsSlotsRecoveredAfterListing|TestStatusNamesReturnForThreeZeroUpgradeQuarantine' -count=1

  • go test ./internal/pool -run 'TestUpgrade_' -count=1

  • ℹ️ internal/pool/state.go - When the state file is corrupt or truncated, the startup warning still says to remove recovered slots with treehouse destroy &lt;path&gt; --include-leased --yes. On the same screen, status offers treehouse return &lt;path&gt;. Both commands work, and the README calls destroy the alternative, but the warning never mentions the named-return path. Informational only; no change is required.

  • Live validation: ✅ go - 6 of 6 scenarios driven live against the product

Scenario Result Live Evidence
Baseline repro: 3.0.0 (fd5927e) run on a valid 2.0.1 pool relabels every slot 'recovered' and writes v4 plus a key ✅ pass live s0-s1-upgrade-from-2.0.1.txt (S0 section)
User upgrades from 2.0.1 to the fixed build: idle slots stay available, the live lease keeps holder 'live-agent', and get --lease reuses slot 1 instead of creating slot 4 ✅ pass live s0-s1-upgrade-from-2.0.1.txt (S1 section)
Issue #151: 3.x runs inside a live 2.3.0 get subshell (writes v4 and key), then 2.3.0 exits and rewrites the state without a version; the next 3.x status shows no recovered slots and get --lease r… ✅ pass live s2-live-2.3.0-rewrite-beside-key.txt
Pool 3.0.0 already quarantined: fixed build keeps those slots leased, status shows treehouse return &lt;path&gt;, get --lease creates a fresh slot, return --all skips them (1 of 4 returned, 3 skippe… ✅ pass live s3-s4-recovered-and-adversarial.txt (S3 section)
Adversarial: v4 state next to a tampered key, v4 state with the key deleted, and a truncated state file are all still quarantined, not taken over ✅ pass live s3-s4-recovered-and-adversarial.txt (S4a/S4b/S4c sections)
Adversarial race: return --all blocked at a dirty-worktree prompt, key rotated before answering y; both slots skipped as recovered, none released, dirty file kept ✅ pass live s5-return-all-recovered-after-listing.txt; also go test ./cmd -run TestReturnAllSkipsSlotsRecoveredAfterListing
  • Built go build binaries from tags v2.0.1 and v2.3.0, base commit fd5927e (3.0.0) and HEAD e1d773e, in disposable git worktrees under /tmp
  • S0: v2.0.1 get --lease/return pool, then th-fd5927e status (bug repro: all slots recovered, v4 plus key written)
  • S1: v2.0.1 pool, then th-new status, th-new get --lease, th-new return --all, th-new status
  • S2: v2.3.0 pool, then SHELL=sub.sh th-v2.3.0 get with th-new status run inside the live subshell (writes v4 and key); 2.3.0 exit rewrites unversioned state; then th-new status and th-new get --lease
  • S3: pool quarantined by th-fd5927e status, then th-new status, th-new get --lease, th-new return --all, th-new return &lt;slot1&gt;
  • S4a/b/c: after th-new ran, overwrite treehouse-state.key / delete it / truncate treehouse-state.json, then th-new status
  • S5: th-new return --all held at the dirty-worktree prompt via a FIFO, key rotated before answering y, then th-new status and a check that the dirty file is still there
  • go test ./cmd -run 'TestReturnAllSkipsSlotsRecoveredAfterListing|TestReturnAllSkipsQuarantinedSlotsWithoutFailing|TestStatusNamesReturnForThreeZeroUpgradeQuarantine' -count=1
  • go test ./internal/pool -run 'TestUpgrade_' -count=1
✅ **Document** - passed

✅ No issues found.

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

✅ No issues found.

…y 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 (#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.
@greptile-apps

greptile-apps Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[High risk] Changes how pool state recovery and quarantine work.

The PR appears safe to merge based on this review; no new actionable issue remains.

Reviews (2) · Last reviewed commit: "no-mistakes(ci): The only failing check ..."

Comment thread internal/pool/state.go Resolved
Comment thread docs/design.md Resolved
…sed 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)
@kunchenguid
kunchenguid merged commit 706ae59 into main Sep 26, 2026
8 checks passed
@kunchenguid
kunchenguid deleted the fm/treehouse-v3-state-upgrade-r1 branch September 26, 2026 00:05
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.

1 participant