Repository navigation
fix(watcher): flush file changes on a steady cadence instead of waiting for quiet - #30270
Conversation
…ing for quiet Watcher batches used a 150 ms trailing debounce capped at 500 ms, so a worktree with agents writing continuously always waited the full cap. The git status nudge had no cap and could starve until the 60 s safety poll. Batches now flush 25 ms after the first change following a quiet period, then at most every 100 ms; new events join an armed flush instead of pushing it back.
|
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: 🔵 Low · up to
|
Raise the first-flush delay to 75 ms so the native watcher's split burst lands in one batch, cap the flush delay at one interval so a backwards clock jump can't stall delivery, and widen the editor delete debounce to cover a split across one flush interval.
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:
67e964ec-a0ca-46e1-b2bc-0c9db1061b28
📒 Files selected for processing: 7
src/main/runtime/mobile-session-tabs-notify-coalescer.tssrc/renderer/src/components/right-sidebar/useFileExplorerWatch.tssrc/renderer/src/hooks/editor-external-watch-event-reconciliation.tssrc/renderer/src/hooks/useEditorExternalWatch-wsl-repro.test.tssrc/renderer/src/store/slices/restored-editor-owner-reparent.test.tssrc/shared/filesystem-watch-batch-window.test.tssrc/shared/filesystem-watch-batch-window.ts
🚧 Files skipped from review as they are similar to previous changes: 1
- src/renderer/src/components/right-sidebar/useFileExplorerWatch.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.
…d widen delete grace Markdown document refresh used a resetting 125 ms debounce that never fired once watch batches arrive every 100 ms. Delete tombstones now wait two batch intervals so slow stat calls (WSL, AV scans) can't split a save into a flash.
…ites One watcher-triggered editor read and one markdown scan per target in flight, with a single follow-up; markdown scans honour the latest change time; the headless Windows watcher no longer resets its refresh timer on every event.
…r-driven reloads files.watch takes an optional batchCadence; hosts keep legacy trailing batching unless the client opts in. Coalesced editor follow-ups re-check the tab and replace a hung read only once; Markdown mounts skip pre-change scans; the Windows fallback refreshes the whole tree at most every 500 ms.
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:
4af17a68-e083-4ef7-b4ea-c6c08e250949
⛔ Files ignored due to path filters: 1
src/shared/rpc-contract/rpc-params-catalog.generated.tsis excluded by!**/*.generated.*
📒 Files selected for processing: 18
src/main/runtime/files/watch/windows-file-watch.test.tssrc/main/runtime/files/watch/windows-file-watch.tssrc/main/runtime/orca-runtime-files-watch.test.tssrc/main/runtime/rpc/methods/file-watch-event-batcher.test.tssrc/main/runtime/rpc/methods/file-watch-event-batcher.tssrc/main/runtime/rpc/methods/file-watch-stream-lifecycle.tssrc/main/runtime/rpc/methods/files-watch-batch-cadence.test.tssrc/main/runtime/rpc/methods/files.tssrc/renderer/src/components/editor/editor-watcher-reload-coalescer.test.tssrc/renderer/src/components/editor/editor-watcher-reload-coalescer.tssrc/renderer/src/components/editor/use-markdown-document-watch-refresh.tssrc/renderer/src/components/editor/useEditorPanelExternalContentEvents.test.tsxsrc/renderer/src/components/editor/useEditorPanelExternalContentEvents.tssrc/renderer/src/components/editor/useMarkdownDocuments.tssrc/renderer/src/components/editor/useMarkdownDocuments.watch.test.tssrc/renderer/src/runtime/runtime-file-client-watch.test.tssrc/renderer/src/runtime/runtime-file-watch-client.tssrc/shared/rpc-contract/files-target-params.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.
Combined-diff section reloads and per-file editor reload dispatch no longer push an armed timer back; a queued editor follow-up for a tab that left the screen marks it stale instead of dropping the change.
… sustained writes A combined-diff section discards an invalidated in-flight load at most once in a row; worktree base-directory notifications no longer restart their timer.
… reloads A combined-diff load never commits over a section with unsaved edits; a reload queued behind a hung read starts after the stale limit without needing another change event.
…edited tabs A Markdown scan that never settles is abandoned after the join window so later changes scan again; a queued editor follow-up for a tab edited meanwhile marks it changed-on-disk and stale instead of dropping the change.
Payloads from the same burst still share the in-flight read; a payload from a later task gets exactly one fresh read issued after the current one settles.
ELI5
When files change on disk, Orca collects the changes into small batches before refreshing the file tree, open files and git status. The batching waited for things to go quiet first. With agents writing files nonstop, things never go quiet, so every batch sat until a 0.5 s cap ran out. The git status refresh had no cap at all and could wait up to a minute. Now Orca sends the first change within 75 ms and then keeps sending on a steady 100 ms rhythm, however busy the disk is.
What Changed
files.watchstream) used a 150 ms "wait for quiet" timer that restarted on every change, capped at 500 ms. Under constant agent writes that meant every refresh took about 500 ms, on top of the native watcher's own delay.files.watchtakes an optionalbatchCadence: 'interval'). This client sends it because its consumers run one read at a time; older clients don't, so a newer host keeps their 150 ms / 500 ms batching and they keep working on slow links. Older hosts ignore the field.watchBatchFlushDelayMsinsrc/shared/filesystem-watch-batch-window.ts, computes the delay for all three batchers. The renderer's Explorer refresh scheduler already flushed with no delay. It no longer imports the shared window constants; its two callers pass their own values.Every consumer of watch events (audited)
files.watchbatcher.gitwatch; raw events over SSH)Why
A timer that restarts on every change is the wrong tool when changes never stop, which is the normal state with several agents working. Measured on macOS and Linux with 20 worktrees under agent-like write load, delivery sat at the 500 ms cap. A steady cadence keeps refreshes bounded and fresh without increasing git work.
Alternatives considered:
Linked Issue
Fixes #
Visual Proof
N/A: timing-only change with no new UI. File tree, editor and git status updates arrive sooner during heavy agent activity.
Testing
Covered by tests:
Results:
pnpm testpasses forsrc/main/ipc,src/renderer/src/components/right-sidebar,src/renderer/src/hooksand the new shared tests: 9,204 tests.pnpm tcandpnpm run check:code-quality:changedare clean.Review
Agent skill upstream boundary
Notes
batchCadenceonfiles.watch). Without it, hosts batch exactly as before, so older clients see no change; older hosts ignore it. SSH watch batching runs on the client, so an older desktop never receives a newer host's batches there. Remote hosts sendfs:changedbatches in the same format, only on a different schedule, and older clients handle any cadence.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)