Skip to content

fix(spawn): acquire crew worktrees via treehouse get --lease - #324

Open
nbdSteve wants to merge 2 commits into
kunchenguid:mainfrom
nbdSteve:fm/treehouse-lease-spawn-fix
Open

fix(spawn): acquire crew worktrees via treehouse get --lease#324
nbdSteve wants to merge 2 commits into
kunchenguid:mainfrom
nbdSteve:fm/treehouse-lease-spawn-fix

Conversation

@nbdSteve

@nbdSteve nbdSteve commented Jul 7, 2026

Copy link
Copy Markdown

Problem

treehouse v2.0.0's interactive treehouse get opens a subshell inside the worktree ("Type 'exit' to return"). tmux's #{pane_current_path} does not report that subshell's cwd, so fm-spawn.sh's worktree-discovery poll never observed the pane leaving the project directory and timed out at 60s on every crewmate/scout spawn - even though the worktree was created successfully. This blocks all crewmate dispatch on the current treehouse release.

Fix

Acquire the worktree via treehouse get --lease as a subprocess (path printed to stdout, banners to stderr), then cd the pane into it. This is the same durable primitive fm-home-seed.sh already uses for secondmate homes, and fm-bootstrap.sh already requires --lease support - the crewmate/scout path was simply left on the old interactive approach. Spawn drops from a 60s timeout to ~2s.

Also fixes a latent collision: when firstmate runs inside a tmux session whose name is a plain integer (e.g. 58), tmux new-window -t 58 is parsed as a window index, so a second task fails with index 58 in use. Addressing the session as <session>: forces session interpretation (correct for named sessions too).

Tests

  • Updated fm-spawn/backend tests to the lease contract (treehouse stub prints the worktree path on get --lease).
  • Converted the spawn old-vs-new byte-identical conformance test to a forward contract test, since this is an intended behavior change.
  • Added a regression test proving spawn succeeds purely from the lease, with no pane-cwd read.
  • Full suite passes locally; shellcheck clean on changed scripts.

Verified end-to-end: real crewmate spawns now complete in ~2s and launch into the leased worktree.

treehouse v2.0.0's interactive `get` opens a subshell in the worktree whose
cwd tmux's #{pane_current_path} does not report, so fm-spawn's old
worktree-discovery poll timed out at 60s on every crewmate/scout spawn even
though the worktree was created. Switch to `treehouse get --lease` (path on
stdout, banners on stderr) - the same durable primitive fm-home-seed.sh
already uses for secondmate homes, and the mode bootstrap already requires -
then cd the pane into the leased worktree. Spawn drops from a 60s timeout to
~2s.

Also fix a numeric-session-name collision: when firstmate runs inside a tmux
session whose name is a plain integer, `new-window -t <n>` is parsed as a
window index, so a second task collides with 'index <n> in use'. Address the
session as '<session>:' to force session interpretation.

Update the fm-spawn/backend tests to the lease contract and add a regression
test proving spawn no longer depends on pane-cwd polling.
nbdSteve

This comment was marked as duplicate.

…e-and-forget

A freshly created pane's shell can drop the first keystroke, so `cd <worktree>`
arrives as `d <worktree>` and the pane never leaves the primary checkout - the
agent then launches in the wrong directory. Read the pane cwd back and re-send
`cd` (up to 30x, 0.5s apart) until it matches the worktree, comparing
physically-resolved paths; abort with a clear error if it never lands. Re-adds
the small spawn_current_path backend dispatcher for the read.

Also make tests/fm-spawn-batch.test.sh hermetic: it used FM_CONFIG_OVERRIDE=''
(the real config dir), so a live config/crew-dispatch.json tripped the
explicit-harness backstop before the missing-brief check the test targets; point
it at an empty config dir. Update the spawn/backend test tmux stubs to answer
pane_current_path so the verify loop is exercised, and add a regression test
proving a dropped first cd is retried until the pane enters the worktree.
@nbdSteve

Copy link
Copy Markdown
Author

Follow-up commit (668a703): the post-lease cd into the worktree is now verified and retried rather than fire-and-forget. A freshly created pane can drop the first keystroke (cd <wt>d <wt>), leaving the agent in the primary checkout; the spawn now reads the pane cwd back and re-sends until it lands. Also makes fm-spawn-batch hermetic against a live config/crew-dispatch.json and adds a dropped-cd regression test.

This was referenced Jul 24, 2026
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