Skip to content

fix(pipeline): stream pipeline stage stderr live in the sequential loop - #3468

Merged
caomengxuan666 merged 2 commits into
masterfrom
fix/3434-pipeline-diagnostic-order
Nov 15, 2026
Merged

caomengxuan666 merged 2 commits into
masterfrom
fix/3434-pipeline-diagnostic-order

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

fix(pipeline): stream pipeline stage stderr live in the sequential loop

Root cause

A compound/function pipeline stage captured its whole stderr into one
buffer and flushed it only when the stage completed, while the stage's
stdout streamed live (final member, #1605) or escaped live through a
dup'd fd (>&3), so a diagnostic that execution order puts first
printed last.

GNU: execute_pipeline (execute_cmd.c:2620) forks each element with
the pipe bound to fd 1 and the shell's other descriptors inherited, and
builtin_error (builtins/common.c:98) writes the element's fd 2 as
produced (stdio line-buffered, shell.c:1921-1922). There is no
"collect then order" step.

Fix

Arm the #2483 live-stderr channel in the sequential stage loop
(execute_simple_pipeline_inner) and narrow
pipeline_stage_stderr_may_stream so only redirects that (re)bind fd 2
decline the channel (redirect_claims_fd2): fd == 2, &>/&>>
combined output, or a dynamic {var} fd. A 3>&1 dup no longer
forfeits the live channel for the whole stage.

Regression nail

tests/issue3434_pipeline_builtin_diagnostic_order.rs (11 tests):
7 defect shapes fail-first on base, 4 control/guard shapes pass.

Verification

Leg base (e50cea96) head
Seed seed_r108d.sh (rubash driver) 4 FAIL + 3 PASS Owed — build slots blocked (see below)
Nail issue3434_… (scrubbed_cargo) 7 FAIL / 4 PASS, fail-first on base binary Owed
Morph b/c/e three-way mR7/mR13/mQ3/mQ6 DIFF Owed
Full lib (both sides, count-aligned) — Owed
RUSTFLAGS="-D warnings" cargo check --lib --bins — Owed
Hygiene (fmt / marker-lint / utf8) — PASS (fmt clean, marker-lint OK, utf8 clean)
Adjacent stems issue3324… / issue2699… / issue1134… — Owed

Head build legs are Owed to the review round: the Simular box disk is
100% full, the old server's sshd is banner-dead again, local builds are
prohibited for this lane, and X299 direct access is not yet wired.
Static legs (fmt, marker-lint, utf8) pass; the fix is +42/−1 in one
file plus the 11-test nail.

本 PR 删除了什么

无删除。仅收窄一处否决谓词
(!redirects.is_empty() →
redirects.iter().any(redirect_claims_fd2)),并在顺序循环布防既有标志。

Refs #3434
UNVERIFIED-BY-CAPTAIN

@caomengxuan666

caomengxuan666 commented Nov 13, 2026 •

Copy link
Copy Markdown
Member Author

Captain review: FAIL — three rework items (O1 + N1 + N2)

Head ca7aecba reviewed. The fix itself is sound (GNU anchors re-verified:
execute_cmd.c:2620, builtins/common.c:98, shell.c:1921-1922; the
redirect_claims_fd2 narrowing is exactly as described), the 11-test nail covers
the 7 defect shapes plus 4 control/guard shapes, and the hygiene legs are green on
both faces (fmt / marker-lint / utf8 rc=0, Linux + X299). X299 legs: H-pin 10/11
(base 3/8 — fail-first confirmed), lib 1349 passed / 1 failed / 4 ignored on both
trees with name-set diff ∅ (sole failure both trees is the pre-existing
Windows-only issue863_gap8, identical). But three items block merge.

O1 (product, REQUIRED rework): ? inside the dispatch skips the flag restore

In execute_simple_pipeline_inner (src/executor/pipeline_exec.rs:1777-1831) the
new code saves pipeline_stage_stderr_live, arms it, then runs the stage dispatch
inside a let Some(...) = (...) else { ... } scrutinee — and that scrutinee contains
six ? propagations (:1784, :1786, :1800, :1802, :1811, :1823). An Err via any
of them returns out of the function without restoring the flag, so
pipeline_stage_stderr_live can linger into the next stage / caller. The inline
comment says "Restored right after the dispatch, on both exits" (:1772-1773) — that
is only true for the Some and None exits; Err is a third exit with no restore.

Required rework (sandwich form, unconditional restore): capture the dispatch result
into a variable with no ? between the set and the restore, restore unconditionally,
and only then propagate / handle (? / let … else / return Ok(None)). The two
pre-existing sibling arms already do exactly this — pipeline_exec.rs:2963-2972
(shell-writer path) and :4465-4472 (sandwich path) both assign the stage result to a
variable, restore the flags, and only then match on the result. Follow that in-tree
precedent for the new site, and correct the "on both exits" comment.

N1 (nail defect): 2>file guard test uses an unquoted backslash path

tests/issue3434_pipeline_builtin_diagnostic_order.rs:179-206,
issue3434_stage_stderr_redirect_still_wins, interpolates the temp path unquoted
into the script (format!("... 2>{}", err_path.to_string_lossy())). On Windows the
path is C:\Users\...\err.txt; the shell strips the backslashes as escapes
(POSIX-correct — GNU does the same), so the redirect lands on the mangled relative
name and the read fails NotFound. This is the sole H-pin failure on X299 (10/11).
Fix: quote the path or use forward slashes.

N2 (nail defect): pin's MergedRun.code is never read

tests/issue3434_pipeline_builtin_diagnostic_order.rs: code: i32 declared :41,
set :64, never read anywhere in the file (only merged and dir are read). Genuine
dead_code warning — a hard error under -D warnings once the pin target is
reached. Fix: remove the field or #[allow(dead_code)].

Legs run on this head

  • X299 (banked, not re-run): H-buildbin / B-buildbin rc=0; H-pin 10/11, B-pin 3/8;
    H-lib / B-lib 1349 passed / 1 failed / 4 ignored both trees, name-set diff ∅;
    hygiene rc=0; H-warnings incomplete on a pre-existing Windows-only
    issue2293 dead-code failure (not this PR), product lib clean under -D warnings.
  • Linux: build legs VOID — the local write wall never opened deep enough (1 pass in
    10 battery rounds over 64 min; box disk 100% with no reclaimable tree; old server
    sshd banner-dead; X299 has wsl.exe but no distribution installed). Read-only
    legs banked: hygiene trio rc=0, GNU seed 7/7 PASS. The re-review re-runs the Linux
    legs (leg-driver-3468.sh) on the rework head after the depth gate passes.
  • CI run 43327088639: 7 pass + 1 skipping + 3 fail; all three fails are the same single
    cell api::consumer_tests::issue2875_input_procsub_child_runs_as_rubash_shell.
    The logs carry the tests: lib-only runs false-red the issue2875 procsub cell when no rubash bin is built #3292 no-bin-trap signature (Unrecognized option: 'c'); the
    base run passed the same cell on identical commands, so the bin's absence on the
    head runners is an open question for the re-review (bin-present/bin-absent
    bilateral), not a fourth rework item on current evidence. The new pin stem is not
    run by CI at all.

Re-review plan (focused)

Re-read the reworked hunks only; confirm by inspection that no ? / early return
sits between the set and the restore; re-run cargo fmt --check +
RUSTFLAGS="-D warnings" cargo check --lib --bins (touch pipeline_exec.rs first
so the check cannot be idle); re-run the pin stem on head
(cargo test --test issue3434_pipeline_builtin_diagnostic_order, --bin rubash
built first) — expect 11/11 — plus the -D warnings pin-target check (7d, must
pass after N2) and the issue2875 bin-present/bin-absent bilateral. No full lib
re-run is needed unless the rework touches anything outside the guard (it must not).

Notes

  • Master has moved past the lane base e50cea96 (now be610327 at re-review check
    time — re-check the tip intersection with this PR's two files at re-review; the
    earlier check against 8a73f079 showed an empty intersection, so no rebase was
    needed then).
  • UNVERIFIED-BY-CAPTAIN still stands until the re-review legs above pass.

caomengxuan666 added a commit that referenced this pull request Nov 13, 2026
…op (Refs #3434)

Rework of PR #3468 per captain review FAIL: the new guard set
pipeline_stage_stderr_live and then ran the stage dispatch inside a
let-else scrutinee holding six '?' propagations, so an Err returned
without restoring the flag. Sandwich form now: the dispatch runs in
a closure returning Result, the flag is restored unconditionally,
and only then is the result propagated/handled (cf. the
shell-writer and sandwich paths). The 'on both exits' comment is
corrected: Err is a third exit and now passes through the restore.

Nail fixes in the same commit: quote the temp err path in
issue3434_stage_stderr_redirect_still_wins (unquoted Windows path
lost its backslashes) and drop the never-read MergedRun.code field
(dead_code under -D warnings).
@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT】
PR #3468 第2轮 — 建议:PASS
head: ef687c3 base(merge-base): e50cea9 文件: 2 个(pipeline_exec.rs + issue3434 钉)
关联 issue: #3434(open,核于 2026-11-15)

机制核查:

  • O1 复核:execute_simple_pipeline_inner 现 sandwich 形——dispatch 包进返回 Result 的闭包,set 与 restore 之间无 ?;self.pipeline_stage_stderr_live = saved_stderr_live 无条件先恢复,其后才 dispatch_result? / let-else / return Ok(None)。三出口(Some/None/Err)均过 restore,与 :2963-2972、:4465-4472 两兄弟臂同形。逐行确认闭包内 6 处 ? 只返回进闭包自身。
  • 无关改动:无;ef687c3f 同时带 N1/N2 两钉修正。

腿(X299 本机):

  • 钉自跑 head:issue3434_pipeline_builtin_diagnostic_order 11 passed / 0 failed(前轮 10/11 的 stage_stderr_redirect_still_wins 经 N1 引号修正后转绿)
  • fail-first:base 3/8 为前轮 X299 已记档腿(本轮钉仅改引号/死字段,不改语义,B-pin 不重跑)
  • lib 双边:前轮已记 1349/1/4 双侧 {issue863_gap8 → 现为本机基线 issue2084},本轮回合仅守备区 hunk 重排,无新面;未重跑全量(见欠腿说明)
  • -D warnings:RUSTFLAGS="-D warnings" cargo check --lib --bins(touch pipeline_exec.rs 后跑,非空检)0 错;钉目标 cargo test --test issue3434… --no-run 0 错 —— N2 死字段已消
  • 卫生:rustfmt --check 两文件干净;marker-lint / utf8 前轮双侧 rc=0 未变
  • CI(head ef687c3):3 红任务红名均仅 issue2875_input_procsub_child_runs_as_rubash_shell(基线);Cross-target darwin PASS;其余全绿
  • GNU 对照:前轮 GNU seed 7/7 PASS 记档;本轮语义面无新增形状

F 点回应:

  • O1(6 个 ? 在 set/restore 之间,Err 出口漏 restore):已由 ef687c3 返工为 sandwich 形 —— 逐行复核通过。
  • N1(Windows 路径反斜杠被 shell 当转义吃掉 → 重定向落空):已由 ef687c3 改为 2>"{path}" 双引号包裹 —— 该格本轮转绿。
  • N2(MergedRun.code 声明未读 → -D warnings 死代码):已由 ef687c3 删除字段 —— 钉目标 -D warnings 现 0 错。

续作记录:本轮仅复核与验证腿,未改代码未推送(远端 head ef687c3 未变)。

未跑/VOID 的腿:

…op (#3434)

Root cause: a compound/function pipeline stage captured its whole
stderr into one buffer and flushed it only when the stage completed,
while the stage's stdout streamed live (final member, #1605) or
escaped live through a dup'd fd (>&3), so a diagnostic that execution
order puts first printed last.

GNU: execute_pipeline (execute_cmd.c:2620) forks each element with
the pipe bound to fd 1 and the shell's other descriptors inherited,
and builtin_error (builtins/common.c:98) writes the element's fd 2
as produced (stdio line-buffered, shell.c:1921-1922). There is no
"collect then order" step.

Fix: arm the #2483 live-stderr channel in the sequential stage loop
(execute_simple_pipeline_inner) and narrow pipeline_stage_stderr_may_stream
so only redirects that (re)bind fd 2 decline the channel
(redirect_claims_fd2): fd == 2, &>/&>> combined output, or a dynamic
{var} fd. A 3>&1 dup no longer forfeits the live channel.

Regression nail: tests/issue3434_pipeline_builtin_diagnostic_order.rs
(11 tests; 7 defect shapes fail-first on base, 4 control/guard shapes pass).

本 PR 删除了什么:无删除。仅收窄一处否决谓词
(!redirects.is_empty() -> redirects.iter().any(redirect_claims_fd2)),
并在顺序循环布防既有标志。

Refs #3434
UNVERIFIED-BY-CAPTAIN
…op (Refs #3434)

Rework of PR #3468 per captain review FAIL: the new guard set
pipeline_stage_stderr_live and then ran the stage dispatch inside a
let-else scrutinee holding six '?' propagations, so an Err returned
without restoring the flag. Sandwich form now: the dispatch runs in
a closure returning Result, the flag is restored unconditionally,
and only then is the result propagated/handled (cf. the
shell-writer and sandwich paths). The 'on both exits' comment is
corrected: Err is a third exit and now passes through the restore.

Nail fixes in the same commit: quote the temp err path in
issue3434_stage_stderr_redirect_still_wins (unquoted Windows path
lost its backslashes) and drop the never-read MergedRun.code field
(dead_code under -D warnings).
@caomengxuan666
caomengxuan666 force-pushed the fix/3434-pipeline-diagnostic-order branch from ef687c3 to 01e9dc3 Compare November 15, 2026 02:24
@caomengxuan666
caomengxuan666 merged commit 0677b7d into master Nov 15, 2026
8 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant