Skip to content

feat(bin): give each project its own leased worktree pool on the repo's filesystem - #1142

Closed
adibirzu wants to merge 9 commits into
kunchenguid:mainfrom
adibirzu:fm/fm-pool-relocation
Closed

adibirzu wants to merge 9 commits into
kunchenguid:mainfrom
adibirzu:fm/fm-pool-relocation

Conversation

@adibirzu

@adibirzu adibirzu commented Jul 27, 2026 •

Copy link
Copy Markdown

Intent

PR #1142 (per-project worktree pools): fix the two Behavior-tests-Herdr CI failures — post-create abort fixture updated for leased acquisition, and the projected-teardown focus regression root-caused (treehouse return --force killed the pane's shell before the presentation restore block) and fixed by closing the presentation pane before returning the worktree; 22/22 presentation e2e x3 + 132/132 backend suite green locally. Goal: green Herdr CI lane + the Require-no-mistakes signature on PR #1142.

What Changed

  • Spawn now acquires crew worktrees through treehouse get --lease from a per-project pool placed on the repo's own filesystem. The new bin/fm-treehouse-lib.sh selects the pool by running treehouse under a per-command HOME and verifies the acquired worktree is colocated with the object store, preventing the cross-filesystem split that made no-mistakes init/axi run hang inside git's gitfile open.
  • Teardown and the spawn-abort cleanup path now close the Herdr presentation pane before returning the leased worktree (previously treehouse return --force killed the pane's shell first, letting Herdr's last-pane cleanup destroy the workspace and steal focus), and lease failures now surface treehouse's stderr instead of a generic error. Watcher lock checks also resolve identity paths before comparing.
  • Tests and docs follow the new flow: leased-acquisition and post-create abort fixtures, treehouse stubs in every fakebin, new watcher-lock and pool-settle coverage (11/11 settle, 22/22 Herdr presentation e2e across three runs), plus pool/spawn/teardown doc alignment and recorded verification evidence.

Risk Assessment

✅ Low: All three accepted round-1 findings are fixed correctly in 94148ff (abort-path pane-close-before-return ordering, teardown abort instead of focus-unsafe return under lock contention, lease stderr surfaced with proper temp-file hygiene), no test pins the replaced behaviors, and the only remaining item is an informational version-skew note that CI will confirm.

Testing

Ran the intent-targeted suites against the real Herdr 0.7.4 lab: the presentation e2e passed 22/22 in three consecutive runs with both previously-failing CI checks (post-create abort serialization with focus restoration, and task-pane close restoring the captain's workspace/tab after Herdr's focus steal) green every time; the leased-acquisition/pool-relocation suite passed 11/11; and the teardown, watcher-lock, and backend suites covering the other changed scripts all passed. No UI surface exists for this terminal-multiplexer change, so the real-Herdr lab transcripts serve as the product-level evidence; the full 132-test backend suite is owned by remote CI per repo policy and was deliberately not re-run locally.

Evidence: Distilled evidence summary (both fixed CI checks + x3 stability tally)

## The two previously-failing Herdr CI checks, now green in a real Herdr lab (Herdr 0.7.4): ok - real Herdr lab: concurrent post-create abort cleanup stays serialized with exact focus restoration ok - real Herdr lab: exact task-pane close restores the exact captain workspace/tab after Herdr's raw focus steal ## Presentation e2e stability, three consecutive full runs: run 1: 22/22 ok, 0 failures (duration_ms=72440) run 2: 22/22 ok, 0 failures (duration_ms=72315) run 3: 22/22 ok, 0 failures (duration_ms=72177)

# PR #1142 test-phase evidence (branch fm/fm-pool-relocation @ 94148ff)

## The two previously-failing Herdr CI checks, now green in a real Herdr lab (Herdr 0.7.4):
ok - real Herdr lab: concurrent post-create abort cleanup stays serialized with exact focus restoration
ok - real Herdr lab: exact task-pane close restores the exact captain workspace/tab after Herdr's raw focus steal

## Presentation e2e stability, three consecutive full runs:
run 1: 22/22 ok, 0 failures (duration_ms=72440)
run 2: 22/22 ok, 0 failures (duration_ms=72315)
run 3: 22/22 ok, 0 failures (duration_ms=72177)

## Post-create abort fixture / leased worktree acquisition (fm-spawn-worktree-settle, 11/11):
ok - a single transient stale pane_current_path read is not accepted as the worktree
ok - an already-settled pane confirms via the existing inter-poll sleep, not an extra full cycle
ok - the pane receives a plain cd and nothing that changes its HOME
ok - treehouse is leased under the pool HOME firstmate resolved for the repo
ok - a pane that never enters the leased worktree fails the spawn loudly
ok - a repo on $HOME's filesystem pools on that filesystem
ok - each project resolves to its own pool root
ok - two projects with the same directory name still get separate pools
ok - a repo on another filesystem pools at that filesystem's mount point
ok - the colocation check distinguishes colocated, split, and undeterminable
ok - the mount-point walk resolves to a real ancestor directory

## Other suites owning the changed scripts (fm-teardown.sh, fm-watch-arm.sh, fm-backend.sh):
FM_TEST_END 2026-07-28T10:05:19Z tests/fm-teardown.test.sh exit=0 duration_ms=17060 gate_skip=false
FM_TEST_END 2026-07-28T10:07:00Z tests/fm-watcher-lock.test.sh exit=0 duration_ms=101369 gate_skip=false
FM_TEST_END 2026-07-28T10:07:10Z tests/fm-backend.test.sh exit=0 duration_ms=9615 gate_skip=false
Evidence: Presentation e2e full transcript, run 1
FM_TEST_BEGIN 2026-07-28T10:01:02Z tests/fm-backend-herdr-presentation-e2e.test.sh family=real-herdr-gated expected_gate_skip=herdr
ok - real Herdr lab: flag-off spawn retains the Stage 1 Herdr command sequence with zero ordering calls
ok - real Herdr lab: every projected create, task-tab create, seeded prune, and move preserves active workspace and tab
warning: herdr presentation cleanup could not verify the exact pane; refusing focus-unsafe pane close
ok - real Herdr lab: active seeded-tab pruning refuses the exact pane and preserves exact focus
ok - real Herdr lab: bounded lock contention warns and falls back flat without projection or focus drift
ok - real Herdr lab: concurrent primary workers form one stable contiguous block without active workspace/tab drift
ok - real Herdr lab: forced workspace.move failure leaves a successful worker in default order with a warning and no cleanup
ok - real Herdr lab: concurrent post-create abort cleanup stays serialized with exact focus restoration
ok - real Herdr lab: Treehouse commands and metadata shape are byte-identical except for Herdr container IDs
ok - real Herdr lab: exact task-pane close restores the exact captain workspace/tab after Herdr's raw focus steal
ok - real Herdr lab: concurrent projected cleanup is serialized and leaves active workspace/tab unchanged
ok - real Herdr lab: three repeated concurrent create/order/cleanup waves have zero active workspace or tab drift
ok - real Herdr lab: primary presentation opt-in inherits into real secondmate homes
ok - real Herdr lab: primary and two secondmate homes each own a top-level contiguous child block
ok - real Herdr lab: concurrent primary/A/B spawns preserve parent order and exact focus
ok - real Herdr lab: session lock contention from a secondmate home falls back flat with no journal
ok - real Herdr lab: Hi Bit and Wheelhouse-style same-identity restarts reclaim one nested space with exact focus and idempotence
ok - real Herdr lab: secondmate restart binding and reclaim stay isolated to the exact child home and parent
ok - real Herdr lab: concurrent cross-home recoveries replace exact husks under one session lock with no focus drift
ok - real Herdr lab: legacy projection labels and flat secondmate tabs are left unmigrated
ok - real Herdr lab: multi-home exact-pane teardowns restore captain focus without workspace close authority
warning: no exact herdr presentation token match for missing1; leaving any stale space untouched and spawning flat
warning: no exact herdr presentation token match for renamed1; leaving any stale space untouched and spawning flat
warning: 2 exact herdr presentation token matches for duplicate1 are quarantined; inspecting only for duplicate-agent risk
warning: quarantined herdr presentation for duplicate1 is dead or agent-free; exact bound reclaim may proceed, otherwise spawning flat
warning: 2 exact herdr presentation token matches for duplicate1 are quarantined; inspecting only for duplicate-agent risk
error: quarantined herdr presentation for duplicate1 has a live pane; refusing duplicate launch
ok - real Herdr lab: missing, renamed, and duplicate tokens trigger zero destructive or adoptive calls, and live duplicate risk refuses launch
ok - real Herdr lab validation completed on Herdr 0.7.4 with the default-session tripwire intact
FM_TEST_END 2026-07-28T10:02:15Z tests/fm-backend-herdr-presentation-e2e.test.sh exit=0 duration_ms=72440 gate_skip=false
FM_TEST_SUMMARY total=1 failed=0 skipped_gate=0 duration_ms=72467
FM_TEST_SUMMARY_FAMILY family=real-herdr-gated count=1 duration_ms=72440 failed=0
FM_TEST_SLOWEST rank=1 script=tests/fm-backend-herdr-presentation-e2e.test.sh duration_ms=72440
Evidence: Presentation e2e full transcript, run 2
FM_TEST_BEGIN 2026-07-28T10:02:25Z tests/fm-backend-herdr-presentation-e2e.test.sh family=real-herdr-gated expected_gate_skip=herdr
ok - real Herdr lab: flag-off spawn retains the Stage 1 Herdr command sequence with zero ordering calls
ok - real Herdr lab: every projected create, task-tab create, seeded prune, and move preserves active workspace and tab
warning: herdr presentation cleanup could not verify the exact pane; refusing focus-unsafe pane close
ok - real Herdr lab: active seeded-tab pruning refuses the exact pane and preserves exact focus
ok - real Herdr lab: bounded lock contention warns and falls back flat without projection or focus drift
ok - real Herdr lab: concurrent primary workers form one stable contiguous block without active workspace/tab drift
ok - real Herdr lab: forced workspace.move failure leaves a successful worker in default order with a warning and no cleanup
ok - real Herdr lab: concurrent post-create abort cleanup stays serialized with exact focus restoration
ok - real Herdr lab: Treehouse commands and metadata shape are byte-identical except for Herdr container IDs
ok - real Herdr lab: exact task-pane close restores the exact captain workspace/tab after Herdr's raw focus steal
ok - real Herdr lab: concurrent projected cleanup is serialized and leaves active workspace/tab unchanged
ok - real Herdr lab: three repeated concurrent create/order/cleanup waves have zero active workspace or tab drift
ok - real Herdr lab: primary presentation opt-in inherits into real secondmate homes
ok - real Herdr lab: primary and two secondmate homes each own a top-level contiguous child block
ok - real Herdr lab: concurrent primary/A/B spawns preserve parent order and exact focus
ok - real Herdr lab: session lock contention from a secondmate home falls back flat with no journal
ok - real Herdr lab: Hi Bit and Wheelhouse-style same-identity restarts reclaim one nested space with exact focus and idempotence
ok - real Herdr lab: secondmate restart binding and reclaim stay isolated to the exact child home and parent
ok - real Herdr lab: concurrent cross-home recoveries replace exact husks under one session lock with no focus drift
ok - real Herdr lab: legacy projection labels and flat secondmate tabs are left unmigrated
ok - real Herdr lab: multi-home exact-pane teardowns restore captain focus without workspace close authority
warning: no exact herdr presentation token match for missing1; leaving any stale space untouched and spawning flat
warning: no exact herdr presentation token match for renamed1; leaving any stale space untouched and spawning flat
warning: 2 exact herdr presentation token matches for duplicate1 are quarantined; inspecting only for duplicate-agent risk
warning: quarantined herdr presentation for duplicate1 is dead or agent-free; exact bound reclaim may proceed, otherwise spawning flat
warning: 2 exact herdr presentation token matches for duplicate1 are quarantined; inspecting only for duplicate-agent risk
error: quarantined herdr presentation for duplicate1 has a live pane; refusing duplicate launch
ok - real Herdr lab: missing, renamed, and duplicate tokens trigger zero destructive or adoptive calls, and live duplicate risk refuses launch
ok - real Herdr lab validation completed on Herdr 0.7.4 with the default-session tripwire intact
FM_TEST_END 2026-07-28T10:03:37Z tests/fm-backend-herdr-presentation-e2e.test.sh exit=0 duration_ms=72315 gate_skip=false
FM_TEST_SUMMARY total=1 failed=0 skipped_gate=0 duration_ms=72345
FM_TEST_SUMMARY_FAMILY family=real-herdr-gated count=1 duration_ms=72315 failed=0
FM_TEST_SLOWEST rank=1 script=tests/fm-backend-herdr-presentation-e2e.test.sh duration_ms=72315
Evidence: Presentation e2e full transcript, run 3
FM_TEST_BEGIN 2026-07-28T10:03:42Z tests/fm-backend-herdr-presentation-e2e.test.sh family=real-herdr-gated expected_gate_skip=herdr
ok - real Herdr lab: flag-off spawn retains the Stage 1 Herdr command sequence with zero ordering calls
ok - real Herdr lab: every projected create, task-tab create, seeded prune, and move preserves active workspace and tab
warning: herdr presentation cleanup could not verify the exact pane; refusing focus-unsafe pane close
ok - real Herdr lab: active seeded-tab pruning refuses the exact pane and preserves exact focus
ok - real Herdr lab: bounded lock contention warns and falls back flat without projection or focus drift
ok - real Herdr lab: concurrent primary workers form one stable contiguous block without active workspace/tab drift
ok - real Herdr lab: forced workspace.move failure leaves a successful worker in default order with a warning and no cleanup
ok - real Herdr lab: concurrent post-create abort cleanup stays serialized with exact focus restoration
ok - real Herdr lab: Treehouse commands and metadata shape are byte-identical except for Herdr container IDs
ok - real Herdr lab: exact task-pane close restores the exact captain workspace/tab after Herdr's raw focus steal
ok - real Herdr lab: concurrent projected cleanup is serialized and leaves active workspace/tab unchanged
ok - real Herdr lab: three repeated concurrent create/order/cleanup waves have zero active workspace or tab drift
ok - real Herdr lab: primary presentation opt-in inherits into real secondmate homes
ok - real Herdr lab: primary and two secondmate homes each own a top-level contiguous child block
ok - real Herdr lab: concurrent primary/A/B spawns preserve parent order and exact focus
ok - real Herdr lab: session lock contention from a secondmate home falls back flat with no journal
ok - real Herdr lab: Hi Bit and Wheelhouse-style same-identity restarts reclaim one nested space with exact focus and idempotence
ok - real Herdr lab: secondmate restart binding and reclaim stay isolated to the exact child home and parent
ok - real Herdr lab: concurrent cross-home recoveries replace exact husks under one session lock with no focus drift
ok - real Herdr lab: legacy projection labels and flat secondmate tabs are left unmigrated
ok - real Herdr lab: multi-home exact-pane teardowns restore captain focus without workspace close authority
warning: no exact herdr presentation token match for missing1; leaving any stale space untouched and spawning flat
warning: no exact herdr presentation token match for renamed1; leaving any stale space untouched and spawning flat
warning: 2 exact herdr presentation token matches for duplicate1 are quarantined; inspecting only for duplicate-agent risk
warning: quarantined herdr presentation for duplicate1 is dead or agent-free; exact bound reclaim may proceed, otherwise spawning flat
warning: 2 exact herdr presentation token matches for duplicate1 are quarantined; inspecting only for duplicate-agent risk
error: quarantined herdr presentation for duplicate1 has a live pane; refusing duplicate launch
ok - real Herdr lab: missing, renamed, and duplicate tokens trigger zero destructive or adoptive calls, and live duplicate risk refuses launch
ok - real Herdr lab validation completed on Herdr 0.7.4 with the default-session tripwire intact
FM_TEST_END 2026-07-28T10:04:54Z tests/fm-backend-herdr-presentation-e2e.test.sh exit=0 duration_ms=72177 gate_skip=false
FM_TEST_SUMMARY total=1 failed=0 skipped_gate=0 duration_ms=72206
FM_TEST_SUMMARY_FAMILY family=real-herdr-gated count=1 duration_ms=72177 failed=0
FM_TEST_SLOWEST rank=1 script=tests/fm-backend-herdr-presentation-e2e.test.sh duration_ms=72177
Evidence: Leased acquisition / worktree settle transcript (11/11)
FM_TEST_BEGIN 2026-07-28T10:00:49Z tests/fm-spawn-worktree-settle.test.sh family=backend-dispatch expected_gate_skip=none
ok - a single transient stale pane_current_path read is not accepted as the worktree
ok - an already-settled pane confirms via the existing inter-poll sleep, not an extra full cycle
ok - the pane receives a plain cd and nothing that changes its HOME
ok - treehouse is leased under the pool HOME firstmate resolved for the repo
ok - a pane that never enters the leased worktree fails the spawn loudly
ok - a repo on $HOME's filesystem pools on that filesystem
ok - each project resolves to its own pool root
ok - two projects with the same directory name still get separate pools
ok - a repo on another filesystem pools at that filesystem's mount point
ok - the colocation check distinguishes colocated, split, and undeterminable
ok - the mount-point walk resolves to a real ancestor directory
# all fm-spawn-worktree-settle tests passed
FM_TEST_END 2026-07-28T10:00:55Z tests/fm-spawn-worktree-settle.test.sh exit=0 duration_ms=5990 gate_skip=false
FM_TEST_SUMMARY total=1 failed=0 skipped_gate=0 duration_ms=6018
FM_TEST_SUMMARY_FAMILY family=backend-dispatch count=1 duration_ms=5990 failed=0
FM_TEST_SLOWEST rank=1 script=tests/fm-spawn-worktree-settle.test.sh duration_ms=5990
Evidence: Teardown, watcher-lock, and backend suite transcript
FM_TEST_BEGIN 2026-07-28T10:05:02Z tests/fm-teardown.test.sh family=pr-forge expected_gate_skip=none
ok - local-only worktree with HEAD on a fork remote is torn down (fix holds)
ok - teardown prompts tasks-axi backlog refresh when compatible
ok - teardown honors config/backlog-backend=manual even when tasks-axi is compatible
ok - local-only worktree with truly unpushed work is refused (safety preserved)
ok - local-only worktree with work merged into local main is torn down (no regression)
ok - no-mistakes worktree with HEAD on origin is torn down (no regression)
ok - no-mistakes worktree with genuinely unlanded work is refused (safety preserved)
ok - local-only worktree with unpushed work is torn down under --force (escape hatch)
ok - herdr teardown removes pane-owned escalation dedupe state
ok - herdr projection teardown retires its journal only after confirming the exact recorded pane is gone
ok - herdr projection teardown retains the stale journal and attempts no workspace cleanup when exact-pane close is unconfirmed
ok - squash-merged + deleted-branch worktree (PR merged) is torn down (the fix)
ok - squash-merged PR accepts a local HEAD that is an ancestor of the final PR head
ok - teardown discovers a merged PR by branch name and tears down when no pr= was ever recorded
ok - squash-merged PR accepts replayed unpushed local patches contained in the PR head
ok - merged PR does not allow teardown after a later local commit
ok - fm-pr-check does not refresh PR head after HEAD moves
ok - fm-pr-check records the remote PR head when the local worktree lags
ok - worktree whose content already landed in the default branch is torn down (content fallback)
ok - content fallback refreshes origin default before comparing trees
ok - dirty worktree is refused even when its committed work has landed (dirty always wins)
ok - gh lookup error with content not in default refuses (fail-safe)
ok - provably-stale worktree index.lock (old, no live holder) is cleared and teardown succeeds
ok - live-held worktree index.lock is never removed and teardown refuses
ok - lsof errors leave worktree index.lock in place and refuse teardown
ok - stale lock cleanup rechecks and refuses dirty worktree before return
ok - normal repo index.lock is resolved from the worktree and cleared when stale
ok - lock mtime read failures leave worktree index.lock in place and refuse teardown
ok - transient index.lock cleared after first failed return is retried successfully without force-remove
ok - persistent index.lock exhausts retries and refuses without force-removing the lock
ok - empty retry wait overrides use the default without aborting teardown
ok - fractional legacy retry wait remains supported without arithmetic
FM_TEST_END 2026-07-28T10:05:19Z tests/fm-teardown.test.sh exit=0 duration_ms=17060 gate_skip=false
FM_TEST_BEGIN 2026-07-28T10:05:19Z tests/fm-watcher-lock.test.sh family=watcher-wake-lock expected_gate_skip=none
ok - simultaneous watcher starts leave exactly one live process
ok - fm_pid_identity is locale-invariant across LC_ALL/LC_TIME
ok - watcher lock identity resolves symlinked and physical home names to one identity
ok - fm_lock_paths_equal keeps unresolvable and empty paths distinct
ok - Linux process identity ignores simulated btime changes
ok - Linux process identity detects pid reuse
ok - killed watcher stale lock is reclaimed
ok - live watcher lock with stale heartbeat is actionable
ok - guard banner leads when down with pending wakes (repair-after-drain) and stays silent when fresh
ok - concurrent fm_lock_try_acquire yields exactly one winner
ok - dead-pid stale lock is reclaimed by a single acquirer
ok - concurrent stale-lock steal yields exactly one winner
ok - live steal mutex is not reclaimed
ok - live-held lock is not stolen
ok - empty mid-acquire lock keeps a minimum grace
ok - late original claimant cannot claim a recreated lock
ok - paused mid-acquire claimant backs off to active stealer
ok - watch restart refuses to signal a reused pid
ok - watch restart attaches to a verified healthy peer and later surfaces a successor gap
ok - watcher self-evicts when the lock pid no longer names it
ok - arm turns clean self-eviction without a successor into a typed failure
ok - arm attaches to a live fresh watcher and fails loudly when that cycle has no successor
ok - attached arm signals record a classified lifecycle entry
ok - arm starts+confirms a fresh watcher on a clean lock and self-heals a dead-pid lock (never healthy off a dead pid)
ok - arm cleans child watcher and temp output on HUP
ok - arm propagates an immediate watcher wake before confirmation
ok - arm attaches to a peer watcher after child stands down and surfaces a missing successor
watcher: lock held by live pid 890946 but heartbeat is stale for 838548379s (>300s); inspect or stop that watcher before re-arming.
ok - arm reports FAILED and exits non-zero when no fresh watcher can be confirmed
ok - cycle-exit ledger links a verified successor and remains size-capped
ok - SIGSTOP distinguishes live PID from stale beacon and termination records the exit class
FM_TEST_END 2026-07-28T10:07:00Z tests/fm-watcher-lock.test.sh exit=0 duration_ms=101369 gate_skip=false
FM_TEST_BEGIN 2026-07-28T10:07:00Z tests/fm-backend.test.sh family=backend-dispatch expected_gate_skip=none
ok - fm_backend_name: FM_BACKEND env > config/backend > default tmux
ok - fm_backend_detect: no markers -> undetected, HERDR_ENV=1 -> herdr, $TMUX -> tmux, CMUX_WORKSPACE_ID -> cmux, nested combinations resolve innermost-first
ok - fm_backend_detect: falls back to __CFBundleIdentifier=com.cmuxterm.app when CMUX_WORKSPACE_ID is absent (signal bundle-id; foreign bundle ids rejected)
ok - fm_backend_detect: the cmux fallback signals are macOS-only (inert on a non-Darwin uname)
ok - fm_backend_detect: an inherited cmux bundle id never outranks $TMUX or HERDR_ENV (tmux/herdr-inside-cmux false positive absorbed)
ok - fm_backend_detect: ancestry fallback matches the lsappinfo-resolved (bundle-id) cmux app pid in the parent chain
ok - fm_backend_detect: ancestry fallback matches a bundle-shaped cmux comm path at any install location when lsappinfo cannot resolve a pid
ok - fm_backend_detect: ancestry fallback stops undetected at launchd (a reparented tmux server never reaches cmux)
ok - fm_backend_name: a fallback-detected cmux prints a NOTICE naming the fallback signal; the primary-marker notice is unchanged
ok - fm_backend_name: auto-detect selects herdr or cmux (loud notice) or tmux (silent, including nested tmux-in-herdr/tmux-in-cmux)
ok - fm_backend_name: an explicit FM_BACKEND or config/backend setting always wins over runtime auto-detection, including an ambient cmux marker
ok - fm_backend_validate: implemented adapters accepted, unknown and blocked codex-app backends refused loudly
ok - zsh: shell-portable backend matching skipped (zsh not found)
ok - bash: fm_backend_source recognizes known backends and rejects unknown ones
ok - fm_backend_validate_spawn: all implemented lifecycle backends are spawn-supported
ok - fm_meta_get / fm_backend_of_meta: read key=value, default backend to tmux
ok - fm_backend_resolve_selector: session:window literal, exact task id first, legacy fm-<id> label fallback, ad hoc bare name via tmux list-windows
ok - fm_backend_of_selector: exact task ids, legacy fm-<id> labels, and matching explicit targets inherit metadata backend
ok - fm-send.sh: explicit tmux targets are verified, while --key/plain/slash send command shape stays old-compatible
ok - fm-peek.sh: capture-pane invocation and output are byte-identical old vs new
ok - fm-spawn.sh: a project reached through a symlinked prefix (e.g. macOS /tmp -> /private/tmp) does not trip the isolation guard's false refusal
ok - fm-teardown.sh: treehouse return + tmux kill-window command log is byte-identical old vs new for a scout task
ok - fm-spawn.sh --backend bogus is refused loudly
ok - fm-spawn.sh --backend codex-app is refused
ok - fm-spawn.sh honors FM_BACKEND and refuses an unimplemented value loudly
ok - fm-spawn.sh: an explicit --backend tmux resolves silently and writes no backend= (missing means tmux)
ok - fm-spawn.sh: explicit --backend tmux wins over an ambient HERDR_ENV=1 auto-detect marker
ok - fm-spawn.sh: auto-detect resolves nested tmux-in-herdr to tmux and stays silent end to end
FM_TEST_END 2026-07-28T10:07:10Z tests/fm-backend.test.sh exit=0 duration_ms=9615 gate_skip=false
FM_TEST_SUMMARY total=3 failed=0 skipped_gate=0 duration_ms=128104
FM_TEST_SUMMARY_FAMILY family=backend-dispatch count=1 duration_ms=9615 failed=0
FM_TEST_SUMMARY_FAMILY family=pr-forge count=1 duration_ms=17060 failed=0
FM_TEST_SUMMARY_FAMILY family=watcher-wake-lock count=1 duration_ms=101369 failed=0
FM_TEST_SLOWEST rank=1 script=tests/fm-watcher-lock.test.sh duration_ms=101369
FM_TEST_SLOWEST rank=2 script=tests/fm-teardown.test.sh duration_ms=17060
FM_TEST_SLOWEST rank=3 script=tests/fm-backend.test.sh duration_ms=9615

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 1 info
  • ⚠️ bin/fm-spawn.sh:273 - spawn_abort_cleanup returns the leased worktree before the herdr projection exact-pane close, reintroducing on the spawn-abort path the same ordering failure commit ab5cadf root-caused and fixed in fm-teardown.sh. Concrete path: projected herdr spawn arms HERDR_PROJECTION_ABORT_CLEANUP (~line 1043) and TREEHOUSE_LEASE_ABORT_CLEANUP (line 1309); after the pane lands in the leased worktree, any set -e failure before meta publication at line 1533 (hook-file write, TASK_TMP mkdir, exclude_path git call) fires the EXIT trap, which runs treehouse return --force $WT (line 276) first — killing the pane's top-level shell whose cwd is the worktree — so Herdr's last-pane cleanup destroys the workspace and steals focus before fm_backend_herdr_projection_cleanup_exact (line 289) can close the pane focus-preservingly. Fix at the shared boundary: perform the HERDR_PROJECTION_ABORT_CLEANUP blocks before the lease return inside spawn_abort_cleanup, mirroring the teardown ordering fix.
  • ⚠️ bin/fm-teardown.sh:1179 - When the presentation focus lock cannot be acquired within ~5s (50 x 0.1s), teardown skips the exact-pane close with a warning but still proceeds to teardown_treehouse_return, which kills the still-live pane shell — the same Herdr last-pane focus steal this branch fixes, now reachable only under lock contention. The fix's own invariant ('close the presentation pane before returning the worktree') is violated on this branch. Consider deferring/aborting the worktree return (or retrying the lock longer) instead of proceeding with an unclosed live pane; whether teardown should block on contention is the author's call.
  • ⚠️ bin/fm-spawn.sh:1301 - The treehouse get --lease invocation discards stderr (2>/dev/null), so every lease failure — pool exhaustion, unwritable mount-root .fm-pools directory (a real case when fm_treehouse_pool_home resolves to a filesystem mount point), unsupported --lease flag on an older treehouse — collapses into the same generic 'could not lease a worktree' message with no root cause for the operator. Capture treehouse's stderr (e.g. to a temp file or variable) and include it in the failure diagnostic.
  • ℹ️ docs/verification/runtime-backends.md:199 - The recorded reverification evidence for the teardown-ordering fix was gathered against Treehouse v2.1.0, while CI installs the v2.0.1 pin from bin/fm-install-treehouse.sh (FM_TREEHOUSE_CI_VERSION=2.0.1). The intent's narrative (only 2 of 22 presentation e2e tests failing in CI under the leased flow) evidences that v2.0.1 supports get --lease, so this is a version skew in the evidence, not a demonstrated defect; the pipeline's CI step will confirm behavior on the pinned version.

🔧 Fix: fix abort/teardown pane-close ordering and surface lease stderr
1 info still open:

  • ℹ️ docs/verification/runtime-backends.md:199 - Carried forward from round 1 (unaddressed by the fix commit, informational only): the recorded reverification evidence for the teardown-ordering fix was gathered against Treehouse v2.1.0, while CI installs the v2.0.1 pin from bin/fm-install-treehouse.sh (FM_TREEHOUSE_CI_VERSION=2.0.1). The intent's narrative (only 2 of 22 presentation e2e tests failing in CI under the leased flow) evidences that v2.0.1 supports get --lease, so this is a version skew in the evidence, not a demonstrated defect; the pipeline's CI step will confirm behavior on the pinned version.
✅ **Test** - passed

✅ No issues found.

  • bin/fm-test-run.sh tests/fm-spawn-worktree-settle.test.sh — leased acquisition, per-project pools, and post-create abort/settle contract (11/11 ok)
  • bin/fm-test-run.sh tests/fm-backend-herdr-presentation-e2e.test.sh run 1 — real Herdr 0.7.4 lab, 22/22 ok including 'concurrent post-create abort cleanup stays serialized with exact focus restoration' and 'exact task-pane close restores the exact captain workspace/tab after Herdr's raw focus steal'
  • bin/fm-test-run.sh tests/fm-backend-herdr-presentation-e2e.test.sh run 2 — 22/22 ok (flake check)
  • bin/fm-test-run.sh tests/fm-backend-herdr-presentation-e2e.test.sh run 3 — 22/22 ok (flake check)
  • bin/fm-test-run.sh tests/fm-teardown.test.sh tests/fm-watcher-lock.test.sh tests/fm-backend.test.sh — remaining suites owning the changed scripts, all exit=0
  • git status --porcelain — worktree clean, no transient test artifacts left behind
⚠️ **Document** - 1 info
  • ℹ️ bin/backends/zellij.sh:388 - bin/backends/zellij.sh and bin/backends/cmux.sh current-path comments still narrate the old in-pane treehouse get foreground-subshell flow as the probe's rationale (and zellij.sh cites a docs/zellij-backend.md heading that no longer exists - a pre-existing mismatch). Left intact because they preserve verified empirical pitfall evidence; a follow-up comment refresh to the leased plain-cd flow would be reasonable.
✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@kunchenguid

Copy link
Copy Markdown
Owner

Automated reminder: thanks for the PR! This branch currently has a merge conflict with the base branch.

When you get a chance, please rebase onto (or merge) the latest base branch, resolve the conflict, and push. After that, checks will re-run and the PR will get looked at again.

Noted for firstmate#1142 at e470eac6.

@adibirzu
adibirzu force-pushed the fm/fm-pool-relocation branch from e470eac to 004d5ea Compare July 28, 2026 05:17
@adibirzu
adibirzu force-pushed the fm/fm-pool-relocation branch from 004d5ea to 149b811 Compare July 28, 2026 10:16
@adibirzu adibirzu changed the title fix(bin): place crew worktrees on the repo's own filesystem feat(bin): give each project its own leased worktree pool on the repo's filesystem Jul 28, 2026
@adibirzu
adibirzu force-pushed the fm/fm-pool-relocation branch from 7e7d3b9 to ee0dba7 Compare July 29, 2026 03:45
adibirzu and others added 9 commits August 5, 2026 12:16
A firstmate home is routinely reachable through a symlinked ancestor, so one
directory has two names. bin/ derives its root both ways: fm-arm-pretool-check.sh
and fm-cd-pretool-check.sh resolve with pwd -P, while most scripts use a logical
pwd. The watcher lock records fm-home and watcher-path as raw strings and every
identity check compares them as raw strings, so a lock published under one name
is never recognized when read under the other. The home then treats its own live
watcher as somebody else's, and re-arming records the same divergent pair again,
so nothing recovers on its own.

Resolve both sides before comparing, in one shared comparison owner used by
fm_watcher_lock_matches_pid and by the arm's stale-lock clear. Equal raw strings
short-circuit, and a path that cannot be resolved keeps its raw value so two
different removed homes still stay distinct. fm_lock_abs_path deliberately leaves
the final component unresolved, which is right for the watcher-path file but
leaves a symlinked home directory unresolved, so the home case resolves fully.

Also derive fm-wake-lib.sh's default root and fm-watch-arm.sh's script dir with
pwd -P, so the two scripts that publish this identity stop introducing the
divergence at the source.
A linked worktree and the object store it points at must live on ONE
filesystem. When they are split, git blocks in read_gitfile_gently inside
open(), so `no-mistakes init` and `no-mistakes axi run` hang forever and the
crew can never run the validation pipeline. Ordinary git reads inherit the open
descriptor and look healthy, which is what makes it a trap. Repos on an external
volume with the pool under $HOME are split by construction, so every crew
worktree on such a fleet was unusable for validation.

treehouse takes the pool root from a treehouse.toml in the REPO ROOT (no
ancestor search) and otherwise defaults to $HOME. TREEHOUSE_DIR appears in the
binary but does not select the pool - verified inert against both the v2.0.0
build and the v2.0.1 pin in bin/fm-install-treehouse.sh - so the only lever that
does not write into a project repo is the HOME treehouse runs under.

An interactive `treehouse get` runs the crew's shell as a child of treehouse, so
that HOME would become the agent's HOME: wrong ~/.claude, wrong git config,
wrong gh credentials (leak confirmed directly). Firstmate therefore leases the
worktree itself with `treehouse get --lease` under a per-command HOME resolved
from the repo, and sends the pane a plain cd - the one instruction every
supported shell reads identically.

Deriving the pool from the repo, not a fixed path, keeps this correct for a
fleet holding repos on several volumes; a repo already on $HOME's filesystem
keeps the default location unchanged. The lease also makes the acquisition
deterministic: worktree= now comes from treehouse's own output rather than from
polling the pane's cwd, so the transient stale pane_current_path some tmux/WSL
setups report can no longer record another checkout as the worktree.

Because a repo-root treehouse.toml still outranks that HOME, the invariant is
also checked on the acquired worktree. Firstmate refuses to launch into a split
worktree on the path it places, and reports rather than refuses on the Orca
path, where `orca worktree create` takes no root argument and placement is not
firstmate's to control.

A lease is durable, so unlike the old interactive get the pool slot is not freed
when the pane dies: fm-teardown.sh's existing `treehouse return --force` is what
frees it, and a spawn that fails before publishing state/<id>.meta returns its
own lease.
fm-spawn.sh now EXECUTES treehouse to lease the worktree instead of sending
`treehouse get` to a fake pane, so a fixture whose fakebin has no treehouse stub
falls through to the real binary and leases real pool slots against a test's
throwaway repo. tests/fm-secondmate-harness.test.sh hit exactly that and its
crew-unaffected case failed.

Install the stub from fm_fakebin so every fakebin-based suite is covered at the
source, and add it explicitly to the one fixture that builds its fakebin
directly. Suites that want to record the invocation still call fm_fake_treehouse
with their own arguments.
treehouse's prune and destroy operate on a pool, so one shared pool root means a
cleanup aimed at one project can reach into another project's worktrees. That is
not hypothetical: a pool currently holds worktrees carrying commits that exist
nowhere else, and a prune to clear unrelated orphans would have taken them.

Resolve each project to its own pool root under <filesystem>/.fm-pools/<slug>,
where the slug is the repo's own directory name plus a discriminator derived from
the canonical object-store path, so two projects that share a directory name
still get separate pools. The filesystem is still chosen by the colocation rule,
so this composes with the split-volume fix rather than replacing it.

Existing pooled worktrees are unaffected: they keep their absolute paths, and
fm-teardown.sh returns them by absolute path regardless of pool root.
…r leased acquisition

The leased flow validates treehouse output before the armed isolation check, so
the fake's bare 'exit 0 with no output' now dies on the new empty-path error and
the fixture never reaches the validation it exists to pin. Yield the invoking
project checkout instead: a path that exists but is not an isolated worktree,
so the spawn proceeds past acquisition and the armed validation must stop it.

Unmasks a further pre-existing failure in the same script (projected teardown
focus restoration, case 9) that the case-8 abort previously hid; that defect is
separate and still open.
…tree

teardown_task shape's projected teardown left the captain focused on an
unrelated workspace (w8, order-fail's trailing workspace) instead of
restoring w3/w3:t1, even though teardown itself exited 0.

Evidence (docs/prds/2026-07-28-fm1142-teardown-focus-prd.md, H2/H1):

- The only pane-close audit record for the projected pane
  (herdr_pane_id=w4:p2 from on.meta) was:
    pane-close  w8/w8:t2  w8/w8:t2  w4:p2
  Both the before and after focus snapshots already read w8/w8:t2 - the
  live Herdr focus had already moved to the trailing workspace before this
  call, and no earlier pane-close record for w4:p2 exists. This matches
  the H2 discriminator row exactly (focus stolen before any presentation-
  path Herdr call touched the pane).
- on-teardown.err contained:
    warning: herdr presentation journal for shape remains quarantined; no
    workspace cleanup was attempted
  and home/state/shape.herdr-presentation survived teardown - the H1
  mechanism signature (the retire-candidate gate went false and control
  fell to the raw kill fallback).
- Journal fields (workspace_id/tab_id/pane_id = w4/w4:t2/w4:p2) matched
  on.meta exactly, and every Herdr container id created during the run
  (w1..wA) was monotonic with no reuse, refuting H3 and H4.
- assert_focus_is "$CAPTAIN_FOCUS" passed at 7+ points up to and including
  immediately before teardown (:780); the branch does not touch
  fm-teardown.sh, backends/herdr.sh, or the captain-fixture creation, and
  CAPTAIN_FOCUS was last changed by pre-branch commits f9a89c3/c58cb0f -
  refuting H5 (the fixture is correct, not stale).
- fm_backend_herdr_projection_close_pane_focus_preserving only runs inside
  the retire-candidate branch (old :1180), which never became true here,
  so the restore helper never ran at all - refuting H6 (it never got the
  chance to hit its own failure mode).

Root cause (bin/fm-teardown.sh:1153 pre-fix / product code, not the test):
teardown_treehouse_return ran before the Herdr presentation retire-
candidate gate. Under this branch's leased worktree-acquisition flow
(bin/fm-spawn.sh:1301-1345), the task pane's own top-level shell has cwd
set to the worktree itself (a plain `cd`, not a treehouse child subshell
as under the old interactive `treehouse get` flow). `treehouse return
--force` kills that shell directly, collapsing the pane's workspace via
Herdr's own dead-pane cleanup before any firstmate code ran. The gate's
token-correlation check then failed (the workspace was already gone),
so control fell to the raw `fm_backend_kill` fallback - a bare
`herdr pane close` with no focus snapshot or restore, and a no-op besides
since the pane was already dead.

Fix: run the Herdr presentation retire-candidate gate and
fm_backend_herdr_projection_close_pane_focus_preserving before
teardown_treehouse_return, while the pane is still alive, so the existing
focus-snapshot/close/restore primitive gets the chance its own logic was
written for. The general non-presentation fallback kill and the journal
quarantine bookkeeping stay in their original position (after the
worktree return), unchanged, so no other backend's teardown ordering
moves.

Verification (all from /home/adi/.fm-1142-wt):
- tests/fm-backend-herdr-presentation-e2e.test.sh: 22/22 ok, exit 0,
  3 consecutive runs (was: not ok at "projected teardown")
- tests/fm-backend-herdr.test.sh: 132/132 ok, exit 0
- tests/fm-backend-herdr-eventwait-smoke.test.sh: 3/3 ok, exit 0
- tests/fm-backend-herdr-prune-safety-e2e.test.sh: 6/6 ok, exit 0
- tests/fm-backend-herdr-respawn-idem-e2e.test.sh: 6/6 ok, exit 0
- tests/fm-backend-herdr-smoke.test.sh: 16/16 ok, exit 0
- tests/fm-backend-herdr-workspace-per-home-e2e.test.sh: 10/10 ok, exit 0
- tests/fm-spawn-worktree-settle.test.sh: 11/11 ok, exit 0
- bin/fm-lint.sh: exit 0 (ShellCheck 0.11.0)
@adibirzu

Copy link
Copy Markdown
Author

Superseded by #1338 (consolidated federated-fleet + crew-routing PR): per-project leased worktree pool; folded into #1338. Closing in favor of the single consolidated PR. This can be reopened if needed.

@adibirzu adibirzu closed this Aug 11, 2026
@adibirzu
adibirzu deleted the fm/fm-pool-relocation branch August 23, 2026 09:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants