Repository navigation
perf(editor): watch only active, recent and at-risk workspaces - #30415
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 Walkthrough
Priority: ➖ Normal Merge Risk: 🟡 Moderate · up to
|
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
9e5147fb-087a-4b8a-8e4b-2d57d0c09a23
📒 Files selected for processing: 21
src/renderer/src/components/settings/ExperimentalPane.tsxsrc/renderer/src/components/settings/HiddenExperimentalGroup.test.tsxsrc/renderer/src/components/settings/HiddenExperimentalGroup.tsxsrc/renderer/src/hooks/editor-external-watch-background-trim.test.tssrc/renderer/src/hooks/editor-external-watch-rewatch-reload.test.tssrc/renderer/src/hooks/editor-external-watch-rewatch-reload.tssrc/renderer/src/hooks/editor-external-watch-scope.tssrc/renderer/src/hooks/editor-external-watch-target-rows.tssrc/renderer/src/hooks/editor-external-watch-targets.tssrc/renderer/src/hooks/useEditorExternalWatch-background-trim.test.tsxsrc/renderer/src/hooks/useEditorExternalWatch-subscriptions.test.tsxsrc/renderer/src/hooks/useEditorExternalWatch.tssrc/renderer/src/i18n/locales/en.jsonsrc/renderer/src/i18n/locales/es.jsonsrc/renderer/src/i18n/locales/fr.jsonsrc/renderer/src/i18n/locales/ja.jsonsrc/renderer/src/i18n/locales/ko.jsonsrc/renderer/src/i18n/locales/zh.jsonsrc/shared/default-global-settings.tssrc/shared/global-settings-types.tssrc/shared/telemetry-property-schemas.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.
🟠 Major · Run the reload only after a successful watch installation. · useEditorExternalWatch.ts:89
src/renderer/src/hooks/useEditorExternalWatch.ts:89
🎯 Functional Correctness | 🟠 Major | ⚡ Quick winRun the reload only after a successful watch installation.
If
watchWorktreerejects, the catch handler logs the error and resolvesinstalled. Line 89 then callsreloadCleanEditorTabseven though no watch is live. A later disk write can remain unseen because the target stays selected and this effect does not reinstall its watch. Preserve the installation failure in the promise result, and retry the watch before treating the workspace as restored.
🟡 Minor · Reload clean tabs after the remote watch reports ready. · useEditorExternalWatch.ts:73-74
src/renderer/src/hooks/useEditorExternalWatch.ts:73-74
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winReload clean tabs after the remote watch reports
ready.
subscribeRuntimeFileChangesresolves after the preload subscription handle is created, not after thefiles.watchstream reportsready. Line 74 reloads tabs before that event. A remote write can occur between the reload and remote watcher readiness and remain undetected. Trigger the catch-up reload from the actualreadyacknowledgement instead.
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
bce6c798-a3bd-4344-95c6-69e013ee78f5
📒 Files selected for processing: 1
src/renderer/src/hooks/useEditorExternalWatch.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
65e28b74-43ff-4b06-b79c-9114bea9a810
📒 Files selected for processing: 13
src/renderer/src/components/editor/editor-restored-tab-conflict-scan.tssrc/renderer/src/components/editor/editor-save-baseline-check.tssrc/renderer/src/components/editor/editor-save-queue.tssrc/renderer/src/components/editor/useEditorPanelDiffContentLoader.test.tsxsrc/renderer/src/components/editor/useEditorPanelDiffContentLoader.tssrc/renderer/src/components/editor/useEditorPanelFileContentLoader.tssrc/renderer/src/hooks/editor-external-watch-local-roots.tssrc/renderer/src/hooks/editor-runtime-file-watch.test.tssrc/renderer/src/hooks/editor-runtime-file-watch.tssrc/renderer/src/hooks/useEditorExternalWatch-background-trim.test.tsxsrc/renderer/src/hooks/useEditorExternalWatch-rewatch-typing.test.tsxsrc/renderer/src/hooks/useEditorExternalWatch.tssrc/renderer/src/runtime/runtime-file-watch-client.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
| // Why: an unverified baseline means disk may have moved; check before writing, and refuse until the banner shows. | ||
| if (trigger === 'user' && !(await verifyDiskBaselineBeforeUserSave(store, liveFile))) { | ||
| throw new Error(CHANGED_ON_DISK_SAVE_REFUSAL) | ||
| } | ||
| if ((saveGeneration.get(file.id) ?? 0) !== queuedGeneration) { | ||
| return | ||
| } |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
Re-read the live tab and store state after the baseline-verification await.
Lines 79–98 capture state and liveFile. The same block checks liveFile presence, readOnly, and pendingOwnerMigration there. Then Line 105 awaits verifyDiskBaselineBeforeUserSave. That call performs a disk read, and a remote files.read can take up to 15 seconds. During that await, the tab can close, start an owner migration, or change its routing context. The saveGeneration check at Line 108 detects only a generation bump. After it, Lines 121–141 build fileContext and editorTabFileAccess from the stale state and liveFile. The write can then go to an owner that is no longer current, or it can run for a tab that is no longer open. Before this change, no await separated these guards from the write.
After the verification await, read the store again. Then repeat the liveness and owner-migration guards before you build the write context.
🐛 Proposed fix
if (trigger === 'user' && !(await verifyDiskBaselineBeforeUserSave(store, liveFile))) {
throw new Error(CHANGED_ON_DISK_SAVE_REFUSAL)
}
if ((saveGeneration.get(file.id) ?? 0) !== queuedGeneration) {
return
}
+ if (trigger === 'user') {
+ // Why: the disk check awaited I/O; owner, access and liveness may have changed meanwhile.
+ state = store.getState()
+ liveFile = state.openFiles.find((openFile) => openFile.id === file.id) ?? null
+ if (!liveFile || liveFile.readOnly === true) {
+ return
+ }
+ if (liveFile.pendingOwnerMigration === true) {
+ throw new Error('This file is still restoring its workspace owner. Try saving again.')
+ }
+ }For this fix, declare state and liveFile with let at Lines 79–80.
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.
🟠 Major · Announce readiness to adopted capacity-retry… · filesystem-watcher-local-subscription.ts:95-100
src/main/ipc/filesystem-watcher-local-subscription.ts:95-100
🎯 Functional Correctness | 🟠 Major | ⚡ Quick winAnnounce readiness to adopted capacity-retry listeners.
If sender A is waiting for capacity and sender B later subscribes to an existing live root, this branch adds A as a listener. Only B receives the
fs:watchWorktreeresult. A receives nofs:watchLive, so A’s pending catch-up reload never runs. Announce readiness to each adopted listener after confirming its live membership. The same notification must cover listeners adopted when a new root finishes installation.
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
8756dae8-5b0d-4356-8285-900c16931f63
📒 Files selected for processing: 16
src/main/ipc/filesystem-watcher-handlers.tssrc/main/ipc/filesystem-watcher-live-announce.tssrc/main/ipc/filesystem-watcher-local-subscription.tssrc/main/ipc/filesystem-watcher-remote-controller.tssrc/main/ipc/filesystem-watcher-terminal-resync.test.tssrc/main/ipc/filesystem-watcher.test.tssrc/preload/api/filesystem-api.tssrc/preload/api/fs-bridge.tssrc/renderer/src/hooks/editor-external-watch-local-roots.tssrc/renderer/src/hooks/useEditorExternalWatch-background-trim.test.tsxsrc/renderer/src/hooks/useEditorExternalWatch-rewatch-typing.test.tsxsrc/renderer/src/hooks/useEditorExternalWatch-subscriptions.test.tsxsrc/renderer/src/hooks/useEditorExternalWatch.tssrc/renderer/src/store/slices/restored-editor-owner-reparent.test.tssrc/renderer/src/web/preload-api/web-filesystem-api.tssrc/shared/filesystem-entry-types.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.
579a222 to
13c8d6f
Compare
973947c to
a47c50b
Compare
f3a33ec to
4e4cf54
Compare
32c1f7e to
5868894
Compare
|
Back to draft: the safe version of this needs every editor save to check the disk first (planned as phase 2 of the editor buffer design in #30851). Once that lands, this PR drops its autosave-hold logic and ships on top of it. |
74d6667 to
a904df5
Compare
fd8be59 to
d1ce40e
Compare
Background workspaces no longer hold a whole-tree native file watch. The active workspace, the 3 most recently visited ones, and any showing a deleted/renamed tab keep theirs; every other workspace's subscription is released (local, WSL, SSH via the relay, and runtime hosts alike). When a dropped workspace is watched again, its tabs are verified against disk through the existing paths: one overflow resync once the watch is in place reloads clean tabs and refreshes git status, Files and markdown lists; dirty tabs go through the restored-tab disk check, which shows the changed-on-disk banner. Saves stay guarded by the host-side disk check, so nothing is held while unwatched. Also: watch requests are shared per directory and host; root events reach every workspace on that root and SSH payloads carry their connection id; late SSH and local/WSL capacity-retry installs send an overflow resync.
…Files trees after a rewatch - Overflow catch-up drops cached combined-diff bodies for the workspace and re-reads every loaded section of a mounted review (snapshot-backed too). - Clean edit tabs are probed on the owning host first; a file proven gone is marked deleted and keeps its last content instead of reloading into an error. - Dirty tabs are checked from the overflow itself, so the check runs after the watch is installed, including late capacity/SSH installs. - Local/WSL Files trees also take the renderer-synthesized catch-up. - Deleted/renamed-tab pins are capped at 3 beyond the active and recent set.
…le existence answers - Cached Changes views reset only clean loaded sections; dirty sections keep their drafts and baselines (also for per-path invalidation). - A mounted review re-reads loaded and in-flight sections on catch-up. - Existence answers carry a per-tab generation; a newer probe or watch event for the tab supersedes an older answer. - A tab is marked deleted only on a per-path ENOENT, never on a whole-request not-found or an old host's scalar fallback.
…letions, chunk existence probes - A disk check requested while one is in flight is followed by one fresh read (coalesced) instead of being answered by the older reply. - The restored-tab check probes runtime-owned files on their host; a per-path ENOENT marks the tab deleted. After a retry ceiling it stops, clears the suspension and shows the changed-on-disk banner. - Overflow existence probes are split into host-sized chunks, in order.
…le absence answers re-read - A tab that already read its file and now gets a path-specific ENOENT on reload is marked deleted and keeps its last content, with or without an existence probe, so older paired servers are covered. - The restored-tab check applies its request generation after the absence probe too, so an older answer cannot resolve a newer request.
d1ce40e to
2971065
Compare
…seded or closed (#31128) Follow-up to #30415. A watch event that superseded a pending overflow existence probe left the tab's entry behind forever, and the dirty-tab disk-check request map never removed anything. Superseding now deletes the entry, and closed tabs' disk-check requests are dropped by the scan's existing open-tabs subscription. The disk-check map uses a global sequence so a reopened tab can't reuse an old read's number.
ELI5
Orca used to ask the operating system to watch every folder of every workspace that had a tab open. On a Mac, all of those watches go through one system service that every app shares. When it gets too busy, everything on the machine slows down. One teammate had a chat start that stalled for more than 30 seconds waiting on that service.
Now Orca only watches the workspace you are looking at, plus a few you used recently. When you go back to a workspace it stopped watching, Orca checks your open files against what is on disk and catches up.
What Changed
Before: every workspace with an open editor tab kept a whole-folder watch, whether or not you had looked at it today. With 20 workspaces open, that meant 20 watches.
After: a workspace keeps its watch only if it is:
Every other workspace's watch is released. This applies the same way to local folders, WSL, SSH workspaces (where the watch runs on the remote host and is released through the same request), folder workspaces, and workspaces on a paired Orca server.
Switching back. When a released workspace is watched again, Orca catches up after the new watch is in place. It reuses the existing paths and adds no new UI:
If the watch could not be installed right away (the watcher limit was full, or the SSH connection was still coming up), the late install sends the same catch-up signal when it lands.
What is not here. The earlier draft paused autosave on re-watched tabs and had timers and banners for that pause. All of it is gone. Since #30417, every editor save sends the disk version it was based on, and the host refuses the save if the file changed since then. A stale save cannot overwrite anything, so nothing needs to be held while a workspace is unwatched. The draft's hidden on/off setting is also gone.
Also carried over from the draft:
Why
Watching less is the direct fix for the shared system service being overloaded. The alternatives were:
The 3 recent workspaces stay watched so quick back-and-forth switching never has to catch up. The count is the same on every OS.
Measured with 20 workspaces open, each with a tab, on macOS (Apple Silicon). The native subscription count comes from the watch-target selector. The other three numbers come from a separate 20-second run where a script wrote about 400 files a second spread across 20 folders of 3,000 files each, with one native watch per watched folder:
During this run, the system service's own CPU time was mostly driven by how many writes happened, so it was too noisy to compare here. The win is that it delivers to, and keeps state for, 5 times fewer subscribers.
Linked Issue
Maintainer PR; no issue.
Visual Proof
N/A. Nothing new appears on screen. Switching back reuses the existing reload and "changed on disk" banner, which are covered by the tests below.
Testing
editor-external-watch-background-trim.test.ts: which workspaces stay watched, the order recent workspaces are evicted in, deleted workspaces not holding a recent slot, unsaved/combined-diff/rich-editor tabs no longer pinning a watch, and the same policy for SSH, WSL, folder workspaces and paired servers.useEditorExternalWatch-background-trim.test.tsx: switching away releases the native subscription, switching back re-subscribes and catches up, an SSH workspace is released and re-requested on its connection, and a shared folder is released only once.useEditorExternalWatch-switch-back.test.tsx: on switching back, a clean tab reloads, a tab whose file was deleted keeps its content and shows the deleted banner, and an unsaved tab whose file changed gets the changed-on-disk banner with its edits kept, including when the change lands between the switch and a late install. Git status and Files get exactly one refresh, cached Changes contents are dropped, and autosave is never held.editor-external-watch-overflow.test.ts,use-combined-diff-section-revalidation.test.tsx,useFileExplorerWatch.catch-up.test.tsx: the existence check (including when it fails or the host returns an error), the open Changes view re-reading its sections, and the local Files tree taking the catch-up without double-processing.pnpm tc,pnpm lint, oxlint andpnpm run check:code-quality:changedpass.Review
Agent skill upstream boundary
Notes
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)