Skip to content

perf(renderer): cap remote project refresh concurrency - #13631

Closed
nwparker wants to merge 1 commit into
mainfrom
nwparker/perf-cap-runtime-project-refreshes
Closed

nwparker wants to merge 1 commit into
mainfrom
nwparker/perf-cap-runtime-project-refreshes

Conversation

@nwparker

@nwparker nwparker commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 +492 0 +492
Prod 2 +130 −12 +118

Summary

  • cap event-driven runtime project refreshes at two environments globally
  • reserve one slot for the currently viewed workspace host, with the configured active server as fallback
  • keep background hosts FIFO, coalesce duplicate events, and drop removed hosts before admission
  • wake priority changes without starting extra refreshes or changing debounce/throttle behavior

ELI5

Before, every remote Orca server could open five project-scanning lanes at the same time. Adding more saved hosts added more lanes, so ten hosts could produce up to fifty concurrent worktree scans from this path. That matches the observation that deleting remote hosts made the slowdown disappear.

Now all remote servers share one traffic controller. At most two hosts refresh at once, so this path tops out at ten worktree scans, and one host slot stays available for the workspace currently on screen. Repeated notifications from the same host collapse into one refresh instead of cutting the line repeatedly.

Scope

This caps the runtime client event, reconnect, and reachability project-refresh path. It does not claim to cap every all-host loader in the app. There are no RPC or remote wire changes.

Correctness notes

  • foreground priority follows explicit workspace ownership, including folder workspaces and nested SSH, then falls back to the configured active runtime
  • focus changes reclassify in-flight hosts dynamically so an old foreground host cannot consume the reserved lane as hidden background work
  • a newly focused host runs next when a real in-flight promise settles; permits are not released early because the underlying RPC work is not cancellable
  • per-environment debounce, minimum interval, and five-worktree worker cap remain intact

Validation

  • 118 focused scheduler and useIpcEvents tests passed
  • full suite: 49,273 passed, 99 skipped
  • pnpm typecheck
  • pnpm lint, including code-quality and max-lines gates
  • pnpm build:electron-vite
  • adversarial concurrency, integration, liveness, and test-gap reviews: no P0-P2 findings

Triage review (2026-08-15)

Status: MERGEABLE / clean, all checks green. Held pending owner decision.

Perf impact if merged Real, and likely the largest win in this batch. Before: every remote Orca server could open 5 project-scanning lanes at once, so 10 saved hosts could produce up to 50 concurrent worktree scans from this path. This matches the reported observation that deleting remote hosts made the slowdown disappear. After: 3 total lanes (1 reserved foreground + 2 background).
User-facing trade-off Yes, mild. Background host discovery is now serialized 2-at-a-time, so with many saved hosts a background host's worktree list refreshes later than it does today. The foreground workspace is protected by the reserved lane and never queues behind background work.
Resolvable? No — the serialization is the fix. The tunable part is the lane math, which has been corrected (see below).

Lane math correction

An earlier revision made the foreground reservation dynamic (hold a lane only while the prioritized host has pending work). The existing reclassifies the old foreground before admitting more background work test correctly rejected it: if the foreground switches before the new host requests, background fills both lanes and the foreground then queues behind an un-preemptable refresh — exactly what the reservation exists to prevent.

The shipped fix instead raises the cap from 2 to 3. A cap of 2 left exactly one background lane once the reserved slot was subtracted, which serialized host discovery entirely.

Residual risk

Workspaces with a large number of saved remote hosts will see background worktree lists settle more slowly than today. No correctness impact; foreground latency improves.

@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: e36106db-4106-429c-9e65-6e23aab3790f

📥 Commits

Reviewing files that changed from the base of the PR and between 5b7f442 and 6fbd59b.

📒 Files selected for processing (4)
  • src/renderer/src/hooks/runtime-project-refresh-scheduler.test.ts
  • src/renderer/src/hooks/runtime-project-refresh-scheduler.ts
  • src/renderer/src/hooks/useIpcEvents-runtime-project-refresh-priority.test.ts
  • src/renderer/src/hooks/useIpcEvents.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/renderer/src/hooks/useIpcEvents.ts
  • src/renderer/src/hooks/runtime-project-refresh-scheduler.test.ts
  • src/renderer/src/hooks/runtime-project-refresh-scheduler.ts

📝 Walkthrough

Walkthrough

The runtime refresh scheduler now uses bounded queues with FIFO admission, foreground prioritization, request coalescing, desired-environment filtering, failure recovery, and shutdown cleanup. Worktree and environment refreshes use separate concurrency defaults. The scheduler exposes reprioritize. useIpcEvents selects the prioritized runtime environment and triggers reprioritization when relevant workspace state changes. Tests cover scheduler behavior and workspace-driven reprioritization.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The description explains the change and validation, but it omits required template sections, including Linked Issue, Visual Proof, Testing checklist, and Checklist. Add the required template sections, include a linked issue, provide visual proof or N/A with a reason, and complete the testing and checklist items.
✅ Passed checks (3 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 and concisely describes the main change: limiting remote project refresh concurrency.
✨ Finishing Touches 💡 1
📝 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 force-pushed the nwparker/perf-cap-runtime-project-refreshes branch from f5a290d to 6fbd59b Compare August 15, 2026 09:57
@coderabbitai

coderabbitai Bot commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@nwparker

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (now MERGEABLE) and fixed the lane math.

The bug: maxConcurrentNonPriorityRefreshes = maxConcurrentRefreshes - 1 with a default cap of 2 left exactly one background lane, not the two this PR's description claims. The reserved foreground slot is never lent out, so whenever the viewed workspace's host had nothing queued — the steady state — the second slot sat idle and host discovery serialized to one host at a time. With 10 saved hosts and a couple unreachable, the sidebar would populate one host per ~30s timeout instead of concurrently.

I first tried making the reservation dynamic (hold a lane only while the prioritized host has work pending). That was wrong and the existing reclassifies the old foreground before admitting more background work test caught it: when the foreground switches before the new host requests, background fills both lanes and the subsequent foreground request queues behind a refresh that cannot be preempted — exactly what the reservation exists to prevent.

The fix is the cap, not the reservation: default concurrency 2 → 3. One reserved foreground lane plus two real background lanes, matching the documented intent. Peak fanout is still bounded (3 hosts), versus the unbounded N×~7 on main.

Two new tests, both verified non-vacuous (they fail at cap=2, pass at cap=3):

  • runs two background hosts concurrently beside the reserved foreground lane
  • still admits the foreground host while both background lanes are busy

The five existing tests that assert reservation semantics now pin maxConcurrentRefreshes: 2 explicitly so they test the algorithm rather than the default constant.

Also carried across #14728's test split: the reprioritize test moved to useIpcEvents-runtime-project-refresh-priority.test.ts, and a stale expectation was updated for the suppressRemoteLineageRefresh option main added since.

Verified: 739 tests pass across src/renderer/src/hooks, all tsconfigs clean, max-lines ratchet passes.

Bound cross-host runtime project refreshes behind a scheduler with a reserved
lane for the foreground workspace, so N remote hosts no longer fan out N x ~7
concurrent RPCs on startup and reconnect.

Sets the cap to 3 rather than 2: the reserved foreground slot is never lent
out, so a cap of 2 left exactly one background lane and serialized host
discovery. Tests that assert reservation semantics pin the cap explicitly.

Lease tests moved to a focused file after #14728 split useIpcEvents.test.ts.
@nwparker

Copy link
Copy Markdown
Contributor Author

Closing: conflicts with main, which deliberately raised connect concurrency to 15. The cap delays background hosts' data with no measured win.

@nwparker nwparker closed this Oct 14, 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