Repository navigation
feat(chat): Escape stops the running turn from the composer - #23496
Conversation
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
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of 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
What this change shipsInventory (9 items) — 6 justifiedIntent: stop a running turn from the keyboard with Escape in the focused prompt box, as the CLI does. ADDITION.
[FIRST-PRINCIPLES-REVIEWED] 21d882a Description read[DESCRIPTION-READ] 4722808ee9c43915fc97cd22ff547cb65c84ffb6ec49d3d0787d0f61aeac3da3 That sha256 names the PR description this verdict read. Recompute it with |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS No design-level concerns: one shared precedence gate drives both editors, the stop goes through the existing Notes
[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 |
UX Review (Opus 5.5) — ✅ PASSUX-level review of 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 |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
iamwhatever
left a comment
There was a problem hiding this comment.
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)
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
DEFAULT_SHORTCUTSentry with a Stop-button tooltip (Escape in the composer should stop the running turn, like the CLI's cancel-streaming binding #22315 item 5). Tracked in Escape-to-stop: double-tap setting and rebindable stop-turn shortcut (follow-up to #22315) #23462.What changed (motivation → approach → change)
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 sameonStopprotocol 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.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_HIGHwith the editor's other key commands.preventDefault, and stopping speech clearsvoicePlayingsynchronously, 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 aWeakSet(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.anotherEscapeOwnerIsOpen()(chat-input/escapeOwners.ts) is the single rule both the stop gate andvoice.ts's dictation discard consult, so the two cannot drift. It yields to:[role="dialog"]surfaces (command bar, snip overlay, confirms, and the non-modalSessionControlHost, which lets Escape propagate unstopped by design and relies on this probe), except one carryingdata-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 readdefaultPrevented), so without the marker one Escape would both close it and stop the turn. Carried while open by the embedded file preview (MarkdownPanelviaDetailPanel's opt-inescapeOwnerprop), the message-search bar (SearchBar), and the paste-preview tooltip (PastePreviewTooltipvia an opt-inescapeOwner, set byPasteHoverLayerandPastedChip).voice.tsused 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'srole="dialog"made Escape do nothing to it).defaultPreventedis set, and both composer claimants (stop gate, dictation discard)preventDefaultthe Escape they take before it bubbles todocument. 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.ImeEnterClaimRatchet.test.tskeeps 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, noonStop, IME composing (nopreventDefaulteither), an Escape already marked as having stopped speech (and stops on the next unmarked one), picker open, recording, draining, approval, nudge, openrole="dialog", and an opendata-escape-ownersurface; stops the turn when the open dialog opts out withdata-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 callsonStopand 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 theonEscapeStopwiring removed fromChatInput(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.escapeStoppedSpeechcheck removed (checked locally).NotificationBanner.test.tsx: new case. An Escape alreadydefaultPreventedby a focused surface leaves the pending card in place.ComputerUseLiveView.test.tsx: asserts the rendered dialog carriesdata-escape-passthrough.ImeEnterClaimRatchet.test.ts: all 22 cases pass against the unmodified ratchet.tsc -p tsconfig.app.jsonclean,eslintclean 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
Contribution License Agreement
Contributions are accepted under the project's Apache-2.0 license.