Fix late device-attributes response leaking to the active pane#5128
Fix late device-attributes response leaking to the active pane#5128chris-monardo wants to merge 1 commit into
Conversation
tty_start_timer_callback unconditionally OR'd in TTY_ALL_REQUEST_FLAGS (TTY_HAVEDA|TTY_HAVEDA2|TTY_HAVEXDA) when the 5s query timer fired. That same bit was also the "we have already parsed one" gate in the DA response parsers, so a legitimate response arriving later than 5s -- common over slow SSH on first attach -- was rejected by the parsers and fell through to the generic key parser, leaking bytes like ?61;4;6;...c into the active pane. Introduce a separate TTY_DA_QUERIESDONE flag for "stop waiting" and leave TTY_HAVEDA/TTY_HAVEDA2/TTY_HAVEXDA to mean strictly "we parsed one". tty_start_timer_callback sets only TTY_DA_QUERIESDONE; tty_send_requests gates each query on (TTY_HAVE* | TTY_DA_QUERIESDONE); the partial-key escape-delay check no longer treats the timer-set flags as "responses received". DA response parsers are unchanged. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
e42682d to
f864943
Compare
|
I don't get it. We send all the requests together, so if the timer fires, don't we want to give up on them all? |
|
The leak path I'm trying to fix:
So the timer's "give up on them all" is fine in spirit — the issue is that Two ways to plug it:
Both fix the leak. Which would you prefer? |
|
To put a finer point on the choice — it really comes down to how the 5 s timer is meant to be read. Its mechanics today are an "unblock": it lets three things that were waiting move forward — commit to default features so the first draw can proceed, stop `tty_send_requests` from re-issuing queries, and return the partial-key escape-delay to normal. None of those require rejecting a response that does eventually arrive. `tty_update_features` already anticipates the case:
So:
Both fix the leak. It's a policy call: correct feature detection for slow terminals at the cost of a possible late redraw, vs. commit to defaults at 5 s and never change them. |
|
Once the timer expires, the intent is that they to be processed as keys. Otherwise if you typed (if you could do so quickly enough) or pasted a sequence, tmux would consume it. Whether this is useful or not is another thing, but that's the intent. |
|
I've hit this regularly with slow SSH/terminal combos — the symptom is 20–30 garbage chars landing in the prompt on attach, which is hard to recover from without restarting tmux. After the 5 s timer, the trade-off is: a legitimate late DA response from the terminal (common in my experience) vs. a user pasting or typing a `\033[?…c` sequence (rare — DA-shaped sequences essentially don't occur in normal pasted content, and typing one inside the escape-time window is implausible). Both produce silent corruption in their respective failure modes, but the late-response case is the common one. Defaulting to it seems more useful, even with the acknowledged paste-corruption downside. |
|
Do you regularly see it on terminals which are not Windows Terminal? Which ones? How slow is your connection? Can you show me a log? |
|
This does not seem like the same problem as Windows Terminal where it is actually sending the responses twice. It seems more like you have big problems with your network or computer or terminal or something. Making tmux ignore the sequences when they are late is not the right answer. The fact there is a five second gap between query and response seems crazy. You can try bumping |
|
Oh wait, I read what you are doing wrong. You are sending the queries with passthrough... what do you expect to happen? Why shouldn't tmux send them as keys, that's what you asked for? |

Fixes #5129.
Summary
tty_start_timer_callback(tty.c:304) unconditionally OR's inTTY_ALL_REQUEST_FLAGS— i.e.TTY_HAVEDA|TTY_HAVEDA2|TTY_HAVEXDA— when the 5 s query timer fires. Those same bits are the "we have already parsed one" gate in the DA response parsers, so a legitimate DA response arriving later than 5 s is rejected by the parsers and falls through to the generic key parser, leaking bytes like?61;4;6;...cinto the active pane. The original report (Windows Terminal over SSH on first attach) is exactly the case where the response lands late. See #5129 for the standalone bug report and a reproducer.Changes
Split the flag's two meanings:
TTY_HAVEDA/TTY_HAVEDA2/TTY_HAVEXDAstay as "we parsed one" — set only on a successful parse, as before.TTY_DA_QUERIESDONEmeans "stop waiting" — set bytty_start_timer_callback(and by the non-VT100LIKE shortcut intty_send_requests).tty_send_requestsgates each query on(TTY_HAVE* | TTY_DA_QUERIESDONE)so the timer still suppresses re-querying.tty_keys_device_attributesetc.) are unchanged — late responses now reach them withTTY_HAVEDAunset and parse normally, including the feature update and redraw.