Skip to content

fix(executor): pipeline bad substitution reports once and discards the element (Refs #3499) - #3761

Merged
caomengxuan666 merged 1 commit into
masterfrom
ai-fix/rubash-3499
Nov 16, 2026
Merged

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

Conversation

@arookieofc-ai

Copy link
Copy Markdown
Contributor

Fixes #3499

GNU reports one diagnostic per bad element and discards it (DISCARD, status 1, no output). Rubash reported one diagnostic per bad word, ran the element with the failure's empty product, and leaked the verdict latch into the next command.

Root cause: the parameter_bad_substitution verdict latch was set at each bad-substitution diagnostic site but the pipeline stage path never handled it — execute_pipeline_stage_inner's adjudication didn't check it, the stage wrapper's DISCARD latch family didn't include it, and the speculative concurrent specs didn't decline on it. The latch then leaked to the next command (silently discarded, fatal under POSIX mode / set -e), and external members ran with the failure's empty product (a "" argv reached cat as a filename; a live-piped producer's bytes escaped the wrapper's string harvest through the real pipe).

What changed (13 files, +629/-68):

  • src/shell/state.rs, src/executor/init.rs: new one-shot print budget bad_substitution_reported, riding every boundary the verdict rides (Clone, snapshot/restore, comsub clears, verdict consumers, prompt save/restore).
  • src/executor/expand_word.rs, parameter_words.rs, embedded_parameters.rs: all 7 expansion-time print sites guarded by the budget; the verdict still sets at every site.
  • src/executor/pipeline_exec.rs: verdict joins the DISCARD latch family (8-tuple); both spec nets decline on it; the wrapper harvests a set verdict to (empty, 1) (discarding the doomed run's captured stderr too) and flags the discard so the routing walk doesn't materialize the element's redirects; arg-word expansion drops all arguments when a word newly sets the verdict.
  • src/executor/pipeline_stages.rs: external stages never spawn on a failed argv; tail-word expansion drops all arguments the same way.
  • src/executor/mod.rs, command_substitution.rs: new pipeline_stage_bad_substitution_discarded flag for the routing skip.
  • tests/issue3499_bad_substitution_pipeline_discard.rs: 7 regression tests (issue shapes, latch leak, pipeline positions, later-words-never-expand, ERR trap + errexit, POSIX containment, discarded-element side effects).

Verification (Simular box, GNU bash 5.2.21 oracle):

  • 11 probe scripts byte-identical to GNU after path normalization (stdout+stderr sha256): issue shapes, latch leak, pipeline positions incl. /bin/echo, two bad elements, assignment-only element, later-words side effects, ERR trap + errexit, POSIX mode, DEBUG-trap-forced sequential path, comsub + 2>&1 diagnostic routing.
  • New suite: 7 passed, 0 failed. cargo test --lib: 1249 passed, 0 failed, 4 ignored. 15 neighbor suites (bad-substitution / pipeline expansion / discard / redirect): 134 passed, 0 failed.
  • cargo fmt --check and git diff --check clean.

Known limitation: a discarded element's own output redirect still creates/truncates its target — the stage redirect preflight opens the target before the word expansion that detects the failure (an unopenable target also swallows the bad-substitution diagnostic outright). Fixing that needs the preflight to move after expansion; the same pre-existing divergence exists for the ${x?word} gate. The driver's routing walk already skips a bad-substitution discard.

No new ledger API item is added (both new fields are internal executor/shell state), so the canary ledger comparison should be unaffected by this PR.

…e element (Refs #3499)

GNU reports one diagnostic per bad element and discards it (DISCARD,
status 1, no output); rubash reported one per bad word, ran the
element with the failure's empty product, and leaked the verdict
latch into the next command:

- one-shot print budget (`bad_substitution_reported`) for the
  diagnostic; the verdict latch still sets at every site.
- the verdict joins the DISCARD latch family, so spec nets decline
  and the stage wrapper harvests (empty, 1) instead of leaking.
- external stages never spawn on a failed argv, and a failed word's
  arguments are dropped whole (a pre-failure `file` in
  `rm file ${-x}` must not reach the command).
- the driver's routing walk skips a bad-substitution discard, so
  the element's redirects are not materialized there.

Known limitation: a discarded element's own output redirect still
creates/truncates its target - the stage redirect preflight opens
the target before the word expansion that detects the failure (an
unopenable target also swallows the diagnostic outright). Fixing
that needs the preflight to move after expansion; same pre-existing
divergence for the `${x?word}` gate.
@caomengxuan666 caomengxuan666 added bug Something isn't working gnu-baseline Tracked by the GNU Bash 5.3.0 true-baseline ledger P3-low 低:优化、文档、远期规划,有机会再做 area:expansion word splitting, quote removal, parameter/brace expansion labels Nov 16, 2026
@caomengxuan666 caomengxuan666 self-assigned this Nov 16, 2026
@caomengxuan666

Copy link
Copy Markdown
Member

Thank you for the PR — received and queued for captain review. Per the owner's rule, external PRs are reviewed by the captain first; this is intake triage, not a merge decision.

CI checked by name (main run 43805456889, canary run 43805456921):

  • The only failures are known baseline reds, no PR-specific red seen: Rust tests (Linux + macOS) and GNU goldens each fail solely on issue2875_input_procsub_child_runs_as_rubash_shell (precondition: no rubash binary on a fresh target, rubash#3292); the niubash canary's only red is the known ledger drift MISSING Session::cwd.
  • API ledger tripwire passes, consistent with the PR adding no new ledger API item. Compatibility CLI tests, shell functionality tests, cross-target checks and the Windows compile check all pass.

Two things flagged for the captain's review:

  1. Title says Refs #3499 but the body says Fixes #3499 — as written, merging would auto-close [bug] bad substitution 多报诊断且不丢弃命令(DISCARD) #3499. The captain will confirm the intended wording at merge time.
  2. The stated known limitation (a discarded element's own output redirect still creates/truncates its target, since the redirect preflight runs before word expansion) is acknowledged in the body; whether that residual is acceptable for this PR or needs follow-up is for the captain to judge.

No action needed from you right now — CI is watched and the captain will review.

@caomengxuan666

Copy link
Copy Markdown
Member

【WIN-AGENT-AUDIT】
PR #3761 第1轮 — 建议:PASS
head: f1e60fa base(merge-base): 8100d76 文件: 13 个 +629/-68
关联 issue: #3499(状态:open,我核过的时间:2026-11-16 本地)

机制核查:

  • 一次性 print budget bad_substitution_reported + verdict 加入 DISCARD latch family + 两处 word-list 遇首败即弃 + pipeline_stage_bad_substitution_discarded 让 routing walk 跳过落实 redirects。GNU 依据已核:subst.c:4283-4296 call_expand_word_internal -> exp_jump_to_top_level(DISCARD)(词表首败即弃整表);subst.c:10277 bad_substitution: report_error(每 latch 期只报一次);execute_cmd.c:1811 setjmp_nosigs(top_level) 子壳内收束(POSIX 下管道元素仍只 exit 1)。
  • 无关改动:无。

腿:

  • 钉自跑:issue3499_bad_substitution_pipeline_discard 7 passed / 0 failed
  • fail-first:base(8100d76) 上 0 passed / 7 failed,红名 = 全部 7 个,与 PR 声称一致
  • lib 双边:head 失败名集 {api::consumer_tests::issue2084_session_end_restores_host_process_state} / base 同集 / 差集 {}(该失败两侧一致,为本地环境基线红,非本 PR 账)
  • -D warnings:cargo check 干净,0 警告
  • 卫生:rustfmt --check 13 个 PR 文件全净;marker-lint OK (117 consts/268 allowlisted);utf8-boundary clean
  • CI:Rust tests(Linux+macOS) 与 GNU goldens 唯一红 = issue2875_input_procsub_child_runs_as_rubash_shell(基线);niubash-canary 红 = MISSING ledger Session::cwd,与 merge-base run 43779513466 完全同格(docs(ledger): record Session::cwd #3704 在飞落地的条目),基线
  • GNU 对照:WSL GNU bash 5.3.20(/usr/local/bin/bash),脚本 target/s2probe/p3499.sh:echo ${-x} ${-y} / echo a=${-x} b=${-y} / echo a=${-x} | cat — GNU 与 head 均为每形一次诊断、元素被丢弃(无 a= 输出)、管道 rc 取 cat 的 0,逐形一致

F 点:无
未跑/VOID 的腿:无
备注:PR 正文含 "Fixes #3499"(外部作者所写);合入走 squash,标题自带 (Refs #3499)。

@caomengxuan666
caomengxuan666 merged commit afd0778 into master Nov 16, 2026
17 of 24 checks passed
@caomengxuan666

Copy link
Copy Markdown
Member

【WIN-AGENT-AUDIT】s2 批次汇总(S 审计波 s2,10 个 PR 全部有处置)

PR 建议判词 处置 关联 issue
#3761 PASS(他 lane 已审合) MERGED afd0778(06:06Z,早于本 lane 开工) #3499 CLOSED
#3760 PASS MERGED 358a83e #3456 CLOSED
#3759 PASS MERGED 299d11d #3410 CLOSED
#3758 PASS MERGED 364478d #3408 CLOSED
#3757 PASS MERGED 109ab51 #3392 CLOSED
#3756 PENDING(队长专属文件) 未合 —— diff 动 src/lexer/continuation.rs,规程 1.5 停手;各腿全绿,报告已给队长 #3307 OPEN
#3755 PENDING(跳过) 未合 —— head 审计期间被并行推进(d63d975a→0541d577),且栈底 #3754 判 FAIL、markers.rs 与在飞 f3590 重叠 #3605 OPEN
#3754 FAIL 未合 —— F1/F2:非空白 IFS 字面 separator 不切分 / outer-dquote 永不切分,GNU 5.3.20 对照有最小复现 #3605 OPEN
#3751 PASS MERGED fb6f289(伞 issue 未关) #3605 OPEN
#3750 PASS MERGED 304a516(伞 issue 未关) #3605 OPEN

要点:

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 P3-low 低:优化、文档、远期规划,有机会再做

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] bad substitution 多报诊断且不丢弃命令(DISCARD)

2 participants