Skip to content

Fix workspace renderer freeze during runtime reconnects - #11472

Merged
brennanb2025 merged 1 commit into
mainfrom
brennanb2025/fix-electron-freeze-repro
Jul 30, 2026
Merged

brennanb2025 merged 1 commit into
mainfrom
brennanb2025/fix-electron-freeze-repro

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • stop runtime reachability flaps from launching global all-host worktree and lineage scans from the workspace sidebar
  • rely on the existing per-environment, debounced/throttled runtime refresh scheduler
  • remove the obsolete sidebar single-flight coalescer and add reconnect-flap regression coverage
  • retain longer camelCase React error/component stacks so a future #185 captures application frames
  • include the complete production and isolated-Electron incident report

The user-visible result is that a reconnecting remote host no longer makes worktree-sidebar scrolling progressively slower or pins the workspace renderer in a JavaScript hot loop.

Screenshots

No intended visual change. This is the fixed 266-worktree sidebar after the runtime-flap stress test; a real wheel event moved the list from scrollTop=2419 to 10419.

Fixed worktree sidebar after reconnect stress

Testing

  • pnpm lint
  • pnpm typecheck
  • pnpm test
  • pnpm build
  • Added or updated high-quality tests that would catch regressions, or explained why tests were not needed

Completed:

  • pnpm exec vitest run --config config/vitest.config.ts src/shared/crash-reporting.test.ts src/renderer/src/components/sidebar/Sidebar.test.tsx src/renderer/src/hooks/runtime-project-refresh-scheduler.test.ts src/renderer/src/hooks/useIpcEvents.test.ts src/renderer/src/components/terminal-pane/TerminalPaneOverlayLayer.react185.test.tsx src/renderer/src/components/activity/activity-portal-readiness-loop.react185.test.tsx
    • 6 files and 118 tests passed
  • focused oxlint on all changed TypeScript/TSX files
  • pnpm exec tsc --noEmit -p config/tsconfig.web.json --composite false
  • git diff --check
  • commit hooks: oxlint, React Doctor lint, and oxfmt

Electron replay used the real Orca dev runner with an isolated profile, 13 repo rows, 266 visible worktrees, and 3,458 detected worktree records:

Scenario Global scans Duration Mean frame gap p95 Max
Pre-fix, 600 runtime transitions 139 35.7s 59.5ms 124.6ms 272.5ms
Fixed, identical transitions 0 18.2s 30.3ms 49.5ms 150.1ms

During the pre-fix replay, the renderer reached 140.9% CPU and a 2.1 GiB physical footprint; all 2,353 active sample frames were in V8/JavaScript execution. After the fixed run, interval CPU returned to 0% and visible wheel scrolling remained responsive.

AI Review Report

Reviewed the complete reconnect event chain, historical introduction of both refresh paths, store merge behavior, and existing scheduler coverage.

Main risks checked:

  • remote projects still refresh when a runtime reconnects
  • normal repo-count changes retain their existing broad refresh
  • continuous flapping cannot fall back to an unbounded leading/trailing global scan
  • direct SSH, SSH-hosted workspaces, folder workspaces, and local git worktrees keep their existing paths
  • the crash-stack change preserves the ordinary 240-character detail cap
  • the deleted coalescer has no remaining consumers

The initial crash-stack fixture was too short after path redaction to exercise the 4,000-character cap; it was lengthened and the regression now passes.

Cross-platform review explicitly checked macOS, Linux, and Windows behavior. This change adds no shortcuts, labels, shell commands, path assumptions, native modules, or Electron platform branches. Windows runtime hosts use the same environment-scoped renderer scheduler, and SSH/folder-workspace routing is unchanged.

Security Audit

  • no new user input, command execution, auth, IPC, network, dependency, or persistence surface
  • no secrets or raw terminal contents are included in the incident report
  • crash details continue through the existing path/secret sanitizers and bounded length caps
  • the fix removes work rather than adding privileged operations

Notes

  • The reconnect-driven all-host scan is conclusively reproduced as the renderer hot-loop amplifier. The exact downstream React setter that emitted the original production #185 remains unproven.
  • The isolated replay injected a synthetic Windows-runtime status into the real renderer store; it exercised the exact sidebar dependency and scan path without requiring a live Windows host.
  • Full evidence and remaining follow-ups are in renderer-worktree-freeze-incident-2026-07-29.md.

Root-cause and architecture assessment

This is a root-cause fix for the reproduced reconnect failure, not symptom suppression. The architectural defect was incorrect invalidation scope: a status change from one runtime could launch a global scan across every host. This PR removes that redundant trigger and preserves the existing per-environment refresh owner.

The resulting design has the intended properties:

  • reconnect discovery is scoped to the affected runtime environment
  • noisy events are debounced, throttled, and serialized per environment
  • repo refresh fan-out remains bounded
  • startup and actual repo-catalog changes retain their legitimate broad refresh paths
  • no arbitrary delay, reload, feature flag, platform exception, or recovery hack is introduced

An independent architecture comparison found the same mature pattern: keyed, scoped refresh queues for noisy workspace events, with broad scans reserved for explicit lifecycle boundaries.

Review verdict: high confidence in the implementation and merge readiness. The Electron replay causally validates the removed refresh storm. The remaining confidence boundary is narrower: the exact downstream React setter that emitted the original production #185 is not yet proven, so this should not be described as eliminating every possible renderer update loop. The longer stack diagnostics preserve the evidence needed if a separate loop remains.

@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@brennanb2025, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 3 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: ceff65a9-0d69-4c3c-8f23-683eada8a489

📥 Commits

Reviewing files that changed from the base of the PR and between 7915778 and 279b990.

📒 Files selected for processing (7)
  • renderer-worktree-freeze-incident-2026-07-29.md
  • src/renderer/src/components/sidebar/Sidebar.test.tsx
  • src/renderer/src/components/sidebar/index.tsx
  • src/renderer/src/components/sidebar/single-flight-coalescer.test.ts
  • src/renderer/src/components/sidebar/single-flight-coalescer.ts
  • src/shared/crash-reporting.test.ts
  • src/shared/crash-reporting.ts

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.

@greptile-apps

greptile-apps Bot commented Jul 30, 2026

Copy link
Copy Markdown

Greptile Summary

This PR fixes a workspace renderer hot-loop triggered by runtime reconnect flaps: each connect/disconnect event re-computed onlineRuntimeEnvKey in the Sidebar, fired the global fetchAllWorktrees + fetchWorktreeLineage pair, and the resulting store updates caused cascading re-renders that pinned the renderer at ~140% CPU. The fix removes the sidebar's reconnect-driven all-host scan entirely, delegating reconnect-triggered worktree refresh to the existing per-environment runtimeProjectRefreshScheduler in useIpcEvents. A second independent change normalizes camelCase crash-report detail keys (errorStack, componentStack) to snake_case before the length-cap lookup so React component stacks retain the full 4,000-character limit instead of being silently cut to 240.

  • sidebar/index.tsx: Removes the runtimeStatusByEnvironmentId subscription, the onlineRuntimeEnvKey memo, and the reconnectRefreshRef single-flight coalescer; deletes single-flight-coalescer.ts and its tests; updates the regression test to verify no scans fire on repeated connect/disconnect cycles.
  • crash-reporting.ts: Adds a /([a-z0-9])([A-Z])/g normalization step so errorStack → error_Stack matches the existing _stack tail pattern (case-insensitive); extends the test fixture from 80 to 200 frame lines so the sanitized string exceeds the 4,000-char cap, and adds explicit assertions for errorStack, componentStack, and a non-stack key.

Confidence Score: 5/5

Safe to merge. The change removes work rather than adding it, is backed by a profiled Electron replay, and the two modified subsystems are independently validated by the updated test suite.

The sidebar deletion is a clean subtraction: the removed code path (global all-host scan on every runtime status change) is fully covered by the per-environment scheduler already wired in useIpcEvents, which calls fetchRuntimeEnvironmentRepos, refreshRuntimeProjectWorktrees, and fetchWorktreeLineage with debouncing and throttling. No existing scan trigger is lost. The crash-reporting normalization is mechanically verified by the new toBe(4_003) assertions, and the camelCase-to-snake_case regex correctly handles all relevant key shapes. No new IPC surface, no new async paths, no behavioral change for non-reconnect renders.

Files Needing Attention: No files require special attention. The only non-obvious detail is that the new flap regression test in Sidebar.test.tsx passes runtimeStatusByEnvironmentId in mock state even though the component no longer subscribes to it — this is intentional: changing that value across rerenders is exactly what proves no fetch is triggered.

Important Files Changed

Filename Overview
src/renderer/src/components/sidebar/index.tsx Removes the reconnect-triggered global scan: deletes the runtimeStatusByEnvironmentId subscription, onlineRuntimeEnvKey memo, and reconnectRefreshRef coalescer. The runtime scheduler in useIpcEvents covers this path with per-environment debouncing.
src/shared/crash-reporting.ts Adds camelCase normalization before the stack-key length-cap regex so errorStack and componentStack get 4,000-char limit instead of 240. Logic is correct; /i flag on the test pattern handles the mixed-case output of the replace.
src/renderer/src/components/sidebar/Sidebar.test.tsx Replaces the old async reconnect test (which verified the now-deleted trigger) with a synchronous flap regression: cycles runtimeStatusByEnvironmentId 5 times and asserts fetchAllWorktrees is never called.
src/shared/crash-reporting.test.ts Extends the frame fixture from 80 to 200 entries so the sanitized string exceeds 4,000 chars; adds toBe(4_003) assertions for errorStack and componentStack, and a 243-char assertion for a non-stack key.
src/renderer/src/components/sidebar/single-flight-coalescer.ts Deleted: the coalescer is no longer referenced anywhere in the codebase now that the sidebar's reconnect scan is removed.
src/renderer/src/components/sidebar/single-flight-coalescer.test.ts Deleted along with the implementation; no orphaned test coverage concern.
renderer-worktree-freeze-incident-2026-07-29.md New incident report documenting the production freeze, isolated Electron replay, profiling evidence, and fix validation. No executable code; no security surface.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Runtime host reconnects] --> B{Before fix}
    A --> C{After fix}

    B --> D[runtimeStatusByEnvironmentId changes in store]
    D --> E[Sidebar onlineRuntimeEnvKey memo recomputes]
    E --> F[useEffect fires]
    F --> G[reconnectRefreshRef.request]
    G --> H[fetchAllWorktrees ALL hosts]
    H --> I[fetchWorktreeLineage ALL hosts]
    I --> J[Store update Sidebar re-renders]
    J --> F
    J --> K[Hot loop pinned CPU frozen scroll]

    C --> L[useIpcEvents detects reconnect]
    L --> M[runtimeProjectRefreshScheduler.request envId]
    M --> N[Debounce 250ms + throttle 5s per environment]
    N --> O[fetchRuntimeEnvironmentRepos envId]
    O --> P[refreshRuntimeProjectWorktrees]
    P --> Q[fetchWorktreeLineage]
    Q --> R[Sidebar not subscribed to runtime status no cascade]
Loading

Reviews (1): Last reviewed commit: "fix(sidebar): isolate runtime reconnect ..." | Re-trigger Greptile

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Post-review Electron QA

Validated final HEAD 279b990d32 in a fresh isolated Electron profile after the same-model senior review returned clean.

  • loaded the current PR worktree and discovered 260 worktrees
  • real wheel input moved the sidebar from scrollTop=24 to scrollTop=8024
  • 60 post-scroll animation frames: mean 8.31 ms, p95 8.90 ms, max 9.40 ms
  • sidebar remained responsive with no visual regression observed

Final-HEAD branch and linked-PR identity:

Final HEAD branch and PR identity

Scrolled 260-worktree sidebar after the real wheel input:

Scrolled 260-worktree sidebar

@brennanb2025
brennanb2025 merged commit f0eca5f into main Jul 30, 2026
42 checks passed
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