Skip to content

fix(bin): harden bash 3.2 compat and gate cmux surface check on CLI exit status - #302

Closed
SebasWB wants to merge 5 commits into
kunchenguid:mainfrom
SebasWB:fm/fix-brief-q5
Closed

SebasWB wants to merge 5 commits into
kunchenguid:mainfrom
SebasWB:fm/fix-brief-q5

Conversation

@SebasWB

@SebasWB SebasWB commented Jul 6, 2026 •

Copy link
Copy Markdown

Intent

Fix macOS bash 3.2 compatibility gaps in the firstmate bin/ toolbelt. Original task: a bash 3.2 heredoc-in-command-substitution apostrophe bug made bin/fm-brief.sh fail to parse entirely (blocking all brief scaffolding on macOS), and bin/fm-spawn.sh batch mode failed under 3.2 set -u on an empty shared_args array; audit all of bin/ for both hazard classes and add a cheap CI regression guard. Investigation showed the two core bugs were already fixed on main by PR #173 (apostrophe reworded, shared_args guarded, regression test added), so this change deliberately covers only the remaining scope: (1) add a bash -n sweep over bin/.sh and bin/backends/.sh to the existing CI lint job, as the task explicitly requested, with a comment noting the 3.2-specific bug does not reproduce on the runner's newer bash; (2) add a warning comment ahead of the three DOD heredoc blocks in bin/fm-brief.sh - the task's prescribed proportionate fallback; (3) guard the one remaining possibly-empty array expansion found by the audit: should_force_self() prefixes in bin/fm-supervise-daemon.sh, where read -ra yields an empty array when the input's first line is empty and bash 3.2 set -u errors; the guard pattern used was mandated by the task and the empty case was empirically verified on /bin/bash 3.2.57; (4) record the bash 3.2 compatibility rule and both traps in CONTRIBUTING.md and mark the bash -n pre-push check as CI-enforced. The audit found no other unguarded possibly-empty array expansions and all remaining heredoc bodies have balanced apostrophes, so no further code changes were needed - a small diff is the intended outcome. All acceptance criteria verified locally with system /bin/bash 3.2.57. A previous pipeline run (01KWWFH1M3YCNQTCHTH8HESYKF) already validated this exact content - review, test, document, and lint all completed, with the test step fixing a pre-existing cmux jq-1.6 exit-status bug and deflaking the tmux smoke test - and failed only at the push step due to a 403 before the gate was reconfigured with the fork push target; this rerun delivers through the fork per the captain-approved flow.

What Changed

  • Hardened the bin/ toolbelt for macOS system bash 3.2: guarded the possibly-empty prefixes array expansion in should_force_self() in bin/fm-supervise-daemon.sh (empty "${arr[@]}" errors under set -u on 3.2), added a warning comment ahead of the heredoc-in-$(...) DOD blocks in bin/fm-brief.sh (an unbalanced apostrophe there breaks parsing of the whole script on 3.2), added a bash -n sweep over bin/*.sh and bin/backends/*.sh to the CI lint job, and recorded both 3.2 traps and the compatibility rule in CONTRIBUTING.md and the firstmate-coding-guidelines skill.
  • Fixed fm_backend_cmux_surface_exists in bin/backends/cmux.sh to capture the CLI output and gate on the CLI's own exit status before piping into jq -e, since jq 1.6's -e exits 0 on empty input and would misread a failed CLI call as "surface exists"; documented the gate in docs/cmux-backend.md.
  • Deflaked three e2e tests (added during pipeline fix rounds): the afk-inject e2e loop-readiness and HUP waits, the watcher-lock SIGHUP test (resets the inherited SIGHUP disposition), and the tmux backend smoke test (wider readiness waits).

Risk Assessment

✅ Low: A small, deliberately-scoped hardening change (CI syntax sweep, one canonical array guard matching existing repo usage, an exit-status gate fixing a real jq-1.6 false success, test deflaking, and docs) with no behavior-changing surprises and only theoretical residual edges.

Testing

Baseline full suite passed; on top of that I demonstrated the change working as an end user would hit it on macOS bash 3.2.57 — the CI bash -n sweep over all 50 bin scripts, fm-brief.sh scaffolding a complete brief end-to-end, and the real should_force_self() surviving the empty-array set -u case that provably crashes without the guard — and re-ran the seven relevant test files (including the three deflaked flaky ones), all green. No visual artifacts because this is a pure CLI/shell change with no rendered surface; transcripts are the product-level evidence.

Evidence: bash -n parse sweep on macOS bash 3.2.57 (all 50 bin scripts clean)

$ /bin/bash --version | head -1 GNU bash, version 3.2.57(1)-release (arm64-apple-darwin25) $ for f in bin/.sh bin/backends/.sh; do /bin/bash -n "$f" || echo "PARSE FAIL: $f"; done # exact CI sweep, run on macOS system bash 3.2 all 50 scripts parse clean under bash 3.2.57

$ /bin/bash --version | head -1
GNU bash, version 3.2.57(1)-release (arm64-apple-darwin25)

$ for f in bin/*.sh bin/backends/*.sh; do /bin/bash -n "$f" || echo "PARSE FAIL: $f"; done  # exact CI sweep, run on macOS system bash 3.2
all 50 scripts parse clean under bash 3.2.57
Evidence: fm-brief.sh end-to-end under bash 3.2.57 (scaffolds brief incl. heredoc DOD section)
$ FM_HOME=/tmp/fm-brief-ev.PvvOsQ /bin/bash bin/fm-brief.sh fix-widget-a1 myrepo   # macOS system bash 3.2.57
scaffolded: /tmp/fm-brief-ev.PvvOsQ/data/fix-widget-a1/brief.md (ship, mode=no-mistakes; replace {TASK})

--- scaffolded brief: '# Definition of done' section (rendered from the guarded heredoc-in-$() blocks) ---
# Definition of done
The task is complete only when committed on your branch.
When you believe it is complete, append `done: {summary}` to the status file and stop.
Firstmate will then instruct you to run /no-mistakes to validate and ship a PR.

You drive no-mistakes by responding to its gates, not by implementing fixes.
Follow the guidance no-mistakes itself provides for the mechanics: it loads when you invoke /no-mistakes, and `no-mistakes axi run --help` plus the `help` lines in each `axi` response are authoritative and version-matched to the installed binary.
Do not hand-edit, commit, or fix findings yourself while a run is active - the pipeline applies every fix.

Two firstmate-specific rules layer on top of that guidance:
- ask-user findings are not yours to answer: escalate to firstmate (rule 6) and stop.
  When the decision comes back, feed it to the gate with `no-mistakes axi respond` and let the pipeline apply it - do not route the question to "the user" or implement the fix yourself.
- Avoid `--yes`: the captain, not you, owns the ask-user decisions it would silently auto-resolve.

After /no-mistakes reports CI green (the CI-ready return point - do not wait for it to keep monitoring in the background until merge), append `done: PR {url} checks green` and stop. You are finished.
Evidence: should_force_self set -u guard: shipped form clean vs pre-fix unbound-variable crash on bash 3.2.57

guarded (shipped) form: exit=1 (no crash, correctly no match) # Counterfactual: the PRE-FIX unguarded loop 'for prefix in "${prefixes[@]}"' on the same input: /bin/bash: prefixes[@]: unbound variable

# Real should_force_self() extracted verbatim from bin/fm-supervise-daemon.sh,
# run on macOS /bin/bash 3.2.57 under set -u with FM_INJECT_SKIP whose first line
# is empty (read -ra then yields an EMPTY array).

$ /bin/bash -uc '. /tmp/fm-should-force-self.sh; FM_INJECT_SKIP=$'"'"'
x'"'"' should_force_self "some reason"; echo "exit=$?"'
guarded (shipped) form: exit=1 (no crash, correctly no match)

# Counterfactual: the PRE-FIX unguarded loop 'for prefix in "${prefixes[@]}"' on the same input:
/bin/bash: prefixes[@]: unbound variable
Evidence: Relevant test subset run (brief, spawn-batch, daemon, cmux, watcher-lock, tmux smoke, afk-inject e2e) — all pass
== tests/fm-brief.test.sh ==
ok - fm-brief.sh: no-mistakes/direct-PR/local-only briefs generate cleanly
ok - fm-brief.sh: no-mistakes DOD wording avoids the apostrophe regression
== tests/fm-spawn-batch.test.sh ==
ok - batch detection: single pair batches, non-pair rejected, single-task and slash-id stay single
ok - projects/ paths are scoped through the firstmate home for single-task spawn
== tests/fm-daemon.test.sh ==
ok - inject_msg: herdr pane-gone check defers before any busy/composer/submit call
ok - inject_msg: dispatches busy-guard/composer-guard/submit through the herdr backend and succeeds on a confirmed empty composer
== tests/fm-backend-cmux.test.sh ==
ok - fm_backend_cmux_list_live: lists only this home's scoped task workspaces using plain fm-<id> labels
ok - fm-spawn.sh: refuses backend=cmux for --secondmate spawns (mirrors Orca's refusal; no secondmate launch design exists yet)
== tests/fm-watcher-lock.test.sh ==
watcher: lock held by live pid 2511 but heartbeat is stale for 836676021s (>300s); inspect or stop that watcher before re-arming.
ok - arm reports FAILED and exits non-zero when no fresh watcher can be confirmed
== tests/fm-backend-tmux-smoke.test.sh ==
ok - real tmux: fm_backend_tmux_resolve_bare_selector fails for a window that does not exist
ok - real tmux: fm_backend_tmux_kill removes the window and is idempotent/best-effort
== tests/fm-afk-inject-e2e.test.sh ==
ok - Scenario C: a normal captain status injects exactly one clean single-line sentinel digest
all e2e injection tests passed
- Outcome: 🔧 1 issue found → auto-fixed (2) ✅ across 3 runs (1h33m21s)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 2 infos
  • ℹ️ bin/backends/cmux.sh:397 - Residual jq-1.6 edge: if fm_backend_cmux_cli exits 0 but emits empty output, the empty input still reaches jq -e, which exits 0 on jq 1.6 and would falsely report the surface as existing. The new || return 1 gate covers the real failure mode (CLI failure), and a successful list-panes --json always emits a JSON document, so this is theoretical; adding [ -n &#34;$out&#34; ] || return 1 would close it completely.
  • ℹ️ tests/fm-backend-tmux-smoke.test.sh:113 - The tag-line-80 poll times out silently after 100 iterations (~20s) instead of calling fail like the shell-ready poll above it does; on timeout the test falls through to the capture assertions, which still fail with the pane content but with a less direct message ("a 3-line capture should still contain the most recent output") than an explicit "pane never finished printing" failure would give.
🔧 **Test** - 1 issue found → auto-fixed (2) ✅
  • 🚨 tests failed with exit code 1
  • 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: deflake afk-inject e2e loop readiness and HUP wait
1 error still open:

  • 🚨 tests failed with exit code 1
  • 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: reset SIGHUP for watcher-arm HUP test; widen tmux smoke wait
✅ 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"
  • baseline: full suite for t in tests/*.test.sh; do bash &#34;$t&#34;; done (ran green before this round)
  • for f in bin/*.sh bin/backends/*.sh; do /bin/bash -n &#34;$f&#34;; done on macOS system bash 3.2.57 — the exact new CI sweep, all 50 scripts parse clean
  • manual e2e: FM_HOME=&lt;tmp&gt; /bin/bash bin/fm-brief.sh fix-widget-a1 myrepo under bash 3.2.57 — brief scaffolds and renders the full Definition-of-done heredoc section
  • manual guard check: real should_force_self() extracted from bin/fm-supervise-daemon.sh run under /bin/bash -u 3.2.57 with empty-first-line FM_INJECT_SKIP — guarded form exits 1 cleanly; pre-fix unguarded form reproduces prefixes[@]: unbound variable
  • bash tests/fm-brief.test.sh (apostrophe-wording regression guard)
  • bash tests/fm-spawn-batch.test.sh (batch empty shared_args regression)
  • bash tests/fm-daemon.test.sh
  • bash tests/fm-backend-cmux.test.sh (covers the surface_exists jq exit-status gate change)
  • bash tests/fm-watcher-lock.test.sh (deflaked SIGHUP test)
  • bash tests/fm-backend-tmux-smoke.test.sh (deflaked)
  • bash tests/fm-afk-inject-e2e.test.sh (deflaked)
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

SebasWB added 5 commits July 6, 2026 15:47
… array guard

The core bugs (fm-brief.sh apostrophe parse break, fm-spawn.sh empty
shared_args under set -u) were already fixed by PR kunchenguid#173 with a regression
test. This closes the remaining gaps from the same audit:

- ci.yml: add a bash -n sweep over bin/*.sh and bin/backends/*.sh to the
  lint job, catching syntax regressions shellcheck's parser tolerates.
- fm-brief.sh: warning comment ahead of the three DOD heredoc-in-$()
  blocks, since the bash 3.2 apostrophe trap does not reproduce on CI.
- fm-supervise-daemon.sh: guard the one remaining possibly-empty array
  expansion (should_force_self prefixes; read -ra yields an empty array
  when the input's first line is empty, which errors under 3.2 set -u).
- CONTRIBUTING.md: record the macOS bash 3.2 compatibility rule and the
  two known traps; mark the bash -n sweep as CI-enforced.

Audited all of bin/ for both hazard classes: no other unguarded
possibly-empty expansions, and all remaining $(cat <<EOF) bodies have
balanced apostrophes. Verified with /bin/bash 3.2.57 on macOS.
@SebasWB SebasWB changed the title Fm/fix brief q5 fix(bin): harden bash 3.2 compat and gate cmux surface check on CLI exit status Jul 6, 2026
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: closing this as stale. It has been waiting on a contributor update for 14+ days with no author push or comment. Reopen if you want to pick it back up.

fritznoff pushed a commit to fritznoff/starship that referenced this pull request Nov 2, 2026
…patch picker or the status second look (kunchenguid#302)

* fix(bin): never send Harbour or never-send-listed text to the dispatch picker or the status second look

The dispatch resolver now takes its off path for a private-app brief,
named by --project or by the brief's scaffolded setup line, matching the
command guard's always-excluded project. The status second look leaves out
lines from private-app tasks and lines matching config/dispatch-never-send
before the request is built, and withholds the whole scan when that list is
unreadable.

* no-mistakes(document): Sync second-look and resolver evidence with never-send exemptions

@meisbokai meisbokai left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review-rectify pass (independent re-review of the full PR diff at b3714f39).

Verdict: APPROVE — clean. (Submitted as a comment review because GitHub refuses a formal APPROVE from the PR's own author account; the verdict stands as written.) No new findings beyond what this branch's earlier review rounds already fixed; every fix on the branch (restricted backfill, 23def80/PR #295 client-authorship anchor, DEFAULT FALSE down shape, dropped impossible-replay claim, NULL-unknown rows deliberately left non-round-trippable) matches the accepted design and holds up under an independent pass.

ID Severity Finding Decision Fix
— none Migration 000073 up: backfill correctly restricted to provable rows (earn_membership_points = TRUE only), NULL-unknown rows preserved, known-flag rows untouched; atomic-deploy window documented accepted (no change) none needed
— none Down migration DEFAULT FALSE shape + documented non-round-trippable NULLs accepted (no change) none needed
— none Sweep: no remaining two-value DerivedRedeemable() callers, no SQL outside migrations/tests names redeemable, CSV export never named the column, all Redeemable usages are the JSON-only db:"-" field or unrelated domain terms accepted (no change) none needed
— none Docs (api-contract, RUNBOOK incl. NULL-count verification query + deploy-order, ohip-endpoints, ADR 0001, CODEMAPS) consistent with the dropped column accepted (no change) none needed

Basis: go build ./... and go vet ./... clean; go test ./internal/models/... ./internal/database/... ./internal/handlers/... ./internal/services/pms/... all green (incl. the new 000073 up/down migration probe against real PostgreSQL, which pins all four backfill rules, known-flag preservation, the non-destructive drop, and the DEFAULT FALSE down shape).

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.

3 participants