Skip to content

fix(executor): termsig death during comsub, blocking read and simulated-exec waits (Refs #3401) - #3455

Merged
caomengxuan666 merged 6 commits into
masterfrom
fix/3401-3284-residuals
Nov 14, 2026
Merged

caomengxuan666 merged 6 commits into
masterfrom
fix/3401-3284-residuals

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Refs #3401 (P2, #3284 residual family; Uarz resting, captain temporary takeover).

What this fixes

A terminating signal (TERM/HUP) delivered while the shell waits in one of three faces rode out the whole wait instead of killing the shell promptly in GNU order (EXIT trap first, then death by the signal; jobs.c:3064 wait_for CHECK_TERMSIG, sig.c:590 termsig_handler).

  • Face 1 — comsub wait. The clone is a conduit, not a judge: its trap table is reset for the subshell child, so it records a parent-death delivery raw (comsub_termsig_pending) and the teardown re-queues it for the parent's next boundary poll. The pin shape x=$(/usr/bin/sleep 5) is served by the external-command fast path, not the clone, so that path's wait_with_output is replaced by a reader thread plus 10ms try_wait slices classifying each delivery with the shared &self verdict (pending_termsig_verdict).
  • Face 2 — blocking read wait. The sliced-readability gate is generalized to all blocking reads (not just the interactive SIGINT guard); each 50ms slice drains the termsig mailbox (read.def:766 CHECK_TERMSIG after every read attempt). -t deadline loop gets the same per-slice drain.
  • Face 3 — simulated-exec wait. The executor is threaded through the exec builtin's spawn chain (13 trap_exec call sites); both simulated waits now run through wait_fg_child_draining (execute_cmd.c:6126 exec_builtin -> shell_execve has no simulated-wait layer). The capture path additionally drains its pipes on reader threads so large output cannot deadlock.

Pins

tests/issue3284_engine_wait_termsig_regressions.rs, 9 -> 12 cells: term-comsub un-gated, plus new term-read, term-read-t, term-sim-exec ($(exec ...) via the capture-bound fd table). Base fail-first on c28a9dd: 7 passed / 1 failed (hup-ext, inherited SIG_IGN environment in the driver session) / 1 ignored; comsub FAILED at 5.26s. Box head legs pending (box disk at 100% at push time).

本 PR 删除了什么

  • 删除了 with_exec_diag_stderr 辅助函数(src/executor/trap_exec.rs):其四个调用方已改为 inline take/restore(闭包无法同时借 &mut self.stderr_capture 与 &mut self 执行器参数),删除后无调用方;inline 形保留了原 helper 的关键保证——capture slot 在错误传播前恢复。
  • 未删除任何产品行为、公开 API 或测试;仅删除上述一个私有辅助函数。

…ed-exec waits (Refs #3401)

Face 1 (comsub): the clone is a conduit, not a judge — its trap table
is reset, so it records a parent-death delivery raw and the teardown
re-queues it for the parent's next boundary poll (EXIT trap first,
then death by the signal; jobs.c:3064 wait_for CHECK_TERMSIG). The
pin shape x=$(/usr/bin/sleep 5) is served by the external-command
fast path, not the clone, so its wait_with_output is replaced by a
reader thread plus 10ms try_wait slices classifying each delivery
with the shared &self verdict. Un-gates term-comsub.

Face 2 (blocking read): the sliced-readability gate is generalized
to all blocking reads (not just the interactive SIGINT guard); each
50ms slice drains the termsig mailbox (read.def:766 CHECK_TERMSIG
after every read attempt). Adds term-read and term-read-t cells.

Face 3 (simulated exec): the executor is threaded through the exec
builtin's spawn chain (13 trap_exec call sites); both simulated
waits now run through wait_fg_child_draining (execute_cmd.c:6126
exec_builtin -> shell_execve has no simulated-wait layer). Adds the
term-sim-exec cell ($(exec ...) via the capture-bound fd table).

Pins: tests/issue3284_engine_wait_termsig_regressions.rs 9 -> 12
cells (term-comsub un-gated, term-read, term-read-t, term-sim-exec).
Base fail-first on c28a9dd: 7 passed / 1 failed (hup-ext, inherited
SIG_IGN environment) / 1 ignored; comsub FAILED at 5.26s.
…it, Option-thread the executor (Refs #3401)

- wait_fg_child_draining lives in external_inner; re-export it from
  crate::executor (same pattern as spawn_error_diagnostic) so the
  builtins::exec waits resolve (E0425 x2).
- The execute_with_* chain takes Option<&mut Executor>: Some on the
  engine path (13 trap_exec sites, explicit reborrow), None on the
  standalone execute() entry, which has no session — there the bare
  wait is correct, because no mailbox defers the signal and the
  disposition is SIG_DFL, so the process dies at delivery exactly as
  GNU does for an untrapped termsig. execute() keeps its public
  io::Result<i32> contract via a boundary map (IoError passthrough).
- Fix the 5 cargo fmt --check violations the first commit left
  (exec.rs, command_substitution.rs, trap_exec.rs x2, pin stem).
…io call (Refs #3401)

- Some(&mut *self) activates its mutable reborrow at once (no
  two-phase borrow through Some), so the later
  self.exec_inherited_stdin()? argument is E0502 (CI Rust tests,
  trap_exec.rs:4578). Hoist the resolve before the call, mirroring the
  else branch below, which already hoists it the same way.
… too (Refs #3401)

- pending_termsig_verdict never returned death on the fast path:
  comsub_parent_termsig_armed read only the snapshot Cell, which is
  always false on the parent executor (initialised false, only ever
  set when a clone is built). The pin shape x=$(/usr/bin/sleep 5)
  runs on the parent, so the TERM was re-queued slice after slice
  and the wait rode out the whole child (term-comsub died at 5.05s
  on head ddd41e5; probe comsub 5.06s vs GNU 0.80s).
- EXIT-armed now has two sources: the clone's snapshot Cell (the
  clone's only source — its trap table was reset) OR the live trap
  table, exactly like termsig_death_armed. On the parent this makes
  the verdict identical to termsig_death_armed; on the clone the
  snapshot still arms it.
…t (Refs #3401)

- wait_fg_child_draining is #[cfg(unix)], so the ungated re-export in
  executor/mod.rs is E0432 on Windows (CI run 43278490674, both
  windows-latest legs; Linux legs all pass). The builtins::exec call
  sites are not cfg-gated, so gating the re-export would only move
  the error to E0425 at the calls. Add a #[cfg(not(unix))] twin that
  is the plain blocking wait — there is no termsig/mailbox model off
  unix, the same shape the fast path's #[cfg(not(unix))] arm and the
  non-unix branches of wait_external_child use.
- Fix the one cargo fmt --check violation the live-table fix left
  (trap_exec.rs:2730, rustfmt's own layout for the || chain).
@caomengxuan666

Copy link
Copy Markdown
Member Author

复核:PASS(Refs #3401,终头 f5f38597)

复核员结论:PASS。产品修法、钉、lib、相邻双边、CI、卫生均已核实;
相邻 1990/1991 三红为基底红(已知问题,不新立案);两个小项
(Windows Read 警告、正文标记)不阻塞,见末节。

已证实(复核员独立证据 + 车道原始日志亲读)

  • 三面等待的修法在终头上与 GNU 一致(复核员自有三方探针,
    probe-3455-faces.py,5 面 × HEAD/BASE/GNU 5.3.20):
    comsub / comsub-multi / read / read-t / sim-exec 皆 rc=-15、0.80s、
    EXIT-TRAP;基底 comsub 5.03s、read CAP>8s、GNU 皆 0.80s。
    根因是 comsub_parent_termsig_armed 只读 clone 快照 Cell,
    51d7740e 的 live-table OR 已修复。
  • 钉 12/12 双遍(复核员自有执行,f5f38597,3.57s/3.32s):
    12 格逐名皆 ok,含 term-comsub、term-read、term-read-t、term-sim-exec。
    基底 fail-first(车道原始日志亲读):7 绿 / 1 红(HUP)/ 1 忽略,
    其中 term-comsub 在 un-ignore 单跑中 FAILED(5.26s)——fail-first 成立。
    (订正:DESIGN.md 所称“基底 pin 8/9 红”与原始日志不符,实际如上。)
  • lib 双边名集 ∅:头 1246/0/4(复核员自有执行,先 --bin rubash,
    repo 根目录跑);基底 1246/0/4(车道原始日志亲读)。同数同名集。
  • 相邻 1990/1991 三红 = 基底红:头 3/6 红与基底 3/6 红逐字相同
    (同名、同 panic 行 :306/:137/:221、同消息,含 BOOT42/K42RC);
    相邻 1035/1036 头尾皆 9/9。建议不新立案(已有 [bug][P1] Ctrl+C 报 130、回提示符,但前台子进程没死(Android 实机,#1662 后续) #1990 跟踪面)。
  • 终头 CI 三红同因一格,已定性 VOID(run 43281257788,复核员逐名
    重读三腿日志):Rust tests / macOS / goldens 唯一红皆
    issue2875_input_procsub_child_runs_as_rubash_shell
    (Unrecognized option: 'c',consumer_tests.rs:2911)——已知的
    lib 腿缺 --bin rubash 环境陷阱;同格在父头 51d7740e 的 CI 为 PASS,
    且 51d7740e→f5f38597 的差只含 not(unix) twin + fmt 空白,Linux 上
    行为中性。goldens 段因 lib 失败被 skip(无 golden 回归证据;
    “goldens 实际比较通过”言过其实,比较根本没跑)。
  • Windows E0432 已修:f5f38597 补 #[cfg(not(unix))] twin 后,
    Windows tests compile check 绿。
  • -D warnings:车道原始日志亲计数——1468 次 flagged rustc 调用、
    0 警告、0 错误(Finished … in 3m 01s);复核员自有部分执行至 670 次
    调用皆干净,后因盒盘写满中断(环境 VOID)。
  • 卫生:cargo fmt --check rc=0、marker-lint OK、UTF-8 clean(皆 f5f38597)。
  • 交集对活尖 e50cea96:3 文件(command_substitution.rs / init.rs /
    mod.rs),hunk 不重叠——合入须 update-branch + 合并形重验。
  • 首代速败定性:a6b96183 的 E0425/E0308 与 0069dbb5 的 E0502 皆为
    编译错,非产品红;均已消除。
  • 正文:Refs-only ✓;删除节在(删 with_exec_diag_stderr 私有 helper)。

不阻塞的小项(队长定:合入前修或后续跟进)

  1. command_substitution_values.rs:4 的 use std::io::Read 在 Windows 下
    未用,加 #[cfg(unix)](Windows 腿仍有此 warning;CI 不用 -D warnings
    故仍绿)。
  2. 正文缺 UNVERIFIED-BY-CAPTAIN 标记,补。

环境说明(证据等级)

  • 自有基底构建被本地 OOM 阻(5 个 rustc 并发、可用内存 1.1G),
    自有完整 -D warnings 重跑被盒盘写满(0%)阻;基底侧与 -D warnings
    的证据改由车道原始日志复核员亲读 + 复核员自有部分执行补足,
    详见卷宗 ~/workspace/review-3455/CAPTAIN-VERIFY.md §7、§9。
  • 合入条件:头仍为 f5f38597;update-branch + 合并形重验(钉 + lib);
    Refs-only,合入后 [bug] termsig death still delayed on comsub, blocking-read and simulated-exec waits (residual of #3284) #3401 由队长手动关。

@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 14, 2026 17:01
@caomengxuan666
caomengxuan666 merged commit 12aa434 into master Nov 14, 2026
8 of 11 checks passed
caomengxuan666 added a commit that referenced this pull request Nov 14, 2026
…(Refs #3211) (#3220)

Refs #3211

## 根因(机制定性)

动态变量整表复合赋值缺属主落点钩子。GNU 把 BASH_ALIASES / BASH_CMDS
注册为带元素 assign hook 的动态变量(variables.c:1882-1897
`initialize_dynamic_variables`):

| 变量 | hook | 语义 |
| --- | --- | --- |
| BASH_ALIASES | assign_aliasvar(variables.c:1785) | `valid_alias_name` 校验后 `add_alias`;非法名报错跳过该元素、其余照落、语句 rc 不变 |
| BASH_CMDS | assign_hashcmd(variables.c:1715) | `phash_insert(key, value, 0, 0)`:被点名条目 hits 重置、未点名条目原样保留 |

整表赋值无第二条路:`subst.c:3441 do_compound_assignment` →
`arrayfunc.c:700 assign_compound_array_list` 逐元素经
`bind_assoc_var_internal` / `bind_array_var_internal` 调钩子;标量
绑定走 `bind_variable_internal` 的 assign_func 臂、以 key `"0"` 调
钩子(variables.c:3140),`+=` 标量先 `make_variable_value`
ASS_APPEND 读现值拼接(variables.c:3328)。非追加复合形只换 cell
投影、**从不清属主表**——列表外属主条目保留。declare / typeset /
export 的操作数绑定同走 bind_variable 家族、钩子同路。

rubash 侧:#3107 的 `sync_dynamic_assoc_vars` 只在「属主 → 镜像」
方向发布;整表赋值落通用路径只写镜像 + typed 存储,下一命令边界
`sync_dynamic_assoc_cells` 对账时以未被触碰的属主表重建两者,赋值
被丢弃。对照 DIRSTACK 早有属主落点门 `apply_dirstack_assignment`,
assoc 对偶一直缺位——本 PR 补上。

## 普查(全部动态变量整表赋值落点,GNU 探针 27 格实测)

| 变量 | GNU 机制 | rubash 处置 |
| --- | --- | --- |
| BASH_ALIASES | assign_aliasvar 逐元素落 alias 表 | **本 PR 新增门**(复合/标量/追加/kvpair/列表内 `[k]+=`) |
| BASH_CMDS | assign_hashcmd 逐元素落 hash 表 | **本 PR 新增门**(同上;hits 语义 = 只重置被点名条目) |
| DIRSTACK | assign_dirstack → set_dirstack_element([0]/越界忽略) | 既有门(回归锁钉覆盖) |
| GROUPS / BASH_ARGC / BASH_ARGV / BASH_SOURCE / BASH_LINENO / FUNCNAME | null_array_assign no-op + att_noassign | 既有 noassign 臂吞(非追加形);追加形普查与残余见车道 REPORT |
| BASH_REMATCH | 无钩子普通数组(match 时重建) | 通用路径即正道 |
| PIPESTATUS | 无钩子普通数组;赋值语句自身管线状态在边界覆写读值 | 通用路径 + 既有 note 机制 |

declare / typeset / export 三门与 local 影子、unset 后整表赋值的
基底行为由车道普查对基底二进制逐格核对后回填(见
`~/workspace/fix-3211/REPORT.md` §2,工作区文件不入仓)。

## 修法

`apply_shell_assignment_inner` 在 DIRSTACK 臂旁加动态 assoc 门
`apply_dynamic_assoc_assignment`(`dynamic_arrays.rs`,与 DIRSTACK
门同居):复合形经与通用路径同一
`rewrite_compound_element_subscripts` + `append_assoc_value` 扫描
后逐条路由属主(aliases 表 / `set_hashed_path`);`=` 形以空表为
扫描种子(列表内追加在本列表内组合)、`+=` 形以属主现表为种子算
终值且只路由列表点名的键;标量形 = key `"0"` 单条,`+=` 先读属主
[0] 拼接。门控与 DIRSTACK 同口径:readonly 由上游臂先行拒绝,
unset 标记 / local / tempenv 影子让位普通 cell。收尾统一
`sync_dynamic_assoc_vars()` 发布。

回归钉 `tests/issue3211_dynamic_whole_assignment.rs`:普查每个
动态变量的整表赋值形 + 元素赋值回归锁 + unset 后普通变量锁。

## 验证(队长已核,见 PR #3220 评论 6880965406)

- 合并形钉(终头 `3e7c069f`,update-branch 至 `#3455` 合入后的尖 `12aa434e`):**10/10**。
- Fail-first(顶-up 形,基底 `c01a5417`):**3 passed / 7 failed**——7 红格恰为门控格,3 守卫格在基底上绿;翻转真实(基底 3/7 → 合并头 10/10)。
- 尖端 sanity:被拆出的 #3573 面格在尖 `ca89c83a` 上 **1/1** 绿(已由合入的 #3577 修复),故本钉删该格安全;邻居 #3573 钉在终头上 **14/14**。
- Lib 双边:终头 1249/0/4 vs 基底 1206/0/4,失败名集差 **∅**(两边皆 0 FAILED 行)。
- 交集 vs 活尖:两产品文件 hunk 级无重叠(本 PR 的 hunk 在 dynamic_arrays.rs:1870、temporary_assignments.rs:1783;区间内最近 hunk 相距 ≥51 行);update-branch 已干净应用。

## 本 PR 删除了什么

无删除:纯新增(赋值门 + 回归钉)。通用路径对这两个变量名的整表
赋值自本 PR 起不可达(由门接管),但代码不删——影子/unset 情形仍
走通用路径绑定普通 cell。
caomengxuan666 added a commit that referenced this pull request Nov 14, 2026
…(Refs #3500)

## Summary

A bad substitution inside a compound-assignment element was diagnosed with the `${...}` fragment instead of the element word. GNU quotes the whole element and reports the word being expanded, e.g. `a=([0]=${-x})` → `\[0\]=${-x}`.

## Root cause

`subscripted_parameter_element` hands the RHS to `whole_word_parameter_single_value`, whose `has_word_operator` arm misjudges `${-x}` (empty `var_name` at position 0) and expands it standalone with no pending diagnostic word installed, so `expand_braced_parameter_word` falls back to the synthesized `${-x}` fragment. The plain-element path had the same gap (the walker default names the raw token, without `quote_assign`'s `\[sub\]` quoting).

## Fix

- New `compound_element_diag_word` (module level, mirrors GNU `quote_assign`): indexed `[sub]=value` → `\[sub\]=value`; assoc elements → the bare value; a quoted value keeps the fragment's own word.
- The element word is installed as the pending diagnostic word at the two element-expansion sites (`subscripted_parameter_element`, `compound_plain_element_value[_fields]`), install-if-absent.
- An `assoc` parameter is threaded through `expand_compound_positional_at_assignment[_bare]` (4 call sites), computed by new `compound_assignment_is_assoc` (live `ASSOC_VARS` marking OR the declare-assoc hint).
- New declare-assoc thread-local hint (`DECLARE_ASSOC_HINT` + RAII guard), installed by the `declare_assoc_operand_names()` scan in `command_prepare.rs`, covering the `declare -A` command-word expansion path, which runs before the declare builtin.
- Bare (eval-argument) flatten installs no word: documented residual, not fixed here.

GNU anchors: `arrayfunc.c:557/:581/:594-599/:606/:630/:938-977/:1108-1129`; `subst.c:10278`.

## Regression pin

`tests/issue3500_compound_elem_diag_word.rs` — 19 cells (10 fix shapes + 6 guard shapes + 2 quiet guards + 1 first-bad-wins). Expectations verified against GNU bash 5.3.20.

## Verification (captain-verified legs)

- Merged head `d11ffbcf` (update-branch of `00c0a07` onto tip `021705cf`, three update-branch rounds: `8eb07872` (#3510), `12aa434e` (#3455, disjoint files), `021705cf` (#3220, disjoint files); intersection `{src/executor/assignment_expansion.rs}` via #3599, hunks ≥164 lines apart, no overlap): pin **19/19**; same-file neighbor issue3501 pin **68/68**; adjacent assoc-face issue3573 pin **14/14**.
- Fail-first (top-up form on base `11719895`): pin 11/19 — 8 red, each reporting `Some("${-x}")` where the element word is expected.
- Neighbor `array_compound_quote_regressions` 17/17 on head.
- Full lib bilateral (bin built first): base 1247 passed / 0 failed / 4 ignored; merged head 1249 passed / 0 failed / 4 ignored — failure name-set diff empty (the +2 are the tip's Mach-O unit tests from #3510).
- `RUSTFLAGS="-D warnings" cargo check` RC=0, 0 warnings; `cargo fmt --check` RC=0; utf8-boundary hygiene clean.
- Head CI run `43619058744` (on `10da84b4`, the second update-branched head): 3 failing jobs, sole FAILED name `issue2875` (known baseline). A fresh CI run starts on the final head `d11ffbcf` from the third update-branch; it differs from `10da84b4` only by the disjoint #3220 merge.
- `continuation.rs` untouched.

Refs #3500

## 本 PR 删除了什么

Nothing — purely additive fix plus the new regression pin. No code, test, file, or behaviour removed.
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