CodeWhale icon indicating copy to clipboard operation
CodeWhale copied to clipboard

tui: PASTE_BURST_MAX_BYTES (64 KiB) silently truncates raw pastes

Open Hmbown opened this issue 2 weeks ago • 3 comments

Why this matters

crates/tui-kit/src/paste_burst.rs PASTE_BURST_MAX_BYTES = 64*1024: a raw (non-bracketed) paste larger than 64 KiB drops the tail silently. After PR #7398 routes non-ASCII chars through the burst buffer, a large CJK paste reaches the byte cap sooner than an ASCII one — silent data loss in the composer.

Current behavior

Overflow chars are discarded without warning; the user sees a truncated paste with no signal.

Desired behavior

  • Preserve the data: on overflow, flush the buffer through insert_str and keep buffering (chunked), or commit the overflow directly — never drop.
  • Or at minimum surface a visible "paste truncated at 64 KiB" notice; prefer preservation.

Acceptance criteria

  • [ ] a >64 KiB paste lands complete in the composer (test at, e.g., 256 KiB)
  • [ ] bracketed and raw paths behave identically; cargo test -p codewhale-tui -- paste passes

Related

PR #7398 (paste-latency fix), user-reported large-paste slowness 2026-11-19

Hmbown avatar Nov 19 '26 12:11 Hmbown

Covered by #7422, now merged into main (25fed0fdb).

The drop itself was already fixed. d867cc681 turned the cap into a chunk size: PasteBurst::take_chunk_if_full hands a full buffer back, FlushResult::TextContinuation marks the rest of an already-chunked paste, and all three raw-paste call sites in crates/tui/src/tui/paste.rs commit the chunk with insert_str before buffering continues. Bracketed paste never had a cap.

What was missing was evidence, and that is what #7422 adds: oversized_raw_and_bracketed_pastes_preserve_every_char_and_newline drives a 341 KB ASCII+CJK+emoji payload through handle_paste_burst_key one key event per character, requires the final flush to be TextContinuation (so a stopped chunking mechanism fails), and then asserts raw and bracketed paths deliver byte-identical text with the cursor at the end.

Acceptance criteria, both met:

  • [x] a >64 KiB paste lands complete in the composer — tested at 341 KB, and the fixture width is deliberately chosen to drift off the 64 KiB boundary so re-introducing the original push_bounded drop rule fails the test (it loses 10 bytes there; a boundary-aligned fixture loses 0 and would hide it)
  • [x] bracketed and raw paths behave identically — same payload, byte-for-byte comparison, cargo test -p codewhale-tui -- paste green on Linux, Windows and macOS in CI

One gap left open, deliberately: the test cannot catch a single chunk check being deleted. A mixed payload keeps ASCII and non-ASCII characters adjacent, so each branch's own check covers for the other. Closing that needs ASCII-only and CJK-only fixtures; both existed in an earlier revision and were dropped to honour the maintainer's "one case" rewrite. Catching a full loss of chunking — the failure mode that would actually truncate — is covered.

Leaving this open for a maintainer to close.

donglovejava avatar Nov 20 '26 13:11 donglovejava

The gap I left open in my previous comment is closed in #7444.

I had written that one chunk-flush site — the take_chunk_if_full() after append_newline_if_active in the KeyCode::Enter arm — could not be observed, because deleting it still leaves the pasted text complete. The second half is true but the conclusion was wrong: the text survives because the flush moves to the next plain character, and an assertion placed between the newline and that character sees the difference. Injecting the deletion gives left: 0, right: 65536. What was untestable was content equality, not the behaviour.

All four sites now have a fixture that fails when that site is removed:

injected regression ascii_only cjk_only mixed newline
ASCII-path take_chunk_if_full removed fails — — —
non-ASCII-path take_chunk_if_full removed — fails — —
Enter-path take_chunk_if_full removed — — — fails
push_bounded drop rule restored (this issue) — fails fails —

So the acceptance criteria in the opening report are covered by tests that were checked against the actual regression, not only against a green suite:

  • a >64 KiB paste lands complete in the composer — 341 KB, with the fixture width chosen so the original drop rule loses 10 bytes and fails
  • bracketed and raw paths behave identically — byte-for-byte comparison on the same payload

CI on #7444: 32 checks, 0 failures, across Linux, Windows and macOS.

One correction to my previous comment for anyone reading this later: I reported that credential_paste_content_never_enters_traces_or_rendered_status overflows its stack as an unrelated pre-existing failure. That is only true when cargo test is run directly. scripts/dev-cargo.sh and CI both export RUST_MIN_STACK=16777216 to match the product's 16 MiB owner-thread stack, and under that the test passes — the repo documents this in .config/nextest.toml. Bypassing the project's script is what produces the overflow; it is not a defect in that test.

donglovejava avatar Nov 21 '26 06:11 donglovejava

@donglovejava thank you. This was careful work. You showed the 64 KiB drop is gone with a 341 KB ASCII+CJK+emoji paste, sized off the chunk boundary on purpose so the old drop rule would fail. Then in PR 7444 you showed that each of the four chunk sites has a test that fails when that site is removed, including the Enter path you had first called untestable. Thanks too for correcting the stack-overflow note. The fix (d867cc681) and both test PRs (7422, 7444) shipped in v0.10.3 (https://github.com/codewhale-hq/Codewhale/releases/tag/v0.10.3), so I'm closing this as fixed.

Written by Claude Fable 5.2 (AI), working with Hmbown.

Hmbown avatar Nov 23 '26 04:11 Hmbown