Skip to content

Fix renderer starvation blocking settings and worktree switching - #16138

Merged
nwparker merged 1 commit into
mainfrom
fix/live-ui-backend-starvation
Aug 23, 2026
Merged

nwparker merged 1 commit into
mainfrom
fix/live-ui-backend-starvation

Conversation

@nwparker

@nwparker nwparker commented Aug 23, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​74 $\color{#cf222e}{\Huge{\mathbf{−}}}$​5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​69
Prod 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​72 $\color{#cf222e}{\Huge{\mathbf{−}}}$​50 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​22

ELI5

Orca had three chores in the path of two simple actions. It repeatedly rechecked every parked terminal when only a terminal label changed, rebuilt most of Settings for every search keystroke, and waited for the backend before showing a workspace switch. With hundreds of worktrees and terminals, those chores could crowd out clicks and delay the search timer. This PR narrows the terminal check to meaningful changes, keeps typing local to the search box, and makes navigation independent from a slow backend wake-up.

Problem

The live packaged app became intermittently unusable at accumulated-state scale:

  • 393 worktrees and 193 terminal sessions
  • renderer sampled at 109–111% CPU during the stall
  • main sampled at 25% CPU
  • Settings accepted text, but the result-driving debounce could not run promptly
  • worktree clicks waited on optional VM-resume IPC before changing local navigation state

The app later becoming responsive without a restart is consistent with a burst that eventually drained, rather than a permanently dead process. This PR removes work from the interaction path so the same kind of burst is less able to starve input and navigation.

What this solution fixes

1. Stops display-only terminal churn from starting global parking work

Terminal stays mounted across routes and watches terminal tabs for every worktree. The parking effect previously depended on the complete tabsByWorktree object, so any immutable tab update—including a title change—could rerun worktree parking, watcher reconciliation, retention, and timer bookkeeping across the mounted terminal fleet.

The effect now depends on a semantic key containing only the fields the parking policy consumes:

  • worktree ID
  • terminal tab ID
  • PTY ID
  • pending activation/spawn state

Title-only and other display-only changes therefore do not start the global parking pass. Real lifecycle changes still do.

2. Keeps each Settings keystroke out of the full Settings render tree

Settings has an immediate input value and a separately debounced query that drives filtering. The full Settings parent previously subscribed to the immediate value only to pass it back to the search box. Every keystroke could therefore rebuild the large Settings tree before the debounced query applied; under renderer saturation, the trailing timer was delayed repeatedly, producing “text changes but results do not.”

The immediate subscription now lives inside the search-field component. Typing updates the input immediately without rerendering every Settings section. The parent remains subscribed only to the applied query used for filtering.

3. Makes worktree navigation local-first instead of backend-gated

A sidebar click previously awaited optional ephemeral-runtime resume IPC before publishing the selected worktree. If the provider or backend was slow, the visible workspace did not change and the click looked ignored.

The click now publishes the local worktree selection first, then wakes and refreshes the runtime asynchronously. A slow backend can leave the selected workspace temporarily disconnected, but it cannot trap navigation on the previous workspace. Wake failures still produce an error toast.

Expected user-visible result

  • Worktree clicks change the selected workspace immediately.
  • Settings typing stays responsive and matching sections appear after the existing debounce.
  • Routine terminal title/output activity no longer causes unnecessary fleet-wide parking passes.
  • Backend wake failures remain visible without making the rest of the UI unclickable.

Tradeoff

A slow or failed VM wake now shows the selected workspace in a loading/disconnected state instead of keeping the user on the previous workspace until wake succeeds. No terminal is deleted or shut down by this ordering change.

Scope

This PR targets the renderer interaction paths directly associated with the observed symptoms. It does not claim to eliminate every source of background work: the live profile also has large persisted state, Git activity, and terminal inventory. Those remain separate performance surfaces.

Verification

  • pnpm exec vitest run --config config/vitest.config.ts src/renderer/src/components/sidebar/sleep-worktree-activation-race.test.ts src/renderer/src/lib/sidebar-worktree-activation.test.ts src/renderer/src/store/slices/settings-search-state.test.ts src/renderer/src/components/settings/SettingsSidebar.test.tsx src/renderer/src/components/settings/Settings.load-performance.test.ts src/renderer/src/components/terminal-pane/terminal-hidden-worktree-retention.test.ts
    • 6 files, 34 tests passed
  • pnpm run typecheck:web
  • Electron/CDP smoke on the branch:
    • attached to Orca: fix/live-ui-backend-starvation
    • Settings search visibly changed from no results to the matching General → Editor → Minimap control
    • loaded the repo catalog showing 348 discovered worktrees
    • replaced ephemeralVm.resumeWorkspace with a never-settling promise, clicked the real workspace row, and observed activeWorktreeId plus the terminal surface update immediately

@nwparker
nwparker force-pushed the fix/live-ui-backend-starvation branch from 8cecef5 to 95fc1cd Compare August 23, 2026 21:12
@coderabbitai

coderabbitai Bot commented Aug 23, 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: fdbf6525-c8d1-490d-8e43-745595abe046

📥 Commits

Reviewing files that changed from the base of the PR and between 8cecef5538ba3ece30e1fa7c2b39c6f79c02ca81 and 95fc1cd.

📒 Files selected for processing (1)
  • src/renderer/src/components/sidebar/sleep-worktree-activation-race.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 1 remains after this review.


📝 Walkthrough

Walkthrough

The terminal parking effect now derives a revision key from policy-relevant tab properties and uses a current store snapshot during parking decisions. Settings search state is managed by a local field through the app store instead of sidebar props. Sidebar worktree activation now occurs before ephemeral VM resume handling, with tests covering pending runtime wake behavior.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description clearly explains the problem, solution, scope, tradeoffs, and verification, but it omits several required template sections. Add the Linked Issue, Visual Proof or N/A statement, AI Disclosure, Review, boundary, Notes, and Checklist sections.
✅ Passed checks (4 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring check was indeterminate for this PR — some files could not be analyzed in time. Not blocking.
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 summarizes the main renderer performance fixes for Settings responsiveness and worktree switching.
✨ Finishing Touches
📝 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 merged commit b89b58b into main Aug 23, 2026
47 checks passed
kunsanglee added a commit to kunsanglee/orca that referenced this pull request Aug 24, 2026
stablyai#16138 stopped reading tabsByWorktree through the effect deps, reading it once
from the store instead so terminal load cannot stall navigation. This branch
enriches the same list with each tab's active leaf, which the owner check needs
as pane identity.

Kept both: the tabs come from main's single store read, and the layout map is
read beside it rather than per tab, which is what the branch's inline getState
was doing.

Taking main's side wholesale here would compile and pass every test —
activeLeafId is optional, so every ownership check would silently fall back to
a null leaf. Nothing in the suite covers this call site.
paidaxingyo666 pushed a commit to paidaxingyo666/Manta that referenced this pull request Aug 25, 2026
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.

1 participant