Repository navigation
fix(repl): paste-chunk detection decides submits structurally, not by timing (#284, #287) - #288
Merged
Merged
Conversation
… timing (#284) The 50 ms arrival-burst heuristic of #252 classified every bare Enter that arrived within one burst as paste data, so "text + Enter" in a single feed - fast human typing, ConPTY test drivers' send_line, expect scripts, send-keys - lost its submit and needed a second Enter. 35/47 tests/interactive.rs cases timed out on that swallow. The submit-versus-paste decision at a bare Enter is now structural: a machine-fed line break is a CRLF pair (the LF surfaces as Enter + CONTROL), and reedline's own batch loop stops at a bare Enter, so the pair's LF is always still queued when the CR is dispatched. A bounded lookahead (PASTE_LF_PROBE, 10 ms) peeks at the queue: an LF partner proves paste - the pair folds into the pending chunk and the Enter never reaches reedline; any other queued key or silence proves a typed submit, and the lookahead's read is pushed back so it lands, in order, at the next prompt (GNU typeahead semantics). A bare Ctrl+J opens a chunk by itself (humans do not submit with it). The 50 ms gap keeps one job: the burst boundary where a pending chunk flushes as ONE InsertString. Multi-line paste keeps buffering quietly until the user's Enter - the niubash#202 contract holds: the 257-line issue payload benches at 4.62 s end to end with 0 mid-paste executions (calibration ~4.6 s / 0). Interactive suite: 5 passed / 35 failed / 7 ignored before, 43 passed / 0 failed / 7 ignored after. Also fixes the TypeaheadGuard double-injection (niubash#287): the sweeper's self-heal path reinjected a borrowed view of the saved records without draining them, so disarm_and_reinject wrote the same records back a second time - one swept key per prompt cycle arriving twice. The self-heal now drains under the lock; a console-input regression test stages records through a duplicate stdin handle and asserts each comes back exactly once (verified to fail on the pre-fix path). Tests: rapid_input_burst and multiline_raw_paste re-pin the #252/#284 contract (CRLF feed buffers as one chunk, bare-CR feed submits per line); new send_line_first_enter_submits_and_typeahead_executes pins the #284 regression shape; multiline_crlf_paste_buffers_whole_chunk_ and_executes_once pins the issue-scale 0-mid-execution surface; esc_sequenced_arrow_keys_edit_without_absorption pins the #277/#280 arrow path. Fixes #284, fixes #287
This was referenced Oct 13, 2026
caomengxuan666
added a commit
that referenced
this pull request
Oct 13, 2026
…hunk (closes #308) (#309) A paste followed immediately by Enter — send(paste_crlf + "\r"), one write, the Enter <50 ms after the last paste key — was swallowed: the pending-chunk branch of translate_event() pushed every bare Enter into the chunk as newline data unconditionally, so nothing executed and a second Enter was needed. Extend the #288 structural judgment to the pending branch: a bare CR now runs the same LF-partner lookahead as the chunk-open Enter (extracted as PasteChunkEditMode::cr_has_lf_partner). An LF partner queued behind the CR proves the break paste data (a break still INSIDE the block); silence or any other queued key proves the block complete and the Enter the user's submit — the chunk flushes and submits in one batch, first Enter, no second. Anchored in reedline 0.50.0 bracketed paste semantics: Event::Paste folds breaks into \n data of one insert (edit_mode/mod.rs:44-47) and the buffer "can then be submitted with a separate enter" (engine.rs:408-416); the probe is sound because reedline's batch loop itself stops at a bare Enter (engine.rs:1052-1067), so the queue behind a dispatched CR is intact. The CR now always consumes its partner when present, which retires the last_bare_cr pairing flag: a directly dispatched Ctrl+J during a burst is by construction a lone LF — real newline data, never a folded pair. Tests: unit — pending bare CR without partner flushes+submits the whole chunk mid-burst (chunk content pinned), interior CRLF pair stays data with the partner consumed, typeahead behind the pending Enter submits in order; interactive — paste_with_same_burst_enter_submits_ on_first_enter pins the one-write repro (fails on pre-fix code, verified). Co-authored-by: cmx <[email protected]>
caomengxuan666
added a commit
that referenced
this pull request
Oct 13, 2026
… and #309 coverage (refs #291) (#317) The niubash#291 "minimal repro" is a false positive: the scratch probe's negative assertion !screen.contains("cho two") fails on a CORRECT run too, because "cho two" is a strict substring of the intact rendering "echo two". Every captured failure screen shows "echo two" complete with both outputs correct on a single submit; ~70 execution-level runs across builds/claim/write-shapes reproduce no byte loss. #291 therefore stays OPEN pending owner-side evidence (history bytes / rc / terminal / IME / build provenance) - this PR closes nothing. What lands here, all test-only (zero runtime code changed): - Unit (crates/niubash-runtime/src/repl.rs): feed_paste_burst() feeds the exact console event stream of a one-write CRLF paste through PasteChunkEditMode (scripted lookahead queue, post-#309 semantics: every pasted CR consumes its queued LF partner) and reassembles the text reaching reedline from the translated events. Four shapes must reassemble byte-for-byte: the reported empty-line burst, two consecutive empty lines, an indented line after an empty line, and a no-empty-line CRLF control. - Interactive (tests/interactive.rs): execution-level marker technique - the pasted body carries `echo RES_$((40+2))`-shaped lines, so the output RES_42 appears nowhere in the echoed input and proves the line executed with every leading byte intact; a swallowed head leaves no marker. Substring assertions against the screen are banned in this suite (the probe's trap). Shapes: the owner burst with a settled submit, the SAME-burst submit Enter (one write - niubash#309 coverage on the empty-line shape: first Enter must submit, the test sends nothing else), two consecutive empty lines, indented line, the no-empty-line control, and the claimed/custom-PS1 surface from issue comment 3 (the one variable the original 30-run sweep never varied). Adjacent semantics pinned green on current master: whole-CRLF-block integrity (#288 surface), burst interior Enters stay data (#284), the burst-settled Enter submits the whole chunk once, and #309's first-Enter submit holds on the empty-line shapes. Verification: cargo fmt --check clean; RUSTFLAGS="-D warnings" cargo check --all-targets clean; RUST_TEST_THREADS=1 NIU_INTERACTIVE_TESTS=1 cargo test --test interactive: new suite green; lib suite green.
This was referenced Oct 14, 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.
Summary
Fixes #284 (P1 regression from #252) and #287 in one pass — both live on the Windows console input path.
#284: the 50 ms arrival-burst heuristic classified every bare
Enterarriving within one burst as paste data, so "text + Enter" in a single feed lost its submit: fast human typists (last char → Enter < 50 ms), ConPTY drivers'send_line, expect scripts,send-keys— everyone needed a second Enter. 35/47tests/interactive.rscases timed out on this.The fix — structural, not timing-based. A machine-fed line break is a CRLF pair: the CR arrives as a bare
Enter, its LF asEnter + CONTROL(the console's Ctrl+J), and reedline's own batch loop (engine.rs read_line_helper) stops every batch at a bare Enter — so the LF partner is always still queued when the CR is dispatched.PasteChunkEditModenow runs a bounded lookahead (PASTE_LF_PROBE, 10 ms) at a bareEnterthat would open a chunk:Multiplecan't carry them: reedline drops sub-events after the firstExits).Enter + CONTROL(Ctrl+J) with no chunk pending opens one by itself — humans don't submit with Ctrl+J, and it catches slow pastes whose CR already slipped through.InsertString.burst_charsis gone.#287: the TypeaheadGuard sweeper's self-heal path reinjected a borrowed view of
savedwithout draining it, sodisarm_and_reinject(which takes the buffer after the sweeper parks) wrote the same records back a second time. The self-heal now drains under the lock.Verification matrix
scripts/perf/paste_multiline_bench.py --payload issue202)elapsed 4.62 s(calibration ~4.6 s),bad_executions_paste 0, 3.7 KB output — no #252 regressionsend_line_first_enter_submits_and_typeahead_executes+ all 35 healed send_line testssend_linehalf of the new test; bare-CR feed stays per-line (multiline_raw_paste_windows_crlf_buffers_and_cr_executes_per_line)esc_sequenced_arrow_keys_edit_without_absorption: arrows + insert + submit land; vi matrix greenniubash-runtime --lib)Test-contract updates
Two tests pinned the pre-#252 per-line Windows fallback and had to move with the contract (their own doc comments said the pin exists so a parser change "cannot silently change it without notice" — #252/#284 is that change, now deliberate):
rapid_input_burst_all_lines_executeandmultiline_raw_paste_per_line_windows→ renamed/reworked tomultiline_raw_paste_windows_crlf_buffers_and_cr_executes_per_line, pinning CRLF feed = buffered one-chunk paste; bare-CR feed = per-line typeahead. Executed-output rc-variable markers distinguish execution from echoed buffer text.Known-unrelated failures (verified on a clean origin/master worktree, not this branch)
smoke_1_3_0d2/d3 wizard journeys stall at the collection-install →niu-gitstep. On cleanorigin/master(2a6a12a) d2 fails identically and d3 fails earlier (at "Pick a theme"); this branch's d3 gets one stage further. d2 spawnsniu setupstandalone — no REPL, no guard, no paste logic on that path. Introduced between 0830c78 and 2a6a12a by something else; separate defect.ctrl_d_after_background_job_exitsis timing-flaky standalone (fails 3/3 on an unmodified checkout too) but green in suite runs.Notes
PASTE_LF_PROBE= 10 ms: an order of magnitude above observed ConPTY handoff latency (the LF is synthesized in the same pipe write as the CR), an order below a perceptible submit delay; only hot bare-CR Enters pay it, and only when the queue is empty.Fixes #284, fixes #287