fix(spawn): require same-repo worktree selection#707
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ea90f14c72
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| wt_common_real=$(git_common_dir_real "$candidate") || return 1 | ||
| [ "$wt_common_real" = "$PROJ_GIT_COMMON_REAL" ] || return 1 |
There was a problem hiding this comment.
Require the newly acquired worktree, not merely the same repo
Captain, when the transient cwd is another existing linked worktree of the requested repository, this predicate accepts it because its Git common directory matches. The spawn loop then records that other task's worktree, installs hooks there, and launches a second agent into it, risking cross-task edits; correlate the candidate with the worktree acquired by this treehouse get invocation rather than accepting any non-primary worktree from the repository.
Useful? React with 👍 / 👎.
Summary
This fixes a spawn-safety race where
bin/fm-spawn.shcould persist a transient unrelated Git repository asworktree=duringtreehouse getstartup.The end-user-aligned regression drives the observed current-path sequence: the primary project root, then an unrelated Git root such as a shell startup repo, then the real isolated worktree for the same requested project.
The poll now ignores transient or unrelated Git roots and accepts only an isolated worktree whose Git common directory matches the requested primary repository.
That same-repository check is a deterministic Git invariant, not a Treehouse path-name convention.
Safety
If no matching same-repository isolated worktree appears, spawn still fails closed at the bounded timeout before durable metadata is written.
Symlink normalization and stable tmux window-id targeting are preserved and covered by the fake-tmux regression.
The cmux recovery helper now also fails closed when
list-panesexits nonzero even if it emits parseable JSON, so target recovery cannot mask a failed cmux structural read.Verification
Exact current head:
2a42a6a244ba1f7242bc10a2019495e62dea595a.Prior Opus rereview of head
7449faa7c7805a1570cae7e09bac97c1822e0257found that three deterministic test fakes still emitted no leased worktree path fortreehouse get --lease:tests/fm-gate-refuse.test.shtests/fm-grok-harness.test.shtests/fm-tangle-guard.test.shCommit
2a42a6a244ba1f7242bc10a2019495e62dea595acorrects those stale lease fakes.The mandated Behavior workflow command also surfaced one additional stale lease fake in
tests/fm-secondmate-harness.test.sh, and this commit corrects that fake too.It also refreshes the tangle recording assertion from the old in-pane
treehouse getcommand to the current stable-windowcd <leased worktree>command that production now sends after acquiring the lease outside the pane.Focused correction proof passed:
tests/fm-gate-refuse.test.sh,tests/fm-grok-harness.test.sh, andtests/fm-tangle-guard.test.shreproduced the Opus-reported failures before edits.tests/fm-gate-refuse.test.sh,tests/fm-grok-harness.test.sh, andtests/fm-tangle-guard.test.sh.tests/fm-secondmate-harness.test.sh.shellcheck -x tests/fm-gate-refuse.test.sh tests/fm-grok-harness.test.sh tests/fm-tangle-guard.test.sh tests/fm-secondmate-harness.test.sh.git diff --check.set -eu; for test_script in tests/*.test.sh; do "$test_script"; done.