Skip to content

fix(spawn): require a proven worktree root before ending the treehouse poll - #26

Merged
Bre77 merged 2 commits into
mainfrom
fm/fm-spawn-cwd-race
Jul 22, 2026
Merged

Bre77 merged 2 commits into
mainfrom
fm/fm-spawn-cwd-race

Conversation

@Bre77

@Bre77 Bre77 commented Jul 22, 2026

Copy link
Copy Markdown
Owner

Intent

bin/fm-spawn.sh's post-treehouse get worktree-detection poll accepted the FIRST pane cwd sample that merely differed from the project path, then handed it to validate_spawn_worktree. Reproduced live today (2026-07-22): on the herdr backend that first differing sample can be an intermediate cwd - the treehouse pool root (/home/brett/.treehouse) - captured while the subshell is still resolving, so the spawn refused with worktree root 'none' even though the pane landed in a valid worktree slot moments later. Failed 3 consecutive spawns on the api pool and 1 on the homey pool in the same session; other spawns in the same window won the race and succeeded, confirming it's timing-dependent rather than a hard failure.

Fix: only accept a sampled path once it proves out as an actual worktree root - it must differ from the project AND git -C <path> rev-parse --show-toplevel must resolve back to that same path. Otherwise the poll keeps trying until the existing 60s deadline, and the existing timeout error message is unchanged.

Also updated tests/fm-tangle-guard.test.sh's spawn-abort case: a pane that never leaves a non-worktree path now correctly polls the full deadline and hits the timeout error, not the old immediate validate_spawn_worktree message (which is no longer reachable via this path since a worktree is only ever accepted once already proven).

Testing

bin/fm-lint.sh (clean, pinned ShellCheck 0.11.0) and the full tests/*.test.sh suite (1554 assertions passing), including the two new fm-backend.test.sh regression cases (an intermediate non-worktree sample followed by the real worktree still succeeds; all-non-worktree samples for the full poll window still fail with the existing timeout error) and the updated fm-tangle-guard.test.sh case. One unrelated, pre-existing flaky failure in fm-afk-launch.test.sh ("launcher signal: interrupted lifecycle resumed or retained its lock") was independently reproduced on unmodified main (fails ~2/3 of runs) and is untouched by this change.

Bre77 added 2 commits July 22, 2026 13:18
…e poll

The worktree-detection poll after `treehouse get` accepted the first
pane cwd sample that merely differed from the project path. On herdr
that can be an intermediate cwd (the treehouse pool root) sampled
while the subshell is still resolving, so validate_spawn_worktree then
refused with "worktree root 'none'" even though the pane reached a
real worktree moments later. Now a sample is only accepted once
`git rev-parse --show-toplevel` confirms it IS a worktree root; the
poll otherwise keeps trying until the existing 60s deadline.
fm-spawn.sh's worktree-detection poll now only accepts a sample once
git rev-parse --show-toplevel proves it a real worktree root, so a
pane that never leaves a non-worktree path polls the full deadline
and hits the "did not enter a worktree within 60s" timeout instead of
the immediate validate_spawn_worktree message these cases used to hit.
Update the two abort assertions to match and stub sleep so the test
doesn't cost 60 real seconds per case.
@Bre77
Bre77 merged commit f28ed1f into main Jul 22, 2026
5 checks passed
Bre77 added a commit that referenced this pull request Jul 29, 2026
The Stage-7 alert-router cutover moved fm.ba.id.au off this repo's own
listener, so every inbound Twilio webhook was 401'd. Teslemetry/tools PR #26
made the router relay /captain-msg verbatim into the existing inbox dir
instead of validating it; this teaches the poll path to validate and
normalize (or quarantine) that shape, sharing one HMAC implementation with
the direct-listener path via a new fm_twilio_sig.py module.
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