Skip to content

fix(terminal): send only the text a Linux IME commits, not the candidate key - #28275

Merged
nwparker merged 2 commits into
mainfrom
nwparker/IME-ja-here-10-13
Oct 13, 2026
Merged

nwparker merged 2 commits into
mainfrom
nwparker/IME-ja-here-10-13

Conversation

@nwparker

@nwparker nwparker commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 17 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1822 $\color{#cf222e}{\Huge{\mathbf{−}}}$​946 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​876
Prod 10 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​193 $\color{#cf222e}{\Huge{\mathbf{−}}}$​471 $\color{#cf222e}{\Huge{\mathbf{−}}}$​278

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 + 3 produced nothing in any pane.
  • A literal Space typed right after a pick could turn into an extra space.

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:

  • The letters you spell arrive as key releases only. There are no key presses for them.
  • A one-character pick arrives as an ordinary Space or 3 key press (keyCode 32/51, not composing). The chosen character only shows up in that key's keypress and its input event (insertText "你").
  • A multi-character phrase arrives as a 229/Process key press, which already worked.

Why that broke Orca. xterm turns a printable key press into bytes using the key's own name:

  • When a program turns on the kitty keyboard protocol, as Claude Code does, xterm encodes Space at the key press and cancels it. Chromium then never fires the keypress/input that carry 你. A space leaks and the character is lost.
  • Digits are sent from the key press in every mode. On top of that, an old Linux timer window cancelled the digit key press, which threw away Sogou's commit along with it.

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 input event says the text system committed. This PR:

  • installs that forwarder on desktop Linux, in both the terminal pane and the dashboard terminal preview;
  • deletes the two Linux timer windows it replaces (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 whose input carried the commit;
  • removes the Hangul-preedit tracking that only those windows used;
  • pairs a key release with its press when XIM delivers the press with an empty code. Without this, the app got two release reports per pick under kitty event reporting;
  • narrows the forwarder's "a composition transaction already owns this text" drop to presses the forwarder itself claimed. Before, it also stopped unclaimed input, so on Linux a Process commit 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 claude started 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 real installTerminalPaneInputHandling and a real xterm are bundled from each tree.

typed main, legacy keys main, kitty 1 (Claude Code) this PR, legacy this PR, kitty 1
ni Space 你 " " 你 你
hao 3 nothing nothing 浩* 浩
nihao Space 你好 你好 你好 你好
IME off: ls 7 ls 7 ls 7 ls 7 ls 7
pick 你, then Space 7 你 7 7 你 7 你 7
ni Esc 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

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

Tests that replay real recordings:

  • terminal-ime-linux-fcitx4-trace-replay.test.ts replays 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 on main; 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.ts now replays the recorded IBus and fcitx5 Hangul commits followed by a digit, and checks that 한1 reaches 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.ts drops one step that only passed because of the removed timer. That step expected a digit committed as 4 to be swallowed.

Results:

  • pnpm tc:web is clean.
  • Unit tests in terminal-pane, dashboard-popout and lib all pass.
  • Terminal IME e2e specs (Linux, macOS and Windows platform policies): 15 passed, 5 skipped. The skipped ones need a real Codex CLI.
  • 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:

Known flaky test this PR does not change. terminal-linux-direct-ime-commit.spec.ts sometimes 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

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Platforms: Linux only in effect. The forwarder already ran on macOS. Windows is untouched. Android, ChromeOS and iOS web are excluded.
  • SSH and folder workspaces: unaffected. The decision happens in the renderer before any bytes are written, so local and remote hosts behave the same.
  • Wire, security, performance: no wire or protocol changes, no new permissions. Performance is neutral: this removes a per-keystroke state machine and its global listeners.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

…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
@coderabbitai

coderabbitai Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Walkthrough

The shared native-text forwarder now supports desktop Linux as well as macOS. The terminal pane removes Linux-specific candidate-state tracking and uses the shared composition and candidate-key policy. The preview bridge also permits Linux. New recorded-event fixtures and replay tests cover fcitx4 input, candidate commits, ordinary text, and post-commit digits.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: 🔵 Low · up to 20ff8

A rare Linux/XIM key rollover can pair a release with the wrong press and disrupt terminal input. This is a bounded but unresolved edge case.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 52.38% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 21 functions across 14 files. (1 skipped:… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: Linux IME input now sends committed text instead of the candidate key.
Description check Passed The description is complete and aligned with the repository template. It includes the user impact, implementation details, rationale, linked issues, visual-proof justification, testing results, platfo…
Linked Issues check Passed The PR meets the coding requirements for [#28213] and [#26352]. installTerminalPaneInputHandling installs the native text forwarder for desktop Linux without agent classification. The forwarder send…
Out of Scope Changes check Passed The changes remain within the linked issue scope. The dashboard preview uses the same Linux terminal input behavior. The new fixtures and replay tests provide automated coverage for the reported IME e…
Full details: Docstring Coverage

Explanation

Docstring coverage is 52.38% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 21 functions across 14 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/renderer/src/components/terminal-pane/terminal-ime-native-text-forwarder.ts (1)

179-187: 🎯 Functional Correctness | 🔵 Trivial | 💤 Low value

Review the keyup elimination fallback for cross-key mispairing.

For any keyup, the loop returns the first record whose code is empty. A record with an empty code is a claimed XIM pick. The loop does not check that the keyup belongs 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
📥 Commits

Reviewing files that changed from the base of the PR and between 9e52645 and 6c1c121.

📒 Files selected for processing (25)
  • src/renderer/src/components/dashboard-popout/AgentTerminalPreview.test.tsx
  • src/renderer/src/components/dashboard-popout/preview-terminal-ime-bridge.ts
  • src/renderer/src/components/terminal-pane/__fixtures__/fcitx4-googlepinyin-client-preedit-trace.json
  • src/renderer/src/components/terminal-pane/__fixtures__/fcitx4-sogou-gtk-im-module-trace.json
  • src/renderer/src/components/terminal-pane/__fixtures__/fcitx4-sogou-xim-trace.json
  • src/renderer/src/components/terminal-pane/terminal-ime-candidate-key-release-guard.test.ts
  • src/renderer/src/components/terminal-pane/terminal-ime-candidate-key-release-guard.ts
  • src/renderer/src/components/terminal-pane/terminal-ime-composition-tracker.ts
  • src/renderer/src/components/terminal-pane/terminal-ime-composition-transaction-ownership.test.ts
  • src/renderer/src/components/terminal-pane/terminal-ime-hangul-terminating-digit.test.ts
  • src/renderer/src/components/terminal-pane/terminal-ime-linux-candidate-state.test.ts
  • src/renderer/src/components/terminal-pane/terminal-ime-linux-candidate-state.ts
  • src/renderer/src/components/terminal-pane/terminal-ime-linux-claimed-preedit-release.test.ts
  • src/renderer/src/components/terminal-pane/terminal-ime-linux-claimed-preedit-selector.test.ts
  • src/renderer/src/components/terminal-pane/terminal-ime-linux-fcitx4-trace-replay.test.ts
  • src/renderer/src/components/terminal-pane/terminal-ime-linux-pane-replay-fixture.ts
  • src/renderer/src/components/terminal-pane/terminal-ime-native-text-forwarder.ts
  • src/renderer/src/components/terminal-pane/terminal-ios-hangul-preedit-fixture.ts
  • src/renderer/src/components/terminal-pane/terminal-pane-pane-input.ts
  • src/renderer/src/components/terminal-pane/xterm-bypass-policy-non-mac.test.ts
  • src/renderer/src/components/terminal-pane/xterm-bypass-policy.ts
  • tests/e2e/chinese-ime-chat-input-repro.spec.ts
  • tests/e2e/terminal-cjk-ime-committed-text.spec.ts
  • tests/e2e/terminal-ime-platform-policy.ts
  • tests/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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔇 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 updatedAt date.

Line 3 still reports 2026-09-11, but this new evidence is dated 2026-10-13. Update updatedAt so 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
📥 Commits

Reviewing files that changed from the base of the PR and between 6c1c121 and 20ff856.

📒 Files selected for processing: 2
  • config/reliability-gates.jsonc
  • tests/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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant