Repository navigation
fix(terminal): stop the Korean gate caching an unknown input source as negative - #13182
Conversation
…s negative On a fresh session the Won rewrite silently did not fire — real-hardware capture on macOS 26.5.2 with 2-Set Korean read 3 of 3 Backquote presses as e2 82 a9 at the PTY, and the feature only started working after the first press or an input-source round trip. Cause: the reader returns null for 'no signal' — the IPC is not exposed yet at startup — as well as for a genuinely absent source, and refreshInputSourceId committed that as isKoreanInputSourceId(null) === false. An unknown became a confirmed negative that nothing retried, because a keystroke-triggered refresh is async and cannot classify the press that triggered it. Leaves the cache unknown on a null read and retries the startup probe with bounded backoff, so the gate is warm before the first key. Bounded because each probe spawns defaults export | plutil | plutil. Co-authored-by: Orca <help@stably.ai>
📝 WalkthroughWalkthroughKorean input-source detection now retries during startup when the input-source ID is null. The retry sequence uses backoff intervals, checks listener ownership, stops after a bounded number of probes, and stops when classification succeeds. Null refresh results no longer set the active classification to non-Korean. Tests cover delayed Korean detection and exhaustion after repeated null results. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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: 43ebd6a0-0a71-4487-b437-aab9aca9f657
📒 Files selected for processing (2)
src/renderer/src/lib/keyboard-layout/korean-input-source.test.tssrc/renderer/src/lib/keyboard-layout/korean-input-source.ts
| void runInitialProbe(readInputSourceId, target) | ||
| } | ||
|
|
||
| /** Why: a keystroke-triggered refresh is async, so it can never classify the | ||
| * press that triggered it — the cache has to be warm BEFORE the first key. At | ||
| * startup the IPC is not always exposed yet, so retry with backoff until the | ||
| * reader yields an ID rather than leaving the gate cold for the session. */ | ||
| async function runInitialProbe( | ||
| readInputSourceId: InputSourceIdReader, | ||
| target: Pick<Window, 'addEventListener' | 'removeEventListener'> | ||
| ): Promise<void> { | ||
| for (const delayMs of INITIAL_PROBE_BACKOFF_MS) { | ||
| // Why: a reset (or a prefetch onto another window) must stop this loop, or | ||
| // it repopulates the cache the reset just cleared. | ||
| if (!listenerAttached || focusTarget !== target) { | ||
| return | ||
| } | ||
| lastRefreshAt = Date.now() | ||
| await refreshInputSourceId(readInputSourceId) | ||
| if (cachedIsKorean !== null) { | ||
| return | ||
| } | ||
| await new Promise((resolve) => setTimeout(resolve, delayMs)) | ||
| } | ||
| if (!listenerAttached || focusTarget !== target) { | ||
| return | ||
| } | ||
| lastRefreshAt = Date.now() | ||
| await refreshInputSourceId(readInputSourceId) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Bind each startup probe to a listener session.
A reset followed by prefetchKoreanInputSource() on the same Window does not stop the old loop. Lines 175 and 185 pass again after the new listener sets listenerAttached and restores the same focusTarget.
The old loop can then call its old readInputSourceId and overwrite the new cache value. Add a monotonically increasing listener-session token. Capture it in prefetchKoreanInputSource(). Check it before every probe. Increment it during reset. Add a regression test that resets and re-prefetches the same mock window with a different reader.
The PR objective requires retries to stop on reset.
* Revert "fix(terminal): detach the Korean input-source probe when its setting goes off (#13283)" This reverts commit 5a84dbb. * Revert "fix(terminal): stop the Korean gate caching an unknown input source as negative (#13182)" This reverts commit 4349599. * Revert "perf(terminal): gate the Korean input-source probe on its setting (#13181)" This reverts commit 42fc537. * Revert "feat(terminal): Korean Won (₩) → backquote key mapping for Korean keyboards (#13104)" This reverts commit 2400393.
…s negative (stablyai#13182) On a fresh session the Won rewrite silently did not fire — real-hardware capture on macOS 26.5.2 with 2-Set Korean read 3 of 3 Backquote presses as e2 82 a9 at the PTY, and the feature only started working after the first press or an input-source round trip. Cause: the reader returns null for 'no signal' — the IPC is not exposed yet at startup — as well as for a genuinely absent source, and refreshInputSourceId committed that as isKoreanInputSourceId(null) === false. An unknown became a confirmed negative that nothing retried, because a keystroke-triggered refresh is async and cannot classify the press that triggered it. Leaves the cache unknown on a null read and retries the startup probe with bounded backoff, so the gate is warm before the first key. Bounded because each probe spawns defaults export | plutil | plutil. Co-authored-by: Orca <help@stably.ai>
* Revert "fix(terminal): detach the Korean input-source probe when its setting goes off (stablyai#13283)" This reverts commit 4b8d3e9. * Revert "fix(terminal): stop the Korean gate caching an unknown input source as negative (stablyai#13182)" This reverts commit d7061e0. * Revert "perf(terminal): gate the Korean input-source probe on its setting (stablyai#13181)" This reverts commit 0712e9a. * Revert "feat(terminal): Korean Won (₩) → backquote key mapping for Korean keyboards (stablyai#13104)" This reverts commit eee48f8.
Found by real-hardware verification of #13104 on macOS 26.5.2 with 2-Set Korean, reading PTY bytes rather than the UI.
The good news first: the concern I raised in review — that
return falsemight not suppress the native ₩, giving the user both a backtick and a ₩ — is disproven. One press produces exactly one0x60and zeroe2 82 a9, under fast taps and 120 ms held keys alike. The native insertion does still reach the DOM (beforeinput/inputwithdata="₩"), but xterm swallows it and it never becomes PTY data. The setting-disabled control reproduces main's deliberate ₩-verbatim behavior, so the harness was measuring the right thing.What it did find: on a cold session the rewrite silently does not fire at all.
e282a9 e282a9 e282a9— all ₩60 60 60— all backticke282a9 60 60— first press leaksCause:
defaultInputSourceIdReaderreturnsnullfor no signal — the IPC is not exposed yet at startup — as well as for a genuinely absent source.refreshInputSourceIdthen committedisKoreanInputSourceId(null), which isfalse. An unknown became a confirmed negative. Nothing recovered it promptly either, because a keystroke-triggered refresh is async and so can never classify the press that triggered it — which is why a 6 second wait did not help, only a later press did.Fix is two halves: leave the cache unknown on a null read, and retry the startup probe with bounded backoff so the gate is warm before the first key. Bounded deliberately — each probe spawns
defaults export | plutil | plutil, and an unbounded retry would be worse than the cold gate it fixes.The retry loop aborts on reset or on a prefetch onto another window. I got that wrong first: the loop kept running across tests and repopulated a cache that had just been cleared, which the existing
reset detaches listeners and invalidates in-flight probestest caught.Both new tests fail with the fix reverted, so they discriminate rather than merely pass. Verified: keyboard-layout + terminal-pane 264 files / 3062 tests, typecheck across all three configs with
config/*.tsbuildinfocleared first, oxlint clean.User-visible impact: without this, the first Backquote of every session types ₩ and the feature looks dead. Worth having before the next release.
cc @hyein-cbio
Made with Orca 🐋