Skip to content

fix(tui): allow interrupting running session regardless of prompt focus - #48607

Open
OmarAlaaeldein wants to merge 1 commit into
anomalyco:devfrom
OmarAlaaeldein:fix/tui-session-interrupt-focus
Open

OmarAlaaeldein wants to merge 1 commit into
anomalyco:devfrom
OmarAlaaeldein:fix/tui-session-interrupt-focus

Conversation

@OmarAlaaeldein

Copy link
Copy Markdown

Issue for this PR

Closes #42960

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

When using the terminal TUI, pressing Escape to interrupt a running session frequently failed to work.

In packages/tui/src/component/prompt/index.tsx, the session.interrupt command handler guarded execution with:

if (!input.focused) return

However, while a session is running/busy (executing tool commands, streaming responses, or running background tasks), the user focus is typically not on the prompt text box (e.g. while reviewing the transcript or tool output). Because of this guard:

  • The initial Escape press was ignored and never incremented store.interrupt.
  • The footer hint never updated to again to interrupt.
  • The second Escape press was also dropped, making it impossible to abort running sessions.

Since session.interrupt is already explicitly conditioned on enabled: status().type !== "idle", requiring input.focused is unnecessary and prevents intended aborts. This PR removes the !input.focused guard from session.interrupt.

How did you verify your code works?

  • Added regression unit tests in packages/tui/test/cli/tui/session-interrupt.test.ts verifying that double Escape successfully triggers session abort when the prompt input is unfocused, while respecting autocomplete popups and shell mode.
  • Ran bun test test/cli/tui/session-interrupt.test.ts (3/3 pass).
  • Ran bun run --cwd packages/tui typecheck (tsgo --noEmit passes with 0 errors).
  • Ran monorepo typecheck via bun turbo typecheck --concurrency=2 (30/30 pass).

Screenshots / recordings

N/A (TUI keybinding handling)

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

When a session is busy/streaming/running, user focus is often not on
the prompt text input (e.g. scrolling the transcript or reviewing tool output).
Guarding session.interrupt with `!input.focused` caused Escape presses to be
silently dropped, preventing users from aborting hung or long-running sessions.
Remove the input.focused check so Escape can interrupt whenever the session
status is non-idle.

Closes anomalyco#42960
@rhighs

rhighs commented Sep 27, 2026

Copy link
Copy Markdown

@adamdotdevin can we get this merged?

Comment on lines +3 to +12
// Regression test for session.interrupt in packages/tui/src/component/prompt/index.tsx
//
// Previously, session.interrupt guarded execution with `if (!input.focused) return`.
// When a session was running/busy, the text prompt input was frequently unfocused
// (e.g. while scrolling the scrollback transcript or inspecting tool output).
// As a result, pressing Escape to interrupt had no effect.
//
// With the `!input.focused` check removed from session.interrupt, pressing Escape
// while status is non-idle increments the interrupt counter and aborts the session
// on double-escape regardless of whether the prompt input has focus.

@rhighs rhighs Sep 27, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need these comments

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

V2: esc interrupt broken

2 participants