Discard TUI typeahead after prompt rewind and fork (#63193)

## Why

Rewinding to edit an earlier prompt restores it in the composer. If a
second rewind gesture is already buffered, its Enter can submit the
restored prompt before the user edits it. [Prompt rewind behavior](https://github.com/openai/codex/pull/45845)

## What changed

Pause terminal input as soon as a rewind is queued. Drain buffered input
before showing the restored prompt, and use the same drain after forks
from a locked thread or the agents overview. Retry in bounded batches
while input is still pending, deliver buffered focus changes in order,
and recheck terminal size when the drain finishes.

## Testing

Extend PTY coverage to verify that repeated rewind keystrokes and a
trailing Escape leave the restored prompt ready for a fresh edit and
submission. Cover delayed paste completion, focus event ordering,
and terminal resize during a drain.

GitOrigin-RevId: 65ba4f343892ed3ba2eeb120172f66bfbebe120f
This commit is contained in:
Eric Traut
2026-11-22 21:18:40 +00:00
committed by copyberry
parent 0bbbda9250
commit 9f2cbb9c09
13 changed files with 268 additions and 30 deletions
@@ -112,6 +112,25 @@ async fn picker_side_worktree_fork_and_cd_run_on_the_production_stack() -> Resul
terminal.wait_for_screen("Worked for")?;
terminal.wait_for_screen("Ask Codex to do anything")?;
// A second rewind gesture is already buffered when the first is confirmed.
// A trailing bare Escape must not consume the first character of the fresh edit.
terminal.write_input(b"\x1b[27u\x1b[27u\r\x1b[27u\x1b[27u\r\x1b")?;
terminal.wait_for_screen("Conversation reverted to this point")?;
terminal.write_input(b" Revised.")?;
terminal.wait_for_screen("Reply with the marker requested by this test. Revised.")?;
let _edited_reply = responses::mount_sse_once_match(
&server,
body_string_contains("Reply with the marker requested by this test. Revised."),
responses::sse(vec![
responses::ev_assistant_message("edited", "STACK_SAVED_HISTORY_EDITED"),
responses::ev_completed("edited-response"),
]),
)
.await;
terminal.write_input(b"\r")?;
terminal.wait_for_screen("STACK_SAVED_HISTORY_EDITED")?;
terminal.wait_for_screen("Worked for")?;
// Starting and closing a side conversation both rebuild the displayed chat widget.
// Repeat through the real event loop, whose dev-build frames share the production stack.
for attempt in 1..=3 {