Skip to content

fix(bin): refuse spawn worktrees outside the project's own repository - #2562

Open
SilvioLima94 wants to merge 14 commits into
kunchenguid:mainfrom
SilvioLima94:fm/fm-spawn-isolation-a1
Open

SilvioLima94 wants to merge 14 commits into
kunchenguid:mainfrom
SilvioLima94:fm/fm-spawn-isolation-a1

Conversation

@SilvioLima94

@SilvioLima94 SilvioLima94 commented Aug 18, 2026 •

Copy link
Copy Markdown

Intent

Close a safety hole in validate_spawn_worktree() in bin/fm-spawn.sh: the worker-isolation assertion accepts a worktree belonging to the wrong repository, including firstmate's own home.

The defect: validate_spawn_worktree() asserts that the worktree path resolves, is a real git top-level, that the resolved path equals that top-level, and that it is not the project's own primary checkout. It never asserts that the worktree belongs to the project's repository. Found live dispatching a scout task: a spawn whose terminal never left the firstmate home recorded worktree=/Users/young/work/firstmate and passed, because the firstmate home is a valid git top-level distinct from the project clone. The worker would have been launched against firstmate's own primary checkout, which AGENTS.md sections 7 and 8 exist to prevent. The two-consecutive-reads guard does not cover this: it defends against a transient stale path, and a pane that never moved trivially agrees with itself. Call sites to keep correct: the Orca path, the relaunch path, and the treehouse get path.

Required outcomes:

  1. Reproduce the incorrect-repository acceptance before fixing, demonstrating that the old assertion accepts a worktree from a different repository than the project, including the firstmate-home case, with the evidence in the PR.
  2. Verify repository identity positively: resolve the worktree's git common dir (or its .git file pointer) and require it to land inside the project's repository. A worktree of any other repository, most dangerously firstmate's own, must be refused. Identity must be proven, never inferred from path shape or string prefix.
  3. Fail closed when identity cannot be established: unreadable pointer, unresolvable path, command failure, or unexpected output must refuse the launch with a clear diagnostic naming what could not be established. An inconclusive check is never a pass. Keep the existing refusal style: loud, specific, non-zero.
  4. Regression tests covering the firstmate-home misrouting case, wrong-repo-in-general, and the identity-unknown path, plus assertions that legitimate worktrees still pass so the fix cannot pass by refusing everything. Colocate under tests/ as .test.sh, extend the existing pattern rather than inventing a runner, and exercise behavior through an executable or public interface, never asserting implementation source bytes directly or through a wrapper.
  5. Backend compatibility review across each supported backend's path into the assertion (treehouse-provided for tmux, herdr, zellij, cmux; Orca owns its own worktree and does not run treehouse get), confirming the new check is correct for each or stating why an axis is not applicable after inspecting its integration surface.
  6. Full validation: bin/fm-lint.sh (shellcheck is mandatory for bin/*.sh) and the relevant existing test suites, reporting what was run and its result.

This change touches firstmate's shared tracked material, so the firstmate-coding-guidelines skill's knowledge-placement, one-owner, compatibility, and repo-style rules are binding.

Later accepted corrections, decided by the captain, to be carried in this run:

  • Add a distinct FM_HOME_RETURN_NOT_OWNED outcome so that only proven foreign ownership releases the pooled treehouse lease. Every other refusal cause, including mktemp, manifest, and first-move failures that leave this run's own marker on the slot, must preserve the lease rather than releasing it and poisoning the pool slot.
  • Retain repository-root-only project registration, and correct only its misleading diagnostic, which currently describes a project directory that is a genuine subdirectory of its own repository as "nested inside another git repository".
  • Fold in the helper-shadowing auto-fix.
  • Keep the no-op finding as a no-op.

Preserve all existing safety contracts. Do not merge; the captain approves the merge personally.

Further accepted requirements after the first PR went red in upstream CI (PR #2562, head 7dcdb4e6, 12 of 13 checks passed):

  • FIX IN THIS TASK - a regression this branch introduced. The check "Behavior portable serial 1" failed because tests/fm-gotmp.test.sh reports "not ok - teardown exited non-zero with a valid tasktmp". Root cause established: bin/fm-teardown.sh line 192 now unconditionally sources bin/fm-home-return-lib.sh, but the fake root built by tests/fm-gotmp.test.sh symlinks each library teardown sources and was never given the new one, so the real teardown subprocess fails at source time and exits non-zero. Evidence that this is ours: upstream CI on the exact base commit 64d61ae is green, the test file is byte-identical between base and this branch, and running the test from a clean export reproduces "teardown exited non-zero with a valid tasktmp" on this branch while base fails only a different, macOS-local assertion. Fix it so the fixture provides every library the real teardown requires, following the pattern and commentary already used for the other symlinked siblings in that fixture, and check whether any other test fixture enumerating teardown's sourced libraries needs the same addition.

  • DO NOT FIX HERE, keep this PR scoped - tests/fm-pi-watch-extension.test.sh reported "not ok - Pi must deliver the actionable wake after bounded hung-successor recovery: expected exit 0, got 1" in the same CI shard. This branch touches no Pi, watcher, or wake code (the changed files are bin/fm-ff-lib.sh, bin/fm-home-return-lib.sh, bin/fm-home-seed.sh, bin/fm-spawn.sh, bin/fm-teardown.sh, bin/fm-test-isolation-proof.sh, bin/fm-test-run.sh, two docs, one skill pointer, and the two new identity test files), and the test passes from a clean export of this branch, so it is not attributable to this change and is being recorded as a separate follow-up item. Do not expand this task to chase it.

Validate the final head exactly once, push normally to the existing fork branch, and do not merge; the captain approves the merge personally.

What Changed

  • validate_spawn_worktree() in bin/fm-spawn.sh now proves repository identity instead of only checking worktree shape: it compares the physically resolved --git-common-dir of the task worktree against the project's, requires the project directory to be its own repository's top level (so the identity is not walked up to from a subdirectory), and separately refuses any worker root that is a firstmate home (active home, firstmate repo root, a directory carrying the seeded-home marker, or the holder of this fleet's state/data/config/projects directories). Every unresolvable path, git failure, or unexpected output fails closed with a diagnostic naming what could not be established; secondmate spawns still skip the assertion.
  • New bin/fm-home-return-lib.sh owns the shared "clear a leased home's identity, then return it to the treehouse pool" transaction used by both retirement (bin/fm-teardown.sh) and failed-seed rollback (bin/fm-home-seed.sh), staging owned artifacts aside and restoring them if the return fails. Its outcome codes distinguish FM_HOME_RETURN_NOT_OWNED — proven foreign ownership, the only refusal on which a pooled lease may be released — from refusals that leave this run's own marker on the slot. bin/fm-spawn.sh also drops its duplicated operational-directory validator in favor of validate_operational_dirs from bin/fm-ff-lib.sh.
  • Added tests/fm-spawn-worktree-identity.test.sh and tests/fm-teardown-home-identity.test.sh (wrong-repo, firstmate-home misrouting, identity-unknown, and legitimate-worktree cases), registered both in bin/fm-test-run.sh families and bin/fm-test-isolation-proof.sh, taught families_for_changed_path() that teardown/home-return changes re-select session-bootstrap, and gave the tests/fm-gotmp.test.sh fake root the fm-home-return-lib.sh symlink the real teardown subprocess now requires at source time. Docs in AGENTS.md, docs/architecture.md, docs/configuration.md, docs/verification/runtime-backends.md, and the project-management skill were updated for the repository-identity requirement and repository-root-only project registration.

Risk Assessment

⚠️ Medium: All four prior findings are verifiably closed and the fix round is small and correct, but the branch as a whole is large (~2570 lines) and installs a new launch-blocking spawn gate plus a repository-root-only project-registration refusal — both explicitly captain-authorized and covered by 18 behavior-driven regression cases, so it is safe to merge with only the test-fixture deduplication as a follow-up.

Testing

I reproduced the reported defect end-to-end before validating the fix: running the new identity suite against a clean export of the head with only bin/fm-spawn.sh reverted to base shows the old assertion accepting firstmate's own home and printing spawned ... worktree=<firstmate home>. On the fixed head the same scenario is refused with a specific non-zero diagnostic naming the repository mismatch, and I captured the actual operator-facing CLI refusal text for all cases — foreign repository, unreadable/empty/garbage worktree identity, unresolvable project identity, self-hosted firstmate-home signals, and the corrected non-top-level project-registration wording that no longer accuses a foreign repository — alongside the two accept cases that still spawn, so the fix cannot pass by refusing everything. The Orca and relaunch call sites are driven by their own cases; the tmux/herdr/zellij/cmux backends share the single treehouse-get path that the suite drives with a fake tmux. I also reproduced the CI regression (teardown exiting non-zero because the fake root lacked fm-home-return-lib.sh) and confirmed the fixture fix clears it, and swept the tests tree to confirm no other fixture enumerates teardown's sourced libraries. Related existing spawn, relaunch, teardown, and tangle-guard suites pass; two suites fail one assertion each, but identically on the base commit, so they are pre-existing macOS-local failures rather than regressions. This is a shell/CLI change with no rendered UI surface, so the reviewer-visible evidence is CLI transcripts rather than screenshots. Lint was not run — it belongs to a different phase.

Evidence: Pre-fix reproduction: base assertion accepts the firstmate home

not ok - spawn accepted the firstmate home as the task worktree --- output --- spawned identity-firstmate-home-i1 harness=codex kind=ship mode=no-mistakes yolo=off window=firstmate:fm-identity-firstmate-home-i1 worktree=/var/.../identity-firstmate-home/home

not ok - spawn accepted the firstmate home as the task worktree
--- output ---
warning: /var/folders/vt/36bg7pjx1711x3w5wyr1z88h0000gn/T//fm-spawn-worktree-identity.Ax032R/identity-firstmate-home/home/data/identity-firstmate-home-i1/brief.md records no delivery contract line (scaffolded before ship briefs recorded one); launching on the explicit --mode no-mistakes - confirm its definition of done matches
spawned identity-firstmate-home-i1 harness=codex kind=ship mode=no-mistakes yolo=off window=firstmate:fm-identity-firstmate-home-i1 worktree=/var/folders/vt/36bg7pjx1711x3w5wyr1z88h0000gn/T//fm-spawn-worktree-identity.Ax032R/identity-firstmate-home/home
Evidence: Post-fix CLI refusal transcript (operator-visible diagnostics for every identity case)

===== case: identity-firstmate-home-i1 (exit=1) ===== error: treehouse get yielded a worktree that belongs to a different repository (resolved '.../identity-firstmate-home/home'; its repository '.../identity-firstmate-home/home/.git'; the project's repository '.../identity-firstmate-home/project/.git'); refusing to launch a worker for .../project outside that project's own repository. ===== case: identity-unreadable-fail-i3 (exit=1) ===== error: the repository identity of treehouse get's worktree '.../wt' could not be established (its git common directory did not resolve); refusing to launch without proof it belongs to the project's repository '.../project/.git'. ===== case: identity-legit-worktree-i5 (exit=0) ===== spawned identity-legit-worktree-i5 harness=codex kind=ship mode=no-mistakes yolo=off window=firstmate:fm-identity-legit-worktree-i5 worktree=.../identity-legit-worktree/wt


===== case: identity-firstmate-home-i1 (exit=1) =====
warning: /var/folders/vt/36bg7pjx1711x3w5wyr1z88h0000gn/T//fm-spawn-worktree-identity.Zhut8s/identity-firstmate-home/home/data/identity-firstmate-home-i1/brief.md records no delivery contract line (scaffolded before ship briefs recorded one); launching on the explicit --mode no-mistakes - confirm its definition of done matches
error: treehouse get yielded a worktree that belongs to a different repository (resolved '/var/folders/vt/36bg7pjx1711x3w5wyr1z88h0000gn/T//fm-spawn-worktree-identity.Zhut8s/identity-firstmate-home/home'; its repository '/private/var/folders/vt/36bg7pjx1711x3w5wyr1z88h0000gn/T/fm-spawn-worktree-identity.Zhut8s/identity-firstmate-home/home/.git'; the project's repository '/private/var/folders/vt/36bg7pjx1711x3w5wyr1z88h0000gn/T/fm-spawn-worktree-identity.Zhut8s/identity-firstmate-home/project/.git'); refusing to launch a worker for /var/folders/vt/36bg7pjx1711x3w5wyr1z88h0000gn/T/fm-spawn-worktree-identity.Zhut8s/identity-firstmate-home/project outside that project's own repository. Inspect target firstmate:fm-identity-firstmate-home-i1

===== case: identity-other-repo-i2 (exit=1) =====
warning: /var/folders/vt/36bg7pjx1711x3w5wyr1z88h0000gn/T//fm-spawn-worktree-identity.Zhut8s/identity-other-repo/home/data/identity-other-repo-i2/brief.md records no delivery contract line (scaffolded before ship briefs recorded one); launching on the explicit --mode no-mistakes - confirm its definition of done matches
error: treehouse get yielded a worktree that belongs to a different repository (resolved '/var/folders/vt/36bg7pjx1711x3w5wyr1z88h0000gn/T//fm-spawn-worktree-identity.Zhut8s/identity-other-repo/other-wt'; its repository '/private/var/folders/vt/36bg7pjx1711x3w5wyr1z88h0000gn/T/fm-spawn-worktree-identity.Zhut8s/identity-other-repo/other-project/.git'; the project's repository '/private/var/folders/vt/36bg7pjx1711x3w5wyr1z88h0000gn/T/fm-spawn-worktree-identity.Zhut8s/identity-other-repo/project/.git'); refusing to launch a worker for /var/folders/vt/36bg7pjx1711x3w5wyr1z88h0000gn/T/fm-spawn-worktree-identity.Zhut8s/identity-other-repo/project outside that project's own repository. Inspect target firstmate:fm-identity-other-repo-i2

===== case: identity-unreadable-fail-i3 (exit=1) =====
warning: /var/folders/vt/36bg7pjx1711x3w5wyr1z88h0000gn/T//fm-spawn-worktree-identity.Zhut8s/identity-unreadable-fail/home/data/identity-unreadable-fail-i3/brief.md records no delivery contract line (scaffolded before ship briefs recorded one); launching on the explicit --mode no-mistakes - confirm its definition of done matches
error: the repository identity of treehouse get's worktree '/var/folders/vt/36bg7pjx1711x3w5wyr1z88h0000gn/T//fm-spawn-worktree-identity.Zhut8s/identity-unreadable-fail/wt' could not be established (its git common directory did not resolve); refusing to launch without proof it belongs to the project's repository '/private/var/folders/vt/36bg7pjx1711x3w5wyr1z88h0000gn/T/fm-spawn-worktree-identity.Zhut8s/identity-unreadable-fail/project/.git'. Inspect target firstmate:fm-identity-unreadable-fail-i3

===== case: identity-unreadable-empty-i3 (exit=1) =====
warning: /var/folders/vt/36bg7pjx1711x3w5wyr1z88h0000gn/T//fm-spawn-worktree-identity.Zhut8s/identity-unreadable-empty/home/data/identity-unreadable-empty-i3/brief.md records no delivery contract line (scaffolded before ship briefs recorded one); launching on the explicit --mode no-mistakes - confirm its definition of done matches
error: the repository identity of treehouse get's worktree '/var/folders/vt/36bg7pjx1711x3w5wyr1z88h0000gn/T//fm-spawn-worktree-identity.Zhut8s/identity-unreadable-empty/wt' could not be established (its git common directory did not resolve); refusing to launch without proof it belongs to the project's repository '/private/var/folders/vt/36bg7pjx1711x3w5wyr1z88h0000gn/T/fm-spawn-worktree-identity.Zhut8s/identity-unreadable-empty/project/.git'. Inspect target firstmate:fm-identity-unreadable-empty-i3

===== case: identity-unreadable-garbage-i3 (exit=1) =====
warning: /var/folders/vt/36bg7pjx1711x3w5wyr1z88h0000gn/T//fm-spawn-worktree-identity.Zhut8s/identity-unreadable-garbage/home/data/identity-unreadable-garbage-i3/brief.md records no delivery contract line (scaffolded before ship briefs recorded one); launching on the explicit --mode no-mistakes - confirm its definition of done matches
error: the repository identity of treehouse get's worktree '/var/folders/vt/36bg7pjx1711x3w5wyr1z88h0000gn/T//fm-spawn-worktree-identity.Zhut8s/identity-unreadable-garbage/wt' could not be established (its git common directory did not resolve); refusing to launch without proof it belongs to the project's repository '/private/var/folders/vt/36bg7pjx1711x3w5wyr1z88h0000gn/T/fm-spawn-worktree-identity.Zhut8s/identity-unreadable-garbage/project/.git'. Inspect target firstmate:fm-identity-unreadable-garbage-i3

===== case: identity-no-project-repo-i4 (exit=1) =====
warning: /var/folders/vt/36bg7pjx1711x3w5wyr1z88h0000gn/T//fm-spawn-worktree-identity.Zhut8s/identity-no-project-repo/home/data/identity-no-project-repo-i4/brief.md records no delivery contract line (scaffolded before ship briefs recorded one); launching on the explicit --mode no-mistakes - confirm its definition of done matches
error: the repository identity of project '/var/folders/vt/36bg7pjx1711x3w5wyr1z88h0000gn/T/fm-spawn-worktree-identity.Zhut8s/identity-no-project-repo/project' could not be established (its git common directory did not resolve); refusing to launch treehouse get's worktree '/var/folders/vt/36bg7pjx1711x3w5wyr1z88h0000gn/T//fm-spawn-worktree-identity.Zhut8s/identity-no-project-repo/other-wt' without proof it belongs to the project's repository. Inspect target firstmate:fm-identity-no-project-repo-i4

===== case: identity-legit-worktree-i5 (exit=0) =====
warning: /var/folders/vt/36bg7pjx1711x3w5wyr1z88h0000gn/T//fm-spawn-worktree-identity.Zhut8s/identity-legit-worktree/home/data/identity-legit-worktree-i5/brief.md records no delivery contract line (scaffolded before ship briefs recorded one); launching on the explicit --mode no-mistakes - confirm its definition of done matches
spawned identity-legit-worktree-i5 harness=codex kind=ship mode=no-mistakes yolo=off window=firstmate:fm-identity-legit-worktree-i5 worktree=/var/folders/vt/36bg7pjx1711x3w5wyr1z88h0000gn/T//fm-spawn-worktree-identity.Zhut8s/identity-legit-worktree/wt

===== case: identity-selfhosted-home-i8 (exit=1) =====
warning: /var/folders/vt/36bg7pjx1711x3w5wyr1z88h0000gn/T//fm-spawn-worktree-identity.Zhut8s/identity-selfhosted-home/home/data/identity-selfhosted-home-i8/brief.md records no delivery contract line (scaffolded before ship briefs recorded one); launching on the explicit --mode no-mistakes - confirm its definition of done matches
error: treehouse get yielded a firstmate home, not a task worktree (resolved '/var/folders/vt/36bg7pjx1711x3w5wyr1z88h0000gn/T//fm-spawn-worktree-identity.Zhut8s/identity-selfhosted-home/home'; it is the active firstmate home); refusing to launch a worker for /var/folders/vt/36bg7pjx1711x3w5wyr1z88h0000gn/T/fm-spawn-worktree-identity.Zhut8s/identity-selfhosted-home/project inside firstmate's own home even though it belongs to the project's repository '/private/var/folders/vt/36bg7pjx1711x3w5wyr1z88h0000gn/T/fm-spawn-worktree-identity.Zhut8s/identity-selfhosted-home/project/.git'. Inspect target firstmate:fm-identity-selfhosted-home-i8

===== case: identity-selfhosted-seeded-i9 (exit=1) =====
warning: /var/folders/vt/36bg7pjx1711x3w5wyr1z88h0000gn/T//fm-spawn-worktree-identity.Zhut8s/identity-selfhosted-seeded/home/data/identity-selfhosted-seeded-i9/brief.md records no delivery contract line (scaffolded before ship briefs recorded one); launching on the explicit --mode no-mistakes - confirm its definition of done matches
error: treehouse get yielded a firstmate home, not a task worktree (resolved '/var/folders/vt/36bg7pjx1711x3w5wyr1z88h0000gn/T//fm-spawn-worktree-identity.Zhut8s/identity-selfhosted-seeded/sub-home'; it carries the seeded firstmate home marker .fm-secondmate-home); refusing to launch a worker for /var/folders/

... [4520 bytes truncated] ...

fhosted-operational/project inside firstmate's own home even though it belongs to the project's repository '/private/var/folders/vt/36bg7pjx1711x3w5wyr1z88h0000gn/T/fm-spawn-worktree-identity.Zhut8s/identity-selfhosted-operational/project/.git'. Inspect target firstmate:fm-identity-selfhosted-operational-id

===== case: identity-selfhosted-symlinked-op-ih (exit=1) =====
warning: /var/folders/vt/36bg7pjx1711x3w5wyr1z88h0000gn/T//fm-spawn-worktree-identity.Zhut8s/identity-selfhosted-symlinked-op/home/data/identity-selfhosted-symlinked-op-ih/brief.md records no delivery contract line (scaffolded before ship briefs recorded one); launching on the explicit --mode no-mistakes - confirm its definition of done matches
error: treehouse get yielded a firstmate home, not a task worktree (resolved '/var/folders/vt/36bg7pjx1711x3w5wyr1z88h0000gn/T//fm-spawn-worktree-identity.Zhut8s/identity-selfhosted-symlinked-op/alt-home'; it holds this fleet's operational directory /var/folders/vt/36bg7pjx1711x3w5wyr1z88h0000gn/T//fm-spawn-worktree-identity.Zhut8s/identity-selfhosted-symlinked-op/links/state); refusing to launch a worker for /var/folders/vt/36bg7pjx1711x3w5wyr1z88h0000gn/T/fm-spawn-worktree-identity.Zhut8s/identity-selfhosted-symlinked-op/project inside firstmate's own home even though it belongs to the project's repository '/private/var/folders/vt/36bg7pjx1711x3w5wyr1z88h0000gn/T/fm-spawn-worktree-identity.Zhut8s/identity-selfhosted-symlinked-op/project/.git'. Inspect target firstmate:fm-identity-selfhosted-symlinked-op-ih

===== case: identity-selfhosted-legit-ia (exit=0) =====
warning: /var/folders/vt/36bg7pjx1711x3w5wyr1z88h0000gn/T//fm-spawn-worktree-identity.Zhut8s/identity-selfhosted-legit/home/data/identity-selfhosted-legit-ia/brief.md records no delivery contract line (scaffolded before ship briefs recorded one); launching on the explicit --mode no-mistakes - confirm its definition of done matches
spawned identity-selfhosted-legit-ia harness=codex kind=ship mode=no-mistakes yolo=off window=firstmate:fm-identity-selfhosted-legit-ia worktree=/var/folders/vt/36bg7pjx1711x3w5wyr1z88h0000gn/T//fm-spawn-worktree-identity.Zhut8s/identity-selfhosted-legit/wt

===== case: identity-nested-project-ib (exit=1) =====
warning: /var/folders/vt/36bg7pjx1711x3w5wyr1z88h0000gn/T//fm-spawn-worktree-identity.Zhut8s/identity-nested-project/home/data/identity-nested-project-ib/brief.md records no delivery contract line (scaffolded before ship briefs recorded one); launching on the explicit --mode no-mistakes - confirm its definition of done matches
error: project '/var/folders/vt/36bg7pjx1711x3w5wyr1z88h0000gn/T/fm-spawn-worktree-identity.Zhut8s/identity-nested-project/enclosing/nested/project' is not the top level of the repository it resolves to, and a project has to be registered at its repository's top level for the repository identity '/private/var/folders/vt/36bg7pjx1711x3w5wyr1z88h0000gn/T/fm-spawn-worktree-identity.Zhut8s/identity-nested-project/enclosing/.git' to be the project's own rather than one walked up to from a subdirectory. The repository top level resolved from it is '/private/var/folders/vt/36bg7pjx1711x3w5wyr1z88h0000gn/T/fm-spawn-worktree-identity.Zhut8s/identity-nested-project/enclosing'; re-register this project at '/private/var/folders/vt/36bg7pjx1711x3w5wyr1z88h0000gn/T/fm-spawn-worktree-identity.Zhut8s/identity-nested-project/enclosing', or give this directory a repository of its own, and dispatch again. Refusing to launch treehouse get's worktree '/var/folders/vt/36bg7pjx1711x3w5wyr1z88h0000gn/T//fm-spawn-worktree-identity.Zhut8s/identity-nested-project/enclosing-wt' against an identity the project itself does not anchor. Inspect target firstmate:fm-identity-nested-project-ib

===== case: identity-own-subdir-ic (exit=1) =====
warning: /var/folders/vt/36bg7pjx1711x3w5wyr1z88h0000gn/T//fm-spawn-worktree-identity.Zhut8s/identity-own-subdir/home/data/identity-own-subdir-ic/brief.md records no delivery contract line (scaffolded before ship briefs recorded one); launching on the explicit --mode no-mistakes - confirm its definition of done matches
error: project '/var/folders/vt/36bg7pjx1711x3w5wyr1z88h0000gn/T/fm-spawn-worktree-identity.Zhut8s/identity-own-subdir/own-repo/services/api' is not the top level of the repository it resolves to, and a project has to be registered at its repository's top level for the repository identity '/private/var/folders/vt/36bg7pjx1711x3w5wyr1z88h0000gn/T/fm-spawn-worktree-identity.Zhut8s/identity-own-subdir/own-repo/.git' to be the project's own rather than one walked up to from a subdirectory. The repository top level resolved from it is '/private/var/folders/vt/36bg7pjx1711x3w5wyr1z88h0000gn/T/fm-spawn-worktree-identity.Zhut8s/identity-own-subdir/own-repo'; re-register this project at '/private/var/folders/vt/36bg7pjx1711x3w5wyr1z88h0000gn/T/fm-spawn-worktree-identity.Zhut8s/identity-own-subdir/own-repo', or give this directory a repository of its own, and dispatch again. Refusing to launch treehouse get's worktree '/var/folders/vt/36bg7pjx1711x3w5wyr1z88h0000gn/T//fm-spawn-worktree-identity.Zhut8s/identity-own-subdir/own-wt' against an identity the project itself does not anchor. Inspect target firstmate:fm-identity-own-subdir-ic

===== case: identity-relaunch-other-repo-if (exit=1) =====
warning: /var/folders/vt/36bg7pjx1711x3w5wyr1z88h0000gn/T//fm-spawn-worktree-identity.Zhut8s/identity-relaunch-other-repo/home/data/identity-relaunch-other-repo-if/brief.md records no delivery contract line (scaffolded before ship briefs recorded one); launching on the explicit --mode no-mistakes - confirm its definition of done matches
error: relaunch yielded a worktree that belongs to a different repository (resolved '/var/folders/vt/36bg7pjx1711x3w5wyr1z88h0000gn/T//fm-spawn-worktree-identity.Zhut8s/identity-relaunch-other-repo/other-wt'; its repository '/private/var/folders/vt/36bg7pjx1711x3w5wyr1z88h0000gn/T/fm-spawn-worktree-identity.Zhut8s/identity-relaunch-other-repo/other-project/.git'; the project's repository '/private/var/folders/vt/36bg7pjx1711x3w5wyr1z88h0000gn/T/fm-spawn-worktree-identity.Zhut8s/identity-relaunch-other-repo/project/.git'); refusing to launch a worker for /var/folders/vt/36bg7pjx1711x3w5wyr1z88h0000gn/T/fm-spawn-worktree-identity.Zhut8s/identity-relaunch-other-repo/project outside that project's own repository. Inspect target firstmate:fm-identity-relaunch-other-repo-if

===== case: identity-orca-other-repo-i6 (exit=1) =====
warning: /var/folders/vt/36bg7pjx1711x3w5wyr1z88h0000gn/T//fm-spawn-worktree-identity.Zhut8s/identity-orca-other-repo/home/data/identity-orca-other-repo-i6/brief.md records no delivery contract line (scaffolded before ship briefs recorded one); launching on the explicit --mode no-mistakes - confirm its definition of done matches
error: orca worktree create yielded a worktree that belongs to a different repository (resolved '/var/folders/vt/36bg7pjx1711x3w5wyr1z88h0000gn/T//fm-spawn-worktree-identity.Zhut8s/identity-orca-other-repo/other-wt'; its repository '/private/var/folders/vt/36bg7pjx1711x3w5wyr1z88h0000gn/T/fm-spawn-worktree-identity.Zhut8s/identity-orca-other-repo/other-project/.git'; the project's repository '/private/var/folders/vt/36bg7pjx1711x3w5wyr1z88h0000gn/T/fm-spawn-worktree-identity.Zhut8s/identity-orca-other-repo/project/.git'); refusing to launch a worker for /var/folders/vt/36bg7pjx1711x3w5wyr1z88h0000gn/T/fm-spawn-worktree-identity.Zhut8s/identity-orca-other-repo/project outside that project's own repository. Inspect target fm-identity-orca-other-repo-i6

===== case: identity-orca-legit-i7 (exit=0) =====
warning: /var/folders/vt/36bg7pjx1711x3w5wyr1z88h0000gn/T//fm-spawn-worktree-identity.Zhut8s/identity-orca-legit/home/data/identity-orca-legit-i7/brief.md records no delivery contract line (scaffolded before ship briefs recorded one); launching on the explicit --mode no-mistakes - confirm its definition of done matches
spawned identity-orca-legit-i7 harness=codex kind=ship mode=no-mistakes yolo=off window=fm-identity-orca-legit-i7 worktree=/var/folders/vt/36bg7pjx1711x3w5wyr1z88h0000gn/T//fm-spawn-worktree-identity.Zhut8s/identity-orca-legit/wt
Evidence: fm-gotmp CI regression: before/after the fixture fix, with base for comparison

### Before the fixture fix (branch bin/ + base tests/fm-gotmp.test.sh) - the CI regression not ok - teardown exited non-zero with a valid tasktmp ### After the fixture fix (branch HEAD) not ok - teardown did not remove the tasktmp dir (... still exists) ### Base commit d023c45 for comparison (same macOS-local removal assertion) not ok - teardown did not remove the tasktmp dir (... still exists)

### Before the fixture fix (branch bin/ + base tests/fm-gotmp.test.sh) - the CI regression
not ok - teardown exited non-zero with a valid tasktmp

### After the fixture fix (branch HEAD)
not ok - teardown did not remove the tasktmp dir (/var/folders/vt/36bg7pjx1711x3w5wyr1z88h0000gn/T//fm-gotmp-tests.fAm5KH/fm-td-rm-z2 still exists)

### Base commit d023c45 for comparison (same macOS-local removal assertion)
not ok - teardown did not remove the tasktmp dir (/var/folders/vt/36bg7pjx1711x3w5wyr1z88h0000gn/T//fm-gotmp-tests.guL75K/fm-td-rm-z2 still exists)
Evidence: New spawn worktree-identity suite result on the fixed head
ok - a pane sitting in the firstmate home is refused, not recorded as the task worktree
ok - a real worktree of an unrelated repository is refused
ok - an unreadable worktree repository identity refuses the launch instead of passing
ok - a project whose repository identity cannot be established refuses the launch
ok - a legitimate worktree of the project's repository still spawns
ok - a firstmate home that belongs to the project's own repository is still refused
ok - a seeded firstmate home in the project's own repository is refused
ok - a secondmate identity marker alone refuses the checkout as a task worktree
ok - a symlinked operational path does not argue a marked home out of being one
ok - the firstmate repository root is refused even when it belongs to the project's repository
ok - a directory holding the running fleet's operational state is refused as a home
ok - a symlinked operational override still identifies the home it points into
ok - an isolated worktree still spawns when firstmate's own homes share that repository
ok - a project nested inside another repository refuses the launch instead of borrowing its identity
ok - a project below its own repository's top level is refused without accusing a foreign repository
ok - a relaunch whose recorded worktree belongs to another repository is refused
ok - an Orca worktree belonging to another repository is refused
ok - an Orca worktree of the project's own repository still spawns
# all fm-spawn-worktree-identity tests passed
Evidence: Teardown home-identity suite result on the fixed head
ok - a seeded home in service keeps its identity and operational state
ok - a successful retirement returns a reusable checkout with no home residue
ok - a failed return restores the complete home and keeps its registration
ok - a staging holding unaccounted content is kept and reported, never deleted
ok - the double-fault path names every location holding the home and rearms nothing under it
ok - supported home layouts retire through the pooled and the standalone path alike
ok - unsafe home layouts refuse on both paths with the same reason
ok - an unrelated reusable checkout in the same pool is untouched
ok - no identity is cleared before the ownership check passes
ok - the next lease after a retirement reuses the retired slot and carries no home residue
ok - a rolled-back seed returns its lease with no seeded identity on the slot
ok - a seed rollback whose return fails restores the identity it staged
ok - a seed rollback that cannot clear its own identity keeps the lease instead of poisoning the slot
ok - a seed rollback that owns nothing on the slot hands its lease back untouched
# all fm-teardown-home-identity tests passed
- Outcome: ⚠️ 1 info across 1 run (10m59s)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 1 info
  • 🚨 tests/fm-gotmp.test.sh:80 - The intent's required fix is missing from the change. Criterion: "FIX IN THIS TASK - a regression this branch introduced. ... bin/fm-teardown.sh line 192 now unconditionally sources bin/fm-home-return-lib.sh, but the fake root built by tests/fm-gotmp.test.sh symlinks each library teardown sources and was never given the new one ... Fix it so the fixture provides every library the real teardown requires, following the pattern and commentary already used for the other symlinked siblings in that fixture." tests/fm-gotmp.test.sh is not in this branch's diff and contains no reference to fm-home-return-lib.sh. Both fixture builders (make_fake_root, ending at line 80, and the inline root in test_teardown_skips_gracefully_without_tasktmp, ending at line 158) symlink every other sourced library but not the new one. bin/fm-teardown.sh:158 sets SCRIPT_DIR from dirname "$BASH_SOURCE" without resolving the symlink, so it points at the fake bin/; with set -eu (line 156), the source at line 192 fails and the subprocess exits non-zero. All three cases fail, reproducing "not ok - teardown exited non-zero with a valid tasktmp". Fix: add ln -s "$ROOT/bin/fm-home-return-lib.sh" "$fake/bin/fm-home-return-lib.sh" to both builders with the sibling commentary. No other fixture needs it - tests/fm-gotmp.test.sh is the only file matching 'ln -s .bin/fm-.-lib.sh', and the three fixtures that copy bin/ wholesale (fm-teardown.test.sh:1545, fm-herdr-session-cleanup.test.sh:287, fm-claude-stop-autoarm-live-e2e.test.sh:45) pick the library up automatically.
  • ⚠️ bin/fm-test-run.sh:943 - The new families_for_changed_path arm maps bin/fm-home-return-lib.sh to pr-forge and secondmate only, but tests/fm-gotmp.test.sh - which drives the real bin/fm-teardown.sh subprocess and is the test this branch broke - is mapped to session-bootstrap (bin/fm-test-run.sh:180). bin/fm-teardown.sh itself maps to pr-forge only (line 932), so no targeted family run selected by either the library or teardown ever runs the fixture that enumerates teardown's sourced libraries. That is precisely why the breakage surfaced only in the full portable-serial lane. Consider adding session-bootstrap to the bin/fm-home-return-lib.sh arm (and, if the author agrees, to the bin/fm-teardown.sh arm) so a change to teardown's sourced-library set re-selects the fixture that models it. Flagging rather than fixing because the enumeration is a deliberate authoring decision and the teardown side is pre-existing.
  • ℹ️ bin/fm-ff-lib.sh:152 - validate_secondmate_home_shape() and VALIDATED_MARKER_ID were extracted in commit c4976f9 so bin/fm-spawn.sh's isolation gate could require a full seeded-home shape; commit 8071387 reverted that approach ("the marker alone is enough"), and grep across bin/ and tests/ shows the only caller left is validate_secondmate_home() at line 225 in the same file. The split now buys nothing and silently reorders a refusal diagnostic for ff-lib's five consumers (fm-config-push.sh:173, fm-stow-cascade.sh:201, fm-fleet-snapshot.sh:1179, fm-bootstrap.sh:382/430, ff-lib's own process_secondmate:427): a home marked for another secondmate that also lacks AGENTS.md previously reported "marked for secondmate X, expected Y" and now reports "not a firstmate home (missing AGENTS.md)", because the id comparison moved after the home-material checks. No existing test asserts that combination (fm-secondmate-safety.test.sh:1401 goes through fm-spawn.sh's own validate_firstmate_home_for_spawn, which kept the original order), so nothing breaks - but folding the shape function back into validate_secondmate_home would drop the indirection and restore the original diagnostic precedence.
  • ℹ️ tests/fm-teardown-home-identity.test.sh:1 - The file is committed as mode 100644 while 147 of the 149 tests/*.test.sh files are 100755 (the only other 644 is the pre-existing tests/fm-ask-user-authority.test.sh). bin/fm-test-run.sh invokes scripts with bash "$script" (lines 1556, 1663), so CI still runs it, but invoking ./tests/fm-teardown-home-identity.test.sh directly - the way its own header and the sibling identity test invite - fails with permission denied. chmod +x for consistency.

🔧 Fix: restore teardown fixture libs, family map, and ff-lib shape
1 info still open:

  • ℹ️ tests/fm-gotmp.test.sh:141 - test_teardown_skips_gracefully_without_tasktmp() builds its fake root inline with a library symlink list that is byte-for-byte the same set as make_fake_root()'s (I diffed the two extracted lists: identical, 14 entries plus the three stubs). The only real difference is the meta block, which omits tasktmp=. That duplication is exactly what made this round's regression fix a two-place edit, and it is the same shape that let the fixture drift behind bin/fm-teardown.sh's source list in the first place: a future library added to teardown will again silently break only whichever copy is forgotten. Simplification: have test_teardown_skips_gracefully_without_tasktmp call make_fake_root and then rewrite $fake/state/$id.meta without the tasktmp= line, leaving one authoritative enumeration of teardown's sourced siblings. Non-functional; the assertions and the real-subprocess exercise are unchanged.
⚠️ **Test** - 1 info
  • ℹ️ tests/fm-backend-orca.test.sh - tests/fm-backend-orca.test.sh ("Orca spawn should fail when metadata cannot be written"), tests/fm-teardown.test.sh ("herdr-preflight-missing-adapter"), and tests/fm-gotmp.test.sh ("teardown did not remove the tasktmp dir") each fail one assertion locally on macOS. All three fail identically on the base commit d023c45 from a clean export, so they are pre-existing environment-local failures, not introduced by this change. No action taken.
  • bash tests/fm-spawn-worktree-identity.test.sh on HEAD — 18/18 pass (firstmate-home, wrong-repo, unreadable/empty/garbage worktree identity, unreadable project identity, self-hosted home signals, non-top-level project, relaunch path, Orca path, two accept cases)
  • Pre-fix repro: clean git archive HEAD export with bin/fm-spawn.sh replaced by git show d023c451:bin/fm-spawn.sh, then bash tests/fm-spawn-worktree-identity.test.sh → not ok - spawn accepted the firstmate home as the task worktree
  • bash tests/fm-teardown-home-identity.test.sh on HEAD — all pass, including the lease-preserving vs. FM_HOME_RETURN_NOT_OWNED release cases
  • CI-regression repro: clean HEAD export with base tests/fm-gotmp.test.sh → not ok - teardown exited non-zero with a valid tasktmp; with the fixture fix that assertion passes
  • bash tests/fm-gotmp.test.sh on HEAD and on a clean base d023c45 export — identical remaining failure (teardown did not remove the tasktmp dir), confirming it is pre-existing
  • grep -rn 'ln -s .*bin/fm-' tests/*.sh and a sweep for teardown's sourced libs — fm-gotmp.test.sh is the only fixture symlinking teardown's libraries
  • bash bin/fm-test-run.sh tests/fm-spawn-worktree-settle.test.sh tests/fm-spawn-batch.test.sh tests/fm-spawn-pool-base-freshen.test.sh tests/fm-backend-orca.test.sh tests/fm-control-relaunch.test.sh tests/fm-teardown.test.sh tests/fm-teardown-endpoint-safety.test.sh tests/fm-tangle-guard.test.sh tests/fm-trace-context-spawn.test.sh
  • bash bin/fm-test-run.sh tests/fm-backend-orca.test.sh tests/fm-teardown.test.sh on a clean base d023c45 export — same two assertions fail
  • Captured the real CLI refusal transcript for every identity case by running the suite with the per-case spawn output echoed to stderr
⚠️ **Document** - 1 info
  • ℹ️ docs/scripts.md:87 - docs/scripts.md does not list the new shared library bin/fm-home-return-lib.sh, though peer shared libs (fm-lock-lib.sh, fm-config-inherit-lib.sh) are listed. Left unchanged deliberately: that table is already non-exhaustive (33 of 43 bin scripts are absent, including recently added ones like fm-procevent-lib.sh and fm-transition-lib.sh), no drift check enforces coverage, and adding a row here would be an addition rather than a staleness fix. Worth a separate decision on whether that inventory is meant to be complete.
✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@SilvioLima94
SilvioLima94 force-pushed the fm/fm-spawn-isolation-a1 branch from 7dcdb4e to 4bab329 Compare August 18, 2026 04:44
@SilvioLima94 SilvioLima94 changed the title fix(bin): prove worker worktree identity before arming a spawn fix(bin): refuse spawn worktrees outside the project's own repository Aug 18, 2026
The worker-isolation assertion proved only that the resolved worktree was a
real git top-level distinct from the project's primary checkout. Any other
repository satisfied that, so a spawn whose pane never left the firstmate home
recorded worktree=<firstmate home> and passed, which would have launched a
project worker straight into firstmate's own primary checkout. The settle
loop's two-consecutive-reads guard does not cover it: a pane that never moved
agrees with itself.

Prove repository membership positively instead. validate_spawn_worktree now
resolves the physical git common directory of both the project and the
worktree and requires them to be equal, so one repository's checkout and its
linked worktrees are accepted and every other repository is refused by name.
An identity that cannot be established on either side - not a repository, a
failed query, empty or unexpected output, an unresolvable path - refuses the
launch rather than passing as inconclusive.

The check sits in the single assertion every call site already shares, so the
treehouse-get path (tmux, herdr, zellij, cmux), the Orca worktree-create path,
and relaunch are all covered; secondmate spawns skip the assertion as before.

tests/fm-spawn-worktree-identity.test.sh covers the firstmate-home misrouting
case, wrong-repo in general, all three unreadable-identity shapes, the
unreadable project side, and both Orca call-site directions, and asserts a
legitimate worktree still spawns so the fix cannot pass by refusing
everything.
@SilvioLima94
SilvioLima94 force-pushed the fm/fm-spawn-isolation-a1 branch from 4bab329 to b608a60 Compare August 23, 2026 19:43
@greptile-apps

greptile-apps Bot commented Aug 23, 2026

Copy link
Copy Markdown

Confidence Score: 5/5

The PR appears safe to merge, with no concrete blocking or independently actionable new defect remaining after review.

The changed spawn paths fail closed when repository identity or isolation cannot be established, while the pooled-home lifecycle preserves ownership, lease, and recovery state across tested success and failure paths.

Reviews (1): Last reviewed commit: "no-mistakes(document): require project r..." | Re-trigger Greptile

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