Skip to content

Refs #3802 - #3805

Merged
caomengxuan666 merged 2 commits into
masterfrom
fix/3802-jobs-table-killed-wording
Nov 17, 2026
Merged

caomengxuan666 merged 2 commits into
masterfrom
fix/3802-jobs-table-killed-wording

Conversation

@caomengxuan666

@caomengxuan666 caomengxuan666 commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Refs #3802

UNVERIFIED-BY-CAPTAIN

Root cause

GNU jobs.c:1969-2015 printable_job_status renders a job that died by a signal with the signal description (j_strsignal (WTERMSIG (p->status)) — Killed for SIGKILL) and only a plain nonzero exit as Exit %d. The distinction is the wait status's WIFSIGNALED bit, which Windows ExitStatus does not carry: rubash's own kill encodes the kill as TerminateProcess (128 + signal) (src/builtins/kill.rs signal_process), so a SIGKILL'd job reaps with exit code 137 and no recorded signal, and the table rendered [1]+ Exit 137 sleep 30.

Fix (in progress): record the signal this shell's own kill delivered (JobTable, via the shared note_kill_delivery bookkeeping site) and decode the reap against it at the boundary sweep, so the table renders Killed / Terminated. A plain exit 137 keeps rendering Exit 137 — the signal is attributed only from the shell's own kill record, never from the exit code alone. No change to src/builtins/wait.rs or the notification emission path (#3803's face).

Regression nails

tests/issue3802_jobs_table_killed_wording.rs (fail-first on Windows/X299; the KILL/TERM legs already pass on Linux via the wait status):

  • SIGKILL -> jobs row contains Killed, no Exit 137; wait still reports 137
  • kill -KILL -> same
  • SIGTERM -> Terminated, no Exit 143; wait still reports 143
  • plain exit 137 -> still Exit 137, never Killed

本 PR 删除了什么

无删除:只新增回归钉(本提交);修法提交随后。

Verification

  • Fail-first run of the new nails on X299 (rubash.exe, native cargo test)
  • Fix green on X299 + seed_r118a.sh checks 2-3
  • GNU oracle对照 (Linux)
  • Full lib + base alignment, RUSTFLAGS="-D warnings" cargo check, rustfmt --check

修法(26769c2f7 已落)

note_kill_delivery(单 pid 与 jobspec 两条投递路径共用的唯一记账点)把终止信号记入 JobTable::delivered_signals;apply_job_completion 在平台 wait status 无信号时取出该记录交给 note_term_signal,render_background_jobs 已有的 term_signal → signal_death_description 分支即打印 GNU 的 Killed/Terminated。控制格 exit 137 没有投递记录,保持 Exit 137;pid 重新注册会丢弃旧记录。

GNU 锚点:jobs.c:1969-1985 printable_job_status(WIFSIGNALED → j_strsignal(WTERMSIG),否则 Exit %d)。

验证:钉 4/4(base 308e97f:3 红 1 绿);WSL GNU bash 5.3.20 脚本文件三格(KILL/TERM/exit 137)PID 归一后逐字节一致;lib 差集空(issue2084 环境);warnings/fmt 净。

Fail-first nails: a SIGKILL'd background job must list as Killed
(seed_r118a checks 2-3), SIGTERM as Terminated, and a plain
exit 137 must keep rendering Exit 137.

GNU jobs.c:1969-2015 printable_job_status: WIFSIGNALED prints
j_strsignal(WTERMSIG); only a plain nonzero exit prints Exit %d.
Refs #3802
@caomengxuan666

Copy link
Copy Markdown
Member Author

【Y3-AUDIT】PR #3805 第1轮 — 建议:PASS(钉已就位且与 GNU 一致;注意:本 PR 当前仅含回归钉,修法未落——合入前必须等修法提交,否则会给 master 带进 3 条新红)
head: a9e96c7 base(merge-base): 308e97f 文件: 1 个 +150/-0
关联 issue: #3802(状态:open,核于 2026-11-17 本地;issue 正文本人属实:Windows jobs 表把 SIGKILL 渲染成 Exit 137)

机制核查:

  • GNU 锚点:jobs.c:1969-2015 printable_job_status——WIFSIGNALED 走 j_strsignal(WTERMSIG(p->status))(SIGKILL→Killed、SIGTERM→Terminated),仅 WIFEXITED 非零走 Exit %d。钉的期望与该分支一一对应。
  • 根因陈述属实:Windows ExitStatus 无 WIFSIGNALED 位;rubash 自家 kill 以 TerminateProcess(128+signal) 编码(builtins/kill.rs signal_process),reap 得 137/143 且无信号记录 → 现表行 [1]+ Exit 137 sleep 30(本地实测复现)。
  • diff 仅 +tests/issue3802_jobs_table_killed_wording.rs(150 行),无产品代码——与正文「Fix (in progress)…修法提交随后」的自述一致,不是正文虚报修复。
  • 无无关改动;无桥接/翻译层;正文/标题/commit 仅 Refs #3802,无关单词+编号同句。

腿:

  • 钉自跑(head = base + 该测试文件,产品树与 merge-base 逐字节一致):issue3802_jobs_table_killed_wording 1 passed / 3 failed——红名 = {issue3802_jobs_kill9_renders_killed, issue3802_jobs_kill_kill_renders_killed, issue3802_jobs_kill_term_renders_terminated},绿名 = {issue3802_jobs_plain_exit_137_stays_exit_137};失败输出即 issue 报告的 [1]+ Exit 137 / Exit 143 行,红因正确
  • fail-first:merge-base 308e97f 无此文件;因 diff 仅 +1 测试文件,head 上的红即 base 上的红(构造性等价,未重复构建)
  • lib 双边:diff 不含 src/ 任何文件,lib 目标与 base 完全相同 → 差集 {}(构造性成立,未重跑)
  • -D warnings:测试文件经 cargo test 编译无警告(test target 编译通过)
  • 卫生:rustfmt --edition 2021 --check tests/issue3802_jobs_table_killed_wording.rs rc=0
  • CI(head a9e96c7):红 = GNU regression goldens(基线同名 issue_753::case_9 + upstream_suite_slice_snapshots)+ census 39 红 stem(vs master 37:+issue1902 已知 flake、+issue3255 跨 PR 漂移、−issue371 已知 flake);Rust tests / macOS / Shell / CLI / 两个 cross-target / niubash builds 全 pass → 均非本 PR 账
  • GNU 对照:WSL bash 5.3.20(1)-release,脚本 target/devin-dispatch/probes/gnu-3802.sh:kill -9 → [1]+ Killed sleep 30 wrc=137;kill -TERM → [1]+ Terminated sleep 30 wrc=143;exit 137 → [1]+ Exit 137——与钉断言逐字一致;exit 137 控制格在 Windows 本就绿(判别腿双侧有效)

钉质量专项(本批钉审口径):

  • 4 钉覆盖 SIGKILL(-9/-KILL 两形)、SIGTERM、plain exit 137 对照;断言含「正词在 + 误词不在 + 命令名在 + wait 退出码不变」四层,非假绿形态。
  • 文件注释明示 Linux 上 KILL/TERM 腿修复前已绿(wait status 自带信号),exit-137 是双侧判别腿——与 GNU 机制一致,钉设计诚实。
  • 唯一保留:钉等修法落地才转绿;修法须保证「plain exit 137 永不误判 Killed」(钉已钉死该不变量)。

F 点:无

未跑/VOID 的腿:lib 双边(构造性等价,diff 仅 +tests/ 文件);fail-first 独立 base 构建(同上等价性)

@caomengxuan666

Copy link
Copy Markdown
Member Author

【Y3-AUDIT】判词更正:#3805 当前仅含回归钉、修法未落,按批次口径应记 建议 PENDING(缺修法腿),不进入 merge 队列。钉本身已验证(见上条报告)。

#3802)

GNU printable_job_status (jobs.c:1969-1985) renders a signal death as
`j_strsignal (WTERMSIG (p->status))` — `Killed` for SIGKILL,
`Terminated` for SIGTERM — and only a plain nonzero exit as `Exit %d`.
Windows ExitStatus carries no WIFSIGNALED bit, and this shell's own
`kill` encodes a kill as TerminateProcess (128 + signal)
(builtins/kill.rs signal_process), so a SIGKILL'd background job reaped
with exit code 137 and the table printed `Exit 137`.

Record the terminating signal at the shared delivery bookkeeping site
(`note_kill_delivery`, the one place the single-pid and jobspec paths
both pass) in JobTable::delivered_signals, and consume it at
apply_job_completion: when the platform wait status has no signal, the
record supplies it for note_term_signal, so the row renders GNU's
description. A plain `exit 137` leaves no record and keeps
`Exit 137`; a re-registered pid drops a stale record.

Verified against WSL GNU bash 5.3.20 from a script file: KILL/TERM
rows and the `exit 137` control are byte-identical after PID
normalization. Pin issue3802_jobs_table_killed_wording 4/4 (3 red at
the branch's base commit).
@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 17, 2026 07:51
@caomengxuan666

Copy link
Copy Markdown
Member Author

【o1 收网验证 · 建议 PASS】head 26769c2f7(在钉 a9e96c7d 之上补产品修法)

Y3-AUDIT 第1轮/更正(PENDING=缺修法腿)已回应:修法已落,机制如下。

  • 投递记账:note_kill_delivery(limit_builtins.rs,单 pid 与 jobspec 两条 kill 路径的唯一共用点)在终止信号面把 (pid, signal) 记入新增的 JobTable::delivered_signals。
  • 收割解码:apply_job_completion 在平台 wait status 无 term_signal(Windows ExitStatus 无 WIFSIGNALED,signal_process 以 TerminateProcess(128+signal) 编码)时取出投递记录,交给既有 note_term_signal,render_background_jobs 的 term_signal → signal_death_description 分支打印 Killed/Terminated。
  • 控制格:exit 137 无投递记录 → 保持 Exit 137;pid 重新注册(register_pipeline_stages)丢弃旧记录,回收 pid 不会借用。
  • GNU 锚点:jobs.c:1969-1985 printable_job_status。

腿:

  • 钉 issue3802_jobs_table_killed_wording 4/4(KILL9 / kill -KILL / kill -TERM / exit 137 控制)
  • fail-first:base 308e97fc5 + 钉 → 1 passed / 3 failed(红名 = 三格信号行,控制格绿),红名与审计第1轮逐字一致
  • GNU 对照:WSL GNU bash 5.3.20 脚本文件 sleep&kill-9/jobs/wait、kill-TERM、$BASH -c 'exit 137' 三格 PID 归一后 stdout 逐字节一致([N]+ Killed ... / [N]+ Terminated ... / [N]+ Exit N ...)
  • 相邻 jobs/kill 切片:issue1494 2/2、issue2931 9/9、issue1302 13/13、issue549 11/11(issue2398/2624/2397/1645 为 unix-gated,Windows 0 tests)
  • lib 双边:head 1368P/1F、base 1368P/1F,同名 api::consumer_tests::issue2084_session_end_restores_host_process_state(本机 __RUBASH_CURRENT_LINE 注入)→ 差集空
  • RUSTFLAGS=-D warnings cargo check 净;3 个改动文件 rustfmt 净
  • CI:本 PR 前一轮仅钉时 CI 无新增红(gh pr checks 归因沿用);新 head run 由本合并触发,基线红口径见 master 同窗口 census/goldens(issue_753::case_9、upstream_suite_slice_snapshots)
  • 未跑腿:WSL Linux 原生构建(改动为 Windows wait-status 面,pins 的 Linux 腿本身已绿)

关联 #3802:本 PR 覆盖 issue 描述的全部形状(KILL/TERM 表行措辞 + 单一死亡报告 + exit 137 控制),合入后关单。

@caomengxuan666
caomengxuan666 merged commit 5b6fcb1 into master Nov 17, 2026
8 of 12 checks passed
@caomengxuan666

Copy link
Copy Markdown
Member Author

【P1 车道复核 — 已合入后的残余回归】#3805 的修法在 Linux 上把「被 kill 过但最终正常退出」的 job 误判成信号死亡

本 PR 已合入(merge 5b6fcb1db,master 当前 72e160b55)。KILL/TERM/exit 137 三形与 GNU 一致(我这边独立复跑 4/4 绿),但合入后我补跑了 trapped-signal 类,发现与 GNU 不一致:

脚本(LF 文件,WSL GNU bash 5.3.20) GNU 5.3.20 master(72e160b55,Linux rubash)
"$BASH" -c 'trap "" TERM; sleep 1; exit 5' & p=$!; sleep 0.3; kill -TERM "$p"; sleep 1.2; jobs [1]+ Exit 5 [1]+ Terminated
"$BASH" -c 'trap "exit 143" TERM; sleep 1; exit 0' & p=$!; sleep 0.3; kill -TERM "$p"; sleep 1.2; jobs [1]+ Exit 143 [1]+ Terminated

根因(GNU 锚点)

GNU jobs.c:1969-2015 printable_job_status:只有 WIFSIGNALED 才走 j_strsignal(WTERMSIG(p->status));WIFEXITED 一律 Exit %d(即使进程刚收到过 SIGTERM 并捕获/忽略它)。kill_pid(jobs.c:3988-4007)只是投递,投递 ≠ 死亡。

当前实现 JobTable::take_delivered_signal(pid) 只按 pid 取投递记录、不校验 reap 出来的 code 是否等于 128+signal:

  • src/executor/job_builtins.rs:2340-2344 term_signal.or_else(|| ...take_delivered_signal(pid))
  • src/jobs/table.rs:611-617 take_delivered_signal(pid) -> Option<i32>

Linux 上正常退出的 term_signal(来自 exit_status_signal)是 None,于是 fallback 把投递的 15 直接当 WTERMSIG。Windows 侧因为 TerminateProcess 必然 128+signal,这个漏洞不显现。

建议修法(保持 #3802 的全部钉绿)

take_delivered_signal(pid, status):仅当 status == 128 + signal 时返回 Some(signal),否则丢弃记录并返回 None(记录应在完成时消费,避免 pid 复用借用旧投递;register_process 已有清理)。调用点传 status。这样:

  • kill -9; jobs → Killed(137 == 128+9)
  • kill -TERM; jobs → Terminated(143 == 128+15)
  • kill -TERM + trap "" TERM; exit 5 → Exit 5
  • 裸 exit 137 → Exit 137(无投递记录)

替代方案是把该 fallback 整体 #[cfg(not(unix))] 掉(unix 有真 wait status),但上表的 Linux 缺陷只是被隐藏,Windows 上「trap 后 exit N」仍会误判(Windows 该形不可达,风险较低)。

请后续车道补一格 pin:#[cfg(unix)] 的 trapped-signal 两形(Exit 5 / Exit 143,断言不含 Terminated),并跑 WSL GNU 5.3.20 对照。issue #3802 保持 OPEN。

caomengxuan666 added a commit that referenced this pull request Nov 17, 2026
… (Refs #3802) (#3841)

#3805 made the jobs table name the signal this shell's own kill
delivered, decoding the Windows `TerminateProcess (128+signal)` exit
code against a per-pid delivery record. The decode was unconditional:
`take_delivered_signal(pid)` ignored the reaped status, so on unix a
job that ignored or trapped SIGTERM and then exited on its own was
rendered from the record instead of its wait status --
`trap "" TERM; exit 5` printed `Terminated` where GNU prints `Exit 5`,
and `trap "exit 143" TERM` printed `Terminated` where GNU prints
`Exit 143`.

GNU decides the wording from the wait status alone: jobs.c:1969-2015
printable_job_status() calls j_strsignal(WTERMSIG(p->status)) only in
the WIFSIGNALED arm, and the WIFEXITED arm always renders `Exit %d`
(jobs.c wait_for reaps the status; kill_pid, jobs.c:3988-4007, is pure
delivery and never proof of death). A code equal to 128+signal is not
that proof: an `exit 143` is WIFEXITED.

Owner split:
- unix: the kernel wait status is authoritative (exit_status_signal),
  so the delivery record is only consumed, never applied
  (JobTable::discard_delivered_signal);
- Windows: no WIFSIGNALED exists, so the record supplies the signal
  only when the reaped code is exactly 128+signal
  (take_delivered_signal(pid, status)).

Oracle: WSL GNU bash 5.3.20 script files vs the fixed Linux binary,
5 shapes x {jobs-then-wait, wait-then-jobs} -- byte-identical except
the pre-existing Killed notice path (shell path/pid, #3803 face):
  a. trap "" TERM; exit 5          -> [1]+ Exit 5        rc=5
  b. trap "exit 143" TERM          -> [1]+ Exit 143      rc=143
  c. kill -9 (real SIGKILL)        -> [1]+ Killed        rc=137
  d. kill -TERM default            -> [1]+ Terminated    rc=143
  e. plain exit 7                  -> [1]+ Exit 7        rc=7
Fail-first on master: a/b print Terminated.

Pins: tests/issue3802_delivered_signal_guard.rs 5/5 (trapped shapes
`#[cfg(unix)]`; Windows now has no in-child signal disposition), plus
the #3805 pin 4/4 on Windows and Linux. Neighbouring jobs/wait stems
unchanged (issue2340's two reds are identical on master).
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