Skip to content

Render conditional/for/select word lists from raw text in source serializer, Refs #2987 - #2990

Merged
caomengxuan666 merged 4 commits into
masterfrom
fix/2987-timeout-cond
Nov 7, 2026
Merged

caomengxuan666 merged 4 commits into
masterfrom
fix/2987-timeout-cond

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Refs #2987

根因

后台作业 respawn 时,子进程的 -c 源码由 bash_command_source_text 序列化(函数表 prelude + 作业体)。其中 conditional_command_source_text 直接 join cooked 的 [[ ]] 参数(引号标记在 cond 参数收集时已被剥除),for/select 的词表同样 cooked-join:

  • [[ "$1" != '|' ]] → [[ $1 != | ]] → unexpected argument '|' to conditional binary operator
  • [[ "$1" == "" ]] → [[ $1 == ]] → unexpected argument ']]' ...
  • [[ $x == "p q" ]] → [[ $x == p q ]] → syntax error
  • [[ "$1" == "a*" ]] → [[ $1 == a* ]] → 能 parse,但引号字面量静默变成模式(语义损坏)
  • for i in "a b" c → for i in a b c → 迭代次数改变

子进程在 parse 阶段整体死亡、一行不跑。bats-core 的每测试超时看门狗正是这样死的:bats-exec-test 的函数表里有这类条件式(如 test_functions.bash 的 [[ "$current_command_or_arg" != '|' ]]),倒计时子壳 ( ... ) & 的 -c 源码 parse 失败 → 看门狗从未运行 → 没人发 TERM → BATS_TEST_TIMEOUT=1 的测试睡满 10s 以 ok 退出(timeout.bats rubash 1 ok / 3 not-ok,GNU 4/0)。

GNU 侧:print_cmd.c:881 print_cond_node 打印 cond->op->word(存词原文、引号犹在),print_cmd.c:586 command_print_word_list、:602 print_for_command_head、:656 print_select_command_head 同理;且 GNU 的异步路径根本不重序列化(execute_cmd.c:701 单次 make_child fork 继承整张已解析表)——rubash 的 respawn 序列化必须无损往返。

修复

src/executor/command_text.rs 三处渲染器统一改走已有的 command_word_source_text(metadata.value 匹配时用 raw、否则 cooked 值单引号兜底、comsub 规范化)——与本文件 case 臂(#1704)已保持的 raw 契约一致:

  • conditional_command_source_text([[ ]] 参数)
  • for_command_source_text(for 词表)
  • select_command_source_text(select 词表)

回归钉

tests/issue2987_respawn_conditional_word_quoting.rs(10 钉):引号 |/空串/空格/glob 操作数、=~ alternation + 转义空格、unary/bang、内联子壳体、for/select 词表、看门狗倒计时链微缩版(子壳内嵌后台 + TERM trap + wait + 函数调用)、TERM 送达主壳完整链。master 上 fail-first 9/10 红。

本 PR 删除了什么

无删除。净行数以 diff 为准(渲染器三处改走既有 helper + 新钉文件)。

UNVERIFIED-BY-CAPTAIN(车道自报;队长复核为准)

…Refs #2987

Background respawn serializes the function table through
bash_command_source_text; its conditional arm joins cooked [[ ]] args,
so [[ "$1" != '|' ]] re-serializes as [[ $1 != | ]] and
[[ "$1" == "" ]] as [[ $1 == ]] - the respawned child dies at parse
before its first command. In bats-core this kills the per-test timeout
watchdog subshell (bats-exec-test's table carries such conditionals),
so BATS_TEST_TIMEOUT never fires. Pins: quoted pipe/empty/space/glob
operands, regex alternation + escaped space, inline subshell bodies,
for/select word lists, and the watchdog countdown chain in miniature.
Fail-first on master b3e4ff8: 9 of 10 pins red (only the unary/bang
control passes both ways). GNU oracle: bash 5.3.20 script-file probes.
…alizer, Refs #2987

conditional_command_source_text joined the cooked ConditionalCommand
args (quote markers stripped at cond-arg collection); for/select
source text joined cooked map_list words the same way. GNU prints all
three lists from the stored word text, quotes intact:
print_cmd.c:881 print_cond_node (cond->op->word), print_cmd.c:586
command_print_word_list, :602 print_for_command_head, :656
print_select_command_head. GNU's async path never re-serializes
(execute_cmd.c:701 single make_child fork inherits the parsed table);
rubash's respawn must therefore round-trip losslessly. Route all three
renderers through command_word_source_text (raw when metadata.value
matches, single-quoted cooked fallback, comsub canonicalization) -
the contract the case arm already keeps (rubash#1704).
@caomengxuan666

Copy link
Copy Markdown
Member Author

Lane verification update (release-caliber acceptance)

timeout.bats standalone, release binary built from this branch (seq-run.sh semantics, BATS_TEST_TIMEOUT=1 fixtures):

The remaining wall-time gap is a separate mechanism, out of this PR's scope, documented in the lane REPORT for captain adjudication: rubash's sleep fastpath emulation (command_registry row policy ResolvablePolicy::Replace; command_dispatch_primary → builtins/sleep.rs, "interruptible virtual-child wait") executes a foreground sleep in-process — no OS child exists (verified via ps/pstree//proc: GNU shows sleep as a direct child of the shell, rubash shows none). bats' countdown kills descendants found by a ps ppid-walk, so it can only TERM the exec-test shell itself; that TERM is trapped, and both GNU and the emulation defer a trapped TERM until the foreground wait ends — the real child GNU relies on being killed separately does not exist here. Fixing that is a stand-down/policy decision on the emulation layer (with perf blast radius), not part of the serializer defect this PR fixes.

@caomengxuan666

Copy link
Copy Markdown
Member Author

Captain review — rubash PR #2990 (Fixes #2987): verified, ready to merge.

  • Head e48f7242af70e1eb013b186000b5b507b9d380c5 (= API head). Exactly 2 files: src/executor/command_text.rs (+49/−3), new pin stem tests/issue2987_respawn_conditional_word_quoting.rs (+179). No REPORT.md, no ledger, no continuation.rs.
  • Root cause confirmed by diff read: the three renderers (conditional_command_source_text, for_command_source_text, select_command_source_text) joined cooked word values; the fix routes each word through the existing command_word_source_text raw contract (same as the case arm, [ecosuite] nvm alias paths break in full nvm.sh context: empty alias file, empty global-package list, call-time parse errors #1704). GNU anchors print_cmd.c:881/586/602/656. Class fix, no guard, no new public surface.
  • Pin stem captain re-run on PR head: 10/10. Fail-first on base b3e4ff89: 1 passed / 9 failed — exactly the lane's claim; the single passer is the no-regression guard pin.
  • Full lib on PR head: 1188/0/4, identical to base. RUSTFLAGS="-D warnings" cargo check --locked --lib --bins: rc=0. Hygiene clean; rustfmt clean on both touched files. CI on head: 10 pass + 1 skipping.
  • Release eco check (captain's own run, seq-run.sh semantics, timeout.bats standalone on the PR-head release binary): 2 ok / 2 not-ok in 31 s. The two failures are ONLY the final ((SECONDS < 10)) assertion — the timeout-marking assertions pass, so the watchdog now fires and the inner runs are correctly marked as timed out. This is the pass shape for mechanism 1.
  • Residual: the wall-clock remainder is a second mechanism — rubash's sleep is a Fastpath emulation with no OS child process, so bats' ps-tree kill chain cannot interrupt an in-flight sleep (three-way ps/pstree//proc evidence in the lane REPORT §4). Filed separately as rubash sleep Fastpath 仿真无 OS 子进程:ps 树杀链(bats 每测试超时)够不着在飞的 sleep #2995 (bug/gnu-baseline/area:fastpath, no milestone — policy axis 麻烦ai审核一下所有的内建以及和winuxcmd冲突 #2036 + perf tradeoff, adjudication first). It does not block this merge: bats timeout.bats: per-test timeout watchdog never fires; [[ ]] with '|' in generated -c code errors #2987's defect (watchdog silently never firing) is fixed.

Overlap note for the bats wave: Finding C of the bats lane edits the same command_text.rs functions — its C1/C3 must be reconciled against this merged shape at its review.

@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 7, 2026 14:30
@caomengxuan666
caomengxuan666 merged commit fb96e74 into master Nov 7, 2026
11 checks passed
caomengxuan666 added a commit that referenced this pull request Nov 7, 2026
…-depth

The three issue2982 pins cover the prelude rendering regressions
(quoted-empty [[ ]] word, for-word carrier leak) fixed by merged
#2990 (fb96e74), not by this PR's C2 trap reset. Rewriting the file
header so the attribution is accurate, and recording the honesty
note: no independently fail-first probe shape for C2 alone was found
(definitions skip DEBUG, the respawned child reads no startup file,
the prelude is definitions-only), so C2 stays defense-in-depth,
behavior-preserving, not pin-proven. Refs #2982
caomengxuan666 added a commit that referenced this pull request Nov 7, 2026
…) (#3012)

Fixes #2982

Background wrapper trap re-arm (C2): the respawned wrapper child inherited live
DEBUG/ERR traps while the prelude re-defined functions, so traps could fire against
an incomplete function table. GNU's forked async child never has this window
(execute_cmd.c:1576 execute_in_subshell). Fix resets DEBUG/ERR for the wrapper
child and re-arms them after the prelude (src/builtins/trap.rs,
src/executor/compound_exec.rs).

Captain adjudication (decision (b), recorded in the captain review): C2 is accepted
as defense-in-depth — its shape matches GNU trap handling and it is
behavior-preserving on every probe. No distinguishing fail-first pin exists for C2
itself, and none is claimed. The two regression stems in this PR
(issue2982_background_wrapper_trap_prelude_regressions, 3 tests;
issue2983_background_wrapper_pgrp_kill_regressions, 1 test) pass unchanged on
master without this PR (captain transplant onto 446d766: 3/0 and 1/0): they guard
the render behavior delivered by merged #2990 (fb96e74), and the credit for what
they verify belongs there.

Refs #2983 — that issue stays open; its root is Finding E, blocked on #2995.

本 PR 删除了什么:无删除。净 diff 4 文件 +246/−0,纯新增(C4 重定向目标假设已在分支内调查证伪并回退,不在净 diff 中)。

Captain verification: pins on head 3/0 + 1/0; lib 1188/0/4 (baseline-identical);
RUSTFLAGS="-D warnings" cargo check rc=0; hygiene clean; rustfmt clean over the
branch diff; transplant no-fail-first result as documented above.
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