Skip to content

Reduce idle remote runtime workspace work - #5895

Merged
Jinwoo-H merged 4 commits into
stablyai:mainfrom
dvic:dvic/fix-runtime-idle-work
Jun 22, 2026
Merged

Jinwoo-H merged 4 commits into
stablyai:mainfrom
dvic:dvic/fix-runtime-idle-work

Conversation

@dvic

@dvic dvic commented Jun 20, 2026 •

Copy link
Copy Markdown
Contributor

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:

  • reposChanged events from a connected runtime kept re-triggering repo/worktree/lineage fetches.
  • Desktop mirrored all remote session tabs just for being connected, keeping PTY machinery warm for sessions nobody had open.
  • A repo-level runtime owner could make local worktrees look remote-owned once you focused a runtime.

What I changed:

  • Coalesce the noisy runtime repo events before refreshing project state (connected remotes still show up immediately).
  • Desktop only syncs session tabs for the active worktree of that runtime; full all-session mirroring stays web-only.
  • Worktree host ownership wins over the repo-level runtime default when routing terminals/sessions.
  • Restore a repo's main worktree when no active tab was stored, and treat inactive PTY ids as wake hints instead of advertising them as live.

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:

  1. 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.

  2. 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 useIpcEvents mounts, and for each one that connects later.

Screenshots

No visual change.

Testing

  • typecheck ✅
  • Focused renderer suites green (worktree host stamping, session-tab sync, idle refresh coalescing, terminal hydration, auto-discover-on-connect).
  • lint trips on pre-existing localization-catalog drift in status-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.


Open in Stage

@ghost

ghost commented Jun 20, 2026 •

Copy link
Copy Markdown

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

Title
1 Introduce runtime project refresh scheduler
2 Refine worktree runtime ownership logic
3 Stamp remote host IDs onto worktrees
4 Limit session tab mirroring on desktop
5 Optimize terminal hydration and PTY advertising
6 Integrate throttled project discovery into IPC
Open in Stage

Chapters generated by Stage for commit 3bc8c08 on Jun 22, 2026 8:32pm UTC.

@coderabbitai

coderabbitai Bot commented Jun 20, 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: 9959282e-a17b-49fe-9b56-93603aa6ad78

📥 Commits

Reviewing files that changed from the base of the PR and between ad6fe2d and 3bc8c08.

📒 Files selected for processing (4)
  • src/renderer/src/hooks/useIpcEvents.test.ts
  • src/renderer/src/hooks/useIpcEvents.ts
  • src/renderer/src/runtime/web-session-tabs-sync.test.ts
  • src/renderer/src/runtime/web-session-tabs-sync.ts

📝 Walkthrough

Walkthrough

This PR introduces createRuntimeProjectRefreshScheduler, a debouncing and throttling utility that coalesces per-environment refresh requests and coordinates worktree/lineage fetches through useIpcEvents. It extends WorktreeRuntimeOwnerState with per-worktree hostId tracking and adds host-parsing helpers plus a new exported getExplicitRuntimeEnvironmentIdForWorktree function implementing a precedence chain (folder-workspace → worktree host → repo host) for explicit runtime environment resolution. Web session tab sync is refactored from a boolean-gated model to environment ID matching: shouldSyncRuntimeSessionTabs now requires the active worktree's explicit runtime environment ID to match the active runtime environment ID, and a new shouldSyncAllRuntimeSessionTabs predicate gates web client mirroring. Worktrees are consistently stamped with the correct execution-host identity when stored during lineage updates, list fetches, and creations. Finally, hydrateWorkspaceSession gains a fallback to the repo's main worktree when activeWorktreeId is absent, and reconnectPersistedTerminals now gates ptyIdsByTabId advertisement to the currently active worktree only.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 6.25% 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 accurately summarizes the main change: reducing background work from idle remote/SSH runtimes through coalesced repo events, scoped session syncing, and refined host ownership logic.
Description check ✅ Passed The PR description is comprehensive and well-structured, covering the problem statement, implementation details, performance results, and testing status. However, it does not include screenshots (though noted as 'No visual change') and the AI Review Report and Security Audit sections are minimal/missing.
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.

✏️ 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@dvic

dvic commented Jun 21, 2026

Copy link
Copy Markdown
Contributor Author

@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 :)

@dvic

dvic commented Jun 21, 2026

Copy link
Copy Markdown
Contributor Author

hmm there are still some bugs here, converting the PR to draft for now

dvic added 2 commits June 22, 2026 09:54
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.
@dvic

dvic commented Jun 22, 2026 •

Copy link
Copy Markdown
Contributor Author

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

@dvic
dvic marked this pull request as ready for review June 22, 2026 17:09

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 5839bc02-cde9-4faa-adb6-636969086e95

📥 Commits

Reviewing files that changed from the base of the PR and between 8951134 and ad6fe2d.

📒 Files selected for processing (4)
  • src/renderer/src/hooks/useIpcEvents.test.ts
  • src/renderer/src/hooks/useIpcEvents.ts
  • src/renderer/src/store/slices/worktrees.test.ts
  • src/renderer/src/store/slices/worktrees.ts

Comment on lines +841 to +847
: replaceWorktreeInRepoLists(
s.worktreesByRepo,
withRepoHostId(
result.updatedRemoteWorktree,
repoHostId(s, getRepoIdFromWorktreeId(result.updatedRemoteWorktree.id))
)
),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

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

@Jinwoo-H Jinwoo-H left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Jinwoo-H
Jinwoo-H merged commit bbc5951 into stablyai:main Jun 22, 2026
1 check passed
@AmethystLiang AmethystLiang added the orca-remote-server Remote Orca Server / orca serve / paired remote runtime label Jul 22, 2026
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
* 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

orca-remote-server Remote Orca Server / orca serve / paired remote runtime

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants