Repository navigation
fix(terminal): send only the text a Linux IME commits, not the candidate key - #28275
Conversation
…ate key fcitx4 with Sogou reports a single-character candidate pick as a plain Space/digit keydown whose keypress and insertText carry the candidate. xterm encoded the keydown instead: under kitty keyboard mode the Space leaked and the candidate was lost, and the old Linux digit window cancelled the keydown that carried the commit. Install the native text forwarder on desktop Linux (terminal pane and dashboard preview) so printable bytes come only from committed text, and delete the Linux timer heuristics it replaces. Pair an XIM pick's keyup with its code-less press, and stop dropping unclaimed input while an xterm composition transaction settles. Replay tests use real fcitx4 recordings (Sogou via GTK module and XIM, Google Pinyin in-client preedit). Fixes #28213 Fixes #26352
📝 Walkthrough
Priority: ➖ Normal Severity of issue fixed: Medium Merge Risk: 🔵 Low · up to
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/renderer/src/components/terminal-pane/terminal-ime-native-text-forwarder.ts (1)
179-187: 🎯 Functional Correctness | 🔵 Trivial | 💤 Low valueReview the keyup elimination fallback for cross-key mispairing.
For any
keyup, the loop returns the first record whosecodeis empty. A record with an emptycodeis a claimed XIM pick. The loop does not check that thekeyupbelongs to that pick. If a pick is still held and an unrelated key is released, the release can settle the pick's record early. The release then carries the wrong key identity. The real Space keyup then has no record and falls through to xterm. The replay test covers only the sequential case, not rollover. A narrow rollover case is the only trigger. Consider restricting the fallback to a keyup that matches no held press.
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
10bc846a-e93b-4710-b9d8-d93dd4083641
📒 Files selected for processing (25)
src/renderer/src/components/dashboard-popout/AgentTerminalPreview.test.tsxsrc/renderer/src/components/dashboard-popout/preview-terminal-ime-bridge.tssrc/renderer/src/components/terminal-pane/__fixtures__/fcitx4-googlepinyin-client-preedit-trace.jsonsrc/renderer/src/components/terminal-pane/__fixtures__/fcitx4-sogou-gtk-im-module-trace.jsonsrc/renderer/src/components/terminal-pane/__fixtures__/fcitx4-sogou-xim-trace.jsonsrc/renderer/src/components/terminal-pane/terminal-ime-candidate-key-release-guard.test.tssrc/renderer/src/components/terminal-pane/terminal-ime-candidate-key-release-guard.tssrc/renderer/src/components/terminal-pane/terminal-ime-composition-tracker.tssrc/renderer/src/components/terminal-pane/terminal-ime-composition-transaction-ownership.test.tssrc/renderer/src/components/terminal-pane/terminal-ime-hangul-terminating-digit.test.tssrc/renderer/src/components/terminal-pane/terminal-ime-linux-candidate-state.test.tssrc/renderer/src/components/terminal-pane/terminal-ime-linux-candidate-state.tssrc/renderer/src/components/terminal-pane/terminal-ime-linux-claimed-preedit-release.test.tssrc/renderer/src/components/terminal-pane/terminal-ime-linux-claimed-preedit-selector.test.tssrc/renderer/src/components/terminal-pane/terminal-ime-linux-fcitx4-trace-replay.test.tssrc/renderer/src/components/terminal-pane/terminal-ime-linux-pane-replay-fixture.tssrc/renderer/src/components/terminal-pane/terminal-ime-native-text-forwarder.tssrc/renderer/src/components/terminal-pane/terminal-ios-hangul-preedit-fixture.tssrc/renderer/src/components/terminal-pane/terminal-pane-pane-input.tssrc/renderer/src/components/terminal-pane/xterm-bypass-policy-non-mac.test.tssrc/renderer/src/components/terminal-pane/xterm-bypass-policy.tstests/e2e/chinese-ime-chat-input-repro.spec.tstests/e2e/terminal-cjk-ime-committed-text.spec.tstests/e2e/terminal-ime-platform-policy.tstests/e2e/terminal-linux-claimed-preedit-selector.spec.ts
💤 Files with no reviewable changes (9)
- src/renderer/src/components/terminal-pane/terminal-ime-linux-candidate-state.test.ts
- src/renderer/src/components/terminal-pane/terminal-ios-hangul-preedit-fixture.ts
- src/renderer/src/components/terminal-pane/terminal-ime-linux-claimed-preedit-selector.test.ts
- src/renderer/src/components/terminal-pane/terminal-ime-candidate-key-release-guard.test.ts
- src/renderer/src/components/terminal-pane/terminal-ime-linux-claimed-preedit-release.test.ts
- src/renderer/src/components/terminal-pane/xterm-bypass-policy-non-mac.test.ts
- src/renderer/src/components/terminal-pane/terminal-ime-candidate-key-release-guard.ts
- src/renderer/src/components/terminal-pane/terminal-ime-linux-candidate-state.ts
- src/renderer/src/components/terminal-pane/terminal-ime-composition-tracker.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
… in the Hangul sequence The observed IBus Hangul replay dispatched a bare `a` keydown with no text insertion, which only matched reality while xterm cancelled that keydown. Now that printable Linux text comes from the committed insertText, supply it when the keydown is not cancelled and open the next session at the caret that follows it. Point the IME reliability gate at the fcitx4 replay test that replaced the deleted Linux candidate-state test.
There was a problem hiding this comment.
🔇 Additional comments: 4
config/reliability-gates.jsonc: 1
13602-13602: LGTM!Also applies to: 13605-13605, 13621-13621, 13697-13701, 13979-13979, 13981-13982
tests/e2e/terminal-ime-observed-event-sequences.ts: 2
31-49: LGTM!
76-76: LGTM!Also applies to: 84-92
config/reliability-gates.jsonc-13976-13976: 1
13976-13976: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
⚠️ Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.Update the manifest's
updatedAtdate.Line 3 still reports
2026-09-11, but this new evidence is dated2026-10-13. UpdateupdatedAtso the manifest does not report a stale date.
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
e812b9bc-9382-4242-b554-1137e2a2cf26
📒 Files selected for processing: 2
config/reliability-gates.jsonctests/e2e/terminal-ime-observed-event-sequences.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.
ELI5
You type Chinese with Sogou on Linux. You type
ni, then press Space or a number to pick the character. Orca sent the Space or the number to the terminal and often lost the Chinese character. Now the terminal sends exactly the character the input method chose.What Changed
Before (Linux, fcitx4 + Sogou Pinyin):
ni+ Space inside Claude Code produced a space.你never arrived.hao+3produced nothing in any pane.After:
你,浩, and literal keys go through exactly once. Normal typing, phrases, other input methods, macOS and Windows are unchanged.What the input method actually sends. I recorded real DOM events from Sogou on fcitx4 under X11 in Electron 43.7.5. The simulated keystrokes our existing tests used turned out to be wrong:
3key press (keyCode 32/51, not composing). The chosen character only shows up in that key'skeypressand itsinputevent (insertText "你").229/Processkey press, which already worked.Why that broke Orca. xterm turns a printable key press into bytes using the key's own name:
keypress/inputthat carry你. A space leaks and the character is lost.The mechanism I changed. macOS already solved this shape. The native text forwarder treats a plain printable key press as producing no bytes, and sends whatever the browser's
inputevent says the text system committed. This PR:terminal-ime-linux-candidate-state.ts, from fix(terminal): let Linux IMEs keep the candidate key for a preedit they own #22607 and earlier). These guessed IME ownership from timing and key codes. With the forwarder they are not needed, and they actively cancelled keys whoseinputcarried the commit;code. Without this, the app got two release reports per pick under kitty event reporting;Processcommit typed while xterm was still settling the previous composition could be lost. xterm already removes its own echo.Why
The forwarder's rule ("only committed text becomes bytes") is the real invariant here: the IME, not the key, decides the text. The timer windows tried to guess ownership after the fact. Every new engine shape needed another window, and each window could swallow a real key: #26352 is the digit window eating a literal digit.
Alternatives I rejected:
About the "agent panes work" report. In the issue, agent panes launched by Orca looked fine while a
claudestarted by hand did not. I could not find any agent-specific path in code; both end up in kitty mode. The fix does not depend on how the pane was launched.Linked Issue
Fixes #28213
Also fixes #26352: the removed digit window swallowed the first digit after a Chinese commit.
Visual Proof
N/A. This changes the bytes sent to the terminal, not the layout. The before/after is the byte stream below, recorded with real Sogou.
Real Sogou Pinyin on fcitx4: Ubuntu 22.04 container, Xvfb, Electron 43.7.5, keys driven by
xdotool. Orca's realinstallTerminalPaneInputHandlingand a real xterm are bundled from each tree.niSpace你" "你你hao3浩*浩nihaoSpace你好你好你好你好ls 7ls 7ls 7ls 7ls 7你, then Space7你 77你 7你 7niEsc Space" "" "" "" "* In one run Sogou itself committed
号, because it reorders candidates as it learns. What the IME commits is what the terminal gets.Google Pinyin with the preedit drawn inside the app (the composition-session path) gives
你/浩/你好on both trees.Testing
Tests that replay real recordings:
terminal-ime-linux-fcitx4-trace-replay.test.tsreplays the three real fcitx4 recordings (Sogou through the fcitx GTK module, Sogou through XIM, Google Pinyin with in-app preedit) through the full pane keyboard stack. It runs each with legacy keys, kitty flags 1 and kitty flags 5. 9 of its 36 cases fail onmain; all pass here. A further case checks XIM release pairing under kitty flags 3. It fails without the pairing fix.terminal-ime-hangul-terminating-digit.test.tsnow replays the recorded IBus and fcitx5 Hangul commits followed by a digit, and checks that한1reaches the terminal ([Bug]: Digit typed right after Hangul composition is dropped in the integrated terminal on Wayland (works under XWayland) #15299 stays fixed).Other test changes:
terminal-linux-claimed-preedit-selector.spec.ts(e2e) now drives the real recorded shape through CDP instead of the 229-letter shape no real engine produced.chinese-ime-chat-input-repro.spec.tsdrops one step that only passed because of the removed timer. That step expected a digit committed as4to be swallowed.Results:
pnpm tc:webis clean.terminal-pane,dashboard-popoutandliball pass.pnpm run check:code-quality:changed: 0 findings.Platforms: Linux was tested with real fcitx4 and Sogou. macOS and Windows code paths are unchanged, and their existing tests and e2e policies pass.
Review
Please look closest at:
main. Claude Code (flags 1/5) and Codex (7) are correct.Known flaky test this PR does not change.
terminal-linux-direct-ime-commit.spec.tssometimes drops the,typed right after a composition commit. Stress runs: main 7 of 40, this PR 5 of 40, with the same bytes missing. The cause is a timing race in xterm's composition helper, which lives in our xterm patch. I'd rather fix that in its own PR than mix it in here.Agent skill upstream boundary
Notes
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)