Repository navigation
fix(ime): scope deferred newline to captured sessions - #11983
yeongjunyoo wants to merge 4 commits into
Conversation
Greptile SummaryThis PR scopes the deferred-newline release logic to only the composition sessions that were active at the time of the deferral. Previously, any session started after the newline was queued could hold the deferral open, reversing the intended ordering. The fix snapshots open session IDs at deferral time and uses per-session reference counts in a WeakMap so overlapping route installations on the same terminal element cannot clear each other's pending state.
Confidence Score: 5/5The change is safe to merge — it only narrows which sessions can hold a deferred newline and cannot introduce data loss or double-writes given the existing done guard. The snapshot is captured synchronously before any timers or listeners are registered, so there is no window where a session can slip in unobserved. Per-session reference counts correctly handle overlapping routes. All three decision points in the deferred-newline state machine consistently use the same captured snapshot. The sawRecentUpdate fallback for zero-snapshot is preserved. Files Needing Attention: No files require special attention.
|
| Filename | Overview |
|---|---|
| src/renderer/src/components/terminal-pane/terminal-ime-composition-route.ts | Refactors global pending count to per-session reference counts; adds snapshot capture and filtered pending check; dispose loop and session-end removal are correctly coordinated to avoid double-decrement. |
| src/renderer/src/components/terminal-pane/terminal-ime-deferred-newline.ts | Snapshot captured synchronously before any timers or listeners are registered; all three decision points correctly scope to captured sessions; sawRecentUpdate fallback preserved for zero-snapshot case. |
| src/renderer/src/components/terminal-pane/terminal-ime-composition-route.test.ts | Adds regression coverage for overlapping route ownership with correct reference-count expectations; existing suite continues to pass. |
| src/renderer/src/components/terminal-pane/terminal-ime-deferred-newline.test.ts | New test exercises the core fix — a post-defer session must not hold the newline — and verifies the newline fires exactly once after the captured session ends. |
Reviews (1): Last reviewed commit: "fix(ime): scope deferred newline to capt..." | Re-trigger Greptile
659de87 to
0ada936
Compare
…inal Two ways a committed composition was lost or corrupted. The composition route called preventDefault() before checking whether it owned the session. A route installed mid-composition never saw the matching session start, so it suppressed xterm's own insertion and then returned without delivering anything — the commit vanished. Ownership is now decided first; preventDefault stays for sessions the route does own, including the ones it deliberately drops after a transport swap, since that drop is its decision to make. The deferred-newline fallback fired `finish` directly, bypassing the pending-composition re-check that the event path uses. A composition still open at 200 ms got a newline sent into the middle of its preedit. The deadline now re-arms while a composition is pending, and its 2 s ceiling is measured from the last compositionupdate rather than from the start. A slow candidate window no longer splits the preedit, and neither does multi-segment bunsetsu conversion, which stays legitimately pending well past any fixed total-elapsed ceiling. A composition that stops progressing still cannot strand the keystroke. Co-authored-by: Orca <[email protected]> The re-arm also treats a live compositionupdate as evidence in its own right, not just a session the route recorded. A route installed while a composition was already in flight never saw that session start, so it has nothing to report as pending and the deadline would otherwise split that composition too.
9fc0803 to
2450397
Compare
|
Too many files changed for review. ( |
📝 WalkthroughWalkthroughThis change updates terminal IME composition handling. The composition route now tracks pending sessions per session ID within a per-element map, instead of a single aggregate count, and adds a snapshot API for checking pending status against a captured set of sessions. Session-end handling only prevents events for sessions owned by the route. The deferred-newline sender now captures pending sessions, listens for composition updates and later session starts, tracks idle time, and enforces a configurable maximum idle duration ( 🚥 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: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 11b43cee-5557-4627-85ef-b1b153d70ae9
📒 Files selected for processing (5)
src/renderer/src/components/terminal-pane/terminal-ime-composition-route.test.tssrc/renderer/src/components/terminal-pane/terminal-ime-composition-route.tssrc/renderer/src/components/terminal-pane/terminal-ime-deferred-newline-xterm.test.tssrc/renderer/src/components/terminal-pane/terminal-ime-deferred-newline.test.tssrc/renderer/src/components/terminal-pane/terminal-ime-deferred-newline.ts
| let idleMs = 0 | ||
| let laterSessionStarted = false | ||
| const pendingCompositionSessions = capturePendingTerminalImeCompositionSessions(terminalElement) | ||
| const hasCapturedPendingComposition = (): boolean => | ||
| hasPendingTerminalImeComposition(terminalElement, pendingCompositionSessions) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Measure idle duration from the last relevant update.
idleMs adds a full fallbackMs at each deadline, and sawRecentUpdate is cleared after one deadline. With { fallbackMs: 50, maxIdleMs: 200 }, an untracked update at 30 ms can finish at 100 ms, and a tracked update at 49 ms can finish at 200 ms after only 151 ms idle. This can send the deferred newline during an active composition. Track the last relevant update time, use actual elapsed idle time, and re-arm for the remaining window. Add a regression with an update gap between fallbackMs and maxIdleMs.
Also applies to: 68-100
|
Thanks for this, @yeongjunyoo — the captured-session IME route was the right design. This already landed on This note is from an automated scan of open PRs whose issue already shipped in a later merge. If that's wrong, please reopen and say so. |
Summary
#11896 re-arms the deferred-newline deadline while a composition is pending, but its global pending count also includes sessions that start after the newline was deferred. If a new composition overlaps the original session's end, that later session can hold the older newline and reverse the intended
syllable -> newline -> next syllableordering.This follow-up:
compositionupdatefallback for routes installed mid-composition, where no session start was capturedRelated: #11878. Stacked on #11896.
Screenshots
No visual change.
Testing
pnpm lint— full repository lint not run; both oxlint configurations passed on all four changed filespnpm typecheck— full three-project check not run;tsc --noEmit -p config/tsconfig.tc.web.jsonpassedpnpm test— full suite not run; 59 focused IME tests passed acrosskeyboard-handlers-ime,terminal-ime-composition-route, andterminal-ime-deferred-newlinepnpm build— not runAdditional gates passed:
oxfmt --check,check:max-lines-ratchet, andgit diff --check.AI Review Report
Reviewed the change against the IME transaction lifecycle, delayed completion, route replacement, and local/SSH transport paths. The first implementation stored pending IDs in a
Set; review found that two overlapping routes can own the same session ID, so disposing one route would incorrectly clear the other's pending state. The implementation now uses per-session reference counts, with a regression test for overlapping route ownership.Cross-platform review: the change is platform-neutral DOM/xterm composition bookkeeping. It does not alter shortcuts, labels, file paths, shell commands, or Electron platform branches on macOS, Linux, or Windows. Local, SSH, and relay panes continue to use the same terminal-element-scoped state and transport abstraction.
Security Audit
The change only narrows when an already-resolved terminal input write may fire. It does not add or transform input bytes, execute commands, touch paths, add IPC, change authentication, read secrets, or add dependencies. Snapshot state remains in a terminal-element-keyed
WeakMap; disposed routes release their reference counts.Notes
This PR intentionally targets the head branch of #11896 rather than
main, so it can be reviewed and folded into that existing non-duplicate IME fix.