Repository navigation
fix(backends): target all-digit tmux sessions by name and harden bash 3.2 compatibility - #345
CedricKhuaYanHan wants to merge 12 commits into
Conversation
The fm-brief.sh apostrophe-in-heredoc parse bug (issue kunchenguid#166, fixed in kunchenguid#173) was a whole-class problem: any bin script can regress on macOS /bin/bash 3.2.57 while parsing fine on modern bash. Guard the class three ways: - tests/fm-bash32-parse.test.sh: bash -n sweep over bin/, bin/backends/, and tests/, preferring /bin/bash when it is a 3.x bash (macOS) so dev machines get the true 3.2 parse check. - ci.yml bash32 job: parse everything under the official bash:3.2.57 docker image, since the Linux runner's own bash is too new to catch the heredoc-in-command-substitution quote-tracking class. - tests/fm-brief.test.sh: extend generation coverage to the --scout and --secondmate scaffolds so every generator path is exercised, not just the three ship-mode DOD blocks.
…task Port of the stashed fm-spawn numeric-session fix to where the code now lives (the tmux call moved from fm-spawn.sh into bin/backends/tmux.sh's fm_backend_tmux_create_task; the stash itself no longer applies and is left in place for firstmate to clean up). fm_backend_tmux_container_ensure reuses the current session's name when firstmate runs inside tmux, and that name can be all digits (e.g. a treehouse pool slot). tmux parses a bare numeric new-window -t target as a window INDEX - verified on a private socket: with sessions "2" and "fmhost" (fmhost current), -t "2" landed the window in fmhost:2; with "42" current, -t "42" forced index 42:42 instead of the next free index. The trailing colon (-t "$ses:") forces session-name interpretation. list-windows takes a target-session and is unaffected. Adds an all-digit-session regression case to the real-tmux smoke test; it fails with the bare form and passes with the colon.
An explicit caller merge method leaves merge_args empty, and bash 3.2's set -u treats expanding an empty array as unbound (fixed in bash 4.4), so every fm-pr-merge run with an explicit method after -- died with 'merge_args[@]: unbound variable' on macOS system bash. CI's newer bash masked it; tests/fm-pr-merge.test.sh extra-args already fails under /bin/bash 3.2 and now passes. Same guard idiom as fm-spawn's shared_args (1ff50b1). Swept bin/ for the class: every other bare "${arr[@]}"/"${arr[*]}" expansion is length-guarded, :- guarded, or provably non-empty at the expansion site.
…sh32 parse sweep scope
…no-mistakes tests/fm-tangle-guard.test.sh ran bin/fm-bootstrap.sh with the inherited host PATH, so bootstrap's real 'no-mistakes --version' probe executed inside the suite - the only real-CLI call in the whole test suite, and the header even promises hermetic fakebins. When the suite runs inside a no-mistakes pipeline test step, that probe can block indefinitely (the CLI phones the daemon that is busy executing the very step, observed as 17h-old wedged probe processes), wedging the suite until the run is reaped as 'daemon crashed during execution'. Pin both bootstrap invocations to a stub toolchain plus system dirs, exactly like every other bootstrap-invoking suite (fm-bootstrap, fm-session-start, fm-secondmate-sync, fm-secondmate-harness).
…rdr composer_state functions
|
Automated reminder: thanks for the PR! This branch currently has a merge conflict with the base branch. When you get a chance, please rebase onto (or merge) the latest base branch, resolve the conflict, and push. After that, checks will re-run and the PR will get looked at again. Noted for firstmate#345 at |
|
Automated reminder: this PR still looks blocked on a rebase or merge conflict fix. If you are still interested, please rebase onto the current base branch, resolve the conflict, and push. If I do not hear back, I may close this as inactive. |
|
I am closing this because it has been waiting on a rebase or merge-conflict fix since 2026-07-17, and I have not seen a comment or push since then. If you still want to keep working on this, please reopen it or open a new PR and mention this one. Happy to take another look when there is an update. |
Intent
Fix two firstmate tooling bugs plus one same-class bug found along the way, all around macOS system bash 3.2 compatibility and tmux session targeting. (1) The fm-brief.sh bash-3.2 parse bug (issue #166): the core apostrophe fix already landed on main in PR #173 before this branch, so this branch closes the remaining asked-for gaps: a repo-wide regression guard that runs bash -n over bin/, bin/backends/, and tests/ (tests/fm-bash32-parse.test.sh, preferring /bin/bash when it is a 3.x bash so macOS machines get the true 3.2 parse check), a new bash32 CI job that parses every script under the official bash:3.2.57 docker image because the Ubuntu runner's own bash 5.2 parser accepts the 3.2-breaking heredoc-in-command-substitution constructs and cannot catch this class natively, and extending tests/fm-brief.test.sh with the previously uncovered --scout and --secondmate scaffold variants. (2) Ship the stashed fm-spawn numeric-session fix: the stash targeted tmux new-window -t "$SES" in bin/fm-spawn.sh, but that code was since refactored into bin/backends/tmux.sh fm_backend_tmux_create_task, so per firstmate's explicit approval the equivalent one-character fix (-t "$ses:") was ported there instead of applying the conflicting stash, and the stash itself is deliberately left in place for firstmate to clean up. The trailing colon forces an all-digit session name (tmux reuses the current session name, which can be numeric) to parse as a session name instead of a window index; verified empirically on a private tmux socket that the bare form lands the window in the wrong session or forces a wrong index, and a regression case was added to the real-tmux smoke test that fails with the bare form. The byte-exact old-vs-new backend conformance test still passes because both old and new paths route through the shared backends dir. (3) Bonus fix per the captain's standing fix-failures-you-find rule: tests/fm-pr-merge.test.sh extra-args was failing under /bin/bash 3.2 before this branch, because fm-pr-merge.sh expands an empty merge_args array under set -u, an unbound-variable error until bash 4.4 that Linux CI masks; guarded with the repo's established "${arr[@]+...}" idiom from fm-spawn, and the rest of bin/ was swept for the class (all other array expansions are length-guarded, :-guarded, or provably non-empty). CONTRIBUTING.md documents the bash 3.2 compatibility contract, both trap classes, and which guard catches which. Deliberate choices a diff-only reviewer might flag: the CI docker job is intentionally a separate small job rather than part of lint; the new parse test includes tests/*.sh not just bin/ because the test suite also runs on macOS dev machines; the comment in bin/backends/tmux.sh create_task explains why list-windows keeps the bare form (it takes a target-session, unaffected); commit messages intentionally carry the empirical repro details. Later pipeline commits on the branch (exec bit on the new test, CONTRIBUTING syncs, SC2016 directive) were applied by the no-mistakes pipeline itself in earlier runs. Full behavior suite verified green under /bin/bash 3.2.57 locally.
ADDENDUM: one more same-theme fix on the branch: tests/fm-tangle-guard.test.sh ran bin/fm-bootstrap.sh with the inherited host PATH - the only real-host-CLI call in the suite - and its real 'no-mistakes --version' probe deadlocks when the suite executes inside a no-mistakes pipeline test step (observed wedged probe processes up to 17h old; this is what made earlier pipeline runs die at the test step as 'daemon crashed during execution'). Both bootstrap invocations are now pinned to a stub toolchain plus system dirs, matching every other bootstrap-invoking suite and the file's own hermeticity contract.
What Changed
fm_backend_tmux_create_taskinbin/backends/tmux.shto target the session explicitly with-t "$ses:", so an all-digit (numeric) session name is parsed as a session rather than a window index that lands the new window in the wrong place; added a regression case to the real-tmux smoke test.composer_stateglyph classification forbin/backends/cmux.shandbin/backends/herdr.sh, and restored the canonicalmerge_argsguard idiom inbin/fm-pr-merge.sh.tests/fm-bash32-parse.test.sh) plus abash:3.2.57Docker CI job that the Ubuntu runner's bash 5.2 parser cannot substitute for, and extendedtests/fm-brief.test.shwith--scout/--secondmatecoverage andtests/fm-tangle-guard.test.shto stub the toolchain instead of invoking the hostno-mistakes.CONTRIBUTING.mdand synceddocs/configuration.mdand the coding-guidelines skill.Risk Assessment
✅ Low: The branch is almost entirely additive test and CI coverage plus one verified one-character tmux targeting fix with its own regression test, and the round-1 review fix restored bin/fm-pr-merge.sh to match origin/main exactly.
Testing
The configured e2e suite already passed as baseline. I additionally exercised each part of this multi-fix change on its true end-user surface — the genuine macOS /bin/bash 3.2.57 — since that is exactly the environment these fixes target and where Linux CI's newer bash cannot catch the bug class. The repo-wide parse sweep (tests/fm-bash32-parse.test.sh) confirmed it selects and runs under /bin/bash 3.2.57; the tmux smoke test's new all-digit-session regression, the fm-pr-merge empty-array guard, the cmux/herdr UTF-8 glyph composer classification, the new scout/secondmate brief variants, and the tangle-guard hermeticity fix all pass. I also empirically reproduced the core tmux bug on a private socket: the pre-fix
-t \"204\"form mis-parses the numeric session name as a window index (forcing index 204), while the shipped-t \"204:\"form correctly lands the window at the next free index — evidence saved to tmux-numeric-session-repro.txt. No product or test failures; the full suite was already confirmed green and only exceeds a 2-minute foreground window due to real-tmux/backend timing, not failures.Evidence: tmux numeric-session bug/fix repro (bare form forces index 204, fixed form lands at next free index)
=== BARE FORM (buggy): tmux new-window -t "204" === session=204 index=1 name=zsh session=204 index=204 name=fm-bare <- forced to INDEX 204 === FIXED FORM: tmux new-window -t "204:" === session=204 index=2 name=fm-fixed <- lands at next free indexEvidence: bash 3.2 parse sweep + composer tests running under genuine /bin/bash 3.2.57
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
🔧 **Rebase** - 1 issue found → auto-fixed ✅
CONTRIBUTING.md- merge conflict rebasing onto origin/main🔧 Fix applied.
✅ Re-checked - no issues remain.
bin/fm-pr-merge.sh:93- Post-rebase, this commit (05aff90) no longer adds the set -u guard its message describes - main already got that guard via PR docs: document Orca backend adapter contract #209 (51f7186), so the remaining delta only rewrites the canonical unquoted idiom ${merge_args[@]+"${merge_args[@]}"} (the exact form used at bin/fm-spawn.sh:257, which the commit message claims to match) into a fully-quoted variant. Verified empirically: the base-commit script runs clean under /bin/bash 3.2.57 with an empty merge_args, and the new quoted form expands to zero words on 3.2, so behavior is identical - but the change is redundant, diverges from the repo's established idiom, and CONTRIBUTING now documents the quoted variant. Consider reverting to the unquoted form (and fixing the CONTRIBUTING example) for consistency, or dropping the delta..github/workflows/ci.yml:34- The new bash32 job pulls bash:3.2.57 anonymously from Docker Hub on every run; shared GitHub runners occasionally hit Docker Hub rate limits, so this job can flake independently of the code. Acceptable tradeoff for a true bash-3.2 parse gate - noting it so intermittent failures here are recognized as registry throttling, not a parse regression.🔧 Fix: restore canonical merge_args guard idiom matching main
1 info still open:
tests/fm-tangle-guard.test.sh:104- The new stub toolchain omits quota-axi (a required bootstrap tool per bin/fm-bootstrap.sh's TOOLS list) and its exit-0 treehouse stub fails bootstrap'streehouse get --help | grep --leasecapability probe, so these bootstrap runs emit benign MISSING: quota-axi and MISSING: treehouse lines - a slight divergence from the comment's 'matching every other bootstrap-invoking suite' claim (fm-session-start and fm-secondmate-liveness stub treehouse with --lease usage output). Harmless today because the assertions grep only ^TANGLE: lines and the hermeticity goal (never invoking host CLIs) is fully met.🔧 **Test** - 1 issue found → auto-fixed ✅
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"🔧 Fix: Fixed bash 3.2 UTF-8 character handling in cmux/herdr composer_state functions
✅ Re-checked - no issues remain.
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-bash32-parse.test.sh— repo-widebash -nparse sweep confirmed running under the real /bin/bash 3.2.57 (not a fallback modern bash)bash tests/fm-backend-tmux-smoke.test.sh— real-tmux smoke incl. new all-digit-session regression case (passes)Empirical repro:tmux new-window -t "204"(bare) forces window to index 204;-t "204:"(fixed) lands it at next free index 2 — captured to evidence file/bin/bash tests/fm-pr-merge.test.sh— empty merge_args guard under set -u passes on bash 3.2, incl. extra-args casebash tests/fm-brief.test.sh— new --scout and --secondmate scaffold variants generate cleanlybash tests/fm-tangle-guard.test.sh— bootstrap cases now stubbed (no real host no-mistakes probe), passes/bin/bash tests/fm-backend-cmux.test.shand/bin/bash tests/fm-backend-herdr.test.sh— UTF-8 prompt-glyph composer_state classification passes under bash 3.2bash tests/fm-backend.test.sh— old-vs-new backend command-log conformance still green✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.