Repository navigation
Conversation
Typing a Korean word into a terminal showed the previous syllable being overwritten by the one being composed: "한글" rendered "한", then "그" on top of it, and only settled once "글" committed. stablyai#11293 made compositionstart cancel the pending finalizer and route the just-committed syllable through _endPendingCompositionSession, which announces the commit with dataPendingReconciliation but never sends the bytes; terminal-ime-composition-route.ts drops exactly that event. macOS Hangul commits syllable N at syllable N+1's compositionstart and emits no intervening insertText, so syllable N stayed stranded until the next compositionend. The buffer cursor never advanced, so xterm drew the next composition's opaque overlay on the previous syllable's cell. Drop that block so the already-armed finalizer survives. It fires on the next task, which is after IBus rewrites the textarea (preserving the final-consonant transfer "아아", not "앙아") and still long before the next compositionend, so macOS flushes immediately. One mechanism covers both platforms, and the transaction bookkeeping stablyai#11293 added is untouched. Adds terminal-ime-hangul-syllable-flush.test.ts, which asserts the intermediate state the existing suites miss: they only compare the final joined string, so a withheld-then-late-flushed syllable passed. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdded a happy-dom Vitest suite for Hangul IME behavior in ESM and CJS xterm builds. The suite simulates composition, input, and keyboard events. It verifies syllable-boundary flushing, Korean final-consonant transfer, exact-once emission for 🚥 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
🧹 Nitpick comments (1)
src/renderer/src/components/terminal-pane/terminal-ime-hangul-syllable-flush.test.ts (1)
15-30: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDispose the terminal unconditionally, not only on the success path.
Each test calls
terminal.dispose()itself at the end (Line 96, 120, 133, 162). If anexpectassertion throws earlier in the test body,dispose()is skipped.afterEach(Lines 78-82) clears mocks, real timers, and DOM children, but never callsdispose()on the terminal created inopenTerminal. A failed assertion can leave an xterm instance with active timers/RAF loops running into later tests in the same file, risking cross-test pollution or flakiness.Track the current terminal and dispose it unconditionally in
afterEach.♻️ Proposed fix for guaranteed terminal disposal
+let currentTerminal: EsmTerminal | null = null + function openTerminal(TerminalType: typeof EsmTerminal): { emitted: string[] terminal: EsmTerminal textarea: HTMLTextAreaElement } { const container = document.createElement('div') document.body.appendChild(container) const terminal = new TerminalType() terminal.open(container) if (!terminal.textarea) { throw new Error('xterm textarea was not created') } const emitted: string[] = [] terminal.onData((data) => emitted.push(data)) + currentTerminal = terminal return { emitted, terminal, textarea: terminal.textarea } }afterEach(() => { + currentTerminal?.dispose() + currentTerminal = null vi.useRealTimers() vi.restoreAllMocks() document.body.replaceChildren() })Also applies to: 78-82
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 842b6e63-28e6-4fc9-9f64-0de9b5a1b7a8
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (2)
config/patches/@[email protected]src/renderer/src/components/terminal-pane/terminal-ime-hangul-syllable-flush.test.ts
| textarea.setSelectionRange(0, 0) | ||
| composition(textarea, 'compositionstart') | ||
| keydown(textarea, 'Process', 'KeyG', 229) | ||
| composition(textarea, 'compositionupdate', '한') |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🌐 Web query:
Chromium keydown compositionstart event order for first IME character IBus Linux
💡 Result:
In Chromium on Linux, when using an IBus-based IME, the keydown event precedes the compositionstart event [1][2]. The standard event sequence for the initiation of an IME composition in Chromium is keydown followed by compositionstart [1][3]. This order is consistent with the UI Events specification, which lists keydown as the event that triggers the composition system [1][4]. When a user types a character that initiates an IME session, the browser first dispatches the keydown event for that keystroke before the compositionstart event fires to indicate the beginning of the composition process [1][2]. It is important to note that developers should rely on composition-specific events (such as compositionupdate, beforeinput, and input) for handling text changes, rather than keydown, due to variations in how IMEs and different operating systems handle key events during composition [5][6]. For example, even when a key event is part of a composition, the keydown event is still dispatched, often with a keyCode of 229 (the "IME processed" code) [5]. While Chromium aims for consistency, historically there have been noted complexities regarding Linux IBus behavior, where key events may sometimes contain character values that differ from other platforms [7][6].
Citations:
- 1: Order of keydown relative to compositionstart w3c/uievents#360
- 2: https://chromium.googlesource.com/external/w3c/web-platform-tests/+/merge_pr_6797/uievents/legacy-domevents-tests/submissions/Microsoft/compositionstart.keydown.html
- 3:
beforeinputandcompositionupdateevent order w3c/uievents#354 - 4: preventDefault() of keydown event should not kill composition start caused by the keydown w3c/uievents#180
- 5: https://developer.mozilla.org/en-US/docs/Web/API/Element/keydown_event
- 6: Fire keydown/keyup during composition w3c/uievents#75
- 7: https://codereview.chromium.org/1998783002
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Locate and inspect the relevant test and nearby composition helper behavior.
if [ -f "src/renderer/src/components/terminal-pane/terminal-ime-hangul-syllable-flush.test.ts" ]; then
echo "== file lines =="
nl -ba src/renderer/src/components/terminal-pane/terminal-ime-hangul-syllable-flush.test.ts | sed -n '1,180p'
else
echo "Target file not found"
fd -a terminal-ime-hangul-syllable-flush.test.ts .
fi
echo "== references to compositionstart/keydown handling =="
rg -n "compositionstart|keydown|keyCode === 229|isComposing|keyCode" src/renderer src -g '*.{ts,tsx,js,jsx}' | sed -n '1,220p'Repository: stablyai/orca
Length of output: 208
🏁 Script executed:
#!/bin/bash
set -euo pipefail
TARGET="src/renderer/src/components/terminal-pane/terminal-ime-hangul-syllable-flush.test.ts"
echo "== target file excerpt =="
if [ -f "$TARGET" ]; then
wc -l "$TARGET"
cat -n "$TARGET" | sed -n '1,180p'
else
echo "Target file not found"
fd -a terminal-ime-hangul-syllable-flush.test.ts . || true
fi
echo "== references to compositionstart/keydown handling =="
rg -n "compositionstart|compositionupdate|keydown|keyCode === 229|isComposing|keyCode" src/renderer src -g '*.{ts,tsx,js,jsx}' 2>/dev/null | sed -n '1,240p' || trueRepository: stablyai/orca
Length of output: 42105
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== locate xterm source or references =="
git ls-files | rg '(`@xterm/xterm`|node_modules/@xterm/xterm|terminal.*\.ts|compositionstart|textarea)' | sed -n '1,120p'
echo "== package manifests mentioning `@xterm/xterm` =="
fd -a 'package.json' . -d 4 | while read -r f; do
if rg -q '"`@xterm/xterm`"' "$f" 2>/dev/null; then
echo "--- $f"
rg '"`@xterm/xterm`"' "$f"
fi
done
echo "== read-only probe: current test event sequence effects vs Chromium-compliant sequence =="
python3 - <<'PY'
from pathlib import Path
p = Path('src/renderer/src/components/terminal-pane/terminal-ime-hangul-syllable-flush.test.ts')
text = p.read_text()
seq_start = text.find("it('does not double-send", text.find('terminal-ime-hangul-syllable-flush.test.ts'))
end = text.find("\n })", seq_start)
case = text[max(0, seq_start-text.find(' it(')-40):end]
print(case)
print("case_contains_first_compositionstart_before_keydown:", "composition(textarea, 'compositionstart')" in case and case.index("composition(textarea, 'compositionstart'") < case.find("keydown(textarea, 'Process'"))
print("case_contains_insertText_after_insertCompositionText:", "input(textarea, 'insertCompositionText', '한')" in case and "input(textarea, 'insertText', '한')" in case)
PYRepository: stablyai/orca
Length of output: 13109
Emulate Chromium/IBus event order for the first composing key.
Chromium dispatches keydown before compositionstart for the first IME character, so this test should fire the keyCode === 229/isComposing: true keydown first and keep the later compositionstart. The IBus behavior described here is a commit-reinsert sequence, and the subsequent insertText/second compositionstart order in this flow is correct.
Greptile SummaryThis PR fixes Korean Hangul input lagging one syllable behind the IME in the terminal. The root cause was that the
Confidence Score: 5/5Safe to merge. The change is a minimal deletion in the compositionstart handler; the transaction bookkeeping and IBus-protection logic from #11293 are entirely preserved. The fix is a targeted removal of three calls in compositionstart — no new logic added, no new timers created, no new IPC or transport surface touched. The regression is covered by four new test cases that assert on intermediate state, and the IBus constraint is validated by an automated red-control run. Files Needing Attention: No files require special attention. The stale source maps in the patch are an acknowledged maintenance item with no runtime impact.
|
| Filename | Overview |
|---|---|
| config/patches/@[email protected] | Core fix: removes the compositionstart block that cancelled the pending finalizer; replaces it with just setting nextCompositionStart on the pending composition, letting the deferred flush survive to the next task. The same semantic change is applied to the minified CJS (xterm.js) and ESM (xterm.mjs) bundles by exact string replacement. Source maps are acknowledged-stale (noted by author). |
| src/renderer/src/components/terminal-pane/terminal-ime-hangul-syllable-flush.test.ts | New test file with 4 scenarios (×2 for CJS/ESM = 8 tests): regression gate (syllable N flush before syllable N+1 completes), Korean final-consonant transfer (아아 not 앙아), no-duplication at syllable boundary, and no double-send on IBus insertText path. Timing assertions target intermediate state, closing the gap in the existing adversarial suite. |
| pnpm-lock.yaml | Only change is the @xterm/xterm patch content hash and 24 dependent patch_hash= references that necessarily follow any edit to the vendored patch — no dependency version changes. |
Reviews (2): Last reviewed commit: "test(terminal): dispose Hangul flush ter..." | Re-trigger Greptile
| const emitted: string[] = [] | ||
| terminal.onData((data) => emitted.push(data)) | ||
| return { emitted, terminal, textarea: terminal.textarea } |
There was a problem hiding this comment.
Tests observe
triggerDataEvent, not the production terminal.input() path
In the test there is no installTerminalImeCompositionRoute call, so XTERM_COMPOSITION_SESSION_END_EVENT is never prevented. This means _sendCompositionInput falls through to _coreService.triggerDataEvent, which triggers terminal.onData → emitted.push. In production the route's onSessionEnd calls event.preventDefault() and routes through terminal.input() after validating the pty ID and transport.
The timing assertions (the actual regression gates) are unaffected by this difference, but a future test author might be surprised to find the route's pty-validation logic untested here. Consider adding a companion test or a comment noting that pty/transport validation is covered by the existing route tests.
A failed assertion skipped the inline dispose and leaked xterm timers into the next test in the file. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Addressed the review feedback in
The patch hunk carries the same semantic change in all three places it has to: the TypeScript source ( Re-ran after the change: the new file is 8/8, and the full |
|
Verified this fix on macOS. Summary: still reproduces on current Since this branch is 80 commits behind Environment
The two builds resolve different patched packages, so the patch definitely took effect: ResultTyping Anchor x after each syllable commits, starting from the same baseline column (301):
Control: the anchor never advances across three syllables, so each new composition is painted (The fix build's probe was installed mid-word, so the first syllable's Measurement caveatThe probe listens on Also worth noting: the Not coveredI did not verify Orca's own chat composer ( |
Summary
Korean input in the terminal lags one syllable behind the IME.
Typing
한글after a space renders한, then the next composition (ㄱ,ㅡ) appears to overwrite it, and the display only settles once글commits and both syllables appear. Reported after updating to v1.4.163.The committed syllable was never sent. #11293 made
compositionstartcancel the pending finalizer and route the just-committed syllable through_endPendingCompositionSession, which announces the commit withdataPendingReconciliation: truebut never emits the bytes — andterminal-ime-composition-route.ts:92-101drops exactly that event. The macOS Hangul IME commits syllable N at syllable N+1'scompositionstartand sends no interveninginsertText, so syllable N stayed stranded until the nextcompositionend. With no bytes on the wire the buffer cursor never advanced, so xterm drew the next composition's opaque.composition-viewoverlay on the previous syllable's cell.This drops that block from
compositionstartso the already-armed finalizer survives. It fires on the next task, which is:아아and not앙아;compositionend, so on macOS the syllable flushes immediately and the lag is gone.One mechanism covers both platforms. This is effectively upstream xterm's original flush timing restored, while every piece of transaction bookkeeping #11293 added — transaction ids, the pending record, tracked timers, stale-end rejection, accepted/settled balance — is left intact.
Note the deleted block's own
_cancelPendingFinalizeris not lost:_sendPendingCompositioncancels the finalizer as its first action.Screenshots
orca-korean-ime.mov
Testing
pnpm lintpnpm typecheckpnpm test— see the note below about 5 pre-existing macOS-only failurespnpm buildNew file
src/renderer/src/components/terminal-pane/terminal-ime-hangul-syllable-flush.test.ts— 4 cases against both the CJS and ESM terminal builds (8 tests):flushes syllable N before syllable N+1 finishes composing— the regression gate. Assertsemittedis already한right after the secondcompositionstart, before any secondcompositionend.preserves Korean final-consonant transfer—아아, never앙.emits 한글 exactly once— no duplication at the syllable boundary.does not double-send when an insertText input event follows compositionend— the IBus shape.Why the existing suites missed this.
terminal-ime-xterm-adversarial.test.ts:114-126already replays this exact sequence, but asserts only the joined string after the secondcompositionend, so a withheld-then-late-flushed syllable passes identically to a promptly-flushed one. Every new assertion here is on intermediate state.Red control. With the fix reverted in the installed bundle, cases 1 and 2 fail on both builds with
expected '' to be '한'andexpected '' to be '아'— i.e. nothing has reached the terminal at the moment the next syllable starts composing, which is the bug.Regression runs. Full IME suite 244/244; whole
terminal-paneunit suite 2894/2894 across 219 files, includingterminal-ime-xterm-composition-deduplication.test.ts(the #11293아아/앙아and duplicate-commit guarantees) andterminal-ime-xterm-transaction-events.test.ts(the strictaccepted, settled, accepted, settledordering).An earlier, larger version of this fix was rejected by your own tests. Flushing eagerly inside
compositionstart(right afternextCompositionStartis set) fixes macOS but breaks IBus:preserves a Korean final-consonant transfer across compositionsfails withexpected '앙아' to be '아아', because IBus rewrites the textarea in thecompositionupdatethat followscompositionstart, so a synchronous read there sees the pre-transfer앙. Deferring by one task is what makes a single fix correct on both platforms.AI Review Report
Reviewed with Claude (Opus 5). Risks checked and findings:
Cross-platform (macOS / Linux / Windows). The change is in shared
CompositionHelpercode with no platform guard, so all three were considered explicitly. macOS is the reported break. Linux/IBus is the constraint that shaped the fix — an earlier variant regressed it and was discarded on that evidence (above). Windows IME ownership tests are part of the 244-test IME suite and pass. No keyboard shortcut, shortcut label, filesystem path, or shell invocation is touched, so themetaKey/CmdOrCtrl,⌘/Ctrl+, andpath.joinrules do not apply here. The one Electron-specific surface nearby —xterm-bypass-policy.ts:127suppressingisComposingkeydowns, which is why the keydown flush path is unavailable during Hangul composition — was read but not modified.SSH / remote / local. Composition bytes now reach the pty through
terminal-ime-composition-route.ts→terminal.input()→ xterm's existing orderedonDatatransport, the same path all other input uses. No host-local assumption is introduced and no transport code changed, so local ptys, SSH/relay runtimes, git worktrees, and folder workspaces are all unaffected structurally.Agent / integration / git provider. None touched.
Performance. Net removal of work on a hot input path: three calls per
compositionstartare gone and nothing is added. No new timer is created — the fix reuses the finalizer that was already armed, and the tracked-timer set bookkeeping is unchanged, so the bounded-timer guarantee from #11293 holds.terminal-ime-xterm-adversarial.test.ts's 256-transaction same-task burst still passes.UI quality. No component, token, or style changed;
docs/STYLEGUIDE.mdis not engaged. The visible effect is that the terminal now renders what the user typed.Security. See below.
What the review flagged and what I did. It flagged that the originally-drafted eager flush was unsafe on IBus; I dropped it and shipped the smaller variant, then confirmed the difference with a red control rather than reasoning alone. It also flagged the two dead surfaces listed under Notes, which I deliberately left in place to keep the diff minimal rather than expanding scope.
Security Audit
No new input sanitization, command execution, path handling, auth, secrets, or IPC surface. Concretely:
_coreService.triggerDataEvent, bypassing Orca's route becausedispatchSessionEndwas false once_endPendingCompositionSessionhad setsessionEnded. With that call gone,pending.sessionEndedstays false, so the flush dispatches a normal session-end thatterminal-ime-composition-route.tshandles — meaning the bytes are now validated against the captured pty id and the current transport (:96-100) before being written, instead of going out unchecked.CustomEvents on the xterm textarea, entirely renderer-local.pnpm-lock.yaml's only diff is the@xterm/xtermpatch content hash and its 24 dependentpatch_hash=references, which necessarily follow any edit to the vendored patch.No follow-up security work identified.
Notes
Vendored artifacts — needs a maintainer decision.
config/patches/@[email protected]carries both the TypeScript source and the prebuiltlib/xterm.js/lib/xterm.mjsbundles, and the runtime loadslib/. I applied the same semantic change to all three by exact anchored string replacement (asserted to match exactly once per bundle), but I did not regenerate the bundles from upstream xterm source the way PR #11293 did. Consequently:lib/xterm.js.map/lib/xterm.mjs.mapwere left untouched, so theirmappingsoffsets are now stale relative to the edited bundles.index <sha>..<sha>blob lines for the two bundles still name the pre-edit b-side blobs.pnpm installapplies the patch cleanly regardless.If you would rather land this with properly regenerated artifacts, say so and I will redo it against a clean upstream checkout — or feel free to regenerate on your side, since the semantic change is five deleted lines.
Two surfaces are now unreachable.
_endPendingCompositionSessionhas zero call sites, and with nothing dispatchingdataPendingReconciliationthe guard atterminal-ime-composition-route.ts:94is a defensive no-op. Both were left in place deliberately to keep the reviewable diff to the semantic change and to keep the patch's TypeScript source and minified bundles mirrored. Happy to remove them in this PR or a follow-up, whichever you prefer.Local
pnpm testhad 5 failures, all pre-existing and macOS-specific. Neither file is touched by this PR and both reproduce on a clean tree:config/scripts/check-root-directory-entries.test.mjs(3) —.github/scripts/check-root-directory-entries.sh:14usesdeclare -A, which macOS's system/bin/bash3.2.57 does not support, so the script exits 2 instead of 1. The test spawns barebash, so it can only pass where bash is 4+. Worth a separate fix (#!/usr/bin/env bashplus a bash-4 lookup, or an explicit skip on macOS).src/relay/agent-exec-handler.test.ts(2) — asserts on the spawned process environment and picks upGIT_CONFIG_COUNT/GIT_CONFIG_KEY_*injected by my shell session.Testing notes. Manually verified on macOS with the built-in Korean (2-Set) input source, running the branch through
pnpm dev: typing한글into a terminal pane now renders correctly, where before the second syllable's preview covered the first. The아아/앙아final-consonant case is covered by automated tests rather than that manual pass.Playwright e2e was not run locally (needs a GUI/Electron runtime); the nightly
terminal-ime-e2e.ymlibus-hangul job should exercise the Linux path. A manual pass on a real Windows IME would be welcome from anyone set up for it.X handle: I don't have an X account, so there's no handle to credit — noting it explicitly rather than leaving the field blank.