Skip to content

fix(bin): run fm_exec_timed on bash 3.2 without BASHPID - #9

Merged
VasanthAmana merged 1 commit into
merkensoft-iris:mainfrom
VasanthAmana:fm/firstmate-bash32-bashpid-fix
Oct 5, 2026
Merged

VasanthAmana merged 1 commit into
merkensoft-iris:mainfrom
VasanthAmana:fm/firstmate-bash32-bashpid-fix

Conversation

@VasanthAmana

@VasanthAmana VasanthAmana commented Oct 5, 2026 •

Copy link
Copy Markdown

Intent

Install a modern bash on this laptop with Homebrew.

That was the immediate remedy chosen for a fault found on 5 Oct 2026 after upstream firstmate was merged into this copy; the recommendation it was chosen from was "install bash, followed by a proper fix sent through the normal PR route so the next macOS user does not hit it". This task is that proper fix.

The fault: on macOS's built-in /bin/bash 3.2.57, bin/fm-spawn.sh launched a worker and then failed with "backlog item could not be moved to In flight (bin/fm-timeout-lib.sh: line 224: BASHPID: unbound variable)", removed the task's record, and left the worker's window and local copy to close by hand. Line 224 is [ "$owner" != "$BASHPID" ] || owner=$PPID inside fm_exec_timed; bash 3.2 has no BASHPID, so under set -u the function dies. bin/fm-backlog-transition-lib.sh:347 runs tasks-axi through fm_exec_timed, so every backlog transition is affected - spawn's move to In flight and, by the same path, cleanup's close. Other scripts already write ${BASHPID:-$$}. The original project (kunchenguid/firstmate) has the same line, and bin/fm-wake-lib.sh already branches on BASH_VERSINFO, so bash 3.2 is meant to work.

What Changed

  • fm_exec_timed in bin/fm-timeout-lib.sh no longer reads $BASHPID directly, which is unset on stock macOS bash 3.2 and aborted under set -u ("BASHPID: unbound variable"). It now uses ${BASHPID:-...} and, when BASHPID is missing, recovers the current shell's real pid by exec'ing a throwaway sh and reading its $PPID. The owner-pid logic is the same as on bash 4+: a subshell keeps the script as owner, and the main shell falls back to its parent.
  • tests/fm-timeout-lib.test.sh adds cases that run the production library under /bin/bash when it is older than bash 4. They cover a bounded command called from the main shell and from a subshell, passing through output and exit status, and the subshell-owner behavior. The cases print a skip message on hosts where /bin/bash is not bash 3.x.

Risk Assessment

✅ Low: The fix only changes how fm_exec_timed obtains its own pid when BASHPID is unset. Bash 4+ takes the same path as before. The bash 3.2 fallback gives the same value as BASHPID, and the new tests exercise it behaviorally.

Testing

I ran the timeout-library test file on the real macOS /bin/bash 3.2.57. It passes, including new regressions for main-shell and subshell calls, owner-death handling, and a backlog transition that bounds tasks-axi. I also called the base-commit library directly under set -u, and it fails with "BASHPID: unbound variable" as reported. The fixed library runs the same call cleanly. I did not run bin/fm-spawn.sh or cleanup end to end, and I did not run the full suite.

  • Live validation: ✅ go - 3 of 3 scenarios driven live against the product
Scenario Result Live Evidence
Reproduce the fault: old fm_exec_timed on bash 3.2 under set -u ✅ pass live The base-commit lib run under /bin/bash prints 'line 224: BASHPID: unbound variable'
Fixed fm_exec_timed runs a bounded command on bash 3.2 from the main shell ✅ pass live direct-bash32.txt shows main-ok
Fixed fm_exec_timed on bash 3.2 from a subshell, owner-death handling, and a backlog transition bounding tasks-axi ✅ pass live timeout-lib-test.txt: the four bash 3.2 regression cases pass on the real /bin/bash
Evidence: timeout-lib test output

Source: timeout-lib test output

ok - fm_exec_timed passes a command's status and output through unchanged
Terminated: 15             "$@"
ok - fm_run_timed reports 124 when the bound TERMs a read whose wrapper recorded 143
ok - fm_run_timed passes a natural exit through when the bound fired after completion
ok - fm_exec_timed sends TERM at the bound and a cooperative command ends there
ok - fm_exec_timed kills a TERM-ignoring command once the grace has passed
ok - fm_exec_timed replaces the calling shell instead of wrapping it
ok - fm_exec_timed reaps a descendant that would otherwise hold the output past the bound
ok - fm_exec_timed forwards a TERM it receives to the bounded command
ok - fm_exec_timed ends the command when its named owner is already gone
ok - fm_exec_timed ends the command when its owner dies during watchdog startup
ok - fm_exec_timed prefers its perl watchdog over timeout
ok - fm_exec_timed refuses instead of running unbounded when no mechanism exists
ok - fm_exec_timed rejects a zero, padded, non-numeric, or missing bound and a missing command
ok - fm_exec_timed's GNU timeout fallback (skipped: no timeout binary on this host)
ok - fm_timed_out accepts 124 and 137 and nothing else
ok - fm_exec_timed runs a bounded command on bash 3.2 from the main shell and from a subshell
ok - fm_exec_timed on bash 3.2 ends the command when the owning script dies, not only when its parent does
ok - fm_exec_timed on bash 3.2 ends the command when the replaced shell's parent dies
ok - a backlog transition bounds tasks-axi on bash 3.2 and reports an expired bound
Evidence: direct bash 3.2 run of fixed lib

Source: direct bash 3.2 run of fixed lib

main-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 - 3 of 3 scenarios driven live against the product
Scenario Result Live Evidence
Reproduce the fault: old fm_exec_timed on bash 3.2 under set -u ✅ pass live The base-commit lib run under /bin/bash prints 'line 224: BASHPID: unbound variable'
Fixed fm_exec_timed runs a bounded command on bash 3.2 from the main shell ✅ pass live direct-bash32.txt shows main-ok
Fixed fm_exec_timed on bash 3.2 from a subshell, owner-death handling, and a backlog transition bounding tasks-axi ✅ pass live timeout-lib-test.txt: the four bash 3.2 regression cases pass on the real /bin/bash
  • bash tests/fm-timeout-lib.test.sh (all cases pass, including the four new bash 3.2 regressions)
  • /bin/bash 3.2.57 with set -u: sourced the base-commit library and ran fm_exec_timed 5 1 echo x
  • /bin/bash 3.2.57 with set -u: sourced the fixed library and ran fm_exec_timed 5 1 echo main-ok
✅ **Document** - passed

✅ No issues found.

⚠️ **Lint** - 1 warning
  • ⚠️ linter found issues (exit code 1)
✅ **Push** - passed

✅ No issues found.

fm_exec_timed compared its owner against $BASHPID, which stock macOS bash 3.2
does not define, so under set -u every bounded call died with 'BASHPID:
unbound variable'. That broke every backlog transition that runs tasks-axi
through fm_tasks_axi (spawn's move to In flight, cleanup's close).

Recover the calling frame's real pid from a child's $PPID when BASHPID is
absent, as fm_current_pid already does, so the owner keeps its bash 4+ meaning
in both the main shell and a subshell. Add bash 3.2 regressions that run the
production library under /bin/bash and skip with a message where it is not an
old bash.
@VasanthAmana
VasanthAmana force-pushed the fm/firstmate-bash32-bashpid-fix branch from ca734ba to 3335f5b Compare October 5, 2026 09:37
@VasanthAmana
VasanthAmana merged commit c9d3d50 into merkensoft-iris:main Oct 5, 2026
19 checks passed
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.

1 participant