Repository navigation
fix(executor): yield parseable sleep to a real spawn on unix (Refs #3488) - #3510
Conversation
Captain review — FAILVerdict: FAIL. Sole failing item is leg ⑦: a real macOS defect in The defect (verified firsthand from live CI logs)
What is green (do not re-open)
Rework specInvestigate why the macOS external spawn/parse path reports 126 for Rework acceptance: one fresh head macOS CI run with Notes for the merge (not for this round): |
…859 126) Root cause: on macOS /bin/sleep is a Mach-O image (MH_MAGIC_64), and is_enoexec_candidate treated every non-shebang, non-ELF executable as an ENOEXEC candidate, so execute_external_inner refused it pre-emptively with "cannot execute binary file" / 126 before any execve was attempted -- foreground `sleep 0.5` returned 126 and issue2859_jobs_face_reaped_job_does_not_count panicked (left 126, right 0). Linux stayed green only because /bin/sleep there is ELF. Fix: recognize Mach-O magics (thin 32/64, both byte orders; fat/universal disambiguated from Java class files by the arch count) in the new shared helper is_macho_binary_magic, and admit them in both pre-emptive classifiers -- is_enoexec_candidate and program_execs_directly -- gated on cfg!(target_os = "macos"). On Linux a Mach-O stays an ENOEXEC candidate, preserving GNU's post-ENOEXEC refusal (126): the GNU 5.3 oracle reports 126 for a Mach-O file on Linux, and an ungated exclusion would have flipped it to the glibc /bin/sh fallback's 127 (verified by strace + oracle). program_execs_directly now reads with read() + slicing so 4-7 byte files are still judged on their real prefix. GNU anchors: execute_cmd.c:6126-6233 shell_execve, general.c:718-741 check_binary_file (untouched -- it stays the post-ENOEXEC check). Tests: new unit tests macho_binary_magic_recognizes_thin_and_fat_images and native_binary_classifiers_admit_macho_images (2/2, incl. short-file cases); repro-macho: control /bin/sleep rc 0, fake Mach-O rc 126 on Linux (GNU parity), no execve attempted.
|
队长复核 PASS(新头 FAIL 项已闭合:macOS 腿(复核员自跑 r3 + 亲读 r2 原始日志,队长核查日志原文):
残差:截断 Mach-O(< 28 字节头)在 macOS 上被承认为原生、execve 失败路径未实测——不拦本 PR,已立跟进单 #3625(P3-low)。 合入:Refs #3488(合后队长手关 #3488,随后派 #2983);合入正文须去掉 UNVERIFIED-BY-CAPTAIN 并代入已验腿。 |
…(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.
…875 veil
The issue2875 panic ran nextest's fail-fast at test 23/1249, so two
pre-existing Linux CI failures were never observed:
- tests/{issue2043,issue2046}/fn rubash() resolved the bin target by
popping twice off current_exe — correct only under the deps/ layout.
Under the newer cargo build-dir layout (test binaries inside
build/<pkg>/<fingerprint>/out/) the walk lands inside the fingerprint
dir and spawn fails ENOENT. Anchor on env!("CARGO_BIN_EXE_rubash")
instead, like the rest of the suite.
- corpus.json case sleep-fake kept its Replace-era expectation
(rc=0, no FAKE line) after #3510 flipped the unix sleep face to
ResolvablePolicy::Yield (user ruling 2026-11-14, rubash#3488). A
yielding face spawns the PATH sleep, so the fake script runs —
GNU shape. Relabelled registered->gnu per the command-sleep-fake
precedent in the same file.
Refs #3605
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Same ruling as the corpus flip (rubash#3488 user ruling 2026-11-14, #3510): the unix simple-command face yields every parseable sleep form to a real spawn, so the PATH fake runs and prints FAKE-sleep — the GNU shape (bash has no sleep builtin). The pin asserted the retired Replace-era expectation 'fake sleep must not run'. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…fixes (#3750) * ci: record Session::cwd in api-ledger; surface issue2875 resolver diagnostics Two pieces of master-CI repair: - docs/api-ledger.md: niubash master calls Session::cwd (repl.rs spell-correct path, shell.borrow().session().cwd()) but the §5.5 census entry was never recorded — the 'niubash builds against this tree' check now fails census-missing. Record the face in §2.3 and the §6 symbol block. - consumer_tests.rs issue2875_require_rubash_binary: the CI panic reports no diagnostics about which resolver arm fired or what current_exe was. Report CARGO_BIN_EXE_rubash, both arms, and the resolved path in the assert so the next failing run names the actual gap instead of only the precondition. Refs #3605 Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix(test-resolver): accept the build/<pkg>/<fp>/out test-binary layout CI's newer toolchain places the unit-test binary for a package with a build script inside the package's own build-dir out dir (target/debug/build/rubash/<fingerprint>/out/rubash-<fingerprint>), so the deps-only gate in test_rubash_binary_from_current_exe returned None and issue2875_input_procsub_child_runs_as_rubash_shell panicked on every CI run while passing locally under the classic deps layout. Accept 'out' alongside 'deps'; the ancestor walk already reaches <target>/debug/rubash (which the workflow's cargo build --locked step produces) from that layout, and a file literally named rubash[.exe] still never matches inside it, so production fallback to current_exe is unchanged. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * test: fix masked out/-layout + stale-corpus failures under the issue2875 veil The issue2875 panic ran nextest's fail-fast at test 23/1249, so two pre-existing Linux CI failures were never observed: - tests/{issue2043,issue2046}/fn rubash() resolved the bin target by popping twice off current_exe — correct only under the deps/ layout. Under the newer cargo build-dir layout (test binaries inside build/<pkg>/<fingerprint>/out/) the walk lands inside the fingerprint dir and spawn fails ENOENT. Anchor on env!("CARGO_BIN_EXE_rubash") instead, like the rest of the suite. - corpus.json case sleep-fake kept its Replace-era expectation (rc=0, no FAKE line) after #3510 flipped the unix sleep face to ResolvablePolicy::Yield (user ruling 2026-11-14, rubash#3488). A yielding face spawns the PATH sleep, so the fake script runs — GNU shape. Relabelled registered->gnu per the command-sleep-fake precedent in the same file. Refs #3605 Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * style: fmt-wrap issue2875 resolver diagnostics Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * ci: drop Session::cwd ledger record — adjudicated to the #3704 + niu#1021 lockstep pair Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * test: flip issue2036 shape1 sleep pin to the yield/GNU shape Same ruling as the corpus flip (rubash#3488 user ruling 2026-11-14, #3510): the unix simple-command face yields every parseable sleep form to a real spawn, so the PATH fake runs and prints FAKE-sleep — the GNU shape (bash has no sleep builtin). The pin asserted the retired Replace-era expectation 'fake sleep must not run'. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Refs #3488 — implements the ruling (a) recorded on the issue (user ruling, 2026-11-14).
根因
bats-core 的 timeout 监督靠进程同一性工作:bats-exec-test 的
bats_start_timeout_countdown在测试壳内设 TERM trap,倒计时到期后bats_kill_processes_of用ps枚举测试壳的整棵后代树并逐 pid 发 TERM。GNU 下前台sleep是真子进程(jobs.c:2265 make_child,壳在 jobs.c:3064 wait_for 里等),投递杀掉子进程、等待立即返回、挂起的 trap 在下一命令边界运行(execute_cmd.c:643 run_pending_traps),内层约 1s 结束。rubash 的进程内 sleep 仿真没有进程同一性(#2995 的缺口):树里根本没有 sleep 子进程可杀;投向壳本身的那一份投递又被 virtual-child 模型按「同组发送者 = 只投壳」归类而递延到 sleep 跑完,于是内层跑满约 10s(实测 rubash 10271ms/10439ms vs GNU 1021ms),timeout.bats #2/#3 只有最后一行
((SECONDS < 10))不过。改动
政策层翻转,不动 trap 递延机制本体:
src/executor/command_registry.rs:sleep 行的 resolvable 策略 Replace → Yield(附 2026-11-14 裁决注释,体例同 stty 行的用户裁定注记);模块文档与ResolvablePolicy::Yield的文档同步改述;一致性测试里「无行 Yield」的断言改为「Yield 行恰为 sleep」并注明裁决出处;TimedProducer 面补登 per-face 记录 (Replace, FailClosed)——该模型只查 fail-closed 谓词(可解析则建模、不可解析则退让),行策略翻转后账本须如实记其自有规则,per_face_stand_down_records_are_exact同步扩为五条。TimedConsumer 的 KD-4 记录与 timed 模型代码一律不动(审计 R6:timed 面是语义模型、不是分发)。src/executor/command_dispatch_primary.rs:Sleep 臂在 unix 下追加一道既有政策谓词registered_stand_down("sleep")——行策略翻为 Yield 后该谓词在可解析轴为真,unix 上可解析形态全面退让execute_external真 spawn。job control: foreground child SIGTSTP stop is invisible to the shell (no WUNTRACED/tcsetpgrp in interactive wait path) #2398/[bug] Interactive shell stops itself on ^Z instead of only the foreground job #2836/[bug] Single-command-cself-invocation increments SHLVL one extra time (no exec-replacement) #1497 三道历史退让在 unix 上被其涵盖、保留存档;非 unix 面不求值该子句,fastpath 原样保留(Windows 无此 watchdog 契约)。不可解析形态与不可解析名称([bug] time 计时管道后段命令失败被吞(rc 0 应为 127) #1545 的 127 路径)行为不变。docs/builtins.md:fastpath 表 sleep 行补 stand_down=Yield 裁定注记(体例同 stty 行),清单引言加 unix 例外一句。tests/issue3488_bats_timeout_real_sleep.rs(新钉,首笔提交):断言 ① 前台 sleep 期间壳的子进程清单(ps 枚举,与 bats 同法)里有真 sleep 进程;② 树级 TERM 投递在 1s 后落地、墙钟 < 3s 且 TERM trap 在边界运行。钉内脚本形态已对 GNU bash 5.3.20 实测(watchdog 形态 1.03s、trap 运行、rc 42)。GNU 锚点
本 PR 删除了什么
未删除任何产品代码路径:进程内 sleep 本体(builtins/sleep.rs、sleep_interruptibly、virtual-child 机制)保留给非 unix 面。替换掉的只有与新裁决矛盾的账本表述:command_registry.rs 里「Yield 无行使用」的模块文档与枚举文档两处、一致性测试中「无行 Yield」断言一处(改为精确定集断言),以及 builtins.md 中 sleep 行的旧备注。
验证状态
UNVERIFIED-BY-CAPTAIN
RUSTFLAGS="-D warnings"检查 rc=0 且零 error/warning 行(46 次 rustc 调用含 lib/bin/钉三目标实参记录,非空转)、utf8 hygiene clean、marker-lint 本地实跑 OK。lib 全量 head 1337 过 / 13 败 vs base 1340 过 / 10 败,名集差分全在 executor::path::tests 且经同树复跑证明为该模块在本机的不稳定抖动集(详见车道 REPORT)。