Skip to content

Add a per-call background lane for event-driven project refresh - #6160

Closed
audichuang wants to merge 1 commit into
stablyai:mainfrom
audichuang:feat/runtime-rpc-background-lane
Closed

audichuang wants to merge 1 commit into
stablyai:mainfrom
audichuang:feat/runtime-rpc-background-lane

Conversation

@audichuang

@audichuang audichuang commented Jun 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Runtime RPC calls are sorted onto a foreground/background lane by method name
(isBackgroundRuntimeMethod). The event-driven project refresh fired by
server-pushed client events — reposChanged fanning out to repos, worktrees,
and lineage, and worktreesChanged refreshing worktrees, lineage, and (for an
unknown repo) discovery — fires methods (repo.list, project.list,
worktree.detectedList, worktree.lineageList) that are not on that list,
so the refresh storm lands on the foreground lane and competes with
user-initiated calls for transport capacity. With several remote servers
connected this is a visible jank source on every remote event.

This adds a per-call background override that flows end-to-end through the RPC
call queue → main call routing → renderer/preload/web call paths → renderer
fetch helpers. The queue keeps the existing method-name classification as the
default and lets a call site opt in:

background: options?.background ?? isBackgroundRuntimeMethod(method)

Both server-pushed refresh paths are then routed through it:

  • the runtimeProjectRefreshScheduler refresh for reposChanged (repos +
    worktrees + best-effort lineage), and
  • the worktreesChanged refresh (worktrees + lineage, plus its
    ensureRuntimeEventRepoKnown repo discovery) — the same runtime.clientEvents
    stream, treated symmetrically.

No change to what is refreshed — only which lane, so the all-host
project model still refreshes every connected environment exactly as before.

Screenshots

No visual change.

Testing

Rebased onto latest origin/main (v1.4.98-rc.1); the rebase is clean (no conflicts).

  • pnpm lint — clean (oxlint type-aware + localization catalog/parity all pass)
  • pnpm typecheck — green (3 tsgo projects)
  • pnpm test — full suite on the rebased base: 20735 passed, 23 failed,
    75 skipped
    . All 23 failures are pre-existing and live in files this PR does
    not touch (verified zero overlap with the changed file set — git-handler,
    omp-shell-wrapper, automation-schedules, pr-comment localStorage,
    Linear/SidebarToolbar, hook-service). The 7 changed/affected test files pass
    329/329 in a focused run.
  • pnpm build — green on the rebased base (desktop web bundle built in ~35s;
    native build is a no-op on Linux). Only a pre-existing chunk-size advisory, no errors.
  • Added or updated high-quality tests that would catch regressions:
    • per-call override + background-lane saturation/yield (runtime-rpc-call-queue.test.ts)
    • flag forwarding through main routing, renderer client, and the web envelope
    • fetchWorktrees(..., { background: true }) carries background: true on
      both worktree.detectedList and the best-effort worktree.lineageList
    • the reposChanged scheduler refresh issues repos + worktrees + lineage all
      with { background: true } (useIpcEvents.test.ts)
    • the worktreesChanged refresh + its repo discovery ride the background lane,
      while the activateWorktree reveal path stays on the foreground lane
      (useIpcEvents.test.ts)

AI Review Report

Reviewed with multiple independent AI passes. Risks checked: flag continuity
across every layer (queue → main → preload → web → renderer); the three lane
cases (explicit true demotes, explicit false forces foreground, undefined
falls back to method classification); and that no active-only / single-env gate
was introduced that would break the all-host project model. Two real issues were
caught and fixed during review:

  • fetchWorktrees's best-effort lineage follow-up
    (refreshRemoteWorktreeLineageBestEffort) was not forwarding background, so
    the event-driven refresh still issued a foreground worktree.lineageList; it
    now threads the flag and a regression test guards both lineage call sites.
  • the worktreesChanged refresh was still entirely on the foreground lane while
    the sibling reposChanged refresh was demoted — an asymmetry in the same
    client-event handler. The worktreesChanged worktrees/lineage refresh and its
    repo discovery now ride the background lane too, with the activateWorktree
    reveal path kept on the foreground lane (it carries user-facing intent) via an
    explicit option on the shared ensureRuntimeEventRepoKnown helper. Symmetric
    tests lock both lanes.

Cross-platform: no platform-specific paths are touched — the change is shared RPC
plumbing plus renderer store logic, with no OS-specific shortcuts, labels, path
handling, or shell behavior. The background flag rides the existing call
envelope used identically on macOS, Linux, and Windows.

Security Audit

The only new data crossing the IPC boundary is an optional boolean background
flag on the runtime call envelope. It is not user input; it carries no path,
command, secret, or auth material; and it only selects which in-process queue
lane a call uses — it cannot change the selector, method, or params. No new input
handling, command execution, or dependency surface. No follow-up needed.

Notes

  • Scope: both server-pushed event-driven refreshes — the reposChanged
    scheduler refresh and the worktreesChanged refresh (list + lineage + repo
    discovery) — are demoted to the background lane, treated symmetrically since
    they share the same runtime.clientEvents stream. User-initiated calls, the
    activateWorktree reveal path (a CLI-created worktree the user wants shown
    immediately), and the status.get control-plane compatibility probe stay on
    the foreground lane on purpose — the probe gates connection/compatibility UI
    and should not yield.
  • Known limitation (pre-existing, out of scope): the event-driven refresh
    resolves the target host from focused settings rather than the event's
    environmentId, and repo discovery matches on the bare repo.id, so two
    servers sharing a repo id can cross-refresh. This is existing behavior — not
    introduced here — and is being addressed by the upstream host-qualified
    identity stack (Preserve same-id repos across hosts #6030 / Preserve shared project host setups on refresh #6031 / Use host-qualified worktree identities #6096); moving these refreshes onto the
    background lane does not change it.
  • Interacts with fix: Prevent stale worktree refreshes hiding new worktrees #5266 (stale-worktree-refresh guard): that PR adds a
    request-id staleness guard to the same fetchWorktrees. Routing these callers
    onto the (slower) background lane widens the stale-overwrite window fix: Prevent stale worktree refreshes hiding new worktrees #5266
    addresses, and the two conflict textually in worktrees.ts. Whichever lands
    second should reconcile so the background path is also covered by the
    staleness guard.

ELI5

Event-driven project refresh RPC was treated as foreground work and could stall the UI during storms of change events. Those refreshes use a dedicated background lane.

@audichuang
audichuang force-pushed the feat/runtime-rpc-background-lane branch 2 times, most recently from 6a91e38 to 16d4d84 Compare June 23, 2026 09:16
@audichuang audichuang changed the title feat(runtime): add a per-call background lane for event-driven project refresh Add a per-call background lane for event-driven project refresh Jun 23, 2026
@audichuang
audichuang marked this pull request as ready for review June 23, 2026 09:31
@coderabbitai

coderabbitai Bot commented Jun 23, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

A new background?: boolean option is added to runtime RPC queueing and threaded through the IPC, preload, renderer, store, and web call paths. The shared queue now uses the explicit flag for lane selection when provided. Store methods for repos and worktrees accept and forward the option to the relevant runtime RPCs. The event-driven runtime refresh flow now passes { background: true } to its fetch calls.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

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.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding a per-call background lane for event-driven project refreshes.
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.
Description check ✅ Passed The PR description follows the required template and includes complete summary, screenshots, testing, AI review, security, and notes sections.

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.

Runtime RPC calls are sorted onto a background lane by method name (isBackgroundRuntimeMethod), but the event-driven project refresh — a reposChanged event fanning out to repos, worktrees and lineage — fires methods that are not on that list, so the refresh storm competes with user-initiated calls on the foreground lane.

Add a per-call `background` override that flows through the RPC call queue, main call routing, the renderer/preload/web call paths and the renderer fetch helpers, then route the event-driven runtime project refresh through it so the refresh storm yields transport capacity to foreground interaction.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working orca-remote-server Remote Orca Server / orca serve / paired remote runtime

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants