From 3426769f03de5dcb8d0f3ff12973e1e96c76de57 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Sun, 5 Jul 2026 15:23:08 -0400 Subject: [PATCH] Flush terminal input after exit A key release can arrive after Codex has begun shutting down, leaving enhanced-key CSI-u bytes queued for the parent shell. Reuse the existing platform-specific input-buffer flush after terminal restoration so those stale events are discarded before control returns to the shell. --- codex-rs/tui/src/tui.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/codex-rs/tui/src/tui.rs b/codex-rs/tui/src/tui.rs index 7bf72f7cdf..eef84208ff 100644 --- a/codex-rs/tui/src/tui.rs +++ b/codex-rs/tui/src/tui.rs @@ -305,6 +305,9 @@ pub fn restore_after_exit() -> Result<()> { if let Err(err) = terminal_stderr::finish() { first_error.get_or_insert(err); } + // Discard key events queued while shutdown was in progress so the parent shell does not + // receive CSI-u sequences that were encoded before keyboard reporting was reset. + flush_terminal_input_buffer(); match first_error { Some(err) => Err(err),