Skip to content

fix(heredoc): expand heredoc bodies on wordless null commands (Refs #2761) - #3715

Merged
caomengxuan666 merged 1 commit into
masterfrom
ai-fix/rubash-2761
Nov 17, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
ai-fix/rubash-2761

Conversation

@arookieofc-ai

Copy link
Copy Markdown
Contributor

Root cause

A command with redirections but no words at all (a bare <<EOF, or 3<<EOF) went straight from the empty-words arm to execute_empty_words_command, bypassing the stdin pre-expansion funnel (preexpand_command_stdin, the GNU do_redirections point) every word-bearing command passes through. The body was never expanded: no command substitution ran, no := bound.

Fix

Route the bodies through that same funnel inside execute_empty_words_command, after the null command's assignments are bound and before the #535 redirect-rejection gate:

Evidence (GNU bash 5.2.21 on the box; the issue's oracle is 5.3.20)

Validation

Note (found, not fixed here)

A pre-existing here-string divergence on the word-bearing path, unrelated to this null-command fix: cat <<<\"${v:=bound}\" binds on rubash but discards on GNU (the herestring_external_discards test above is that failure). It predates this change and lives outside the empty-words funnel; flagging for a separate issue.

…2761)

A command with redirections but no words at all (a bare <<EOF, or
3<<EOF) went straight from the empty-words arm to
execute_empty_words_command, bypassing the stdin pre-expansion funnel
(preexpand_command_stdin, the GNU do_redirections point) every
word-bearing command passes through, so the body was never expanded:
no command substitution ran, no := bound.

Route the bodies through that same funnel inside
execute_empty_words_command, after the null command's assignments are
bound and after the adjudicated assignment-error arms (#2369/#1542/
#402) have had their chance to discard the command first, so the
expansion goes through that error handling instead of around it. The
funnel classifies the context itself (#2681): an fd-0 heredoc forces
the fork boundary (effects run but do not persist), a numbered-fd
body expands in the shell (bindings persist); the funsub-exit latch
arms mirror the word-bearing path (#2763). Commands without stdin
bodies skip this entirely.
@caomengxuan666 caomengxuan666 added bug Something isn't working P2-medium 中:次要缺陷或边缘路径,排期修复 area:expansion word splitting, quote removal, parameter/brace expansion gnu-baseline Tracked by the GNU Bash 5.3.0 true-baseline ledger labels Nov 15, 2026
@caomengxuan666 caomengxuan666 self-assigned this Nov 15, 2026
@caomengxuan666

Copy link
Copy Markdown
Member

Thank you, @arookieofc-ai — first-pass intake review from the community bot. The captain reviews external PRs first, so this is not a merge decision; it is a checked read of the diff and the CI, queued for captain review.

What I checked

CI, run 43740013432 + canary 43740013543, every cell named

  • Red, all baseline, no PR-specific red cell visible: Rust tests (Linux) fails fail-fast at 26/1249 on the single known baseline cell issue2875_input_procsub_child_runs_as_rubash_shell (precondition: no rubash binary built first); Rust tests (macOS) 1245 passed / 1 failed / 4 ignored, same single cell; GNU goldens 1351 passed / 1 failed / 4 ignored, same single cell; niubash-builds fails only at the ledger step — MISSING session-method rubash::api::Session::cwd, the known ledger drift, whose fix is in flight (docs(ledger): record Session::cwd #3704 / niu [bug] exec N< <(slow-producer) blocks until producer exits (GNU returns immediately) #1021).
  • Green: Compatibility CLI tests, Cross-target check (linux/android), Cross-target check (darwin), Windows tests compile check, Shell functionality tests; API ledger tripwire passes.
  • Two limits on what CI proves here: the Linux lib run stopped early (fail-fast), so a full lib result is not established by CI; and the new nail stem is not in CI's nextest table, so its 11/11 is the PR's local claim — I have not independently re-run the nails or the GNU oracle here. That re-run stays with the captain.

Two things that need a captain decision, not mine

  1. Same issue, second implementation in flight. fix(executor): expand heredoc bodies on raw-empty null commands #3362 (Uarz, draft, Fixes #2761, open since 2026-11-11) already implements this fix at the same funnel, with a different nail file (18 tests, tests/issue2761_heredoc_null_command_expansion.rs) and a different stated residual (its owed P16 divergence). This PR does not supersede fix(executor): expand heredoc bodies on raw-empty null commands #3362 on its own — which implementation survives, or whether the two merge, is for the captain.
  2. The heredoc: bodies on raw-empty null commands are never expanded (empty-words dispatch bypass) #2761 gate has not opened. heredoc: bodies on raw-empty null commands are never expanded (empty-words dispatch bypass) #2761 was gated on heredoc: 限下双 heredoc 同 list 绑定丢失第一条(exec 14<<A 15<<B,#3576 复核带出的存量缺陷) #3578 landing; heredoc: 限下双 heredoc 同 list 绑定丢失第一条(exec 14<<A 15<<B,#3576 复核带出的存量缺陷) #3578 is still open, with two open drafts (fix(executor): redirect-only exec binds every heredoc entry (Refs #3578) #3580 / exec: bind every heredoc/here-string entry at its redirect-list position (Refs #3578) #3603). This PR arriving before that gate opens is noted, not judged.

Noted, not filed: the pre-existing word-bearing here-string divergence flagged in the PR note (cat <<<"${v:=bound}" binds on rubash, discards on GNU) is recorded here as a candidate for a separate issue; I am not filing it from this review.

Queued for captain review; CI watched.

@caomengxuan666

Copy link
Copy Markdown
Member

队长裁断(2026-11-16):感谢提交。#2761 已有更早的在途 PR #3362(Uarz 于 2026-11-11 开,同 issue 的另一实现,18 枚钉),按本仓规矩先审先行 PR,本 PR 暂缓,不并行推进两份实现;若 #3362 不能落地,会回到本 PR 处理,并尽量吸收本 PR 的测试用例。另 #2761 本身卡在 #3578 的合入(其幸存者 #3603 尚在合入轮队列中),该门未开前两支都不会合入。本 PR 不关闭,状态随 #3362 / #3603 的进展更新。CI 已按名:4 红皆为已知基线格(issue2875 + canary 的 ledger 漂移,修补 #3704 / niu #1021 在途),无 PR 专属红格。

@caomengxuan666

Copy link
Copy Markdown
Member

【WIN-AGENT-AUDIT】PR #3715 第1轮 — 建议:PENDING(缺腿)
head: 2d78c0e(gh 实时)state: OPEN(非 draft)
关联 issue: #2761

处置:队长已裁先行实现 = #3362(同 issue 另一实现,18 枚钉),本 PR 暂缓;且 #2761 卡在 #3578 合入(幸存者 #3603 在合入轮队列),门未开前两支都不合。本轮不重跑腿。

@caomengxuan666

Copy link
Copy Markdown
Member

【WIN-AGENT-AUDIT】PR #3715 第1轮 — 建议:FAIL
head: 2d78c0e base(merge-base): e81a1af 文件: 3 个 +254/-2
关联 issue: #2761(状态:open,我核过的时间:2026-11-17 09:52 CST)

机制核查:

腿(逐项给数字与名字):

  • 钉自跑:issue2761_heredoc_empty_words_regressions head 上 11 passed / 0 failed
  • fail-first:base(merge-base) 上 4 passed / 7 failed;红名 = {bare_here_string_side_effect_runs, body_sees_null_command_assignments, fd0_bare_heredoc_body_expands_but_does_not_persist, fd0_funsub_exit_is_command_status, fd3_bare_heredoc_body_expands_and_persists, fd3_funsub_exit_aborts_shell, vanished_words_null_command_still_expands_body};base 上仍绿的 4 条均为阴性/对照钉(quoted-delimiter、readonly-discards、here-string-bind、cat-neighbor),与「base 不展开 body」一致 → 钉有效、非废钉。
  • lib 双边:head 失败名集 {api::consumer_tests::issue2084_session_end_restores_host_process_state} / base 失败名集 {api::consumer_tests::issue2084_session_end_restores_host_process_state} / 差集 ∅(两侧各 1351 passed; 1 failed; 4 ignored;issue2084 为已知并行敏感基线,未用 --test-threads 2 定判)
  • -D warnings:RUSTFLAGS="-D warnings" cargo check --locked --lib --bins → 0 警告
  • 卫生:rustfmt --edition 2021 --check 三个涉及文件 clean(cargo fmt 在本机有 os error 206 前科,用 rustfmt 逐文件替代);marker-lint OK;utf8-boundary clean
  • CI(run 43740013432):Rust tests / GNU regression goldens / Rust tests (macOS) 红名单均只含 api::consumer_tests::issue2875_input_procsub_child_runs_as_rubash_shell(已知基线);niubash builds 红 = ledger 缺 rubash::api::Session::cwd(基线漂移)。无本 PR 归因红。
  • GNU 对照:WSL /usr/local/bin/bash = GNU bash 5.3.20(1)-release (x86_64-pc-linux-gnu),探针脚本 target/probe-3715/{shapes,confirm,confirm2,rest}.sh(LF 行尾,脚本文件喂给双方):
    • 3<<EOF + ${ exit 43; } → GNU 整壳退出 rc=43 / 本 PR head rc=42(N 透传,形状一致)
    • <<EOF + ${ exit 42; } → GNU 下一行 status=1、脚本继续 / 本 PR head status=42 → 分歧(F1)
    • 其余 9 格与钉期望一致:assign-visible=hello、fd0 se=yes v=UNSET、fd3 se=yes v=bound、quoted se=no v=UNSET、here-string se=yes/v=UNSET、vanished rc=0 se=yes、cat-neighbor se=yes v=UNSET、readonly 诊断 ro: readonly variable

F 点(建议 FAIL 逐条):

  • F1: tests/issue2761_heredoc_empty_words_regressions.rs:184-194 fd0_funsub_exit_is_command_status 期望 D2-after status=42,但 GNU bash 5.3.20 实测为 status=1。复现(脚本文件):echo D1-before / <<EOF / ${ exit 42; } / EOF / echo "D2-after status=$?" / echo D3-next-ran → GNU 输出 D2-after status=1;本 PR head 输出 D2-after status=42。机理:fd-0 null command 走 execute_null_command 的 forcefork 子进程(execute_cmd.c:4211-4213 对 fd_is_bash_input 目标置 forcefork;4230-4241 子进程 setjmp_nosigs(top_level),heredoc_expand→funsub 内 exit 经 top_level 长跳后 exit(EXECUTION_FAILURE)=1,N 被折叠);本 PR 的 fork 子进程把 funsub 的 N=42 原样透传为命令状态。钉头注释自称「Expectations verified against GNU bash 5.3.20 per the issue」,此格与 5.3.20 实测矛盾——期望写错了,属钉的问题;产品侧需按 GNU 机理把 fd-0 fork 上下文的 funsub exit 折叠为 EXECUTION_FAILURE(或队长裁定的等价语义)。

续作记录:无(本轮未动代码、未 push)

未跑/VOID 的腿:

  • cargo nextest 本机不可用(error: no such command: nextest),以有界 cargo test --test/--lib 替代
  • issue2084_session_end_restores_host_process_state 在 head/base 双侧同名复现,按已知并行敏感基线处理,未做 threads=2 定判

@caomengxuan666
caomengxuan666 merged commit 487c745 into master Nov 17, 2026
11 of 15 checks passed
caomengxuan666 added a commit that referenced this pull request Nov 17, 2026
…c bodies in the shell (Refs #2761) (#3842)

The vanished-words arm of the empty-words dispatch passed `cmd` with
its raw words (`["$EMPTY"]`) to `execute_empty_words_command`, so the
heredoc fork classifier saw an effective word and expanded a
numbered-fd body in a fork, discarding `:=`. GNU's words==0 check
runs on the EXPANDED word list, which is empty here — the node is a
null command, and the force-fork rule (fd-0 / REDIR_VARASSIGN only)
leaves a numbered-fd body expanding in the shell, so `:=` persists.
Hand the node to the null-command path wordless, as GNU sees it.

GNU anchors (audit tree bash-5.3, verified):
- execute_cmd.c:4626-4640 — `words == 0` dispatches to
  execute_null_command.
- execute_cmd.c:4210-4216 — force-fork only for REDIR_VARASSIGN or
  a redirect targeting fd 0 / bash input; fd-3 does not force it.

Absorb note: this is the surviving remainder of Uarz #3362 after
#3715 merged (487c745). Dropped as already-in-master: both
visibility changes (`abort_on_expansion_errors`,
`preexpand_command_stdin`) and the `command_prepare.rs` insertion
block (superseded by #3715's 61-line version with the funsub-exit
latches). `preexpand_command_stdin` keeps master's `Option<i32>`
return (the #2763 latch); #3362's `()` signature was NOT taken.
Pins trimmed from 17 to the 9 shapes #3715 lacks: the
discriminating `vanished_words_numbered_heredoc_assign_persists`
(red on master by code trace, green after this hunk) plus eight
coverage pins (arithmetic x2, two-heredoc order x2, arith-error x2,
fd0-fatal x1, post-alias x1).

Verification: no cargo/rustc on this VM and the X299/server routes
are down, so no local leg ran. Pin red/green is established by code
trace (see REPORT.md); CI census (which runs all stems) adjudicates
on the PR.

Co-authored-by: Uarz <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:expansion word splitting, quote removal, parameter/brace expansion bug Something isn't working gnu-baseline Tracked by the GNU Bash 5.3.0 true-baseline ledger P2-medium 中:次要缺陷或边缘路径,排期修复

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants