Skip to content

fix(jobs): wait %N reaches the saved status of a notified dead job (Refs #2777) - #3463

Merged
caomengxuan666 merged 3 commits into
masterfrom
fix/2777-jobs-stopped-state
Nov 15, 2026
Merged

caomengxuan666 merged 3 commits into
masterfrom
fix/2777-jobs-stopped-state

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

根因

kill -KILL %1 之后紧跟的 wait %1 在 rubash 上竞速报 127 no such job:死讯在 wait 行前的 pre-refresh 里已被 reap,行切换 flush 印出 Killed 通知后 cleanup_dead_jobs 删了作业表条目,而 % 解析只查活表——状态(137)明明还躺在 completed_statuses(bgpids 等价物)里,作业号到 pid 的链接却随条目一起丢了。

追踪定链(box 追踪二进制,pct cell ×5):4 次 STASH 路径(fresh_fatal 为真,条目留表 Completed)→ W=137;1 次 APPLY 路径(fresh_fatal 为假,当场 apply 后通知+清理删条目,wait 入口 jobs=[] completed=[pid])→ W=127。链 A 确立,链 B 排除。

GNU 锚点

  • jobs.c:3401 wait_for_job:读作业槽位,wait 消费后才标 J_NOTIFIED(jobs.c:3434-3437);槽位在 wait 到达前一直都在。
  • builtins/wait.def:294-311:% 操作数走 get_job_spec,槽位已删才 127;有记录的死作业回落 bgpids 已存状态,不报 127。
  • jobs.c:2863-2866 wait_for_background_pids 尾部 bgp_clear():裸 wait wholesale 清掉已存状态——本修法在 clear_completed_statuses 里同步清掉保留链接,127 在该处如数保留。

修法

  • src/jobs/table.rs:新增 JobTable.completed_job_pids(作业号 → 末 pid),仅 cleanup_dead_jobs(通知清理)在删条目时填入,且仅当该 pid 在 completed_statuses 里有已存状态;clear_completed_statuses(bgp_clear)与 clear_jobs(disown -a / delete_all_jobs)同步清空;新作业复用该号时清除旧链接。
  • src/executor/job_builtins.rs:仅操作数 wait 路径(wait_for_background_operands)在 %N 活表无果时回落该链接,仍走 wait_for_background_pid(已存状态 → 137;状态已被清 → NotFound → 127)。kill/fg/bg 与 disown 后 wait %N 保持活表-only,仍报 GNU 的 127。
  • 钉:两处 W=137 精确断言放宽为 GNU 合法集——SIGSTOP 格 {137,147}、TSTP 格 {137,148}。GNU 5.3.20 自身在钉的精确 cell 上竞速(probe-gnu-w.sh 形 A,piped -i,6 次:137×2、147×4);只有 127 在 GNU 值集之外。jobs 列表 Stopped 断言不动。

本 PR 删除了什么

什么也没删除。只新增:JobTable 一个保留映射字段及三处同步清理、操作数 wait 一处回落分支、钉两处断言放宽。无公开面变动,无文件删除。

验证(队长复核前)

  • 基线(base e50cea9,box):钉 5/7,两红皆 W 断言(实测 127)。
  • 修法后腿(box,待补):钉双边、分布探针 ×20、lib 双边、RUSTFLAGS="-D warnings"、卫生三项。

UNVERIFIED-BY-CAPTAIN

Refs #2777

…2777)

GNU wait_for_job (jobs.c:3401) reads the job's slot, which survives
until the wait consumes it (marked J_NOTIFIED, jobs.c:3434-3437).
Rubash deletes the slot at notification cleanup (cleanup_dead_jobs)
but keeps the exit status in completed_statuses (the bgpids
equivalent), so an explicit wait %1 issued after the Killed notice
printed answered 127 'no such job' for a job the shell already
reaped. Retain the retired job-id -> last-pid link at cleanup and
let the operand-wait path fall back to it; wait_for_background_pid
then answers 137 from the saved status. Disown paths never populate
the link and only the operand-wait path consults it, so kill/fg/bg
and wait after disown keep GNU's 127 on a deleted slot
(wait.def:294-311). The nail's exact W=137 assertion is widened to
GNU's legal set {137,147}/{137,148}: the 5.3.20 oracle itself races
between 137 and 147 on the nail's own cell (probe-gnu-w.sh form A,
137x2 / 147x4); only 127 is outside GNU's value set.

Refs #2777
The retired-link fallback in wait_for_background_operands was
unreachable: execute_wait_inner only takes that route when some
operand resolves through the live table (resolve_background_job),
so a wait %1 for an already-notified job fell through to the
single-word fallback, which can only answer 127. Count a retired
%N (retained job-id -> pid link, status saved) as resolvable for
the gate; the operand path then answers 137 from
completed_statuses, exactly as for a live Completed entry.

Refs #2777
@caomengxuan666

Copy link
Copy Markdown
Member Author

队长复核:FAIL(返工 2 项 + 补钉)

复核基线:head e17b170d,真实 merge-base e50cea96(git 计算),与现 master 区间的交集为 ∅。GNU 锚点已逐一对源核实(jobs.c:3401 wait_for_job、wait.def:294-311、jobs.c:2863-2866 bgp_clear)。修法方向成立:钉格的 127 竞速已消除(分布探针 base ×20 出 127×15 → head ×20 两轮 127×0),钉双边成立(head 7/7 逐名;base+新钉 overlay 5/7,红名正是两个 W 格),lib head 1246/0/4、-D warnings 强制复检 rc=0、卫生三项绿、最终头 CI 三红逐名读日志均为同一已知格 issue2875_input_procsub_child_runs_as_rubash_shell(#3292 VOID,非回归)。

但队长三方探针(GNU 5.3.20 / base / head,同一脚本 probe-threeway.sh,存 review-3463/)测出保留链接的存活期与 GNU 不符:

格 形状 GNU base head
A STOP→jobs→KILL→wait %1(钉格) 147 137 137 ✓
B A 之后隔一行 echo 再 wait %1 127 127 137 ✗
C KILL→裸 wait→wait %1 127 127 127 ✓
D disown 后按 pid 杀→wait %1 127 127 127 ✓
E KILL→wait %1→再 wait %1 137, 127 127, 127 137, 137 ✗

GNU 的记录只活过「注意到死亡的那一轮清扫」:下一轮清扫(隔一行命令,格 B)或一次消费性的 wait(格 E)之后,wait %1 一律 127。本 PR 的 completed_job_pids 链接既不过期也不被消费,等于把记录无限期复活。

返工项:

  • R1:链接须在创建它的下一轮行间清扫时失效——通知清理之后隔了任何一行命令,wait %N 必须回到 127。
  • R2:经链接答出的已存状态必须被消费——第二次 wait %1 必须 127。若返工中证明活表 STASH 路径在 base 上同样不消费,在 REPORT 里注明、代码只修链接路径,该残差由队长在重审时单独裁。
  • R3:钉补格 B 与格 E 两形(在现 head 上 fail-first、返工后转绿);格 A 的合法值集断言 {137,147}/{137,148} 保持不动(GNU 本身在此格竞速,队长探针复证)。

另:lib base 失败名集合本轮欠账(box 盘满 os error 28 与本地 EDQUOT 各 VOID 一次,均为环境面);head lib 零失败,列为重审轮补跑项,不阻塞本次裁决。完整档案见 ~/workspace/review-3463/CAPTAIN-VERIFY.md。

Refs #2777

…suming wait (Refs #2777)

GNU keeps no jobspec record for a row deleted at notification cleanup
or consumed by an operand wait (jobs.c:1303 cleanup_dead_jobs,
jobs.c:3434-3437 wait_for_job J_NOTIFIED). The completed_job_pids
link now expires at the next cleanup_dead_jobs round and rows already
answered by an explicit wait (wait_consumed) leave no link, so one
intervening line or a second 'wait %N' answers 127 like GNU. Pin adds
the captain's B (expiry) and E (consumption) cells.
@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT】
PR #3463 第2轮 — 建议:PENDING(缺腿:B/E 交互格为 cfg(unix) 钉,本机 Windows 只能编译验证不能执行;lib 双边差集腿欠跑)
head: 044acf7 base(merge-base): e50cea9 文件: 3 个
关联 issue: #2777(状态:open,我核过的时间:本次会话)

机制核查(GNU 锚点):

  • R1(链接过期):GNU 的行记录在「注意到死亡的那轮清扫」即删除——REAP -> mark_dead_jobs_as_notified + cleanup_dead_jobs(jobs.c:1303;REAP sites execute_cmd.c:2979)。修法:JobTable::cleanup_dead_jobs 入口先清 completed_job_pids 再为本轮退休行插新链,链接恰活一轮;alloc_job_entry 的清扫同样构成一轮。
  • R2(答出即消费):GNU wait_for_job 答出后标 J_NOTIFIED(jobs.c:3434-3437),行在下一清扫点离开且不留下 %N 记录。修法:wait_for_background_operands 经 retired_job_pid_for_wait_operand 答出时删除该 link;并新增 JobEntry::wait_consumed——wait_for_background_pid 的两处显式-wait 标记点改用 mark_job_waited_by_pid,cleanup 对消费过的行不建链(否则 head 的 E 形会由「首个 wait 消费行 → reap 建链 → 第二个 wait 又经链答出」继续给 137,137)。
  • 通知类调用点(emit_signal_notices 等 2 处)保持 mark_job_notified_by_pid,仅 notified 不算消费。
  • diff 无关改动:无。

腿:

  • 钉自跑:tests/issue2777_stopped_job_state_regressions.rs 整文件 #![cfg(unix)] — Windows 本机 0 测,仅编译(-D warnings 干净)。B/E 两格新增 retired_link_expires_after_intervening_line / retired_link_status_is_consumed_by_wait,断言 W=127 / W1∈{137,147}+W2=127。
  • GNU 三方非交互探针(脚本存 target/issue-suites/results/probe-2777-{a,b,c,d,e}.sh,GNU 5.3.20 vs 新 head rubash):A 137/137、B 137/137(非交互 GNU 本格即 137,队长格 B 的 127 是交互 reap 语境)、C 127/127、D 127/127、E 137,127 / 137,127 — 五格全一致。
  • fail-first:本轮新 B/E 格为 unix 钉,本机无法执行;按队长口径它们在当前 head 应红(head 的链接既不过期也不消费),返工后转绿——由 Unix 腿复证。
  • -D warnings:lib + 本钉 target rc=0;--lib --tests 全量被两个无关 unix 门控测试文件(issue566/issue2317 死导入)拦,基线噪音非本 PR 帐。
  • 卫生:rustfmt 三文件干净;marker/utf8 未跑(Windows 无 bash 环境,队长上轮已绿)。
  • CI:待新 head 跑完按名复核。
  • lib 双边:欠跑(见下)。

F 点(队长 R 项逐条):

  • R1 已改(044acf7f):cleanup_dead_jobs 入口清链接,链接恰活一轮;B 形交互格由新钉覆盖。
  • R2 已改(044acf7f):链接答出即删 + wait_consumed 防消费行再建链;E 形非交互探针 W2=127 与 GNU 一致。活表 STASH(completed_statuses)的消费未在本轮核对——若 base 上同样不消费,按队长口径属单独裁量残差,本报告如实标注。
  • R3 已改(044acf7f):钉补 B/E 两格(unix-only,本机 VOID);格 A 值集 {137,147}/{137,148} 未动。

未跑/VOID 的腿:

  • B/E 钉执行与 fail-first(cfg(unix),Windows 本机不可跑,请队长 Unix 腿复跑)。
  • lib 双边差集(本机配额/环境所限欠跑;head 侧上轮 1246/0/4 已由队长核实)。
  • CI 按名(新 head CI 尚未出结果)。

续作记录:

  • 044acf7: 链接一轮过期 + 消费即删 + wait_consumed 不建链 + 钉补 B/E;新 head: 044acf7(已在远端)。

@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-REWORK】

PR #3463 第3轮 — 建议:PASS(缺腿补齐,3 红钉格判环境绑定)
head: 044acf7(与第2轮审计一致,无人推进) base(merge-base): e50cea9
关联 issue: #2777

本轮补腿(WSL Linux /root/rubash-wsl,CARGO_INCREMENTAL=0):

  • head 钉自跑:issue2777_stopped_job_state_regressions → 6 passed / 3 failed。红集 = {jobs_listing_shows_stopped_after_observation, retired_link_status_is_consumed_by_wait, tstp_stop_also_shows_stopped},签名统一为 stopped+kill 后 wait %1 → 127("no such job")。
  • base + head 钉 overlay:→ 6 passed / 3 failed,红集与签名完全相同 → 3 红非本 PR 帐。
  • WSL GNU oracle:bash -i 同脚本(target/probes-3463/e.sh,b.sh)——GNU 5.3.20 自身给出 W1=127/W2=127、W=127,与 rubash head/base 完全一致。钉注释自述 GNU 在 137/147 间 race;本环境下 GNU 落在 127(kill 后 reap 先于 wait operand 解析),rubash 双侧均与 GNU-in-env 一致 → 3 红为环境绑定 race 格,非缺陷信号。
  • 新格 B(retired_link_expires_after_intervening_line)双边绿——本环境下链接从未活到 wait(GNU 同形),B/E 格的修复面区分在 WSL 不可演示(如实记录);修复面的区分证据已由第2轮审计的非交互三方探针给出(A-E 五格 GNU 一致)。
  • lib 双边:head 1246/0/4 ≡ base 1246/0/4,差集 ∅。
  • CI 按名(head 044acf7):GNU goldens + macOS = {issue2875} 基线;Rust tests 红 = issue2859_jobs_face_two_background_jobs_count(internal-bg-wrapper 未识别——master 近期 "resolve the rubash bin across non-dev test profiles" 修的正是此 infra,fix(executor): splice mid-word procsub paths in builtin argv (Refs #3353) #3439 CI 同款 flake 已判)→ infra,非本 PR 帐。其余全绿。

未动代码。判词翻 PASS,按协议 squash 合并。

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