Repository navigation
fix(terminal): claim printable keydowns structurally so committed IME text survives - #13288
Conversation
288cd9d to
c210fec
Compare
e5bdbba to
9467ed2
Compare
Typing 2-Set Korean shows committed syllables but not the in-progress jamo, so the user composes each syllable blind. Long-standing hole in the vendored terminal library, not a regression: the same test fails identically against the bundle this branch starts from. The `.active` class that CSS keys `display: block` off is added only in `compositionstart` and dropped in `_finalizeComposition`. Some IMEs (observed on Windows/WSL Korean) resume a composition with a bare `compositionupdate` and no second `compositionstart`, by which point `compositionend` has already hidden the overlay, so the resumed preedit is written into a hidden element and never positioned. `updateCompositionElements` also early-returned on `!_isComposing`, so it would not lay the overlay out either. Re-show the overlay on an update that carries data, and key the layout guard on the shown overlay instead. `_isComposing` is deliberately left alone, so no commit bookkeeping changes and `onData` stays byte-identical. The two guards are equivalent on every pre-existing path: `compositionstart` sets both, `_finalizeComposition` clears both. The bundle hunks are the same two edits applied to the shipped minified output; the sourcemaps are carried through unchanged.
…ows capture The synthetic test pins the shape; this replays events a real Microsoft Korean IME emitted on Windows/WSL. The capture holds three compositionupdates that resume a composition with no second compositionstart — the exact ordering that wrote the preedit into a hidden overlay. Without the fix all three report shown:false; with it all three are visible. Fixture derived from the sealed 11919-windows-wsl-current capture, which is read-only and unmodified. Co-authored-by: Orca <[email protected]>
… artifact The capture logs each event twice — a dispatch record and a batched next-frame re-log. Deriving from both replayed every event twice, which made three compositionupdates appear to land after a session had ended. Filtered to dispatch records the capture holds zero resumes and 11 balanced sessions, so the previous toHaveLength(3) was pinning an artifact of the derivation. Re-scoped to what the capture does prove: the preedit stays visible across all 37 real updates. Verified by reverting the patch that this passes either way, so it is coverage and the synthetic test remains the discriminator. Both facts are now stated in the file. Co-authored-by: Orca <[email protected]>
The previous commit accidentally reverted it: checking main's patch and lockfile into the worktree to test whether a test discriminates also stages them, so the commit that followed swept them up. Co-authored-by: Orca <[email protected]>
…t survives Co-authored-by: Orca <[email protected]>
…allowlist removal The gate listed terminal-ime-input-source.test.ts, which went with the input-source allowlist. Points at the substituted-text commit test instead, which covers what the gate is actually protecting: text committed outside a composition session reaching the pty exactly once. Co-authored-by: Orca <[email protected]>
The predicate withholds a keydown's byte until the commit arrives, so a key the IME eats without committing would be dropped. Measured across the recorded corpus that case does not occur, and the browser marks IME-owned presses on the keydown itself. Both facts belong next to the predicate rather than only in a handoff note, since the obvious fix for the imagined gap is a timer, and a timer here once wrote a newline the user never typed. Co-authored-by: Orca <[email protected]>
Flag 8 asks for every printable key as an escape code; this path sends the committed text raw instead. That is a deliberate trade, not an oversight, but it was untested — the suite only covered the disambiguate flag. Pinning it makes the choice visible and records the gate to use if it ever needs closing. Co-authored-by: Orca <[email protected]>
cd73ded to
5c07f0b
Compare
39379d4 to
0b0aa25
Compare
…ched the pty Claiming the keyup unconditionally suppressed xterm's release report. That was sized for the old design, which claimed only a short punctuation list; the structural claim takes every printable keydown, so on macOS an app that negotiated kitty report_event_types stopped seeing releases for ordinary typing and would treat every printable key as held down. Suppress the release only when the press put nothing on the wire — swallowed by the input source, or owned by a composition transaction. xterm emits nothing from keyup unless kitty report_event_types (or win32 input mode) is on, so letting it through is inert everywhere else. Co-authored-by: Orca <[email protected]>
📝 WalkthroughWalkthroughThe change removes macOS input-source tracking and candidate detection from terminal IME handling. Native-text forwarding now uses structural printable-key detection, event-bounded claims, committed-byte tracking, and composition transaction handling. Terminal lifecycle and preview bridge wiring no longer provide input-source features. Tests cover forwarding behavior, substitution flows, composition ordering, and Backslash bypass behavior. Reliability gates now run the substituted-text commit test. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
📝 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.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
config/reliability-gates.jsonc (2)
6684-6689: 🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick winUpdate the assertion text for the renamed file.
The file reference now points to
terminal-ime-substituted-text-commit.test.ts, but the assertion still describes input-source classification. That behavior was removed in this PR, and the new test contains no such assertion. Describe what the new test proves instead.📝 Proposed assertion text
"file": "src/renderer/src/components/terminal-pane/terminal-ime-substituted-text-commit.test.ts", "assertions": [ - "synthetic and native input-source paths are classified for covered fixtures" + "input-source substituted text reaches the terminal instead of the raw layout characters", + "shifted, backslash-position, multi-code-unit, full-width, and letter substitutions each commit once", + "substitutions still commit with kitty disambiguate and all-keys-as-escape-codes flags negotiated" ]
6684-6689: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick winThe rename was applied to fields that are not a file path. Replacing
terminal-ime-input-source.test.tswithterminal-ime-substituted-text-commit.test.tsis correct forcommandsandtestFiles, but two other fields describe past facts or removed behavior and must not follow the rename.
config/reliability-gates.jsonc#L6684-L6689: replace the input-source classification assertion text with assertions the new test actually makes; also check the gate'scoverageNotesandoracleprose for the same stale claim.config/reliability-gates.jsonc#L6769-L6776: restore the original 2026-07-07 command, and record the new test in a separateevidenceRunsentry for a run that executed it.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: a5dea5bf-f666-477b-88a7-85aedd1972cb
📒 Files selected for processing (13)
config/reliability-gates.jsoncsrc/renderer/src/components/dashboard-popout/AgentTerminalPreview.test.tsxsrc/renderer/src/components/dashboard-popout/preview-terminal-ime-bridge.tssrc/renderer/src/components/terminal-pane/terminal-ime-input-source.test.tssrc/renderer/src/components/terminal-pane/terminal-ime-input-source.tssrc/renderer/src/components/terminal-pane/terminal-ime-native-text-candidates.tssrc/renderer/src/components/terminal-pane/terminal-ime-native-text-forwarder.test.tssrc/renderer/src/components/terminal-pane/terminal-ime-native-text-forwarder.tssrc/renderer/src/components/terminal-pane/terminal-ime-substituted-text-commit.test.tssrc/renderer/src/components/terminal-pane/terminal-ime-won-composition-order.test.tssrc/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.tssrc/renderer/src/components/terminal-pane/xterm-bypass-policy.test.tssrc/renderer/src/components/terminal-pane/xterm-bypass-policy.ts
💤 Files with no reviewable changes (4)
- src/renderer/src/components/terminal-pane/xterm-bypass-policy.ts
- src/renderer/src/components/terminal-pane/terminal-ime-native-text-candidates.ts
- src/renderer/src/components/terminal-pane/terminal-ime-input-source.test.ts
- src/renderer/src/components/terminal-pane/terminal-ime-input-source.ts
main replaced the design this branch was written against, so the conflict could not be resolved by picking a side. What changed underneath. The branch was based on eea0bb6, before stablyai#13128 gave terminal composition ownership to xterm and before stablyai#13282 reverted it. Since then stablyai#13288 made the native-text claim structural (every single printable keydown, `key` read for length only) and stablyai#13310 encodes commits as CSI-u under the kitty all-keys flag. terminal-ime-native-text-candidates.ts and the getInputSourceFeatures argument the branch built on no longer exist. Resolution, three judgments. 1. The forwarder takes main's version wholesale. The branch's punctuation feature-list claim is gone from main and reviving it would undo stablyai#13288. 2. The defect the branch reported is still in main, so it is reapplied on the new shape. claimKeyEvent bails on a chorded or composing event BEFORE the keyup branch that retires the claim, and every keyup inside a composition reports isComposing. The release is the only event that retires a claim, so the claim survives the composition; nothing else clears it until the next non-composing printable keydown or a blur. While it is stranded a keypress whose own keydown was refused (composition still live at keydown, ended by keypress) is bypassed with nothing armed to forward it, and the character is dropped. Fix: retire on a matching keyup first, then fold the chord and composition test into the return value. Every existing return value is preserved. Only the leaked state changes: a chorded or composing release returned false before and returns false now. 3. terminal-ime-native-text-claim-release.test.ts is rewritten against main's API. Its old body imported terminal-ime-native-text-candidates, which main deleted, so it could not compile. The two cases it now pins are the two the fix repairs; both fail against main's forwarder and pass against this one (verified by swapping the file back and rerunning). Verified: terminal-ime-native-text-forwarder.test.ts 32/32 (main's own, all still pass), the rewritten suite 2/2, use-terminal-pane-lifecycle 29/29, dashboard-popout 220/220. tsconfig.node, tsconfig.tc.cli, tsconfig.tc.web all 0 errors. oxlint clean. max-lines ratchet OK.
… text survives (stablyai#13288) * fix(terminal): show a preedit the IME resumes without a compositionstart Typing 2-Set Korean shows committed syllables but not the in-progress jamo, so the user composes each syllable blind. Long-standing hole in the vendored terminal library, not a regression: the same test fails identically against the bundle this branch starts from. The `.active` class that CSS keys `display: block` off is added only in `compositionstart` and dropped in `_finalizeComposition`. Some IMEs (observed on Windows/WSL Korean) resume a composition with a bare `compositionupdate` and no second `compositionstart`, by which point `compositionend` has already hidden the overlay, so the resumed preedit is written into a hidden element and never positioned. `updateCompositionElements` also early-returned on `!_isComposing`, so it would not lay the overlay out either. Re-show the overlay on an update that carries data, and key the layout guard on the shown overlay instead. `_isComposing` is deliberately left alone, so no commit bookkeeping changes and `onData` stays byte-identical. The two guards are equivalent on every pre-existing path: `compositionstart` sets both, `_finalizeComposition` clears both. The bundle hunks are the same two edits applied to the shipped minified output; the sourcemaps are carried through unchanged. * test(terminal): prove the resumed-preedit fix against a recorded Windows capture The synthetic test pins the shape; this replays events a real Microsoft Korean IME emitted on Windows/WSL. The capture holds three compositionupdates that resume a composition with no second compositionstart — the exact ordering that wrote the preedit into a hidden overlay. Without the fix all three report shown:false; with it all three are visible. Fixture derived from the sealed 11919-windows-wsl-current capture, which is read-only and unmodified. Co-authored-by: Orca <[email protected]> * test(terminal): stop the recorded Hangul fixture pinning a derivation artifact The capture logs each event twice — a dispatch record and a batched next-frame re-log. Deriving from both replayed every event twice, which made three compositionupdates appear to land after a session had ended. Filtered to dispatch records the capture holds zero resumes and 11 balanced sessions, so the previous toHaveLength(3) was pinning an artifact of the derivation. Re-scoped to what the capture does prove: the preedit stays visible across all 37 real updates. Verified by reverting the patch that this passes either way, so it is coverage and the synthetic test remains the discriminator. Both facts are now stated in the file. Co-authored-by: Orca <[email protected]> * fix(terminal): restore the preedit visibility patch onto its own branch The previous commit accidentally reverted it: checking main's patch and lockfile into the worktree to test whether a test discriminates also stages them, so the commit that followed swept them up. Co-authored-by: Orca <[email protected]> * fix(terminal): claim printable keydowns structurally so committed text survives Co-authored-by: Orca <[email protected]> * chore(reliability-gates): retarget the IME forwarding gate after the allowlist removal The gate listed terminal-ime-input-source.test.ts, which went with the input-source allowlist. Points at the substituted-text commit test instead, which covers what the gate is actually protecting: text committed outside a composition session reaching the pty exactly once. Co-authored-by: Orca <[email protected]> * docs(terminal): record why withholding a claimed keydown needs no timer The predicate withholds a keydown's byte until the commit arrives, so a key the IME eats without committing would be dropped. Measured across the recorded corpus that case does not occur, and the browser marks IME-owned presses on the keydown itself. Both facts belong next to the predicate rather than only in a handoff note, since the obvious fix for the imagined gap is a timer, and a timer here once wrote a newline the user never typed. Co-authored-by: Orca <[email protected]> * test(terminal): pin the kitty all-keys-as-escape-codes hole explicitly Flag 8 asks for every printable key as an escape code; this path sends the committed text raw instead. That is a deliberate trade, not an oversight, but it was untested — the suite only covered the disambiguate flag. Pinning it makes the choice visible and records the gate to use if it ever needs closing. Co-authored-by: Orca <[email protected]> * fix(terminal): keep the kitty key-release report for presses that reached the pty Claiming the keyup unconditionally suppressed xterm's release report. That was sized for the old design, which claimed only a short punctuation list; the structural claim takes every printable keydown, so on macOS an app that negotiated kitty report_event_types stopped seeing releases for ordinary typing and would treat every printable key as held down. Suppress the release only when the press put nothing on the wire — swallowed by the input source, or owned by a composition transaction. xterm emits nothing from keyup unless kitty report_event_types (or win32 input mode) is on, so letting it through is inert everywhere else. Co-authored-by: Orca <[email protected]> --------- Co-authored-by: Orca <[email protected]>
The design
The forwarder that #13282 restored claims a keydown when the current input source matches a
hardcoded 23-term allowlist and the key is one of several punctuation tables. This replaces
both halves with one structural predicate:
The rule it encodes: a plain printable keydown never produces terminal bytes. Bytes for printable
characters come only from the
inputevent. On macOS that event is the text system's commitcallback, and
ev.datais the text the input source actually produced. Today xterm sends the rawlayout character from the keydown and then calls
preventDefault(), which destroys the substitutedtext before Chromium can deliver it.
e.key.length === 1readskeyfor length only, never identity. That is the load-bearingdetail: it is invariant under the
keyrewrite a CJK input source performs, which is the failuremode behind #12171 and #13033. Nothing in the new code branches on which character
keyis.Length also excludes
Enter,Tab,ArrowLeft,DeadandF3without enumerating them.Why the allowlist was the wrong design, not an incomplete one
Research against mature native terminals found zero IME bundle identifiers across them. The only
input-source literals in that class of code are keyboard layouts, used as negative exceptions — never
to grant ownership. So the fix for #10896 is not "add this IME to the list"; it is to stop having a
list. Input sources that do not exist yet are covered, and #10896 cannot structurally reopen.
Probe: before and after
forwarder-form-probe.test.tsfrom the re-land checklist drives a realTerminalwired the wayuse-terminal-pane-lifecycle.tswires it.main(e172a51)The three failures were full-width digit (
1instead of1), unrecognised-source comma andVietnamese-source comma (both
,instead of,).The checklist expected 6/4, and the fourth case — unrecognised-source backslash — already passed on
main. That is not probe drift. #13282 deliberately kept a narrow!kittyKeyboardActive && event.code === 'Backslash'bypass inxterm-bypass-policy.tsso #10896would not reopen on the revert, and the probe was scored before that line existed. This PR deletes
that bypass, so the backslash case now passes on the forwarder's own merit rather than on the
workaround's — all four originally-named cases are covered.
Fixed as a consequence rather than as special cases: full-width
,/。, full-width digits,Vietnamese substitutions, multi-code-unit commits like
——(two code units from one press, freebecause
ev.datais read wholesale), and every input source outside any list.Deleted
Net −877 lines (
495 insertions, 1372 deletions); production code alone is −459(
59 insertions, 518 deletions).terminal-ime-native-text-candidates.ts(173 lines) — withisAsciiPunctuationKey,isCjkDirectPunctuationKey,isHangulJamoKey,isAsciiShortTextReplacementKey,isSyntheticUnicodeTextKeyand the 29-entry punctuation table.terminal-ime-input-source.ts(221 lines) + its test (210) — the 23-term allowlist, the fourfeature profiles, and the whole input-source tracker. Nothing else consumed it, so the
input-source read is off the keydown hot path entirely.
shouldBypassXtermForMacNativeTextand theBackslashspecial case inxterm-bypass-policy.ts.schedulePendingForwardClear()and itssetTimeout(..., 100).No timers. A stale claim — the input source swallowed the key and committed nothing — is now
dropped by the next keydown re-arming, not by elapsed time. A test asserts
vi.getTimerCount()is0 after a press whose commit never arrives.
terminal-ime-native-text-forwarder.test.tswas rewritten rather than dropped: it is the 622-linesuite that was classified safe to lose last time and turned out to be the guard for the full-width
punctuation regression.
New coverage
terminal-ime-substituted-text-commit.test.tscoversinsertTextoutside a composition session —the shape no existing test exercised, and the exact shape of the reverted regression, because every
IME test we had was composition-session-shaped (
compositionstart → update → end).One fixture changed, and why
terminal-ime-won-composition-order.test.tsdispatched a bareakeydown with nokeypressand noinputevent. Chromium cannot produce that sequence for an unprevented printable key. It onlypassed before because
awas not on the allowlist, so xterm handled the keydown directly. Thefixture now emits the full real sequence; the assertion is unchanged.
This is worth naming rather than burying: it is the first place the open risk below shows up.
Risks
Open — not closed by this PR. "The input source swallowed the key and committed nothing." A
mature native terminal re-sends the key when the OS produced no text, but does so synchronously,
which we cannot:
inputarrives after our keydown handler returns. There is no known timer-freedesign for this, and the previous timer-based attempt is what wrote a Shift+Enter payload to the
PTY with no Enter pressed, 10/10 reproducible. The working assumption is that the drop is correct
(the input source ate the key, so the terminal sees nothing) and that the old timer was really just
clearing stale state — which clearing on the next keydown now does. Unverified; settle it on
hardware before merge.
Accepted and stated, not hidden. Under the kitty
report_all_keys_as_escape_codesflag(
0b1000) printable keys should be CSI-u, while this path sends raw text. This PR does not gateon that flag: committed text is written raw under every keyboard protocol, so nothing about a
negotiated pane requires re-encoding it, and correct text beats protocol fidelity. Mature native
terminals have exactly this hole and took it deliberately. If we decide to close it, the gate must be
that single flag — not "kitty is active", which is what the deleted bypass did and which is too
coarse. macOS only either way.
Closed by running, not by reading. Returning
falsemakes xterm bail beforepreventDefault(),so the default action proceeds and
inputfires. Previously read in source only; the new test drivesa real
Terminal, checksdefaultPreventedon the dispatched keydown, and only then emits the inputevents — so this is now verified by execution.
Deliberately left out
Moving
resolveTerminalKoreanWonInput/resolveTerminalJisYenInputfrom the keydown side to theinput-event side. It is the right end state — it dissolves the Won double-send trap instead of
working around it — but it would plumb two settings into the forwarder and add code to a diff whose
whole point is minimality, and it touches a contributor's feature that needs hardware verification.
No double-send exists today: the Won handler returns before the forwarder is consulted, so the
forwarder is unarmed when the browser fires its
input. The existing ordering tests cover it.Verification
npx vitest run --config config/vitest.config.ts src/renderer/src/components/terminal-pane/ src/renderer/src/lib/pane-manager/— 311 files passedrm -f config/*.tsbuildinfo && pnpm run typecheck— cleannpx oxlint <changed files>— clean;npx oxfmt --checkcleannode config/scripts/check-react-doctor-changed.mjs— exit 0, 0 issuesNot verified on real macOS hardware with a physical CJK input source. That is the gate before this
stops being a draft.
Made with Orca 🐋