Skip to content

Speed up startup with deferred remote catalogs - #7087

Merged
Jinwoo-H merged 2 commits into
mainfrom
Jinwoo-H/startup-slow
Jul 6, 2026
Merged

Jinwoo-H merged 2 commits into
mainfrom
Jinwoo-H/startup-slow

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • hydrate persisted UI and local catalog data before probing saved remote runtimes
  • defer remote repo/group/folder/worktree refresh into a post-hydration background pass
  • preserve runtime-owned session partitions during local-first startup using runtime worktree owner placeholders
  • dedupe recent offline runtime compatibility failures during startup catalog bursts

Verification

  • pnpm exec vitest run --config config/vitest.config.ts src/renderer/src/app-startup-routing.test.ts src/renderer/src/runtime/runtime-rpc-client.test.ts src/renderer/src/store/slices/repos-all-hosts.test.ts src/renderer/src/lib/workspace-session-host-persistence.test.ts src/renderer/src/store/slices/terminals-hydration.test.ts src/renderer/src/store/slices/worktrees.test.ts
  • pnpm run typecheck:web
  • pnpm exec oxlint src/renderer/src/App.tsx src/renderer/src/app-startup-routing.test.ts src/renderer/src/lib/workspace-session-host-persistence.ts src/renderer/src/lib/workspace-session-host-persistence.test.ts src/renderer/src/runtime/runtime-rpc-client.ts src/renderer/src/runtime/runtime-rpc-client.test.ts src/renderer/src/store/slices/repos.ts src/renderer/src/store/slices/repos-all-hosts.test.ts src/renderer/src/store/slices/terminals-hydration.test.ts src/renderer/src/store/slices/worktree-helpers.ts src/renderer/src/store/slices/worktrees.ts src/renderer/src/store/slices/worktrees.test.ts

Note: typecheck:web passed with the local Node-version warning: repo wants Node 24, shell is Node 26.

Review

  • Subagent review initially found a P1 around runtime session ownership during local-first startup.
  • Addressed by passing runtime host ownership into hydrateWorkspaceSession and adding restore/write-routing regressions.
  • Subagent re-check found no remaining P1 blockers.

Made with Orca 🐋

@coderabbitai

coderabbitai Bot commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Changes

This PR reworks renderer startup hydration to be runtime-host-aware. Local catalogs now load first while skipping remote hosts, worktree purge can be deferred, and persisted workspace sessions are read with runtime-host ownership data used to hydrate terminal state. A later background pass refreshes remote catalogs and worktrees. Repo, project-group, and folder-workspace fetch paths now use catalog helpers and optional all-host fetch options. Runtime RPC compatibility checks now use a TTL-based cache after failures. Persisted UI hydration and setup-script prompt dismissal handling were also tightened. Related tests were updated across these paths.

Sequence Diagram(s)

See hidden artifact diagram for startup hydration flow.

Related PRs: None identified

Suggested labels: renderer, startup, refactor

Suggested reviewers: none identified

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description omits required template sections like Screenshots, Testing checklist, AI Review Report, Security Audit, and Notes. Add the missing template sections, fill the testing checklist, note screenshots or no visual change, and include the AI review, security, and platform-coverage details.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: deferred remote catalog loading to speed up startup.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

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.

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

🧹 Nitpick comments (1)
src/renderer/src/store/slices/repos-all-hosts.test.ts (1)

703-742: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Bounded polling loop risks flakiness.

The fixed for (let attempt = 0; attempt < 10 ...) loop with setTimeout(0) waits for both probes to be captured, but under CI load 10 microtask/macrotask ticks may not be enough before the subsequent assertion runs, causing intermittent failures. Consider vi.waitFor(() => expect(firstStatusResolvers.size).toBe(2)) for a more robust, self-adjusting wait.

♻️ Suggested refactor using vi.waitFor
-    const load = store.getState().fetchReposForAllHosts()
-    for (let attempt = 0; attempt < 10 && firstStatusResolvers.size < 2; attempt += 1) {
-      await new Promise((resolve) => setTimeout(resolve, 0))
-    }
+    const load = store.getState().fetchReposForAllHosts()
+    await vi.waitFor(() => {
+      expect(firstStatusResolvers.size).toBe(2)
+    })

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 6d7970fb-cb2a-4394-83db-d27b7e53a4c3

📥 Commits

Reviewing files that changed from the base of the PR and between 6dafe8c and 6e003fa54e70aad6251eadc802562a93b5672136.

📒 Files selected for processing (13)
  • src/renderer/src/App.tsx
  • src/renderer/src/app-startup-routing.test.ts
  • src/renderer/src/lib/workspace-session-host-persistence.test.ts
  • src/renderer/src/lib/workspace-session-host-persistence.ts
  • src/renderer/src/runtime/runtime-rpc-client.test.ts
  • src/renderer/src/runtime/runtime-rpc-client.ts
  • src/renderer/src/store/slices/repos-all-hosts.test.ts
  • src/renderer/src/store/slices/repos.ts
  • src/renderer/src/store/slices/terminals-hydration.test.ts
  • src/renderer/src/store/slices/terminals.ts
  • src/renderer/src/store/slices/worktree-helpers.ts
  • src/renderer/src/store/slices/worktrees.test.ts
  • src/renderer/src/store/slices/worktrees.ts

Comment on lines +57 to +70
function collectWorktreeIdsFromHostSession(session: WorkspaceSessionState): string[] {
const ids = new Set<string>()
for (const field of WORKTREE_KEYED_SESSION_FIELDS) {
const value = session[field]
if (isPlainRecord(value)) {
for (const id of Object.keys(value)) {
ids.add(id)
}
}
}
for (const id of session.activeWorktreeIdsOnShutdown ?? []) {
ids.add(id)
}
return [...ids]

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.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Normalize workspace keys before adding owner-map IDs.

Line 62 adds record keys directly, but persisted session keys can be canonical WorkspaceKey values as well as raw worktree IDs. A key like worktree:repo::/path will later be treated as a raw worktree ID, causing runtime placeholders to be synthesized for the wrong repo/worktree and dropping or misrouting restored runtime tabs. Normalize worktree:* keys to their raw worktree ID and ignore folder:* keys before adding them to ids.

@Jinwoo-H
Jinwoo-H force-pushed the Jinwoo-H/startup-slow branch from 6e003fa to 8eaffa0 Compare July 2, 2026 08:31

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

🧹 Nitpick comments (1)
src/renderer/src/lib/workspace-session-host-persistence.ts (1)

207-210: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add a short Why: comment for the extra runtime host set.

additionalRuntimeHostIds exists for the startup path where saved runtime session hosts are known before their repo catalogs hydrate; that constraint is non-obvious from the code alone. As per coding guidelines, **/*.{ts,tsx,js,jsx} code driven by a non-obvious constraint should include a short comment explaining why.

Suggested comment
+  // Why: startup can know saved runtime session hosts before their repo
+  // catalogs hydrate, so include those partitions in the first read.
   const runtimeHostIds = new Set<ExecutionHostId>([
     ...listKnownRuntimeHostIds(repos),
     ...additionalRuntimeHostIds
   ])

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: d51fdaac-2830-4c1c-b5ba-8cfeea6a4904

📥 Commits

Reviewing files that changed from the base of the PR and between 6e003fa54e70aad6251eadc802562a93b5672136 and 8eaffa0284a53d13f7d1955294721a16a38034cb.

📒 Files selected for processing (13)
  • src/renderer/src/App.tsx
  • src/renderer/src/app-startup-routing.test.ts
  • src/renderer/src/lib/workspace-session-host-persistence.test.ts
  • src/renderer/src/lib/workspace-session-host-persistence.ts
  • src/renderer/src/runtime/runtime-rpc-client.test.ts
  • src/renderer/src/runtime/runtime-rpc-client.ts
  • src/renderer/src/store/slices/repos-all-hosts.test.ts
  • src/renderer/src/store/slices/repos.ts
  • src/renderer/src/store/slices/terminals-hydration.test.ts
  • src/renderer/src/store/slices/terminals.ts
  • src/renderer/src/store/slices/worktree-helpers.ts
  • src/renderer/src/store/slices/worktrees.test.ts
  • src/renderer/src/store/slices/worktrees.ts
🚧 Files skipped from review as they are similar to previous changes (11)
  • src/renderer/src/store/slices/worktree-helpers.ts
  • src/renderer/src/store/slices/terminals-hydration.test.ts
  • src/renderer/src/runtime/runtime-rpc-client.test.ts
  • src/renderer/src/store/slices/worktrees.ts
  • src/renderer/src/app-startup-routing.test.ts
  • src/renderer/src/store/slices/repos-all-hosts.test.ts
  • src/renderer/src/store/slices/worktrees.test.ts
  • src/renderer/src/runtime/runtime-rpc-client.ts
  • src/renderer/src/store/slices/repos.ts
  • src/renderer/src/App.tsx
  • src/renderer/src/store/slices/terminals.ts

@Jinwoo-H
Jinwoo-H force-pushed the Jinwoo-H/startup-slow branch from 8eaffa0 to 8a1ac37 Compare July 2, 2026 08:53

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

🧹 Nitpick comments (2)
src/renderer/src/runtime/runtime-rpc-client.test.ts (1)

139-209: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider adding a TTL-expiry test.

These tests cover failure reuse and post-recovery retry, but not the TTL eviction path (RECENT_RUNTIME_COMPATIBILITY_FAILURE_TTL_MS) called out in the cache implementation — i.e., a cached failure older than the TTL should be discarded and re-checked even with reuseRecentCompatibilityFailure: true. Adding a fake-timers test would round out coverage of the new cache contract.

src/renderer/src/store/slices/repos-all-hosts.test.ts (1)

752-755: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Replace the fixed scheduler loop with a deterministic probe barrier.

The 10-iteration setTimeout(0) polling can make this concurrency test flaky on slow CI. Resolve a promise from the mock when both selectors have been observed, with an explicit timeout for a clear failure.

Proposed refactor
     const firstStatusResolvers = new Map<string, (value: unknown) => void>()
+    let resolveBothStatusProbes = (): void => {}
+    const bothStatusProbesStarted = new Promise<void>((resolve, reject) => {
+      const timeout = setTimeout(
+        () => reject(new Error('Timed out waiting for both runtime probes')),
+        1_000
+      )
+      resolveBothStatusProbes = () => {
+        clearTimeout(timeout)
+        resolve()
+      }
+    })
     runtimeEnvironmentTransportCall.mockImplementation(
       (args: RuntimeEnvironmentCallRequest & { selector?: string }) => {
         if (
           args.method === 'status.get' &&
           args.selector &&
@@
         ) {
           return new Promise((resolve) => {
             firstStatusResolvers.set(args.selector!, resolve)
+            if (firstStatusResolvers.size === 2) {
+              resolveBothStatusProbes()
+            }
           })
         }
         return createCompatibleRuntimeStatusResponseIfNeeded(args) ?? runtimeEnvironmentCall(args)
       }
     )
@@
 
     const load = store.getState().fetchReposForAllHosts()
-    for (let attempt = 0; attempt < 10 && firstStatusResolvers.size < 2; attempt += 1) {
-      await new Promise((resolve) => setTimeout(resolve, 0))
-    }
+    await bothStatusProbesStarted
 
     expect([...firstStatusResolvers.keys()].sort()).toEqual(['env-1', 'env-2'])

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 4b9bdd63-46cd-4cfb-a885-31bf0a435963

📥 Commits

Reviewing files that changed from the base of the PR and between 8eaffa0284a53d13f7d1955294721a16a38034cb and 8a1ac37.

📒 Files selected for processing (16)
  • src/renderer/src/App.tsx
  • src/renderer/src/app-startup-routing.test.ts
  • src/renderer/src/lib/setup-script-prompt.ts
  • src/renderer/src/lib/workspace-session-host-persistence.test.ts
  • src/renderer/src/lib/workspace-session-host-persistence.ts
  • src/renderer/src/runtime/runtime-rpc-client.test.ts
  • src/renderer/src/runtime/runtime-rpc-client.ts
  • src/renderer/src/store/slices/repos-all-hosts.test.ts
  • src/renderer/src/store/slices/repos.ts
  • src/renderer/src/store/slices/terminals-hydration.test.ts
  • src/renderer/src/store/slices/terminals.ts
  • src/renderer/src/store/slices/ui.test.ts
  • src/renderer/src/store/slices/ui.ts
  • src/renderer/src/store/slices/worktree-helpers.ts
  • src/renderer/src/store/slices/worktrees.test.ts
  • src/renderer/src/store/slices/worktrees.ts
🚧 Files skipped from review as they are similar to previous changes (10)
  • src/renderer/src/store/slices/terminals-hydration.test.ts
  • src/renderer/src/store/slices/worktrees.test.ts
  • src/renderer/src/lib/workspace-session-host-persistence.test.ts
  • src/renderer/src/store/slices/worktrees.ts
  • src/renderer/src/runtime/runtime-rpc-client.ts
  • src/renderer/src/app-startup-routing.test.ts
  • src/renderer/src/store/slices/worktree-helpers.ts
  • src/renderer/src/lib/workspace-session-host-persistence.ts
  • src/renderer/src/store/slices/repos.ts
  • src/renderer/src/store/slices/terminals.ts

@Jinwoo-H
Jinwoo-H force-pushed the Jinwoo-H/startup-slow branch from 8a1ac37 to 8a52b41 Compare July 2, 2026 21:13

@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

♻️ Duplicate comments (1)
src/renderer/src/lib/workspace-session-host-persistence.ts (1)

61-92: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Canonical worktree:* session keys still aren't normalized before use.

collectWorkspaceSessionKeysFromHostSession adds dict keys from tabsByWorktree/etc. directly to ids (Lines 66-68) without stripping a worktree: prefix, and buildHostIdByWorktreeId's returned lookup (Lines 169-186) explicitly parses worktreeId via parseWorkspaceKey but only special-cases type === 'folder' — for type === 'worktree' it falls straight through, still using the prefixed string against runtimeHostIdByWorktreeId/repoIdByWorktreeId (keyed by raw ids) and getRepoIdFromWorktreeId (which would slice worktree:repoId::path into worktree:repoId, matching no real repo). A canonical worktree:repo::/path session key would therefore be misrouted to LOCAL_EXECUTION_HOST_ID, dropping/misrouting restored runtime tabs — exactly the scenario called out in a prior review on this file.

🛠️ Proposed fix
 function collectWorkspaceSessionKeysFromHostSession(session: WorkspaceSessionState): string[] {
   const ids = new Set<string>()
   for (const field of WORKSPACE_SESSION_KEYED_FIELDS) {
     const value = session[field]
     if (isPlainRecord(value)) {
       for (const id of Object.keys(value)) {
-        ids.add(id)
+        const scope = parseWorkspaceKey(id)
+        ids.add(scope?.type === 'worktree' ? scope.worktreeId : id)
       }
     }
   }
   return (worktreeId: string): ExecutionHostId => {
     const workspaceScope = parseWorkspaceKey(worktreeId)
     if (workspaceScope?.type === 'folder') {
       return getFolderWorkspaceRuntimeHostId(state, worktreeId)
     }
-    const worktreeHostId = runtimeHostIdByWorktreeId.get(worktreeId)
+    const rawWorktreeId =
+      workspaceScope?.type === 'worktree' ? workspaceScope.worktreeId : worktreeId
+    const worktreeHostId = runtimeHostIdByWorktreeId.get(rawWorktreeId)
     if (worktreeHostId) {
       return worktreeHostId
     }
-    const repoId = repoIdByWorktreeId.get(worktreeId) ?? getRepoIdFromWorktreeId(worktreeId)
+    const repoId = repoIdByWorktreeId.get(rawWorktreeId) ?? getRepoIdFromWorktreeId(rawWorktreeId)

Based on a prior review comment: "A key like worktree:repo::/path will later be treated as a raw worktree ID, causing runtime placeholders to be synthesized for the wrong repo/worktree and dropping or misrouting restored runtime tabs."

Also applies to: 169-186


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 067cb23d-7684-45e3-b466-9e16fc9d095d

📥 Commits

Reviewing files that changed from the base of the PR and between 8a1ac37 and 8a52b41125136a8643e84482543b8c2381d18309.

📒 Files selected for processing (24)
  • src/renderer/src/App.tsx
  • src/renderer/src/app-startup-routing.test.ts
  • src/renderer/src/lib/setup-script-prompt.ts
  • src/renderer/src/lib/workspace-session-host-persistence.test.ts
  • src/renderer/src/lib/workspace-session-host-persistence.ts
  • src/renderer/src/lib/workspace-session-hydration-keys.ts
  • src/renderer/src/lib/worktree-runtime-owner.test.ts
  • src/renderer/src/lib/worktree-runtime-owner.ts
  • src/renderer/src/runtime/runtime-rpc-client.test.ts
  • src/renderer/src/runtime/runtime-rpc-client.ts
  • src/renderer/src/store/slices/browser.ts
  • src/renderer/src/store/slices/editor.ts
  • src/renderer/src/store/slices/repos-all-hosts-folder-workspaces.test.ts
  • src/renderer/src/store/slices/repos-all-hosts.test.ts
  • src/renderer/src/store/slices/repos.ts
  • src/renderer/src/store/slices/store-session-cascades.test.ts
  • src/renderer/src/store/slices/tabs.ts
  • src/renderer/src/store/slices/terminals-hydration.test.ts
  • src/renderer/src/store/slices/terminals.ts
  • src/renderer/src/store/slices/ui.test.ts
  • src/renderer/src/store/slices/ui.ts
  • src/renderer/src/store/slices/worktree-helpers.ts
  • src/renderer/src/store/slices/worktrees.test.ts
  • src/renderer/src/store/slices/worktrees.ts
🚧 Files skipped from review as they are similar to previous changes (10)
  • src/renderer/src/store/slices/worktree-helpers.ts
  • src/renderer/src/store/slices/terminals-hydration.test.ts
  • src/renderer/src/runtime/runtime-rpc-client.test.ts
  • src/renderer/src/store/slices/ui.test.ts
  • src/renderer/src/app-startup-routing.test.ts
  • src/renderer/src/App.tsx
  • src/renderer/src/lib/setup-script-prompt.ts
  • src/renderer/src/runtime/runtime-rpc-client.ts
  • src/renderer/src/store/slices/repos.ts
  • src/renderer/src/store/slices/ui.ts

@Jinwoo-H
Jinwoo-H force-pushed the Jinwoo-H/startup-slow branch from 8a52b41 to 3730b4a Compare July 2, 2026 21:49
Resolve conflicts from deferred-remote-catalog startup optimization:
- App.tsx: combine main's parallel keybindings/onboarding promises with the
  PR's local-first ui-get -> hydrate -> local catalog -> deferred remote flow
- browser.ts: keep both hydrateBrowserSession(options) and
  switchBrowserTabProfile(sessionPartition) signature changes
- app-startup-routing.test.ts: point the startup-block end at session-get and
  drop the obsolete all-hosts scope-overlap test the PR's design replaces
- terminals.ts: use findLast(Boolean) for basename to satisfy main's newly
  added unicorn/prefer-array-find lint rule

Co-authored-by: Orca <[email protected]>
@Jinwoo-H
Jinwoo-H merged commit bc84f4b into main Jul 6, 2026
1 check passed
@Jinwoo-H
Jinwoo-H deleted the Jinwoo-H/startup-slow branch July 6, 2026 22:15
Jinwoo-H added a commit that referenced this pull request Jul 6, 2026
Brings in 9 commits: deferred remote catalogs at startup (#7087),
owner-aware pane title decision gating the Gemini GPU fallback (#7458),
incremental transcript parsing for JSONL agents (#7593), gh rate-limit and
git-status spawn-churn fixes (#7595), WSL Codex session bridging (#7477),
jump-palette subscription gating (#7558), and the IDE font dropdown fix.

Conflict resolutions (our structure, main's semantics):
- pty-connection.ts onTitleChange: kept this branch's third parameter and
  stale-derived-title guard (staleWorkingTitleClear must never feed
  completion tracking), grafted main's resolvePaneTitleDecision so the
  display label, GPU policy, and observeTitle all ride the owner-aware
  decision (#7428/#7447).
- App.tsx startup: kept this branch's publishTerminalViewAttributesAtAppStart
  (hidden-at-launch OSC 10/11 replies) ahead of main's restructured
  local-first startup; dropped this branch's early ui.get() overlap — main's
  #7087 now awaits ui.get at effectively the same point, making it redundant.

Gates: typecheck clean; 4298 tests across src/main/ipc, src/main/daemon,
terminal-pane, pane-manager. The delivery path (ipc/pty.ts, dispatcher,
scheduler, snapshots) had no conflicts and no incoming changes.

Co-authored-by: Orca <[email protected]>
@AmethystLiang

Copy link
Copy Markdown
Contributor

looking into it

@AmethystLiang

Copy link
Copy Markdown
Contributor

thanks for reporting. looking into it

enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 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.

2 participants