Repository navigation
fix(repl): the submit writes the probe-parked typeahead back to the console queue (niubash#417) - #433
Merged
Merged
Conversation
…onsole queue (niubash#417) The Enter signature probe reads the kernel queue's next record to decide a bare Enter. With typeahead behind it — the next line of a fast burst — that record is not paste evidence, so it was parked in the IN-PROCESS pushback while the Enter submitted. The accepted command's engine `read` then reads the KERNEL queue next, which cannot see the in-process deque: with nothing else queued the read blocks forever, and the parked keystrokes are unreachable until the next prompt (the #417 wedge). #426 landed the unread re-injection face (WriteConsoleInputW) for #420's partner CR; this completes the chain for the parked typeahead. Parse_event now flushes the pushback to the input stream's head whenever a batch ends in an Enter — the boundary where reedline stops reading and a command may read. Batches that do not end in a submit keep the park (the next parse_event drains it FIFO, nothing left the read loop). The face grew to carry the shapes the pushback can hold, not just a bare Enter: - `win_unread` synthesizes KEY_EVENT records for any key Press the console parser can produce, mirroring conhost's own conventions (control code in uChar + base letter in the VK for chords, VKs inverse to crossterm 0.29's parse table for special keys, one record per UTF-16 unit for non-BMP chars) so reedline's parser and the engine's console reader decode back the exact event that was consumed. Pure mapping, unit-tested off-Windows. - `typeahead_guard::requeue_console_input` inserts at the queue's HEAD: WriteConsoleInputW appends at the tail, but the probed events sat ahead of everything still queued — a tail append would let line 2's 'ead...' run before the parked 'r' of 'read' and shred the burst. The pending records are drained first and rewritten behind the re-queued ones, so the queue reads the exact order the probe found. #420's partner-CR requeue shares the face and inherits the same order guarantee. The pushback still never holds a bare CR (#341): the probe pushes only non-Enter keys, and an Enter batch's park is exactly that probe's own pushes, so the writeback can never inject a CR across a batch boundary. New witnesses: - probe_parked_typeahead_reaches_engine_read_417 and typeahead_burst_read_line_gets_parked_key_417 (tests/interactive.rs, echo-proof execution level, #420's two test forms): both RED on unpatched master (read blocks on the emptied queue) and GREEN here. - Detector-level: the submit requeues the parked key at the stream's head ahead of still-queued events (head-vs-tail pinned), the two former park-in-pushback assertions re-pinned to the requeue contract, and the record-synthesis mapping unit tests (chars, chords, special keys, surrogate pairs, releases/unparseable shapes). Verification (this host, Win10 19045, --test-threads=1): runtime lib 558 passed / 0 failed; interactive 83 passed / 0 failed (5 ignored, unix-only legs); issue373 3, completion_probe 29, repl_command 11; cargo fmt --check clean; RUSTFLAGS=-D warnings cargo check clean; clippy --all-targets vs origin/master: no new warnings (77 -> 76, the rewrite deletes one unnecessary cast). No GPL code introduced.
Member
Author
CR verdict: APPROVE-WITH-NITS (no blockers; 5 non-blocking notes below)Independent review of 26ef3d3 vs base 7b4ee73 (fresh detached worktree, not the author's tree; every suite re-run locally on Win10 19045; clippy/fmt re-measured, not quoted). The three claims I most doubted — head-vs-tail requeue necessity, bare-CR impossibility through the new writeback face, and the RED state of the new tests — were each re-derived from scratch with my own probes, not the PR's. Verified independently
Non-blocking notes
No blockers. APPROVE-WITH-NITS — recommend a follow-up for note 1; nothing here needs to gate the merge. |
Conflict resolution (crates/niubash-runtime/src/repl.rs, two hunks): 1. Unread type doc — both sides kept: #432's MSDN tail-append framing is the primitive's truth (WriteConsoleInput APPENDS, it cannot prepend); the merged text states that #417's face wraps that primitive with a drain-and-rewrite (requeue_console_input) so the re-queued events land at the head slot, the position the probe took them from. 2. win_unread record construction — the #417 general synthesis kept (fields.*); #432's clippy-cast deletion survives inside it (the '0x0D as u16' cast no longer exists anywhere — UnicodeChar comes from a u16 field; the necessary char casts live in key_press_records). Stale #432 derivations of the old tail-append behavior updated to the compensated face (comments still cite the MSDN append as the primitive): the unread field doc (tail-write claim -> drain-and-rewrite, and why the #417 writeback needs the head slot: a plain append would shred a burst into 'ead...'), with_scripted_queue (head slot is now a production guarantee, not a test-only fidelity upgrade), enter_opens_chunk (the requeued partner CR is the next submit nothing has to drain past), and typeahead_guard::requeue_console_input's doc (same primitive as the guard's reinjection; the guard can settle for the bare append — its queue is empty at reinjection — this face buys the head slot). Verification (this host, Win10 19045, --test-threads=1) on the merge result: runtime lib 560/0; interactive 85/0 (5 ignored, unix-only legs; includes #432's two new tests and both #417 echo-proof regressions); issue373 3/0; cargo fmt --check clean; RUSTFLAGS='-D warnings' cargo check clean. niubash#434 (control-chord synthesis arm) intentionally NOT touched here — separate ticket.
This was referenced Oct 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #417. Follows #420/#426 (the unread re-injection face) and #284/#308/#341/#373/#418 (the probe's submit semantics this builds on). Open for review — not merging.
The wedge
The Enter signature probe reads the kernel console queue's next record to decide whether a bare Enter is paste data or a typed submit. With typeahead behind it (the next line of a fast burst), that record is not paste evidence — so it was parked in the in-process pushback while the Enter submitted. The accepted command's engine
readthen reads the kernel queue next, which cannot see the in-process deque: with nothing else queued,read -n1blocks forever and the parked keystrokes are unreachable until the next prompt.#426 landed the
unreadre-injection face (WriteConsoleInputW,typeahead_guard.rs) for #420's partner CR. This PR completes the chain for the parked typeahead.The fix
PasteChunkEditMode::parse_event): a batch ending in anEnteris the boundary where reedline stops reading and a command may read — whatever the probe parked goes back to the input stream's head at that point, via the existingUnreadface. Batches that do not end in a submit keep the park (the nextparse_eventdrains it FIFO; nothing left the read loop in between). A validator-held Enter (PS2) re-reads the records through the same queue — same order, no observable change.key_press_records, pure + unit-tested off-Windows): any key Press the console parser can produce, synthesized the way conhost synthesizes it — control code inuChar+ base letter in the VK for chords, VKs inverse to crossterm 0.29's parse table for special keys, one record per UTF-16 unit for non-BMP chars — so reedline's parser and the engine's console reader decode back the exact event that was consumed.typeahead_guard::requeue_console_input):WriteConsoleInputWappends at the tail, but the probed events sat AHEAD of everything still queued — a tail append would let line 2'sead...run before the parkedrofreadand shred the burst. The pending records are drained first and rewritten behind the re-queued ones; the queue reads the exact order the probe found. interactive shared-driver wedge: session echoes the input line but the submitted command never executes (reproducible with a Ctrl+R flow driver; 5 baseline failures share the signature) #420's partner-CR requeue shares the face and inherits the same guarantee.The pushback still never holds a bare CR (#341): the probe pushes only non-Enter keys, and an Enter batch's park is exactly that probe's own pushes, so the writeback can never inject a CR across a batch boundary.
New witnesses
tests/interactive.rs, interactive shared-driver wedge: session echoes the input line but the submitted command never executes (reproducible with a Ctrl+R flow driver; 5 baseline failures share the signature) #420's two test forms — both verified RED on unpatchedorigin/master(the read blocks on the emptied queue), GREEN here):probe_parked_typeahead_reaches_engine_read_417— one writeread -n1 R417; echo "R417=[$R417]"\rZ: the probe parksZ, the accepted command'sreadmust get it.typeahead_burst_read_line_gets_parked_key_417— three back-to-back lines in one write; line 2's submit probe parks line 3'sW, and the head writeback must not let line 2 run before it (a tail append fails this).paste_chunk_detector_submit_requeues_parked_typeahead_at_stream_head_417); the two former park-in-pushback assertions re-pinned to the requeue contract; the record-synthesis mapping unit tests (chars, chords, special keys, BackTab, surrogate pairs, releases/unparseable shapes).不变式自查(BLOCKER 检查)
paste_chunk_detector_pushback_never_holds_a_bare_cr_341重钉(提交后 pushback 空、键回流队头);写回面不可能注入裸 CRpaste_chunk_wrapper_dismissal_esc_rides_only_the_tab_window、Ctrl+R accept+submit burst(420 形态)全绿;包裹提交批次[Esc, Enter]不受影响(parked 集合为空)typeahead_bare_cr_pair_submits_per_line_420、ctrl_r_accept_submit_in_one_burst_420、paste_chunk_detector_open_cr_pair_submits_and_requeues_420全绿;伙伴 CR 仍走 unread,且新面升级为队头插入(顺序更严格)Verification(本机 Win10 19045,
--test-threads=1)cargo fmt --checkclean;RUSTFLAGS="-D warnings" cargo checkclean;clippy--all-targets对比 origin/master:无新增(77 → 76,重写消掉一个既有 unnecessary cast)