Skip to content

fix(watcher): flush file changes on a steady cadence instead of waiting for quiet - #30270

Merged
nwparker merged 12 commits into
mainfrom
nwparker/file-watcher-stuff
Oct 19, 2026
Merged

nwparker merged 12 commits into
mainfrom
nwparker/file-watcher-stuff

Conversation

@nwparker

@nwparker nwparker commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

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

  • Before:
    • Watcher batches (local, SSH, and the runtime files.watch stream) 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.
    • Git status: the refresh nudged by file changes used a 125 ms timer that also restarted on every change, with no cap. A worktree with an agent writing continuously never got a watcher-driven git status refresh, only the 60 s safety poll.
  • After:
    • Watcher batches: the first change after a quiet period flushes after 75 ms. That is just long enough for the native watcher's split burst, such as a temp-file write plus rename, to land in one batch. While a flush is pending, new changes join it instead of delaying it. The next flush can't start until 100 ms after the previous one.
    • Worst-case delay drops from about 500 ms to about 100 ms, and a batch is sent at most 10 times a second.
    • Clock jumps: the delay is capped at one interval, so a backwards clock change can't stall delivery.
    • Editor delete debounce: raised from 75 ms to 250 ms (two batch intervals plus margin, so slow stat calls on WSL or under antivirus scans can't split a save). When a save is split into a delete and a create in separate batches, the open tab doesn't flash "deleted".
    • Markdown file list: its refresh used the same restarting timer and would never fire under sustained writes; it now fires 125 ms after the first change.
    • "All Changes" diff sections: their 300 ms reload timer restarted on every change, and a change during a slow load threw that load's result away, so they never refreshed while writes continued. The timer no longer restarts, and a load is discarded at most once in a row.
    • Worktree list and branch metadata over SSH: the 250 ms notification timer restarted on every raw event; it no longer does.
    • Open files on slow connections: a file changing continuously used to start a fresh read on every batch, and each read was thrown away when the next one started, so over SSH or WSL the tab could stop updating. Now one read per file is in flight at a time, with a single follow-up for changes that arrive meanwhile. The follow-up re-checks that the tab is still open, unedited and on screen, and a read that hangs is replaced at most once (after 10 s, even if no further changes arrive). If you switch away while a follow-up is queued, the tab is marked stale so it reloads when you come back; if you start typing first, your edit is kept and the tab shows the changed-on-disk warning.
    • Markdown document list: only one scan runs at a time, and it asks for a scan newer than the latest change rather than the first. Switching back to a Markdown tab won't reuse a scan that started before the latest change.
    • Windows remote-host watcher: it used the same restarting timer and stopped reporting under sustained writes; it now does one whole-tree refresh every 500 ms while changes continue.
    • Remote hosts keep the old timing for old clients. The faster cadence is opt-in on the remote file-watch stream (files.watch takes an optional batchCadence: '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.
    • Git status: the nudge now fires 125 ms after the first change in a burst and is never pushed back. The existing 3 s minimum between git status runs still applies, so git can't run more often than before.
  • Mechanism: one shared helper, watchBatchFlushDelayMs in src/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)

Consumer Timing before Now
Main local batcher, SSH batch, runtime files.watch batcher 150 ms restarting, 500 ms cap 75 ms first flush, then every 100 ms (remote: only for clients that opt in)
Windows remote-host fallback watcher 150 ms restarting one whole-tree refresh per 500 ms, not restarted
File Explorer refresh scheduler 0 ms, one refresh in flight unchanged
Git status nudge 125 ms restarting 125 ms, not restarted; 3 s minimum between runs (unchanged)
Markdown document list 125 ms restarting 125 ms, not restarted; one scan in flight plus one follow-up; a scan that never returns is abandoned after 30 s
Editor per-file reload dispatch 75 ms restarting 75 ms, not restarted (latest event wins)
Editor content and diff reads new read per event, older read discarded one read per tab in flight plus one follow-up; re-checks the tab; switched-away tabs are marked stale
Combined-diff section reload 300 ms restarting; every in-flight load discarded on the next change 300 ms, not restarted; a change during a load discards that result at most once in a row, then the next result is shown and one follow-up runs; a section with unsaved edits is never overwritten
Worktree list and git-metadata notifications (.git watch; raw events over SSH) 250 ms restarting 250 ms, not restarted; changes join the pending notification
Editor delete tombstone 75 ms 250 ms, intentionally restarting (a create cancels it)
Self-save echo verification read later events joined an in-flight read events in the same burst share the read; a later event gets one fresh read after it settles
Autosave reset on external change, combined-diff cache bust synchronous unchanged

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:

  • Shrinking the debounce numbers: under continuous writes the same starvation remains.
  • Removing batching: this would multiply renderer refreshes and IPC sends during file-change storms.

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

  • I manually tested these changes locally (not run in the app; covered by unit tests)
  • Automated tests added/updated, or explained why not below

Covered by tests:

  • The first flush happens at 75 ms.
  • Changes during a pending flush join it.
  • The next flush waits the full interval.
  • A change every 10 ms for 1 s keeps flushing about every 100 ms instead of starving (local, SSH and runtime batchers).
  • Git status still refreshes while file events arrive every 50 ms. This test fails on the old code.

Results:

  • pnpm test passes for src/main/ipc, src/renderer/src/components/right-sidebar, src/renderer/src/hooks and the new shared tests: 9,204 tests.
  • pnpm tc and pnpm run check:code-quality:changed are clean.
  • The pure timing logic is platform-independent. The batchers run the same on macOS, Linux, Windows and SSH hosts.

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Known follow-ups (pre-existing, not introduced here): (1) the saved-content snapshot used to recognise Orca's own save echo can be briefly stale relative to a very fast follow-up save; (2) a self-save verification read that never returns (no transport timeout) blocks echo verification for that one file until it settles.
  • Cost: under sustained writes, batches now go out up to 10 times a second instead of about 2. Each batch refreshes only the touched, expanded folders, and the renderer won't start a new refresh while one is still running. Git status keeps its 3 s minimum gap, so git work does not increase. Over SSH, Explorer re-reads can happen up to ~10×/s instead of ~2×/s, bounded by the scheduler never starting a refresh while one is in flight.
  • Wire compatibility: one optional request field (batchCadence on files.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 send fs:changed batches in the same format, only on a different schedule, and older clients handle any cadence.
  • Not in this PR: the native watcher's own internal delay (also capped at 500 ms) is compiled into the native module, so it can't be changed from Orca's code. That will be a separate change.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

…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.
@coderabbitai

coderabbitai Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Filesystem watcher batchers now use a leading delay and recurring interval. New events do not reset an armed batch timer. Runtime files.watch clients can request interval cadence, while clients that omit it retain trailing batching. Renderer refresh scheduling preserves armed timers, Markdown scans serialize changes, and editor reloads are coalesced by key. Tests cover timing, sustained events, cadence selection, and reload behavior.

Priority: ➖ Normal

Merge Risk: 🔵 Low · up to 76e98

If a file read hangs and no further file changes arrive, an open editor tab can keep showing stale content. This is an edge case, and the next file change recovers it. It is worth fixing but need not block the merge.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 13.79% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 29 functions across 40 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
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.
Title check Passed The title clearly describes the main change: file-watcher batches now flush on a steady cadence instead of waiting for quiet.
Description check Passed The description is detailed and covers the user impact, mechanism, rationale, compatibility, testing, and checklist. The Linked Issue section is incomplete because it contains only "Fixes #" without a…
Full details: Description check

Explanation

The description is detailed and covers the user impact, mechanism, rationale, compatibility, testing, and checklist. The Linked Issue section is incomplete because it contains only "Fixes #" without an issue number, and the reported test results do not explicitly confirm the full checklist commands.

  • Fix all pre-merge checks with AI
✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@nwparker nwparker changed the title perf(watcher): flush file changes on a steady cadence instead of waiting for quiet fix(watcher): flush file changes on a steady cadence instead of waiting for quiet Oct 18, 2026
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.

@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


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 67e964ec-a0ca-46e1-b2bc-0c9db1061b28
📥 Commits

Reviewing files that changed from the base of the PR and between 2f482a0 and 01b3c56.

📒 Files selected for processing: 7
  • src/main/runtime/mobile-session-tabs-notify-coalescer.ts
  • src/renderer/src/components/right-sidebar/useFileExplorerWatch.ts
  • src/renderer/src/hooks/editor-external-watch-event-reconciliation.ts
  • src/renderer/src/hooks/useEditorExternalWatch-wsl-repro.test.ts
  • src/renderer/src/store/slices/restored-editor-owner-reparent.test.ts
  • src/shared/filesystem-watch-batch-window.test.ts
  • src/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.

@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


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4af17a68-e083-4ef7-b4ea-c6c08e250949
📥 Commits

Reviewing files that changed from the base of the PR and between 0b4a411 and 76e98b2.

⛔ Files ignored due to path filters: 1
  • src/shared/rpc-contract/rpc-params-catalog.generated.ts is excluded by !**/*.generated.*
📒 Files selected for processing: 18
  • src/main/runtime/files/watch/windows-file-watch.test.ts
  • src/main/runtime/files/watch/windows-file-watch.ts
  • src/main/runtime/orca-runtime-files-watch.test.ts
  • src/main/runtime/rpc/methods/file-watch-event-batcher.test.ts
  • src/main/runtime/rpc/methods/file-watch-event-batcher.ts
  • src/main/runtime/rpc/methods/file-watch-stream-lifecycle.ts
  • src/main/runtime/rpc/methods/files-watch-batch-cadence.test.ts
  • src/main/runtime/rpc/methods/files.ts
  • src/renderer/src/components/editor/editor-watcher-reload-coalescer.test.ts
  • src/renderer/src/components/editor/editor-watcher-reload-coalescer.ts
  • src/renderer/src/components/editor/use-markdown-document-watch-refresh.ts
  • src/renderer/src/components/editor/useEditorPanelExternalContentEvents.test.tsx
  • src/renderer/src/components/editor/useEditorPanelExternalContentEvents.ts
  • src/renderer/src/components/editor/useMarkdownDocuments.ts
  • src/renderer/src/components/editor/useMarkdownDocuments.watch.test.ts
  • src/renderer/src/runtime/runtime-file-client-watch.test.ts
  • src/renderer/src/runtime/runtime-file-watch-client.ts
  • src/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.
@nwparker
nwparker merged commit 5f126af into main Oct 19, 2026
49 checks passed
nwparker added a commit that referenced this pull request Oct 20, 2026
…rt stacks (#31216)

Fixes bugs found reviewing #30270, #30605, #30885, #30417, #31113, #30415,
#30992 and #30997, and removes code those PRs made unnecessary.

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