Repository navigation
fix(scm): keep git-status pacing across scheduler rebuilds - #11820
brennanb2025 merged 2 commits into
Conversation
📝 WalkthroughWalkthroughGit status refresh scheduling now supports shared pacing state with completion timestamps and run durations. Polling stores pacing per worktree ID and path and reuses it when scheduler instances rebuild. Activity-floor and slow-scan backoff calculations use the shared state. Tests cover scheduler recreation, execution-host changes, stale and aborted runs, the three-second activity floor, and 30-second slow-scan backoff. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 8030d607-a272-4ac6-a1a8-c4ba617c39a3
📒 Files selected for processing (4)
src/renderer/src/components/right-sidebar/git-status-refresh-scheduler.test.tssrc/renderer/src/components/right-sidebar/git-status-refresh-scheduler.tssrc/renderer/src/components/right-sidebar/useGitStatusPolling.rerender.test.tssrc/renderer/src/components/right-sidebar/useGitStatusPolling.ts
Greptile SummaryThis PR fixes a git-status refresh storm (150–283 spawns/min vs a normal 26–35/min) triggered when a remote/mobile runtime client is attached while agents are active. The root cause was that scheduler pacing state was closure-local: every execution-host or push-target change that rebuilt the scheduler reset
Confidence Score: 5/5Safe to merge. The change is purely additive renderer-side TypeScript — no IPC, shell, or persistence paths touched — and the fix is tightly scoped to pacing continuity across scheduler rebuilds. The root cause is clearly identified and the fix is minimal: two closure-local variables are promoted to a shared object, with a monotone run-ID guard to prevent late-finishing disposed runs from corrupting the shared state. All existing scheduler contracts (generation bump, in-flight abort, trailing-refresh, aborted-scan zero-duration rule) remain intact and verified by the pre-existing test suite. The three new unit tests and one integration test directly reproduce the storm shape and the two cross-rebuild invariants. No behavioral change occurs outside of the specific host-flapping and push-target-change paths. Files Needing Attention: No files require special attention. The core logic change in git-status-refresh-scheduler.ts is small and well-covered by tests.
|
| Filename | Overview |
|---|---|
| src/renderer/src/components/right-sidebar/git-status-refresh-scheduler.ts | Introduces GitStatusRefreshPacing as a shareable value object; replaces two closure-local pacing variables with a reference to it; adds runId ordering to prevent stale finally-callbacks from corrupting shared state. Logic is correct and all edge cases are covered by new tests. |
| src/renderer/src/components/right-sidebar/useGitStatusPolling.ts | Adds statusPacingRef to cache one pacing object per active worktree key; correctly excludes executionHostId and pushTarget from the cache key so host/push flaps reuse pacing while worktree switches start fresh. Integration with the scheduler effect is clean. |
| src/renderer/src/components/right-sidebar/git-status-refresh-scheduler.test.ts | Adds four new unit tests exercising floor preservation, slow-scan backoff continuity, out-of-order late-finishing runs, and repeated rebuild pacing. Tests correctly use fake timers and the deferred helper pattern. |
| src/renderer/src/components/right-sidebar/useGitStatusPolling.rerender.test.ts | Adds the integration regression test for host-ID flapping (the exact storm shape from the report) and extends the worktree-switch test to verify immediate refresh on back-navigation. Both additions directly cover the regressed behaviors. |
Sequence Diagram
sequenceDiagram
participant Hook as useGitStatusPolling
participant PacingRef as statusPacingRef (worktree-keyed)
participant S1 as Scheduler (host=local)
participant S2 as Scheduler (host=runtime:env-2)
participant S3 as Scheduler (host=local, rebuilt)
Hook->>PacingRef: create pacing for worktree A
Hook->>S1: createGitStatusRefreshScheduler(pacing)
S1->>S1: "resumeSafety() → startRun(runId=1)"
S1->>PacingRef: "lastRunEndedAt=T, lastRunDurationMs=D"
Note over Hook: host flaps to runtime:env-2
Hook->>S1: dispose() [aborts in-flight]
Hook->>PacingRef: key matches → reuse pacing
Hook->>S2: createGitStatusRefreshScheduler(pacing)
S2->>S2: "resumeSafety() → delay = max(0, T+3000−now) ≈ 3s"
Note over Hook: host flaps back to local
Hook->>S2: dispose() [aborts in-flight]
Hook->>PacingRef: key matches → reuse pacing
Hook->>S3: createGitStatusRefreshScheduler(pacing)
S3->>S3: resumeSafety() → floor still ~3s
Note over Hook: worktree switches to B
Hook->>PacingRef: new key → fresh pacing(-Infinity)
Hook->>S3: dispose()
Hook->>Hook: Scheduler for worktree B gets instant refresh
Reviews (2): Last reviewed commit: "fix(scm): order shared refresh pacing up..." | Re-trigger Greptile
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/renderer/src/components/right-sidebar/git-status-refresh-scheduler.ts (1)
160-163: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueShorten the cancellation comment.
Lines 160-163 explain implementation details across four lines. Keep only the non-obvious policy rationale in one concise line.
As per coding guidelines, comments must be concise, limited to non-obvious information, and preferably one line.
Proposed change
- // Why: cancelled scans never delivered a useful result, so their wall - // time must not stretch the next activity/safety gap. Otherwise hide → - // reveal after a slow abort waits out the aborted scan's full duration - // before the catch-up refresh can start. + // Cancelled scans do not extend the next refresh gap.Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: d8c78a95-5462-47fe-b13d-8b7c651f948a
📒 Files selected for processing (4)
src/renderer/src/components/right-sidebar/git-status-refresh-scheduler.test.tssrc/renderer/src/components/right-sidebar/git-status-refresh-scheduler.tssrc/renderer/src/components/right-sidebar/useGitStatusPolling.rerender.test.tssrc/renderer/src/components/right-sidebar/useGitStatusPolling.ts
🚧 Files skipped from review as they are similar to previous changes (2)
- src/renderer/src/components/right-sidebar/useGitStatusPolling.ts
- src/renderer/src/components/right-sidebar/git-status-refresh-scheduler.test.ts
Review + Electron QAA same-model/same-reasoning review found and fixed two PR-scope issues in
Verification:
The deterministic call-count/timing tests are the primary regression evidence for this nonvisual scheduler fix; the uncropped screenshot is visible app proof after the live interaction. Mobile emulator QA was not applicable: this PR changes only the desktop renderer scheduler/hook and tests, with no mobile UI or mobile package changes. |
…11820) * fix(scm): keep git-status pacing across scheduler rebuilds * fix(scm): order shared refresh pacing updates

Summary
Fixes the git-status refresh storm that makes the app lag badly (typing latency, renderer pegged at 100-160% CPU) when a remote/mobile runtime client is attached while agents are active.
Root cause: #11346 added
activeExecutionHostIdto the git-status scheduler effect's dependency array inuseGitStatusPolling. The rebuild on host change is intentional (generation bump + in-flight abort), but the scheduler's pacing state (lastRunEndedAt,lastRunDurationMs) was closure-local, so every rebuild reset it to-Infinity. With a connected runtime client the resolved host id flaps (local vsruntime:<env>publications overwrite each other in the repoId-keyed store), each flap minted an unthrottled scheduler, and the pre-existing loop (git status rewrites.git/worktrees/<n>/index→ 2s base-directory poller → status signal) then ran at the bare 125ms debounce instead of the 3s floor + slow-task backoff (#7983).Measured on the affected machine (1.4.163-rc.3, live trace spans): git spawn rate jumped from 26-35/min (rc.1, same workload) to a sustained 150-283/min, full 5-command status cycles every 1-3s per busy worktree, renderer main thread ~73% busy.
Fix (two commits):
6eece0b41e: pacing becomes a shareable object (GitStatusRefreshPacing) owned by the hook and keyed to the current worktree, surviving scheduler rebuilds. Host/push-target changes still dispose the scheduler, abort in-flight scans, and bump the generation — they just no longer forget how recently git ran. Worktree switches keep their instant refresh (fresh pacing per worktree).1414b6a239: hardening — run-id ordering so a stale run from a disposed scheduler that settles late cannot stamp pacing over a newer run's result, and the hook holds a single current-worktree pacing slot instead of an unbounded map.Empirical A/B validation
Beyond unit tests, the mechanism and fix were validated in a live dev app with real git subprocesses: two instances from pinned commits differing only by this fix (
cd2b62ed14= main/broken vs6eece0b41e= main+fix), isolatedORCA_DEV_USER_DATA_PATHprofiles, a fixture repo with 500ms file churn, Source Control active, then a scheduler-dep flip injected every 1s via the exposed store (same dependency array and rebuild path as the production host-id flap). Git spawns measured from each profile'smain.trace.ndjson:cd2b62ed14(broken)6eece0b41e(fix)Baselines are identical, so the fix changes nothing in normal operation; under the storm input, the broken build runs status at the flap rate while the fix build holds the floor.
Screenshots
No visual change.
Testing
pnpm lintpnpm typecheckpnpm test(targeted suites run locally; full suite left to CI)pnpm build(left to CI)Targeted runs (all green):
git-status-refresh-scheduler.test.ts,useGitStatusPolling.rerender.test.ts,useGitStatusPolling.test.ts.New regression coverage:
Plus the live A/B above as end-to-end validation.
AI Review Report
Reviewed the change against the scheduler's correctness contracts:
pacingoption is optional; the only factory consumer isuseGitStatusPolling, and omitting it reproduces the old per-instance behavior.Cross-platform: renderer-only TypeScript using timers and in-memory state — no shortcuts, labels, paths, shell, or Electron platform APIs touched; behavior identical on macOS/Linux/Windows. Applies equally to SSH-hosted and folder workspaces since the pacing key is the worktree id + path already used by the scheduler effect.
Security Audit
No input handling, command execution, path construction, auth, secrets, dependency, or IPC changes. The pacing key is built from in-app worktree id/path values and stays in renderer memory; nothing is persisted or transmitted.
Notes
setActiveWorktreecall sites clearactiveWorkspaceExecutionHostIdby omitting the new argument — making it sticky would reduce host-id flapping at the source; (2)detectedWorktreesByRepois keyed by repoId alone, so local and runtime publications of the same repo overwrite each other.active/post-pushreasons, which multipliedghspawns during the storm (~50-100/min). Also a candidate for its own PR.v1.4.163-rc.3(landed between rc.1 and rc.3); it is not in stable v1.4.162. Recommend landing this before promoting 1.4.163 to stable.