Skip to content

fix(executor): wire every pipeline stage's fd 2 from the fd table on the Windows and shell-stage spawn paths (Refs #3402) - #3562

Merged
caomengxuan666 merged 4 commits into
masterfrom
fix/3402-pipeline-stage-stderr-fd-table
Nov 18, 2026
Merged

caomengxuan666 merged 4 commits into
masterfrom
fix/3402-pipeline-stage-stderr-fd-table

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Fixes #3402

修了什么

流水线成员的 fd 2 在 #3308 之后仍有多条 spawn 路径绕过 fd 表、直接继承/写入进程原始 stderr,导致外层 2>file / 2>/dev/null / 2>&- / exec 2>file 对非末成员(以及 Windows 全外部路径的末成员中继)无效:

路径 平台 旧行为
spawn_wait_concurrent_external_stages(全外部并发 + 前缀并发) Windows 非末成员只在 2>&1 合并时接线,其余继承原始 stderr
execute_external_pipeline_concurrently 末成员中继 Windows std::io::stderr().write_all(议题点名的 raw write)
execute_external_prefix_streaming_tail(builtin 尾) Windows #3308 的 plan 被 cfg(not(windows)) 挡掉
execute_streaming_sandwich_pipeline(一个 shell 侧成员) 两平台 非末成员从不接线(注释误以为"继承即 shell 的 fd 2")
execute_shell_writer_pipeline 消费者循环 两平台 非末消费者只在 2>&1 时接线

机制修法:ConcurrentPipelineStderr 枚举与 concurrent_pipeline_stderr_plan() 去掉 cfg(not(windows))(fd 表与 duplicate_handle_inheritable 两平台都有),新增 ConcurrentPipelineStderr::wire() 统一接线;上表每个 spawn 循环在循环前解析一次 plan、按 plan 接线,Piped 成员自 spawn 起排水、收割后经 write_default_stderr 按成员序中继(2>&1 即走 dup 时快照,不再走 write_default_stdout 喂进活 capture)。原 Unix 孪生与 streaming tail 里两份手写 match 也收拢到 wire(),行为不变。

删了什么

  • 删除 Windows 末成员 stderr 的 std::io::stderr().write_all 原始写。
  • 删除 streaming tail 中 5 处 #[cfg(not(windows))] 门控。
  • 删除两份重复的 plan match(并入 wire())。
    无文件、功能、测试被删除。

GNU 依据

验证(Windows 本机,逐 stem 报数)

  • 新钉 tests/issue3402_pipeline_stage_stderr_fd_table.rs(18 格:每条 spawn 路径 × devnull / err 文件 / 2>&- / exec 2>file / 2>&1 捕获,外加 2 个 GNU 正确"泄漏"对照格防过度抑制):
    • head 18/18;基底(git checkout origin/master -- src/executor/pipeline_exec.rs 重建)fail-first 3 passed / 15 failed,红格恰为缺陷格(绿的是 2>&1 捕获格与两个对照格)。
    • 18 格脚本逐格过 WSL GNU 5.3.20(/usr/local/bin/bash,脚本文件,独立 cwd):stdout / stderr / err.txt 与钉期望全一致。
  • 相邻 23 个 stem,head 与基底失败名集合逐名相同(差集只有新钉的 15 格):issue1358 1/0、issue1363 19/2、issue1371 1/0、issue144 10/0、issue1462 1/0、issue1545 11/2、issue1552 7/1、issue158 5/0、issue2244 8/0、issue2589 2/2、issue2602 1/2、issue3308 9/9、issue3324 0/18、issue761 6/0 ×2(其余 issue1454/1596/1822/2250/2294/2483/723 在 Windows 为 0 测)。这些既有红格两侧一致,均为 Windows 环境面(钉内写死 PATH=/usr/bin:/bin 找不到 cat、2>{} 内插 Windows 反斜杠路径等),与本改动无关。
  • rustfmt --edition 2021 --check 覆盖 cargo metadata 列出的全部 1487 个 target 源:本 PR 文件全净;唯一 diff 是 master 既有的 tests/d11_pipeline_squote_carrier_regressions.rs(非本 PR)。

Owed

  • Linux 腿(新钉 + issue3308 等在 WSL Linux 构建上跑):见后续评论;未贴结果前视为 owed。
  • Windows CI 不跑集成 stem(只 cargo check --tests),新钉在 Windows 上仅本机跑过。
  • 提交钩子:本机 cargo fmt --check 因 1487 个 target 路径超出 Windows 命令行上限报 os error 206 必然失败(与改动无关,主仓库同样复现),本次提交以等价的逐文件 rustfmt --check 全量校验代替,钩子未能执行 —— 如实说明。

…the Windows and shell-stage spawn paths (Refs #3402)

GNU execute_cmd.c:2620 execute_pipeline forks every element with the
shell's fd 2 exactly as redir.c:237 do_redirections bound it. #3308
wired the Unix concurrent twins; the remaining spawn loops still left
non-last members on the raw process stderr past an enclosing
`2>file` / `2>/dev/null` / `2>&-` / `exec 2>file` binding:

- Windows spawn_wait_concurrent_external_stages (all-external and
  prefix-concurrent paths) only wired fd 2 for the `2>&1` merge, and
  execute_external_pipeline_concurrently relayed the last stage's
  collected stderr through std::io::stderr();
- the prefix streaming tail gated the #3308 plan to non-Windows;
- the streaming sandwich (one shell-side stage) and the shell-writer
  consumer loop never wired non-last members at all (both platforms).

ConcurrentPipelineStderr and its resolver are now platform-neutral and
carry a `wire` helper; every loop resolves the plan once and relays a
Piped member through write_default_stderr.

Pin: tests/issue3402_pipeline_stage_stderr_fd_table.rs (18 cells, one
per spawn path x binding, plus two GNU-correct controls).

Generated with [Devin](https://devin.ai)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…te stderr (Fixes #3566)

The Windows prefix-concurrent driver (execute_external_prefix_concurrently
caller) assigned the prefix's stdout to the next stage's input only in
the merged and the stderr-empty arms; a prefix whose last member wrote
any stderr with fd 2 not merged relayed the diagnostic and handed the
shell-side stages an empty input. GNU execute_cmd.c:2620 execute_pipeline
gives each member an fd 1 pipe independent of its fd 2, so the payload
is unconditional.

Pin: two more cells in tests/issue3402_pipeline_stage_stderr_fd_table.rs
(fail-first 18/2 -> 20/0).

Generated with [Devin](https://devin.ai)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@caomengxuan666

Copy link
Copy Markdown
Member Author

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

head: 3995c71 base(merge-base): 8b48c16 文件: 2 个 +404/-65
关联 issue: #3402(状态: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(唯一的源码文件,另有一个新增钉)。

背景提示(供续作参考):

  • 本 PR 与清单内 fix(executor): keep pipelines concurrent with fd-2 redirects (Refs #3516) #3509 打的是同一个文件同一片区域(pipeline_exec.rs 的 fd-2 准入/中继),两者互相也会冲突;定序时建议先合一方、另一方按合并形重做,不要各自消解后平行落。
  • 机制方向(成员 fd 2 走 fd 表、ConcurrentPipelineStderr::wire() 统一接线、末成员经 write_default_stderr 按成员序中继)与 GNU 一致(execute_cmd.c:2620 execute_pipeline() 每个成员 fork 进 OS 管线并继承 shell 当时的 fd 2;redir.c:237 do_redirections() 外层重定向在成员内生效),但需在现尖上重跑 18 格钉与 fail-first。

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

未跑/VOID 的腿:

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

@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT】
PR #3562 ↔ #3509 定序裁决 — 建议:#3509 先合(已落地,顺序正确);#3562 以 rebase 续作推进,两机制互补不互替

head: 3995c71 mergeable=CONFLICTING/DIRTY;关联 issue #3402(open,我核过的时间:本地 2026-11-18)

两者修的不是同一不变量:

GNU 语义(third_party/bash @9c465866 复核):execute_cmd.c:2620 execute_pipeline 给每个成员 fork 管道、继承 shell 当时的 fd 2;成员自身的 2>... 由子进程内 do_redirections 再覆盖(execute_disk_command 子路径 execute_cmd.c:5870 do_piping → :5884 do_redirections(RX_ACTIVE))。ambient 绑定与成员重定向是两层正交语义——缺一不可,故两 PR 互补而非竞争。

完整性与定序:#3509 范围窄但修的是挂死(严重度高),先合正确;#3562 覆盖 5 条 spawn 路径的 ambient 面,范围更广、属正确性误路由,issue #3402 未关,仍需要。定序事实已成立:#3509(3d8c9ff8)与 #3860(9d00b569,ANCESTOR-OK,已把本 PR 内的 #3566 input = prefix_output 修复落地,issue #3566 现为 CLOSED)均在本 PR 基底之后。

#3562 rebase 续作要点(供队长/续作,非本轮判词):

裁决:#3562 不废弃、保持 draft;定序 = #3509(已合)→ #3860(已合)→ #3562 rebase 续作。本评论不合并、不关闭任何 PR。

未跑/VOID 的腿:无(纯裁决评论,未动代码;机制对照引自 third_party/bash 源码与 gh/git 只读核验)。

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.
@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT】PR #3562 第2轮 — 建议:PASS
head: da605a1(本轮续作 merge 提交;原 head 3995c71 已被其第一父覆盖,远端已确认更新)base(merge-base): 8b48c16 文件: 2 个 +404/-65(pipeline_exec.rs + 新增钉文件)
关联 issue: #3402(状态:open,核于本地时间 2026-11-18)

机制核查:

腿(逐项):

  • 钉自跑:cargo test --test issue3402_pipeline_stage_stderr_fd_table → test result: ok. 20 passed; 0 failed
  • fail-first:base 8b48c16 + 原样钉文件 → 3 passed; 17 failed。红名 = {concurrent_comsub_group_devnull, concurrent_comsub_last_stage_devnull, concurrent_exec_err_file, concurrent_group_closed_fd2, concurrent_group_err_file, prefix_stdout_survives_last_prefix_member_stderr, prefix_stdout_survives_silenced_prefix_stderr, prefix_two_shell_stages_closed_fd2, prefix_two_shell_stages_err_file, sandwich_closed_fd2, sandwich_function_middle_err_file, sandwich_function_tail_devnull, shell_writer_consumer_closed_fd2, shell_writer_consumer_devnull, shell_writer_consumer_err_file, streaming_tail_devnull, streaming_tail_err_file};绿名 = {concurrent_merge_into_capture, control_last_stage_redirect_does_not_silence_first_stage, control_unredirected_sandwich_reaches_stderr}(3 个对照/已工作形状)。与 PR 声称方向一致——钉确实咬住未修复面。
  • lib 双边:head 失败名集 {api::consumer_tests::issue2084_session_end_restores_host_process_state} / base 失败名集 {同} / 差集 {}(两侧各 1376-1380 passed、1 failed,为已知 host-env 记账问题,与本 PR 无关)
  • -D warnings:cargo check --locked --all-targets(RUSTFLAGS=-D warnings)→ Finished,0 警告
  • 卫生:cargo fmt --check 仓库级在 Windows 命令行长度下不可跑(既有基线限制);rustfmt --edition 2021 --check src/executor/pipeline_exec.rs 目标文件干净;marker-lint OK(118 registry consts, 269 allowlisted sites);check-utf8-boundary-hygiene scanned src → clean
  • cli_tests:head 477 passed; 6 failed; 3 ignored。6 红 = {c_command_substitution_captures_type_t_output_without_leak, compat_issue_regressions::background_redirected_job_releases_stdout_pipe_at_exit, examples::script_aliasconv_example_converts_aliases, extensionless_shell_script_on_path_runs_without_external_sh, fd_redirects::c_external_command_reports_write_error_for_closed_stdout, login_flag_does_not_change_windows_startup_behavior};同一 stem 在 master 5379741 上逐名复现同 6 红(断言 diff 一致)→ 全部基线/环境面,非本 PR 账
  • goldens(marker_leak_golden):head 17 passed; 3 failed = {compgen_carries_no_markers, dap_json_channel_carries_no_markers, diagnostics_carries_no_markers};master 5379741 同 3 红逐名一致 → 基线(marker/DAP/诊断子系统,与 pipeline 无关)
  • CI:新 head da605a1 的 CI/niu-canary 刚入队(queued,未出结果);旧 head 3995c71 CI 红 = {Rust tests, Rust tests (macOS), GNU regression goldens and canaries} 的 "Run Rust library tests" 步,失败名 = api::consumer_tests::issue2875_input_procsub_child_runs_as_rubash_shell(已知基线 issue2875)+ api::consumer_tests::issue2859_jobs_face_stopped_job_counts(master a1f9718 自身 CI 同样大面积红,含该面,判基线待新 head CI 复核);niu-canary 旧 head 绿
  • GNU 对照:WSL /usr/local/bin/bash = GNU bash 5.3.20(1)-release;脚本文件对照 { ls /nonexistent_xyz_probe | cat; } 2>/dev/null、{ ls ... | cat | cat; } 2>err.txt 等组重定向形状,GNU 与本 PR 逐字节一致(N/N);Windows 并发路径 Linux 不可达,语义参照以 GNU C 源 + WSL 可观察行为为准

F 点:无

续作记录:

  • da605a1 merge master 5379741 into fix/3402-pipeline-stage-stderr-fd-table,解 8 处冲突(取 master 精化 + 接入 wire());新 head: da605a1

未跑/VOID 的腿:

  • 新 head CI 结果(queued,出结果后需按名复核归因);cargo fmt --check 仓库级(Windows 命令行长度限制,以逐文件 rustfmt 替代)

@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-BATCH-SUMMARY】l3 波次完成(Windows 面两条收尾)

@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 18, 2026 08:29
@caomengxuan666
caomengxuan666 merged commit 00e264f into master Nov 18, 2026
10 of 12 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/3402-pipeline-stage-stderr-fd-table branch November 18, 2026 08:29
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.

[bug] pipeline stage stderr bypasses the fd table on the Windows concurrent path (Windows face of #3308)

1 participant