Skip to content

executor: transport CMD_IGNORE_RETURN through coproc/async respawns and comsub - #3743

Merged
caomengxuan666 merged 3 commits into
masterfrom
devin/coproc-errexit-invert
Nov 16, 2026
Merged

caomengxuan666 merged 3 commits into
masterfrom
devin/coproc-errexit-invert

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Summary

Two missing halves of GNU's CMD_IGNORE_RETURN model, root-caused off exec16.sub (! coproc CP { set -e; false; echo reached; } never printed its marker):

  1. coproc / trailing & respawn — GNU runs an exempt coproc or async body in a real fork that inherits the node's flag (execute_cmd.c:2546 execute_coproc → execute_in_subshell, fork at execute_cmd.c:1576). Rubash respawns those bodies in a fresh rubash -c process whose suppress_errexit seeded 0. A __RUBASH_SUPPRESS_ERREXIT env stamp now brackets the respawn (env entry → init.rs seeds the child). Procsub children are deliberately NOT stamped — subst.c:6362 builds them without the flag path (! cat < <(set -e;false;echo x) prints nothing under GNU 5.3.20).

  2. comsub_ignore_return counter — ported from execute_cmd.c:252: raised around expand_words of a flagged simple command (execute_cmd.c:4616), a flagged [[ ]]'s operand expansion (execute_cmd.c:4012/:4060/:4067), and rubash's pure-assignment RHS loop (execute_empty_words_command — it bypasses expand_command_words, so ! x=$(...) never saw the bracket). While held, builtins/evalstring.c:496 stamps CMD_IGNORE_RETURN on every command a $( ) body parses. The comsub boundary now clears suppress_errexit only when the counter is zero; the subst.c:7023-7029 errexit env / errexit_ignore_frame clears are unchanged.

Verified byte-identical vs GNU bash 5.3.20 across: invert/if/while/until coproc, async &, ! x=$(…), if z=$(…), ! eval 'w=$(…)', ! { v=$(…) }, function-body assignment under ! f, plus plain coproc / plain comsub / procsub staying dead. exec16.sub byte-identical; 4 new pin tests in tests/issue3605_errexit_suppression_transport.rs.

Refs #3605

…nd comsub

exec16.sub: `! coproc CP { set -e; false; echo reached; }` never
printed `reached` — GNU runs the flagged coproc body in a real fork
where the node's CMD_IGNORE_RETURN flag carries by inheritance
(execute_cmd.c:2546 execute_coproc -> execute_in_subshell,
execute_cmd.c:1576's subshell fork), but rubash respawns the body in
a fresh `rubash -c` process that seeds suppress_errexit = 0. The same
leak applied to trailing `&` async wrappers
(execute_background_ast_command).

Fix 1: a `__RUBASH_SUPPRESS_ERREXIT` env stamp on the respawn env map
brackets the boundary — init.rs consumes it into the child Executor's
suppress_errexit = 1. Procsub spawns are deliberately NOT stamped:
subst.c:6362 builds procsub children without the flag path, verified
(`! cat < <(set -e;false;echo x)` prints nothing under GNU 5.3.20).

Fix 2: GNU's comsub_ignore_return counter (execute_cmd.c:252) was
missing entirely. It is raised around expand_words of a
CMD_IGNORE_RETURN-flagged simple command (execute_cmd.c:4616) and a
flagged `[[ ]]`'s operands (execute_cmd.c:4012/:4060/:4067), and
builtins/evalstring.c:496 stamps CMD_IGNORE_RETURN on every command
a comsub's parse_and_execute yields while the counter is held — so
`! x=$(set -e; false; echo cs)` assigns cs, `if z=$(...)` assigns
ifz, `! f` exempts the function body's `x=$(...)`. Ported as
Executor.comsub_ignore_return, raised around expand_command_words
(command_execute), the pure-assignment RHS loop
(execute_empty_words_command — bypasses expand_command_words), and
expand_conditional_word; the comsub boundary now clears
suppress_errexit only when the counter is zero (subst.c:7023-7029
errexit env/errexit_ignore_frame clears unchanged).

Verified byte-identical vs GNU bash 5.3.20 across invert/if/while/
until coproc, async `&`, eval/group/function-body comsubs, plain
coproc/comsub/procsub non-exemption; exec16.sub byte-identical.

Refs #3605

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

Copy link
Copy Markdown
Member Author

队长 FAIL:自家面测试红。CI run 43748436648 上 executor::markers::tests::env_namespace_census_is_complete 在 Rust tests、macOS、goldens 三 job 全红(另只红基线 issue2875)。根因已定位:本 PR 新增 env 命名空间 key __RUBASH_SUPPRESS_ERREXIT(SUPPRESS_ERREXIT_TRANSPORT,mod.rs),但未在 markers.rs 的 census 登记——census 枚举全部 __RUBASH_* key,要求每 key 有登记,缺登即红。修法 = 在 census 补登该 key(同族先例见 #3653 的 attribute-transport keys);产品 hunk 与其余红暂不判。

The env_namespace_census_is_complete test scans src/ for __RUBASH_* tokens
and requires every one to be censused; SUPPRESS_ERREXIT_TRANSPORT added
the key without an EXACT entry, turning the census test red on CI.

Refs #3605

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

Copy link
Copy Markdown
Member Author

确认。census 漏登 __RUBASH_SUPPRESS_ERREXIT,已在 c48b8a8 补登 EXACT 条目,env_namespace_census_is_complete 本地转绿。

@caomengxuan666

Copy link
Copy Markdown
Member Author

队长跟进:新头 c48b8a8 的 census 红已解除,FAIL 撤销。

本 PR 转入 Windows agent Wave 2:钉 fail-first + 全绿、邻居、lib 双边、-D warnings、守卫扫描诸腿仍欠,腿齐后队长复核。

@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT】PR #3743 第2轮 — 建议:PASS
head: 2bfb9b6 base(merge-base): e3a7b7b 文件: 9 个 +239/-5
关联 issue: #3605(状态:open,伞目录 issue,本轮不关单;我核过的时间:2026-11-16 本地)

机制核查:

  • 机制成立。GNU 侧:comsub_ignore_return 是 execute_cmd.c:252 的全局计数;带 CMD_IGNORE_RETURN 的简单命令在 expand_words 期间raise(execute_cmd.c:4616),由此展开出的 $( ) 在 parse_and_execute 循环里对每条命令盖 CMD_IGNORE_RETURN(builtins/evalstring.c:496);coproc / trailing & 体走 execute_coproc→execute_in_subshell(execute_cmd.c:2546)/ 异步 fork(:1576),节点标志随 fork 继承。本 PR 用 comsub_ignore_return 计数(mod.rs)+ comsub 边界只在计数为 0 时才清 suppress_errexit(command_substitution.rs:1851-1862、:2453-2462)+ __RUBASH_SUPPRESS_ERREXIT 运输键给两类 respawn 子进程播种(compound_exec.rs:1571/:5581、init.rs:949-961),并明确注释 procsub 不带戳(subst.c:6362)。四处 raise 点(command_execute.rs:362-378、command_prepare.rs:742-756 纯赋值 RHS、conditional.rs:419-432 [[ ]] 操作数)与 GNU 的 bracket 位置一一对应。
  • 无无关改动:9 个文件全在同一条链上;env 命名空间新键已在 markers.rs census 登记(env_namespace_census_is_complete 本地与 CI 均绿),init.rs 对非 internal respawn 会剥除该键(不泄漏为用户变量);未碰 src/lexer/continuation.rs,无新公开面(除 docs 声称的 inject_console_ctrl_z 属另一 PR)。

腿(逐项给数字与名字):

  • 钉自跑 issue3605_errexit_suppression_transport:4 passed / 0 failed(coproc_invert_and_if_test_carry_the_exemption、exempt_comsub_inherits_cmd_ignore_return、non_exempt_comsub_and_procsub_stay_dead、plain_coproc_stays_under_errexit)。
  • fail-first:base(e3a7b7b src) 上 2 passed / 2 failed,红名 = {coproc_invert_and_if_test_carry_the_exemption, exempt_comsub_inherits_cmd_ignore_return};绿的两格是「不得放开」对照(plain coproc、plain comsub+procsub),与 PR 声称一致。
  • lib 双边:head 失败名集 {api::consumer_tests::issue2084_session_end_restores_host_process_state} / base 失败名集 {同} / 差集 {}(本机环境绑,两边同红)。
  • -D warnings:cargo check --locked --lib --bins clean,0 警告。
  • 卫生:rustfmt --check 产品 8 文件 clean;钉文件原头不满足 rustfmt(3 处 assert! 超宽),已由 2bfb9b6 仅格式化(无断言/无期望改动);marker-lint OK (117 registry consts, 268 allowlisted sites);utf8-hygiene clean。
  • CI:红 4 个——Rust tests / Rust tests (macOS) / GNU regression goldens and canaries 三者仅 issue2875_input_procsub_child_runs_as_rubash_shell(基线;env_namespace_census_is_complete 在 macOS 与 goldens job 均为 ok);niubash builds 为 Session::cwd ledger 缺口(跨仓漂移基线)。均非本 PR 引入。
  • GNU 对照(WSL /usr/local/bin/bash 5.3.20(1)-release;探针 target/probe/m3743.sh,9 个形状):逐字节相同 —— ! coproc { set -e; false; echo invert-body; }、if coproc ... 测试位、plain coproc 仍死、! x=$(set -e; false; echo cs) / if z=$(...) / ! eval 'w=$(...)' / ! { v=$(...) } / 函数体内赋值 under ! f、plain comsub 仍死、! cat < <(set -e;false;echo px) 不放开、! { set -e; false; echo asy; } &+wait、! [[ $(...) == x ]]、顶层 set -e 不被误放开。

F 点:无

续作记录(本轮动过代码):

  • 2bfb9b6 style(tests): rustfmt the errexit-suppression transport pin (Refs #3605) —— 只跑 rustfmt --edition 2021 于钉文件,24 增 6 删全是换行重排;改后钉仍 4/4 绿。新 head: 2bfb9b6。push 前已 fetch 确认远端 head 仍为 c48b8a8(非 force-push)。说明:本地提交时 cargo fmt --check 在本机会报 os error 206(台账记录的已知环境问题),故用 rustfmt 逐文件校验并以空 hooksPath 提交,已在报告披露。

未跑/VOID 的腿:无

已知残余(PR 正文自述,出界、不影响本单):fg 期间第二个 ^Z、pipeline 等待臂、跨会话 kill -STOP。

合并处置:head 与审计时点一致、MERGEABLE,已 squash 合入;#3605 为伞目录 issue,按台账铁律不关单。

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