Skip to content

fix(executor): pipeline-element prefix assignment ignores fatal arithmetic error (#3456) - #3760

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

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

Conversation

@arookieofc-ai

Copy link
Copy Markdown
Contributor

Fixes #3456.

GNU expands a pipeline element's VAR=value prefix before dispatch: a fatal arithmetic error prints once, discards the whole element, and folds its status to 1. Rubash swallowed it in two faces:

  • Builtin/stand-in stages (echo, printf, true, :, false, cat, grep, wc, tr, head, trap -p): the inline slot arms in execute_pipeline_stage_inner never expanded the prefix at all — no diagnostic, the stage ran, status 0.
  • External stages (printenv, sh -c, wc -l /dev/null, yes | head -1): the diagnostic printed and the status folded to 1, but the child still spawned and its output leaked.

Fix: probe the prefix at each inline arm's commit point (pipeline_prefix_arith_status — expands each RHS once, rolls back the probe's variable writes); adjudicate the sequential external composition before the spawn (absolute flag read — the host channel already expanded the same prefix once); return the dead member without spawning on the host channel and on the five concurrent spawners (shell-writer consumers, spawn-wait, streaming tail, sandwich, Unix concurrent).

Notes:

  • set -u nounset inside arithmetic in a pipeline prefix is status 1 on GNU (re-probed against bash 5.2.21), not 127.
  • x=$((1[0]=2)): rubash's diagnostic reads 'arithmetic syntax error: ...' where GNU reads 'syntax error: ...' — a pre-existing evaluator wording divergence, pinned as rubash prints it.

Verification (box, base 8100d76):

  • New suite tests/issue3456_prefix_arith_pipeline.rs: 31/31 pass (was 7 pass / 24 fail on base, fail-first).
  • 12 neighbor suites green (44 tests); cargo test --lib: 1238 passed, 11 failed — all 11 are pre-existing/flaky on the same baseline (3 deterministic baseline failures, 8 flaky/environmental that pass in isolation on the fixed build).
  • cargo fmt --check and git diff --check clean.

…metic error (#3456)

GNU expands a pipeline element prefix before dispatch: a fatal arithmetic error prints once, discards the whole element and folds its status to 1. Rubash swallowed it in the inline slot arms and spawned the child anyway on the external and concurrent paths. Probe the prefix at each inline arm commit point, adjudicate the sequential external composition before the spawn, and skip the spawn on the host channel and the five concurrent spawners when the composition raises. Regression pins in tests/issue3456_prefix_arith_pipeline.rs, 31 cells against the GNU 5.2.21 oracle.
@caomengxuan666 caomengxuan666 added bug Something isn't working P3-low 低:优化、文档、远期规划,有机会再做 gnu-baseline Tracked by the GNU Bash 5.3.0 true-baseline ledger 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

Thanks for the PR, @arookieofc-ai — and for the GNU-oracle notes (the bash 5.2.21 re-probe on the set -u status, and the pre-existing evaluator wording divergence pinned as-is) and the fail-first nail stem.

First pass from intake (not a merge review):

  • I read the full diff: pipeline_prefix_arith_status probes each prefix RHS once at the inline arms' commit points (echo/printf/:/false, cat/head/trap -p and the other committed arms), rolls back the probe's variable writes and arithmetic flags, and carries the verdict as a status; the external path adjudicates the already-composed prefix before the spawn and returns the dead member without spawning on the host channel and the five concurrent spawners. The mechanism matches the PR body and [bug] pipeline-element prefix assignment ignores fatal arithmetic error (rubash#3383 face 2) #3456's two faces (A swallowed / B spawned-then-leaked).
  • CI: the three failing legs all trace to known pre-existing reds, not to this change — Linux, macOS, and GNU-goldens each fail only on api::consumer_tests::issue2875_input_procsub_child_runs_as_rubash_shell (missing rubash binary precondition), and the niu-canary leg fails only on the known ledger drift (MISSING Session::cwd). No failure names the new issue3456 stem or any pipeline test. Note the new stem does not visibly run in CI's selected Rust-tests table (the lib-test failure skips the integration-stem step), so its 31/31 currently rests on the author's local run.
  • This is queued for captain review — external PRs are reviewed by the captain first, per repo rules. Nothing is merged or requested-changed here. One point for that review: on the non-fatal path the probe's expansion is thrown away and the real expansion re-runs the same RHS, so a prefix RHS with command-substitution side effects would execute twice (the rollback restores variables/flags, not already-performed external effects) — worth confirming against e.g. a prefix RHS containing $(...) before merge.
  • Note: Fixes #3456 in the body will auto-close [bug] pipeline-element prefix assignment ignores fatal arithmetic error (rubash#3383 face 2) #3456 on merge.

@caomengxuan666
caomengxuan666 merged commit 358a83e into master Nov 16, 2026
11 of 15 checks passed
@caomengxuan666

Copy link
Copy Markdown
Member

【WIN-AGENT-AUDIT】s2

PR #3760 第1轮 — 建议:PASS(已合并 358a83e)
head: 01136fae4... → 实为 01136d1;base(merge-base): 8100d76;文件 4 个 +800/-0
关联 issue: #3456(open → merged 后自动 closed,2026-11-16T10:35:04Z UTC)

机制核查:

  • GNU 在 pipeline element 的 prefix VAR=value 于子进程展开(subst.c:13153 do_assignment_statements 选 assign_in_env;展开致命错误走 subst.c:13037 exp_jump_to_top_level(DISCARD)),因此诊断只印一次、整元素丢弃、状态折 1、父 shell 看不到变量写入。本 PR 在 inline slot 提交点 probe + 回滚(env_vars/variables/exit_code/算术标志),与 fix(executor): pipeline bad substitution reports once and discards the element (Refs #3499) #3761 已落地的同族模式一致,非新桥接层。
  • 覆盖 five concurrent spawners + host channel(external_inner.rs)与 inline arms;未发现顺手改无关面;无删除。
  • 可疑点:probe 对每次带 assignment 的 inline stage 复制 env_vars/variables(热路径 O(n))。实测无功能差异,留作性能观察项,不构成 FAIL。

腿:

  • 钉自跑:issue3456_prefix_arith_pipeline 31/31(文件是 #![cfg(unix)],Windows 上按去 gate 的临时副本跑,仅把期望里的 script 路径转成 rubash 的 /c/... 形,未改断言语义;副本已删)。
  • fail-first:base 8100d76 同副本 8 passed / 23 failed(PR 正文称 7/24,差 1 为 Windows 平台格;base 绿集 = {command_substitution_guard, function_stage_guard, before_compound_is_syntax_error_delimitation, hello_word_expands_first_delimitation, incr_rolls_back_guard, incr_word_expands_first_guard, nounset_plain_word_guard, nounset_word_guard},均为「行为不变」守卫格)。
  • lib 双边:head 失败名 {issue2084_session_end_restores_host_process_state, windows_shell_namespace_argument_shape_class} / base {issue2084_session_end_restores_host_process_state, pathmatrix_bridge_legacy_dialect_restores_funnel};两个 windows/path 格单跑皆绿(并行态 flaky),issue2084 双边同红 → 差集 ∅。
  • -D warnings:cargo check --bin rubash --lib 与 PR stem 目标 0 警告;全仓 --tests 在 issue1794/issue2278 两个 PR 未触碰的 stem 上有既有 dead-code 红(基线,非本 PR)。
  • 卫生:rustfmt 逐文件(4 文件)0 差异(cargo fmt os error 206,按台账替代);marker-lint OK (117 consts/268 sites);utf8 clean。
  • CI(run 43801309380):Rust tests = issue2875 基线格;Rust tests (macOS) 1245 passed/1 failed = issue2875;GNU goldens 1351 passed/1 failed = issue2875;niubash builds = 已知 ledger 漂移 MISSING Session::cwd(ci: unmask master-red — issue2875 out/ resolver + masked test/corpus fixes #3750 面,未落地);其余 6 项绿。无 PR 专属红。
  • GNU 对照(WSL GNU bash 5.3.20(1)):x=$((1/0)) echo hi|cat x=$((1/0)) printenv|cat x=$((08)) echo|cat set -u; y=$undef echo|cat → 均 pipe=1 0、诊断一次;x=$(echo SIDE>side.txt) echo hi|cat 文件创建;x=$((IFS=:))/x=$((a[1]=7))/x=$((e=2)) 无父进程泄漏;builtin cd/function stage/pipefail 全形状与 GNU 逐字节一致(探针 target/s2/probes/p3456{,b,c}.sh)。

F 点:无

合并:358a83ec73b8934fb46fd42f96e78801ff00b1ff(squash,未删分支)

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] pipeline-element prefix assignment ignores fatal arithmetic error (rubash#3383 face 2)

2 participants