Skip to content

WIP: fix #806 R2 — same-chunk trailing CR submits (paste body required to open a chunk) - #819

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/806-same-chunk-cr
Nov 2, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/806-same-chunk-cr

Conversation

@caomengxuan666

@caomengxuan666 caomengxuan666 commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

WIP: fix the R2 residual of #806 — the line editor dropped the SAME-CHUNK trailing CR, so one pty write of cmd\r\n left the command parked in the edit buffer instead of executing it. Refs #806.

Root cause

crates/niubash-runtime/src/repl.rs:2337 PasteChunkEditMode::enter_opens_chunk — the PastePartner::LfPartner arm 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_line writing cmd\r\n as 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: \r is accept-line.

Fix

Second, structural look at chunk-open — repl.rs:2415 paste_body_behind, called from the LfPartner arm:

Deliberate, documented tradeoffs:

Not touched: the dispatched-lone-LF chunk-open branch (enter.modifiers == CONTROL), the mid-chunk fold arms, the Unix bracketed-paste path (PASTE_CHUNK_DETECTION is cfg!(windows)).

Verification

…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
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