Skip to content

fix(redir): unify RX_UNDOABLE move verdict across respawn payload faces and async compound roots (Fixes #4046) - #4251

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/4046-respawn-compound-rx-undoable
Nov 28, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/4046-respawn-compound-rx-undoable

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Fixes #4046.

GNU C Specification

  • third_party/bash/execute_cmd.c:1759-1772 (execute_in_subshell): for any forked async command (cmd &, simple or compound) or subshell head (( ... ) redirs), the command's own command->redirects run with RX_ACTIVE only (no RX_UNDOABLE), so redir.c:1171-1175 never runs add_undo_redirect and emits only the per-redirection N: Bad file descriptor line (1 line).
  • third_party/bash/execute_cmd.c:854 / 4268 / 5606 (execute_command_internal): commands executing inside a forked child body — ( { true; } ... ) &, { { true; } ...; } &, <({ true; } ...), >({ true; } ...) — apply redirects with RX_ACTIVE | RX_UNDOABLE, emitting both redirection error: cannot duplicate fd: Bad file descriptor and line N: 10: Bad file descriptor (2 lines).

Root Cause

  1. In src/executor/command_input_scope.rs, compound_dup_bad_fd checked self.respawn_payload_face.get() == 0 while src/executor/redirection.rs (output_walk_is_undoable) checked respawn_payload_face.get() != 1. That split suppressed the first diagnostic line for compound commands inside face 2 (( ... ) &) and face 3 (<(...) / >(...)).
  2. src/executor/compound_exec/background.rs stamped "compound" which src/executor/init.rs mapped to face 0, so an outer async compound command's own redirects ({ true; } 8>/dev/null 8>&10- &) ran as undoable (2 lines) instead of GNU's RX_ACTIVE-only pass (1 line).
  3. (Note: the earlier fd-10/12 carrier leak in procsub respawn children from #4045 is already resolved on master after #4050 merged; cat <(ls -1 /proc/$$/fd) now matches GNU 5.3.20 0 1 2 63 255.)

Summary of Changes

  • src/executor/redirection.rs & src/executor/command_input_scope.rs:
    • Extracted shared Executor::move_walk_is_undoable(&self, cmd: &CommandNode) -> bool used by output_walk_is_undoable, compound_dup_bad_fd, and with_command_input_redirects_scoped.
    • Returns false for pipeline/subshell-head/background nodes and respawn faces 1 (async simple) / 4 (async compound root); returns true for face 0 (main shell), face 2 (async subshell body), and face 3 (procsub body).
    • Consumes one-shot face 4 in with_command_input_redirects_inner after the root's own redirects apply and before the body executes, so { true; } 8>&10- & emits 1 line while { { true; } 8>&10-; } & emits 2 lines.
  • src/executor/compound_exec/background.rs, src/executor/init.rs, src/executor/ast_exec.rs, src/executor/mod.rs, src/executor/markers.rs:
    • Maps "compound" to face 4u8 (stamped only when unconsumed own-redirects replay in the child) and restricts ast_exec.rs nofork arming to matches!(payload_face, 1..=3).
  • tests/issues_3900_4199/issue4028_move_fd10_bad_fd_diag.rs:
    • Added 3 regression test functions (8 shapes, inside the existing consolidated crate — no new top-level tests/issue*.rs binary per #4210/#4219): async simple/group roots (1 line), nested async group / subshell-body group / subshell-body if (2 lines), and input/output procsub bodies (2 lines).

What this PR deletes

  • Deletes the duplicated inline undoable_walk predicates in command_input_scope.rs and redirection.rs (replaced by shared move_walk_is_undoable).

Verification

  • Oracle: WSL GNU Bash 5.3.20 (/usr/local/bin/bash, script files) — 27/28 shapes byte-identical (sole excluded shape is pre-existing cat <(if...) parser line-3 numbering quirk, separate owner).
  • Windows: cargo test --test issues_3900_4199 issue4028 — 8/8 passed.
  • WSL Linux: cargo test --test issues_3900_4199 issue4028 — 8/8 passed; issue3932 — 38/38 passed; full issues_3900_4199 sweep — 677/682 passed (the 5 failures are verified pre-existing master @ 9f4fc4894 behavior).
  • Hygiene: scripts/check-api-ledger.py (298 symbols), scripts/check-marker-literals.py (117 consts), and scripts/check-rustfmt.py (225 targets) all passed.

@caomengxuan666

Copy link
Copy Markdown
Member Author

CAPTAIN-VERIFY(只读复核):达合入门(只读,待运行时)。共享谓词 move_walk_is_undoable + 一次性 face 4 正对 #4046 双根因,3 钉 8 形双向 fail-first;census 9 名零新名、goldens #4038 面。待补运行时:作者 oracle 为 WSL 自建 5.3.20、不作准,队长以云端真 GNU bash 5.3.20 复核关键形,过后终裁。

@caomengxuan666

Copy link
Copy Markdown
Member Author

CAPTAIN-VERIFY(devin-mac 运行时复验):语义面全证、达合入门附一枚钉的平台稳健化。

已证面:云端真 GNU bash 5.3.20 oracle 14/14 逐字全合(新 face-4 async group 根、r1/r3/c5 全合);双向 fail-first 均成立;issue3932 38/38、issue4028 7/8(唯一红见下)。

唯一未闭项——新钉 procsub_body_walks_stay_undoable 在 macOS 确定性 6/6 红:手动实跑证明两行诊断实际产出、move 判据正确,红只倒在输出 procsub 形——procsub body 输出异步落在进程退出之后、测试捕获不到。这是先存的 macOS 输出 procsub 交付竞态被新钉首次照亮(非本 PR 判据逻辑引入),队长已另立 #4252 跟踪该产品面。

裁决:本 PR 代码面可合,但不带一枚在受支持平台确定性红的新钉入主干(会成为新基线红)。请作者把该钉的输出捕获改成平台稳健形(如经临时文件重定向收齐两行诊断再断言,判据断言本身不动),推新 head 后队长按证据沿用直接合入、无需整轮重验。

@caomengxuan666
caomengxuan666 force-pushed the fix/4046-respawn-compound-rx-undoable branch from cc75a6f to bcc57ed Compare November 28, 2026 01:43
@caomengxuan666

Copy link
Copy Markdown
Member Author

Rebased onto master (55b0aebb6) as bcc57ede5 and hardened procsub_body_walks_stay_undoable per the CAPTAIN-VERIFY review:

  • Output-procsub pin hardening (tests/issues_3900_4199/issue4028_move_fd10_bad_fd_diag.rs): redirected the async >(...) child's stderr to a temp file (out_procsub.err), wrote a sentinel file (out_procsub.done) after { true; } 8>/dev/null 8>&10-, and polled for the sentinel (up to 5s) before asserting out_procsub.err == expected(1). This removes the parent-exit vs async output-procsub capture race (tracked separately in [macOS] procsub body output can land after process exit and be lost to capture #4252) while keeping the exact same RX_UNDOABLE diagnostic assertion.
  • Verification:
    • WSL GNU Bash 5.3.20 (/usr/local/bin/bash): hardened output-procsub probe matches expected(1) byte-for-byte.
    • WSL Linux: RUSTFLAGS="-D warnings" cargo check --lib --locked clean; cargo test --test issues_3900_4199 issue4028 8/8 passed.
    • Windows: cargo test --test issues_3900_4199 issue4028 8/8 passed; python scripts/check-rustfmt.py ok (225 targets).

@caomengxuan666
caomengxuan666 merged commit 08f8fbf into master Nov 28, 2026
11 of 13 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/4046-respawn-compound-rx-undoable branch November 28, 2026 02:38
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.

respawn 孩子中 procsub plumbing 占用 fd 致 move 误判成功(生产者 fd 布局)

1 participant