Repository navigation
Description
Summary
Request a way to return a leased worktree only if it is clean and quiet, checked and acted on as one step under treehouse's own lock: no uncommitted changes, no commits that are not on a remote, and no processes in the slot. If any of those fail, treehouse keeps the slot and the lease and exits with a distinct code that says what blocked. If all pass, it resets and returns the slot.
Something like:
treehouse return <path|name> --if-lease-id <id> --if-clean
(The flag name is only a suggestion.)
Use case
dibs is a lease manager for local dev resources. It is adding an opt-in treehouse-worktree adapter. dibs acquires slots through treehouse get --lease or registers an existing slot with treehouse lease. It never allocates or resets slots itself. When a lease ends (released, or reclaimed after its owner process is proven dead or its TTL expired), dibs hands the slot back with the conditional treehouse return <path> --if-lease-id <id>.
dibs must never throw away work that has not landed. Before it returns a slot, it checks:
git statusshows no uncommitted changes.- HEAD is reachable from a remote ref, so no commits are unpushed.
treehouse statuslists no processes in the slot.
If any check fails, dibs keeps the lease and reports what blocked the return.
The race
These checks run in dibs, and the return runs later in a separate treehouse process. Between the last check and the reset inside treehouse return, a process can start in the slot and make a commit. Example: an agent shell attaches with treehouse enter and runs git commit. return then terminates that process and resets the slot. The tree is clean, so return does not refuse. return does not check for unpushed commits, so it resets the slot anyway. A commit on a named branch survives in the shared repository but is no longer checked out anywhere. A commit made on a detached HEAD is reachable only from the reflog.
dibs narrows the window: it checks processes and unlanded work again right before it calls return, and the slot stays leased throughout, so get never hands it to anyone else. But only treehouse can close the window. It owns the slot lock, and it already terminates processes and resets under that lock. Running "is it clean, unpushed-free, and quiet?" in the same critical section as the reset would make the guarantee exact.
Proposed behavior
- Under the slot's lock, after treehouse terminates lingering processes, or instead of terminating them (whichever fits; refusing on any live process is the most conservative option):
- refuse if the worktree has uncommitted changes (including untracked files that are not ignored),
- refuse if HEAD (or any local branch created in the slot) has commits that no remote ref contains,
- otherwise reset and return as today.
- On refusal: keep the lease, change nothing, and exit with a distinct non-zero code. A
--jsonreason (dirty,unpushed,processes) would let callers report exactly what blocked. - Compose with
--if-lease-id/--if-lease-holder, so a stale caller still cannot touch a reassigned slot. - Never prompt. This is for non-interactive callers.
Offer
We are happy to implement this and send a PR if the shape sounds right to you. Pointers to where the return critical section lives, or a different flag or exit-code design you prefer, are welcome.
Activity
feat(adapter): add Treehouse worktree lease support (#50)
kunchenguid commentedon Nov 16, 2026
Speaking as Kun's firstmate: thanks for the detailed write-up, @Dematom1, and for the offer to implement it.
I checked latest main (
bd3cc28).treehouse returntoday only confirms on uncommitted changes (and--forceor a non-TTY skips/aborts that), and it does not check for unpushed commits or refuse on live processes; it terminates them. So the race you describe is real and only treehouse can close it under its own lock.VISION.md check:
treehouse returnkeeps behaving exactly as it does now; the new checks run only when the caller asks for them.I've labeled this
ready-for-pr, and a PR from you is welcome. Pointers: the single-worktree path isreleaseWorktreeincmd/return_cmd.go(which already composes--if-lease-id/--if-lease-holderviapool.ReleasePreconditionsininternal/pool/pool.go), and exit codes live incmd/exit.go(ExitNotReturned = 3is the existing "not returned" code). Please cover the jj backend as well as git (or refuse clearly where "unpushed" cannot be verified), and include realistic end-to-end tests for the dirty, unpushed and live-process refusals, plus the race where a commit lands right before the return. VISION asks for that on lifecycle and destructive changes. Please also raise the PR via no-mistakes, since CI requires it.fix(return): make --if-clean Git-only and refuse jj workspaces
feat(pool): add return --if-clean (#217)
kunchenguid commentedon Nov 18, 2026
Speaking as Kun's firstmate: implemented by #217 (
treehouse return --if-clean), now merged as 38fcb38. Thanks @Dematom1 for both the proposal and the implementation.