Repository navigation
fix(pool): reuse lowest available slot number - #206
artburkart wants to merge 1 commit into
Conversation
[Medium impact] The PR appears safe to merge. Reviews (1) · Last reviewed commit: "fix(pool): reuse lowest available slot n..." · Reviewed by Greptile |
|
Speaking as Kun's firstmate: thanks @artburkart. I reviewed the diff (slot-number selection in Nothing is needed from you while CI runs. One heads-up so it doesn't surprise you later: I'm classifying this as a change to default behavior, which means Kun decides it rather than it auto-merging. Today an unconfigured Contract-class: new-default (the unconfigured acquisition now picks the lowest free slot number instead of max+1). VISION per-rule (
|
|
Speaking as Kun's firstmate: a quick update, @artburkart. I reran the Windows job on Nothing here is waiting on you. This is still the new-default call for Kun I described above, plus the repo-wide Windows test budget. I've passed both to him. |
What Changed
destroyorprunefrees a number, the next acquire takes that number again rather than growing the pool past it.freeTemplatedSlot), it now steps to the next unused number with each attempt. Before, it walked a fixed consecutive range. Now it skips numbers already in state when a candidate's worktree path is occupied.TestNextSlotNumber_ReusesTheLowestFreedNumberandTestFreeTemplatedSlot_SkipsRegisteredNumbersAfterAnOccupiedPath.Risk Assessment
✅ Low: The change is small and runs under the state lock. Reusing a freed number at a path that is still registered is already handled: git uses
worktree add --force, jj forgets the stale path-keyed workspace before adding, the built-in layout reclaims an empty leftover directory, and the templated layout skips an occupied path. The new tests check the 'lowest unused positive number' spec and the skip behaviour.Testing
I built the real treehouse CLI and ran it against a throwaway git remote and clone, with HOME isolated. After slot 2 was destroyed, the next
getreused slot 2 and the one after it created slot 4. With a templatedworktree_path,getwarned about and skipped an occupied path for slot 1, reused the freed slot 2, then skipped the registered slots 3 and 4 and created slot 5. The foreign directory was left untouched. A binary built from the base commit handed out slot 4 instead of 2, which confirms the change fixes the old behavior. The new focused unit tests pass. All temp directories were removed afterwards.treehouse get --leasereuses slot 2 (local CLI, disposable repo)getcreates slot 4 and no number is used twiceEvidence: Scenario 1 CLI transcript: freed slot 2 reused, then slot 4
Evidence: Scenario 2 CLI transcript: templated path, occupied slot 1 skipped, slot 2 reused, then 5
Evidence: Baseline transcript (pre-fix binary gave slot 4 instead of 2)
Pipeline
Updates from git push no-mistakes
⏭️ **Intent** - skipped
Step was skipped.
✅ **Rebase** - passed
✅ No issues found.
internal/pool/pool.go:1534- Recovery backups are keyed by slot name only (recoveryBackupDir(poolDir, wt.Name)in internal/pool/recovered.go:96), andstatusreports one for any entry with that name (internal/pool/pool.go:1226). Before this change, a slot number was reused only when the highest slot was freed. Now any freed number is reused, so this case is more common. Example: slot 3 is recovered and its untracked files go totreehouse-recovered-backup-<pool>-3. Slot 3 is then destroyed and a latergetcreates a new slot 3.statusnow shows the old backup folder on the fresh slot. Nothing is lost: the folder is kept, and a later recovery writes into a suffixed subfolder. The old pattern already allowed this case, so no change is required.✅ **Test** - passed
✅ No issues found.
treehouse get --leasereuses slot 2 (local CLI, disposable repo)getcreates slot 4 and no number is used twicego buildof the target commit, driven against a disposable bare remote, clone and HOME under /tmpScenario 1:treehouse get --leasex3 →return+destroy --yesslot 2 →get --leasetwice →statusScenario 2:get --lease --worktree-path '{repo_parent}/{repo}-{slot}'x4 → destroy slots 1 and 2 → put a foreign directory at proj-1 →gettwice →status→ls proj-1Baseline: same steps as scenario 1 with a binary built from f168807 (gave slot 4)go test ./internal/pool/ -run 'TestFreeTemplatedSlot_SkipsRegisteredNumbersAfterAnOccupiedPath|NextSlot|...'✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.