Skip to content

Reduce idle git status polling - #7069

Merged
nwparker merged 1 commit into
mainfrom
nwparker/energy-impact
Jul 2, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/energy-impact

Conversation

@nwparker

@nwparker nwparker commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

Orca was asking Git for status every 3 seconds even in cases where the user was only sitting in a terminal and no UI surface was actively showing git status. This changes Orca to keep the fast 3-second refresh when Source Control, Explorer, Checks, or open files need it, but slow down the terminal-only fallback to 30 seconds. If the active worktree cannot be polled anyway, such as disconnected SSH or huge-status pause, Orca now avoids installing the timer at all.

Why

While investigating high Energy Impact, live process snapshots and diagnostics showed repeated git/status-related subprocess churn alongside renderer/GPU terminal cost. This PR removes a low-value fixed polling loop without changing the fast path for visible git UI.

What changed

  • Split "interactive git status consumer" from "should poll at all".
  • Keep 3s active git status polling when Source Control, Explorer file view, Checks, or open files are consuming status.
  • Use a 30s cadence for terminal-only branch-detection fallback.
  • Do not install the active status interval when polling would immediately no-op, such as disconnected SSH, non-git repos, huge-status pause, disabled polling, or privacy-suppressed macOS app data paths.

Tradeoffs and user degradation

Expected degradation is effectively zero for normal visible status workflows.

  • Source Control / Explorer / Checks visible: no degradation. Still uses the 3s cadence and runs immediately when the surface becomes relevant.
  • Open files in the active worktree: no degradation. Still uses the 3s cadence.
  • File changes in the active worktree: no degradation expected. File-watch refreshes still nudge status directly and are coalesced.
  • Active worktree switch: no degradation. The rerender test verifies the new worktree still polls immediately.
  • Disconnected SSH: improvement, not degradation. The old interval woke up just to discover it should do nothing.
  • Terminal-only branch changes: possible small degradation. If a user changes branches inside a terminal while Source Control/Explorer/Checks are closed and no file from that worktree is open, sidebar branch/status metadata may take up to 30s to update instead of up to 3s. This is the intended tradeoff: there is no active status consumer in that state, and opening a status-consuming surface restores the fast path.
  • Terminal rendering/GPU energy: not directly fixed here. I inspected the terminal repaint guards, but they protect tested WebGL/grid correctness paths and need a dedicated perf repro before changing.

Verification

  • pnpm exec vitest run --config config/vitest.config.ts src/renderer/src/components/right-sidebar/useGitStatusPolling.test.ts src/renderer/src/components/right-sidebar/useGitStatusPolling.rerender.test.ts src/renderer/src/lib/passive-macos-app-data-access.test.ts
  • pnpm run typecheck:web
  • pnpm exec oxlint src/renderer/src/components/right-sidebar/useGitStatusPolling.ts src/renderer/src/components/right-sidebar/useGitStatusPolling.test.ts src/renderer/src/lib/passive-macos-app-data-access.ts
  • git diff --check

Open in Stage

@ghost

ghost commented Jul 2, 2026

Copy link
Copy Markdown

Ready to review this PR? Stage has broken it down into 3 individual chapters for you:

Title
1 Define interactive git status consumer logic
2 Implement dual-cadence polling in useGitStatusPolling
3 Verify slower terminal-only polling cadence
Open in Stage

Chapters generated by Stage for commit 7661715 on Jul 2, 2026 5:01am UTC.

@coderabbitai

coderabbitai Bot commented Jul 2, 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: 6bd24d71-84e5-49b2-ba70-fbd73bc490e5

📥 Commits

Reviewing files that changed from the base of the PR and between 4dbc9f3 and 7661715.

📒 Files selected for processing (3)
  • src/renderer/src/components/right-sidebar/useGitStatusPolling.test.ts
  • src/renderer/src/components/right-sidebar/useGitStatusPolling.ts
  • src/renderer/src/lib/passive-macos-app-data-access.ts

📝 Walkthrough

Walkthrough

This change refactors git status polling logic to distinguish between interactive UI consumers and background terminal-only usage. A new shared function, hasInteractiveActiveGitStatusConsumer, is extracted and used by both shouldPollActiveGitStatus and a new precomputed eligibility flag in useGitStatusPolling. Polling cadence now varies: a minimum refresh interval (3s) for active/interactive polling and a slower terminal-only interval (30s) otherwise, replacing a single fixed interval. The hook's fetch guard logic and visibility-driven interval installation were simplified accordingly. Tests were extended with a stateOverrides option and new/updated assertions covering the SSH-disconnected and terminal-only polling scenarios.

Changes

Cohort / File(s) Summary
Interactive consumer extraction — src/renderer/src/lib/passive-macos-app-data-access.ts Adds ActiveGitStatusPollingArgs type and exported hasInteractiveActiveGitStatusConsumer function; refactors shouldPollActiveGitStatus to delegate to it.
Polling cadence rework — src/renderer/src/components/right-sidebar/useGitStatusPolling.ts Introduces MIN_STATUS_REFRESH_INTERVAL_MS and terminal-only interval constants; precomputes shouldPollActiveWorktreeGitStatus and activeStatusPollIntervalMs; simplifies runFetchStatus guard; updates coalesced runner, visibility-driven interval installation, and stale-conflict polling to use new interval logic.
Test coverage — src/renderer/src/components/right-sidebar/useGitStatusPolling.test.ts Adds stateOverrides option to usePollingOnce harness; asserts no interval scheduling in SSH-disconnected scenario; adds test for 30s cadence when sidebar is closed.

Sequence Diagram(s)

sequenceDiagram
  participant Hook as useGitStatusPolling
  participant Predicate as hasInteractiveActiveGitStatusConsumer
  participant Runner as runFetchStatus
  participant Interval as setInterval

  Hook->>Predicate: evaluate(rightSidebarOpen, openFiles, userAgent)
  Predicate-->>Hook: interactive boolean
  Hook->>Hook: compute shouldPollActiveWorktreeGitStatus
  Hook->>Hook: select activeStatusPollIntervalMs (3s or 30s)
  Hook->>Runner: guard on shouldPollActiveWorktreeGitStatus
  Runner-->>Hook: gitStatus fetched or skipped
  Hook->>Interval: install with activeStatusPollIntervalMs (if activeStatusPollScope)
Loading

Related PRs: None specified.

Suggested labels: refactor, polling, renderer

Suggested reviewers: None specified.

Poem:
A rabbit hops through polling code,
Choosing fast or slow the road—
Three seconds when eyes are near,
Thirty when the sidebar's clear.
Tests confirm each ticking beat,
Hop, hop, cadence now complete! 🐇⏱️

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers the change, but it does not follow the required template or include the required Summary, Screenshots, Testing, AI Review Report, Security Audit, and Notes sections. Rewrite the PR description to use the template headings and add the missing sections, including screenshot status, testing checklist, AI review, security audit, and notes.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: reducing idle git status polling.
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.

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