Skip to content

fix(terminal): keep the text of an IME key pressed before a commit finalizes - #28441

Merged
nwparker merged 2 commits into
mainfrom
nwparker/ime-direct-commit-flake
Oct 14, 2026
Merged

nwparker merged 2 commits into
mainfrom
nwparker/ime-direct-commit-flake

Conversation

@nwparker

@nwparker nwparker commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​82 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​82
Prod 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​120 $\color{#cf222e}{\Huge{\mathbf{−}}}$​88 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​32

ELI5

If you finish a Chinese or Japanese word and quickly type punctuation right after it, the terminal sometimes dropped the punctuation. Now it always arrives.

What Changed

Before: a full-width comma or period typed straight after a commit could vanish: 你 then , reached the shell as 你. It only happened when the punctuation key landed in a few-millisecond window, so it showed up as an intermittent failure in terminal-linux-direct-ime-commit.spec.ts. That test failed 4 to 7 times in 40 runs, on main too.

After: the punctuation always reaches the shell. 200 stress runs since the fix have passed.

The mechanism. Orca's patched xterm finishes a composition commit on a deferred timer. I added timestamps to a failing run and got this order:

0.0ms compositionend "你"     (Chromium has already written 你 into the textarea)
2.7ms keydown Process (229)   ← the commit's finalizer is still pending
6.1ms onData "你"             ← the deferred finalizer runs
7.0ms input ","              ← nothing is emitted

Three things combine to lose the comma:

  1. The 229 key press arrived while the finalizer was pending. It took the "still composing" early return, so it never recorded that it owed its own text. An ordinary 229 key press does record this.
  2. The finalizer then cleared the pending transaction.
  3. When , arrived, there was no pending transaction and no owed text, so xterm dropped it.

The test passed whenever the timer fired before the key press or after the text.

The fix is in config/patches/xterm-src/…src.patch (CompositionHelper.ts). The shipped patch and lockfile hash were regenerated with regenerate-xterm-patches.mjs --write.

  • Key press: a 229 key press that lands after the composition ended, while its finalizer is pending, now records that it owes its own text. It only does this when the commit is already in the textarea.
  • Input: when the pending transaction handles the text itself, it clears that debt, so the text can't be sent twice.
  • IBus/fcitx5 echo: sessions still waiting for their post-composition echo keep the old path, so that echo can't be sent twice either.

Why

The bug was a missing "this key still owes text" record, so the fix restores that record. The alternatives either guess or hide the problem:

  • Treating any input during a pending transaction as new text breaks the echo dedupe that IBus and fcitx5 rely on.
  • Waiting longer in the test only hides real input loss.

Linked Issue

None. This was found while validating #28275, where it showed up as a flaky test that fails at the same rate on main.

Visual Proof

N/A. This changes terminal input bytes, not the UI. The before and after are the PTY bytes in the e2e spec (,。你。 before, ,。你,。 after).

Testing

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

New regression test:

  • terminal-ime-xterm-consumed-key-commit.test.ts uses a real xterm Terminal. It runs compositionend 你, a Process key press, then insertText ',', both with the finalizer firing between the key press and the text and without.
  • Before the fix the first case failed every time (expected '你' to be '你,'). Both cases pass now.

Results:

  • terminal-linux-direct-ime-commit.spec.ts with --repeat-each=40 --workers=4: 4 of 40 failed before the fix. After, it passed 80/80 in one set of runs and 120/120 in another.
    • One earlier 40-run batch had 2 uncaptured failures while the machine was at load average 75+. The next three batches under the same load were clean. Separately, app-launch failures were seen under that kind of load, so I believe these were launch contention, not this bug.
  • IME e2e set under the macOS, Windows and Linux policies: 19 passed. The 1 skip is the opt-in real-Codex test.
  • Unit tests in terminal-pane, dashboard-popout and lib: 12,324 passed.
  • pnpm tc:web is clean, regenerate-xterm-patches.mjs --check reports the patches in sync, and check:code-quality:changed passes.

Review

The change is narrow: it only applies when the composition has ended and its finalizer is still pending, and the commit is already in the textarea. The case where it stays on the old behaviour is a 229 key press landing between compositionend and an expected IBus/fcitx5 echo. No recorded trace has that order.

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: this is shared xterm composition code, so it affects macOS, Windows and Linux. It only changes behaviour in the narrow window described above, and the IME suites for all three platform policies pass.
  • Wire and SSH: no wire changes. SSH is unaffected because this happens in the renderer.

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)

@coderabbitai

coderabbitai Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 4 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e6d03297-8f4f-4cdd-a0cb-2b80621d5ca9
📥 Commits

Reviewing files that changed from the base of the PR and between ce94861 and 0d3222e.

⛔ Files ignored due to path filters: 1
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing: 4
  • config/patches/@[email protected]
  • config/patches/xterm-src/@[email protected]
  • src/renderer/src/components/terminal-pane/terminal-ime-xterm-composition-deduplication.test.ts
  • src/renderer/src/components/terminal-pane/terminal-ime-xterm-consumed-key-commit.test.ts
📝 Walkthrough

The patch updates IME key, input, and composition-event handling to reconcile composition commits and suppress duplicate text. It also changes composition preedit rendering and positioning, updates SortedList indexing, and exports WidthCacheFontVariantCanvas. A test checks that punctuation is emitted once in two event orderings.

Priority: ➖ Normal

Merge Risk: 🟡 Moderate · up to ce948

The IME changes fix one intermittent input-loss case, but some key orderings remain broken. Text can be dropped or typed twice, and pressing Escape right after committing a composition can lose the committed text. These cases should be fixed or explicitly accepted before merge.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Description check Warning The description is detailed and covers the user impact, mechanism, rationale, testing, platform impact, and checklist. However, the required Linked Issue section does not link an actual issue; it stat… Add an actual issue link in the Linked Issue section, using the repository's required format such as "Fixes #28275" or another applicable issue. If #28275 is not the tracked issue for this fix, link the correct issue.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary fix: preserving text from an IME key pressed before commit finalization.
Docstring Coverage Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 1…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description is detailed and covers the user impact, mechanism, rationale, testing, platform impact, and checklist. However, the required Linked Issue section does not link an actual issue; it states "None" and only references #28275 as context.

✨ Finishing Touches: 💡 1
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🛠️ Fix failing CI checks: 💡
  • 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.

Actionable comments posted: 3


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ea840c1f-73cc-4279-b9a2-2c8694a690c2
📥 Commits

Reviewing files that changed from the base of the PR and between 26a265d and ce94861.

⛔ Files ignored due to path filters: 1
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing: 3

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.

@nwparker
nwparker force-pushed the nwparker/ime-direct-commit-flake branch from ce94861 to b1aba4a Compare October 14, 2026 01:16
…nalizes

A Process (229) keydown that lands after compositionend but before xterm's deferred
finalizer runs took the composing early return and never recorded that it owed its
own commit. When the finalizer ran first, the key's insertText found no pending
transaction and no owed commit, so xterm dropped it: `你` then `,` reached the PTY
as `你`.

Record the debt for such a keydown when the ended session's commit is already in the
textarea, and clear it when the pending transaction settles the text itself. Sessions
still waiting for their post-composition echo keep their old path, so the echo cannot
be sent twice.

Fixes the intermittent terminal-linux-direct-ime-commit e2e failure.
…itionend

A plain Escape after compositionend cancelled the accepted commit, dropping both the
text and the Escape; it now settles the commit and then sends Escape. The Escape that
itself ends a session (still composing, reported after compositionend) still cancels.

A keypress for the Process key that owes a commit now clears that debt, so a later
input cannot send the key's text a second time.
@nwparker
nwparker force-pushed the nwparker/ime-direct-commit-flake branch from 1b0d0f7 to 0d3222e Compare October 14, 2026 04:26
@nwparker
nwparker merged commit 58d0de6 into main Oct 14, 2026
91 of 93 checks passed
akiya3 added a commit to akiya3/orca that referenced this pull request Oct 16, 2026
Resolve the xterm patch conflicts left by the beta.303 -> beta.304 bump
(stablyai#27935) and the consumed-key commit fix (stablyai#28441): the clause-selection
change is carried onto the beta.304 source patch, and the dist patch and
pnpm-lock.yaml patch hash are regenerated with
config/scripts/regenerate-xterm-patches.mjs (--check in sync).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01ULRg9j8BYaqbuCeANNH1AQ
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.

1 participant