Repository navigation
fix(spawn): accept only a genuine isolated worktree in the treehouse cwd poll - #3
Merged
Merged
Conversation
…cwd poll A freshly created pane transiently reports $HOME as its cwd before its shell finishes initializing, and the worktree poll grabbed the first reading that differed from the project, so every ship/scout spawn failed on hosts with slow pane-shell startup. Poll with the same accept condition the launch guard enforces - the path is its own git toplevel, physically distinct from the project - via a shared fm_isolated_worktree predicate in fm-tangle-lib.sh, keeping validate_spawn_worktree as defense in depth.
kostas-nt
force-pushed
the
fix-spawn-worktree-poll-transient
branch
from
July 14, 2026 11:07
c9fe287 to
503676d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Intent
Fix a race in bin/fm-spawn.sh's treehouse-worktree cwd poll that deterministically broke every ship/scout spawn on hosts with slow pane-shell startup: a freshly created pane transiently reports $HOME as #{pane_current_path} before its shell finishes initializing (traced live 2026-07-13: tick 1 = /home/kostas, tick 2 = project dir, tick 5 = treehouse worktree), and the poll accepted the FIRST reading that differed from the project, so WT resolved to $HOME and validate_spawn_worktree refused the launch, 3/3 reproductions. The fix: the poll now accepts a candidate only when it is itself a git toplevel physically distinct from the project. Deliberate decisions: (1) the accept predicate was extracted as fm_isolated_worktree into bin/fm-tangle-lib.sh (the prevention/detection lib for exactly this worktree-tangle guard family) and is shared by both the poll and validate_spawn_worktree per the repo's one-owner rule; validate_spawn_worktree is deliberately kept after the loop as defense in depth. (2) real_path_or_raw was removed from fm-spawn.sh as dead code - both former consumers now go through the predicate. (3) The poll-timeout error message was reworded to 'did not yield an isolated worktree within Ns' because it now also covers 'entered a dir that never became a valid worktree', sharing the load-bearing phrase with validate_spawn_worktree's error. (4) FM_SPAWN_WT_POLLS is a deliberate test-only override of the poll count (default 60, unchanged); tests set it to 3 because reject-and-retry abort cases now run to the timeout instead of aborting on the first different reading. (5) One fix covers tmux/herdr/zellij/cmux since they all route through the same spawn_current_path loop; orca and secondmate spawns never enter it; the poll keeps targeting the stable WT_TARGET window id per upstream kunchenguid#134. This branch was deliberately REBUILT on the post-fork-sync origin/main (b708731) by cherry-picking only the fix commit and its doc-sync commit, resolving conflicts with upstream's kunchenguid#134 window-id targeting and the new GUARD 1c window-construction tests, because the fork history it originally shipped on was reset; the PR branch was force-with-lease updated with explicit authorization, and the gate's stale pre-rebuild branch ref was cleared so this run's gate push is a clean create. Tests extend tests/fm-tangle-guard.test.sh (the suite owning the fm-spawn isolation seam): unit rows for the predicate plus an e2e regression test replaying the live-traced pane-cwd sequence via a sequence-capable fake tmux; the regression test was verified to fail against pre-fix fm-spawn.sh and pass with the fix. shellcheck bin/.sh bin/backends/.sh tests/.sh is clean. KNOWN PRE-EXISTING, UNRELATED FAILURE ON THIS HOST: tests/fm-watcher-lock.test.sh's 'restart reports healthy peer' case (added upstream in kunchenguid#375) fails identically on a pristine origin/main export on this machine (status 124, arm starts a fresh watcher instead of reporting the healthy TERM-resistant peer); this branch does not touch any watcher/lock code (bin/fm-watch.sh, bin/fm-wake-lib.sh, tests/fm-watcher-lock.test.sh are byte-identical to origin/main), so that failure must not be attributed to or fixed by this change.
What Changed
bin/fm-spawn.sh's treehouse-worktree cwd poll where a freshly created pane transiently reports$HOMEas its current path before the shell finishes initializing; the poll previously accepted the first reading that merely differed from the project dir, soWTresolved to$HOMEandvalidate_spawn_worktreerefused the launch on hosts with slow pane-shell startup. The poll now accepts a candidate only when it is itself a git toplevel physically distinct from the project.fm_isolated_worktreeinbin/fm-tangle-lib.sh, shared by both the poll andvalidate_spawn_worktree(kept after the loop as defense in depth); removed the now-deadreal_path_or_rawfromfm-spawn.shand reworded the poll-timeout error to "did not yield an isolated worktree within Ns".tests/fm-tangle-guard.test.shwith unit rows for the predicate and an e2e regression test replaying the live-traced pane-cwd sequence via a sequence-capable fake tmux (verified to fail pre-fix, pass post-fix); tests use the test-onlyFM_SPAWN_WT_POLLSoverride since reject-and-retry cases now run to timeout. The Test stage reports one failure intests/fm-watcher-lock.test.sh, a pre-existing host-specific failure in code this branch does not touch.Risk Assessment
✅ Low: Well-bounded, faithful extraction of an existing isolation check into a shared predicate that is strictly more restrictive than the prior poll condition; it is covered by new unit and e2e regression tests, matches every stated intent decision, and introduces no regression path.
Testing
Completed 1 recorded test check.
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
✅ **Review** - passed
✅ No issues found.
command -v tmux >/dev/null || { echo "tmux is required for e2e tests" >&2; exit 1; }; tmux -V; rc=0; for t in tests/*.test.sh; do echo "== $t =="; bash "$t" || rc=1; done; exit "$rc"✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.