fix(ralph-loop): crash on macOS (bash 3.2) with "mem_limit_prefix[@]: unbound variable"#12
Merged
Conversation
Under `set -u` on bash < 4.4 (the default macOS bash 3.2), expanding an
empty array with "${arr[@]}" is treated as an unbound variable and aborts
the script. On macOS, systemd-run --user is unavailable, so
build_mem_limit_prefix leaves mem_limit_prefix empty, triggering the crash
on the first tool invocation:
line 308: mem_limit_prefix[@]: unbound variable
Use the ${arr[@]:+"${arr[@]}"} idiom for all four tool invocations
(codex, claude, gemini, devin). It expands to nothing when empty and
identically to "${arr[@]}" when populated, so Linux behaviour with a
systemd RAM-limit prefix is unchanged.
Add a bats regression guard ensuring no bare mem_limit_prefix expansion is
reintroduced.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ralph-loop crashes on macOS (bash 3.2) with
mem_limit_prefix[@]: unbound variableEnvironment
#!/usr/bin/env bashwhen no newer bash is onPATH)RALPH_MEMORY_MAX=8G,RALPH_TOOL=codexSymptom
On the first iteration the loop aborts with exit code 1:
Root cause
Three factors combine:
set -uis active (line 22).build_mem_limit_prefix()leavesmem_limit_prefix=()empty (warning branch)."${arr[@]}"underset -uis treated as an unbound variable. On bash >= 4.4 this expands to nothing without error, so it does not reproduce on Linux.Affected: the four tool invocations that prefix the array — codex (308), claude (322), gemini (346), devin (357).
Isolated repro
Fix
Use the safe empty-array idiom, compatible with bash 3.2+:
${arr[@]:+"${arr[@]}"}(expands to nothing when empty; to the quoted elements otherwise). Applied to all fourrun_tool()invocations.Verification
bash -n ralph-loop.shOK under bash 3.2.57.RALPH_MEMORY_MAX=8G ralph-loop 1 plan/plan.mdno longer crashes; the informative one-shot warning remains and the agent starts without a RAM limit.mem_limit_prefixis populated (systemd available),${arr[@]:+"${arr[@]}"}expands identically to"${arr[@]}"."${mem_limit_prefix[@]}"expansion is reintroduced.Notes
The systemd
--userRAM limit never applies on macOS; the warning is already a one-shot (mem_limit_warned). Bumping the shebang / requiring bash >= 4.4 was considered but the:+fix is less intrusive and keeps compatibility with the factory macOS bash.