Skip to content

Prevent continuous git status scanning in large repositories - #8005

Merged
brennanb2025 merged 2 commits into
mainfrom
brennanb2025/7983
Jul 10, 2026
Merged

brennanb2025 merged 2 commits into
mainfrom
brennanb2025/7983

Conversation

@brennanb2025

Copy link
Copy Markdown
Contributor

Fixes #7983

What changes

On repositories where a background git status --untracked-files=all scan takes tens of seconds, Orca no longer restarts the next scan 3 seconds after the previous one finishes. The background poll now paces itself by how long the previous refresh actually took, so an idle workspace on a large monorepo drops from a near-continuous git process (~92% duty cycle) to roughly 1/6 duty, and the pacing is capped at 5 minutes so status can never go indefinitely stale.

Refresh triggers are split into two lanes in the coalesced poll runner:

  • Evidence-free timer ticks (the 3s/30s background poll) wait 5x the previous refresh duration before running again.
  • Change signals (file-watch events, repo metadata pushes, finished terminal commands, and the window becoming visible again) wait only 1x the previous duration, and can pull an already-scheduled tick run earlier. The strongest pending trigger wins for trailing reruns.

Additionally, a backoff-deferred scan that comes due while the window is hidden is skipped instead of burning tens of seconds of git work nobody can see; the becoming-visible run catches up on the short lane. The stale-conflict badge poll gets the same pacing, which also spaces slow remote SSH probe chains.

What does not change

  • Fast repos keep the exact 3-second refresh cadence: the duration multiplier never drops the gap below the existing floor.
  • User-triggered refreshes (Source Control actions, manual refresh) bypass the poll runner entirely and are unaffected.
  • No git arguments changed; --untracked-files=all output and sidebar behavior are identical.

Validation

  • New regression tests pin the fix: reverting coalesced-poll-runner.ts to HEAD fails 6 of 11 runner tests; all 27 tests across the runner, useGitStatusPolling, and window-visibility-interval pass with the fix. tsgo typecheck and oxlint clean.
  • Perf audit of the diff: no timer churn (O(1) compare per tick during a backoff window, at most one pending timeout), no leaks (dispose clears timer + trailing trigger, StrictMode-safe), and no code path runs git more often than before.
  • Live manual test on a 1.2M-file fixture repository where each clean scan takes ~12s, driven through the real app (project registered, worktree created, Source Control open):
    • Idle: scans of ~12s followed by ~58–63s gaps (5x duration) — previously the gap was a fixed 3s.
    • Change signal: after touching a tracked file, the next scan started 0.95s later and the file appeared in the Source Control panel.
    • Verified second-display behavior is preserved (visibility, not focus, gates polling).

Review

Two independent review passes (an architecture/state-machine lane and a reproduction lane that re-ran the tests against the reverted implementation) plus a dedicated performance audit returned no actionable findings.

On repos where `git status --untracked-files=all` takes tens of seconds,
the background status poll restarted a fresh scan 3s after the previous
one finished, keeping a git process at high CPU almost continuously
while the workspace sat idle (#7983).

The coalesced poll runner now paces reruns by the previous run's
duration, split by trigger class:

- Evidence-free timer ticks wait 5x the last refresh duration (capped
  at 5 minutes), bounding idle polling to ~1/6 duty cycle.
- Change signals (file-watch events, repo metadata pushes, finished
  terminal commands, window reveal after hidden) wait only 1x, so real
  changes in a slow repo still surface promptly; a change signal can
  pull an already-scheduled tick run earlier, and the strongest pending
  trigger wins for trailing reruns.
- Backoff-deferred scans are skipped while the window is hidden; the
  becoming-visible run catches up on the short lane.

Fast repos keep the exact 3s cadence (the multiplier never drops the
gap below the existing floor), and user-triggered refreshes are
unaffected (they bypass the poll runner). The stale-conflict poll gets
the same pacing, which also spaces slow remote SSH probe chains.

Fixes #7983
@coderabbitai

coderabbitai Bot commented Jul 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

Run ID: 93560a5c-c12f-4e5b-9c16-0f35110f247c

📥 Commits

Reviewing files that changed from the base of the PR and between 552b992 and 806c5be.

📒 Files selected for processing (1)
  • src/renderer/src/components/right-sidebar/useGitStatusPolling.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/renderer/src/components/right-sidebar/useGitStatusPolling.ts

📝 Walkthrough

Walkthrough

Coalesced polling now accepts trigger metadata and applies duration-based, capped backoff with separate timer and change-signal behavior. Visibility intervals can invoke a dedicated callback when the window becomes visible while retaining normal interval ticks. Git-status polling uses these capabilities to skip hidden-window work, route file-watch, push, visibility, and stale-conflict refreshes through change-signal triggers, and apply shared slow-task backoff settings. Tests cover scheduling, rescheduling, pacing, and visibility behavior.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers the behavior and validation, but it omits required template sections like Summary, Screenshots, AI Review Report, Security Audit, and Notes. Add the missing template sections: Summary, Screenshots, Testing checklist, AI Review Report, Security Audit, and Notes.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: reducing continuous git status scanning in large repositories.
Linked Issues check ✅ Passed The code backs off background git polling based on prior duration, keeps change signals responsive, and skips hidden-window scans, matching #7983.
Out of Scope Changes check ✅ Passed The added runner, polling, visibility, and tests all support the stated large-repo polling fix and do not appear unrelated.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ 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.

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/renderer/src/components/right-sidebar/useGitStatusPolling.ts (1)

231-267: 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Add visibility check to pollStale for consistency with runFetchStatus.

runFetchStatus early-returns when !isWindowVisible() to skip backoff-deferred runs that fire after the window hides. pollStale lacks this guard. A trailing run from the coalesced runner can fire while hidden (e.g., interval tick captured mid-flight → window hides → task completes → trailing timeout fires), executing getRuntimeGitConflictOperation SSH/RPC work nobody can see. The PR objective states hidden-window backoff scans should be skipped.

🛡️ Proposed fix
     const pollStale = async (): Promise<void> => {
+      // Why: a backoff-deferred run can fire long after the window hides; skip
+      // the probe instead of running SSH/RPC work nobody can see. The
+      // becoming-visible run catches up via the change-signal lane.
+      if (!isWindowVisible()) {
+        return
+      }
       for (const { id, path } of staleConflictWorktrees) {

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: bdb25978-e3f4-44b4-97be-44269968c68f

📥 Commits

Reviewing files that changed from the base of the PR and between 5662bf4 and 552b992.

📒 Files selected for processing (5)
  • src/renderer/src/components/right-sidebar/coalesced-poll-runner.test.ts
  • src/renderer/src/components/right-sidebar/coalesced-poll-runner.ts
  • src/renderer/src/components/right-sidebar/useGitStatusPolling.ts
  • src/renderer/src/lib/window-visibility-interval.test.ts
  • src/renderer/src/lib/window-visibility-interval.ts

@brennanb2025
brennanb2025 merged commit feac6a5 into main Jul 10, 2026
2 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…i#8005)

* Prevent continuous git status scanning in large repositories

On repos where `git status --untracked-files=all` takes tens of seconds,
the background status poll restarted a fresh scan 3s after the previous
one finished, keeping a git process at high CPU almost continuously
while the workspace sat idle (stablyai#7983).

The coalesced poll runner now paces reruns by the previous run's
duration, split by trigger class:

- Evidence-free timer ticks wait 5x the last refresh duration (capped
  at 5 minutes), bounding idle polling to ~1/6 duty cycle.
- Change signals (file-watch events, repo metadata pushes, finished
  terminal commands, window reveal after hidden) wait only 1x, so real
  changes in a slow repo still surface promptly; a change signal can
  pull an already-scheduled tick run earlier, and the strongest pending
  trigger wins for trailing reruns.
- Backoff-deferred scans are skipped while the window is hidden; the
  becoming-visible run catches up on the short lane.

Fast repos keep the exact 3s cadence (the multiplier never drops the
gap below the existing floor), and user-triggered refreshes are
unaffected (they bypass the poll runner). The stale-conflict poll gets
the same pacing, which also spaces slow remote SSH probe chains.

Fixes stablyai#7983

* Skip hidden-window stale-conflict probes like the status poll

---------

Co-authored-by: Brennan Benson <[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.

[Bug]: Continuous full-untracked Git polling consumes CPU in large monorepos on v1.4.130

1 participant