From 311d9285ffc9ebd39b709df77db28bc1c5319f0b Mon Sep 17 00:00:00 2001 From: l0ng-ai <24760907+l0ng-ai@users.noreply.github.com> Date: Sun, 26 Jul 2026 19:11:39 +0800 Subject: [PATCH] fix(deps): pin a patched alacritty to survive deep keyboard-mode pushes Enabling `kitty_keyboard` (#184) made an upstream `alacritty_terminal` bug reachable from any foreground program. `push_keyboard_mode` caps its stack by removing from `title_stack` instead of `keyboard_mode_stack` -- a copy-paste slip from `push_title` that compiles because both are `Vec`s and the removed value only feeds a `trace!`. Two consequences. Each overflowing push silently drops a saved window title, so a later XTPOPTITLE restores the wrong one. And once the title stack is empty, `Vec::remove(0)` panics: 4097 unpopped `CSI > 1 u` pushes -- roughly 20KB of output -- kill the `tty7-remote-reader` thread and freeze the pane. The depth cap never trimmed `keyboard_mode_stack` at all, so it was doing nothing. Hostile output is not required. A TUI that pushes without popping (per redraw, per keypress) reaches 4096 on its own in a long session. Pin our fork of Zed's fork instead: `tty7` is Zed's `fcf32fe` plus the one-word fix. No `[patch]` section is needed -- tty7 is the only crate in the tree that depends on `alacritty_terminal`, so a plain URL/rev swap cannot split it into two incompatible copies the way the gpui pin would. The regression test guards the pin rather than our own code: it pushes past the 4096 cap and then queries, using the reply as a liveness probe. Verified to fail against the unpatched rev. Still present on alacritty master as of 852e971. Drop the fork once it lands upstream. --- Cargo.lock | 2 +- Cargo.toml | 13 +++++++++++-- src/terminal/remote.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 058c0252..777cffdb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -196,7 +196,7 @@ dependencies = [ [[package]] name = "alacritty_terminal" version = "0.26.1-dev" -source = "git+https://github.com/zed-industries/alacritty?rev=fcf32feacb367b75ec84dd40f041e4fd411d3cc1#fcf32feacb367b75ec84dd40f041e4fd411d3cc1" +source = "git+https://github.com/l0ng-ai/alacritty?rev=22b1d74842732f6ea30d8f4eec768b3ac659d0b6#22b1d74842732f6ea30d8f4eec768b3ac659d0b6" dependencies = [ "base64", "bitflags 2.13.0", diff --git a/Cargo.toml b/Cargo.toml index ae24182e..51b151f6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -65,10 +65,19 @@ image = "0.25" # to gpui's rev so the shared `http_client`/`zed-reqwest` versions stay aligned. reqwest_client = { git = "https://github.com/zed-industries/zed", rev = "1d217ee39d381ac101b7cf49d3d22451ac1093fe" } -# Zed's fork of alacritty_terminal — same rev Zed pins. Used by the *client* +# Our fork of Zed's alacritty_terminal fork. Used by the *client* # (`terminal::remote`) for the VT parser + grid (`Term`/`ansi::Processor`) that # renders the mirror. The daemon's PTY itself is driven by `portable-pty` below. -alacritty_terminal = { git = "https://github.com/zed-industries/alacritty", rev = "fcf32feacb367b75ec84dd40f041e4fd411d3cc1" } +# +# The `tty7` branch is Zed's `fcf32fe` (the rev Zed pins) plus one commit: +# `push_keyboard_mode` capped its stack by removing from `title_stack` instead of +# `keyboard_mode_stack` — a copy-paste slip from `push_title` that compiles because +# both are `Vec`s. With `kitty_keyboard` on (see `terminal_config_from_user`) every +# overflowing push silently drops a saved title, and once the title stack is empty +# `Vec::remove(0)` panics — 4097 unpopped `CSI > 1 u` pushes, about 20KB of output, +# kill the reader thread and freeze the pane. Still present on alacritty master as +# of 852e971; drop this fork once it lands upstream. +alacritty_terminal = { git = "https://github.com/l0ng-ai/alacritty", rev = "22b1d74842732f6ea30d8f4eec768b3ac659d0b6" } # Desktop notifications driven by OSC 9 / OSC 777 escape sequences. Cross-platform; # the macOS backend uses the deprecated NSUserNotification (weak — a completion diff --git a/src/terminal/remote.rs b/src/terminal/remote.rs index fb5780e0..5971763a 100644 --- a/src/terminal/remote.rs +++ b/src/terminal/remote.rs @@ -1692,6 +1692,46 @@ mod tests { ); } + /// Guards the `alacritty_terminal` pin, not our own code. Upstream's + /// `push_keyboard_mode` trims its stack by removing from `title_stack` — a + /// copy-paste slip from `push_title` — so once the title stack is empty the + /// `Vec::remove(0)` panics and takes the reader thread with it. Enabling + /// `kitty_keyboard` made that reachable from any foreground program: ~20KB of + /// unpopped pushes is enough. Our fork fixes it; a bump back to an unpatched + /// rev must fail here rather than in the field. + #[test] + fn deep_keyboard_mode_pushes_leave_the_reader_alive() { + let (client_side, mut daemon_side) = UnixStream::pair().unwrap(); + let term = RemoteTerminal::from_stream(client_side, TermSize::new(80, 24)).unwrap(); + + // One past alacritty's KEYBOARD_MODE_STACK_MAX_DEPTH (4096): the push that + // overflows is the one that used to panic. The trailing query is the + // liveness probe — a dead reader thread simply never answers. + let mut payload = b"\x1b[>1u".repeat(4097); + payload.extend_from_slice(b"\x1b[?u"); + DaemonMsg::Output(payload).encode(&mut daemon_side).unwrap(); + daemon_side.flush().unwrap(); + + let mut reply = None; + for _ in 0..200 { + while let Ok(event) = term.events.try_recv() { + if let AlacEvent::PtyWrite(text) = event { + reply = Some(text); + } + } + if reply.is_some() { + break; + } + std::thread::sleep(std::time::Duration::from_millis(5)); + } + + assert_eq!( + reply.as_deref(), + Some("\x1b[?1u"), + "the reader thread must survive a deep mode-push run and still answer queries" + ); + } + #[test] fn spawn_retry_only_for_daemon_disconnects() { let eof: anyhow::Error =