Skip to content

fix(ime): stop dropping and splitting composition commits in the terminal - #12942

Closed
nwparker wants to merge 1 commit into
mainfrom
nwparker/ime-backport-composition-commit-loss
Closed

nwparker wants to merge 1 commit into
mainfrom
nwparker/ime-backport-composition-commit-loss

Conversation

@nwparker

@nwparker nwparker commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Draft — opened to run CI, not to request review. Close it freely; the branch stands alone.

Backports 0ada9368fd5 to main. Two IME defects currently ship on main; both are closed by this one commit, and the behavioural change for the first is one moved line.

1. A committed composition is silently dropped

terminal-ime-composition-route.ts calls event.preventDefault() before checking whether it owns the session. The patched xterm skips its own triggerDataEvent when the session-end event is defaultPrevented, so a route that never saw the matching session start silences xterm and then returns without delivering anything. The commit vanishes — no error, no partial, no residue.

Reachable because the route's lifetime is bound to the PTY connection, not the terminal: TerminalPane.tsx:1643 deliberately keeps the pane mounted across a reconnect, so the composition survives while the route is swapped underneath it.

Fix: decide ownership first. preventDefault stays for sessions the route genuinely owns, including the ones it deliberately drops after a transport swap.

2. Enter is sent into an open preedit

The deferred-newline fallback fires finish directly, bypassing the pending-composition re-check the event path uses, so a composition still open at 200 ms takes a newline into the middle of its preedit. The same module checks whether a composition is open on one path and not the other — that asymmetry is the bug.

Fix: re-arm the deadline while a composition is pending, with the idle ceiling measured from the last compositionupdate rather than from the start, so multi-segment Japanese conversion is not split.

Scope — neither defect is Korean-specific

The drop is ownership-specific, not payload-specific: an ASCII payload through the same uncaptured-session path fails identically. Every CJK/IME user on 1.4.163–1.4.165 and on main today is exposed. Korean reporters dominate only because 2-Set Hangul composes on nearly every keystroke.

Verification

  • Cherry-picked onto origin/main with zero conflicts; terminal-ime-composition-route.ts's blob on main is byte-identical to the fix's parent, and the deferred-newline file auto-merges.
  • Merged content checked by hand: setTimeout(finish, fallbackMs) gone, main's later code guard retained, preventDefault() now after the ownership check.
  • Both suites on the merged result: 58 passed, 0 failed.
  • Two-arm reproductions rebuild from git objects — v1.4.163 fails, fixed passes — so nothing depends on scratch state.

What it does not touch

No change to the xterm patch, pty-connection.ts, or anything under src/main/daemon/. No dependency, lockfile or build change. The route's deliberate drops after a transport swap are unchanged, by design.

Made with Orca 🐋

…inal

Two ways a committed composition was lost or corrupted.

The composition route called preventDefault() before checking whether it owned
the session. A route installed mid-composition never saw the matching session
start, so it suppressed xterm's own insertion and then returned without
delivering anything — the commit vanished. Ownership is now decided first;
preventDefault stays for sessions the route does own, including the ones it
deliberately drops after a transport swap, since that drop is its decision to
make.

The deferred-newline fallback fired `finish` directly, bypassing the
pending-composition re-check that the event path uses. A composition still open
at 200 ms got a newline sent into the middle of its preedit. The deadline now
re-arms while a composition is pending, and its 2 s ceiling is measured from the
last compositionupdate rather than from the start. A slow candidate window no
longer splits the preedit, and neither does multi-segment bunsetsu conversion,
which stays legitimately pending well past any fixed total-elapsed ceiling. A
composition that stops progressing still cannot strand the keystroke.

Co-authored-by: Orca <[email protected]>

The re-arm also treats a live compositionupdate as evidence in its own right, not
just a session the route recorded. A route installed while a composition was
already in flight never saw that session start, so it has nothing to report as
pending and the deadline would otherwise split that composition too.
@nwparker

nwparker commented Aug 8, 2026

Copy link
Copy Markdown
Contributor Author

Closing as obsolete rather than superseded — this one can't be rebased.

All four files it touches (terminal-ime-composition-route.ts, terminal-ime-deferred-newline.ts and their tests) were deleted by #13128 (17b3dff), which hands composition ownership back to xterm rather than routing and deferring commits ourselves.

The deferral mechanism turned out to be the bug, not the fix. On 1.4.171 we could get Orca to write a Shift+Enter payload to the PTY with no Enter pressed — 10/10 deterministic, landing 203-218 ms after keydown, which was the 200 ms fallback firing straight past the pending-composition gate that only the event path checked. #12890 reported the same thing independently from the Japanese/Chinese side, where phrase-level preedits stay open well past that bound.

If a commit-splitting case still reproduces on current main, please reopen with a trace and I'll take it from the new baseline.

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