Skip to content

fix(terminal): stop Ctrl+Enter leaking CSI-u without kitty keyboard - #12331

Closed
ShreyanshVaibhaw wants to merge 1 commit into
stablyai:mainfrom
ShreyanshVaibhaw:fix/ctrl-enter-csi-u-fallback
Closed

ShreyanshVaibhaw wants to merge 1 commit into
stablyai:mainfrom
ShreyanshVaibhaw:fix/ctrl-enter-csi-u-fallback

Conversation

@ShreyanshVaibhaw

Copy link
Copy Markdown

Summary

Fixes #12329.

Pressing Ctrl+Enter in a local Windows ConPTY pane inserted the literal text [13;5u into the prompt instead of delivering the chord.

Ctrl+Enter emitted the kitty CSI-u sequence unconditionally:

return { type: 'sendInput', data: '\x1b[13;5u' }

CSI-u is application input. It only reads as a chord while the kitty keyboard protocol is negotiated for that pane, and on a local Windows ConPTY pane it is not, so the TUI printed the escape verbatim.

Shift+Enter, three lines above, already guards exactly this and falls back to \x1b\r:

const canSendCsiU = hasTrustedWindowsCsiU || isKittyKeyboardActivePane?.() === true
return { type: 'sendInput', data: canSendCsiU ? '\x1b[13;2u' : '\x1b\r' }

Ctrl+Enter had no such guard, and its own comment acknowledged the gap: "no Windows fallback yet (#2418)".

This gates the sequence on active kitty keyboard and otherwise sends the bare CR that xterm.js would have collapsed Ctrl+Enter to. That restores the pre-existing default rather than inventing an encoding, and matches the fallback the reporter validated locally.

Behavior change worth reviewing

The rewritten test replaces an assertion that documented the opposite assumption:

Windows uses the same kitty sequence for now: no TUI is known to treat the CSI-u Ctrl+Enter form as inert (cf. the Shift+Enter Codex-on-PowerShell case).

#12329 is the counter-example, with Codex 0.146.0 on ConPTY. So this is a deliberate reversal, not an oversight being patched. It narrows Ctrl+Enter only where the chord was never being delivered anyway: with kitty keyboard active the CSI-u path is unchanged.

I used isKittyKeyboardActivePane alone rather than also reusing Shift+Enter's getWindowsShiftEnterEncoding signal. That setting is specifically about the Shift+Enter encoding, and borrowing it to authorize a different chord would couple two unrelated decisions.

Screenshots

No visual change.

Testing

  • pnpm lint (one pre-existing unrelated failure, see Notes)

  • pnpm typecheck

  • pnpm test (full suite does not pass on this machine before or after, see Notes)

  • pnpm build (not run locally)

  • Added regression tests

  • src/renderer/src/components/terminal-pane/: 2887 passed, 218 files, 0 failed

  • New sends a bare CR for Ctrl+Enter when kitty keyboard is not active covers Windows, non-Windows, and the unset-callback case.

  • The existing CSI-u expectation is kept for the kitty-active path on both platforms, so the chord is still pinned where it works.

  • Confirmed to fail against the previous implementation: reverting the source fails exactly the new case and nothing else.

Verification caveat

I do not have Codex on a Korean IME Windows setup and did not reproduce the literal [13;5u first-hand. The diagnosis in #12329 is unusually precise (the reporter located the branch in the shipped renderer bundle and validated a fallback locally), and it matches the source exactly. Verified here by tests rather than by observation.

AI Review Report

Reviewed with Claude. Risks checked:

  • Cross-platform. No platform branch added. The guard is the kitty-keyboard capability, not an OS check, so macOS and Linux panes with negotiated KKP keep the CSI-u chord and those without get the CR they would have had from xterm.js anyway.
  • Does not disturb Shift+Enter. That branch is untouched, including its getWindowsShiftEnterEncoding trusted-Windows path.
  • Fallback choice. \r rather than Shift+Enter's \x1b\r: alt-enter means newline, whereas Ctrl+Enter collapsing to CR is the documented pre-interception xterm.js behavior, so CR is the conservative restore.
  • Flagged and addressed. The review flagged that the existing test called resolveTerminalShortcutAction positionally with 5 args and could not reach the 8th parameter. The test now uses a small helper so the kitty callback is actually exercised instead of left undefined in every case.

Security Audit

  • Input handling. This strictly reduces what is written to the PTY: an escape sequence is replaced by a single carriage return on the path where the escape was being printed as text. No new input is trusted or forwarded.
  • Command execution, path handling, auth, secrets, IPC, dependencies. Untouched. No dependency changes.
  • Worth noting the pre-fix behavior injected attacker-irrelevant but user-visible escape text into a prompt; narrowing it removes a small correctness hazard where a TUI could receive unintended literal characters.

Notes

Ctrl+Enter always emitted `\x1b[13;5u`. CSI-u is application input that only
reads as a chord while the kitty keyboard protocol is negotiated; on a local
Windows ConPTY pane it is not, so the TUI printed the escape and `[13;5u`
landed in the prompt.

Shift+Enter already guards its CSI-u emission and falls back. Ctrl+Enter did
not, and its comment acknowledged the gap ("no Windows fallback yet").

Gate the sequence on active kitty keyboard and otherwise send the bare CR
xterm.js would have collapsed the chord to, which restores the pre-existing
default rather than inventing an encoding.

This narrows Ctrl+Enter behavior where the chord was never being delivered
anyway, so the rewritten test replaces an assertion that assumed no TUI
treats the CSI-u Ctrl+Enter form as inert. stablyai#12329 is a counter-example.

Fixes stablyai#12329
@coderabbitai

coderabbitai Bot commented Aug 3, 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 Plus

Run ID: 5fccd889-76e3-45df-9651-97f61af45767

📥 Commits

Reviewing files that changed from the base of the PR and between cd68a8b and 06d3e1f.

📒 Files selected for processing (2)
  • src/renderer/src/components/terminal-pane/terminal-shortcut-policy.test.ts
  • src/renderer/src/components/terminal-pane/terminal-shortcut-policy.ts

📝 Walkthrough

Walkthrough

Ctrl+Enter now emits \x1b[13;5u only when Kitty keyboard mode is active. It emits \r when Kitty mode is inactive or unspecified. Tests cover these outcomes on Windows and non-Windows panes through a shared local helper.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the fix to prevent Ctrl+Enter from sending CSI-u without Kitty keyboard support.
Description check ✅ Passed The description covers the summary, testing, visual impact, AI review, security audit, and relevant limitations with sufficient detail.
Linked Issues check ✅ Passed The changes satisfy #12329 by gating CSI-u on active Kitty keyboard support and using a safe carriage-return fallback with regression tests.
Out of Scope Changes check ✅ Passed The changes are limited to Ctrl+Enter policy logic and focused regression tests, with no unrelated code or dependency changes.
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 commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Thanks @ShreyanshVaibhaw — independently reproduced and confirmed your diagnosis is exactly right. I built a fix before seeing this PR and we converged on the identical source change (gate on isKittyKeyboardActivePane?.() === true, fall back to \r), including the same reasoning for not reusing getWindowsShiftEnterEncoding to authorize a different chord.

Real-host confirmation on a Windows 11 local ConPTY pane (Git Bash), writing exactly the bytes the policy emitted:

$ orca terminal send --terminal term_799db70f-... --text $'\x1b[13;5u'
  "send": { "accepted": true, "bytesWritten": 7 }

# readline prompt:
$ ;5u
# with cat -v running in the same pane:
^[[13;5u

So the escape really does arrive as literal application input, as you described. With the fallback byte the same prompt executes cleanly.

One gap worth flagging: this PR updates the unit test but not the two e2e specs that still pin the old bytes — tests/e2e/terminal-shortcuts.spec.ts:540 (pressAndExpectWrite(..., 'Control+Enter', '\x1b[13;5u') in a plain, non-negotiated shell pane) and both Ctrl+Enter fixtures in tests/e2e/korean-ime-terminal-shift-enter-commit.spec.ts. Those would fail e2e CI against this source change.

I've opened #12462 with the same fix plus those e2e updates, a test for the dashboard-popout preview call site (which shares the policy), a platform × kitty-state matrix, and the real-host evidence above. Full credit to you for the find and the diagnosis — it's cited in the PR body.

@AmethystLiang

Copy link
Copy Markdown
Contributor

Duplicate of #12462 (fixes #12329).

Same root cause and intended fix: stop Ctrl+Enter from emitting kitty CSI-u into ConPTY when the pane has not negotiated kitty keyboard. Please continue review/landing on #12462. If this branch has a meaningfully different implementation detail worth cherry-picking, call it out on #12462.

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]: Ctrl+Enter leaks literal [13;5u in 1.4.167 Windows ConPTY terminal

3 participants