Repository navigation
fix(bin): guard worktree isolation by filesystem identity, not path text - #10
Merged
Merged
Conversation
… text The spawn isolation guard decided "this launch worktree is not the primary checkout" with a string compare of two canonicalized paths. bash's builtin `pwd -P` resolves symlinks, `.`, `..`, and trailing slashes, but it does not case-fold, so on a case-insensitive filesystem (macOS's default) the primary checkout reached under a different case survived canonicalization as unequal text and the guard blessed it as isolated. A crewmate then branched and committed inside the primary checkout, the exact tangle this guard exists to prevent. Compare device and inode instead, so every alias of one directory is recognized as that directory. Each side is confirmed to be an existing directory first, because `test -ef` is also false when a side cannot be stat'd and that would read as "distinct"; anything that cannot be proven distinct is now refused rather than allowed. The identity compare also drops a false rejection the text compare had: a genuinely distinct worktree whose launch path spelling differed from git's report of its root. Refs kunchenguid#2654
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 the worktree-isolation guard in bin/fm-spawn.sh so it cannot bless the primary checkout as an isolated task worktree on a case-insensitive filesystem (macOS default). Reported as issue kunchenguid#2654.
Problem
pwd -Presolves symlinks,.,.., and trailing slashes, but it does NOT case-fold (unlike/bin/pwd -P, which calls getcwd and does)..../PROJECT, pane never leaving the true-cased.../Project-> spawn exited 0 and recordedworktree=.../Projectalongsideproject=.../PROJECT, the same directory.Fix
validate_spawn_worktreenow test filesystem identity (device + inode) viatest -efinstead of path text, so every alias of one directory is recognized as that directory.test -efis also false when a side cannot be stat'd, which would read as "distinct", so each side is confirmed to be an existing directory before any identity test runs. An unresolvable path now refuses the spawn where the old text compare passed it.did not yield an isolated worktreesubstring that four existing suites assert on.Deliberate scope decisions
PROJ_ABS_REALalso feeds the treehouse settle loop's[ "$p_real" != "$PROJ_ABS_REAL" ]check, which is why the loop handed the primary checkout to the guard. CanonicalizingPROJ_ABS_REALat its source would fix both and give a more precise diagnosis, but it is a behavior change beyond the guard and was deliberately left for a follow-up. The outcome is already safe: the loop's miscompare now ends in a refusal.pwd -PDOES resolve symlinks, so a symlinked alias never reaches the guard - the settle loop catches it 60s earlier via timeout. Case-folding was the only surviving gap. Keeping a symlink case would have asserted the guard's message for the wrong reason and cost 60s per run. The test comment records this.Proof
tests/fm-tangle-guard.test.sh(extending the suite that already covers this guard, per repo convention), asserting the case-variant primary checkout is refused with no meta recorded, and that a genuinely distinct worktree is still accepted.expected exit 1, got 0); with the fix it passes.bin/fm-lint.shexit 0 (shellcheck 0.11.0 pinned);bin/fm-doc-audience-check.shok.What Changed
validate_spawn_worktree(bin/fm-spawn.sh) now test filesystem identity withtest -ef(device + inode) instead of comparing canonicalized path text, so a case-variant alias of the primary checkout on a case-insensitive filesystem is recognized as the primary and refused rather than blessed as an isolated task worktree.tests/fm-tangle-guard.test.shasserting the case-variant primary checkout is refused with no meta recorded and a distinct worktree is still accepted; the case-variant assertion self-skips on case-sensitive filesystems.Risk Assessment
✅ Low: A tightly-scoped, fail-closed fix that replaces path-text comparison with device+inode identity, fully closing the case-fold gap from issue kunchenguid#2654 with a matching regression test and preserved error-substring contract.
Testing
Confirmed the temp filesystem is case-insensitive so the meaningful guard branch runs, ran the extended fm-tangle-guard suite (7/7 pass), proved the new regression test is genuine by reverting the guard and seeing the exact
expected exit 1, got 0failure before restoring, and drove the real fm-spawn.sh binary end-to-end to reproduce issue kunchenguid#2654: the case-variant primary checkout is now refused (exit 1, specific reason, no meta) while a distinct worktree still spawns cleanly. The four related spawn/backend suites also pass and the working tree is clean. This is a shell/CLI change with no rendered UI, so evidence is CLI transcripts rather than screenshots.Evidence: End-to-end issue kunchenguid#2654 reproduction transcript (real fm-spawn.sh: case-variant primary refused, distinct worktree accepted)
$ fm-spawn.sh crew-2654 SPAWN-PROJ codex error: treehouse get did not yield an isolated worktree (launch path is the primary checkout under another name; ...); refusing to launch to avoid tangling the primary checkout. -> exit status: 1 -> meta recorded? no (spawn refused; primary checkout protected) $ fm-spawn.sh crew-ok spawn-proj codex (pane in isolated worktree spawn-wt) spawned crew-ok harness=codex ... worktree=.../spawn-wt -> exit status: 0 -> meta recorded? yes (spawn proceeded)Evidence: fm-tangle-guard suite (green, with fix)
Evidence: fm-tangle-guard suite (RED: guard reverted to old text compare — new test fails)
not ok - spawn must abort when the launch path is the primary checkout under another case: expected exit 1, got 0Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
✅ **Review** - passed
✅ No issues found.
✅ **Test** - passed
✅ No issues found.
bash tests/fm-tangle-guard.test.sh(7/7 pass incl. new identity test)Red/green: reverted guard -> new test failsexpected exit 1, got 0; restored -> passes; tree cleanEnd-to-end repro against realbin/fm-spawn.sh: case-variant primary refused (exit 1, no meta), isolated worktree accepted (exit 0)fm-spawn-worktree-settle,fm-spawn-batch,fm-spawn-dispatch-profile,fm-backend-orcaall pass✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.