Skip to content

fix(spawn): require same-repo worktree selection#707

Open
astev89 wants to merge 4 commits into
kunchenguid:mainfrom
astev89:fix/spawn-worktree-repo-invariant
Open

fix(spawn): require same-repo worktree selection#707
astev89 wants to merge 4 commits into
kunchenguid:mainfrom
astev89:fix/spawn-worktree-repo-invariant

Conversation

@astev89

@astev89 astev89 commented Jul 18, 2026

Copy link
Copy Markdown

Summary

This fixes a spawn-safety race where bin/fm-spawn.sh could persist a transient unrelated Git repository as worktree= during treehouse get startup.
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-panes exits 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 7449faa7c7805a1570cae7e09bac97c1822e0257 found that three deterministic test fakes still emitted no leased worktree path for treehouse get --lease:

  • tests/fm-gate-refuse.test.sh
  • tests/fm-grok-harness.test.sh
  • tests/fm-tangle-guard.test.sh

Commit 2a42a6a244ba1f7242bc10a2019495e62dea595a corrects 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 get command to the current stable-window cd <leased worktree> command that production now sends after acquiring the lease outside the pane.

Focused correction proof passed:

  • Red first: tests/fm-gate-refuse.test.sh, tests/fm-grok-harness.test.sh, and tests/fm-tangle-guard.test.sh reproduced the Opus-reported failures before edits.
  • Green targeted rerun: tests/fm-gate-refuse.test.sh, tests/fm-grok-harness.test.sh, and tests/fm-tangle-guard.test.sh.
  • Additional stale-fake proof: 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.
  • Exact Behavior workflow test command: set -eu; for test_script in tests/*.test.sh; do "$test_script"; done.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread bin/fm-spawn.sh
Comment on lines +720 to +721
wt_common_real=$(git_common_dir_real "$candidate") || return 1
[ "$wt_common_real" = "$PROJ_GIT_COMMON_REAL" ] || return 1

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

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.

1 participant