You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[bug] P0 Command substitution with a compound body returns EMPTY when the enclosing function call has a stdout redirection — direnv stdlib path_add exports PATH='' (silent env wipe) #362
Found by ecosweep4 lane (wt22/nest22; corpus: direnv stdlib.sh per-function drive; worktree base a522eb3, release build; oracle WSL GNU Bash 5.3.0 script-file runs).
Reproducer
f2() { v=$(IFS=:;echo hi);echo"compound=[$v]">&2; }
f2 >/dev/null # any outer stdout redirect on the call
rubash: compound=[] (capture lost; the hi goes to the outer redirect target)
GNU 5.3.0: compound=[hi]
Full matrix (target/issue-suites/results/ecosweep4/direnv/cs2.sh, both-side captures cs2.{rub,gnu}.err):
shape
body
rubash under f >/dev/null
GNU
simple
v=$(echo hi)
[hi] OK
[hi]
compound ;
v=$(IFS=:; echo hi)
EMPTY
[hi]
group
v=$( { echo hi; } )
EMPTY
[hi]
sequence
v=$(printf a; printf b)
EMPTY
[ab]
compound+param-op
v=$(IFS=:; echo "a:b:c") then ${v%%:*}
EMPTY
[a:b]
array join
v=$(IFS=:; echo "${arr[*]}")
EMPTY
[/x:/y]
Without the outer redirect, the same compound comsubs capture fine (f2 bare call OK). So the trigger is: compound comsub body × active stdout redirection on the enclosing function call — the body's writes go to the redirected fd 1 instead of the substitution capture.
Real-world hit (why it is P0)
direnv stdlib.sh path_add() (the implementation behind PATH_add / every layout_* / load_prefix):
Any .envrc doing layout go / layout node / layout perl / load_prefix (these call layout X >/dev/null internally in common wrappers, or are called redirected by user code) ends up with export PATH= — an EMPTY PATH — under rubash, while GNU exports the joined path. Verified live: layout go >/dev/null under rubash yields GOPATH=[] and PATH= exported empty (xtrace: the inner echo prints the full joined PATH, then + path= and + export PATH= — xtrace artifacts at target/issue-suites/results/ecosweep4/direnv/lg.err). Everything downstream dies (tr: command not found).
rubash#289 (CLOSED) fixed command -v/-V describe output bypassing the thread-local STDOUT_CAPTURE; per its close comment the capture "owns fd 1" during substitution. This issue is the same interplay with a different trigger: ordinary echo/printf writes in a compound comsub body follow the OUTER redirect instead of the capture. GNU anchor: subst.c:7143 command_substitute — dup2(fildes[1], 1) (subst.c:7320) makes fd 1 the pipe write end for the WHOLE body (compound or not) for the duration of the substitution; an enclosing function-call redirect is irrelevant because the substitution saves/restores fd 1 around itself (execute_cmd.c redirection stacking), it never lets body output escape to the caller's redirected fd 1.
.../direnv/lg.sh + lg.err (layout_go xtrace showing + path= empty after the join echo)
per-function verdicts: .../direnv/verdict.txt (52 drivers, 35/52 identical; reds map to this issue + message-form items below)
Suggested Rust owners to inspect: the comsub executor's compound-body path where fd 1 is swapped for the capture (the #289 fix introduced the buffered single-truth path for command -v; the compound-body echo/printf path still seems to write to the live fd 1, which an active caller redirect has already moved).
Fixed by wt22/p0fix (645ecff, master 3ade4b2): three in-process comsub body executors had fd-1 rebinding (subshell path Q16, function shortcut #161) — but the COMPOUND-body AST path (run_ast_command_substitution_with_context, the ;/&&/newline dispatch entry) executed in place with NO rebind, so body writes followed the caller's redirected fd 1 into the outer target (verified: hi landed in outer.txt). GNU subst.c:7143 command_substitute -> dup2(fildes[1],1) at 7306-7320 covers the WHOLE body. Fix: the same fd-1 rebind bracket (saved_fd_table restore already existed). 16-shape separated-stream matrix 15/16 byte-identical (the one exception is the pre-existing dup-snapshot family, fails on master identically); comsub/comsub2/comsub-eof/comsub-posix/lastpipe/exp/more-exp/dstack/ifs all 0 diff; direnv layout_node/layout_php turn green (31->33/52). 11 regressions.
Activity
fix(#358): apply bundled short flags in set's slow path (set -euo pip…
fix(#363): direct external scripts run as fresh shells — assignments …
fix(#362): compound comsub bodies capture under an enclosing redirect
caomengxuan666 commentedon Sep 30, 2026
Fixed by wt22/p0fix (645ecff, master 3ade4b2): three in-process comsub body executors had fd-1 rebinding (subshell path Q16, function shortcut #161) — but the COMPOUND-body AST path (run_ast_command_substitution_with_context, the ;/&&/newline dispatch entry) executed in place with NO rebind, so body writes followed the caller's redirected fd 1 into the outer target (verified: hi landed in outer.txt). GNU subst.c:7143 command_substitute -> dup2(fildes[1],1) at 7306-7320 covers the WHOLE body. Fix: the same fd-1 rebind bracket (saved_fd_table restore already existed). 16-shape separated-stream matrix 15/16 byte-identical (the one exception is the pre-existing dup-snapshot family, fails on master identically); comsub/comsub2/comsub-eof/comsub-posix/lastpipe/exp/more-exp/dstack/ifs all 0 diff; direnv layout_node/layout_php turn green (31->33/52). 11 regressions.
fix(tests): temp probe paths in mapfile/comsub tests (#324/#362)\n\nB…
fix(tests): temp probe paths in mapfile/comsub tests (#324/#362)\n\nB…