Skip to content

fix(bin): load backend sibling libraries when sourced under zsh - #6221

Merged
kunchenguid merged 4 commits into
kunchenguid:mainfrom
guanchengh-lgtm:fm/fm-base-failing-suites
Oct 1, 2026
Merged

kunchenguid merged 4 commits into
kunchenguid:mainfrom
guanchengh-lgtm:fm/fm-base-failing-suites

Conversation

@guanchengh-lgtm

@guanchengh-lgtm guanchengh-lgtm commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Intent

Context: a worker building another fix ran 63 changed-selection test suites of the firstmate repository. Seven failed the same way on the base commit, so they are not caused by its change: fm-muse-harness, fm-timeout-lib, fm-harness-precedence, fm-calm-claude-mod, fm-backend zsh source, fm-control-relaunch and fm-git-strip-ai-trailers. Real-herdr and live test families were not run. The Outside Voice verified all seven fail every time on a clean default branch on macOS with Bash 3.2 and zsh, while upstream CI passes them because it runs Bash 5 on Linux without zsh. Two of the causes are ours to fix and need a fix: fm_backend_source in bin/fm-backend.sh depends on word splitting, which zsh does not do, so sourcing a backend under zsh fails (a regression against a contract the repository tests on purpose); and the fm-calm-claude-mod test uses the Bash 4.4 expansion ${var@Q}, which fails on older Bash with a bad substitution.

What Changed

  • fm_backend_source in bin/fm-backend.sh now passes each backend's sibling library list through the positional parameters (set -- / "$@") and no longer uses an unquoted space-separated string. Under zsh, which does not word-split, the old string was read as one path, so the call failed. The loop local is now sibling, not path, because zsh ties path to PATH, and a local named path would clobber PATH while the adapter loads.
  • tests/fm-backend.test.sh limits the zsh check to backend name matching and the sibling precheck. It also adds a stub-adapter case that confirms PATH still resolves external commands while fm_backend_source loads a backend under zsh.
  • tests/fm-calm-claude-mod.test.sh replaces the Bash 4.4 ${var@Q} expansions in its generated Node scripts with a js_string helper (it uses JSON.stringify in Node). The suite now runs on stock macOS Bash 3.2 without a bad-substitution error.

🤖 Generated with Claude Code

Risk Assessment

✅ Low: The change is small and well-bounded. Moving the sibling list into function-local positional parameters makes the list split the same way under bash and zsh. The rename removes the clobbering of the zsh path variable, which is tied to PATH. No adapter or sibling library reads the inherited positional parameters at top level. The tests replace ${var@Q} with a JSON-encoded node literal that works on Bash 3.2, and the new zsh PATH check tests real behavior.

Testing

I sourced bin/fm-backend.sh in real zsh and in real macOS Bash 3.2, at both the base commit and the head commit. At base, zsh rejected tmux, herdr, zellij and cmux. At head, zsh loaded all five backends, rejected the bogus name, and kept PATH working. Bash behavior did not change. On Bash 3.2, both changed suites pass at head. The base calm-claude-mod suite fails with "bad substitution". I removed all temporary files.

  • Live validation: ✅ go - 6 of 6 scenarios driven live against the product
Scenario Result Live Evidence
A zsh user sources bin/fm-backend.sh and loads each known backend (tmux, herdr, zellij, orca, cmux); every call returns 0 (base: 4 of 5 returned 1) ✅ pass live zsh-backend-source-base-vs-head.txt
Adversarial: after a backend loads under zsh, external commands (dirname) still resolve, so the zsh path local does not clobber PATH ✅ pass live zsh-backend-source-base-vs-head.txt (PATH_OK, no 'command not found' at head); fm-backend.test.sh PATH-intact check ok
Adversarial: under zsh, an unknown backend name (bogus) is still rejected with 'unknown backend' and a non-zero exit ✅ pass live zsh-backend-source-base-vs-head.txt
Bash 3.2 callers see no change: all five backends load and bogus is rejected, the same as at base ✅ pass live zsh-backend-source-base-vs-head.txt bash section
The fm-calm-claude-mod suite runs on stock macOS Bash 3.2 without 'bad substitution' (base exit 1, head exit 0) ✅ pass live suites-head-bash32.txt
The fm-backend suite, with its zsh source checks, passes on Bash 3.2 with zsh present ✅ pass live suites-head-bash32.txt
Evidence: zsh/bash fm_backend_source base vs head

Source: zsh/bash fm_backend_source base vs head

=== BASE 549e07f3 ===
zsh fm_backend_source tmux -> RC=1 PATH_OK  | 
zsh fm_backend_source herdr -> RC=1 PATH_OK  | 
zsh fm_backend_source zellij -> RC=1 PATH_OK  | 
zsh fm_backend_source orca -> RC=0 PATH_OK  | /var/folders/p3/95t2_00n2jl3r2cn79bfn18h0000gp/T/fm-base.U6RPEn/bin/backends/orca.sh:13: command not found: dirname
zsh fm_backend_source cmux -> RC=1 PATH_OK  | 
zsh fm_backend_source bogus -> RC=1 PATH_OK  | error: unknown backend 'bogus' (known: tmux herdr zellij orca cmux)
--- bash 3.2 ---
bash fm_backend_source tmux -> RC=0
bash fm_backend_source herdr -> RC=0
bash fm_backend_source zellij -> RC=0
bash fm_backend_source orca -> RC=0
bash fm_backend_source cmux -> RC=0
bash fm_backend_source bogus -> RC=1
=== HEAD ffb67ec0 ===
zsh fm_backend_source tmux -> RC=0 PATH_OK  | 
zsh fm_backend_source herdr -> RC=0 PATH_OK  | 
zsh fm_backend_source zellij -> RC=0 PATH_OK  | 
zsh fm_backend_source orca -> RC=0 PATH_OK  | 
zsh fm_backend_source cmux -> RC=0 PATH_OK  | 
zsh fm_backend_source bogus -> RC=1 PATH_OK  | error: unknown backend 'bogus' (known: tmux herdr zellij orca cmux)
--- bash 3.2 ---
bash fm_backend_source tmux -> RC=0
bash fm_backend_source herdr -> RC=0
bash fm_backend_source zellij -> RC=0
bash fm_backend_source orca -> RC=0
bash fm_backend_source cmux -> RC=0
bash fm_backend_source bogus -> RC=1
Evidence: Changed suites on Bash 3.2 (head) and calm suite base comparison

Source: Changed suites on Bash 3.2 (head) and calm suite base comparison

\### HEAD: /bin/bash tests/fm-calm-claude-mod.test.sh
ok - the Calm mod is one hooks module, linked into the project's auto-load path, with no command, skill, agent, or classic hook path that bypasses its exact opt-in
ok - the Pi working ship renders byte-for-byte the shared sprite core's frame painted in standard ANSI, at every width, cadence step, freeze, clamp, and reset
ok - the Raster packing lays the shared frame out row-major in Claude Code's dark or light theme palette, using light as the both-readable fallback, with plain padding, default backgrounds, BMP glyphs, clipping, and a standard base64 encoding
ok - the Calm policy resolves the shared preference exactly as Pi does, reads on, max, and off as Pi does, and shares Pi's 240-character-or-newline preservation behavior while classifying working notes by stop reason, tool use, and restored transcript shape
ok - the supervision notes read the store owner's tail copy and markers as Pi does: sailboat and anchor lines, silent rows skipped, bounded replay of unread and unprocessed rows not already shown in the session, and latch notes
ok - the mod's operational-input classifier agrees with bin/fm-operational-input.sh on all 77 corpus cases: every current kind the owner encodes, every legacy shape, and every near miss
ok - the mod's doorbell port agrees with bin/fm-operational-input.sh doorbell-kind on all 28 cases: every record the owner writes and every unbacked or malformed near miss
exit=
\### HEAD: /bin/bash tests/fm-backend.test.sh (zsh subset shown)
exit=0
ok - zsh: fm_backend_source recognizes known backends and rejects unknown ones
ok - zsh: fm_backend_source keeps PATH intact while loading a backend adapter
ok - fm_backend_source: missing adapter fails before lifecycle continuation
ok - fm_backend_source: unreadable adapter fails before lifecycle continuation
warning: templates not found in /opt/homebrew/opt/git/share/git-core/templates
warning: templates not found in /opt/homebrew/opt/git/share/git-core/templates
ok - fm-spawn.sh: auto-detect resolves nested tmux-in-herdr to tmux and stays silent end to end
Bash: GNU bash, version 3.2.57(1)-release (arm64-apple-darwin25)
BASE 549e07f3 tests/fm-calm-claude-mod.test.sh on /bin/bash: exit=1, ": bad substitution", "not ok - plugin shape check did not complete"
HEAD ffb67ec0 tests/fm-calm-claude-mod.test.sh on /bin/bash: exit=0, all 7 checks ok

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 6 of 6 scenarios driven live against the product
Scenario Result Live Evidence
A zsh user sources bin/fm-backend.sh and loads each known backend (tmux, herdr, zellij, orca, cmux); every call returns 0 (base: 4 of 5 returned 1) ✅ pass live zsh-backend-source-base-vs-head.txt
Adversarial: after a backend loads under zsh, external commands (dirname) still resolve, so the zsh path local does not clobber PATH ✅ pass live zsh-backend-source-base-vs-head.txt (PATH_OK, no 'command not found' at head); fm-backend.test.sh PATH-intact check ok
Adversarial: under zsh, an unknown backend name (bogus) is still rejected with 'unknown backend' and a non-zero exit ✅ pass live zsh-backend-source-base-vs-head.txt
Bash 3.2 callers see no change: all five backends load and bogus is rejected, the same as at base ✅ pass live zsh-backend-source-base-vs-head.txt bash section
The fm-calm-claude-mod suite runs on stock macOS Bash 3.2 without 'bad substitution' (base exit 1, head exit 0) ✅ pass live suites-head-bash32.txt
The fm-backend suite, with its zsh source checks, passes on Bash 3.2 with zsh present ✅ pass live suites-head-bash32.txt
  • zsh -c "source bin/fm-backend.sh && fm_backend_source <tmux|herdr|zellij|orca|cmux|bogus>; command -v dirname" at base 549e07f3 (git archive copy) and head
  • bash -c "source bin/fm-backend.sh && fm_backend_source <each>" on /bin/bash 3.2.57 at base and head
  • /bin/bash tests/fm-backend.test.sh (head)
  • /bin/bash tests/fm-calm-claude-mod.test.sh (head)
  • base copy of tests/fm-calm-claude-mod.test.sh run on /bin/bash 3.2 (temp file, removed)
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@greptile-apps

greptile-apps Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 4/5

[Medium risk] Fixes shell library loading for zsh compatibility.

The PR does not yet appear safe to merge because real backend adapters can still load incompletely under zsh.

Reviews (2) · Last reviewed commit: "test: narrow the zsh backend claim to na..."

Comment thread bin/fm-backend.sh
Comment on lines +651 to +653
for rel in "$@"; do
sibling="$FM_BACKEND_LIB_DIR/$rel"
fm_backend_source_readable "$sibling" || return 1

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Real adapters load incompletely
Under zsh, this new check can pass for every sibling file, but the real adapters still use BASH_SOURCE to locate those files when sourcing them. Zsh does not populate BASH_SOURCE, so an adapter can look in the wrong directory. fm_backend_source can then report success and mark the adapter as loaded even though required shared functions are missing. The new stub test does not exercise the real adapter imports.

Knowledge Base Used: Agent backends and harnesses

Comment thread tests/fm-backend.test.sh
mkdir -p "$stub/backends"
printf 'command -v dirname > "%s"\n' "$probe" > "$stub/backends/orca.sh"
: > "$stub/fm-composer-lib.sh"
zsh -c "cd '$ROOT' && source bin/fm-backend.sh && FM_BACKEND_LIB_DIR='$stub' && fm_backend_source orca" >/dev/null 2>&1 \

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Zsh regression check skips CI
The new check runs only when zsh is installed. The described Linux CI environment does not install zsh, so CI can pass even if backend loading under zsh regresses again. This leaves the new regression test unable to protect the behavior it was added to cover.

Nova Agent B added 4 commits October 1, 2026 18:00
fm_backend_source kept each backend's sibling list in one space-separated
string and iterated it unquoted. zsh does not word-split an unquoted
expansion, so the readability check saw the whole list as one path and
refused every backend with more than one sibling. Hold the list in the
function's positional parameters instead, which needs no word splitting
in Bash 3.2, Bash 5, or zsh.

The existing zsh case in tests/fm-backend.test.sh covers it wherever zsh
is installed.
The suite injected shell values into its generated Node scripts with the
${value@Q} transformation, which needs Bash 4.4. Stock macOS Bash 3.2
reports a bad substitution, so every case failed before it asserted
anything. Build each JavaScript string literal with JSON.stringify
through a small helper instead, which works on any Bash and is a valid
literal for any value.
Under zsh the adapters locate their siblings through BASH_SOURCE, so a
successful fm_backend_source is not a full load. Assert only what the
contract states, and pass js_string values after -- so node never reads
a leading-dash value as its own option.
@guanchengh-lgtm
guanchengh-lgtm force-pushed the fm/fm-base-failing-suites branch from d3a85bb to ffb67ec Compare October 1, 2026 10:02
@guanchengh-lgtm guanchengh-lgtm changed the title fix(bin): load backend sibling libraries under zsh fix(bin): load backend sibling libraries when sourced under zsh Oct 1, 2026
@kunchenguid
kunchenguid merged commit 589ccec into kunchenguid:main Oct 1, 2026
20 of 21 checks passed

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: this is merged. Thank you @guanchengh-lgtm — really appreciate you taking the time on this.

contract-class: restore — tip fm_backend_source used an unquoted space-separated sibling string; zsh does not word-split, so sourcing backends under zsh failed against the repository's own zsh portability contract. Positional set -- / "$@" restores that path; calm-mod test ${var@Q} → js_string restores Bash 3.2 suite run. Greptile P1 (adapters still use BASH_SOURCE for their own sibling locate under zsh) is pre-existing and outside this PR's sibling-precheck claim — not a merge blocker.

VISION: One captain/interface — aligns. Authority — aligns. Scripts/judgment — aligns. Restart — n/a. Delegation — n/a. Fleet/vendor — aligns (backend adapters load under zsh name/sibling precheck). Scope — aligns.

Squash merge 589ccec821bf6310ce888e2a702e4fc9258eb1e8. Firstmate flag no.