Skip to content

fix(terminal): claim printable keydowns structurally so committed IME text survives - #13288

Merged
nwparker merged 10 commits into
mainfrom
nwparker/ime-structural-forwarder
Aug 9, 2026
Merged

nwparker merged 10 commits into
mainfrom
nwparker/ime-structural-forwarder

Conversation

@nwparker

@nwparker nwparker commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

DRAFT — NOT FOR MERGE YET. A release is being cut from main; this must not land tonight.
It needs hardware verification on macOS before it is merge-ready (see Open risk).

The design

The forwarder that #13282 restored claims a keydown when the current input source matches a
hardcoded 23-term allowlist
and the key is one of several punctuation tables. This replaces
both halves with one structural predicate:

e.type === 'keydown'
  && !e.ctrlKey && !e.altKey && !e.metaKey
  && e.key.length === 1
  && !e.isComposing

The rule it encodes: a plain printable keydown never produces terminal bytes. Bytes for printable
characters come only from the input event.
On macOS that event is the text system's commit
callback, and ev.data is the text the input source actually produced. Today xterm sends the raw
layout character from the keydown and then calls preventDefault(), which destroys the substituted
text before Chromium can deliver it.

e.key.length === 1 reads key for length only, never identity. That is the load-bearing
detail: it is invariant under the key rewrite a CJK input source performs, which is the failure
mode behind #12171 and #13033. Nothing in the new code branches on which character key is.
Length also excludes Enter, Tab, ArrowLeft, Dead and F3 without enumerating them.

Why the allowlist was the wrong design, not an incomplete one

Research against mature native terminals found zero IME bundle identifiers across them. The only
input-source literals in that class of code are keyboard layouts, used as negative exceptions — never
to grant ownership. So the fix for #10896 is not "add this IME to the list"; it is to stop having a
list. Input sources that do not exist yet are covered, and #10896 cannot structurally reopen.

Probe: before and after

forwarder-form-probe.test.ts from the re-land checklist drives a real Terminal wired the way
use-terminal-pane-lifecycle.ts wires it.

against main (e172a51) with this change
result 7 pass / 3 fail 10 pass / 0 fail

The three failures were full-width digit (1 instead of 1), unrecognised-source comma and
Vietnamese-source comma (both , instead of ,).

The checklist expected 6/4, and the fourth case — unrecognised-source backslash — already passed on
main.
That is not probe drift. #13282 deliberately kept a narrow
!kittyKeyboardActive && event.code === 'Backslash' bypass in xterm-bypass-policy.ts so #10896
would not reopen on the revert, and the probe was scored before that line existed. This PR deletes
that bypass
, so the backslash case now passes on the forwarder's own merit rather than on the
workaround's — all four originally-named cases are covered.

Fixed as a consequence rather than as special cases: full-width ,/。, full-width digits,
Vietnamese substitutions, multi-code-unit commits like —— (two code units from one press, free
because ev.data is read wholesale), and every input source outside any list.

Deleted

Net −877 lines (495 insertions, 1372 deletions); production code alone is −459
(59 insertions, 518 deletions).

  • terminal-ime-native-text-candidates.ts (173 lines) — with isAsciiPunctuationKey,
    isCjkDirectPunctuationKey, isHangulJamoKey, isAsciiShortTextReplacementKey,
    isSyntheticUnicodeTextKey and the 29-entry punctuation table.
  • terminal-ime-input-source.ts (221 lines) + its test (210) — the 23-term allowlist, the four
    feature profiles, and the whole input-source tracker. Nothing else consumed it, so the
    input-source read is off the keydown hot path entirely.
  • shouldBypassXtermForMacNativeText and the Backslash special case in xterm-bypass-policy.ts.
  • schedulePendingForwardClear() and its setTimeout(..., 100).

No timers. A stale claim — the input source swallowed the key and committed nothing — is now
dropped by the next keydown re-arming, not by elapsed time. A test asserts vi.getTimerCount() is
0 after a press whose commit never arrives.

terminal-ime-native-text-forwarder.test.ts was rewritten rather than dropped: it is the 622-line
suite that was classified safe to lose last time and turned out to be the guard for the full-width
punctuation regression.

New coverage

terminal-ime-substituted-text-commit.test.ts covers insertText outside a composition session —
the shape no existing test exercised, and the exact shape of the reverted regression, because every
IME test we had was composition-session-shaped (compositionstart → update → end).

One fixture changed, and why

terminal-ime-won-composition-order.test.ts dispatched a bare a keydown with no keypress and no
input event
. Chromium cannot produce that sequence for an unprevented printable key. It only
passed before because a was not on the allowlist, so xterm handled the keydown directly. The
fixture now emits the full real sequence; the assertion is unchanged.

This is worth naming rather than burying: it is the first place the open risk below shows up.

Risks

Open — not closed by this PR. "The input source swallowed the key and committed nothing." A
mature native terminal re-sends the key when the OS produced no text, but does so synchronously,
which we cannot: input arrives after our keydown handler returns. There is no known timer-free
design for this
, and the previous timer-based attempt is what wrote a Shift+Enter payload to the
PTY with no Enter pressed, 10/10 reproducible. The working assumption is that the drop is correct
(the input source ate the key, so the terminal sees nothing) and that the old timer was really just
clearing stale state — which clearing on the next keydown now does. Unverified; settle it on
hardware before merge.

Accepted and stated, not hidden. Under the kitty report_all_keys_as_escape_codes flag
(0b1000) printable keys should be CSI-u, while this path sends raw text. This PR does not gate
on that flag: committed text is written raw under every keyboard protocol, so nothing about a
negotiated pane requires re-encoding it, and correct text beats protocol fidelity. Mature native
terminals have exactly this hole and took it deliberately. If we decide to close it, the gate must be
that single flag — not "kitty is active", which is what the deleted bypass did and which is too
coarse. macOS only either way.

Closed by running, not by reading. Returning false makes xterm bail before preventDefault(),
so the default action proceeds and input fires. Previously read in source only; the new test drives
a real Terminal, checks defaultPrevented on the dispatched keydown, and only then emits the input
events — so this is now verified by execution.

Deliberately left out

Moving resolveTerminalKoreanWonInput / resolveTerminalJisYenInput from the keydown side to the
input-event side. It is the right end state — it dissolves the Won double-send trap instead of
working around it — but it would plumb two settings into the forwarder and add code to a diff whose
whole point is minimality, and it touches a contributor's feature that needs hardware verification.
No double-send exists today: the Won handler returns before the forwarder is consulted, so the
forwarder is unarmed when the browser fires its input. The existing ordering tests cover it.

Verification

  • npx vitest run --config config/vitest.config.ts src/renderer/src/components/terminal-pane/ src/renderer/src/lib/pane-manager/ — 311 files passed
  • rm -f config/*.tsbuildinfo && pnpm run typecheck — clean
  • npx oxlint <changed files> — clean; npx oxfmt --check clean
  • node config/scripts/check-react-doctor-changed.mjs — exit 0, 0 issues

Not verified on real macOS hardware with a physical CJK input source. That is the gate before this
stops being a draft.

Made with Orca 🐋

@nwparker
nwparker force-pushed the nwparker/ime-structural-forwarder branch from 288cd9d to c210fec Compare August 9, 2026 03:15
@nwparker
nwparker changed the base branch from main to nwparker/ime-resumed-preedit-visibility August 9, 2026 03:16
@nwparker
nwparker force-pushed the nwparker/ime-structural-forwarder branch from e5bdbba to 9467ed2 Compare August 9, 2026 03:34
nwparker and others added 8 commits August 9, 2026 01:09
Typing 2-Set Korean shows committed syllables but not the in-progress jamo, so
the user composes each syllable blind. Long-standing hole in the vendored
terminal library, not a regression: the same test fails identically against the
bundle this branch starts from.

The `.active` class that CSS keys `display: block` off is added only in
`compositionstart` and dropped in `_finalizeComposition`. Some IMEs (observed on
Windows/WSL Korean) resume a composition with a bare `compositionupdate` and no
second `compositionstart`, by which point `compositionend` has already hidden the
overlay, so the resumed preedit is written into a hidden element and never
positioned. `updateCompositionElements` also early-returned on `!_isComposing`,
so it would not lay the overlay out either.

Re-show the overlay on an update that carries data, and key the layout guard on
the shown overlay instead. `_isComposing` is deliberately left alone, so no
commit bookkeeping changes and `onData` stays byte-identical. The two guards are
equivalent on every pre-existing path: `compositionstart` sets both,
`_finalizeComposition` clears both.

The bundle hunks are the same two edits applied to the shipped minified output;
the sourcemaps are carried through unchanged.
…ows capture

The synthetic test pins the shape; this replays events a real Microsoft Korean
IME emitted on Windows/WSL. The capture holds three compositionupdates that
resume a composition with no second compositionstart — the exact ordering that
wrote the preedit into a hidden overlay.

Without the fix all three report shown:false; with it all three are visible.
Fixture derived from the sealed 11919-windows-wsl-current capture, which is
read-only and unmodified.

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

The capture logs each event twice — a dispatch record and a batched next-frame
re-log. Deriving from both replayed every event twice, which made three
compositionupdates appear to land after a session had ended. Filtered to
dispatch records the capture holds zero resumes and 11 balanced sessions, so
the previous toHaveLength(3) was pinning an artifact of the derivation.

Re-scoped to what the capture does prove: the preedit stays visible across all
37 real updates. Verified by reverting the patch that this passes either way,
so it is coverage and the synthetic test remains the discriminator. Both facts
are now stated in the file.

Co-authored-by: Orca <[email protected]>
The previous commit accidentally reverted it: checking main's patch and lockfile
into the worktree to test whether a test discriminates also stages them, so the
commit that followed swept them up.

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

The gate listed terminal-ime-input-source.test.ts, which went with the
input-source allowlist. Points at the substituted-text commit test instead,
which covers what the gate is actually protecting: text committed outside a
composition session reaching the pty exactly once.

Co-authored-by: Orca <[email protected]>
The predicate withholds a keydown's byte until the commit arrives, so a key the
IME eats without committing would be dropped. Measured across the recorded
corpus that case does not occur, and the browser marks IME-owned presses on the
keydown itself. Both facts belong next to the predicate rather than only in a
handoff note, since the obvious fix for the imagined gap is a timer, and a timer
here once wrote a newline the user never typed.

Co-authored-by: Orca <[email protected]>
Flag 8 asks for every printable key as an escape code; this path sends the
committed text raw instead. That is a deliberate trade, not an oversight, but it
was untested — the suite only covered the disambiguate flag. Pinning it makes
the choice visible and records the gate to use if it ever needs closing.

Co-authored-by: Orca <[email protected]>
@nwparker
nwparker force-pushed the nwparker/ime-resumed-preedit-visibility branch from cd73ded to 5c07f0b Compare August 9, 2026 08:17
@nwparker
nwparker force-pushed the nwparker/ime-structural-forwarder branch from 39379d4 to 0b0aa25 Compare August 9, 2026 08:17
…ched the pty

Claiming the keyup unconditionally suppressed xterm's release report. That was
sized for the old design, which claimed only a short punctuation list; the
structural claim takes every printable keydown, so on macOS an app that
negotiated kitty report_event_types stopped seeing releases for ordinary typing
and would treat every printable key as held down.

Suppress the release only when the press put nothing on the wire — swallowed by
the input source, or owned by a composition transaction. xterm emits nothing
from keyup unless kitty report_event_types (or win32 input mode) is on, so
letting it through is inert everywhere else.

Co-authored-by: Orca <[email protected]>
@nwparker
nwparker changed the base branch from nwparker/ime-resumed-preedit-visibility to main August 9, 2026 22:30
@nwparker
nwparker marked this pull request as ready for review August 9, 2026 22:31
@coderabbitai

coderabbitai Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The change removes macOS input-source tracking and candidate detection from terminal IME handling. Native-text forwarding now uses structural printable-key detection, event-bounded claims, committed-byte tracking, and composition transaction handling. Terminal lifecycle and preview bridge wiring no longer provide input-source features. Tests cover forwarding behavior, substitution flows, composition ordering, and Backslash bypass behavior. Reliability gates now run the substituted-text commit test.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description gives detailed design, risks, testing, and verification, but it omits the required Screenshots, AI Review Report, and Security Audit sections. Add the missing template sections, state whether there is visual change, document the AI review and cross-platform checks, and include the required security audit summary.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: structurally claiming printable keydowns so committed IME text is preserved.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
config/reliability-gates.jsonc (2)

6684-6689: 🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

Update the assertion text for the renamed file.

The file reference now points to terminal-ime-substituted-text-commit.test.ts, but the assertion still describes input-source classification. That behavior was removed in this PR, and the new test contains no such assertion. Describe what the new test proves instead.

📝 Proposed assertion text
           "file": "src/renderer/src/components/terminal-pane/terminal-ime-substituted-text-commit.test.ts",
           "assertions": [
-            "synthetic and native input-source paths are classified for covered fixtures"
+            "input-source substituted text reaches the terminal instead of the raw layout characters",
+            "shifted, backslash-position, multi-code-unit, full-width, and letter substitutions each commit once",
+            "substitutions still commit with kitty disambiguate and all-keys-as-escape-codes flags negotiated"
           ]

6684-6689: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

The rename was applied to fields that are not a file path. Replacing terminal-ime-input-source.test.ts with terminal-ime-substituted-text-commit.test.ts is correct for commands and testFiles, but two other fields describe past facts or removed behavior and must not follow the rename.

  • config/reliability-gates.jsonc#L6684-L6689: replace the input-source classification assertion text with assertions the new test actually makes; also check the gate's coverageNotes and oracle prose for the same stale claim.
  • config/reliability-gates.jsonc#L6769-L6776: restore the original 2026-07-07 command, and record the new test in a separate evidenceRuns entry for a run that executed it.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a5dea5bf-f666-477b-88a7-85aedd1972cb

📥 Commits

Reviewing files that changed from the base of the PR and between a47b9d1 and 25e68dd.

📒 Files selected for processing (13)
  • config/reliability-gates.jsonc
  • 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/terminal-ime-input-source.test.ts
  • src/renderer/src/components/terminal-pane/terminal-ime-input-source.ts
  • src/renderer/src/components/terminal-pane/terminal-ime-native-text-candidates.ts
  • src/renderer/src/components/terminal-pane/terminal-ime-native-text-forwarder.test.ts
  • src/renderer/src/components/terminal-pane/terminal-ime-native-text-forwarder.ts
  • src/renderer/src/components/terminal-pane/terminal-ime-substituted-text-commit.test.ts
  • src/renderer/src/components/terminal-pane/terminal-ime-won-composition-order.test.ts
  • src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.ts
  • src/renderer/src/components/terminal-pane/xterm-bypass-policy.test.ts
  • src/renderer/src/components/terminal-pane/xterm-bypass-policy.ts
💤 Files with no reviewable changes (4)
  • src/renderer/src/components/terminal-pane/xterm-bypass-policy.ts
  • src/renderer/src/components/terminal-pane/terminal-ime-native-text-candidates.ts
  • src/renderer/src/components/terminal-pane/terminal-ime-input-source.test.ts
  • src/renderer/src/components/terminal-pane/terminal-ime-input-source.ts

@nwparker
nwparker merged commit 01bcc8d into main Aug 9, 2026
47 of 89 checks passed
kunsanglee added a commit to kunsanglee/orca that referenced this pull request Aug 11, 2026
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.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
… text survives (stablyai#13288)

* fix(terminal): show a preedit the IME resumes without a compositionstart

Typing 2-Set Korean shows committed syllables but not the in-progress jamo, so
the user composes each syllable blind. Long-standing hole in the vendored
terminal library, not a regression: the same test fails identically against the
bundle this branch starts from.

The `.active` class that CSS keys `display: block` off is added only in
`compositionstart` and dropped in `_finalizeComposition`. Some IMEs (observed on
Windows/WSL Korean) resume a composition with a bare `compositionupdate` and no
second `compositionstart`, by which point `compositionend` has already hidden the
overlay, so the resumed preedit is written into a hidden element and never
positioned. `updateCompositionElements` also early-returned on `!_isComposing`,
so it would not lay the overlay out either.

Re-show the overlay on an update that carries data, and key the layout guard on
the shown overlay instead. `_isComposing` is deliberately left alone, so no
commit bookkeeping changes and `onData` stays byte-identical. The two guards are
equivalent on every pre-existing path: `compositionstart` sets both,
`_finalizeComposition` clears both.

The bundle hunks are the same two edits applied to the shipped minified output;
the sourcemaps are carried through unchanged.

* test(terminal): prove the resumed-preedit fix against a recorded Windows capture

The synthetic test pins the shape; this replays events a real Microsoft Korean
IME emitted on Windows/WSL. The capture holds three compositionupdates that
resume a composition with no second compositionstart — the exact ordering that
wrote the preedit into a hidden overlay.

Without the fix all three report shown:false; with it all three are visible.
Fixture derived from the sealed 11919-windows-wsl-current capture, which is
read-only and unmodified.

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

* test(terminal): stop the recorded Hangul fixture pinning a derivation artifact

The capture logs each event twice — a dispatch record and a batched next-frame
re-log. Deriving from both replayed every event twice, which made three
compositionupdates appear to land after a session had ended. Filtered to
dispatch records the capture holds zero resumes and 11 balanced sessions, so
the previous toHaveLength(3) was pinning an artifact of the derivation.

Re-scoped to what the capture does prove: the preedit stays visible across all
37 real updates. Verified by reverting the patch that this passes either way,
so it is coverage and the synthetic test remains the discriminator. Both facts
are now stated in the file.

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

* fix(terminal): restore the preedit visibility patch onto its own branch

The previous commit accidentally reverted it: checking main's patch and lockfile
into the worktree to test whether a test discriminates also stages them, so the
commit that followed swept them up.

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

* fix(terminal): claim printable keydowns structurally so committed text survives

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

* chore(reliability-gates): retarget the IME forwarding gate after the allowlist removal

The gate listed terminal-ime-input-source.test.ts, which went with the
input-source allowlist. Points at the substituted-text commit test instead,
which covers what the gate is actually protecting: text committed outside a
composition session reaching the pty exactly once.

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

* docs(terminal): record why withholding a claimed keydown needs no timer

The predicate withholds a keydown's byte until the commit arrives, so a key the
IME eats without committing would be dropped. Measured across the recorded
corpus that case does not occur, and the browser marks IME-owned presses on the
keydown itself. Both facts belong next to the predicate rather than only in a
handoff note, since the obvious fix for the imagined gap is a timer, and a timer
here once wrote a newline the user never typed.

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

* test(terminal): pin the kitty all-keys-as-escape-codes hole explicitly

Flag 8 asks for every printable key as an escape code; this path sends the
committed text raw instead. That is a deliberate trade, not an oversight, but it
was untested — the suite only covered the disambiguate flag. Pinning it makes
the choice visible and records the gate to use if it ever needs closing.

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

* fix(terminal): keep the kitty key-release report for presses that reached the pty

Claiming the keyup unconditionally suppressed xterm's release report. That was
sized for the old design, which claimed only a short punctuation list; the
structural claim takes every printable keydown, so on macOS an app that
negotiated kitty report_event_types stopped seeing releases for ordinary typing
and would treat every printable key as held down.

Suppress the release only when the press put nothing on the wire — swallowed by
the input source, or owned by a composition transaction. xterm emits nothing
from keyup unless kitty report_event_types (or win32 input mode) is on, so
letting it through is inert everywhere else.

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

---------

Co-authored-by: Orca <[email protected]>
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