Repository navigation
fix(mobile): hold the Japanese IME reading off the terminal until it commits - #13070
makoto-developer wants to merge 2 commits into
Conversation
|
Heads-up, and apologies for the timing — this needs a rebase and the ground moved under it. 17b3dff returned IME composition ownership to xterm and deleted the first-party composition layer. Three of the four files here went with it: Worth checking before you spend time rebasing: the behavior you are fixing may now be native. The rule you want — a reading/preedit must not reach the terminal until it commits — is what the mounted-composition path now gives for free, because we stopped mirroring composition state ourselves. I landed a test on main that pins the Korean form of exactly this ( So the useful first step is to check whether your Japanese repro still reproduces on current main. If it does, the shape that survives is a test against the current One thing we learned the hard way and that applies directly: the deferral mechanism this layer used was itself the bug. On 1.4.171 it would write a Shift+Enter payload to the PTY with no Enter pressed, 10/10, and Japanese phrase-level preedits stay open far longer than any timeout bound we picked. Timers lost to letting the IME finish. Thanks for the report and the fix attempt — the diagnosis is sound even where the code no longer applies. |
…commits Orca Mobile's direct terminal input mirrors every TextInput change to the PTY. React Native exposes no composition events, so the mirror infers preedit from the trailing code points — but it only recognised Hangul. Gboard's Japanese IME writes the reading into the field itself (pending romaji as full-width Latin, then kana), so every intermediate reading was forwarded and erased again. Captured on an Android 16 emulator with Gboard 日本語 (romaji), typing one 差: tap s -> terminal.send "s" (U+FF53, uncommitted) tap a -> terminal.send "\x7fさ" pick 差 -> terminal.send "\x7f差" Three sends and two erases for a single character, with the reading visible on the PTY the whole time. Over a relayed link the echo and the erases interleave, which is the `sあ` corruption reported in the issue. Hold the whole trailing run of Japanese reading code points instead of a single syllable, and let only a display-final Hangul syllable settle on the pause timer: a reading is discarded the moment a candidate is picked, so committing it on a pause is the leak itself. Kanji is excluded from the held run because it only appears once the user has picked a candidate. The same trace now sends "差" once, with no erases, and Enter still flushes the reading before the carriage return. Full-width punctuation is deliberately not held. Chinese IMEs compose in the candidate bar and emit it as committed text, and that path works today. The mock host answered terminal.send with `ok` rather than `accepted`, so the client read every live send as rejected and dropped the carriage return after a flushed composition. Align it with the real runtime so the harness can exercise the path at all.
9f25c50 to
7d5478c
Compare
|
Thanks — rebased onto The ground moved back.
The repro on current Byte-for-byte the same trace as before the revert. So this does not close itself. Same taps on this branch, rebased: One send of the committed text, no erases, and Enter still flushes the reading before the carriage return. On the timer point — that matches what I hit, and it is the part of this PR I would most want you to look at. My first attempt kept the existing 300 ms settle timer and it still leaked, because the timer committed the reading during a normal typing pause. Japanese phrase-level preedits are exactly the case you describe: no timeout bound is right, because the reading is discarded when a candidate is picked. So the timer is now opt-in per script — Hangul keeps it (a syllable is display-final, and its existing tests are untouched), Japanese never uses it and waits for a real boundary instead. This PR does not add a new deferral mechanism; it removes the timer from the path where the timer was the bug. Rebase was clean; the Two things I would still like your call on, both in the PR body: whether to keep the file rename (it will conflict with #12341 if that comes back), and whether you would rather close this outright once the native route relands rather than carry both. Happy either way — the traces above are the part worth keeping regardless. One unrelated thing I hit while building the harness: |
📝 WalkthroughWalkthroughThe terminal live composition mirror now supports Hangul and Japanese preedit text. It holds Japanese readings until conversion or explicit submission, while Hangul can commit after a pause. The input hooks use the new mirror module and pause-commit flag. Tests cover Japanese romaji, kana, kanji, katakana, submission, deletion, and punctuation behavior. The mock terminal stream now returns acceptance and UTF-8 byte-count fields. Mergeability Score: 🟡 Moderate · up to Whole-line Japanese kana pasted or produced by dictation may not reach the terminal until a later commit boundary, leaving input apparently stuck. This bounded correctness issue should be fixed or explicitly accepted before merge. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 3b72e8e7-45b5-4c80-8d42-a4961527f64b
📒 Files selected for processing (6)
mobile/scripts/mock-server-terminal-stream.tsmobile/src/terminal/terminal-live-composition-mirror.test.tsmobile/src/terminal/terminal-live-composition-mirror.tsmobile/src/terminal/terminal-live-hangul-mirror.tsmobile/src/terminal/use-terminal-live-input-commit.test.tsmobile/src/terminal/use-terminal-live-pending-input-flush.ts
💤 Files with no reviewable changes (1)
- mobile/src/terminal/terminal-live-hangul-mirror.ts
Classifying every trailing kana as a reading was wrong for the common case of a candidate that keeps a kana tail. たべる → 食べる sent 食 and held べる, so the PTY sat on a partial word until the next boundary, and most Japanese verbs and adjectives take okurigana. Script alone cannot separate "picked 食べる" from "typed を after 日本語" — both end in kana. The text before the trailing run settles it: a conversion rewrites that prefix, continued typing leaves it untouched. Compare the field against the one the user was last looking at (sent + held) and commit everything when the prefix moved. A whole line arriving at once, which is what paste and dictation look like, also commits rather than stranding a tail. Also stop re-holding text the PTY already echoed, so typing more kana after a committed candidate (食べる → 食べるもの) no longer erases and replays べる. Verified on the Android 16 emulator with Gboard 日本語 romaji: picking 食べる sends "食べる" once, with no erases. The mock host reported bytesWritten as UTF-16 units of `text`, which misstates every CJK send and ignores the enter and interrupt suffixes. Count UTF-8 bytes of the payload the runtime actually writes, matching buildSendPayload.
|
Both review comments were right, and the okurigana one was a real defect — thanks. Okurigana ( Most Japanese verbs and adjectives take okurigana, so this was closer to "broken" than "edge case". Script alone cannot separate picked 食べる from typed を after 日本語 — both end in kana. What separates them is the text before the trailing run: a conversion rewrites it, continued typing leaves it untouched. The step now compares the field against the one the user was last looking at (
Re-verified on the Android 16 emulator with Gboard 日本語 romaji: typing
Added regressions for the okurigana conversion, for continuing to type after a committed candidate, and for a reading typed after committed kanji (which must still be held). |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
mobile/src/terminal/terminal-live-composition-mirror.test.ts (1)
216-216: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueRemove redundant BDD phase labels.
The test names and assertions already identify these phases. Keep comments only when they add behavior rationale.
As per coding guidelines: “Comments must be concise, non-obvious, and brief—prefer one line; do not explain obvious behavior.”
Also applies to: 227-227, 297-297, 317-317, 330-330
Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 92b01ba2-c2aa-4f26-97e5-e46d348513ea
📒 Files selected for processing (4)
mobile/scripts/mock-server-terminal-stream.tsmobile/src/terminal/terminal-live-composition-mirror.test.tsmobile/src/terminal/terminal-live-composition-mirror.tsmobile/src/terminal/use-terminal-live-pending-input-flush.ts
🚧 Files skipped from review as they are similar to previous changes (2)
- mobile/scripts/mock-server-terminal-stream.ts
- mobile/src/terminal/use-terminal-live-pending-input-flush.ts
|
Closing — #7427 is fixed on main by #15007 ( Your diagnosis of the symptom was right, and the DEL-repair trace in your PR is what made the failure legible. Where this went differently: adding The fix takes the text system's marked-text/composing range instead and deletes the Hangul ranges outright, so it covers kana, kanji, pinyin and anything else without a table to extend. One thing worth flagging from reviewing yours: it asserts Thanks for the work. If Japanese still misbehaves on a current build, that's a live bug and worth reopening with a capture. |
Summary
Partial fix for #7427 — the kana/reading half, on Android. Romaji-to-kanji conversion now works end to end; the native-side gap is called out under Notes.
Orca Mobile's direct terminal input (the default for a first-seen terminal tab) mirrors every
TextInputchange to the PTY. React Native exposes no composition events, soterminal-live-hangul-mirror.tsinfers preedit from the trailing code points — but it only recognised Hangul. Gboard's Japanese IME writes the reading into the field itself, so every intermediate reading was forwarded to the PTY and erased again.Captured on an Android 16 emulator with Gboard 日本語 (romaji) against a mock host that logs the exact bytes reaching
terminal.send. Typing a single 差:s"s"— U+FF53, still uncommitteda"\x7fさ""\x7f差"Three sends and two erases for one character, with the reading sitting on the PTY the whole time. That is the
sあcorruption in the issue: over a relayed link the echo and the erases interleave, and any TUI that reacts to keystrokes sees the reading before the erase arrives.The fix. Hold the whole trailing run of Japanese reading code points rather than a single syllable, and let only a display-final Hangul syllable settle on the pause timer. A reading is discarded the moment a candidate is picked (にほんご → 日本語), so committing it on a pause is the leak — Japanese now waits for a real boundary (candidate pick, Enter, accessory key). Kanji is excluded from the held run because it only appears once the user has already picked a candidate.
Same trace after the fix, same device, same taps:
sa"差""さ", then"\r"One send of the committed text, no erases, and Enter still flushes the reading before the carriage return.
The module now covers two scripts, so it is renamed
terminal-live-hangul-mirror.ts→terminal-live-composition-mirror.tsper the naming rule in AGENTS.md. Hangul behavior is byte-identical; its existing tests are unchanged.Mock host fix.
mock-server-terminal-stream.tsansweredterminal.sendwith{ ok: true }while the client gates follow-up controls onaccepted(isTerminalSendRpcAccepted). Every live send therefore read as rejected, and the carriage return after a flushed composition was silently dropped. The native-chat scenario already returnsaccepted; this aligns the terminal scenario with it and with the real runtime. Without it the harness cannot exercise Enter at all.Screenshots
No visual change. The behavioral difference is in the bytes reaching the PTY, tabulated above.
Testing
pnpm lint(mobileoxlint, clean)pnpm typecheck(repo root, andtsc --noEmitinmobile/)pnpm test—mobile/3401 passed. One pre-existing unrelated failure,src/mock-server-key-pair.test.ts > makes concurrent creators converge on the persisted winner, which fails identically on an unmodified tree.pnpm build— not run; the change is confined tomobile/and touches no Electron main/renderer code.Tests replay the captured device traces at two levels: the mirror step (
terminal-live-composition-mirror.test.ts) and the commit hook with fake timers (use-terminal-live-input-commit.test.ts). I verified they fail against the pre-fix logic — reverting the held-run change alone fails 5 of them, including thes→a→差trace and the settle-timer case.Device verification: Android 16 (API 36, Google Play, arm64) emulator, Gboard 日本語 romaji QWERTY, dev-client build, mock host. Before/after traces above are from that rig, not from reasoning about the source.
AI Review Report
Reviewed with Claude. What it checked and what changed as a result:
heldCommitsOnPause) rather than firing for any held text.terminal.sendround trips per composed character, which helps most on a relayed or SSH-backed session.measureHeldRunwalks only the trailing run and short-circuits on the first non-reading code point; the previous code inspected one code point. Bounded by the length of the composing reading, on a path that already allocates a code-point array.Security Audit
Reviewed with Claude. This changes which locally composed characters are forwarded to an existing, already-authenticated
terminal.sendchannel, and when.mobile/scripts/), not shipped in the app.Notes
isComposing, but only inRCTTextInputComponentView.mm, so Android users get nothing from it. fix(mobile): derive terminal input from native replacement ranges #12341 is the native route (areact-native-terminal-inputmodule with an Android Kotlin side) and is the better long-term fix. This is a JS-only change that helps Android today and can be dropped wholesale once fix(mobile): derive terminal input from native replacement ranges #12341 lands — happy to close it if you would rather not carry both.terminal-live-hangul-mirror.ts→terminal-live-composition-mirror.ts. This will conflict with fix(mobile): derive terminal input from native replacement ranges #12341, which edits the same file. Say the word and I will keep the old filename to reduce the conflict surface.