Skip to content

test(3051): pin PTY byte-level ^D EOF deferral with stopped jobs (Refs #3051) - #3110

Merged
caomengxuan666 merged 3 commits into
masterfrom
fix/3051-pty-eof-deferral-stopped-jobs
Nov 10, 2026
Merged

caomengxuan666 merged 3 commits into
masterfrom
fix/3051-pty-eof-deferral-stopped-jobs

Conversation

@caomengxuan666

@caomengxuan666 caomengxuan666 commented Nov 8, 2026 •

Copy link
Copy Markdown
Member

Refs #3051

根因

交互 PTY 下的字节级 ^D(apply_edit_char 在空缓冲上见 \x04 → EditOutcome::Eof)在 run_interactive_stdin(src/script_driver.rs)的三处消费点直接置 eof = true,根本不查作业表:Unix tty 分支、Windows RawConsole 分支、cooked-line 字符循环。共享的 EOF deferral(Executor::defer_interactive_eof_for_jobs)只挂在管道/脚本 Ok(0) 与 Err 两臂上(#2397),所以有 stopped 作业时 ^D 直接退出。

GNU 侧:^D 在空提示行即 EOF 单输入单元——parse.y:516-523(yacc_EOF 动作)调 handle_eof_input_unit()(parse.y:6973),其 roll this/last 为 exit_builtin 并跑同一 exit_builtin;builtins/exit.def:100-131 exit_or_logout 扫 live 作业表:有 STOPPED(checkjobs 开时 RUNNING 也算)即 stderr 报 There are stopped jobs.(+ 列表),pin this/last 为 exit_builtin,返 EXECUTION_FAILURE 拒绝退出;下一次 ^D/exit 因 exit_immediate_okay 立即退出。

修法(已落实,0d3badef)

  • Unix tty 分支 / Windows RawConsole 分支 / cooked-line 字符循环:空缓冲真 EOF 时先走 defer_interactive_eof_for_jobs();defer 则继续读(下一 EOF 因 pin 住的 Exit 类立即退出),否则按原路置 eof。echo 顺序与 GNU 一致:exit/logout 先打(exit.def:59-62),再查作业表。
  • 挂起(pty master 关闭)分类不变:SIGHUP 结算优先于折叠,不走 deferral;非空缓冲的 accept-line 形亦不走 deferral。
  • 不动:Ok(0)/Err 两臂([bug] 交互退出时作业保护缺失:checkjobs 运行作业不延迟、停止作业恒不保护 #2397 已绿)、存储形态、src/lexer/continuation.rs、docs/api-ledger.md。单文件 src/script_driver.rs,+51/−4。

队长复核前自验(车道自跑)

  • 钉 @ 修复树:4 passed / 0 failed(issue3051_pty_eof_deferral,15.67s;脚本内重跑 5.62s)
  • 钉 @ 真基底移植 fail-first:2 passed / 2 failed(ctrl_d_once_* 与 ctrl_d_twice_* 红,两个对照形绿;基底 1c132f68 干净 worktree 移植,25.30s)
  • lib 头/基底双边:头 1200 passed / 6 failed / 4 ignored,基底 1204 passed / 2 failed / 4 ignored;失败名集不交:头 6 个为 api::consumer_tests(issue822 winsize + 4× GAP-13)与 fd::unix spawn_whitelisted,基底 2 个为 builtins::kill(handshake nonce + pdeathsig)——均为时序/全局态敏感形,与本修法面(script_driver EOF)无交。孤立重跑裁决:8/8 通过(头 6 格 + 基底 2 格各 1/0),全量 lib 两跑的失败均为负载下时序 flake,无一为本修引入(见 REPORT §5)。
  • 邻茎:全绿——issue2397 8/0、issue2834 1/0、issue2835_2837 2/0、issue2836 2/0、issue2849 1/0
  • RUSTFLAGS="-D warnings":cargo check --locked --lib --bins rc=0,无警告
  • fmt / hygiene / CR:cargo fmt --check rc=0;marker-lint OK(117 registry consts, 265 allowlisted sites);utf8-boundary hygiene clean;api-ledger 281 symbols 全在;CR 计数 0
  • GNU 探针:PTY 探针(script(1)+父 bash -i)——GNU 1×^D defer、2×^D 首 defer 次退出;修复后 rubash 同形。管道 \x04 形:GNU 与修复后 rubash 均 exit + There are stopped jobs. + 次 EOF 退出,逐字节同形(除 rubash 沿用既有 raw 回显多一个 \x04 字节)。

UNVERIFIED-BY-CAPTAIN

本 PR 删除了什么

无(钉文件新增;修法为三处 Eof 消费点加同一 deferral 调用,无文件/函数/行为删除)。

…#3051)

GNU: parse.y handle_eof_input_unit rolls this/last with
exit_builtin and runs the same exit_builtin, so a ^D at an empty
prompt defers on stopped jobs (builtins/exit.def:100-131) and the
next ^D exits at once. Rubash's byte-level ^D path
(apply_edit_char -> EditOutcome::Eof) sets eof directly with no
job scan, so the shell exits immediately.

Pins: ^D once defers (banner + child alive), ^D twice exits on
the second, ^D with no jobs exits at once (control), piped-stdin
EOF with a stopped job still defers exactly once (#2397 control).
Fail-first on base 1c132f6: 2 passed / 2 failed.
…ferral (Refs #3051)

PTY byte-level ^D on an empty buffer ended the session at once even
with stopped jobs: the three EditOutcome::Eof consumers in
run_interactive_stdin (Windows RawConsole branch, Unix tty branch,
cooked-line chars loop) set eof=true without consulting the job
table, while the piped/script Ok(0) and Err arms already defer via
Executor::defer_interactive_eof_for_jobs (rubash#2397). GNU's
handle_eof_input_unit runs the same exit_builtin for every EOF
(parse.y:516-523, 6973; builtins/exit.def:59-62 echo first, then
exit_or_logout checks STOPPED jobs; the deferral pins this/last to
Exit so the next EOF is immediate). Route all three byte-level EOF
sites through the same deferral; hangup EOFs (rubash#2233) and the
nonempty-buffer accept-line shape still fold at once.
@caomengxuan666
caomengxuan666 merged commit f7aee5c into master Nov 10, 2026
11 checks passed
caomengxuan666 added a commit that referenced this pull request Nov 11, 2026
第二波钉先行 J1 组(#2340 #2697 #2769 #2777):修法面被在飞 PR #3110(#3051,jobs/table 同面)占着,本 PR 只落钉 + 根因/修法设计(车道 REPORT),不写产品代码。门开后修法车道按 REPORT 设计动。

Refs #2697 — tests/issue2697_subshell_member_death_notice_regressions.rs(5 格):前台子 shell 成员被 SIGXFSZ 杀死时期望裸成员文本(通知由子 shell 自身作业表视角打印);exec 形与后台子 shell 作业两控制格期望整段子 shell 文本。

Refs #2769 — tests/issue2769_death_notice_line_stamp_regressions.rs(5 格):边界通知行戳 = 读位置行(下一命令行 / EOF 末行 +1 / 多行复合的终点行);前台通知格守即时打印方向(戳死亡命令本行)。

Refs #2777 — tests/issue2777_stopped_job_state_regressions.rs(7 格):深审 B4 原会话(kill -STOP $! 后立即 exit)期望 "There are stopped jobs.";含 jobs 列表状态格、STOP→CONT 链路格、TSTP 形、PTY 无观察点格、脚本模式控制格(GNU 脚本内显 Running,防过修)。

Refs #2340 — 已由 56dc41a 修复且钉已在仓(tests/issue2340_wait_job_retention_regressions.rs,9 格),本 PR 不含 #2340 新钉;本车道在基底上复跑既有钉存证,供关单裁决。

期望值全部以 GNU bash 5.3.20 oracle 脚本文件实测为准(2026-11-09);fail-first 逐格结果见车道 REPORT。

## 本 PR 删除了什么

无(纯测试新增)。净行数 +960 行(3 个新测试文件),未删除任何文件或代码。

## 队长复核附记(rebase 轮,2026-11-11)

PR #3319(Refs #2340 的修法本体)合入 master(71de8b76)后,本 PR 头 c2a5ab1 与现 master 的组合头(eca5e5ca,合并无冲突、产品面与 master 逐字同)上四茎复跑,卷宗 review-3180-rebase/CAPTAIN-VERIFY.md:

- issue2340 茎 9/9 四连绿;窗口强制探针(%1 于 0.3s 处杀 %2、死亡落在 wait 阻塞期内)组合头 5/5 输出 done 1、与 GNU oracle 5/5 同形,基底 0/5。基底茎采样另见 survivor 删除签名三形(8/1、6/3、8/1)。
- issue2697 茎双边皆 1 过 4 红、红名集与登记四名逐字同;issue2777 茎组合头 5 过 2 红两轮(登记两名,皆红于 kill 后 wait 状态 W 断言),整茎约 16.4 秒有界完成;issue2769 茎双边皆 2 过 3 红,eof 格经多采样裁定为 EOF 死亡通知的出现竞速(失败原文为通知缺席、戳值恒对,GNU 同构造 40/40 确定),属既存产品面、非本轮引入。
- lib 组合头 1243 过 0 败 4 忽略、基底 1206 过 0 败 4 忽略,失败名集双边差为空;fmt、全树 UTF-8 卫生、marker-lint 皆 rc=0;RUSTFLAGS 带 -D warnings 的 lib 与 bins 检查 rc=0(带旗痕迹亲核),四茎逐个 scoped 同旗检查 rc=0;全树 tests 同旗检查的红仅在 master 既存 tests 警告族(issue2584、issue2514 两文件,不在本 PR diff 内)。
- 本 PR 合入后,#2340 由队长以证据评论另行处置;#2697、#2769、#2777 保持开启,钉即其 fail-first 证据。
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