Skip to content

fix(bin): default BASHPID so bounded execution works on Bash 3.2 - #2

Merged
earljman merged 2 commits into
mainfrom
fm/bash32-bashpid-fix
Sep 29, 2026
Merged

earljman merged 2 commits into
mainfrom
fm/bash32-bashpid-fix

Conversation

@earljman

Copy link
Copy Markdown
Owner

Intent

Make Firstmate able to launch workers again on a stock macOS host whose only bash is 3.2. Every crewmate or scout spawn on the captain's Mac failed at the backlog transition with 'bin/fm-timeout-lib.sh: line 218: BASHPID: unbound variable' because fm_exec_timed read $BASHPID with no default under set -u; Bash 3.2 has no BASHPID. The captain chose to apply, unchanged, the one-line fix already committed on the MacBook's Firstmate (commit a815c01, 'fix(bin): default BASHPID so bounded execution works on Bash 3.2'), cherry-picked verbatim: it uses the existing bin/fm-wake-lib.sh fm_current_pid idiom, exec a child sh whose PPID identifies the frame when BASHPID is unset, and behaviour on Bash 4+ is unchanged. A second small commit adjusts the two probes in tests/fm-timeout-lib.test.sh that themselves wrote $BASHPID, so the existing suite can run and witness the fix on Bash 3.2 (it aborted before reaching the probe). Scope is deliberately limited to these two commits: no sweep of other BASHPID sites (every other site already uses ${BASHPID:-$$}), no bash-version floor declaration, no docs change, no extra hardening. Verified locally on bash 3.2.57: fm_exec_timed returns the command's own status, a command that outruns its bound reports 124, and bash bin/fm-test-run.sh tests/fm-timeout-lib.test.sh passes all 15 checks; shellcheck and bin/fm-lint.sh are clean.

What Changed

  • Fix bounded execution on Bash 3.2 by falling back to a child shell’s PPID when BASHPID is unset, preserving Bash 4+ behavior.
  • Update two timeout test probes with the same PID fallback so the existing suite can run on Bash 3.2.

Risk Assessment

✅ Low: The narrowly scoped change removes the Bash 3.2 unbound-variable failure at the shared execution boundary, preserves Bash 4+ behavior, and updates only the two affected behavioral probes.

Testing

The focused suite, before/after reproduction, status and timeout probes, and isolated real backlog transition passed. Manual setup and assertion issues were resolved. CLI evidence was captured; no real worker was launched, and Bash 4+ was unavailable.

Evidence: Bash 3.2 regression reproduction, corrected statuses, and real backlog transition

Source: Bash 3.2 regression reproduction, corrected statuses, and real backlog transition

$ /bin/bash --version
GNU bash, version 3.2.57(1)-release (arm64-apple-darwin25)
Copyright (C) 2007 Free Software Foundation, Inc.
exit_status=0

$ base: bounded command exits 7
/bin/bash: line 218: BASHPID: unbound variable
exit_status=1

$ fixed: bounded command exits 7
worker-command-reached
exit_status=7

$ fixed: fm_exec_timed 1 1 /bin/sleep 30
exit_status=124

$ create isolated queued worker
{
  "ok": true,
  "action": "add",
  "task": {
    "id": "bash32-worker",
    "title": "Bash 3.2 worker",
    "state": "queued",
    "kind": null,
    "repo": null,
    "priority": null,
    "created": "2026-09-28",
    "closed": null,
    "deps": [],
    "hold": null,
    "links": [],
    "body": null,
    "blocked": false,
    "blocked_by": [],
    "held": false
  }
}
exit_status=0

$ Bash 3.2 bounded fm_tasks_axi start
{
  "ok": true,
  "action": "start",
  "task": {
    "id": "bash32-worker",
    "title": "Bash 3.2 worker",
    "state": "in_flight",
    "kind": null,
    "repo": null,
    "priority": null,
    "created": "2026-09-28",
    "closed": null,
    "deps": [],
    "hold": null,
    "links": [],
    "body": null,
    "blocked": false,
    "blocked_by": [],
    "held": false
  }
}
exit_status=0

$ read back worker state
task:
  id: bash32-worker
  title: Bash 3.2 worker
  state: in_flight
  blocked: no
  blocked_by: none
  held: no
  hold_reason: "-"
  hold_kind: "-"
  hold_until: "-"
  kind: task
  repo: "-"
  priority: "-"
  created: 2026-09-28
  closed: "-"
  deps: none
  links: none
  body: ""
exit_status=0

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.

  • PATH=/usr/bin:/bin:/usr/sbin:/sbin /bin/bash bin/fm-test-run.sh tests/fm-timeout-lib.test.sh — passed; GNU timeout case skipped because unavailable.
  • Executed the base library under /bin/bash -u: reproduced BASHPID: unbound variable.
  • Executed fixed fm_exec_timed with stock PATH: preserved command status 7 and returned 124 for an expired bound.
  • Executed real fm_tasks_axi start under Bash 3.2 against an isolated markdown backlog; verified persisted state through tasks-axi show as in_flight.
  • Corrected manual verification setup by exposing the existing Node executable, then corrected the assertion to the CLI's in_flight state value.
  • Removed temporary fixtures and verified git status --short was clean.
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

pm-justinm and others added 2 commits September 28, 2026 12:14
fm_exec_timed read $BASHPID with no default while the library runs under
set -u. Bash 3.2 has no BASHPID, so on a host whose only bash is 3.2 -
stock macOS - every call aborted with "BASHPID: unbound variable" before
reaching its watchdog. The repo declares no bash floor, and every other
BASHPID reference in bin/ is already written ${BASHPID:-$$}; this one site
was not, so the single owner of bounded command execution bounded nothing
there and each caller lost its timeout.

Use the Bash 3.2 idiom bin/fm-wake-lib.sh's fm_current_pid already
establishes: exec a child shell whose PPID identifies this frame the way
BASHPID does. Behaviour on Bash 4+ is unchanged, and on 3.2 the owner is
now resolved rather than fatal.

Verified on bash 3.2.57: fm_exec_timed returns the command's own status,
and a command that outruns its bound still reports 124.
Two probes in tests/fm-timeout-lib.test.sh wrote $BASHPID to identify the
calling subshell, so under Bash 3.2 the suite aborted on the same unbound
variable the library fix removes and could not witness that fix. Use the same
child-shell PPID idiom the library now uses; Bash 4+ still reads BASHPID.

Verified on bash 3.2.57: bash bin/fm-test-run.sh tests/fm-timeout-lib.test.sh
passes all 15 checks (previously failed before reaching the probe).
@earljman
earljman merged commit 662d45e into main Sep 29, 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.

2 participants