Skip to content

feat(chat): Escape stops the running turn from the composer - #23496

Merged
iamwhatever merged 1 commit into
mainfrom
fix/22315-escape-stops-turn-v3
Oct 24, 2026
Merged

iamwhatever merged 1 commit into
mainfrom
fix/22315-escape-stops-turn-v3

Conversation

@RohanK6

@RohanK6 RohanK6 commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

Fixes #22315

Problem / Motivation

Goal: Pressing Escape in the focused prompt box stops the running turn, matching the CLI's cancel-streaming binding.

Enhancement: the dashboard had only the Stop button and no keyboard way to stop a turn; the CLI binds Esc to cancel the streaming turn.

Why it matters

Stopping a runaway or mis-aimed turn is a frequent, time-sensitive action. Reaching for the mouse to hit Stop is slower than the Escape every CLI user already has muscle memory for, and keyboard users had no equivalent at all.

Not a goal

What changed (motivation → approach → change)

  • Goal: a keyboard way to stop the turn, scoped and precedence-safe.
  • Approach: bind a bare Escape inside the composer's own key handling (not a global shortcut), behind one precedence gate that yields to everything that already owns Escape in the composer.
  • Gate: useComposerStopKey (chat-input/stopKey.ts) returns a callback (event, { native, composing }) => boolean. It claims the key only when a turn is running on this slot and no picker, dictation, approval, approval nudge, IME composition, voice read-back or other Escape owner has it, then runs the same onStop protocol the Stop button runs (first press soft-cancels, a deliberate second press after the arm window force-kills). A held (auto-repeat) Escape is swallowed and never escalates.
  • Both editors call the gate, so the binding works whichever composer is active:
stop-speaking (useKeyboardShortcuts, capture phase)
  speech playing? -> noteEscapeStoppedSpeech(e), voice-stop
        │ same keydown continues
        v
textarea keydown (keyboard.ts)          ─┐
  composing = ime.isComposing(e)          │
                                          ├─> useComposerStopKey gate ─> onStop()  (same as Stop button)
Lexical KEY_ESCAPE_COMMAND               │      yields to: IME │ escapeStoppedSpeech(e) │ picker │
  (LexicalComposerInput, "Style           │                 dictation │ approval/nudge │
   Markdown While Typing" on)            ─┘                 anotherEscapeOwnerIsOpen()
  composing = editor.isComposing() || latch || native flags

Each editor supplies its own composition verdict from its own IME latch, so an Escape that only cancels a candidate window never stops the turn in either editor. The Lexical command ignores a modified Escape and is registered at COMMAND_PRIORITY_HIGH with the editor's other key commands.

  • Voice read-back: with auto-speak on, the reply is read aloud while the turn streams, and Escape is the stop-speaking shortcut. That capture-phase listener deliberately does not preventDefault, and stopping speech clears voicePlaying synchronously, so by the time the same keydown reaches the composer the store no longer shows speech playing. The listener now records the keydown it spent in a WeakSet (utils/speechStopKey.ts: noteEscapeStoppedSpeech / escapeStoppedSpeech), and the gate yields on a marked event. So the press that silences speech never also cancels the turn, and a second press for the next sentence can't force-kill it. The next unmarked Escape stops the turn as usual. This narrows Escape in the composer should stop the running turn, like the CLI's cancel-streaming binding #22315 item 4, which let read-aloud stop share the press: it still does, but the turn is no longer the second thing that press acts on.
  • Escape-owner precedence: a shared probe anotherEscapeOwnerIsOpen() (chat-input/escapeOwners.ts) is the single rule both the stop gate and voice.ts's dictation discard consult, so the two cannot drift. It yields to:
    • [role="dialog"] surfaces (command bar, snip overlay, confirms, and the non-modal SessionControlHost, which lets Escape propagate unstopped by design and relies on this probe), except one carrying data-escape-passthrough. ComputerUseLiveView, a read-only live-desktop panel open alongside a focused composer that never steals focus or claims Escape, carries that attribute, so Escape still stops the turn while it is up.
    • [data-escape-owner]: a non-dialog surface whose own document-level handler closes on Escape whether or not the event was already handled (it does not read defaultPrevented), so without the marker one Escape would both close it and stop the turn. Carried while open by the embedded file preview (MarkdownPanel via DetailPanel's opt-in escapeOwner prop), the message-search bar (SearchBar), and the paste-preview tooltip (PastePreviewTooltip via an opt-in escapeOwner, set by PasteHoverLayer and PastedChip).
  • Dictation discard behaviour changes too, on purpose. voice.ts used to yield only to [role="dialog"]; it now asks the same shared probe. So while the file preview, the message-search bar or the paste-preview tooltip is open, Escape closes that surface and keeps the dictation (before, one Escape closed the surface and also discarded the dictation). And while the read-only live-desktop view is open, Escape now discards a dictation (before, that view's role="dialog" made Escape do nothing to it).
  • Known cost of the probe: it checks the whole document, not just the focused surface. While a file preview is open in a side panel, Escape in the focused composer closes the preview first and leaves the turn running; the next Escape stops it. That is the price of one Escape never doing two things.
  • The notification banner is deliberately not an Escape owner. Its document handler already skips an Escape whose defaultPrevented is set, and both composer claimants (stop gate, dictation discard) preventDefault the Escape they take before it bubbles to document. So with the composer focused, Escape stops the turn or discards the dictation and the pending card stays; with nothing running, Escape dismisses the card as today. Marking the banner would have made any pending card silently disable both composer bindings.
  • IME ratchet left untouched: ImeEnterClaimRatchet.test.ts keeps its original predicate. The gate takes the caller's composition verdict as a parameter and folds it into its opening compound condition, so it never presents the bare composition-decline-return shape the ratchet pins.

Backwards compatibility

Compatible: Escape still does all of its existing composer jobs first (closes a picker, discards a recording or draining dictation, dismisses a pending approval or its nudge, cancels IME composition, closes a dialog). It only falls through to stop when none of those apply and a turn is running.

Removes nothing: the diff adds a key binding, two opt-in DOM markers, three optional props (DetailPanel.escapeOwner, PastePreviewTooltip.escapeOwner, LexicalComposerInput.onEscapeStop) and a per-event speech mark the stop-speaking listener writes without changing what it does; no key, prop, record or public function is removed or renamed.

Tests

  • composerStopKey.test.ts (new): 13 cases pinning the gate's precedence matrix. Fires when running and clear; yields for not-running, no onStop, IME composing (no preventDefault either), an Escape already marked as having stopped speech (and stops on the next unmarked one), picker open, recording, draining, approval, nudge, open role="dialog", and an open data-escape-owner surface; stops the turn when the open dialog opts out with data-escape-passthrough; swallows a held Escape without escalating.
  • ChatInput.lexicalKeys.test.tsx: three new cases on the real Lexical composer. A bare Escape while a turn runs calls onStop and a Shift+Escape does not; an Escape marked by the stop-speaking listener leaves the turn running; Escape does nothing with no turn running and on a keyCode-229 (post-composition) keydown. The first case fails with the onEscapeStop wiring removed from ChatInput (checked locally).
  • ChatInput.escapeStop.test.tsx (new): the same wiring on the mounted textarea composer. Bare Escape stops, Shift+Escape doesn't, nothing with no turn running, and a speech-marked Escape leaves the turn running.
  • useKeyboardShortcuts.test.tsx: two new cases. The stop-speaking listener marks the Escape it spent, and only that one; it marks nothing when no speech is playing.
  • The three speech-marked cases above fail with the gate's escapeStoppedSpeech check removed (checked locally).
  • NotificationBanner.test.tsx: new case. An Escape already defaultPrevented by a focused surface leaves the pending card in place.
  • ComputerUseLiveView.test.tsx: asserts the rendered dialog carries data-escape-passthrough.
  • ImeEnterClaimRatchet.test.ts: all 22 cases pass against the unmodified ratchet.
  • Proof: not provable -- frontend test (prove.py runs Python only)
  • Local gates: tsc -p tsconfig.app.json clean, eslint clean on every changed file, and the related vitest subset (ChatInput, Lexical, NotificationBanner, SearchBar, MarkdownPanel, DetailPanel, voice/Dictation, Paste, composer, ratchets, i18n, ComputerUse, keyboard shortcuts) 257 files / 4647 tests passing.

Manual verification

Behavior is covered at the gate and on the mounted Lexical composer. A full live check (press Escape mid-turn in the dashboard and confirm the turn stops, while a picker, dictation or approval still takes Escape first) needs a running gateway with an active turn (and auto-speak for the read-back case), which the sandbox this was built in cannot provision.

Screenshots / video

Why no screenshot: no rendered surface changes; the change binds a key to the existing Stop protocol, and the composer, Stop button and pickers look identical.

Related Issues

Fixes #22315. Deferred items 3 and 5 are tracked in #23462. Supersedes #23463 (same change, which had to grow past two commits to take main's Windows test fix without a force-push) and fork PR #22410.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable) -- N/A, no user docs cover composer key bindings
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

Contributions are accepted under the project's Apache-2.0 license.

A bare Escape in the focused prompt box runs the same Stop protocol as the
Stop button (soft cancel, then force kill on a deliberate second press after
the arm window). A shared precedence gate (useComposerStopKey) yields to an
open picker, a recording or draining dictation, a pending approval or its
nudge, IME composition, an Escape that already stopped voice read-back, and
any other Escape owner found by the shared anotherEscapeOwnerIsOpen() probe.
A held Escape never escalates.

The gate is wired into both composer editors: the textarea's keydown and the
rich-text (Lexical) editor's KEY_ESCAPE_COMMAND, so the binding also works
with "Style Markdown While Typing" on. Each editor supplies its own IME
verdict from its own latch.

Voice read-back: the capture-phase stop-speaking listener marks the keydown
it spent (utils/speechStopKey.ts) because stopping speech clears
voicePlaying before the composer sees the key; the gate yields on a marked
event, so the press that silences speech never also cancels the turn.

The notification banner is not an Escape owner: it already skips an Escape
whose defaultPrevented is set, and the composer's claimants preventDefault,
so a pending card does not disable Escape-to-stop or dictation discard.

Refs #22315
@github-actions

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 21d882aac0fefb68a5d434c6ce296880e02a690a — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

First-Principles-Verdict: PASS

Nothing blocks: Escape-to-stop traces to issue #22315, and the precedence probe is the single shared rule. Two dictation-discard behaviour changes ride along.

Notes

  • Item 7 — rides along: the PR says "while the read-only live-desktop view is open, Escape now discards a dictation (before, that view's role="dialog" made Escape do nothing to it)". This changes dictation behaviour that the stop-key goal does not need, and no defect is cited. Subtraction: keep voice.ts on the bare [role="dialog"] probe, which leaves the passthrough affecting only the stop gate.
  • Item 5 — one consumer, generalized: data-escape-passthrough has 1 consumer (ComputerUseLiveView.tsx:362). I grepped data-escape-passthrough across website/src, excluding tests and the probe file. Subtraction: none smaller that keeps the stop working while that view is open. It is a note only.

What this change ships

Inventory (9 items) — 6 justified

Intent: stop a running turn from the keyboard with Escape in the focused prompt box, as the CLI does. ADDITION.

  1. Bare Escape in the focused composer, in both editors, stops the running turn — justified
  2. A held Escape is swallowed and never escalates to a force-kill — justified
  3. An Escape that silenced voice read-back no longer also stops the turn — justified
  4. Escape yields to the file preview, search bar and paste tooltip (data-escape-owner) — justified
  5. The live-desktop view opts out of dialog precedence (data-escape-passthrough) — one consumer, generalized
  6. Dictation discard now spares an open preview, search bar or paste tooltip — rides along
  7. Dictation discard now fires while the live-desktop view is open — rides along
  8. Optional props DetailPanel.escapeOwner, PastePreviewTooltip.escapeOwner and LexicalComposerInput.onEscapeStop — justified
  9. The trust-dialog retry hunks (TrustAppModal, AppDetailPage) match base fix(apps): retry without re-granting trust from the trust-saved dialog state #23257 and are not this head's work — justified

[FIRST-PRINCIPLES-REVIEWED] 21d882a

Description read

[DESCRIPTION-READ] 4722808ee9c43915fc97cd22ff547cb65c84ffb6ec49d3d0787d0f61aeac3da3

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 21d882aac0fefb68a5d434c6ce296880e02a690a — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

No design-level concerns: one shared precedence gate drives both editors, the stop goes through the existing onStop protocol, and the change removes nothing.

Notes

  • [data-escape-owner] only works if every future document-level Escape handler remembers to add it. One that doesn't will close itself and also stop the turn on a single Escape. A one-line pointer to escapeOwners.ts in the owning frontend spec would make the convention discoverable.
  • Because the probe checks the whole document, an open side-panel preview takes the first Escape away from a focused composer. The PR accepts this cost, but users may read it as "Escape didn't stop." Revisit if that shows up in feedback.

[DESIGN-REVIEWED] 21d882a

Description read

[DESCRIPTION-READ] f09b919618d8ece3e825113c2396c54f8efb422d46d7a8f58128672c590e4b8b

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ✅ PASS

UX-level review of 21d882aac0fefb68a5d434c6ce296880e02a690a — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

UX-Verdict: PASS

Nothing blocks. The diff adds a key binding and DOM markers only. It adds or changes no visible control, string or layout, so no screenshot is needed and none is missing.

Notes

[UX-REVIEWED] 21d882a

Description read

[DESCRIPTION-READ] eed8683e77611c3c6099ef9b93db8f39f997efb6a282602794246edbe7396436

That sha256 names everything this verdict read: the PR description, plus the 3 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 21d882aac0fefb68a5d434c6ce296880e02a690a and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 21d882a

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 21d882aac0fefb68a5d434c6ce296880e02a690a: <one-sentence reason>

@github-actions

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 21d882aac0fefb68a5d434c6ce296880e02a690a — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 21d882a

Verdict parsed from the review's SHA-scoped output markers for commit 21d882aac0fefb68a5d434c6ce296880e02a690a.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 21d882aac0fefb68a5d434c6ce296880e02a690a: <one-sentence reason>

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Oct 23, 2026

@iamwhatever iamwhatever left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

APPROVE at 21d882a.

A bare Escape in either composer editor now runs the same onStop as the Stop button. It goes through one gate that yields to IME, pickers, dictation, approvals, an Escape that stopped speech, and any other open Escape owner. A held Escape is swallowed, so it never escalates to a force-kill (stopKey.ts#L53-L83). The live-desktop view opt-out is safe because that view has no Escape handling of its own.

All AI lanes pass with notes only. The ride-along dictation change and the whole-document probe cost are explained in the description. The deferred double-tap setting, rebindable shortcut and Stop tooltip are tracked in #23462. PR Readiness is green, and the PR is mergeable. The queued Sensitive Change Review and Publish readiness signal runs are not required checks.

A new commit needs a new review.

— crew-pr-reviewer (r123)

@iamwhatever
iamwhatever merged commit 1fec550 into main Oct 24, 2026
104 of 185 checks passed
@iamwhatever
iamwhatever deleted the fix/22315-escape-stops-turn-v3 branch October 24, 2026 02:48
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 24, 2026
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.

Escape in the composer should stop the running turn, like the CLI's cancel-streaming binding

2 participants