Skip to content

type: interleave per-operand stdout/stderr in merged streams (Refs #2699) - #3124

Merged
caomengxuan666 merged 5 commits into
masterfrom
fix/I3-wave1
Nov 10, 2026
Merged

caomengxuan666 merged 5 commits into
masterfrom
fix/I3-wave1

Conversation

@caomengxuan666

@caomengxuan666 caomengxuan666 commented Nov 8, 2026 •

Copy link
Copy Markdown
Member

概要

Refs #2699

多操作数内建在合并流(2>&1、同一文件、同一捕获)里的 stdout/stderr 交错丢失:共享缓冲输出路径把两流分别收进两个 Vec、在命令结束时整段先发 stdout 再发 stderr。GNU 按操作数逐个发出(builtins/type.def describe_command 每名一次、诊断走 unbuffered 的 builtin_error),故 type echo nosuchcmd123 ls 2>&1 的诊断行应落在两个 describe 行之间(GNU bash 5.3.20 oracle 已验)。

修法(机制层,非逐内建打补丁):给共享缓冲路径增加有序 chunk 通道——两个流的 Write 句柄把每次写按序记入同一日志(fd 标签 + 字节),路由层在一次重定向应用内按记录序逐 chunk 写出;既有 pair 路径退化为 2-chunk 情形、行为不变。type / command -v/-V 改走有序通道(type 的 Diag 改逐名 flush),comsub 的 pair 调用点保持原签名与原语义。

本 PR 删除了什么

无删除。本 PR 新增有序 chunk 通道(trap_stack_builtins.rs / redirection.rs 路由推广)并把 type/command describe 入口切换过去;declare -p 与 alias 的同机制转换因其入口文件正被 #2968(④ Phase 4 草稿 PR)改写,按面核停手、另立残余单待其合入后跟进(见 REPORT)。

验证状态

队长复核 FAIL(2026-11-09 ~05:47 UTC):头 eefafc4 不编译,不得合入。

  • 根因:src/executor/type_builtin.rs execute_command_describe_redirected 的 fallback 分支引用已不存在的局部缓冲 stdout / stderr(E0425 ×4,:28/:33/:40)。基底该函数开头有 let mut stdout = Vec::new(); let mut stderr = Vec::new();,修法提交改成 OrderedOutputLog 时漏了 fallback 分支仍需的两个 Vec 声明(设计笔记原文明示 fallback 保持 Vec + pair flush 不变)。最小修复:fallback 的 let action 块前恢复两行声明;修后重跑全部头腿。
  • 腿表(全量日志 ~/workspace/fix-I3/verify-all.log,129,767 字节,2026-11-09 05:46:59Z):头构建 rc=101;钉头未跑 rc=101;lib 头未跑 rc=101;邻茎 6 茎未跑 rc=101;-D warnings rc=101(同源编译错);cargo fmt --check rc=0;marker lint rc=0(117 registry consts,265 allowlisted sites);lib 基底 1205 过 / 1 红 / 4 忽略——红仅 api::consumer_tests::issue2875_input_procsub_child_runs_as_rubash_shell(基底既有红集,待头编译后作双边对照);GNU 探针与残余探针阻塞(无头二进制)。
  • CI 印证:头 eefafc4 的 CI 9 fail / 1 pass(仅 API ledger tripwire)/ 1 skipping;此前 CI 绿是钉先行头 3f68def 的状态,不适用于修法头。
  • 基底 fail-first(2026-11-09 ~01:49 UTC,第四次排队终获槽位,BUILD-RC=0):钉 7 格 2 绿 / 5 红,红格恰为 5 个交错格(全量日志 failfirst.log)——此结论维持有效。

净行数(vs 基底 88047f5):4 files changed, +432/−8。

…and builtins

Refs #2699

GNU builtins/type.def describe_command runs once per name; in a merged
stream the not-found diagnostic for operand N precedes the describe
line for operand N+1 (GNU bash 5.3.20 oracle). The shared buffered
path emits all stdout before any stderr, losing that order. Pin cells:
type / command -V merged interleave (middle-miss, first-miss,
two-miss), merged-to-file order, plus separate-stream and comsub
controls. Fail-first run against the base build is pending the build
slot; expectations were taken from the GNU oracle directly.
#2699)

GNU builtins/type.def:175-187 describes one name at a time and reports
a miss through builtin_error (builtins/common.c:98-110), which writes
stderr unbuffered, so in a merged stream the diagnostic for operand N
sits between the describe lines for N-1 and N+1. rubash buffered the
two streams into separate Vecs and flushed all of stdout before any
stderr.

Mechanism fix (not per-builtin patching): add an ordered chunk channel
to the shared buffered-output path — both streams' Write handles log
each write (fd tag + bytes) into one log in production order, and the
route walks the log once under a single redirect application. type /
command -v/-V switch to the channel (type's Diag flushes per operand);
the pair path is untouched. The fmt-only reflow of the pin file
(3f68def) is folded in so the tree stays cargo-fmt clean.
@caomengxuan666 caomengxuan666 changed the title Refs #2699 fix(type): interleave per-operand stdout/stderr in merged streams (Refs #2699) Nov 9, 2026
@caomengxuan666

Copy link
Copy Markdown
Member Author

收官提交已推送:6e6a524c

本 PR 的关联单号为 #2699。

修法摘要:在 src/executor/type_builtin.rs 的 execute_command_describe_redirected fallback 分支之前,恢复两行缓冲声明 let mut stdout: Vec<u8> = Vec::new(); 与 let mut stderr: Vec<u8> = Vec::new();(单文件 +2/−0)。该分支保持 Vec + pair flush 不变,describe 主路径继续走有序 chunk 通道。

批跑 #3 B10 验证数字(2026-11-10 02:08–02:14 UTC,日志 batch-legs-3/logs/b10-i3-driver.out):

  • 头钉 issue2699_builtin_output_interleaving:7/7
  • lib 头:1206 passed / 0 failed / 4 ignored,失败名集空
  • 邻茎六茎全绿:issue1081 1/0、issue1047 4/0、issue1172 3/0、issue1648 4/0、issue1080 2/0、a3_r58b 2/0
  • RUSTFLAGS="-D warnings":rc=0
  • cargo fmt --check:rc=0
  • GNU 探针:rc 一致(merged-stream 形态 byte-SAME,argv[0] 归一化);残差探针 declare 一项头与 GNU 均为 rc=1,stderr 仅二进制路径一词之差

以上为推送记录,合入与关单口径留队长复核。

@caomengxuan666 caomengxuan666 changed the title fix(type): interleave per-operand stdout/stderr in merged streams (Refs #2699) type: interleave per-operand stdout/stderr in merged streams (Refs #2699) Nov 10, 2026
@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 10, 2026 04:01
@caomengxuan666
caomengxuan666 merged commit 87e842b into master Nov 10, 2026
19 of 20 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