Skip to content

fix(windows): foreground Ctrl+Z stop surface — inject_console_ctrl_z + Windows Stopped arms (Refs #3467) - #3746

Merged
caomengxuan666 merged 2 commits into
masterfrom
ai-fix/rubash-3467
Nov 17, 2026
Merged

caomengxuan666 merged 2 commits into
masterfrom
ai-fix/rubash-3467

Conversation

@arookieofc-ai

Copy link
Copy Markdown
Contributor

Root cause

niubash#877 (Windows foreground Ctrl+Z) was ruled not implementable on the
niubash side alone: the engine had no surface to stop a foreground job.
script_driver had only inject_console_ctrl_c() (hard-wired signal 2);
queuing 20 (SIGTSTP) into the mailbox was worse than a no-op — the Windows
foreground wait unwound it as a termsig (exit 128+20 = 148), the non-unix
wait_external_child killed the child, jobs showed nothing, fg had
nothing to resume. All Stopped arms were unix-only.

What changed (companion spec, engine half)

  1. Static face script_driver::inject_console_ctrl_z(), mirroring
    inject_console_ctrl_c, queueing 20 on the self-signal queue
    (kill::note_console_ctrl_z(); unix is a no-op). Ledger updated
    (docs/api-ledger.md, check-api-ledger.py passes, 288 symbols).
  2. Windows Stopped arms in the two non-unix foreground waits:
    • wait_external_child: untrapped TSTP suspends the child via the
      Windows signal_process STOP path, parks a duplicated handle in
      background_children, job_table.mark_stopped(pid, Some(20)),
      prints format_stopped_job_notice, returns 128+20.
    • sleep_interruptibly: same, for the virtual sleep (see carrier).
      A stop is neither a death nor a discard: both arms clear the death
      record + discard mark observe_signals_while_blocked attached, and
      the list continues after the stop (verified against bash 5.2: sleep 5; echo CONTINUED + ^Z prints the notice and still runs CONTINUED).
      Trapped TSTP still runs the trap and does not stop (pinned by test).

Carrier decision: stop-time materialisation

The virtual sleep has no pid, and mark_stopped needs a job entry. On
untrapped TSTP the arm spawns this binary as a real sleeper child
(rubash -c "sleep <remaining>", same exe-resolution chain as the &
respawn), suspends it at once, and parks it as the stopped job.
fg/bg/wait/kill then work through ordinary real-child machinery;
the spawn is lazy (only on ^Z). Rejected: synthetic pid + Executor
sidecar (leaves bg a phantom Running job and wait broken); making
Windows sleep a real child (dispatch-semantics change); notice-only
(fails acceptance); defer.

Verification (Simular box, cross-compiled + wine)

Known gaps (out of scope)

  • Second ^Z during fg (non-unix wait_for_background_pid has no stop
    arm): the child keeps running, the job stays Running.
  • Pipeline waits (spec names only the two arms).
  • kill -STOP <fg-pid> from another session (shell would hang waiting —
    pre-existing).

Only opening the PR, not merging — niubash side follows after this lands.

…+ Windows Stopped arms (Refs #3467)

- script_driver::inject_console_ctrl_z() mirrors inject_console_ctrl_c,
  queueing SIGTSTP (20) on the self-signal queue; kill::note_console_ctrl_z.
- wait_external_child (non-unix): untrapped TSTP suspends the child via the
  Windows signal_process STOP path, parks its handle in background_children,
  marks the job Stopped(20), prints the stop notice, returns 128+20.
- sleep_interruptibly (non-unix): untrapped TSTP materialises a real sleeper
  child (rubash -c "sleep <remaining>", same exe-resolution chain as the &
  respawn), suspends it at once and parks it the same way — the virtual
  sleep's Stopped carrier. fg/bg/wait/kill then work through ordinary
  real-child machinery; spawn is lazy (only on ^Z).
- New tests/issue3467_windows_ctrl_z_stop_regressions.rs: Windows faces
  (wine) + unix neighbours pinning pre-existing unix semantics.
- docs/api-ledger.md: new inject_console_ctrl_z symbol (check-api-ledger
  passes, 288 symbols).
Known gaps (out of scope, see PR body): fg re-stop under the non-unix
wait_for_background_pid, pipeline waits, kill -STOP from another session.
@arookieofc-ai

Copy link
Copy Markdown
Contributor Author

Note on the red niubash builds against this tree check: it fails at the first step (cmp rubash/docs/api-ledger.md niubash/docs/api-ledger.md, byte 61679, line 986) because this PR adds the new ledger item rubash::script_driver::inject_console_ctrl_z (+ 2 prose rows naming it) and niubash master's vendored copy cannot have it yet. The diff between the two ledgers is exactly this change, nothing else — verified locally. The niubash copy syncs after this lands; the tripwire is doing its job. The actual niubash build-against-this-tree step never ran because the ledger step gates it.

@caomengxuan666 caomengxuan666 added bug Something isn't working P2-medium 中:次要缺陷或边缘路径,排期修复 area:jobs jobs, signals, process ownership, coproc labels Nov 15, 2026
@caomengxuan666 caomengxuan666 self-assigned this Nov 15, 2026
@caomengxuan666 caomengxuan666 added platform:windows Divergence specific to the Windows build family:S9 taxonomy S9: trap/job/signal - no subprocess ownership model labels Nov 15, 2026
@caomengxuan666

Copy link
Copy Markdown
Member

Thank you for the PR — and for the detailed root-cause write-up and the wine evidence. This is now queued for captain review: per the owner's rule, external PRs are reviewed by the captain first, and I am not merging anything here.

CI naming (run 43755493006, canary 43755493010):

  • Rust tests (macOS): lib 1245 passed / 1 failed / 4 ignored — the single red cell is the known baseline api::consumer_tests::issue2875_input_procsub_child_runs_as_rubash_shell, not a new failure.
  • GNU regression goldens: lib 1351 passed / 1 failed / 4 ignored — the same single baseline cell.
  • Rust tests (Linux): also fails; the log names the same single cell (issue2875). The full-lib totals line is not visible in the failed log (fail-fast), so I am not quoting a Linux pass count.
  • niubash builds against this tree fails at the ledger cmp step, exactly as you explained in your comment — the new rubash::script_driver::inject_console_ctrl_z item is not yet in niubash master's vendored ledger. That is the expected lockstep gap, not a product failure; the API ledger tripwire itself passes.
  • Green: Compatibility CLI tests, Shell functionality tests, both cross-target checks, Windows tests compile check.

One thing the captain has to rule on before this can move — same-issue dual implementation:

What I did not independently verify (left for captain review): the new nail suite's 3/3 wine + 2/2 unix results are your local claim — CI's nextest table has no new-nail stem, so CI green/red here is not evidence the new suite ran; no Windows real-machine run; GNU-oracle fit for the materialisation carrier; and this PR touches src/executor/trap_exec.rs, a guarded file. Your listed known gaps (second ^Z during fg, pipeline waits, kill -STOP <fg-pid>) are recorded as out of scope, not adjudicated.

Small hygiene ask: please add one line to the body — a "Deleted: none" section (the repo convention asks every PR body to state what it deleted, even when the answer is nothing).

@caomengxuan666

Copy link
Copy Markdown
Member

队长裁决(#3467 双在途):先行链 = #3538 → #3567,本 PR 暂缓、不关闭、不并行合入。

依据(队长核三支 PR 的头/基底/文件面 + 既有裁决记录):

本 PR 的存活价值:钉文件保留待吸收。tests/issue3467_windows_ctrl_z_stop_regressions.rs(417 行)与在飞链的钉(298+38 行)文件名不冲突。#3538 → #3567 合入后,队长按合并形逐格复核本 PR 的钉:与提案 A 载体语义一致的格吸收合入(作者署名保留),编码「停时物化」期望的格按合并形重新定期望或弃。在此之前请勿自行 rebase 或关闭本 PR。

@caomengxuan666

Copy link
Copy Markdown
Member

【WIN-AGENT-AUDIT】PR #3746 第1轮 — 建议:PENDING(缺腿)
head: a7dbde6(gh 实时)state: OPEN(非 draft)
关联 issue: #3467

处置:队长已裁先行链 = #3538 → #3567(虚拟 sleep 载体提案 A 已裁),本 PR「停时物化」属另一条载体路线,暂缓、不关闭、不并行合入。本轮不重跑腿,判词随队长裁决。

@caomengxuan666

Copy link
Copy Markdown
Member

【WIN-AGENT-AUDIT】PR #3746 第2轮 — 建议:PENDING(缺腿已补;队长排序裁决不变)
head: a7dbde6(gh 实时复核未变)base(merge-base): 0a405d8 文件: 9 个 +744/-10
关联 issue: #3467(状态:open)

队长裁决维持:先行链 = #3538 → #3567,本 PR「停时物化」载体暂缓、不关闭、不并行合入。本轮补跑第1轮缺的腿,不改判词。

腿(逐项数字与名字):

  • 钉自跑(head,Windows 原生):issue3467_windows_ctrl_z_stop_regressions 3 passed / 0 failed(15.25s)——virtual_sleep_ctrl_z_stops_job_and_fg_resumes_it、real_child_ctrl_z_stops_job_and_fg_resumes_it、trapped_tstp_runs_trap_and_does_not_stop 全绿;unix 侧 2 条 #[cfg(unix)] 用例在 Windows 编译期裁掉,未跑。
  • fail-first:VOID——钉引用本 PR 新增 API rubash::script_driver::inject_console_ctrl_z,base(0a405d8) 上不存在,整文件编译失败(E0425,建议名 inject_console_ctrl_c)。无法以「原样钉放 base」形式取红名集合;行为面红证据缺位,记 VOID 而非通过。
  • lib 双边(Windows):head 失败名集 {api::consumer_tests::issue2084_session_end_restores_host_process_state} / base 失败名集 {api::consumer_tests::issue2084_session_end_restores_host_process_state} / 差集 ∅(两侧各 1351 passed; 1 failed; 4 ignored;issue2084 已知并行敏感基线)
  • -D warnings:RUSTFLAGS="-D warnings" cargo check --locked --lib --bins → 0 警告
  • 卫生:rustfmt --edition 2021 --check 8 个 .rs 涉及文件 clean;marker-lint / utf8 第1轮已记 clean
  • CI(run 43755493006):Rust tests / GNU goldens / macOS 红名单均只含基线 issue2875_input_procsub_child_runs_as_rubash_shell;niubash builds 红 = ledger Session::cwd 漂移;无本 PR 归因红
  • GNU 对照:本 PR 核心是 Windows 控制台 Ctrl+Z 注入面(inject_console_ctrl_z + Windows Stopped 臂),无直接 GNU 对照腿;语义断言(148=128+20、jobs 列 Stopped、fg 恢复)与 GNU jobs.c job-control 模型同形,但 Windows 注入机制本身无 oracle。unix 侧钉(queued TSTP 不扰 real-child sleep)系 [ecosuite] bats timeout.bats #2/#3: timed-out test's process tree/pipe not reaped, outer run takes full 10s #3488 已有行为的回归钉,未在 Linux 复跑——记未跑。

F 点:无新增(机制层面与 #3538→#3567 的载体冲突已由队长裁决覆盖)

续作记录:无(未动代码、未 push)

未跑/VOID 的腿:

  • fail-first(钉依赖新 API,base 编译不过,见上)
  • unix cfg 用例 Linux 复跑(Windows-only lane,收益低)
  • cargo nextest 不可用,以有界 cargo test 替代

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:jobs jobs, signals, process ownership, coproc bug Something isn't working family:S9 taxonomy S9: trap/job/signal - no subprocess ownership model P2-medium 中:次要缺陷或边缘路径,排期修复 platform:windows Divergence specific to the Windows build

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants