Repository navigation
fix(bin): wait out transient primary-checkout reads in the spawn worktree poll - #3834
Conversation
After `treehouse get` is sent, the worktree-discovery poll reads the pane's foreground-process cwd. While treehouse is still fetching and checking a slot out, the foreground process is treehouse itself and it reports the repository's PRIMARY checkout as its cwd for several seconds. The poll accepted any path that merely differed from the spawning project, so from a linked spawning home - whose project is itself a worktree of that repository - it adopted the primary, and the isolation guard then refused a launch whose slot treehouse went on to create normally. Screen every candidate with the isolation guard's own conditions, extracted as spawn_worktree_isolated, so a read the guard would reject stays a transient the poll keeps waiting through. The two-consecutive-reads rule and the guard as final backstop are unchanged; a pane that never reaches an isolated worktree still fails at the existing 60s deadline, now naming the last path it reported. The already-settled timing assertion counted whole-spawn wall time against a 5s budget and failed on unmodified HEAD on slower machines; it now counts pane reads, which is what "one confirming read, not an extra cycle" actually means.
Screening every discovery-poll candidate means a host that never reaches an isolated worktree spends the whole 60s window before refusing. That wait is deliberate - separating a transient from a terminal misconfiguration needs machinery this path does not want - so the refusal explains itself instead: the isolation check records why a candidate failed, and the deadline names the last path seen together with that reason. Message and diagnostics only; the poll's control flow is unchanged. Two suites asserted the guard's wording on paths the poll now rejects rather than adopts, so their refusal arrives from the deadline instead: realign fm-tangle-guard's non-git and subdirectory-of-primary cases (each now also asserting the stated reason, and the second the metadata absence it was missing) and the herdr projection e2e's forced non-worktree cwd.
The refusal-reason assertion for a path outside any repository assumed TMPDIR is not inside a git repository. Where it is, git walks up from the temporary directory, finds that repository, and the spawn reports the subdirectory cause instead - so the case passed or failed on a property of the host rather than on the behaviour under test. Build the path under a directory the test then names in GIT_CEILING_DIRECTORIES, which git documents as not chdir-ing up into a listed directory while looking for a repository. Git never excludes the directory being searched, so the ceiling is the parent of the path handed to the spawn. The assertions pin which cause fired rather than the sentence that explains it, leaving the operator wording free to improve.
|
Speaking as Kun's firstmate: Triage on DRAFT HEAD Contract-class: restore. Isolation for linked-worktree homes is already promised; treating a transient primary-checkout pane read as settle-and-refuse is a defect (#3808). Polling until an isolated slot appears (or loud deadline refuse) restores the promised isolation path without widening authority. VISION (short): First mate reads projects / workers in isolated copies — strengthens the refusal path when no isolated worktree is ever reached; Scripts own the mechanics (deterministic poll predicate). Status: Still draft — will not merge from triage. CI 34015704880 in progress (Lint + several serial/Herdr still pending; parallels/macOS/invariants green so far). Ask: When CI is fully green, mark the PR ready for review (leave draft until then if you prefer). No competing PRs / no code edits from triage. outcome=waiting-author; merge=no; Firstmate-flag=no; security FYI=none. |
…sts/fm-tangle-guard.test.sh ("non-worktree spawn did not say why the path was rejected (missing: 'not inside a git worktree')"). Root cause, in this PR's code: bin/fm-spawn.sh's spawn_worktree_isolated resolved the git toplevel with `wt_top_real=$(cd "$SPAWN_WT_TOP" ...)`. For a path in no repository, `git rev-parse --show-toplevel` yields empty, and `cd ""` is a SUCCESSFUL no-op on bash before 5.3 (CI's ubuntu-latest ships bash 5.2). The empty toplevel therefore resolved to fm-spawn's own cwd — the CI checkout — so the poll reported "it is a subdirectory of worktree root '/home/runner/work/firstmate/firstmate'" instead of the correct "it is not inside a git worktree". Dev machines with bash 5.3 fail `cd ""`, which is why the suite passed locally and only failed on CI; it is a genuine shell-portability defect in the reason vocabulary this change added, not a test-environment artifact. Fix (smallest root-cause change, 1 line + comment, bin/fm-spawn.sh:2168-2173): guard the empty value so it never reaches `cd` — if [ -n "$SPAWN_WT_TOP" ] && ! wt_top_real=$(cd "$SPAWN_WT_TOP" 2>/dev/null && pwd -P); then No change to the poll's timing or deadline behavior (respecting the recorded refusal-latency and spawn-wt-reason-vocabulary decisions), no new tests, no other files touched. Verification: - Reproduced the exact CI failure locally by putting bash 3.2 (same `cd ""` semantics as CI's 5.2) first on PATH: fails before the fix with the identical message shape, passes after. - tests/fm-tangle-guard.test.sh passes under both bash 3.2 and bash 5.3. - tests/fm-spawn-worktree-settle.test.sh and tests/fm-spawn-pool-base-freshen.test.sh pass; shellcheck -x bin/fm-spawn.sh clean. - bin/fm-test-run.sh --changed: 46 suites completed, every FM_TEST_END exit=0, 1076 passing assertions, 0 "not ok" (including fm-tangle-guard, fm-control-relaunch, fm-lint). The run ended on my own 900s wall-clock cap (rc=124), not on any test failure
Confidence Score: 5/5The PR appears safe to merge, with the changed polling behavior preserving the isolation contract while fixing the documented linked-worktree launch failure. The shared predicate rejects transient primary-checkout and invalid paths until a stable isolated worktree root appears, while existing supported backends settle at such a root and deadline failures remain explicit. Reviews (1): Last reviewed commit: "no-mistakes(ci): Fixed the "Behavior por..." | Re-trigger Greptile |
|
Speaking as Kun's firstmate: this is merged. Thank you @tiago-peixoto — really appreciate you taking the time on this. |
Intent
Restore crewmate and scout launches from a Firstmate home whose project is itself a linked worktree of a repository (a home whose workers take pooled worktrees of that same repo). Every launch from such a home currently exits with:
error: treehouse get did not yield an isolated worktree (resolved ''; worktree root ''; spawning project ''); refusing to launch to avoid tangling the primary checkout
treehouse does create a correct isolated worktree for the task, so this is a defect in bin/fm-spawn.sh's worktree discovery rather than a local configuration problem: the spawn settles on the repository primary checkout it observes before treehouse has finished preparing the slot, and the isolation guard then refuses the launch. A spawn should land on the isolated worktree treehouse creates, and should still refuse loudly when no isolated worktree is ever reached. Reported and confirmed on main as #3808.
What Changed
spawn_worktree_isolatedpredicate inbin/fm-spawn.shand made the pane-cwd discovery poll screen every read through it, so a pane reporting the spawning project or the repository's primary checkout whiletreehouse getprepares the slot is treated as a transient and waited out instead of adopted and then refused by the isolation guard.validate_spawn_worktreereuses the same predicate and reason for its own message.tests/fm-spawn-worktree-settle.test.shfor a transient primary-checkout read that later settles into the real slot and for a pane that never leaves the primary, and updated the expected refusal strings and causes in the tangle-guard, pool-base-freshen, and herdr presentation e2e suites; the tangle-guard non-git case now pinsGIT_CEILING_DIRECTORIESso the fixture directory is non-git wherever the suite runs, and stubs the poll's sleep.Risk Assessment
✅ Low: The change makes an existing guard strictly more conservative on one code path (the screen can only reject more candidates than the old poll, never accept more), preserves the guard predicate condition-for-condition for the relaunch and orca callers, and lands a regression test that provably fails against the base commit; the only cost is refusal latency the user has already accepted.
Testing
Beyond the already-green baseline run, I exercised the three touched suites directly and then demonstrated the intent as an end user would: real
bin/fm-spawn.shlaunches from a Firstmate home whose project is a linked worktree of a repository, with the task pane transiently reporting the repository primary checkout. On the base commit both the crewmate and scout launches exit 1 with the verbatim error from the report and write no task metadata; on the change both succeed and record the isolated slottreehouse getcreated. A pane that never reaches an isolated worktree still refuses loudly at the real 60s deadline, naming the last path seen and the reason it was rejected. The new regression case also fails against the base spawn script and passes against the change, and the worktree was restored clean after the swap. No UI surface is involved — this is a CLI launch path, so the evidence is command transcripts rather than screenshots.Evidence: End-to-end launch transcripts (before/after, crewmate + scout, and the loud refusal)
Source: End-to-end launch transcripts (before/after, crewmate + scout, and the loud refusal)
Evidence: Regression proof: new settle cases fail on base c499f84, pass on the change
Source: Regression proof: new settle cases fail on base c499f84, pass on the change
Evidence: Repro script used for the manual launches (rerunnable: fm3808-repro.sh <label> <worktree> <ship|scout> <stale-reads>)
Source: Repro script used for the manual launches (rerunnable: fm3808-repro.sh <label> <worktree> <ship|scout> <stale-reads>)
Evidence: Crewmate launch, before vs after
Evidence: Pane that never reaches an isolated worktree still refuses loudly (real 60s deadline)
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
bin/fm-spawn.sh:2898- Durability bound, not a regression: the fix converts the linked-home failure from "adopt the primary at ~2s and refuse" into "wait for the pane to reach an isolated worktree", but that wait is still capped by the pre-existing 60-iteration/60s deadline. Iftreehouse geton the reporter's host needs longer than 60s to fetch and check out the slot, the launch still ends in the same refusal class the intent asks to eliminate (now wordeddid not enter an isolated worktree within 60s (last seen '<primary>': it is the repository's primary checkout ...)). The change does not shrink that budget - it strictly enlarges the window in which a slow slot can still be adopted - so there is nothing to correct here; noting it because the fix's success on any given host depends on a timeout the change deliberately left alone. Any remedy (configurable or adaptive deadline) would extend the change beyond its stated scope.✅ **Test** - passed
✅ No issues found.
bin/fm-test-run.sh --changed --exclude-family real-herdr-gated./tests/fm-spawn-worktree-settle.test.sh— 4/4 pass on the change (includes the two new primary-checkout cases)Regression proof: same suite re-run withbin/fm-spawn.shswapped to basec499f84, then restored —test_transient_primary_checkout_is_not_acceptedfails there withdid not yield an isolated worktree (resolved '<primary>' ...)./tests/fm-tangle-guard.test.sh— 6/6 pass, ~18s wall (the stubbed poll sleep from review round 1 holds)./tests/fm-spawn-pool-base-freshen.test.sh— all pass, including the fourlinked spawning home: ...casesManual end-to-end launch, crewmate:bin/fm-spawn.sh demo-ship-a1 $R/acme-mate --mode no-mistakes --yolo offfrom a linked-worktree home, pane on the repository primary for 3 reads then the slot — base exits 1 with the reported error, change exits 0 and recordsworktree=$R/acme-slot-7Manual end-to-end launch, scout: same fixture with--scout— base exits 1 with the reported error, change exits 0 and recordsworktree=$R/acme-slot-7withkind=scoutManual loud-refusal check: same fixture with the pane never leaving the primary, real 60s deadline and realsleep— exits 1, writes nostate/<id>.meta, and reportsdid not enter an isolated worktree within 60s (last seen '$R/acme': it is the repository's primary checkout ...)docs/architecture.md:204- Judgment call, left unchanged: the spawn-isolation regression pointer names tests/fm-spawn-pool-base-freshen.test.sh and tests/fm-control-relaunch.test.sh, but the definitive regression for this change's invariant (the discovery poll screening a transient primary-checkout read instead of adopting it) is tests/fm-spawn-worktree-settle.test.sh. That suite pre-dates this change and the line never listed it, so the omission is not staleness this change introduced, and adding a third pointer would be opportunistic expansion of an unrelated line. Worth a follow-up only if the pointer list is meant to be exhaustive.✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.