Skip to content

fix(hermes): tolerate empty args under bash 3.2 set -u - #8399

Merged
kunchenguid merged 1 commit into
kunchenguid:mainfrom
fmaggi-cw:fm/fm-hermes-bash32-words
Nov 13, 2026
Merged

kunchenguid merged 1 commit into
kunchenguid:mainfrom
fmaggi-cw:fm/fm-hermes-bash32-words

Conversation

@fmaggi-cw

@fmaggi-cw fmaggi-cw commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Intent

Fix a crash in bin/fm-hermes-process-lib.sh: in fm_hermes_process_matches, the loop 'for word in "${words[@]}"; do' aborts with 'words[@]: unbound variable' under set -u on macOS's default bash 3.2 when the args string is empty (words is an empty array). The fix changes only that loop to 'for word in ${words[@]+"${words[@]}"}; do', and adds one regression test in the existing hermes test suite that calls the function with an empty args string under set -u and passes under /bin/bash 3.2 (it failed before the fix). Nothing else is in scope. This branch already has open PR #8399 against kunchenguid/firstmate main from the fork fmaggi-cw/firstmate; the maintainer confirmed the fix and asked only that it be re-raised through no-mistakes so the PR body carries the structured Pipeline attestation bound to the head. Change no code beyond what the pipeline's own fix rounds require; keep the existing PR title and narrative.

What Changed

  • fm_hermes_process_matches in bin/fm-hermes-process-lib.sh now loops over ${words[@]+"${words[@]}"}. Under set -u, macOS's bash 3.2 treats an empty array expansion as an unbound variable, so an empty args string used to abort the caller with words[@]: unbound variable. Now that case expands to nothing on every bash version and the function returns non-zero.
  • tests/fm-hermes-harness.test.sh adds a regression assertion: calling fm_hermes_process_matches '' must return non-zero instead of crashing. Under /bin/bash (3.2.57) the suite fails at this point before the fix and gets past it after.

Risk Assessment

✅ Low: The change is a one-line bash 3.2 empty-array expansion guard and does not change behavior for non-empty input. It also covers the empty /proc cmdline path. It comes with a behavioral regression test that runs under the suite's set -u, and the diff matches the stated intent exactly.

Testing

I sourced the library directly under set -u with macOS /bin/bash 3.2.57. Empty and whitespace-only args crashed with 'words[@]: unbound variable' on the base library. With the fix they return 1 (no match), and the matching results for real hermes, node TUI, and python -m invocations are unchanged. I also ran the hermes test suite under /bin/bash with the base and fixed libraries. With the base library it aborts at the new empty-args assertion; with the fix it gets past it. On this Mac the suite then stops at a later 'NUL argv identity' assertion that reads /proc/<pid>/cmdline. That assertion fails the same way at base, so the failure comes from the platform, not this change. Evidence is a CLI transcript; there is no UI surface.

  • Live validation: ✅ go - 4 of 4 scenarios driven live against the product
Scenario Result Live Evidence
On macOS /bin/bash 3.2 with set -u, calling fm_hermes_process_matches with empty args returns non-match instead of crashing ✅ pass live hermes-empty-args-bash32.txt: AFTER '' rc=1 and ' ' rc=1; BEFORE '' -> 'words[@]: unbound variable'
Hermes detection results are unchanged for non-empty args (true hermes, node TUI, python -m tui_gateway are detected; node -e and vim are rejected) ✅ pass live hermes-empty-args-bash32.txt AFTER section
The new regression assertion in tests/fm-hermes-harness.test.sh fails before the fix and passes after it under /bin/bash 3.2 ✅ pass live /bin/bash tests/fm-hermes-harness.test.sh with the base lib aborts with 'words[@]: unbound variable' at the new line; with the fixed lib it continues past it
The real caller fm_agent_process_classify works with empty and hermes args under set -u ✅ pass live hermes-empty-args-bash32.txt: classify(python3,'','')=other, classify(hermes,'',hermes)=agent
Evidence: Empty-args before/after transcript on /bin/bash 3.2

Source: Empty-args before/after transcript on /bin/bash 3.2

AFTER: [] rc=1, [ ] rc=1, [hermes] rc=0, [python3 -m tui_gateway.entry] rc=0, [node -e hermes] rc=1 BEFORE: [] old-lib.sh: line 6: words[@]: unbound variable

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

== AFTER fix (HEAD 83ee29a3): direct calls under set -u, /bin/bash 3.2
  [] rc=1
  [   ] rc=1
  [hermes] rc=0
  [/usr/local/bin/hermes chat] rc=0
  [node /opt/x/ui-tui/dist/entry.js] rc=0
  [python3 -m tui_gateway.entry] rc=0
  [node -e hermes] rc=1
  [vim] rc=1

== AFTER fix: /bin/bash tests/fm-hermes-harness.test.sh
not ok - NUL argv identity lost when names/ps args are blind
exit=

== BEFORE fix (base bf0f3468 lib): same probes
  [] /var/folders/rf/0k9kxrnd1qgcmwt_b_cv2gg80000gp/T//old-lib.sh: line 6: words[@]: unbound variable
  [hermes] rc=0

== BEFORE fix lib + HEAD test: /bin/bash tests/fm-hermes-harness.test.sh
~/.no-mistakes/worktrees/998ea6beee83/01M78WBHDQD21XF1H0S2ND7ZEY/bin/fm-hermes-process-lib.sh: line 6: words[@]: unbound variable
exit=
== caller fm_agent_process_classify with empty ps args, /bin/bash 3.2, set -u
-- AFTER fix:
classify(python3,'','')=other
classify(hermes,'',hermes)=agent
-- BEFORE fix:
classify(python3,'','')=other
- Outcome: ⚠️ 1 info across 1 run (3m52s)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

⚠️ **Test** - 1 info
  • ℹ️ tests/fm-hermes-harness.test.sh:47 - On macOS the full hermes suite still stops at 'NUL argv identity lost when names/ps args are blind' because that assertion reads /proc/<pid>/cmdline, which macOS doesn't have. It fails the same way on base bf0f346, so this change didn't cause it, and fixing it is outside the requested scope. Linux CI covers it.
  • Live validation: ✅ go - 4 of 4 scenarios driven live against the product
Scenario Result Live Evidence
On macOS /bin/bash 3.2 with set -u, calling fm_hermes_process_matches with empty args returns non-match instead of crashing ✅ pass live hermes-empty-args-bash32.txt: AFTER '' rc=1 and ' ' rc=1; BEFORE '' -> 'words[@]: unbound variable'
Hermes detection results are unchanged for non-empty args (true hermes, node TUI, python -m tui_gateway are detected; node -e and vim are rejected) ✅ pass live hermes-empty-args-bash32.txt AFTER section
The new regression assertion in tests/fm-hermes-harness.test.sh fails before the fix and passes after it under /bin/bash 3.2 ✅ pass live /bin/bash tests/fm-hermes-harness.test.sh with the base lib aborts with 'words[@]: unbound variable' at the new line; with the fixed lib it continues past it
The real caller fm_agent_process_classify works with empty and hermes args under set -u ✅ pass live hermes-empty-args-bash32.txt: classify(python3,'','')=other, classify(hermes,'',hermes)=agent
  • /bin/bash -c &#39;set -u; . bin/fm-hermes-process-lib.sh; fm_hermes_process_matches &#34;$1&#34;&#39; with args '', ' ', hermes, '/usr/local/bin/hermes chat', node ui-tui entry.js, 'python3 -m tui_gateway.entry', 'node -e hermes', vim (HEAD)
  • Same probes with the base bf0f3468 copy of bin/fm-hermes-process-lib.sh, to reproduce the crash
  • /bin/bash tests/fm-hermes-harness.test.sh at HEAD and with the base lib swapped in (restored afterwards)
  • /bin/bash tests/fm-hermes-harness.test.sh in a temporary worktree at base bf0f3468 (removed afterwards)
  • fm_agent_process_classify (real caller) with empty and hermes args under set -u on /bin/bash 3.2
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@fmaggi-cw
fmaggi-cw marked this pull request as ready for review November 12, 2026 18:13
@greptile-apps

greptile-apps Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Reviews (2) · Last reviewed commit: "fix(hermes): tolerate empty args under b..." · Reviewed by Greptile

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thank you @fmaggi-cw. The bug is real. On main, fm_hermes_process_matches still loops over "${words[@]}", so an empty args string aborts the caller under set -u on stock macOS Bash 3.2. Your ${words[@]+"${words[@]}"} guard and the new empty-args assertion fix that.

What I checked on head ae1465c3 against main a9ae3c0c: the change is one line in bin/fm-hermes-process-lib.sh plus one test line. There are no workflow, network or credential changes. Test coverage guard, Repo invariants and Greptile (5/5, no threads) pass. The unlabelled "Full suite" failure is expected before the full-ci label and isn't something you need to fix.

Contract class (my read): restore. The repo already supports stock macOS Bash 3.2 (it has a dedicated CI lane), and this only stops a crash on that path. Nothing else changes.

One thing blocks this, and it's waiting on you: the required "PR must be raised via no-mistakes" check fails. The body has no no-mistakes ## Pipeline attestation. Could you re-raise once with git push no-mistakes (setup is in CONTRIBUTING.md)? The attestation then binds the head it actually ran on.

FYI: #8384 and #8300 make the same one-line fix. Those two also touch ci.yml, and this one doesn't. Kun will pick which one lands, so nothing more is needed from you on that.

@fmaggi-cw
fmaggi-cw force-pushed the fm/fm-hermes-bash32-words branch from ae1465c to 83ee29a Compare November 12, 2026 22:07
@kunchenguid kunchenguid added the full-ci Maintainer go-ahead: run the full CI suite on this outside pull request label Nov 13, 2026
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @fmaggi-cw for the clean re-raise.

Re-checked on head 83ee29a3 against main ed7fbb84: the change is still one guard line in bin/fm-hermes-process-lib.sh plus the empty-args assertion. The no-mistakes attestation now binds this head with no skipped steps, and live validation is go (4 of 4 on /bin/bash 3.2). The no-mistakes check, Repo invariants and the Test coverage guard pass, and Greptile is 5/5 with no threads.

Contract class (my own read): restore.

Full suite queued. The maintainer full-ci label is going on now. Nothing is waiting on you. #8384 and #8300 carry the same one-line fix. Those two also touch ci.yml, so which one lands is our call, not yours.

@kunchenguid
kunchenguid merged commit 427056c into kunchenguid:main Nov 13, 2026
34 of 36 checks passed
@kunchenguid

Copy link
Copy Markdown
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

full-ci Maintainer go-ahead: run the full CI suite on this outside pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants