Skip to content

fix(terminal): detach the Korean input-source probe when its setting goes off - #13283

Merged
nwparker merged 1 commit into
mainfrom
nwparker/korean-prefetch-teardown
Aug 9, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/korean-prefetch-teardown

Conversation

@nwparker

@nwparker nwparker commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

Two defects in the Korean input-source probe, both found by review of my own earlier changes. Independent of the IME revert (#13282) — this touches only the Won-key feature's probe, which stayed on main.

1. The probe outlived its setting. #13181 gated the call site so the probe never attaches when terminalKoreanWonToBackquote is off. But prefetchKoreanInputSource installs global focus/keydown/keyup listeners behind an idempotent listenerAttached guard, and its only teardown was test-only. So switching the setting off mid-session left the listeners live and still spawning defaults export | plutil | plutil — four processes — on keyboard activity. Confirmed empirically rather than by reading: a test that enables, disables, then dispatches a Lang1 keydown saw the reader called again after the setting was off.

Adds a real disposer and calls it from the effect body, not its cleanup. Cleanup also runs on tab switches and on any dep-identity change, so disposing there would detach and re-probe constantly — a worse regression than the leak. Body-side sync is naturally idempotent.

No reference counting: only the active tab's effect ever prefetches, so a refcount would be machinery with no second owner to count.

2. The initial-probe abort guard was dead code in production. It compared focusTarget !== target, but production always passes the same window singleton, so the check could never fire. Harmless until a disposer exists — with one, a stop/start sequence lets the old sleeping probe loop wake, pass the guard, and race the new one, each bumping refreshGeneration and discarding the other's read. Replaced with an epoch counter.

The existing tests missed this because makeMockWindow() returns a fresh object per call, so the identity check is meaningful in tests and dead in the app.

Verified: keyboard-layout + the gate test 6 files / 68 tests pass, typecheck clean across all three configs with config/*.tsbuildinfo cleared first. Rebased onto post-revert main.

Made with Orca 🐋

…goes off

Gating the prefetch call site stopped the probe from ever attaching, but not
from surviving. prefetchKoreanInputSource installs global focus/keydown/keyup
listeners behind an idempotent listenerAttached guard, and the only teardown
was test-only — so disabling the setting mid-session left the listeners live
and still spawning defaults export | plutil | plutil on keyboard activity.

Syncs in the effect body rather than its cleanup: cleanup also runs on tab
switches and on any dep-identity change, so disposing there would detach and
re-probe constantly.

Also replaces the initial-probe abort guard with an epoch. It compared window
identity, which is dead code in production where window is a singleton, so a
stop/start could let a sleeping probe loop wake and race the new one.

Co-authored-by: Orca <[email protected]>
@coderabbitai

coderabbitai Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Korean input-source prefetching now has an explicit stop function. A prefetch epoch invalidates stale initial-probe loops and refreshes. The keyboard handler stops prefetching when the Korean Won conversion setting is disabled. Tests mock the stop function, reset it between cases, and verify that disabled settings dispose the probe without starting prefetch.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains both defects and the implementation, but it omits required Screenshots, AI Review Report, Security Audit, and Notes sections. Add all required template sections, complete the testing checklist, and document cross-platform review and the security audit.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: detaching the Korean input-source probe when the setting is disabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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
📝 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

🧹 Nitpick comments (1)
src/renderer/src/components/terminal-pane/keyboard-handlers-korean-prefetch-gate.test.tsx (1)

78-85: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Test the setting transition, not only the initial disabled state.

deps(false) mounts with isActive: true at Line 27 and the setting already disabled. It does not attach a probe before calling the disposer, so it cannot verify teardown when the setting changes or when the hook becomes inactive.

Parameterize isActive, render with the setting enabled first, then rerender with the setting disabled. Assert the disposer call and the absence of a new prefetch.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 7a2f30e4-2401-42ab-b3e8-696dcd8bd0ef

📥 Commits

Reviewing files that changed from the base of the PR and between 17cfc96 and 318e2d0.

📒 Files selected for processing (3)
  • src/renderer/src/components/terminal-pane/keyboard-handlers-korean-prefetch-gate.test.tsx
  • src/renderer/src/components/terminal-pane/keyboard-handlers.ts
  • src/renderer/src/lib/keyboard-layout/korean-input-source.ts

Comment on lines +289 to +294
// Synced in the effect body, not its cleanup: cleanup also runs on tab switches and on any
// dep-identity change, so disposing there would reattach and re-probe constantly.
if (koreanWonToBackquoteEnabled) {
prefetchKoreanInputSource()
} else {
stopKoreanInputSourcePrefetch()

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.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Handle the disabled-setting transition when the hook is inactive.

useEffect returns at Lines 274-276 before it reaches this disposer branch. If this hook starts the module-global probe and then becomes inactive before koreanWonToBackquoteEnabled changes to false, the disposer is never called. The global listeners and pending probe can continue after the setting is disabled.

Move disabled-state synchronization into an effect that is not gated by isActive, or guarantee that another active hook always observes the transition.

@nwparker
nwparker merged commit 5a84dbb into main Aug 9, 2026
45 checks passed
@nwparker
nwparker deleted the nwparker/korean-prefetch-teardown branch August 9, 2026 02:21
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
…goes off (stablyai#13283)

Gating the prefetch call site stopped the probe from ever attaching, but not
from surviving. prefetchKoreanInputSource installs global focus/keydown/keyup
listeners behind an idempotent listenerAttached guard, and the only teardown
was test-only — so disabling the setting mid-session left the listeners live
and still spawning defaults export | plutil | plutil on keyboard activity.

Syncs in the effect body rather than its cleanup: cleanup also runs on tab
switches and on any dep-identity change, so disposing there would detach and
re-probe constantly.

Also replaces the initial-probe abort guard with an epoch. It compared window
identity, which is dead code in production where window is a singleton, so a
stop/start could let a sleeping probe loop wake and race the new one.

Co-authored-by: Orca <[email protected]>
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