opencode icon indicating copy to clipboard operation
opencode copied to clipboard

tui: Escape stops dismissing dialogs and composer

Open dpc00 opened this issue 2 weeks ago • 4 comments

Summary

In V2 TUI 2.3.2, the Escape key stopped dismissing anything: the command palette (ctrl+p) and the Subagents composer pane both stayed open after repeated Escape presses, while arrow keys, Home/End and Page Up/Down kept working. The same failure occurred in a GhostShell tab and after detaching/restarting the TUI in Windows Terminal, so it is not specific to one dialog or one terminal host.

Environment

  • opencode version: 2.3.2 (release, latest channel; opencode --version = 2.3.2)
  • OS: Windows_NT 10.0.26300 (win32 x64)
  • Terminal: GhostShell (Sublime Text ConPTY terminal), then Windows Terminal. Service env: TERM=xterm-256color, TERM_PROGRAM=ghostty, COLORTERM=truecolor
  • Shell: C:\Windows\system32\cmd.exe
  • Install/channel: release 2.3.2 under ~/.opencode/bin
  • Active plugins: none in ~/.config/opencode/opencode.json; no .opencode/plugin or .opencode/plugins

Reproduction

Not deterministic from a cold start. It was met during ordinary use in a long session; the user reports it had also happened in a previous session and survived a restart/resume. Once present:

  1. Press down — the Subagents composer pane opens (session.child.first, "Toggle subagent picker").
  2. Press Escape once or repeatedly — the pane stays open.
  3. Press ctrl+p — the command palette opens.
  4. Press Escape — the palette stays open.
  5. Up, arrows and Page keys continue to work in both surfaces.

Expected Behavior

Escape closes the topmost dialog / the composer, as the esc hints promise.

Actual Behavior

Escape had no visible effect in any surface. A plain-text log of the terminal screen captured on four reattaches showed the Subagents pane still open each time:

  Subagents  Shell  Terminals                                            esc
  No active subagents
  show inactive ctrl+a  tabs ←/→

Additional Context

Evidence from an asciicast v3 recording of the session (record_asciicast was enabled after the first occurrence, and the failure reproduced while recording):

  • Input events show the physical Escape presses as bare \x1b bytes written to the TUI's PTY — 7 presses around 233–235 s, then 5 after ctrl+p (\x10) at 553.6 s, then more at 564–567 s and 578–580 s. In the same window arrow keys (\x1b[A/B/C/D) and Page keys (\x1b[5~, \x1b[6~) are present and act.
  • @opentui/core 0.8.4's parseKeypress("\x1b", { useKittyKeyboard: true }) returns { name: "escape", ... } in both kitty modes, so byte delivery and key parsing are not the failure.
  • Reconstructing the screen from the cast shows the palette open at t≈552 s and still open, item for item, at t≈556 s, t≈559 s and t≈583 s despite the Escape bytes.
  • No pending question form or permission request existed on the server at reconnect (GET /api/session/<id>/form and /permission both 404); session.sidebar is hide in cli.json, so the sidebar escape hijack from #56149 does not apply.

What I could and could not establish from the 2.3.2 source (cloned at tag v2.3.2):

  • A bare ESC byte is ambiguous, so the renderer holds it in its stdin parser until an escape timeout flushes it. In a clean testRender harness with kittyKeyboard: true, a lone \x1b reaches the composer's Escape binding after ~70 ms; pressEscape() (an unambiguous kitty sequence) is immediate. Adding a regression test for the bare byte passes.
  • I could not reproduce the permanent failure in the clean harness, so the precise reason the timeout never flushes in the live session is still open. The closest known report is #53653: bare ESC presses that arrive in one read parse as alt+escape or an unnamed key and are silently dropped, and a pending escape state can swallow later presses.

The cast and the screen reconstruction are available locally if a maintainer wants the raw events; I have not attached the recording because it contains session text. Please investigate the stdin-parser escape-timeout path — specifically how a lone ESC is flushed when the client has been busy — rather than the dialog bindings, which appear correct.

dpc00 avatar Nov 21 '26 19:11 dpc00

Thanks for the detailed report and the analysis of the recording.

I couldn't reproduce this here, and the only environment I have is Linux. I ran the released 2.3.2 in a scripted TUI session with a simulated model:

  • Command palette: with ctrl+p open, Escape presses that arrive together in one read (\x1b\x1b, \x1b\x1b\x1b) were ignored. That matches #53653. The next single Escape closed the palette, so it didn't get stuck.
  • Subagents pane: I sent bursts of Escapes while a long reply was streaming, then opened the pane with down and sent more bursts and single Escapes. The pane closed, the turn was interrupted, and the command palette opened and closed with Escape as normal.

What I couldn't get is the lasting state you describe, where every later Escape is ignored even after restarting the TUI. Since you saw it in both GhostShell and Windows Terminal, it may depend on how Windows terminals deliver input, so it needs a maintainer who can test on Windows with a long session.

If it happens again, these would help:

  • whether pressing Escape a few more times, slowly, ever clears it;
  • whether ctrl+c or another key closes the palette while Escape doesn't;
  • roughly what the session was doing just before Escape stopped working (a long streaming reply, subagents running, a resize).

opencodejr[bot] avatar Nov 21 '26 19:11 opencodejr[bot]

Additional detail from the recording relevant to the "multiple ESC in one read" theory (#53653): after ctrl+p (input event at 551.539 s), the first lone ESC byte was written to the PTY at 553.582 s, and the next one only at 555.985 s — 2.4 seconds apart. The reconstructed screen still shows the command palette open after that first ESC. So the very first, isolated Escape was already ineffective; the later bursts are not needed to explain the failure.

I agree this needs a Windows reproduction with a long session. I cannot run one myself, and I have no further diagnostic steps that do not require keyboard interaction with the stuck TUI.

dpc00 avatar Nov 21 '26 19:11 dpc00

Symptom disappeared on its own.

dpc00 avatar Nov 21 '26 20:11 dpc00

Closing since it went away on its own and couldn't be reproduced. If you still see this on the latest version, comment here and we'll reopen.

neriousy avatar Nov 23 '26 11:11 neriousy