Skip to content

fix(executor): keep pipelines concurrent with fd-2 redirects (Refs #3516) - #3509

Merged
caomengxuan666 merged 2 commits into
unixwin:masterfrom
Catapult291:fix/pipeline-stderr-redirect
Nov 17, 2026
Merged

caomengxuan666 merged 2 commits into
unixwin:masterfrom
Catapult291:fix/pipeline-stderr-redirect

Conversation

@Catapult291

@Catapult291 Catapult291 commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Fixes the yes | head -3 2>/dev/null class of hangs: any fd-2 redirect sent the pipeline down the sequential path, draining the unbounded producer.

Opens fd-2 admission on the concurrent path, wires member stderr redirects onto the child stdio, and routes the final member's stderr through the existing stream router. 2>&- stays on the sequential path.

tests/pipeline_stderr_redirect_streaming.rs (8 tests) pins the shapes; cargo test --lib 1349 passed / 1 pre-existing failure (api::consumer_tests::issue2084, fails on master too).

Refs #3516

本 PR 删除了什么

无文件/函数级删除。The −49 lines in src/executor/pipeline_exec.rs are in-place rewires: the two blanket fd-2 admission rejections become stage_closes_stderr, and the three duplicated inline final-member stderr publish blocks are consolidated into the shared write_concurrent_pipeline_output helper, which routes through the existing route_pipeline_stage_streams (one mechanism, not a second walk). src/executor/pipeline_stages.rs is a 1-line visibility widening; the pin file is pure addition.

@caomengxuan666 caomengxuan666 added bug Something isn't working P1-high 高:核心语义或高频路径受损,影响日常使用/发布 area:fd redirection, fd table, /dev/* emulation, dup/close ordering family:S3 taxonomy S3: redirection/fd model (N builtin output paths patched separately) labels Nov 13, 2026
@caomengxuan666 caomengxuan666 self-assigned this Nov 13, 2026
@caomengxuan666

Copy link
Copy Markdown
Member

Thanks for the PR, @Catapult291. Captured: the y | y | y hang class where any fd-2 redirect sent the pipeline down the sequential path and drained the unbounded producer (e.g. yes | head -3 2>/dev/null), fixed by opening fd-2 admission on the concurrent path and routing the final member's stderr through the stream router, with 2>&- staying on the sequential path; plus the 8 new tests in tests/pipeline_stderr_redirect_streaming.rs.

Per the repo rule, external PRs go through captain review first, so this is queued for that review — no merge from this side, and I am not requesting any change here.

CI status, checked just now: 3 legs are red — Rust tests, Rust tests (macOS), and GNU regression goldens and canaries — and all three fail on the same single test, api::consumer_tests::issue2875_input_procsub_child_runs_as_rubash_shell (consumer_tests.rs:2911). Everything else passes, including Compatibility CLI tests, Shell functionality tests, both cross-target checks, the Windows compile check, and both niu-canary legs. The captain's review re-run will adjudicate that one failure (including whether it is the known lib-only-run artifact or something this change touches); the new test stem will also be re-run directly there, since CI's Rust tests job runs a selected table rather than every new stem.

@Catapult291

Copy link
Copy Markdown
Contributor Author

Quick note on the 3 red CI legs (Rust tests, Rust tests (macOS), GNU regression goldens and canaries): all three fail on the same single test, api::consumer_tests::issue2875_input_procsub_child_runs_as_rubash_shell, and master's latest commit (5219be90) shows the identical failure set — same test, same panic at src/api/consumer_tests.rs:2911 (Unrecognized option: 'c', exit code 1 vs 0). So these legs look pre-existing on master and unrelated to this PR's changes.

For reference: the PR body's issue2084 note refers to the one pre-existing failure seen in the local cargo test --lib run; issue2875 is the one CI hits. Both are pre-existing master failures.

@caomengxuan666

Copy link
Copy Markdown
Member

【WIN-AGENT-AUDIT】s10 lane — 建议:PENDING(CONFLICTING,跳过不合)

head: 8248fbe base(merge-base): 8b48c16 文件: 3 个 +474/-50
关联 issue: #3516(状态:open,我核过的时间:2026-11-16 20:15 CST)

处置:不合并。gh pr view 实时 mergeable=CONFLICTING / mergeStateStatus=DIRTY;对现尖 origin/master 12fb4e61 的 git merge-tree --write-tree rc=1,冲突文件:src/executor/pipeline_exec.rs。

背景提示:

  • 这是外部贡献者 Catapult291 的 PR;队长 2026-11-13 评论已登记「外部 PR 先走队长复核,不在这侧合入」,与本次 DIRTY 结论同向。
  • 与清单内 fix(executor): wire every pipeline stage's fd 2 from the fd table on the Windows and shell-stage spawn paths (Refs #3402) #3562 动同一文件同一片区域(fd-2 准入 / 末成员 stderr 中继),两者互相冲突;谁先合需要队长定序,后落的一方按合并形重做。
  • 机制方向(2>/2>&1 成员不再强制顺序路径、末成员 stderr 走既有 route_pipeline_stage_streams、2>&- 仍留顺序路径)本身不违背 GNU:execute_cmd.c:2620 execute_pipeline() 每个成员各自 fork 继承 fd 2;但是否等价要按现尖的 8 格钉 + 无界生产者 hang 形重验。

腿:本轮全部未跑(按 CONFLICTING 跳过规则),不记为通过。

未跑/VOID 的腿:

  • 钉自跑(pipeline_stderr_redirect_streaming)/ fail-first / lib 双边 / -D warnings / 卫生 / GNU 对照 —— 全部因 CONFLICTING 跳过。

@caomengxuan666

Copy link
Copy Markdown
Member

【WIN-AGENT-AUDIT】PR #3509 第2轮 — 建议:PENDING(CONFLICTING,产品语义冲突,需队长定序)
head: 8248fbe265a2828b205185df29103447ff06394e(未变)
关联 issue: #3516(open)

V 波收网复核:

@caomengxuan666

Copy link
Copy Markdown
Member

评审结论:FAIL(需 rebase,本侧无法代改)

跨仓库 fork(Catapult291/fix/pipeline-stderr-redirect),按车道规则只审不合;当前 GitHub 状态
mergeable=CONFLICTING / mergeStateStatus=DIRTY,且本侧无 push 权限,不能代解冲突。

功能本身:正确,且 master 仍缺

在 PR 自身 base(8248fbe26)上构建绿、pin 全绿:

pipeline_stderr_redirect_streaming  8 passed / 0 failed

WSL GNU Bash 5.3.20 脚本文件实测(oracle):

形状 GNU 5.3.20 当前 master(c8109c58)
yes | true 2>/dev/null rc 0,立即返回 挂死(timeout 5s,exit 124)
yes | { head -3; } 2>/dev/null 3 行 y,rc 0 同上
yes | true 2>/dev/null; echo ${PIPESTATUS[0]} 141 —
yes | true 2>/tmp/e rc 0,stderr 文件为空 —

→ 不是被 master 取代,是真实未修 bug(无限生产者 + fd-2 redirect 的 shell-side tail)。

阻断点(冲突实质,非机械文本冲突)

src/executor/pipeline_exec.rs 3 个 hunk,全部撞在 master 之后落地的同族改造上:

  1. tail stderr 的写出模型重叠。PR 新增
    write_concurrent_pipeline_output(tail, &mut tail_result),把 in-shell tail 自己的
    2>…/2>&1 交给并发写出器;master 已有 rubash#3308 的
    write_pipeline_output(...) + write_default_stderr(...)(tail 的 collected stderr
    走 fd-table binding)。两者是同一不变量(tail 的 fd-2 归属)的两套实现,
    merge 后需要 owner 决定保留哪一套,不能简单叠加。
  2. 并发 spawn API 已改签名。master 的
    spawn_wait_concurrent_external_stages(...) 现在返回
    Option<Vec<triple>>(可 decline → Ok(None));PR 仍按 Vec 直接解构,
    第 1、3 个 hunk 即由此产生。
  3. hunk 2 的 statuses[tail_index] = tail_status / write_pipeline_output(tail, &tail_out, false)
    已经是 master 的新双通道模型,PR 的 statuses.push(tail_result.2) 与之冲突。

建议

  1. 在 fork 上 rebase 到 c8109c58(或更新 master),按 master 的
    Option 返回 + write_default_stderr 模型重写 tail 写出;
    若 PR 的 write_concurrent_pipeline_output 确实更优,请在 PR 说明为何替换 [bug][fd] 脚本模式 $(外部 | 外部):管道首进程 stderr 绕过全部重定向直写控制台(-c 模式正常;GNU 无此行为) #3308,
    由 owner 裁决。
  2. 保留现有 8 个 pin(形状与 GNU 字节一致),rebase 后重新跑
    cargo test --test pipeline_stderr_redirect_streaming。
  3. 顺带确认 pipeline_stages.rs 的单行改动在 rebase 后仍需要。

状态:未合并,PR 保持 OPEN;本备注只作评审记录,不关闭任何 issue。

niu-fix-local added 2 commits November 17, 2026 19:05
An infinite producer plus a stderr redirect on any pipeline member fell
back to the sequential stage loop, which materializes the producer to EOF
before starting the consumer: `yes | head -3 2>/dev/null` never returned.

- Admit fd-2 redirects in the concurrent pipeline probes (all-external,
  shell-writer, external-prefix); `2>&-` still takes the sequential path
  because Stdio cannot express a closed fd.
- Wire an intermediate member's resolved fd-2 target onto its child
  stderr (null, file/append, shared fd, or a duplicate of the outgoing
  pipe for `2>&1`), preserving true merged write order.
- Route the final member's captured stderr through the same ordered walk
  as stdout, covering `2>file`, `2>&1`, `>file 2>&1` and `2>&1 >file`.
- Add a watchdog-bounded regression test for the hang and PIPESTATUS.
Follow-up to the concurrent fd-2 wiring: an in-shell tail
(`yes | true 2>/dev/null`) and a single-command brace group
(`yes | { head -3; } 2>/dev/null`) still forced the sequential stage
loop, which drains an unbounded producer forever.

- Allow a streaming tail's own fd-2 redirect; the tail runs in-shell and
  its captured stderr goes through write_concurrent_pipeline_output.
- Fold `{ cmd; } 2>dst` into `cmd 2>dst` during pipeline
  normalization (GNU runs the compound's redirects before the body),
  so the concurrent drivers can admit the member.
@Catapult291
Catapult291 force-pushed the fix/pipeline-stderr-redirect branch from 8248fbe to 9b452e7 Compare November 17, 2026 11:11
@Catapult291

Copy link
Copy Markdown
Contributor Author

Rebased onto current master (23c0afc6, newer than the c8109c58 you reviewed) and force-pushed as 9b452e7c. 逐点回应评审的三个阻断点:

  1. 并发 spawn API 的 Option 签名:三处调用点已全部按 master 的 Result<Option<Vec<...>>> 模型改写(all-external 路径、external-prefix 路径、in-shell tail 的 tail_result 解构),decline 时仍走 Ok(None) 落回顺序路径。

  2. tail stderr 写出模型:write_concurrent_pipeline_output 没有替换 [bug][fd] 脚本模式 $(外部 | 外部):管道首进程 stderr 绕过全部重定向直写控制台(-c 模式正常;GNU 无此行为) #3308,是在其上补一层。tail 自己的 fd-2 重定向(2>/dev/null、2>file、2>&1)先经既有 route_pipeline_stage_streams 走一遍(与 fix(pipeline): stream pipeline stage stderr live in the sequential loop #3468/[bug][fd] 脚本模式 $(外部 | 外部):管道首进程 stderr 绕过全部重定向直写控制台(-c 模式正常;GNU 无此行为) #3308 同一条 walk),剩余 stdout 交给 write_pipeline_output(already_routed=true)、剩余 stderr 交给 write_default_stderr —— 出口就是 [bug][fd] 脚本模式 $(外部 | 外部):管道首进程 stderr 绕过全部重定向直写控制台(-c 模式正常;GNU 无此行为) #3308 的两个面,无第二套写出机制。若 owner 认为应把这段直接折叠进 write_pipeline_output 的 !already_routed 分支(fd-2 准入放开后该分支也具备处理 tail stderr 的条件),这边随时可改。

  3. statuses[tail_index] 双通道模型:保留 master 的预置槽位写法(statuses[tail_index] = tail_result.2),PR 侧的 statuses.push 已移除;external-prefix 路径保留 master 的 Option 解构与 statuses[prefix_len - 1] = status 覆写。

  4. pipeline_stages.rs 单行改动确认仍需要:rebase 后 configure_stage_stderr 仍有两处调用 pipeline_stages::stdio_from_fd_handle,而 master 已把它收紧为私有,故 pub(in crate::executor) 扩宽必须保留。

验证:cargo check 干净;cargo test --test pipeline_stderr_redirect_streaming 8/8 通过;cargo test --lib 1374 通过 / 1 失败(issue2084,master 上同样失败)。8 个钉的形状与 GNU 字节一致,未改动。

@Catapult291

Copy link
Copy Markdown
Contributor Author

CI 归因(run 44071755856,head 9b452e7c):红腿 2 个 —— GNU regression goldens and canaries 与 Regression pin stem census。逐名对照 master 最新 run 44068858178(head 23c0afc6,同款两腿同样红、失败集为 91 个同名测试的超集):golden_issue1230_exec_redirect_undo、issue_753::case_9_declare_indexed_operand_binds_nothing、upstream_suite_slice_snapshots 及 census 各 stem 均为 master 基线失败,与本 PR 改动无关。master 的 Compatibility CLI tests 也红(c_command_keeps_named_coproc_output_fds_distinct),本 PR 该腿通过——本 run 严格优于 master 基线。

@caomengxuan666
caomengxuan666 merged commit 3d8c9ff into unixwin:master Nov 17, 2026
9 of 12 checks passed
caomengxuan666 added a commit that referenced this pull request Nov 17, 2026
Resolve pipeline_exec.rs against #3509 (member-own 2> redirects via
configure_stage_stderr/stage_has_stderr_redirect) and #3860 (#3566
prefix stdout): wire() lays the ambient fd-table default first, then
configure_stage_stderr applies the member's own redirect (the
do_piping -> do_redirections order); Piped drains keep the
child.stderr.take() guard; spawn-failure diagnostics ride
write_default_stderr like the unix twin.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:fd redirection, fd table, /dev/* emulation, dup/close ordering bug Something isn't working family:S3 taxonomy S3: redirection/fd model (N builtin output paths patched separately) P1-high 高:核心语义或高频路径受损,影响日常使用/发布

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants