Skip to content

fix(repl): a bare-CR pair at chunk-open is typeahead, not paste data — the submit requeues its partner (closes #420) - #426

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/420-wedge
Oct 19, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/420-wedge

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Verdict

Product face (niubash PasteChunkEditMode), not the harness. The shared driver and the independent harness deliver byte-identical events (proven with a crossterm event probe: every key record arrives, the second CR ~1 ms behind the first); the loss is in the Enter-signature decision.

Root cause (one paragraph)

cr_paste_partner's CrPartner rule (niubash#341) folded a bare CR queued behind a bare CR as the Windows-Terminal KEY_EVENT paste's empty line at chunk-open. The same bytes are two typeahead submits in one pty write — a driver's send("cmd\r\r"), an expect script's back-to-back Enters, and exactly the Ctrl+R accept-Enter + submit-Enter flow of PR #418's E2E (its shared-driver version sent \r\r unpaced; the independent harness's 150 ms pacing is the one variable that made it green). The fold swallowed the first submit and consumed the second: the line echoed, then parked in the PS2 continuation buffer forever — the wedge. It is the #806/#417 typeahead family's state machine, but the specific decision (the fold at chunk-open) is not covered by #417's pushback-reinjection scope; coordination note left there.

Fix

At chunk-open a CR partner is no longer paste evidence (GNU typeahead semantics): the first CR submits, and the probe-consumed partner CR is requeued verbatim to the head of the input stream — WriteConsoleInputW in production (the #417 requeue face; the in-process pushback is forbidden there by the #341 batch-crossing invariant), push-front on the scripted test queue. A chunk now opens only on real paste evidence: the LF partner (humans never send Ctrl+J) or an already-pending chunk — the mid-chunk fold keeps #341's live-paste empty-line semantics, and the WT owner-script guard stays green (a bare-CR feed executes per line, the documented degraded shape — identical output).

Baseline five of #420 (byte-stable on master; none of them the wedge)

test verdict closure
continuation_single_quote test-expectation bug the closing ' makes the word literal; GNU bash 5.3 (msys oracle, re-run 2026-10-13) prints \ verbatim and niu matches bash. Re-pinned to the oracle semantics.
continuation_subshell_paren engine parser divergence msys bash accepts (A;B);) (subshell runs, exit 0); rubash's parser rejects the lone )'. Filed for rubash — out of this repo. Test pins the clean closing )'.
ctrl_c_interrupts_external_command rubash exec-lookup bug bare ping resolves via type -a but the exec path reports command-not-found on hosts whose System32 ships PING.EXE uppercase (case-sensitive lookup; where.exe sees the file, the full path runs). Tests invoke the absolute path; rubash follow-up.
ctrl_d_after_background_job_exits same rubash lookup bug same absolute-path closure.
gitbash_factory_prompt test-design gap the branch segment spawns git through the session PATH; the System32-only sandbox never had git and the cd submit itself always ran. The test now prepends the host git's dir.

New regressions (echo-proof, execution-level)

Unit-level: the open-fold contract is re-pinned (paste_chunk_detector_open_cr_pair_submits_and_requeues_420, pushback-invariant kept), the mid-chunk fold re-pinned (..._midchunk_cr_pair_still_folds_341), and the #341 protocol sweeps (wt_bare_cr_paste_survives_*) pass unchanged.

Verification (this host, Win10 19045, --test-threads=1, rebased on master @ 117147a incl. #418's reedline 0.52)

  • cargo test -p niubash-runtime --lib: 552 passed / 0 failed
  • --test interactive: 81 passed / 0 failed (5 ignored, pre-existing pins). One ctrl_d host-noise flake in one of three full runs (green alone and in the following full run) — the documented dev-box noise family; CI's clean runner is the gate.
  • repl_command 11 · completion_probe 29 · smoke_1_3_0 11 · issue182 1 · issue359 2 · compat 48 — all green.
  • GPL red line: no GPL code introduced (original MIT code + windows-sys bindings).

Coordination

…— the submit requeues its partner (niubash#420)

The #341 CrPartner rule folded a bare CR queued behind a bare CR as the
WT KEY_EVENT paste's empty line at CHUNK-OPEN. The same bytes are TWO
TYPEAHEAD SUBMITS in one pty write — a driver's send("cmd\r\r"), an
expect script's back-to-back Enters, the Ctrl+R accept-Enter followed by
the submit-Enter (PR #418's E2E, which is where the wedge surfaced). The
fold swallowed the first submit: the line echoed and parked in the PS2
continuation buffer forever — the shared-driver wedge of niubash#420.

GNU typeahead semantics win: at chunk-open a CR partner is no longer
paste evidence. The first CR SUBMITS; the probe-consumed partner CR goes
back to the head of the input stream verbatim (WriteConsoleInputW — the
niubash#417 requeue face; the in-process pushback is forbidden there by
the #341 batch-crossing invariant) to submit the empty line, or to submit
the loaded Ctrl+R match, on its own dispatch. A chunk now only opens on
paste evidence: the LF partner, or an already-pending chunk (the mid-
chunk fold keeps #341's live-paste empty-line semantics, and the WT
owner-script guard stays green: the bare-CR feed executes per line, the
documented degraded shape).

Baseline five of niubash#420 (byte-stable on master, none of them the
wedge):
- continuation_single_quote: the expectation wanted expansion inside
  single quotes; GNU bash (5.3 msys oracle) prints the word literally
  and niu matches bash. Test re-pinned to the oracle semantics.
- continuation_subshell_paren: the trailing ');)' is accepted by msys
  bash (subshell runs, exit 0) but rejected by rubash's parser — engine
  divergence filed for rubash; the test now pins the clean ')) close.
- ctrl_c_interrupts_external_command / ctrl_d_after_background_job:
  bare 'ping' resolves via 'type -a' but the exec path reports command-
  not-found on hosts whose System32 ships PING.EXE uppercase (rubash
  case-sensitive lookup); the tests invoke the absolute path, keeping
  the Ctrl-C/Ctrl-D intent.
- gitbash_factory_prompt: the branch segment spawns git through the
  session PATH, which the System32-only sandbox never had — the test
  now prepends the host git's dir.

New regressions: typeahead_bare_cr_pair_submits_per_line_420 and
ctrl_r_accept_submit_in_one_burst_420 (echo-proof, execution-level).

Verification (this host, Win10 19045, --test-threads=1): runtime lib
552 passed / 0 failed; interactive 81 passed / 0 failed (one ctrl_d
host-noise flake observed in one of three full runs, green alone and
in the following full run — the documented dev-box noise family);
repl_command 11, completion_probe 29, smoke_1_3_0 11, issue182 1,
issue359 2, compat 48. No GPL code introduced.
@caomengxuan666

Copy link
Copy Markdown
Member Author

独立评审结论:APPROVE-WITH-NITS

独立代码评审(worktree niubash-cr-426,head c564137,基于 master 117147a,MERGEABLE 已复核)。全部验证实做复跑,结论如下。

BLOCKER 清单

无。逐项复核未发现任何一条粘贴合同变形或真回归遮掩。

逐验证点(全部实做)

  1. 粘贴合同保真(最重)— 全绿:cargo test -p niubash-runtime --lib -- --test-threads=1 paste_chunk wt_bare_cr = 24/24;全套 lib 552/0。chunk 内折叠语义(midchunk_cr_pair_still_folds_341)、flush-before-submit(paste_with_same_burst_enter_submits_on_first_enter 等全套 reassemble/first-enter 测试)、"pushback 永不持有裸 CR" 不变式(pushback_never_holds_a_bare_cr_341,代码核读确认 CrPartner 在 chunk-open 只走 unread、mid-chunk 只折叠,均不入 pushback)、WT owner-script 守卫(wt_paste_bare_cr_key_event_shape_runs_owner_script_341,76 行/16 空行,本 PR 未改动该测试)——全部保持绿。
  2. fix(repl): a DSR-silent terminal keeps its shell; TAB completion commits (closes #373) #418 交互 — 无回退:tests/issue373.rs 3/3;新增两条执行级回归在本套件内通过:typeahead_bare_cr_pair_submits_per_line_420(共享 driver send("echo $W420A\r\r") = 两次提交,echo-proof)、ctrl_r_accept_submit_in_one_burst_420(fix(repl): a DSR-silent terminal keeps its shell; TAB completion commits (closes #373) #418 Ctrl+R accept+submit 单突发,无间隔无 pacing)。completion_probe 29/0 覆盖 TAB 窗面。
  3. unread 面审查 — 通过,一处注释失实见 NIT-1:crossterm 0.29 Windows source 逐条 read_single_input_event()(windows.rs:51,无内部批缓冲),重注入记录对下一次 read 可见;重注入 CR 在自身 dispatch 时探针再探、无伙伴则提交空行——推进单调,无循环;进程内 pushback 禁令未被绕过(scripted 队列 push_front 保序;生产走 [P2][input] PasteChunkEditMode's Enter-signature probe consumes kernel typeahead at commit: the accepted command's 'read' sees an empty console queue (rubash#806 host half) #417 原语 WriteConsoleInputW+OwnedHandle duplicate,stdin_is_console 守卫,写失败退化为丢失一次空行提交、非楔死)。KEY_EVENT 编码(VK_RETURN/0x1C/UnicodeChar 0x0D/bKeyDown 1/repeat 1)与本管道对真实 Enter 的消费完全等效(Release 事件在探针与 translate 两处本就按惰性丢弃,缺 key-up 不可观测)。
  4. 基线五测试改判复核 — 全部属实,无遮掩:五个 master 原形在我环境对新二进制逐条复跑,全部复现失败——single_quote 期望单引号内展开(GNU bash 5.3.0 msys oracle 实跑:输出字面 $CONT_SQUOTE_OUT/closed,原期望语义错误);subshell_paren 的 );) 在交互 PS2 路径报干净语法错(面板显示整行完整渲染后才报错——非字节丢失/非楔死;GNU bash 5.3 oracle 实跑容忍该尾部);ctrl_c 与 ctrl_d 复现 niu: ping: command not found(实机验证:System32 确为 PING.EXE 大写,type -a ping 解析成功而裸名 exec 127——真引擎缺陷);gitbash 旧形失败(System32/Windows 无 git.exe 实证,分支段无法渲染)。五处改法均保留原测试意图,且 #[ignore] 数量 master/PR 均为 5,无静默 un-ignore。
  5. 回归全套 — 绿:lib 552/0、interactive 81/0(5 个预存 ignore)、compat 18/0(--ignored)、repl_command 11/0、completion_probe 29/0、smoke 13/0、issue182 1/0、issue359 2/0、issue373 3/0、keyevent_record_probe 3/0(--ignored),全部 --test-threads=1。cargo fmt --check --all 干净(CI 唯一格式门)。cargo check --all-targets 0 warning。
  6. 夹带扫描 — 干净:diff 文件集恰为 repl.rs + typeahead_guard.rs + tests/interactive.rs(typeahead_guard.rs 改动即 unread 面所属:stdin_console_handle() + OwnedHandle 可见性放宽,合理);无工作流改动;touched 文件无 GPL 文本;进程终止仅预存 driver Drop killer(5s 有界、只杀自身子进程),driver.rs 本 PR 零改动。

非阻塞 NITS

  • NIT-1(注释失实,建议下轮一行修正):repl.rs 多处(unread 字段 doc、"head of the input stream" 措辞)声称重注入回到输入流头部。MSDN WriteConsoleInput 明文:"places input records into the input buffer behind any pending events"——生产路径是尾部追加。可观测后果良性:canonical 楔形(队列空)尾=头,行为正确;同写多行突发(cmd1\r\rcmd2\r)中重注入 CR 落到后续突发内容之后,空行提交迁移到突发末尾(非空行严格保序)。scripted 测试队列 push_front 建模的是头部语义,比生产保真度略强。建议注释改为如实描述尾追加及该良性行为。
  • NIT-2(新 clippy lint):repl.rs:734 UnicodeChar: 0x0D as u16 触发 clippy::unnecessary_cast(本 PR 新引入;master 全 crate 本就 100+ clippy 错、clippy 非 CI 门,故仅建议顺手删 as u16)。
  • NIT-3(报告计数漂移):实现报告"compat 48 / smoke 11"实为 18 / 13(全绿,仅计数口径);subshell_paren 的 rubash 分歧建议在测试注释补票号,并注明该分歧为交互 PS2 解析路径特有——niu -c '(printf a; printf b);)' 与 stdin 脚本模式均接受同形(实测 exit 0),ticket 应写明以免误导排查方向。

不合并。意见来自独立评审 worktree,复核后可收口。

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