Skip to content

exec: bind every heredoc/here-string entry at its redirect-list position (Refs #3578) - #3603

Closed
caomengxuan666 wants to merge 1 commit into
masterfrom
fix/3578-exec-multi-heredoc
Closed

caomengxuan666 wants to merge 1 commit into
masterfrom
fix/3578-exec-multi-heredoc

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Summary

GNU applies each redirect in do_redirections' list order — here_document_to_fd (redir.c:423) materializes the body and dup2s it onto the redirector at redir.c:1065-1072, and a redirect-only exec keeps those binds persistent (builtins/exec.def). rubash pushed each heredoc into both cmd.redirects (list order) and cmd.heredoc_redirects (body store), but the redirect-only exec walk skipped the heredoc kinds entirely and rescued only the LAST body via a tail lookup — exec 14<<A 15<<B bound fd 15 and left fd 14 a bad descriptor.

Pair the two parallel stores in list order and bind each entry where the walk reaches it: {var} heredocs still consume their twin so the fd_var loop owns their bind, an unnumbered here-string keeps its fd-0 path, and any unpaired leftover still binds at the tail. Verified byte-identical against vendored GNU bash 5.3.20; 4 new pins plus ~150 neighboring heredoc/fd/exec regressions green.

Refs #3578

…ion (rubash#3578)

GNU applies each redirect in do_redirections' list order —
here_document_to_fd (redir.c:423) materializes the body and dup2s it
onto the redirector at redir.c:1065-1072, and a redirect-only exec
keeps those binds persistent (builtins/exec.def). rubash pushed each
heredoc into both cmd.redirects (list order) and
cmd.heredoc_redirects (body store), but the redirect-only exec walk
skipped the heredoc kinds entirely and rescued only the LAST body via
exec_heredoc_fd_input's .rev().find() — 'exec 14<<A 15<<B' bound fd 15
and left fd 14 a bad descriptor.

Pair the two parallel stores in list order and bind each entry where
the walk reaches it: {var} heredocs still consume their twin so the
fd_var loop (vredir1.sub) owns their bind, an unnumbered here-string
keeps its fd-0 path on the here_string mirror, and any unpaired
leftover still binds at the tail. Verified byte-identical against
vendored GNU bash 5.3.20 on the two-heredoc, mixed here-string, and
persistence probes; 4 new pins plus ~150 neighboring heredoc/fd/exec
regressions stay green.

Fixes #3578

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT】
PR #3603 第1轮 — 建议:PASS
head: 4b589f1 base(merge-base): 96802ca 文件: 2 个 +140/-63
关联 issue: #3578(状态:open,我核过的时间:2026-11-15 本地)

机制核查:

  • GNU redir.c:1065-1072(do_redirections 逐条 walk 内 here_document_to_fd,redir.c:423)+ :1120 dup2 到各自 redirector:每条 heredoc/here-string 在自己的列表位置 materialize 并绑定。本 PR 把 redirects 与 heredoc_redirects 两个平行 store 用 heredoc_twins 迭代器按序配对,在 walk 到达该条目处就地绑定;{var}<< 消耗 twin 由 fd_var 回路绑定;无编号 here-string 走 fd-0 旧路径;未配对残余在尾部绑定。删除旧 .rev().find() 尾查实现(-63 行)。就地绑定与 GNU do_redirections 的交错结构一致。
  • 无关改动:无。

腿:

  • 钉自跑(head):issue3578_exec_multi_heredoc 4 passed / 0 failed。
  • fail-first(base 96802ca):同 stem 2 passed / 2 failed;红名 = {issue_script_exec_binds_every_numbered_heredoc, issue_script_exec_binds_mixed_heredoc_here_string}——base 只绑末条(line-15 / w),与 PR 声称缺陷一致。
  • 邻面:issue3195_heredoc_fd_limit 18/18 全绿(含 failed_exec_heredoc_undoes_earlier_binds——就地绑定下 exec 失败回滚仍由既有 undo 路径兜住)。
  • 手工形状(head rubash vs wsl bash 5.3.20 逐字节一致):
  • lib 双边:以 CI head 腿代——红集各仅 {issue2875}(基线),差集 ∅。
  • 卫生:rustfmt --check 2 文件 OK。
  • CI:红腿 3 个,红名各仅 issue2875(基线);其余全绿。
  • GNU 对照:wsl bash 5.3.20(1)-release,脚本 target/p-3578{a..f}.sh:
    • a exec 14<<A 15<<B → line-14\nline-15 ✓
    • b exec 7<<Q 8<<<'w' → qbody\nw ✓
    • c 无编号 fd0 + exec 3<<<"hs-$((1+1))" → solo-body\nhs-2 ✓
    • d 持久化 exec 9<<E → marker\nvia-exec ✓

与 #3580 的只读对比(队长裁断用,两者均未动):

F 点:无

未跑/VOID 的腿:本地全量 lib 与 -D warnings 未跑(以 CI head 腿 + 编译/钉跑通代替判读)。

@caomengxuan666

Copy link
Copy Markdown
Member Author

【队长终裁】PASS —— #3578 存活者裁断:本单(#3603)存活,#3580 随后以 superseded 关单

核过审计报告(6887036738)+ CI 全表 + 与 #3580 的只读对比。钉 4/4,fail-first 2/2(红 = issue 形状:base 只绑末条);邻面 issue3195_heredoc_fd_limit 18/18;CI 三红红名全为 issue2875 基线。存活裁断理由:#3603 的 walk 内就地绑定(heredoc_twins 配对迭代器)与 GNU do_redirections 的交错结构一致——扩展副作用顺序与失败位置逐位对齐;#3580 的 walk 外批量绑定在纯 heredoc 列表上可观察等价,但 materialize 时机移出 walk,与 GNU 的交错扩展/失败位置结构有偏离(exec 3<$(c) 4<<HD 类形状)。机制正确性优先于钉数。#3580 钉面更宽(7 例:三 heredoc、同 fd 后胜、{var}、组对照)是事实,覆盖以合并形重验保全:合入轮在 #3603 合并形上跑 #3580 的钉 stem(issue3578_exec_multi_heredoc,7 例)——7/7 则 #3580 以 superseded 关单;有红则红格另立跟进,不拦 #3603 合入。合入正文 Refs #3578(NOT Fixes——#3654/#3655 仍挂 #3578,#3578 保持 OPEN)。合入轮补跑 lib 双边 + RUSTFLAGS="-D warnings" 全量(agent 未跑)+ 上述 #3580 钉 stem 重验。

caomengxuan666 added a commit that referenced this pull request Nov 15, 2026
…ion (Refs #3578) (#3752)

Synthesis of PR #3603's mechanism and PR #3580's wider pin grid for
issue #3578 (captain's survivor ruling: #3603's in-walk pairing wins
on mechanism fidelity; #3580's extra pin cells re-verified on the
merged shape).

GNU applies each redirect in do_redirections' list order —
here_document_to_fd (redir.c:423) materializes the body and dup2s it
onto the redirector at redir.c:1065-1072/:1120, and a redirect-only
exec keeps those binds persistent (builtins/exec.def). The parser
mirrors every heredoc / numbered here-string into both cmd.redirects
(its list position) and cmd.heredoc_redirects (its body store), but
the redirect-only exec walk skipped the heredoc kinds entirely and
the tail lookup bound only the LAST body — `exec 14<<A 15<<B` left
fd 14 unbound.

Pair the two parallel stores in list order (heredoc_twins): {var}
entries consume their twin so the fd_var heredoc loop keeps owning
their bind (vredir1.sub), an unnumbered here-string keeps its fd-0
here_string path, and any unpaired leftover still binds at the tail.
The #3195 rlimit gate still aborts the whole walk before any bind.
Expansion goes through the canonical expand_heredoc_redirect_text
ladder — the same bytes execute_dynamic_fd_var_heredoc binds —
replacing the deleted exec_heredoc_fd_input tail lookup.

Pins (tests/issue3578_exec_multi_heredoc.rs, 12 cells): #3603's four
plus #3580's union-unique cells (read -u two-heredoc seed, three
heredocs, same-fd last-wins, fd-0+numbered, {var}+numbered,
brace-group control) plus an interleave pin for the at-position bind
itself (exec <<A 3<&0). Every expectation byte-verified against WSL
GNU bash 5.3.x script-file probes.

Refs #3578

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-FIX】#3578 综合收编说明

本单机制已按【队长终裁】落地到 master 现状:PR #3752(squash b69e175)完整移植了本单的 walk 内按位 heredoc 绑定机制(heredoc_twins 配对迭代器,{var}<< 消耗孪生、无编号 <<< 走 here_string fd-0 路径、尾部残余兜底),并按 master 现状重接线(rlimit 门 rubash#3195、fd_var heredoc 独立循环位置不变),展开统一走 canonical expand_heredoc_redirect_text。

钉面为两单并集 12 格(本单 4 格 + #3580 独有 6 格 + 综合新增 1 格 exec <<A 3<&0 按位绑定钉),每格经 WSL GNU bash 5.3.x script-file 探针字节级复验,本地 12/12 绿;CI 红名均为既有基线(issue2875 / Session::cwd api-ledger 缺口),与本 diff 无关。

处置建议(留队长):本单与 #3580 均可按终裁以 superseded 关单;#3578 保持 OPEN(#3654/#3655 仍挂)。

@caomengxuan666

Copy link
Copy Markdown
Member Author

队长关单:superseded by #3752。

#3752(用户自合,merge commit b69e175a,Refs #3578)已收编本单:合入树内有 heredoc_twins 按位绑定机制(diff 4 处),exec_heredoc_fd_input 已删;钉面 tests/issue3578_exec_multi_heredoc.rs 12 格为并集(含本单 4 格 + #3580 的 7 格 + 1 格综合新增)。#3578 本体仍 OPEN(#3654/#3655 仍挂其上),本单不再单独合入。

合入后核实:merge-commit CI run 43777499616 三 lib 腿唯一红皆 issue2875 基线,canary run 43777499821 只红已知 ledger 漂移(MISSING Session::cwd)。一点保留:钉 stem 本轮 CI 未跑(issue2875 红致 integration stems 步 skipped,掩盖口径同 #3750)——12/12 现为作者本地证据,待 #3750 合入解除掩盖后,队长在尖上重跑 issue3578 stem 复核(记入 #3752 合后核验)。

#3729/#3731 解锁序首步(#3603 合入)由 #3752 承接;次步仍为 #3688 合入 → 队长重扫确认最近 ≥1000 行后派工。

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