Repository navigation
fix(tmux): target task-window creation by session name for numeric sessions - #450
Closed
chanjdaniel wants to merge 4 commits into
Closed
chanjdaniel wants to merge 4 commits into
chanjdaniel wants to merge 4 commits into
Conversation
…ect path (#1) * fix(spawn): wait for genuine isolated worktree, not just any non-project path The treehouse worktree wait loop was breaking on the first pane cwd that was not the project directory. Right after tmux new-window, the pane transiently reports the tmux server default (/home/danielc) before treehouse get runs, so the loop breaks immediately with WT=/home/danielc. The isolation guard then correctly refuses, aborting every spawn. Hoist the isolation invariant (real git worktree root, resolved toplevel equals itself, distinct from project checkout) into a reusable is_isolated_worktree() function and use it as the loop's break condition. This skips transient pre-chdir states and waits for the real worktree to appear. validate_spawn_worktree() now delegates to the same function as a redundant final assertion. * no-mistakes(test): make failing tests hermetic against ambient FM_HOME and system node * no-mistakes(document): mark herdr worktree-isolation symlink gap resolved in docs * no-mistakes(lint): fix SC2015 in fm-spawn is_isolated_worktree helper
…ked code (#2) * feat(self-fix): worktree-based self-fix flow so firstmate can ship its own fixes through the gate Add bin/fm-self-fix.sh, which creates an isolated git worktree of this repo on a fix branch (rooted outside any FM_HOME) and dispatches a crewmate into it via a new fm-spawn --worktree mode - so firstmate can fix its own tracked code through the no-mistakes gate without treehouse pooling and without moving the primary checkout off its default branch. - fm-spawn.sh: --worktree <path> skips treehouse get, uses the pre-created isolated worktree (same isolation assertion), starts the tmux window in it, and records selffix=1 in meta. All paths are byte-unchanged when the flag is absent. - fm-teardown.sh: selffix=1 tasks are cleaned with git worktree remove (after the unchanged landed-work safety check), not a treehouse return. Scoped to the tmux backend; other backends are a later follow-up. * no-mistakes(review): enforce tmux-only self-fix and skip fleet-sync on selffix teardown * no-mistakes(document): document worktree-based self-fix flow in scripts, AGENTS, architecture docs
When tmux session name is purely numeric (e.g. '0'), bare -t 0 is
parsed as a window-index target. new-window -t 0 then fails with
'index 0 in use'. Append trailing colon (-t "${ses}:") to force
session-name interpretation on the duplicate-check list-windows and
the new-window calls in fm_backend_tmux_create_task.
- Regression test in tests/fm-backend-tmux-smoke.test.sh (numeric
session + non-numeric session smoke-verified)
- Dated empirical evidence in docs/tmux-backend.md (tmux 3.6a)
chanjdaniel
force-pushed
the
fix/fm-tmux-numeric-session-t9
branch
from
July 11, 2026 03:07
edb1741 to
ea54270
Compare
Author
|
Closing - opened against the upstream parent by mistake; this work belongs only on our own fork (chanjdaniel/firstmate). Re-landing there. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Intent
Fix the tmux backend so task-window creation works when firstmate's tmux session has a purely numeric name (e.g. '0', the tmux default). The bug: tmux parses '-t 0' as a window-index target, not a session, so 'new-window -t 0' fails with 'index 0 in use'. The fix: append a trailing colon ('-t "${ses}:"') to force session-name interpretation on the duplicate-check list-windows and new-window calls in fm_backend_tmux_create_task. Regression test in tests/fm-backend-tmux-smoke.test.sh, documented in docs/tmux-backend.md as dated empirical evidence (2025-07-11, tmux 3.6a).
What Changed
bin/backends/tmux.shnow appends a trailing colon to the session target (-t "${ses}:") on the duplicate-checklist-windowsandnew-windowcalls infm_backend_tmux_create_task, so a purely numeric session name (e.g.0) is interpreted as a session rather than a window index; a regression section intests/fm-backend-tmux-smoke.test.shcovers both numeric and non-numeric sessions, with the behavior documented as dated empirical evidence indocs/tmux-backend.md.bin/fm-self-fix.shand extendsbin/fm-spawn.sh/bin/fm-teardown.shto support a worktree-based self-fix flow for firstmate's own tracked code: a plain isolatedgit worktreeon afix/<id>branch launched viafm-spawn.sh --worktree, recorded asselffix=1in meta and removed withgit worktree removeat teardown.fm-spawn.shisolation checks to wait for a genuine isolated worktree distinct from the primary checkout rather than accepting any non-project path, and syncsAGENTS.md,CONTRIBUTING.md, and thedocs/set to describe the numeric-session handling and self-fix flow.Risk Assessment
✅ Low: The core tmux numeric-session fix is minimal, correct, and covered by a real-tmux regression test; the accompanying spawn-hardening and self-fix commits are well-structured with an equivalent guard refactor and a teardown path gated behind the existing landed-work safety check, leaving only one minor operator-facing robustness gap.
Testing
Baseline test command (all
tests/*.test.sh) had already passed; I re-ran the targetedtests/fm-backend-tmux-smoke.test.shunder tmux 3.6a and it passed all sections including the two new numeric/non-numeric regression cases. To show the fix at the level an end user hits it, I manually reproduced the bug on a private socket — creating the numeric default session0, confirming bare-t 0fails withcreate window failed: index 0 in use, then demonstrating the patchedfm_backend_tmux_create_tasksuccessfully adds the task window to session0and still refuses duplicates. This is a shell/CLI backend change with no UI surface, so CLI transcripts are the appropriate reviewer-visible evidence; no screenshot applies. Overall: the fix works end-to-end and no issues found.Evidence: End-to-end bug reproduction and fix demonstration (CLI transcript)
=== BEFORE FIX (bare '-t 0') === >> tmux new-window -d -t 0 -n fm-task -c /tmp create window failed: index 0 in use ^^ BUG reproduced: window creation FAILED === AFTER FIX (trailing colon '-t "0:"') === ^^ FIX confirmed: window created in numeric session 0 >> Windows now in session 0: 0: tmux 1: fm-task >> Duplicate refusal still fires: error: window 0:fm-task already exists ^^ correctly refused duplicate windowEvidence: tmux backend smoke regression test output
ok - real tmux: fm_backend_tmux_create_task works with a purely numeric session name and refuses a duplicate ok - real tmux: fm_backend_tmux_create_task still works and refuses a duplicate with a non-numeric session namePipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
.agents/skills/afk/SKILL.md- branch carries 2 commit(s) that exist on your local main branch but were never pushed to origin/main; rebasing would bundle this unrelated work (147 file(s)) into the PR:Push main to origin, or rebase your branch onto origin/main, before gating.
🔧 Fix applied.
1 warning still open:
.agents/skills/afk/SKILL.md- branch carries 2 commit(s) that exist on your local main branch but were never pushed to origin/main; rebasing would bundle this unrelated work (147 file(s)) into the PR:Push main to origin, or rebase your branch onto origin/main, before gating.
⏭️ **Review** - skipped
bin/fm-self-fix.sh:37- bin/fm-self-fix.sh creates the worktree and fix/<id> branch (line 32), thenexecs into fm-spawn.sh. If the spawn fails (e.g. crew-dispatch.json is active but no --harness was forwarded), the worktree and branch are left orphaned with no cleanup, and because ofexecthe script cannot recover; a re-run with the same id then aborts on the existing-worktree/existing-branch guards, requiring manualgit worktree remove+branch -D. Consider droppingexecand cleaning up the created worktree/branch on a non-zero spawn exit.✅ **Test** - passed
✅ No issues found.
command -v tmux >/dev/null || { echo "tmux is required for e2e tests" >&2; exit 1; }; tmux -V; rc=0; for t in tests/*.test.sh; do echo "== $t =="; bash "$t" || rc=1; done; exit "$rc"bash tests/fm-backend-tmux-smoke.test.sh— full smoke suite passes including the newnumeric session nameandnon-numeric session still worksregression sectionsManual end-to-end repro: created tmux session0on a private socket, showedtmux new-window -d -t 0fails withcreate window failed: index 0 in use(pre-fix behavior), then called the patchedfm_backend_tmux_create_task 0 fm-task /tmpwhich created the window at index 1 in session0and correctly refused a duplicate✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.