Repository navigation
Revert the terminal IME composition-ownership change - #13282
Conversation
The recorded IBus/fcitx5 and Windows MS-Korean traces from #13168 assert PTY byte order, not composition ownership, so they still hold once the terminal composition layer is restored. The mobile accessory-order test pinned the new handleLiveInputChange signature and does not. Co-authored-by: Orca <help@stably.ai>
|
Too many files changed for review (329 files, 100 file limit). Bypass the limit by tagging |
The restored native-text forwarder only claims keys for input sources in its hardcoded CJK allowlist, so third-party IMEs off that list (Qingg, #10896) still get a raw backslash. #13128 added this bypass as a partial replacement; keep it rather than trade the open issue back. Scoped to the bare backslash key. The rest of shouldBypassXtermForMacNativeText bypassed all unmodified non-ASCII text, which would race the restored forwarder. Co-authored-by: Orca <help@stably.ai>
The restored hook assigned runMirrorStepRef during render, which is not replay-safe — React can discard render work, so the mutation can leak from UI that never commits. Its only read is inside the held-commit timer, which fires long after commit, and the ref has a safe default, so an effect is soon enough. Surfaced by the changed-lines React Doctor gate: the rule postdates this code, so restoring the file re-introduced it as a new violation. Co-authored-by: Orca <help@stably.ai>
Re-landing IME composition ownership — what a second attempt must do differentlyWritten 2026-08-09, after This is not a summary of the change. It is the list of things that were wrong about how it was 1. What actually broke, and why neither was caughtA. Full-width CJK punctuation typed as ASCII (
|
| what | where |
|---|---|
| The reverted work, intact | branch nwparker/ime-xterm-ownership-parked @ 17eefef5021 |
| Punctuation reproduction (policy shape, 28 cases) | swarm-scratch/wave47-fullwidth-punct/parked/terminal-ime-xterm-punctuation-substitution.test.ts |
| Re-land checklist, executable | swarm-scratch/wave47-fullwidth-punct/parked/forwarder-form-probe.test.ts |
| Parked policy-level fix (data point only) | swarm-scratch/wave47-fullwidth-punct/parked/xterm-bypass-policy.{ts,test.ts} |
| Preedit fix (8 lines) + its red-by-design test | swarm-scratch/wave48-preedit-visible/parked/ |
forwarder-form-probe.test.ts runs 6 pass / 4 fail against the restored forwarder, and those
four failures are the remaining gaps: full-width digits, Qingg backslash, Qingg comma, Vietnamese
punctuation. Start there.
5. The restored code is NOT a good baseline — do not straight-apply it
The code the revert brings back violates both rules we adopted after the deferred-newline incident:
- Timers.
schedulePendingForwardClear()→window.setTimeout(..., 100), arming a
pending-forward window across keyup. PlusTERMINAL_LIVE_HELD_SYLLABLE_COMMIT_DELAY_MSon the
mobile side. Millisecond-bound IME sequencing is exactly what wrote a Shift+Enter payload to the
PTY with no Enter pressed, 10/10 reproducible, 203-218 ms after keydown. event.keygating.isImeNativeTextKeydownCandidatekeys onisAsciiPunctuationKey(event.key),
isCjkDirectPunctuationKey(event.key),isHangulJamoKey(event.key). A CJK IME rewriteskeyand
notcode; this cost us [Bug]: In1.4.164version, Korean typing is reflected very late in Terminal #12171 and [Bug]: Cmd+C jumps terminal scrollback to the bottom with Korean input on macOS #13033.
It also does not cover input sources outside a hardcoded 23-term allowlist
(CJK_INPUT_SOURCE_TERMS). Qingg (com.aodaren.inputmethod.Qingg) matches none of them, which is
why #10896 was open before #13128 and would reopen on a naive revert. #13282 keeps a narrowed
!kittyKeyboardActive && event.code === 'Backslash' bypass specifically to prevent that. An
allowlist of IME bundle IDs is a maintenance treadmill, not a design.
A trap to avoid: clearing _keyDownSeen when the custom key handler bypasses looks like the
clean one-line fix and closes more cases, including multi-code-unit commits (——, ……). It
double-sends the Korean Won key: resolveTerminalKoreanWonInput calls terminal.input('\')and returnsfalsewithout preventDefault, so the browser still firesinputwith₩`.
5b. State as of 2026-08-09 02:25 UTC
Main is 5a84dbb564b. Landed:
| PR | what |
|---|---|
| #13282 | the revert. Both regressions gone; !kittyKeyboardActive && event.code === 'Backslash' deliberately kept so #10896 does not reopen; contributor's Won feature preserved |
| #13283 | Korean probe teardown + epoch guard (independent of the revert) |
Open, green, unmerged: #13284 — the resumed-preedit visibility fix. Held only on release timing,
not on doubt. It is a pre-existing upstream bug, broken in every shipped build including v1.4.177.
Two carried caveats on #13284, both disclosed in its PR body:
lib/*.maphunks are not regenerated from a real upstream build, so byte offsets after the
insertion point are approximate. Degrades stack traces, not behaviour.- The revert removed the src-patch generator (
xterm-src/,xterm-upstream.json,
regenerate-xterm-patches.mjs, its doc). That doc explicitly forbade hand-editinglib/. Both the
rule and its tooling arrived with refactor(terminal): return IME composition ownership to xterm #13128 and left with the revert, so hand-maintaining the bundle
patch is the pre-refactor(terminal): return IME composition ownership to xterm #13128 status quo — but restoring correct maps means restoring the generator
(~1400 lines), which would partially un-revert Revert the terminal IME composition-ownership change #13282.
The two xterm bundles are not symmetric. lib/xterm.mjs (esbuild/ESM) and lib/xterm.js
(webpack/UMD) differ in variable binding, let vs const, and whether LRM marks are literal or
escaped. Never assume one edit ports to the other; assert a unique single match per bundle.
Android native module — do NOT re-land standalone
mobile/packages/react-native-terminal-input (250-line Kotlin TerminalInputPackage.kt) was
introduced by #13128, has never shipped (absent from v1.4.177-rc.3), and was dropped by the
revert. Dropping it costs users nothing. It is also orphaned without the rest of the mobile IME
work — the mobile composition path that consumes it was reverted too. Re-land it with that piece,
not before.
5c. Which references to trust for CJK terminal input
Corrected by the user 2026-08-09. During the ₩ investigation I leaned on a large editor's
keyboard-layout table as evidence that the OS behaviour was correct and merely ergonomically
hostile. The user reports that editor does not always handle Chinese input properly, while
iTerm2 and Warp do.
That reprioritises the reference set for anything CJK and terminal-shaped:
- Prefer iTerm2 and Warp. They are PTY-facing terminals solving the same problem — native text
arriving outside a composition session, then having to become bytes on a pty. Both reportedly get
Chinese input right, which makes them the highest-value references for the re-land. - Treat editors as weak references here. An editor owns its own text buffer and keybinding
resolution; it never has to decide what byte reaches a shell. Its layout tables describe what the
OS emits, not how a terminal should forward it. - The Zig/Swift emulator reference remains useful for the key-model question (physical vs
translated keys,intl_yenas a distinct identity) even though it ships no CJK rewrite.
Concretely for the re-land: before designing the forwarder's successor, check how iTerm2 and Warp
handle (a) full-width punctuation substitution, (b) multi-code-unit commits like —— and ……, and
(c) input sources outside any allowlist. Our 23-term CJK_INPUT_SOURCE_TERMS allowlist is the part
most likely to have no counterpart in either.
6. Process
- refactor(terminal): return IME composition ownership to xterm #13128 was 332 files squashed. That is why unrelated work (an Android native module, a macOS
period-substitution fix, an RN patch, tooling) rode along and had to be dropped by the revert. It
also made the blast radius unassessable at review time. Land the next attempt as a stack. - Do not merge on local green. Revert the terminal IME composition-ownership change #13282 passed 4408 files / 47683 tests locally and still failed
CI on a changed-lines React Doctor gate. Confirm from the CI run. - Verify the presentation path, not just the data path, before merging anything IME-shaped.
|
Update — the re-land design, researched against a mature native terminal's source. It is smaller than what was reverted. Headline: no mature terminal enumerates IMEs. Repo-wide greps across two credible native terminals return zero IME bundle IDs between them. The only input-source literals are keyboard layouts, used as negative exceptions — never to grant ownership. Both read the current input source solely for change detection ("did an IME grab this key?"), which is identity-blind and the opposite polarity of an allowlist. So the 23-term The rule that replaces it: a plain printable keydown never produces terminal bytes — bytes for printable characters come only from the It ports. We cannot call Claim on a structural predicate — keydown, no ctrl/alt/meta, What it deletes: the input-source allowlist, the candidates module, every punctuation table, and the input-source read on the hot path. Fixed as consequences rather than special cases: full-width punctuation, #10896 (and every IME that does not exist yet — it cannot structurally reopen), and multi-code-unit commits like Won/Yen should move to the input-event side rather than be special-cased. The reference does its ¥ rewrite inside Two risks worth stating rather than burying. Under kitty's Full notes are in the earlier comment on this PR, now updated. |
main reverted stablyai#13128 (`17cfc968cf`, PR stablyai#13282), which this branch was built on. Two conflicts, both from that revert. `terminal-pane/AGENTS.md` — took the deletion. The file was stablyai#13128's and the revert removed it; this branch only reformatted one line of it. `keyboard-handlers.ts` — took main's restored file and reapplied this branch's additions on top: - No IME gate in `resolveTerminalKeyboardShortcutAction`. This branch had narrowed stablyai#13128's blanket gate; with the blanket gate reverted away, adding the narrowed form back would newly suppress IME-owned events main routes through here (the Windows composing-Enter path among them). - The keydown yield is scoped to the exempt chords. stablyai#13128 yielded on every IME-owned keydown; now only a chord the IME can swallow yields, and every other IME-owned key keeps main's restored path. - The composing-Enter deferral moved out of `runShortcutAction` into a caller-supplied callback. It reads the live keydown and its `imeProcessEnter`; a chord recovered from a release has neither, and is never Enter. KNOWN RED, and not fixable by merging: 14 cases in `keyboard-handlers.issue-12871-recorded-chord-traces.test.ts`. The revert changed where terminal shortcut bytes go. Before, they went through `pane.terminal.input(...)` — xterm held them behind a live preedit and released them at commit, which is the standing safety argument in this branch's own comments. Now they go through `sendCapturedTerminalInput` → `transport.sendInput(...)`, straight to the pty with nothing holding them. So a swallowed chord recovered during a live composition lands AHEAD of the text still being composed, and the suite's spies watch a sink the bytes no longer reach. The redesign rides main's own `sendTerminalInputAfterComposition` (`terminal-ime-deferred-newline.ts`), which waits for the composition to commit. Its open decisions are enumerated in `.loop/spec/fix-ime-deferred-terminal-shortcut-input/` and land in a separate commit, so this one stays what it is: taking the revert. The other five red IME suites under `terminal-pane/` are main's own — 62 failures on `upstream/main` untouched, the same 62 here.
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.
A chord the IME swallows is recovered from its release, and until now the bytes went out there. They no longer travel through xterm: stablyai#13282 moved shortcut input onto the transport, which reaches the pty directly, so a release that fires mid-preedit puts the chord ahead of the text still being composed. With 가나 on the line and 다 in the preedit, Cmd+ArrowLeft yielded 다가나 — the cursor moved to line start and the syllable landed there. The release now defers through sendTerminalInputAfterComposition, with no time bound. The 200ms fallback is right for a newline, where arriving late still means arriving; a cursor chord sent while the preedit is open is the corruption the wait exists to prevent, and a Japanese conversion holds its candidate window open far longer than that. An abandoned composition drops the chord instead, which costs one keypress rather than a mangled line. Routing the chord back through terminal.input() was the smaller change and does not work: on the patched xterm this tree builds, a byte handed to input() during a live composition is dropped outright rather than queued behind the preedit. The recordings that show it queued predate that. A chord remapped onto a pane command keeps firing immediately. Deferring it too would let the commit land after the pane had already cleared or closed, which loses the text rather than ordering it. No platform check: what arms the recovery is a release that still reports itself composing, which an input source either produces or does not. Gating it to macOS was tried and moved nothing measurable, so it would have been an untested claim. The trace rig was watching terminal.input and terminal.onData, so every chord assertion had been reading an empty channel since stablyai#13282. Both records now follow the bytes down either route, and expectEmitted compares as a joined stream because the captures were taken when xterm flushed the preedit and the chord as one payload while the transport writes each on its own. Two captures stop mid-composition, where the contract is now "held, not sent". They assert that, then drive the commit the recording does not contain and check that the chord lands after it. The appended commit is marked as authored so it cannot be read as captured. Two expectations went stale when an earlier merge changed the bundled xterm, and both are about what xterm emits rather than what this handler sends. It no longer commits a session it never saw start, so a capture that opens mid-gesture flushes nothing; and it now commits a cancelled composition from its own buffer instead of the cleared helper textarea. The cancel case stops pinning whether that text arrives and pins that the chord is last either way. The three macOS e2e specs this branch adds are hand-run — no workflow calls them and they need real input sources — and now say so in a header line, so a red local run is not read as a regression of this change. Not touched: the two symptoms stablyai#13282 gave for the revert (full-width punctuation arriving as ASCII, an invisible Korean preedit). Both live in xterm's composition rendering, which nothing here goes near. Local: src/renderer/src/components/terminal-pane is 251 files / 3230 tests, all passing. tsc clean on all three projects, oxlint and oxfmt clean, reliability gate manifest passes for 73 gates, max-lines ratchet OK at 352. Measured after installing this worktree's own dependencies. Worktrees here resolve node_modules from the enclosing checkout, which was serving an xterm patch hash this lockfile does not ask for; the 62 failures seen before that install were entirely that mismatch. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Restore IME Enter protection in workspace details by reusing the existing composition tracker. Reset Notes ownership at textarea detachment and preserve sizing behavior. Repair isolated native test-window delivery without changing the production foreground policy or original native input assertions. Fixes #24097 Related contributor history: #10711, #11067, #13128, #13282. Original implementation and macOS recordings: @setodeve, commit b30f095. Verified on required stock Linux X11/Wayland checks and independent frozen-source review. Co-authored-by: setodeve <keinick11@outlook.com>
* Revert "test(ime): restore coverage the composition-ownership change removed (stablyai#13168)" This reverts commit d1782d4. * Revert "refactor(terminal): return IME composition ownership to xterm (stablyai#13128)" This reverts commit 45169f2. * test(ime): keep the architecture-neutral Korean trace coverage The recorded IBus/fcitx5 and Windows MS-Korean traces from stablyai#13168 assert PTY byte order, not composition ownership, so they still hold once the terminal composition layer is restored. The mobile accessory-order test pinned the new handleLiveInputChange signature and does not. Co-authored-by: Orca <help@stably.ai> * fix(terminal): keep the macOS Backslash bypass through the revert The restored native-text forwarder only claims keys for input sources in its hardcoded CJK allowlist, so third-party IMEs off that list (Qingg, stablyai#10896) still get a raw backslash. stablyai#13128 added this bypass as a partial replacement; keep it rather than trade the open issue back. Scoped to the bare backslash key. The rest of shouldBypassXtermForMacNativeText bypassed all unmodified non-ASCII text, which would race the restored forwarder. Co-authored-by: Orca <help@stably.ai> * fix(mobile): move the mirror-step ref write out of render The restored hook assigned runMirrorStepRef during render, which is not replay-safe — React can discard render work, so the mutation can leak from UI that never commits. Its only read is inside the held-commit timer, which fires long after commit, and the ref has a safe default, so an effect is soon enough. Surfaced by the changed-lines React Doctor gate: the rule postdates this code, so restoring the file re-introduced it as a new violation. Co-authored-by: Orca <help@stably.ai> --------- Co-authored-by: Orca <help@stably.ai>
Reverts the terminal IME composition-ownership change. Main is shipping two user-visible IME regressions and a release needs to go out; this restores the terminal composition layer that shipped in v1.4.177-rc.3.
The two regressions
A. Full-width CJK punctuation typed as ASCII.
,(U+FF0C) arrived as,,。(U+3002) as.. The forwarder that handles IME text arriving asinsertTextoutside a composition session (terminal-ime-native-text-forwarder.ts, plusterminal-ime-native-text-candidates.ts) was deleted by #13128. xterm's own composition handling only covers text inside a composition session, so direct-punctuation commits fell through to the raw key.B. Korean preedit invisible. 2-Set Korean showed committed syllables but not the in-progress jamo, so users typed blind until each syllable committed. The preedit anchor/overlay positioning (
terminal-ime-anchor.ts,terminal-ime-candidate-anchor.ts) was deleted by the same commit.What was reverted
17b3dff3c41— refactor(terminal): return IME composition ownership to xterm #13128, "return IME composition ownership to xterm". Cause of both regressions.25a8c517e19— test(ime): restore coverage the composition-ownership change removed #13168, the restored-coverage tests, reverted then partially re-landed (below).What was deliberately kept
24003936a53), perf(terminal): gate the Korean input-source probe on its setting #13181, fix(terminal): stop the Korean gate caching an unknown input source as negative #13182 — the contributor Won(₩)→backquote feature. Independent of the composition layer: it is a physical-key mapping gated onterminalKoreanWonToBackquote, which defaults tofalse. Its call site inuse-terminal-pane-lifecycle.tssurvived the revert unchanged and its tests pass.terminal-ime-xterm-korean-enter-commit-order.test.tsandterminal-ime-xterm-linux-native-trace-replay.test.ts(with their IBus/fcitx5 fixtures) replay recorded first-party traces and assert PTY byte order, not composition ownership. They pass unchanged after the revert and still describe correct behavior — the committed syllable must reach the terminal before the newline — so they were kept rather than thrown away. The Windows MS-Korean trace now actively guards the restored deferred-newline route, so a stale "(deleted by refactor(terminal): return IME composition ownership to xterm #13128)" comment was corrected.useImeEnterGestureOwnership. Show local and remote Quick Commands by host #13094 ("Show local and remote Quick Commands by host") landed after refactor(terminal): return IME composition ownership to xterm #13128 and builds onuse-tab-bar-quick-command-search-input.ts, which is built onuseImeEnterGestureOwnership. Reverting those would have destroyed unrelated later work.useImeEnterGestureOwnershipis self-contained, is the dialog/form Enter-guard rather than terminal composition, and is implicated in neither regression.Deliberate partial revert: the macOS Backslash bypass
xterm-bypass-policy.tsis not cleanly reverted, on purpose.git log -S"event.code === 'Backslash'"returns exactly one commit — #13128 itself — which added that bypass as a partial replacement for the deleted forwarder. A clean revert would remove it.That matters because the restored forwarder is gated on a hardcoded
CJK_INPUT_SOURCE_TERMSallowlist. Third-party IMEs off that list (Qingg,com.aodaren.inputmethod.Qingg, issue #10896) never get their key claimed, so、would arrive as\again. The reporter's,/。bug is fixed by the revert regardless — Sogou and Apple Pinyin matchpinyin— but there was no reason to trade an open issue back.So
shouldBypassXtermForMacNativeTextis kept, wired intoshouldBypassXtermKeyboardEventexactly as on main, with its three tests. It is deliberately narrowed to the bare backslash key. Main's version also bypassed all unmodified non-ASCII text; kept as-is that would race the restored forwarder and double-send. The Won key is unaffected — it is onBackquote, notBackslash.Shift+Backslash (
|) keeps main's existing expectation of not bypassing.What was dropped from #13168
mobile/src/terminal/terminal-live-native-ime-accessory-order.test.tspinned the newhandleLiveInputChangesignature and fails after the revert (TypeError: text.replace is not a function). It could not be kept.Collateral
#13128 was one squashed commit of 332 files, so the revert also removes non-IME work that rode along with it — notably the
mobile/packages/react-native-terminal-inputAndroid module,SshDisconnectedDialog.tsx,cursor-agent-parked-screen.ts,macos-automatic-period-substitution.ts, and the xterm patch-regeneration tooling. None of it is depended on by any later commit on main (verified: the only later commit touching any removed file is #13168 itself). Any of it can be re-landed independently.Preservation
The pre-revert state is parked on
nwparker/ime-xterm-ownership-parked(at17eefef5021). Re-landing is a revert-of-this-revert.Verification
npx vitest run --config config/vitest.config.ts src/pnpm --dir mobile testpnpm run typecheck(buildinfo cleared)pnpm run lintRegression proofs: the restored
terminal-ime-native-text-forwarder.test.ts(explicit,/。insertTextcoverage) and both anchor test files pass — 57 tests. All four restored files are byte-identical tov1.4.177-rc.3.src/relay/agent-exec-handler.test.tsfails only when the shell exportsGIT_CONFIG_*vars, which the test asserts on; the revert touches no file undersrc/relay. With those unset the whole suite is green, as above.For a future re-land
Root cause of A, measured rather than inferred:
CoreBrowserTerminal.ts_keyDowncallstriggerDataEvent(result.key, ...)and thenpreventDefault(), which cancels Chromium's text pipeline — the keypress andinputcarrying,never fire, so the character is destroyed before_inputEventruns. macOS-only: other platforms' frameworks claim the keydown withkeyCode 229, so their failure mode would be a drop, not an ASCII downgrade. Not gated on kitty, so the blast radius was all macOS users.A re-land is not a straight re-apply of what this PR restores. The restored code violates two constraints set after the last incident:
schedulePendingForwardClear()→window.setTimeout(..., 100)). Millisecond-bound IME sequencing caused the deferred-newline incident.event.key, notevent.code(isAsciiPunctuationKey(event.key)), the rule that cost us [Bug]: In1.4.164version, Korean typing is reflected very late in Terminal #12171 and [Bug]: Cmd+C jumps terminal scrollback to the bottom with Korean input on macOS #13033.And it must cover the two things this attempt missed:
insertTextOUTSIDE a composition session. Direct-punctuation commits never open a composition, so composition-scoped handling cannot see them. This is regression A.Do not take the "obvious" fix of clearing
_keyDownSeenwhen the custom handler bypasses: it double-sends the Korean Won key, becauseresolveTerminalKoreanWonInputcallsterminal.input('')and returnsfalsewithoutpreventDefault, so the browser still firesinputwith₩`.Vietnamese is not in this class — the built-in Telex path commits through a composition session and its test passes on main.
Executable checklist for the re-land:
/tmp/wave47-fullwidth-punct-backup/forwarder-form-probe.test.tsdrives a realTerminalwithinstallTerminalImeNativeTextForwarderwired as the old lifecycle did. Post-revert it gives 6 pass / 4 fail, and those 4 failures are the checklist: full-width digits, Qingg backslash, Qingg comma, Vietnamese punctuation. Deliberately not included in this PR.