Skip to content

fix(mobile): hold Japanese kana composition off the PTY until a real boundary - #11450

Closed
brennanb2025 wants to merge 10 commits into
mainfrom
brennanb2025/mobile-7427-jp-ime
Closed

brennanb2025 wants to merge 10 commits into
mainfrom
brennanb2025/mobile-7427-jp-ime

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Part of #7427 — this PR does NOT close the issue; it must stay open. It fixes only the deterministic kana half of Japanese IME input on the mobile terminal; romaji remains out of scope.

On Japanese flick keyboards, the terminal previously received a base kana before a small-kana, dakuten, or handakuten modifier finished rewriting it. The composition mirror now holds kana until a real boundary and forwards the final text exactly once. Hangul keeps its existing timer policy, while kana is never committed by a timing guess.

The review loop also hardened every asynchronous input path around that boundary:

  • Route, lifecycle, connection, producer-generation, and committed-session snapshots prevent deferred work from reaching a replaced terminal or replaying after reconnect.
  • Field and Return boundaries recover only after definite rejection, only for the exact unchanged field and bytes, and at most once; unknown delivery is never replayed.
  • Paste, image attachment and lease gating, dictation, buffered input, raw accessory input, accessory repeat, and gesture queues now distinguish definite rejection from delivery-unknown outcomes.
  • Definite rejection preserves later input where recovery is safe. Delivery-unknown fences later work, stops active repeats, drops queued gesture batches, and reports uncertainty once instead of risking duplicate terminal input.

Conflict repair

The exact pushed head is 308958eaf7cb4ab795c2e230da98244acf2f0e45; its current-main merge parent is 8fc892dd023850df379c07cc4e7a46cff9a3ea84.

  • The earlier repair against main b04c695750e9859e0d8bf79f503279bc4d656925 resolved one overlap in mobile/app/h/[hostId]/session/[worktreeId].tsx: current main's extracted live-input focus lifecycle was integrated after the PR's connection/scope gate without replacing its kana generation, ordering, or delivery-outcome protections.
  • The final merge from b04c695… to live main 8fc892dd… was conflict-free. Its only mobile delta was an unrelated active-PR polling hint in mobile/src/session/github-pr-rpc.ts.
  • Local merge-tree against exact live main is clean. Romaji behavior was not changed.

Screenshots

No visual change — this changes terminal byte flow, not layout or components. The embedded screenshots below are preserved as historical evidence from the earlier device lane; they are not current-head validation.

Testing

  • Focused changed mobile tests: 24 files, 210/210 passed.
  • Full mobile suite: 398 files, 2,991 passed / 3 skipped.
  • Mobile TypeScript, oxlint, and formatting passed.
  • Root TypeScript under Node 24 and root oxlint passed; all 53 changed tracked files pass formatting.
  • Node 24 changed-code quality: 0 code-quality, 0 type-aware, and 0 React Doctor findings across 52 changed source files.
  • Reliability manifest (61 gates), max-lines ratchet, native quality, iOS release-version (11 runs / 23 assertions), and git diff --check passed.
  • Non-vacuity: removing only the production kana boundary hold caused 12/26 composition tests to fail with the expected provisional-kana/DEL regressions; restoring exact committed production code returned 26/26 green and a clean tracked tree.
  • Hosted checks for 308958eaf7cb4ab795c2e230da98244acf2f0e45: 43 successful, including Greptile Review; only the path-gated e2e job is skipped.

OWNER-LANE VERDICT: CLEAN

Simulator validation — exact public head (PASS)

Fresh Android A/B used the exact current-main baseline 8fc892dd023850df379c07cc4e7a46cff9a3ea84 and exact public head 308958eaf7cb4ab795c2e230da98244acf2f0e45. The lane held one Android AVD (emu_qa_keystore, emulator-5560) alongside the unrelated booted iPad and never controlled the iPad. The Android app data was cleared before the baseline half, then the same AVD, prebuilt com.stably.orca.mobile dev client, native Gboard 日本語(12 キー), saved Host 1 profile, mock process, Narwhal terminal fixture, endpoint 10.0.2.2:6865, Metro port 8092, 4-second accepted-send response delay, and tap coordinates were held constant. Only the Metro-served mobile client bundle changed.

  • Baseline: native か immediately reached the mock as provisional "か"; native dakuten later produced DEL + "が"; native あ then sent "あ".
  • Exact head: native か produced no send after a 2-second pause; dakuten changed the active composition to が and still produced no send after another pause. The real native あ boundary produced exactly one send, "が", with no provisional か, no DEL repair, and no duplicate.
  • Focused exact-head tests passed: 24 files, 210/210 tests.
Baseline — が is visible in native composition, but provisional か and DEL + が have already reached the PTY Exact head — the same が remains held before a real boundary; the mock has received no bytes
Exact-baseline native kana composition Exact-head native kana composition

This exact-head acceptance run intentionally used only native Japanese flick input. Clipboard/ADB Unicode was not treated as acceptance evidence; the older paste and route-reuse evidence remains preserved below as explicitly historical evidence. Romaji was not tested and remains out of scope; #7427 stays open.

Simulator validation — historical and stale

Stale for the current head: no simulator or device was booted, attached, controlled, or killed during this repair. The Android A/B below validated 3fe69c66f9d070c0f7d87c23faa369372eb78016, not current head 308958eaf7cb4ab795c2e230da98244acf2f0e45; wholly fresh exact-parent/head device A/B remains required.

The historical lane used Android AVD emu_qa_keystore with native Gboard 日本語(12 キー). Parent was the then-true merge-base 4d044c47dccb58642cba6df6fe56e42b7b87dc6d; head was 3fe69c66f9d070c0f7d87c23faa369372eb78016. Both halves used the same AVD/app data, IME, dev client, delayed-acceptance mock, endpoint, terminal, and clipboard marker; only the Metro-served client bundle varied.

  • Native か → dakuten → あ: parent sent provisional か, then DEL+が, then あ. The historical head sent nothing for the base/modifier edits and sent exactly one が only when あ created the real boundary; the later Enter flush sent あ, then CR.
  • Paste boundary: parent sent provisional か, DEL+が, then the clipboard text. The historical head sent final が first and CAQA12PASTE second, exactly once each after accepted responses.
  • Route reuse during the mock's 4-second terminal.send response delay: parent let the queued paste reach Manta after leaving Narwhal. The historical head sent only the held Narwhal か, dropped the stale queued paste on route replacement, then a fresh Manta Paste sent exactly once.
Parent — active kana modified to が after provisional bytes had already leaked Historical head — が remains held before a real boundary
Parent native kana composition Historical-head native kana composition
Parent — stale queued paste reached the Manta route Historical head — Manta target after stale paste was fenced
Parent route reuse target Historical-head route reuse target

Romaji was not tested and remains explicitly out of scope. Issue #7427 remains open.

Same-model review loop

The earlier review-only lanes returned literal CLEAN on old head 3fe69c66f9d070c0f7d87c23faa369372eb78016; those verdicts are historical and stale for the newly pushed head.

  • A wholly fresh independent gpt-5.6-sol xhigh read-only review returned literal CLEAN on exact head 308958eaf7cb4ab795c2e230da98244acf2f0e45 versus exact main parent 8fc892dd023850df379c07cc4e7a46cff9a3ea84.
  • After that immutable-head review, a wholly fresh exact-parent/head native Gboard device A/B produced the current evidence above without promoting the stale evidence below.

AI Review Report

The owner lane re-audited kana range and boundary semantics, exact-byte recovery, committed route ownership, disconnect/reconnect invalidation, producer-generation fences, direct and mirrored sends, pending flushes, paste, image attachments, lease gating, dictation, buffered sends, gestures, accessory repeat, and the current-main focus-lifecycle extraction. Definite rejection and delivery-unknown behavior were checked separately so recovery cannot duplicate bytes whose delivery is uncertain.

Cross-platform and remote behavior remain within the shared mobile terminal-send flow. No desktop shortcut, path, provider, or Git behavior changes, and SSH/folder workspaces receive the same ordered terminal bytes.

Security Audit

The change only controls when user-authored terminal input is forwarded and whether uncertain sends may be retried. It adds no command execution, path handling, authentication, secret, dependency, or IPC surface. Treating delivery-unknown outcomes as a fence reduces the risk of replaying input into an interactive shell or TUI.

Notes

  • [Bug]: Orca Mobile terminal cannot enter Japanese via flick or romaji IME #7427 stays open. Romaji composition still leaks intermediate ASCII because React Native does not expose a deterministic composition lifecycle; fixing it requires a native IME-aware input view and is outside this PR.
  • The earlier physical Gboard A/B at 8ae5c6d95d and Android A/B at 3fe69c66f9d remain useful historical evidence only and are stale for current head 308958eaf7cb4ab795c2e230da98244acf2f0e45.
  • The fresh immutable-head review, hosted checks, and native device A/B are complete; this QA lane did not merge or approve.

What the user sees before and after

Before: With a Japanese IME, intermediate kana can leak into the live terminal while composition is still changing, so users can see duplicated or corrupted characters.

After: Kana stays buffered until a real composition boundary, then the final text reaches the terminal exactly once. Romaji composition is unchanged, so #7427 remains open.

@coderabbitai

coderabbitai Bot commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The terminal composition mirror now classifies Hangul and Kana trailing code points with distinct held commit policies. Mirror steps expose those policies and preserve Kana modifier pairs. Pending-input handling queues boundary sends, reconciles disconnects, and starts timers only for timer-based holds. External terminal input, paste, dictation, accessories, and image attachments now use boundary callbacks. Tests cover ordering, failure handling, Kana composition, normalization, and updated integrations.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 23.08% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly identifies the main change: buffering Japanese kana composition until a real terminal input boundary.
Description check ✅ Passed The description covers the required sections, user-visible behavior, testing, review, security, platform impact, and known scope limitations.
✨ Finishing Touches 💡 1
📝 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.

@greptile-apps

greptile-apps Bot commented Jul 30, 2026 •

Copy link
Copy Markdown

Greptile Summary

This PR fixes Japanese kana composition leaking provisional bytes to the PTY on flick keyboards by introducing a 'boundary' hold policy (vs. Hangul's 'timer' policy) in terminal-live-composition-mirror.ts. It also hardens all async input paths — paste, image attachment, dictation, buffered input, accessory repeat, and gesture queues — against stale route, lifecycle, and connection state, by threading liveInputProducerGeneration, inputScope, and isBoundaryCurrent guards through each send path.

  • Kana hold: getTerminalLiveHeldCommitPolicy returns 'boundary' for kana (U+3041–U+30FF / half-width), so the held code point (and any preceding non-modifier kana when a combining mark follows) is only flushed on an explicit boundary (next keystroke, paste, Return), never on a settle timer.
  • Boundary field recovery: terminal-live-boundary-field-recovery.ts tracks per-boundary snapshots so a rejected mirror or boundary send can reconstruct the field text and live-input capture state, with at most one retry for Return/key boundaries.
  • Input path hardening: every send path (paste, gesture queue, accessory repeat, buffered command, dictation, image attachment) now passes isBoundaryCurrent through the send callback and distinguishes 'rejected' (safe to recover) from 'unknown' (fence later work, stop active repeats, report once).

Confidence Score: 5/5

Safe to merge. All changed paths target mobile terminal byte delivery only, with no shared server or desktop logic touched. The kana hold logic is deterministic and validated by AVD simulation. Recovery paths are self-correcting even in edge cases.

The core kana boundary hold and all async guard paths are clearly reasoned, well-tested (391 files, 2,932 passed), and validated on real hardware. The two findings are both narrow edge cases (Return rejection on an empty field; callback-recreation frequency) that self-correct and carry no data-loss or PTY-corruption risk. No correctness, security, or ordering issues were found on any of the main code paths.

Files Needing Attention: terminal-live-boundary-field-recovery.ts and use-terminal-live-input-boundary.ts — the null-recoveryToken recovery path and the snapshot-ordering logic are the most intricate parts of the new code and merit the closest future read.

Important Files Changed

Filename Overview
mobile/src/terminal/terminal-live-composition-mirror.ts New file: adds kana code-point ranges and 'boundary' hold policy; getTerminalLiveHeldSuffixLength correctly holds 2 code points when a combining mark follows a non-modifier kana base. Clean.
mobile/src/terminal/terminal-live-boundary-field-recovery.ts New file: snapshot-based field recovery for rejected/unknown boundary sends. recoverTerminalLiveRejectedBoundary with a null token treats all snapshots as dependent and prepends recoveryBytes to state.currentCaptureText — can transiently set live input to boundary bytes (e.g. '\r') when called on an empty-field rejection.
mobile/src/terminal/use-terminal-live-input-boundary.ts New file: orchestrates flush-then-send ordering, boundary field reservation/release, and one-shot retry for rejected Return. The null-recoveryToken path when no pending mirror state exists has a minor state-corruption edge case on rejection with non-empty recoveryBytes.
mobile/src/terminal/use-terminal-live-pending-input-flush.ts Refactored: switched from useEffect to useLayoutEffect for runMirrorStepRef/dispose teardown; added liveInputGeneration/lifecycleEpoch guards. isLiveInputProducerCurrent is returned as a plain inline arrow (not useCallback), causing dependent useCallback hooks to re-create every render.
mobile/src/terminal/terminal-live-pending-flush-state.ts Added module-level terminalLiveHandleSendTails for per-handle send serialization and queueTerminalLiveBoundarySend. Cleanup logic correctly removes entries when sends settle. Clean.
mobile/src/terminal/terminal-live-mirror-payload-send.ts New file: handles mirror payload send, rejection recovery (recoverTerminalLiveBoundaryFields), and unknown-delivery path (clears state, calls onDeliveryUnknown). Generation/epoch guards prevent stale callbacks from triggering recovery.
mobile/src/terminal/use-terminal-live-input-commit.ts Refactored: replaces flushPendingLiveInputBeforeExternalSend with sendLiveInputExternalBoundary and liveInputProducerGeneration; adds isLiveInputProducerCurrent guard to all handlers. Clean.
mobile/app/h/[hostId]/session/[worktreeId].tsx Wires terminalInputScope/terminalInputStateReady, useTerminalInputCommittedSnapshot, useTerminalAccessoryRepeat, useTerminalGestureInputQueue, and liveInputProducerGeneration through the session screen; removes direct clientRef/connStateRef mutations in favour of committed snapshot hook. Clean.

Sequence Diagram

sequenceDiagram
    participant User as User (flick keyboard)
    participant Commit as useTerminalLiveInputCommit
    participant Flush as useTerminalLivePendingInputFlush
    participant Mirror as computeTerminalLiveMirrorStep
    participant Boundary as useTerminalLiveInputBoundary
    participant PTY as PTY (terminal.send RPC)

    User->>Commit: onChangeText("ka")
    Commit->>Flush: applyLiveInputMirror(handle, "ka")
    Flush->>Mirror: "sentText="", fieldText="ka", commitHeld=false"
    Mirror-->>Flush: "policy='boundary', heldText="ka", payload="""
    Note over Flush: Empty payload - no RPC, kana stays held

    User->>Commit: onChangeText("ka+modifier")
    Flush->>Mirror: "sentText="", fieldText="ka+modifier", commitHeld=false"
    Mirror-->>Flush: "policy='boundary', heldSuffixLen=2, payload="""
    Note over Flush: Modifier + base held together, still no RPC

    User->>Commit: onKeyPress(Enter)
    Commit->>Boundary: runLiveInputBoundary(handle, sendBoundaryBytes, recoveryBytes)
    Boundary->>Flush: "runMirrorStep(handle, fieldText, commitHeld=true)"
    Flush->>PTY: queueTerminalLiveHandleSend - terminal.send(finalKana)
    PTY-->>Flush: accepted
    Boundary->>PTY: queueTerminalLiveBoundarySend - terminal.send(CR)
    PTY-->>Boundary: accepted

    Note over Boundary: On rejected: recoverTerminalLiveRejectedBoundary restores field
    Note over Boundary: On unknown: onDeliveryUnknown - stop repeat, show toast
Loading

Reviews (22): Last reviewed commit: "Merge origin/main into brennanb2025/mobi..." | Re-trigger Greptile

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Re: Greptile's P2 ("Boundary-held kana silently discarded on tab change — wider window than Hangul"): confirmed, and the PR description's Notes section has been updated to state it precisely. The discard mechanism in clearPendingLiveInputCommit predates this PR, but the boundary policy does widen the exposure from Hangul's ~300ms settle window to an indefinite one for held kana. It is deliberately left out of this PR to keep the change scoped to the deterministic kana-modifier fix; the follow-up (flush instead of discard on tab change) is called out in the Notes section.

@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: 4

🧹 Nitpick comments (1)
mobile/src/terminal/use-terminal-live-pending-input-flush.ts (1)

140-176: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Extract the duplicated handle-validity check.

The three-condition check at Line 150-155 (handle !== activeHandleRef.current || (activeSessionTabTypeRef.current != null && activeSessionTabTypeRef.current !== 'terminal') || !liveInputTerminalHandlesRef.current.has(handle)) repeats the identical check in runMirrorStep at Line 80-85. Extract a single predicate function and call it from both places. This prevents the two paths from silently diverging if the validity rule changes later.

♻️ Proposed refactor
+  const isTerminalLiveHandleActive = useCallback(
+    (handle: string): boolean =>
+      handle === activeHandleRef.current &&
+      (activeSessionTabTypeRef.current == null ||
+        activeSessionTabTypeRef.current === 'terminal') &&
+      liveInputTerminalHandlesRef.current.has(handle),
+    [activeHandleRef, activeSessionTabTypeRef, liveInputTerminalHandlesRef]
+  )
+
   const runMirrorStep = useCallback(
     async (handle: string, fieldText: string, commitHeld: boolean): Promise<boolean> => {
-      if (
-        handle !== activeHandleRef.current ||
-        (activeSessionTabTypeRef.current != null &&
-          activeSessionTabTypeRef.current !== 'terminal') ||
-        !liveInputTerminalHandlesRef.current.has(handle)
-      ) {
+      if (!isTerminalLiveHandleActive(handle)) {
         resetMirrorState()
         return false
       }
       ...
     },
-    [
-      activeHandleRef,
-      activeSessionTabTypeRef,
-      clearHeldCommitTimer,
-      liveInputTerminalHandlesRef,
-      resetMirrorState,
-      sendLiveTerminalInputRef,
-      waitForPendingLiveInputFlush
-    ]
+    [
+      clearHeldCommitTimer,
+      isTerminalLiveHandleActive,
+      resetMirrorState,
+      sendLiveTerminalInputRef,
+      waitForPendingLiveInputFlush
+    ]
   )
   ...
   const runLiveInputBoundary = useCallback(
     (expectedHandle: string | null, sendBoundary: () => Promise<boolean>): Promise<boolean> => {
       ...
-      if (
-        handle !== activeHandleRef.current ||
-        (activeSessionTabTypeRef.current != null &&
-          activeSessionTabTypeRef.current !== 'terminal') ||
-        !liveInputTerminalHandlesRef.current.has(handle)
-      ) {
+      if (!isTerminalLiveHandleActive(handle)) {
         clearPendingLiveInputCommit()
         return queueTerminalLiveBoundarySend(pendingLiveInputFlushRef, async () => false)
       }
       ...
     },
-    [
-      activeHandleRef,
-      activeSessionTabTypeRef,
-      clearPendingLiveInputCommit,
-      liveInputTerminalHandlesRef,
-      runMirrorStep
-    ]
+    [clearPendingLiveInputCommit, isTerminalLiveHandleActive, runMirrorStep]
   )

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 6291427c-be32-4f06-99c9-54128dfa30bb

📥 Commits

Reviewing files that changed from the base of the PR and between 8ae5c6d and 4baeafc.

📒 Files selected for processing (19)
  • mobile/app/h/[hostId]/session/[worktreeId].tsx
  • mobile/src/session/mobile-image-attachment.test.ts
  • mobile/src/session/mobile-image-attachment.ts
  • mobile/src/session/use-mobile-attachment-input-lease-gate.test.ts
  • mobile/src/session/use-mobile-attachment-input-lease-gate.ts
  • mobile/src/session/use-mobile-image-attachment.ts
  • mobile/src/session/use-mobile-session-image-attachments.ts
  • mobile/src/session/use-mobile-terminal-paste.ts
  • mobile/src/terminal/terminal-live-composition-mirror.test.ts
  • mobile/src/terminal/terminal-live-composition-mirror.ts
  • mobile/src/terminal/terminal-live-input-sender.ts
  • mobile/src/terminal/terminal-live-pending-flush-state.test.ts
  • mobile/src/terminal/terminal-live-pending-flush-state.ts
  • mobile/src/terminal/use-terminal-live-accessory-input-commit.test.ts
  • mobile/src/terminal/use-terminal-live-accessory-input-commit.ts
  • mobile/src/terminal/use-terminal-live-input-commit.test.ts
  • mobile/src/terminal/use-terminal-live-input-commit.ts
  • mobile/src/terminal/use-terminal-live-pending-input-flush.test.ts
  • mobile/src/terminal/use-terminal-live-pending-input-flush.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • mobile/src/terminal/use-terminal-live-input-commit.test.ts
  • mobile/src/terminal/terminal-live-composition-mirror.test.ts

@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: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: e471e353-32fc-4c7d-9817-6728efc6c9cf

📥 Commits

Reviewing files that changed from the base of the PR and between 4baeafc and abf929c.

📒 Files selected for processing (4)
  • mobile/src/session/use-mobile-attachment-input-lease-gate.test.ts
  • mobile/src/session/use-mobile-attachment-input-lease-gate.ts
  • mobile/src/terminal/use-terminal-live-pending-input-flush.test.ts
  • mobile/src/terminal/use-terminal-live-pending-input-flush.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • mobile/src/session/use-mobile-attachment-input-lease-gate.ts
  • mobile/src/terminal/use-terminal-live-pending-input-flush.ts

@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.

🧹 Nitpick comments (1)
mobile/src/terminal/use-terminal-live-input-disconnect.test.ts (1)

1-58: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Reuse the existing test harness instead of duplicating it.

This file reimplements the Harness component and the react-test-renderer is deprecated console suppression already built for use-terminal-live-input-commit.test.ts (createTerminalLiveInputCommitHarness, suppressReactTestRendererDeprecationWarning). That harness already exposes setConnected, which is exactly what this test needs at Line 64-67.

Export the existing harness factory and suppression helper from a concretely named module (for example terminal-live-input-commit-test-harness.ts, not a generic test-utils.ts) and reuse them here. This keeps warning-suppression and harness behavior consistent across the terminal live-input test suite.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: df5ea2c6-c26b-489b-8ae0-6def6f79a4f0

📥 Commits

Reviewing files that changed from the base of the PR and between abf929c and 76fffda.

📒 Files selected for processing (7)
  • mobile/app/h/[hostId]/session/[worktreeId].tsx
  • mobile/src/session/use-mobile-session-image-attachments.ts
  • mobile/src/terminal/use-terminal-live-input-commit.test.ts
  • mobile/src/terminal/use-terminal-live-input-commit.ts
  • mobile/src/terminal/use-terminal-live-input-disconnect.test.ts
  • mobile/src/terminal/use-terminal-live-pending-input-flush.test.ts
  • mobile/src/terminal/use-terminal-live-pending-input-flush.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • mobile/src/terminal/use-terminal-live-input-commit.test.ts
  • mobile/src/session/use-mobile-session-image-attachments.ts
  • mobile/app/h/[hostId]/session/[worktreeId].tsx

@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: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f0c09700-1186-4324-b6c8-7d657a775ddd

📥 Commits

Reviewing files that changed from the base of the PR and between 76fffda and bf9769f.

📒 Files selected for processing (6)
  • mobile/src/session/mobile-image-attachment.test.ts
  • mobile/src/session/mobile-image-attachment.ts
  • mobile/src/session/use-mobile-terminal-paste.ts
  • mobile/src/terminal/terminal-input-connection-gate.test.ts
  • mobile/src/terminal/use-terminal-live-pending-input-flush.test.ts
  • mobile/src/terminal/use-terminal-live-pending-input-flush.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • mobile/src/session/use-mobile-terminal-paste.ts
  • mobile/src/session/mobile-image-attachment.ts
  • mobile/src/terminal/use-terminal-live-pending-input-flush.ts

@brennanb2025
brennanb2025 force-pushed the brennanb2025/mobile-7427-jp-ime branch from 308958e to db2fd20 Compare August 3, 2026 07:42
nwparker added a commit that referenced this pull request Aug 17, 2026
…a script table (#15007)

* fix(mobile): decide terminal preedit from the marked-text range, not a script table

The live terminal capture field decided what to withhold from the PTY with a
Unicode-block allowlist (Hangul jamo and syllables) and held exactly one trailing
code point. Kana and kanji are not in the table, so a Japanese reading streamed to
the PTY one fragment at a time and was repaired afterwards with DEL bytes (#7427).

A code-point table cannot work, and the counterexample is not exotic: Chinese
pinyin preedit is plain ASCII, and a Japanese romaji reading is one code point on
the first keystroke and three on the fourth. Preedit is a property of the FIELD,
not of the characters in it, so the only signal that identifies it is the text
system's marked-text range. That is what a reference terminal implementation uses
on every platform it supports - `hasMarkedText` there, the input-method context's
composing state elsewhere - and neither one classifies code points anywhere in the
input path.

So the mirror now takes the marked-text report per change and holds the whole
preedit region, whatever its length or script:
- Subscribe the capture field to `onChange`, not `onChangeText`; only the raw
  native event carries the report at all.
- A reported preedit is held entire and is never committed by the settle timer,
  because preedit is not text yet. Explicit boundaries still flush it.
- `isTerminalLiveHangulCodePoint` and its four ranges are deleted.

iOS reports the range but React Native drops it before JS, so the pinned patch
forwards `markedTextRange` into the change payload. It is three hunks and it
compiles because the app already sets `buildReactNativeFromSource` for iOS. The
same idea was proposed in #11450, which is where the patch comes from.

Android has no marked-text report in React Native at all, and a Kotlin patch would
not help: Android consumes the prebuilt react-android artifact, so node_modules
sources are never compiled. Until the report exists there, the fallback holds the
trailing non-ASCII run. It enumerates nothing, it covers kana, kanji and Hangul,
and ASCII keeps its zero-latency echo - but it cannot see an ASCII preedit, so
Chinese pinyin on Android still leaks its reading. Only a report fixes that.

Not-tested: no physical device or emulator was available, so no real IME drove
this path. Japanese, Chinese and Korean composition are covered at the model and
hook level only, and the iOS patch has not been compiled.

Co-authored-by: Brennan Benson <[email protected]>

* fix(mobile): bound the fallback hold to text the pty has not received

The no-report branch walked the trailing non-ASCII run over the whole field and
ignored stableLength, unlike the reported branch directly above it. So after a
settle-timer commit the next keystroke re-held everything already delivered and
the caller erased it with DEL and retyped it — a nine-character Cyrillic word
cost a DEL per already-sent character, and for the 300ms before the re-send the
held text was the only copy, so a blur or reconnect destroyed characters the pty
already had.

Bound it the way the reported branch is bounded. Pinned by a test that drives a
settle commit between every keystroke and asserts no DEL reaches the wire.

---------

Co-authored-by: Brennan Benson <[email protected]>
@nwparker

Copy link
Copy Markdown
Contributor

Closing — but your patch is the part that shipped, and you're credited as co-author on #15007 (66b5993).

Your premise was the load-bearing finding: React Native 0.83.9 genuinely does not expose composition state, so no amount of JS gets at it. I checked this the hard way — an earlier pass concluded RN already shipped isComposing, from reading a workspace whose RN copy had been hand-patched. A pristine install proved you right.

mobile/patches/[email protected] is regenerated cleanly against pristine 0.83.9 and carries your authorship. A readiness review verified it cryptographically: pre-image blob hashes match the npm tarball, post-image match the install, and a full recursive diff shows exactly the three files it names and nothing else.

What changed on the JS side: your if (isComposing === true) return left the Hangul allowlist and the DEL-repair path in place for everything else, so Android — which can't compile the patch, since it links a prebuilt AAR — kept the original bug. #15007 replaces the allowlist entirely and adds a non-ASCII-run fallback for that case.

Closing the branch, not the contribution. Thanks — the patch was the hard part.

@nwparker nwparker closed this Aug 17, 2026
paidaxingyo666 pushed a commit to paidaxingyo666/Manta that referenced this pull request Aug 21, 2026
…a script table (stablyai#15007)

* fix(mobile): decide terminal preedit from the marked-text range, not a script table

The live terminal capture field decided what to withhold from the PTY with a
Unicode-block allowlist (Hangul jamo and syllables) and held exactly one trailing
code point. Kana and kanji are not in the table, so a Japanese reading streamed to
the PTY one fragment at a time and was repaired afterwards with DEL bytes (stablyai#7427).

A code-point table cannot work, and the counterexample is not exotic: Chinese
pinyin preedit is plain ASCII, and a Japanese romaji reading is one code point on
the first keystroke and three on the fourth. Preedit is a property of the FIELD,
not of the characters in it, so the only signal that identifies it is the text
system's marked-text range. That is what a reference terminal implementation uses
on every platform it supports - `hasMarkedText` there, the input-method context's
composing state elsewhere - and neither one classifies code points anywhere in the
input path.

So the mirror now takes the marked-text report per change and holds the whole
preedit region, whatever its length or script:
- Subscribe the capture field to `onChange`, not `onChangeText`; only the raw
  native event carries the report at all.
- A reported preedit is held entire and is never committed by the settle timer,
  because preedit is not text yet. Explicit boundaries still flush it.
- `isTerminalLiveHangulCodePoint` and its four ranges are deleted.

iOS reports the range but React Native drops it before JS, so the pinned patch
forwards `markedTextRange` into the change payload. It is three hunks and it
compiles because the app already sets `buildReactNativeFromSource` for iOS. The
same idea was proposed in stablyai#11450, which is where the patch comes from.

Android has no marked-text report in React Native at all, and a Kotlin patch would
not help: Android consumes the prebuilt react-android artifact, so node_modules
sources are never compiled. Until the report exists there, the fallback holds the
trailing non-ASCII run. It enumerates nothing, it covers kana, kanji and Hangul,
and ASCII keeps its zero-latency echo - but it cannot see an ASCII preedit, so
Chinese pinyin on Android still leaks its reading. Only a report fixes that.

Not-tested: no physical device or emulator was available, so no real IME drove
this path. Japanese, Chinese and Korean composition are covered at the model and
hook level only, and the iOS patch has not been compiled.

Co-authored-by: Brennan Benson <[email protected]>

* fix(mobile): bound the fallback hold to text the pty has not received

The no-report branch walked the trailing non-ASCII run over the whole field and
ignored stableLength, unlike the reported branch directly above it. So after a
settle-timer commit the next keystroke re-held everything already delivered and
the caller erased it with DEL and retyped it — a nine-character Cyrillic word
cost a DEL per already-sent character, and for the 300ms before the re-send the
held text was the only copy, so a blur or reconnect destroyed characters the pty
already had.

Bound it the way the reported branch is bounded. Pinned by a test that drives a
settle commit between every keystroke and asserts no DEL reaches the wire.

---------

Co-authored-by: Brennan Benson <[email protected]>
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…a script table (stablyai#15007)

* fix(mobile): decide terminal preedit from the marked-text range, not a script table

The live terminal capture field decided what to withhold from the PTY with a
Unicode-block allowlist (Hangul jamo and syllables) and held exactly one trailing
code point. Kana and kanji are not in the table, so a Japanese reading streamed to
the PTY one fragment at a time and was repaired afterwards with DEL bytes (stablyai#7427).

A code-point table cannot work, and the counterexample is not exotic: Chinese
pinyin preedit is plain ASCII, and a Japanese romaji reading is one code point on
the first keystroke and three on the fourth. Preedit is a property of the FIELD,
not of the characters in it, so the only signal that identifies it is the text
system's marked-text range. That is what a reference terminal implementation uses
on every platform it supports - `hasMarkedText` there, the input-method context's
composing state elsewhere - and neither one classifies code points anywhere in the
input path.

So the mirror now takes the marked-text report per change and holds the whole
preedit region, whatever its length or script:
- Subscribe the capture field to `onChange`, not `onChangeText`; only the raw
  native event carries the report at all.
- A reported preedit is held entire and is never committed by the settle timer,
  because preedit is not text yet. Explicit boundaries still flush it.
- `isTerminalLiveHangulCodePoint` and its four ranges are deleted.

iOS reports the range but React Native drops it before JS, so the pinned patch
forwards `markedTextRange` into the change payload. It is three hunks and it
compiles because the app already sets `buildReactNativeFromSource` for iOS. The
same idea was proposed in stablyai#11450, which is where the patch comes from.

Android has no marked-text report in React Native at all, and a Kotlin patch would
not help: Android consumes the prebuilt react-android artifact, so node_modules
sources are never compiled. Until the report exists there, the fallback holds the
trailing non-ASCII run. It enumerates nothing, it covers kana, kanji and Hangul,
and ASCII keeps its zero-latency echo - but it cannot see an ASCII preedit, so
Chinese pinyin on Android still leaks its reading. Only a report fixes that.

Not-tested: no physical device or emulator was available, so no real IME drove
this path. Japanese, Chinese and Korean composition are covered at the model and
hook level only, and the iOS patch has not been compiled.

Co-authored-by: Brennan Benson <[email protected]>

* fix(mobile): bound the fallback hold to text the pty has not received

The no-report branch walked the trailing non-ASCII run over the whole field and
ignored stableLength, unlike the reported branch directly above it. So after a
settle-timer commit the next keystroke re-held everything already delivered and
the caller erased it with DEL and retyped it — a nine-character Cyrillic word
cost a DEL per already-sent character, and for the 300ms before the re-send the
held text was the only copy, so a blur or reconnect destroyed characters the pty
already had.

Bound it the way the reported branch is bounded. Pinned by a test that drives a
settle commit between every keystroke and asserts no DEL reaches the wire.

---------

Co-authored-by: Brennan Benson <[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.

2 participants