Skip to content

fix(editor): index WSL watcher aliases per batch - #14015

Merged
Jinwoo-H merged 6 commits into
mainfrom
fix/sta-3942-index-wsl-watcher-aliases
Aug 12, 2026
Merged

Jinwoo-H merged 6 commits into
mainfrom
fix/sta-3942-index-wsl-watcher-aliases

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Aug 12, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fixes the P1 renderer freeze risk in STA-3942.

A maximum-sized local Windows/WSL watcher batch could normalize and compare every event against every open editor path, both in the watcher and again after the reload debounce. This PR builds one path-identity index per watcher batch and memoizes one replacement index if the open-tab snapshot changes, then uses Map/Set lookups for update, delete, recreate, and tab matching.

Deterministic reproduction

The CI oracle drives the real renderer watcher handler with 5,000 opposite-alias update events, 100 restored WSL tabs, and a combined-diff consumer. It deliberately replaces the open-files array during the 75 ms debounce, dispatches all 5,000 downstream notifications, and counts path identity/normalization/alias operations as the required signal; elapsed time is secondary.

Variant Path operations Handler time on Windows 2 Result
latest origin/main 1,005,100 ~1,262 ms FAIL
candidate with production fix disabled 1,005,100 ~1,268 ms FAIL
indexed candidate 5,300 ~48 ms PASS

The bound is <= 3 × (events + open files) = 15,303. Main/reverted fail; the candidate passes with O(events + files) path work.

Implementation

  • expose one authoritative local Windows/WSL path identity
  • canonicalize each eligible event and open path once per batch
  • index literal paths, aliases, WSL-proven aliases, diffs, deletes, and creates
  • share a memoized per-open-files-snapshot index across debounced consumers
  • preserve explicit local-Windows eligibility from fix(editor): unify local WSL terminal and watcher paths #13798
  • preserve owner, folder-workspace, SSH/runtime, POSIX, case, delete/create/rename, overflow, and batching semantics

Why this shape

A memoized comparator still performs event×tab Map lookups and retains the nested algorithm. A batch Map/Set index removes the nested work structurally at the watcher path-identity boundary. If tabs change during debounce, one WeakMap-cached index is rebuilt for that snapshot and reused by all notifications, avoiding both stale matches and renewed nested scans.

Validation

  • identical latest-main / candidate / disabled oracle
  • focused watcher, WSL regression, path identity, autosave, panel-consumer, and target tests
  • pnpm typecheck
  • changed-file lint, formatting, max-lines, and commit hooks
  • physical Windows 2 + real Ubuntu 24.04 WSL headed Electron refresh
  • 5,000 real WSL-file touches with 101 forward-UNC tabs: ~67 ms producer burst, ~169 ms largest sampled renderer gap, active Monaco content correct, 0 dirty/mutation errors
  • final post-finding correctness, performance, and adversarial review round (all clean)
  • CI on latest pushed head, including ready-state pass (all green)

Final review and latest-head CI are clean. Ready for review; do not merge from this task.

@OrcaWin
OrcaWin marked this pull request as ready for review August 12, 2026 10:08
@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The change adds indexed external-watch path processing with normalized Windows and WSL alias matching. The index filters events and open files by scope, tracks deleted editors and combined-diff consumers, and preserves open-file ordering. The editor watcher uses one indexed batch for restoration, deletion handling, notifications, and autosave matching. Tests cover path behavior, runtime ownership, event handling, and bounded path operations.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: indexing WSL watcher aliases per batch.
Description check ✅ Passed The description clearly explains the problem, implementation, linked issue, testing, performance results, and platform validation.
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.

🧹 Nitpick comments (2)
src/renderer/src/hooks/useEditorExternalWatch.ts (1)

606-621: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Declare indexedOpenFiles in the literal instead of Object.defineProperty.

Object.defineProperty creates a non-enumerable property and bypasses type checking. Two consequences follow. TypeScript does not verify the attached shape against ExternalWatchNotification, so a rename of matches compiles. Any consumer that copies the notification with object spread drops the index and silently reverts to per-path scanning.

If a consumer depends on the property staying non-enumerable, keep Object.defineProperty and add a one-line comment that states that dependency.

♻️ Proposed refactor
-      const notification = {
+      const notification: ExternalWatchNotification = {
         worktreeId: target.worktreeId,
         worktreePath: target.worktreePath,
         relativePath,
         runtimeEnvironmentId: target.runtimeEnvironmentId,
-        ...localWslAliasOption(target)
-      }
-      Object.defineProperty(notification, 'indexedOpenFiles', {
-        value: {
-          matches: (openFiles: OpenFile[]) => batchPaths.matchingOpenFiles(change, openFiles)
-        }
-      })
+        ...localWslAliasOption(target),
+        indexedOpenFiles: {
+          matches: (openFiles: OpenFile[]) => batchPaths.matchingOpenFiles(change, openFiles)
+        }
+      }
src/renderer/src/hooks/useEditorExternalWatch-complexity.test.ts (1)

32-39: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Drop the conditional wrapper so a renamed export fails the test.

getLocalWindowsWslPathIdentity exists in src/shared/cross-platform-path.ts, so the guard is dead today. If the export is later renamed, pathOperationCounts.identities stays at zero and the bound assertion passes without measuring identity work.

♻️ Proposed refactor
-    ...(actual.getLocalWindowsWslPathIdentity
-      ? {
-          getLocalWindowsWslPathIdentity: (value: string) => {
-            pathOperationCounts.identities++
-            return actual.getLocalWindowsWslPathIdentity!(value)
-          }
-        }
-      : {})
+    getLocalWindowsWslPathIdentity: (value: string) => {
+      pathOperationCounts.identities++
+      return actual.getLocalWindowsWslPathIdentity(value)
+    }

Then type importOriginal as typeof CrossPlatformPathModule and remove PathModuleWithIdentity.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 87c5ab06-707c-4f73-a962-c05c36d6944d

📥 Commits

Reviewing files that changed from the base of the PR and between e5cd5bf and 24d4dd5.

📒 Files selected for processing (7)
  • src/renderer/src/components/editor/editor-autosave.ts
  • src/renderer/src/components/editor/editor-external-watch-path-index.test.ts
  • src/renderer/src/components/editor/editor-external-watch-path-index.ts
  • src/renderer/src/hooks/useEditorExternalWatch-complexity.test.ts
  • src/renderer/src/hooks/useEditorExternalWatch.test.ts
  • src/renderer/src/hooks/useEditorExternalWatch.ts
  • src/shared/cross-platform-path.ts

@Jinwoo-H
Jinwoo-H merged commit 09ec516 into main Aug 12, 2026
89 checks passed
@Jinwoo-H
Jinwoo-H deleted the fix/sta-3942-index-wsl-watcher-aliases branch August 12, 2026 10:24
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
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.

2 participants