Repository navigation
fix(terminal): deliver Ctrl+C when a non-Latin input source rewrites the key - #14462
Conversation
…the key With a non-Latin input source the OS reports the layout's own glyph for `key` — a Hangul jamo on Korean 2-Set, Cyrillic es on Russian — while `code` stays KeyC. The interrupt policy read `key` for identity and only consulted `code` when `key` was empty or Unidentified, so a jamo short-circuited it to false: the press missed the ETX path and was CSI-u encoded instead, leaving a TUI running. Trust `key` only when it is a Latin letter, which keeps a Dvorak remap of C authoritative. Otherwise ask the layout map what the physical key produces unmodified: an IME layered over a Latin layout answers 'c', and over a Dvorak base answers 'j', which correctly declines. When the map is itself non-Latin it cannot answer either, so fall back to physical position — how terminals have always resolved control chords. Fixes #14460
📝 WalkthroughWalkthroughInterrupt-key detection now distinguishes Latin logical keys from non-Latin input-source glyphs. It uses the physical key’s layout mapping when available and retains physical 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/renderer/src/components/terminal-pane/xterm-bypass-policy-interrupt.test.ts (1)
110-114: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueCondense the test comments.
The test names and assertions already state most of this behavior. Keep only short comments for the non-obvious invariant.
As per coding guidelines, “Comments must be concise, non-obvious, and brief—prefer one line; do not explain obvious behavior or walk through code.”
Also applies to: 137-138, 148-148, 158-159, 170-171, 182-183
Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 29e9f46c-3b55-4a70-8a20-f8fea78d6169
📒 Files selected for processing (2)
src/renderer/src/components/terminal-pane/xterm-bypass-policy-interrupt.test.tssrc/renderer/src/components/terminal-pane/xterm-bypass-policy.ts
…the key (stablyai#14462) With a non-Latin input source the OS reports the layout's own glyph for `key` — a Hangul jamo on Korean 2-Set, Cyrillic es on Russian — while `code` stays KeyC. The interrupt policy read `key` for identity and only consulted `code` when `key` was empty or Unidentified, so a jamo short-circuited it to false: the press missed the ETX path and was CSI-u encoded instead, leaving a TUI running. Trust `key` only when it is a Latin letter, which keeps a Dvorak remap of C authoritative. Otherwise ask the layout map what the physical key produces unmodified: an IME layered over a Latin layout answers 'c', and over a Dvorak base answers 'j', which correctly declines. When the map is itself non-Latin it cannot answer either, so fall back to physical position — how terminals have always resolved control chords. Fixes stablyai#14460
Fixes #14460. Builds on @hgijeon's diagnosis and their patch in #14430 — same root cause, widened, with a hardware measurement that changes the conclusion.
Where it came from
isTerminalInterruptCKeywas introduced by #3941 (65cab0f5da1, "fix terminal kitty recovery for codex"). That PR added the ETX bypass so Ctrl+C would stop being CSI-u encoded for Codex — a real fix — but matched the logical key againstc, which only holds for Latin layouts.The bypass exists because #1247 (
eb92ba9448c) advertises the kitty keyboard protocol. With kitty active and no bypass, Ctrl+C is CSI-u encoded and never becomes ETX. So a non-Latin input source has fallen through since #3941: the bypass that rescues Latin users does not recognise the key.Reproduced
Confirmed from the code path, not just the report:
The
codefallback only ran whenkeywas empty orUnidentified. A Hangul jamo is neither, so it short-circuited tofalseand the press missed the ETX path.Four new cases fail on unmodified
main. Not Korean-only — Russian and Greek fail identically.Measured on hardware
macOS, via
UCKeyTranslateover each installed layout (virtual keycode 8 = physical C):com.apple.keylayout.ABCcU+0063com.apple.keylayout.2SetHangulㅊU+314Acom.apple.keylayout.RussianсU+0441com.apple.keylayout.ABC-AZERTY/-QWERTZcU+0063Korean 2-Set is a keyboard layout, not an IME layered over QWERTY. Its
KeyCgenuinely maps toㅊat the OS level. That is whykeyarrives as a jamo, and it means a fix that asks the layout for the base character getsㅊback, notc.The rule
keyis a Latin letter → authoritative. A Dvorak remap of C keeps working (existing test pinskey: "j"as not-an-interrupt).c; over a Dvorak base it answersjand correctly declines.Given the measurement, Korean 2-Set is resolved by tier 3, not tier 2. Tier 2 is still worth keeping: it is what makes a genuine IME-over-Latin source precise rather than merely positional, and it is @hgijeon's idea from #14430.
The important property is that the fix does not depend on which tier fires — both return the same answer here.
On #14430
Their patch resolves a non-ASCII
keythrough the layout map and then still compares the result againstc. Against the measured2SetHangullayout that comparison is'ㅊ' === 'c', which is false, so the interrupt would still be swallowed. Their unit test passes because it stubs the map with[['KeyC', 'c']].Caveat on that claim: my measurement is of the OS layout via
UCKeyTranslate. Our module reads Chromium'snavigator.keyboard.getLayoutMap(), and I have not measured Chromium's answer under a live Korean input source — if Chromium substitutes an ASCII-capable layout there, #14430 would work and tier 2 would fire instead. Tier 3 makes that difference immaterial here.Tests
xterm-bypass-policy-interrupt.test.ts, +7 cases:key(Korean jamo, Cyrillic, Greek, Hangul syllable) → interruptkey: "j"onKeyC→ still not an interruptKeyC→ not an interruptc→ interrupt; saysj→ declines; is itself non-Latin → positional fallbackVerified on real hosts at this exact commit, not just locally:
Typecheck clean.
Not verified
No live end-to-end run with the Korean input source active driving a real TUI. The layout data above is measured; the browser-level event shape comes from @hgijeon's report and their before/after recordings in #14430.
Credit
@hgijeon reported this with a correct root-cause diagnosis, the measured event shape, a working patch, and before/after recordings against the real Codex CLI.