Repository navigation
fix(editor): index WSL watcher aliases per batch - #14015
Conversation
📝 WalkthroughWalkthroughThe 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)
✅ Passed checks (4 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.
🧹 Nitpick comments (2)
src/renderer/src/hooks/useEditorExternalWatch.ts (1)
606-621: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDeclare
indexedOpenFilesin the literal instead ofObject.defineProperty.
Object.definePropertycreates a non-enumerable property and bypasses type checking. Two consequences follow. TypeScript does not verify the attached shape againstExternalWatchNotification, so a rename ofmatchescompiles. 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.definePropertyand 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 winDrop the conditional wrapper so a renamed export fails the test.
getLocalWindowsWslPathIdentityexists insrc/shared/cross-platform-path.ts, so the guard is dead today. If the export is later renamed,pathOperationCounts.identitiesstays 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
importOriginalastypeof CrossPlatformPathModuleand removePathModuleWithIdentity.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 87c5ab06-707c-4f73-a962-c05c36d6944d
📒 Files selected for processing (7)
src/renderer/src/components/editor/editor-autosave.tssrc/renderer/src/components/editor/editor-external-watch-path-index.test.tssrc/renderer/src/components/editor/editor-external-watch-path-index.tssrc/renderer/src/hooks/useEditorExternalWatch-complexity.test.tssrc/renderer/src/hooks/useEditorExternalWatch.test.tssrc/renderer/src/hooks/useEditorExternalWatch.tssrc/shared/cross-platform-path.ts
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.
origin/mainThe bound is
<= 3 × (events + open files)= 15,303. Main/reverted fail; the candidate passes with O(events + files) path work.Implementation
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
pnpm typecheckFinal review and latest-head CI are clean. Ready for review; do not merge from this task.