Skip to content

perf(renderer): gate runtime store projections - #16173

Merged
nwparker merged 1 commit into
mainfrom
nwparker/perf-runtime-store-guards
Aug 24, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/perf-runtime-store-guards

Conversation

@nwparker

@nwparker nwparker commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​456 $\color{#cf222e}{\Huge{\mathbf{−}}}$​3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​453
Prod 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​288 $\color{#cf222e}{\Huge{\mathbf{−}}}$​88 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​200

Problem

Global Zustand writes rebuilt runtime-event host collections and subscription keys even when no runtime input changed. Paired-runtime parking also depended on the full runtime status map, and two always-mounted floating-workspace consumers repeated the same unread scans.

Why

These subscribers and selectors sit on hot, app-wide store paths. Their work scaled with saved runtimes, terminal tabs, and unread maps, so unrelated local terminal, direct SSH, folder-workspace, and settings updates paid remote-host and UI projection costs.

Solution

  • Add an O(1) semantic reference gate for the runtime catalog, status map, nested runtime SSH state, and trimmed active runtime id before any host enumeration or key construction.
  • Preserve the per-host connection generation, nested SSH generation, and pairing/runtime revision key so connect, disconnect, same-id re-pair, reconnect, and SSH invalidation still replace subscriptions.
  • Coalesce disconnect-triggered nested SSH publication into one final-generation sync.
  • Install the store listener before runtime streams start and explicitly resync replay invalidation when the module-level SSH generation advances without publishing a tracked store reference. Forced hydration failure cannot strand the replay generation.
  • Structurally share paired-parking capability Sets and make per-worktree parking depend on capability membership rather than the full status map.
  • Share one reference-keyed floating-workspace unread cache across its two always-mounted consumers.

ELI5

Before, changing almost anything in the app made Orca recount every paired computer and recheck several UI lists. Now it first checks a few labels: if none changed, it stops immediately. If a runtime stream loses messages, Orca still replaces that one subscription even when there was no visible SSH bucket update to wake the store.

Proof

  • 4 focused test files, 87 tests passing.
  • pnpm run typecheck:web passing.
  • Deterministic coverage includes 1,000 unrelated writes across 100 runtime hosts with zero host enumerations/key builds.
  • Connect, disconnect, re-pair, runtime generation, nested SSH generation, replay invalidation, no-publication stale buckets, and failed forced hydration are covered.
  • Parking capability-stable status writes perform zero parking scans; membership changes rescan.
  • Two floating unread consumers plus 1,000 unrelated writes share the cached scan.

No regression

  • Local daemon, direct SSH, paired runtime, folder-workspace, foreign/fail-open PTY, and mixed-version capability boundaries remain fail-closed and covered.
  • Missing terminal.paired-parking.v1 continues to keep paired PTYs mounted.
  • Runtime subscription keys retain all existing generation and revision invalidation inputs.
  • No mobile-facing surface changed.

User tradeoffs

  • One module-level cache entry is retained for each shared projection.
  • A replay gap forces one SSH hydrate/resubscribe attempt so missed events cannot remain stale.
  • Outside replay gaps and semantic input changes, the added path does zero broad work.

Readiness and security

  • CLEAN across all seven readiness reviews.
  • Security review: P0/P1/P2 = 0.
  • No new external input handling, permissions, persistence, or mobile-facing API.

Readiness verdict

CLEAN — P0: 0, P1: 0, P2: 0.

Residual risk

Residual risk is limited to network timing around runtime replay-gap recovery; generation guards reject stale callbacks, and the focused disconnect/replay/failed-hydration cases pass.

@coderabbitai

coderabbitai Bot commented Aug 24, 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: 7a130c2a-62eb-4a4a-b5f9-d3f64769d7e8

📥 Commits

Reviewing files that changed from the base of the PR and between 0a613d5 and d0bc533.

📒 Files selected for processing (9)
  • src/renderer/src/components/terminal-pane/paired-runtime-parking-capabilities.ts
  • src/renderer/src/components/terminal-pane/terminal-hidden-view-parking.test.ts
  • src/renderer/src/components/terminal-pane/terminal-hidden-view-parking.ts
  • src/renderer/src/components/terminal-pane/use-terminal-tab-cold-parking.test.ts
  • src/renderer/src/components/terminal-pane/use-terminal-tab-cold-parking.ts
  • src/renderer/src/hooks/useIpcEvents-runtime-environment-selectors.test.ts
  • src/renderer/src/hooks/useIpcEvents.ts
  • src/renderer/src/store/selectors.test.ts
  • src/renderer/src/store/selectors.ts

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


📝 Walkthrough

Walkthrough

The change adds memoized selectors for paired runtime parking environments and floating workspace unread state. Terminal cold parking now consumes the paired-runtime selector from application state. Runtime environment synchronization now uses explicit state, a store subscriber, and replay invalidation handling. Tests cover selector reuse, relevant invalidation, runtime transitions, replay recovery, and unrelated store updates.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the problem, solution, testing, risks, and scope, but it omits a linked issue and required visual proof or an N/A explanation. Add a valid issue reference after “Fixes #” and include before/after visual proof, or state N/A with a reason if there is no UI or interaction change.
✅ 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 primary performance change: gating runtime store projections.
✨ 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 a856367 into main Aug 24, 2026
48 checks passed
@nwparker
nwparker deleted the nwparker/perf-runtime-store-guards branch August 24, 2026 22:38
paidaxingyo666 pushed a commit to paidaxingyo666/Manta that referenced this pull request Aug 25, 2026
dallascrilley pushed a commit to dallascrilley/orca that referenced this pull request Aug 27, 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