Skip to content

fix(terminal): stop the Korean gate caching an unknown input source as negative - #13182

Merged
nwparker merged 1 commit into
mainfrom
nwparker/fix-korean-gate-cold-start
Aug 8, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/fix-korean-gate-cold-start

Conversation

@nwparker

@nwparker nwparker commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

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 false might not suppress the native ₩, giving the user both a backtick and a ₩ — is disproven. One press produces exactly one 0x60 and zero e2 82 a9, under fast taps and 120 ms held keys alike. The native insertion does still reach the DOM (beforeinput/input with data="₩"), 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.

scenario PTY bytes
cold session, 3 presses e282a9 e282a9 e282a9 — all ₩
same session after an input-source round trip 60 60 60 — all backtick
warm, 3 presses e282a9 60 60 — first press leaks

Cause: defaultInputSourceIdReader returns null for no signal — the IPC is not exposed yet at startup — as well as for a genuinely absent source. refreshInputSourceId then committed isKoreanInputSourceId(null), which is false. 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 probes test 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/*.tsbuildinfo cleared 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 🐋

…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>
@coderabbitai

coderabbitai Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Korean 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)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the bug, fix, impact, and verification, but it omits several required template sections and confirmations. Add the required Screenshots, Testing, AI Review Report, Security Audit, and Notes sections, including explicit cross-platform review confirmation.
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main fix: preventing an unknown Korean input source from being cached as negative.
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.
✨ 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.

@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: 43ebd6a0-0a71-4487-b437-aab9aca9f657

📥 Commits

Reviewing files that changed from the base of the PR and between d64ccc7 and 6420654.

📒 Files selected for processing (2)
  • src/renderer/src/lib/keyboard-layout/korean-input-source.test.ts
  • src/renderer/src/lib/keyboard-layout/korean-input-source.ts

Comment on lines +161 to +189
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)

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.

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

@nwparker
nwparker merged commit 4349599 into main Aug 8, 2026
46 checks passed
@nwparker
nwparker deleted the nwparker/fix-korean-gate-cold-start branch August 8, 2026 10:12
nwparker added a commit that referenced this pull request Aug 9, 2026
* 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.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…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>
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
* 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.
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.

1 participant