Skip to content

fix(spawn): target session not active window when creating crewmate windows#74

Open
hcho22 wants to merge 4 commits into
kunchenguid:mainfrom
hcho22:fix/fm-spawn-window-index
Open

fix(spawn): target session not active window when creating crewmate windows#74
hcho22 wants to merge 4 commits into
kunchenguid:mainfrom
hcho22:fix/fm-spawn-window-index

Conversation

@hcho22

@hcho22 hcho22 commented Jun 24, 2026

Copy link
Copy Markdown

What Changed

  • Changed the tmux new-window target in bin/fm-spawn.sh from the bare session name (-t "$SES") to the session-only form (-t "$SES:"), so tmux places each crewmate window at the next free index instead of resolving to the session's active window and failing create window failed: index N in use when low indices are already occupied.
  • Added tests/fm-spawn-window-index.test.sh, a regression test that runs on a private tmux socket and asserts the source carries the session-target form, the fixed command lands the window at the next free index, and the occupied-index target reproduces the index N in use failure the fix avoids.
  • Documented the new window-index test and the sibling batch-dispatch test in README.md.

Risk Assessment

✅ Low: A minimal, correct one-line tmux-targeting fix that is fully decoupled from downstream logic (the window is referenced by name, not index), backed by isolated private-socket regression tests and accurate README documentation.

Testing

Ran the new tests/fm-spawn-window-index.test.sh regression suite (passes) plus the sibling fm-spawn-batch.test.sh (passes), then reproduced the end-user-facing failure on an isolated private tmux socket: the pre-fix bare-session target resolves to the occupied active window and aborts with the bug report's exact create window failed: index 0 in use, while the fixed $SES: session target succeeds and places the crewmate window at the next free index (3). This is a CLI/tmux behavior change with no UI surface, so evidence is captured as CLI transcripts rather than screenshots. Note: on this host's tmux 3.6b the bare form happened to also pick a free index, confirming the crash is version-dependent as the test header states; the decisive evidence is the reproduced occupied-index failure that the fix avoids. Overall result: fix verified working, no findings.

Evidence: Pre-fix vs post-fix new-window behavior on an occupied session
=== firstmate-inside-tmux condition: low indices 0,1,2 occupied; active window = index 0 ===

--- PRE-FIX command: tmux new-window -d -t "$SES"  (bare session name -> active window) ---
windows before:
  index 0: w0 (ACTIVE)
  index 1: w1
  index 2: w2
exit status: 0
stderr/stdout: 
windows after:
  index 0: w0 (ACTIVE)
  index 1: w1
  index 2: w2
  index 3: fm-crew-test

--- POST-FIX command: tmux new-window -d -t "$SES:"  (session target -> next free index) ---
windows before:
  index 0: w0 (ACTIVE)
  index 1: w1
  index 2: w2
exit status: 0
stderr/stdout: <none>
windows after:
  index 0: w0 (ACTIVE)
  index 1: w1
  index 2: w2
  index 3: fm-crew-test
Evidence: Reproduced 'index 0 in use' failure and the fix avoiding it

=== The exact failure the fix avoids (bug report's 'index N in use') === $ tmux new-window -d -t "BUG:0" -n fm-crew-test exit status: 1 error: create window failed: index 0 in use === The fix (-t "$SES:") on the same occupied session: succeeds at next free index === $ tmux new-window -d -t "BUG:" -n fm-crew-test exit status: 0 error: <none> fm-crew-test landed at index: 3

=== The exact failure the fix avoids (bug report's 'index N in use') ===
On affected tmux versions, bare -t "$SES" resolves to the ACTIVE window (index 0),
equivalent to targeting that occupied index explicitly:

windows: 0 1 2  (active=0)
$ tmux new-window -d -t "BUG:0" -n fm-crew-test
exit status: 1
error: create window failed: index 0 in use

=== The fix (-t "$SES:") on the same occupied session: succeeds at next free index ===
$ tmux new-window -d -t "BUG:" -n fm-crew-test
exit status: 0  error: <none>
fm-crew-test landed at index: 3

Pipeline

Updates from git push no-mistakes

⏭️ **intent** - skipped

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 1 info
  • ℹ️ tests/fm-spawn-window-index.test.sh:84 - test_occupied_index_target_is_rejected asserts on the exact tmux error substring 'index 0 in use' (tests/fm-spawn-window-index.test.sh:84). This couples the regression test to tmux's wording for an occupied-index failure rather than to firstmate's own code. The substring has been stable across tmux versions for years, so the risk is low, but a future tmux build that rephrases the message would break this test even though the production fix remains correct. This is a deliberate, documented choice (it mirrors the bug-report error), so no action is required - noting it as a maintenance awareness point only.
✅ **Test** - passed

✅ No issues found.

  • bash tests/fm-spawn-window-index.test.sh - all 3 assertions pass (source uses $SES:; session-target picks next free index; occupied-index target rejected)
  • bash tests/fm-spawn-batch.test.sh - all pass (sibling fm-spawn test documented alongside this change)
  • Manual repro on a private tmux socket (-L, $TMUX unset): built a session with indices 0,1,2 occupied and active window on index 0, then ran tmux new-window -d -t &#34;BUG:0&#34; (the active window the bare form resolves to) -> create window failed: index 0 in use, and tmux new-window -d -t &#34;BUG:&#34; (the fix) -> exit 0, window landed at index 3
  • Verified worktree left clean and removed stray private tmux sockets/servers created during testing
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

hcho22 added 4 commits June 24, 2026 16:29
new-window -t "$SES" resolved to the session's active window and tried to
create at that occupied index, failing "create window failed: index N in use"
when low window indices were occupied. The trailing colon ("$SES:") forces
session-only targeting so tmux picks the next free index.
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