Repository navigation
Reduce idle remote runtime workspace work - #5895
Conversation
|
Ready to review this PR? Stage has broken it down into 6 individual chapters for you: Chapters generated by Stage for commit 3bc8c08 on Jun 22, 2026 8:32pm UTC. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughThis PR introduces 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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 |
|
@AmethystLiang not sure if this is the right fix, but without this PR the remote feature is making Orca unusable slow for me, not sure if this is specific to my setup though :) |
|
hmm there are still some bugs here, converting the PR to draft for now |
Remote-runtime and SSH worktrees are fetched/created/reparented through the owning host, which reports them from its own perspective (hostId defaults to "local"). After the per-worktree hostId override in stablyai#2, that bogus "local" overrode the repo's runtime owner, so terminals/sessions for a remote worktree resolved to the local machine instead of the remote (clicking an omarchy-office worktree opened a shell on the local omarchy-thinkpad). Re-stamp every runtime worktree payload with the repo's execution host via a shared withRepoHostId helper, applied at all worktreesByRepo ingress points: toVisibleWorktrees (fetch), createWorktree, and applyWorktreeLineageUpdate. Local-owned repos are left untouched, so an explicit local worktree still overrides a runtime repo owner. Mirrors how repos already get repoWithFetchedOwner.
PR stablyai#2 gated the global session-tab sync to web clients only, removing the desktop path that eagerly populated remote projects. With no on-connect repo fetch left, remote projects only appeared after the user opened the Add-Project dropdown (which calls fetchRuntimeEnvironmentRepos directly). Seed an initial repo/worktree/lineage refresh for every runtime environment that is already connected when useIpcEvents mounts, and for each one that becomes connected afterward. Reuses the debounced/throttled refresh scheduler, and works regardless of whether the remote server emits client events.
|
Update: I think now it's fixed (Follow-up fixes in the PR body), but I'll try it out for a day and report back |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 5839bc02-cde9-4faa-adb6-636969086e95
📒 Files selected for processing (4)
src/renderer/src/hooks/useIpcEvents.test.tssrc/renderer/src/hooks/useIpcEvents.tssrc/renderer/src/store/slices/worktrees.test.tssrc/renderer/src/store/slices/worktrees.ts
| : replaceWorktreeInRepoLists( | ||
| s.worktreesByRepo, | ||
| withRepoHostId( | ||
| result.updatedRemoteWorktree, | ||
| repoHostId(s, getRepoIdFromWorktreeId(result.updatedRemoteWorktree.id)) | ||
| ) | ||
| ), |
There was a problem hiding this comment.
Capture the repo host before the async request.
These paths send the request using one owner snapshot, then stamp the response using current store state after the await. If repo ownership changes while the request is in flight, stale remote payloads can be stored with the wrong hostId, routing terminals/sessions to the wrong host. Capture the execution host alongside the settings/target used for the call and pass that through the merge.
Suggested direction
-const settings = settingsForRepoOwner(get(), repoId)
+const stateBeforeRefresh = get()
+const settings = settingsForRepoOwner(stateBeforeRefresh, repoId)
+const requestHostId = repoHostId(stateBeforeRefresh, repoId)
const detected = await listDetectedWorktreesForRepo(settings, repoId)
...
-const worktrees = toVisibleWorktrees(detected, repoHostId(get(), repoId))
+const worktrees = toVisibleWorktrees(detected, requestHostId)Apply the same pattern to fetchAllWorktrees, and pass a captured requestHostId into applyWorktreeLineageUpdate / the createWorktree reducer instead of recomputing from get()/s after the RPC resolves.
Also applies to: 1450-1455, 1544-1548, 1824-1883
Co-authored-by: Orca <[email protected]>
Jinwoo-H
left a comment
There was a problem hiding this comment.
Thanks, this is a solid fix. I found a few edge cases while reviewing the remote-runtime paths and pushed follow-up fixes:
- Refresh remote projects when an already-selected runtime transitions from unreachable to reachable.
- Bound runtime project worktree refresh fan-out so one coalesced event cannot start every repo scan at once.
- Keep refreshing later repos even if one repo refresh fails.
- Use the active worktree's runtime owner for desktop session-tab sync, rather than the focused runtime setting.
Verified with focused renderer tests, typecheck, and Electron validation of the runtime refresh path.
* Fix idle remote runtime session work * fix: stamp remote/SSH worktrees with their repo execution host Remote-runtime and SSH worktrees are fetched/created/reparented through the owning host, which reports them from its own perspective (hostId defaults to "local"). After the per-worktree hostId override in stablyai#2, that bogus "local" overrode the repo's runtime owner, so terminals/sessions for a remote worktree resolved to the local machine instead of the remote (clicking an omarchy-office worktree opened a shell on the local omarchy-thinkpad). Re-stamp every runtime worktree payload with the repo's execution host via a shared withRepoHostId helper, applied at all worktreesByRepo ingress points: toVisibleWorktrees (fetch), createWorktree, and applyWorktreeLineageUpdate. Local-owned repos are left untouched, so an explicit local worktree still overrides a runtime repo owner. Mirrors how repos already get repoWithFetchedOwner. * fix: auto-discover remote runtime projects on connect PR stablyai#2 gated the global session-tab sync to web clients only, removing the desktop path that eagerly populated remote projects. With no on-connect repo fetch left, remote projects only appeared after the user opened the Add-Project dropdown (which calls fetchRuntimeEnvironmentRepos directly). Seed an initial repo/worktree/lineage refresh for every runtime environment that is already connected when useIpcEvents mounts, and for each one that becomes connected afterward. Reuses the debounced/throttled refresh scheduler, and works regardless of whether the remote server emits client events. * fix: tighten idle runtime refresh behavior Co-authored-by: Orca <[email protected]> --------- Co-authored-by: Jinwoo-H <[email protected]> Co-authored-by: Orca <[email protected]>
Summary
Found this while digging into #4527 (slow scroll/typing). It's not a direct fix for that, but a connected-but-idle remote/SSH runtime turned out to be doing a surprising amount of background work, which was a big part of why things felt bad on my setup. This trims it down.
What was going on:
reposChangedevents from a connected runtime kept re-triggering repo/worktree/lineage fetches.What I changed:
For reference, on my setup an idle 5s window went from ~150 store writes (plus a pile of repo/worktree/lineage fetches) down to 0, and renderer CPU dropped from a ~116% spike to low single digits.
Follow-up fixes
While test-driving I hit two regressions caused by the changes above and fixed them in follow-up commits — both renderer-only, both with tests:
Remote/SSH worktrees were routing to the local machine. Once worktree host ownership started winning, remote worktrees broke: they come back from the owning host with
hostId: "local", so that bogus"local"overrode the repo's real runtime owner and a remote worktree opened a shell on the local box. Fix: re-stamp every runtime worktree with its repo's execution host (withRepoHostId) at all the ingress points (fetch/create/reparent). Local-owned repos are left alone, so an explicit local worktree still wins.Remote projects stopped auto-appearing. Making all-session mirroring web-only removed the desktop path that eagerly populated remote projects, and nothing fetched them on connect — so they only showed up after opening the Add-Project dropdown. Fix: kick off a repo/worktree/lineage refresh for each runtime that's already connected when
useIpcEventsmounts, and for each one that connects later.Screenshots
No visual change.
Testing
typecheck✅linttrips on pre-existing localization-catalog drift instatus-bar/tooltip.tsx, which I didn't touch.Still being test-driven on a real remote/SSH setup before it comes out of draft.
Security
No new IPC channels, deps, auth, or filesystem surface — this only narrows when renderer events trigger refresh work. Host/runtime selection still uses existing store data.
Notes
Came out of #4527. Again, not a direct scroll fix — just removing idle runtime/session work that made typing and scrolling feel bad for me.