Skip to content

fix(terminal): gate Shift+Enter CSI-u on active protocol - #8427

Merged
nwparker merged 1 commit into
stablyai:mainfrom
nwparker:nwparker/bug-grok-terminal-shows-literal-13-2u-shift-ente
Jul 12, 2026
Merged

nwparker merged 1 commit into
stablyai:mainfrom
nwparker:nwparker/bug-grok-terminal-shows-literal-13-2u-shift-ente

Conversation

@nwparker

Copy link
Copy Markdown
Contributor

Description

Fixes the literal [13;2u Shift+Enter leak without broadening terminal byte routing.

  • On macOS/Linux, send Kitty CSI-u (ESC [ 13 ; 2 u) only while the pane's application has active Kitty keyboard flags.
  • Before negotiation and after a protocol reset, use the existing Esc+CR fallback.
  • Preserve current Windows behavior, including the trusted Droid-only CSI-u exception and the conservative SSH/WSL/remote fallback.
  • Keep Ctrl+Enter unchanged because the installed Grok CLI decodes it without advertising active Kitty flags; gating it would collapse the chord to plain Enter.

Closes #8385.

Evidence

Real Grok CLI

Tested the installed grok 0.2.93 (f00f96316d4b) in a real PTY:

  • PRE + CSI-u Shift+Enter + POST rendered as two composer lines.
  • Esc+CR + ALT also rendered a new composer line, confirming the safe fallback preserves Grok multiline input.
  • This Grok build emitted no Kitty push/set activation sequence during startup, which is why the broader Ctrl+Enter gate from fix(terminal): stop leaking Shift+Enter CSI-u without Kitty handshake #8386 was not taken.

Electron / PTY end to end

pnpm run test:e2e -- tests/e2e/terminal-shortcuts.spec.ts --workers=1

  • 7 passed, 1 Windows-only test skipped on macOS.
  • The regression test drives the real DOM keydown → shortcut policy → transport → IPC path and proves:
    1. inactive flags → Esc+CR
    2. PTY-output CSI > 1 u activation → CSI-u Shift+Enter
    3. PTY-output reset/pop → Esc+CR
  • The complete terminal shortcut suite also confirms Ctrl+Enter, Ctrl+C, layout input, scrolling, and other chords remain intact.

Automated checks

  • pnpm test: 2,721 files passed; 28,730 tests passed; 8 files / 40 tests skipped.
  • Focused protocol/shortcut Vitest: 53 tests passed.
  • pnpm run typecheck: passed.
  • pnpm run lint: passed (pre-existing unrelated warnings only).
  • pnpm exec oxfmt --check ...: passed.
  • Electron --mode e2e build: passed.

ELI5

CSI-u is like speaking a special keyboard language. Orca used to say “Shift+Enter” in that language even when the program had not said it understood it, so the program could print part of the instruction as [13;2u. Orca now checks the live “I understand Kitty keyboard” flag first. If it is absent, Orca uses the older safe newline chord instead.

Trade-offs

  • A TUI that understands CSI-u but never activates Kitty keyboard now receives Esc+CR for Shift+Enter. That is intentional protocol hygiene; the real Grok version was verified to treat the fallback as a newline.
  • Ctrl+Enter remains unconditional CSI-u. Changing it is outside the reported [13;2u bug and fix(terminal): stop leaking Shift+Enter CSI-u without Kitty handshake #8386's proposed gate would regress the installed Grok build to plain Enter because it does not publish active flags.
  • Windows routing remains agent-aware rather than handshake-gated. This preserves the hardened Droid path from fix(terminal): send CSI-u Shift+Enter to Droid on Windows (#7620) #7668 and avoids making Grok an unconditional Windows CSI-u exception that could recreate the leak after exit/reset.
  • This fixes the identified control-byte injection path. It does not claim to fix an unrelated long-output renderer bug if one exists independently of the leaked input.

Review of #8386

Kept the core insight: live Kitty state should gate off-Windows Shift+Enter CSI-u. Reworked the patch on current main and omitted two risky additions:

  • gating Ctrl+Enter, which regresses real Grok when it has no active Kitty flags;
  • declaring Grok as unconditional Windows CSI-u, which bypasses live state and can recreate the exact post-reset leak.

Security

No new IPC, filesystem, network, dependency, authentication, or secret surface. The change only selects between two existing key encodings for an already-open PTY.

@coderabbitai

coderabbitai Bot commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: f0ff8720-62cd-448c-932c-c705564f99e3

📥 Commits

Reviewing files that changed from the base of the PR and between d509ee7 and 1d20960.

📒 Files selected for processing (3)
  • src/renderer/src/components/terminal-pane/terminal-shortcut-policy.test.ts
  • src/renderer/src/components/terminal-pane/terminal-shortcut-policy.ts
  • tests/e2e/terminal-shortcuts.spec.ts

📝 Walkthrough

Walkthrough

Shift+Enter handling now sends the CSI-u sequence only when the pane supports it through Windows ConPTY or active Kitty keyboard reporting. Otherwise, it sends \x1b\r. Unit tests cover Kitty activity and Windows encoding variations, while end-to-end tests toggle Kitty keyboard reporting and verify the resulting PTY output.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description uses a custom format and omits required template sections like Summary, Screenshots, Testing, AI Review Report, and Notes. Rewrite the PR description to follow the template headings and include the missing Summary, Screenshots, Testing, AI Review Report, Security Audit, and Notes sections.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed It clearly summarizes the main change: Shift+Enter CSI-u now depends on active protocol state.
Linked Issues check ✅ Passed The code addresses the core #8385 fix by gating Shift+Enter CSI-u on active Kitty flags and falling back to Esc+CR otherwise.
Out of Scope Changes check ✅ Passed All changes stay within terminal shortcut policy and tests; no unrelated code paths were introduced.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@nwparker
nwparker merged commit 2306f82 into stablyai:main Jul 12, 2026
3 checks passed
@nwparker
nwparker deleted the nwparker/bug-grok-terminal-shows-literal-13-2u-shift-ente branch July 12, 2026 22:10
OrcaWin added a commit to OrcaWin/orca that referenced this pull request Jul 16, 2026
… Bash) (stablyai#7620)

Shift+Enter still submitted instead of inserting a newline when Droid ran in
Git Bash on Windows, even after the PowerShell fix (stablyai#7620/stablyai#8065/stablyai#8427).

On Windows, Orca sends Droid the kitty CSI-u byte (ESC [ 13;2u) for Shift+Enter
only when the active pane has fresh, trusted process evidence that Droid is the
foreground app; otherwise it falls back to the Codex-compatible ESC+CR, which
Droid decodes as a plain Enter and submits. That trusted evidence comes from a
confirming foreground read.

PowerShell triggers that read from its OSC 133 command-start event. Git Bash
(and cmd.exe) emit no OSC command boundary, and an Orca-launched agent delivers
its command programmatically (no typed-command inference), so a fresh Droid
spawn in those shells never earned routing trust -- leaving Shift+Enter on the
ESC+CR fallback forever.

Fix: on a fresh spawn into a no-OSC shell, seed the SAME command-start
confirmation the manually-typed launch path already uses
(paneForegroundAgentTracker.onCommandStarted). Its bounded retry ladder spans
Droid boot, and -- crucially -- a miss publishes shellForeground:false, so the
pane stays recoverable by later focus/reveal samples. (A visible-pty sample was
rejected here: on a pathologically slow boot its known-agent shell-confirm would
latch, clear launch identity, and permanently poison Shift+Enter for the rest of
the session.) A real OSC 133;C, if it arrives, simply supersedes this.

Verified on Windows 11 + Git Bash with the real Droid CLI and node-pty ConPTY:
- Droid's TUI treats ESC [ 13;2u as a newline (two-line composer) and ESC+CR as
  a submit -- exactly the reported bug and the fix's mechanism.
- droid.exe is a descendant of bash inside the ConPTY console process list (so
  the main-side scan resolves it) and becomes a live process ~0.8s after launch,
  well within the retry ladder.
Tests: regression test drives the real connectPanePty spawn path and asserts
csi-u; a slow-boot test exercises the shell->droid ladder transition; a
recoverability test proves a total-miss does NOT poison the pane (it fails
against the visible-pty approach and passes with onCommandStarted).
OrcaWin added a commit that referenced this pull request Jul 16, 2026
… Bash) (#7620) (#8948)

Shift+Enter still submitted instead of inserting a newline when Droid ran in
Git Bash on Windows, even after the PowerShell fix (#7620/#8065/#8427).

On Windows, Orca sends Droid the kitty CSI-u byte (ESC [ 13;2u) for Shift+Enter
only when the active pane has fresh, trusted process evidence that Droid is the
foreground app; otherwise it falls back to the Codex-compatible ESC+CR, which
Droid decodes as a plain Enter and submits. That trusted evidence comes from a
confirming foreground read.

PowerShell triggers that read from its OSC 133 command-start event. Git Bash
(and cmd.exe) emit no OSC command boundary, and an Orca-launched agent delivers
its command programmatically (no typed-command inference), so a fresh Droid
spawn in those shells never earned routing trust -- leaving Shift+Enter on the
ESC+CR fallback forever.

Fix: on a fresh spawn into a no-OSC shell, seed the SAME command-start
confirmation the manually-typed launch path already uses
(paneForegroundAgentTracker.onCommandStarted). Its bounded retry ladder spans
Droid boot, and -- crucially -- a miss publishes shellForeground:false, so the
pane stays recoverable by later focus/reveal samples. (A visible-pty sample was
rejected here: on a pathologically slow boot its known-agent shell-confirm would
latch, clear launch identity, and permanently poison Shift+Enter for the rest of
the session.) A real OSC 133;C, if it arrives, simply supersedes this.

Verified on Windows 11 + Git Bash with the real Droid CLI and node-pty ConPTY:
- Droid's TUI treats ESC [ 13;2u as a newline (two-line composer) and ESC+CR as
  a submit -- exactly the reported bug and the fix's mechanism.
- droid.exe is a descendant of bash inside the ConPTY console process list (so
  the main-side scan resolves it) and becomes a live process ~0.8s after launch,
  well within the retry ladder.
Tests: regression test drives the real connectPanePty spawn path and asserts
csi-u; a slow-boot test exercises the shell->droid ladder transition; a
recoverability test proves a total-miss does NOT poison the pane (it fails
against the visible-pty approach and passes with onCommandStarted).
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
… Bash) (stablyai#7620) (stablyai#8948)

Shift+Enter still submitted instead of inserting a newline when Droid ran in
Git Bash on Windows, even after the PowerShell fix (stablyai#7620/stablyai#8065/stablyai#8427).

On Windows, Orca sends Droid the kitty CSI-u byte (ESC [ 13;2u) for Shift+Enter
only when the active pane has fresh, trusted process evidence that Droid is the
foreground app; otherwise it falls back to the Codex-compatible ESC+CR, which
Droid decodes as a plain Enter and submits. That trusted evidence comes from a
confirming foreground read.

PowerShell triggers that read from its OSC 133 command-start event. Git Bash
(and cmd.exe) emit no OSC command boundary, and an Orca-launched agent delivers
its command programmatically (no typed-command inference), so a fresh Droid
spawn in those shells never earned routing trust -- leaving Shift+Enter on the
ESC+CR fallback forever.

Fix: on a fresh spawn into a no-OSC shell, seed the SAME command-start
confirmation the manually-typed launch path already uses
(paneForegroundAgentTracker.onCommandStarted). Its bounded retry ladder spans
Droid boot, and -- crucially -- a miss publishes shellForeground:false, so the
pane stays recoverable by later focus/reveal samples. (A visible-pty sample was
rejected here: on a pathologically slow boot its known-agent shell-confirm would
latch, clear launch identity, and permanently poison Shift+Enter for the rest of
the session.) A real OSC 133;C, if it arrives, simply supersedes this.

Verified on Windows 11 + Git Bash with the real Droid CLI and node-pty ConPTY:
- Droid's TUI treats ESC [ 13;2u as a newline (two-line composer) and ESC+CR as
  a submit -- exactly the reported bug and the fix's mechanism.
- droid.exe is a descendant of bash inside the ConPTY console process list (so
  the main-side scan resolves it) and becomes a live process ~0.8s after launch,
  well within the retry ladder.
Tests: regression test drives the real connectPanePty spawn path and asserts
csi-u; a slow-boot test exercises the shell->droid ladder transition; a
recoverability test proves a total-miss does NOT poison the pane (it fails
against the visible-pty approach and passes with onCommandStarted).
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.

[Bug]: Grok terminal shows literal [13;2u (Shift+Enter CSI-u leak) and long-output garble

1 participant