Repository navigation
Conversation
- Increased character interval to 16ms to reduce flakiness - Added guard delay for reliable test timing - Improved detection of paste-like bursts with whitespace or long strings
nornagon-openai
left a comment
There was a problem hiding this comment.
I'm worried that this will introduce lag during regular typing, as we delay displaying characters until we decide that the input isn't part of a paste burst.
|
@nornagon-openai I submitted the PR based on @bolinfest request/recommendation — not entirely sure which word fits better here. If there are any doubts, I’m not attached to pushing a pointless PR :) I personally use Codex and would love to see it working as smoothly as possible. If this is just about gaining “credit,” I’m totally fine with closing it. Hopefully, the issue with program not found and requested timeout in the context of MCP loading can be resolved. Maybe someday there will be an opportunity to submit something meaningful :) |
In practice — no. Blink duration: usually ~100–150 ms. Typical sources of false positives (non-human or system-level):
Input/rendering latency (roughly): Keyboard → OS: wired often ~1–10 ms, Bluetooth typically ~7–30 ms. Event loop / scheduler: from a few to several dozen ms depending on system load. Rendering at 60 Hz: one frame ≈ 16.7 ms; blocking one or two frames can “compress” timestamps of consecutive keystrokes. Conclusion: |
There was a problem hiding this comment.
@AdsQnn I'm happy to do some experimenting with tweaking this interval, but we need to address FlushResult, since chat_composer.ts depends on this type and this change won't compile in its current form.
Sharing screen recordings of typing/pasting on windows, as well as linux and/or mac platform will help speed up review here.
| Paste(String), | ||
| Typed(char), | ||
| None, | ||
| } |
There was a problem hiding this comment.
I described it in full below, but I did it quite a while ago, so I don’t remember all the details.
It was also about 10 versions ago :)
|
@dylan-hurd-oai Purpose of the change: simplification and encapsulation of logic. Advantages: Simpler API – the caller only checks whether there is text to insert. Better encapsulation – detection details remain internal to the class. More stable behavior and testing – fewer edge cases. Eliminates UI flicker during fast paste sequences. Disadvantages: Loss of semantic distinction between Typed and Paste (may affect telemetry or undo tracking). Minor allocation cost due to to_string() for single characters. Assessment: the change is good – it simplifies the code, improves UX, and enhances testability. Exactly like in belief propagation — each node operates locally, passing upward its resulting estimation rather than raw observations.
You're right — that's why I'm a fan of something like belief propagation and a modular approach. I just dropped it in because it came to mind when I saw it. #2968 No worries — I just mentioned it because I believe the remaining PRs listed below will eventually need to be implemented as well. I think it’s not worth trying to fix this by force — it’s better to rewrite it from scratch for the current version. I’ll close this PR shortly, so all good :) @codex Am I right about this, or am I mistaken? It might need some refinement, but I mean the general concept. Thanks for the constructive discussion, and good luck with the ongoing work on Codex! |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| /// now emit that char as normal typed input. | ||
| /// | ||
| /// Returns None if the timeout has not elapsed or there is nothing to flush. | ||
| pub fn flush_if_due(&mut self, now: Instant) -> FlushResult { | ||
| pub fn flush_if_due(&mut self, now: Instant) -> Option<String> { | ||
| let timed_out = self | ||
| .last_plain_char_time | ||
| .is_some_and(|t| now.duration_since(t) > PASTE_BURST_CHAR_INTERVAL); | ||
| if timed_out && self.is_active_internal() { | ||
| self.active = false; | ||
| let out = std::mem::take(&mut self.buffer); | ||
| FlushResult::Paste(out) | ||
| Some(out) | ||
| } else if timed_out { | ||
| // If we were saving a single fast char and no burst followed, | ||
| // flush it as normal typed input. | ||
| if let Some((ch, _at)) = self.pending_first_char.take() { | ||
| FlushResult::Typed(ch) | ||
| Some(ch.to_string()) |
There was a problem hiding this comment.
Adjust chat compositor to Option-based flush result
Replacing flush_if_due’s return type with Option<String> and dropping the FlushResult enum requires all call sites to change, but chat_composer still imports FlushResult and matches on its variants. The project will no longer compile because the enum no longer exists and the call now expects an Option<String>. Update the caller (e.g., handle_paste_burst_flush) to handle the new API or keep the enum.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Ok, that part was already clear — what I actually wanted to know is whether it’s better, overall, to stick with the current PasteBurst implementation using Option, or to bring back the FlushResult version
There was a problem hiding this comment.
Note
To use Codex here, create an environment for this repo.
There was a problem hiding this comment.
🔧 Potential improvements
1️⃣ is_active() semantics
Current:
pub fn is_active(&self) -> bool {
self.is_active_internal() || self.pending_first_char.is_some()
}
Issue: pending_first_char ≠ active paste — it's only "maybe".
Proposal:
is_active()→ only when we’re actually bufferinghas_pending_state()→ when we’re awaiting a decision
2️⃣ Duplicated time-window logic
Repeated pattern:
self.burst_window_until = Some(now + PASTE_ENTER_SUPPRESS_WINDOW);
Extract helper:
fn extend_suppress_window(&mut self, now: Instant) {
self.burst_window_until = Some(now + PASTE_ENTER_SUPPRESS_WINDOW);
}
3️⃣ decide_begin_buffer does too much
It currently:
- decides whether to start buffering
- mutates state (begin_with_retro_grabbed)
- returns what to remove from the UI
Split responsibilities:
Pure decision:
fn should_retro_grab(&self, grabbed: &str, retro_chars: usize) -> bool {
// heuristic logic
}
State mutation only:
pub fn begin_with_retro_grabbed(&mut self, grabbed: String, now: Instant) {
// ...
}
4️⃣ Magic number in heuristic
Current:
|| grabbed.chars().count() >= 16
Why 16? Extract a named constant with context:
const PASTE_HEURISTIC_MIN_LENGTH: usize = 16; // Typical threshold for URLs/paths
This is a reasonable argument to me - can you rebase the PR and update |
|
@dylan-hurd-oai Ok, I can take this on. However, I’d need about 24–48 hours, because I’d like to test it properly. At the moment, for example, paste doesn’t work for me at all on Ubuntu. I’ll try to get it done as quickly as possible. Let me know if that works for you. |
|
@AdsQnn if the problem is |
|
@dylan-hurd-oai I’d prefer an entirely new one. I’m just asking whether you’d rather handle it yourselves or should I upload it. Should I include only that part, or also slightly increase the Paste Burst just in case and upload that too? I’ve shared the whole process so it’s clear what everything comes from — I’m not guessing :) I’m certain the issue lies right there. I just wrote here to confirm whether you’re okay with this, so there’s no misunderstanding before I create a separate PR. In the attached thread, the author mentions that they also had the same kind of input leak on Windows. I mean that I don’t want to impose anything, so I’m asking before I do anything :) |
|
@AdsQnn new PR is fine! Tag me on it. Please ensure:
|
|
There’s an issue with “paste burst” that I’m trying to solve. Normally, everything is handled by bracketed paste, and that part works fine. But in order to properly test paste-burst, I’m testing it with bracketed paste disabled. The problem is that the terminal sends long pasted text in chunks of 1, 2, or 4 KB (1024 or 2048 characters). So when I paste, for example, 4000 characters, this happens: First I get: [paste 2048 chars] Then nothing happens until I press any key, and only then I receive something like [paste ~1000 chars], and so on… In other words, the first chunk arrives immediately, but the next chunks stay buffered and are only flushed when a new input event occurs (e.g., pressing a key). So for paste-burst to behave as intended, I need to solve this packet-splitting / buffering issue. Something seems to be delaying or holding back the remaining chunks. This is a separate problem from bracketed paste itself — because bracketed paste would intercept everything anyway. But if I want paste-burst to work correctly on its own, I need to deal with this packetization behavior. With paste-burst, the kernel may push, for example, 4 chunks of 1024 bytes into the PTY buffer. The application only receives a single POLLIN, performs one read(), and consumes just the first 1024-byte chunk. The remaining data stays in the buffer because no further input event is generated. Only pressing any key triggers another POLLIN, and only then can the next chunks be read. That’s why after each POLLIN, you need to read in a loop until EAGAIN, to drain all chunks immediately. So in most cases, bracketed paste will work anyway, and the rgb/1818 issue is still a real one. Even though paste burst is used very rarely in practice and most terminals support bracketed paste, I just want it to work the way it should. |
|
It looks like this PR is no longer relevant, so closing. |




Improves paste burst detection logic (16ms interval, guard delay) and reduces test flakiness; enhances whitespace/length heuristics.
Inter-char threshold: 16 ms (from 8 ms) to reduce flakes on slower machines while still masking during paste bursts.
Flush delay: +8 ms above threshold for stable post-burst flush (jitter margin).
Retro-grab: start buffering after ≥2 rapid chars, preventing the 3rd char from leaking; small bursts insert text, large bursts get a placeholder.