Repository navigation
WIP: fix #806 R2 — same-chunk trailing CR submits (paste body required to open a chunk) - #819
Merged
Merged
Conversation
…en a chunk
Root cause: PasteChunkEditMode::enter_opens_chunk classified every
chunk-opening CR with its LF partner queued behind it as paste data.
A single machine-fed line (write("cmd\r\n") as ONE write: send_line,
expect, pywinpty) is the pair and SILENCE — its CR was absorbed, the
line parked in the edit buffer and only a LATER Enter executed it
(t4: 0/5 in window; WSL GNU Bash 5.3 executes the same write).
Fix: a second, structural look at chunk-open (paste_body_behind) — the
pair plus burst body behind it (more text or breaks within
PASTE_CHUNK_GAP) opens the chunk as before (requeue-as-evidence, fold
accounting unchanged); the pair and silence is one machine-fed line and
the CR submits, GNU typeahead semantics (the niubash#420 precedent,
applied to the LF partner). The consumed LF is dropped.
Refs #806
This was referenced Nov 2, 2026
caomengxuan666
marked this pull request as ready for review
November 2, 2026 06:16
This was referenced Nov 2, 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.
WIP: fix the R2 residual of #806 — the line editor dropped the SAME-CHUNK trailing CR, so one pty write of
cmd\r\nleft the command parked in the edit buffer instead of executing it. Refs #806.Root cause
crates/niubash-runtime/src/repl.rs:2337PasteChunkEditMode::enter_opens_chunk— thePastePartner::LfPartnerarm classified EVERY chunk-opening CR with its LF partner queued behind it as paste data (pending = Some("\n"), the CR never reached reedline). But a real paste's first line break is only the START of the burst: the next line's text is queued behind the pair (or arrives within the slice gap). A single machine-fed line — pywinpty/expect/send_linewritingcmd\r\nas ONE write — is the pair and SILENCE, and nothing a paste is made of follows the break. Its CR was absorbed, the line sat in the buffer, and only a LATER Enter executed it.t4 evidence (
D:\repo\nbbuild\evidence\pre-1.5.0\t4\, repro R2):write("echo ok\r\n")→ 0/5 executed in a 0.5 s/2 s window;write("echo ok")+ 0.7 s +write("\r")→ 5/5.GNU oracle (WSL GNU Bash 5.3.20, PTY probe from a script file, per the repo's baseline rule): the same single write EXECUTES —
$ echo ok\r\nok\r\n$ \r\n$— the CR accepts the line and the LF is a second, empty accept. Bash-without-bracketed-markers is per-key:\ris accept-line.Fix
Second, structural look at chunk-open —
repl.rs:2415paste_body_behind, called from theLfPartnerarm:PASTE_CHUNK_GAP, the same budget the burst clock already trusts to absorb paste slice jitter): the chunk opens as before. The found key is REQUEUED to the input stream's head (the [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/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 face) instead of being folded inline, so its own dispatch takes the established mid-chunk fold/absorb arms — every break-accounting invariant ([P1][blocks 1.4.1] interactive paste still swallows line starts in WT on the current build — full script reproduction (owner live session 2026-10-14) #341\r\r, the interior-pair fold, the lone-LF fold) keeps its single owner.\r\r. The CR submits; the consumed LF is dropped (GNU gives it a second, empty accept; requeueing it would open a phantom paste chunk at the next prompt).Deliberate, documented tradeoffs:
send_line, and 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 precedent puts automation correctness first.PASTE_CHUNK_GAPafter its first pair has its first line submitted — exactly the feedstranslate_event's flush-on-gap already treats as two bursts.Not touched: the dispatched-lone-LF chunk-open branch (
enter.modifiers == CONTROL), the mid-chunk fold arms, the Unix bracketed-paste path (PASTE_CHUNK_DETECTIONiscfg!(windows)).Verification
wsl python3pty probe): singleecho ok\r\nexecutes (CR accept + LF empty accept); split write executes; single CR executes;echo a\r\necho b\r\nexecutes per line; bracketedESC[200~…ESC[201~buffers without executing.tests/issue806_same_chunk_cr.rs(3/3): single-write executes, split-write executes, multi-line write still buffers until Enter.paste_chunk*pass, including 4 new [interactive] 行编辑器丢同块尾 CR(cmd\r\n 单写入不执行)+ PROMPT_COMMAND/PS1 不随 prompt 重估 + -ic 缺 $- 的 i / --rcfile 拒收 #806 pins (pair-alone submits, pair+body opens, pair+break opens, pair+chord submits) and the updated Ctrl+V 粘贴多行文本速度极慢 #202/[P1][regression #252] Windows 粘贴块启发式吞掉每个提示符后的第一次 Enter —— ConPTY 驱动/脚本/快速打字全部丢提交 #284/[P2] Enter pressed within the paste burst window is swallowed as chunk data — needs a second Enter #308/[P1][blocks 1.4.1] interactive paste still swallows line starts in WT on the current build — full script reproduction (owner live session 2026-10-14) #341/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 pins and the byte-exact reassembly suite.tests/interactive.rs: 13/13 paste tests pass (60-line scale paste, WT bare-CR owner script, [P1][regression #252] Windows 粘贴块启发式吞掉每个提示符后的第一次 Enter —— ConPTY 驱动/脚本/快速打字全部丢提交 #284/[P2] Enter pressed within the paste burst window is swallowed as chunk data — needs a second Enter #308 shapes).typeahead_survives_prompt_rebuild_window,rapid_input_burst_all_lines_execute,typeahead_bare_cr_pair_submits_per_line_420,ctrl_r_accept_submit_in_one_burst_420,typeahead_burst_read_line_gets_parked_key_417,probe_parked_typeahead_reaches_engine_read_417).cargo test -p niubash-runtime --locked -- --test-threads=1: all green, run twice.tests/interactive.rs: 95/102 pass. The 6 failures (completion_menu_enter_commits_highlighted_candidate,continuation_heredoc_gathers_until_delimiter,ctrl_c_interrupts_builtin_sleep,issue616_ctrl_c_at_prompt_runs_int_trap,issue669_ctrl_c_during_sleep_returns_prompt_with_130,tab_completes_unique_file_path) fail IDENTICALLY on pristine master 9f382e6 on this host (0/6 pass on both trees; every transcript shows the first prompt and no input arriving — the documented dev-box PTY host-noise class, cf. the [P1][blocks 1.4.1] interactive paste still swallows line starts in WT on the current build — full script reproduction (owner live session 2026-10-14) #341 test's comment on continuation/ctrl_d cases this host fails on master). Not caused by this change.