Skip to content

[Perf-LH] Stop re-probing ordinary workspace folders every poll - #13437

Merged
nwparker merged 1 commit into
mainfrom
nwparker/perf-28-marker-cooldown
Aug 10, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/perf-28-marker-cooldown

Conversation

@nwparker

Copy link
Copy Markdown
Contributor

Summary

This PR stops Orca from repeatedly asking the operating system whether long-lived ordinary workspace folders contain a .git marker.

A .git marker is the file or directory Git puts at the root of a repository or worktree. Orca watches for that marker so it can notice worktrees created outside the app.

The poller already had two intended modes:

  1. Fast window: check a newly seen marker-less directory every visible poll cycle for up to 300 cycles. At the production two-second interval, that is about ten minutes.
  2. Backstop: after the fast window, rely on the existing full scan every 15 visible poll cycles, or about every 30 seconds.

The bug was that each full scan forgot which directories had already exhausted the fast window. It removed an expired directory from the pending map, then a later full scan saw the same marker-less directory and added it back as “new.” In steady state, ordinary folders therefore received .git filesystem probes on 95.33% of visible poll cycles.

New state transitions

What Orca observes State kept by the poller What happens next
A new directory without .git First fast-probe tick Probe <directory>/.git on non-backstop cycles
The directory exceeds the fast window null (“backstop only”) Stop individual probes; periodic full scans still inspect it
A full scan finds .git No marker-probe state Emit the same worktree-create event as before
A full scan observes that the directory disappeared No marker-probe state A later directory at the same path gets a fresh fast window

The implementation uses one map instead of a pending map plus a second collection. A numeric value means “still in the fast window”; null means “only inspect this path during a full backstop scan.”

The regression test covers all three important behaviors:

  • stale probes actually stop;
  • a .git marker created much later is still detected by a backstop scan;
  • after an expired path is deleted and recreated, it gets fast probes again.

Benchmark

Harness:

node config/scripts/worktree-base-pending-marker-benchmark.mjs

The harness imports the real production poller, creates 64 ordinary directories with no .git marker, accelerates the poll interval to zero, and records real calls to fs.promises.stat for those 64 marker paths. It runs 900 visible poll cycles and treats the final 300 as the steady-state window.

Both arms used the same harness and fixture. The only switched input was the poller implementation:

  • Before: base commit f3ea376b6b26, poller blob 2f65e0fc28219488aeeb385f49532f4475553b3b
  • After: this PR, poller blob b5076c2ed7ffe326a5286af327c4a960e0b24ecf
Metric (lower is better) Before After Reduction
Total .git marker stats across 900 cycles 55,872 21,824 60.9%
Steady-state marker stats across final 300 cycles 18,304 1,280 93.0%
Steady stats per candidate per cycle 0.9533 0.0667 93.0%

The after value, 0.0667, is the expected backstop floor: one full scan every 15 cycles. The total-run reduction is smaller because the benchmark intentionally includes the initial fast-probe window.

The benchmark also prints elapsed wall time as a diagnostic, but this PR does not claim a wall-time speedup from that number. A zero-delay timer is useful for reproducing syscall counts quickly, but its scheduling overhead is not representative of the production two-second cadence. The deterministic filesystem-operation count is the performance claim.

Screenshots

No visual change.

Testing

  • pnpm lint — full repository lint was not run; pnpm run check:code-quality:changed passed with 0 new standard, type-aware, or React Doctor findings across all 3 changed files.
  • pnpm typecheck — the affected Node target passed with pnpm run typecheck:node; CLI and web targets are untouched.
  • pnpm test — the complete repository suite was not run; the detected-worktree reliability group passed 177/177 tests across 7 files.
  • pnpm build — not run; this does not change packaging, native modules, renderer code, or build configuration.
  • Added a regression test that fails if expired paths resume fast probing, if late marker discovery is lost, or if delete/recreate path reuse stays in cooldown.

Additional checks:

  • Focused poller suite: 22/22 passed.
  • New cooldown test: passed five repeated runs during independent review.
  • pnpm run check:max-lines-ratchet: passed with no new bypasses.
  • pnpm run check:reliability-gates: reliability manifest passed for all 73 gates.
  • git diff --check: passed.
  • Benchmark reruns reproduced exactly 21,824 total stats, 1,280 steady stats, and 0.0667 steady stats per candidate per cycle.

AI Review Report

The final review traced each marker state from initial discovery through expiry, periodic scanning, marker creation, deletion, recreation, hidden-window parking, and unsubscribe cleanup.

The first review found that the initial two-collection implementation pushed the production file over the repository’s 300-line limit. No lint disable or limit increase was added. The implementation was simplified to one nullable map, and the max-lines gate now passes.

The review also flagged that a test using the production 300-cycle cooldown would need roughly 660 zero-delay timer turns and could be slower on heavily loaded Windows CI. The test now uses an explicit test-only 30-cycle window while production keeps the unchanged 300-cycle value. It exercises the same expiry and backstop boundaries in fewer timer turns.

A final independent review found no remaining actionable issues. It explicitly checked:

  • expiry at the exact tick boundary;
  • full scans not reactivating expired entries;
  • late .git discovery;
  • observed delete/recreate state reset;
  • stale state and partial filesystem failures;
  • overlapping poll prevention and unsubscribe cleanup;
  • macOS, Linux, and Windows path handling;
  • local, SSH, WSL UNC, and folder-workspace routing;
  • remote-wire and Git-command compatibility.

No keyboard shortcut, shortcut label, shell invocation, or Electron platform-specific behavior changed. Existing path.join handling remains the only path construction used for marker paths.

Security Audit

This is a reduction in existing filesystem reads and does not add a new authority boundary.

  • Input handling: no new user-controlled input is parsed. The new options are test hooks used by the regression suite.
  • Filesystem access: the code checks the same <candidate>/.git paths as before, using the existing path.join and stat functions. It performs fewer checks after cooldown.
  • Commands and shells: no commands, shell arguments, or Git invocations were added or changed.
  • IPC and remote wire: no RPC parameter, event, stream opcode, serialization, or persisted format changed.
  • Authentication and secrets: untouched.
  • Dependencies: no dependency or lockfile change.
  • Failure behavior: filesystem misses and transient stat failures retain the existing retry/backstop behavior.

No security follow-up is required.

Notes

The deliberate tradeoff is narrow: if a directory has remained marker-less beyond the roughly ten-minute fast window and someone later adds .git inside that same still-existing directory, detection can take until the next full scan—up to roughly 30 seconds while the window is visible—instead of the next two-second fast poll. Normal worktree creation is unaffected because Git creates the marker during directory creation, well inside the fast window. If the old directory is observed disappearing first, recreating that path starts a fresh fast window.

Scope is intentionally limited:

  • local non-folder repository base targets use this poller;
  • SSH targets continue to use provider.watch;
  • WSL UNC roots continue to be skipped;
  • folder workspaces continue to be skipped;
  • git-common targets continue to use their separate watcher;
  • no GitHub-, GitLab-, or other review-provider behavior changed.

@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: decb3d9a-45b1-4be6-bcac-568713eb54f9

📥 Commits

Reviewing files that changed from the base of the PR and between a3ca887 and f30b768.

📒 Files selected for processing (3)
  • config/scripts/worktree-base-pending-marker-benchmark.mjs
  • src/main/ipc/worktree-base-directory-poller.test.ts
  • src/main/ipc/worktree-base-directory-poller.ts

📝 Walkthrough

Walkthrough

The worktree base poller now supports configurable pending .git marker probing. It tracks probe expiration, performs backstop full scans, and exposes probe observation hooks. New integration coverage tests delayed detection, candidate deletion and recreation, probe retirement, and duplicate-event prevention. A benchmark script measures marker stat calls and elapsed time while cleaning up temporary resources.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main performance change: stopping repeated probes of ordinary workspace folders.
Description check ✅ Passed The description includes all required sections and provides detailed scope, testing results, review findings, security analysis, and platform notes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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
📝 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.

@nwparker
nwparker merged commit 8859e73 into main Aug 10, 2026
45 checks passed
@nwparker
nwparker deleted the nwparker/perf-28-marker-cooldown branch August 10, 2026 05: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.

1 participant