fix(dream-cli): double-quote tmpdir in gpu_reassign RETURN trap#1007
Merged
Lightheartdevs merged 1 commit intoLight-Heart-Labs:mainfrom Apr 27, 2026
Merged
Conversation
_gpu_reassign registered a cleanup trap with single-quoted outer syntax, so $tmpdir expansion was deferred until fire time. RETURN traps are process-level (not function-scoped), so when the function returns to cmd_gpu the trap fires again in cmd_gpu's scope where $tmpdir is unbound. Under set -u that triggers 'tmpdir: unbound variable' and exit 1 even on successful reassign. Switched to double-quoted outer to bake $tmpdir in at trap-set time (single-quoted inner keeps paths with spaces safe). Matches the already-landed pattern at dream-cli:542. macOS Apple Silicon and AMD paths are unaffected (the nvidia-smi early-return at line 2825 precedes the trap registration). Linux NVIDIA and Windows WSL2 + NVIDIA passthrough are the affected surface.
4 tasks
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
_gpu_reassignregistered its cleanup trap with single-quoted outersyntax:
Single-quoted outer defers
$tmpdirexpansion until trap fire time.RETURN traps are process-level (not function-scoped), so after
_gpu_reassignreturns tocmd_gputhe trap fires again incmd_gpu's scope where$tmpdiris unbound. Underset -uthattriggers
tmpdir: unbound variableand exit 1 even on a successfulreassign.
How
Switched to double-quoted outer so
$tmpdiris baked in attrap-set time:
Single-quoted inner continues to protect paths containing spaces.
Matches the already-landed pattern at
dream-cli:542.Platform Impact
nvidia-smiearly-return at line 2825 precedes the trap registration.
nvidia-smi, same early-return).Testing
bash -npasses.shellcheckshows the sameSC2064on line 2869 as on theprecedent line 542 — intentional (we want expansion at set time).
bash -c 'set -u; f(){ local t; t=$(mktemp -d); trap "rm -rf \"$t\"" RETURN; }; g(){ f; return 0; }; g'→ exit 0.Merge order (important)
This fix is preventive on upstream/main today:
dream-cliison
set -eonly, so the unbound-variable crash does not manifestyet. It becomes load-bearing the moment #1002
(
refactor/dream-cli-nounset-audit, enablesset -u) merges —without this fix in place,
dream gpu reassignon NVIDIA Linux(and Windows WSL2 + NVIDIA passthrough) exits 1 even on a
successful reassign.
Recommended ordering: merge this PR in the same batch as
#1002, or land this first. If #1002 merges alone, users on
upstream hit the regression immediately.
Known follow-up
The sibling trap at
dream-cli:651has the same wrong quotingstyle but does not leak (it is dispatched from the main case
block, not from a function). Tracked as a minor consistency
follow-up outside this PR.
Manual test (requires NVIDIA Linux host)
dream gpu reassign --dry-run && echo ok→ok, exit 0.