Repository navigation
fix(sidebar): coalesce staggered reconnect refreshes to stop wake freeze (#8539) - #9847
Conversation
📝 WalkthroughWalkthroughAdds a 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
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. Comment |
…eze (#8539) On wake, remote/SSH runtimes reconnect in a staggered burst; the sidebar refetched all worktrees once per host, piling up K synchronous full-sidebar remounts and freezing the UI. Wrap the reconnect refresh in a single-flight coalescer so at most one refresh runs at a time plus one queued rerun, for any K. fetchAllWorktrees and its lineage follow-up are unchanged; only how often they fire changes. Co-authored-by: Orca <[email protected]>
56fe4ea to
6fd1dfe
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 9d35805e-d436-4d53-aade-97506db1af02
📒 Files selected for processing (3)
src/renderer/src/components/sidebar/index.tsxsrc/renderer/src/components/sidebar/single-flight-coalescer.test.tssrc/renderer/src/components/sidebar/single-flight-coalescer.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- src/renderer/src/components/sidebar/single-flight-coalescer.ts
| let resolve!: () => void | ||
| let reject!: (e: unknown) => void |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
file="src/renderer/src/components/sidebar/single-flight-coalescer.test.ts"
wc -l "$file"
cat -n "$file" | sed -n '1,80p'Repository: stablyai/orca
Length of output: 3100
Document the synchronous initialization here resolve! and reject! rely on the Promise executor assigning them before deferred() returns; add a short comment explaining that constraint.
Source: Coding guidelines
…eze (#8539) (#9847) Cherry-pick into 1.4.150-release-prep for the stable cut. On wake, remote/SSH runtimes reconnect in a staggered burst; the sidebar refetched all worktrees once per host. Wrap reconnect refresh in a single-flight coalescer so at most one refresh runs at a time plus one queued rerun.
…eze (stablyai#8539) (stablyai#9847) On wake, remote/SSH runtimes reconnect in a staggered burst; the sidebar refetched all worktrees once per host, piling up K synchronous full-sidebar remounts and freezing the UI. Wrap the reconnect refresh in a single-flight coalescer so at most one refresh runs at a time plus one queued rerun, for any K. fetchAllWorktrees and its lineage follow-up are unchanged; only how often they fire changes. Co-authored-by: Orca <[email protected]>
What & why
Fixes the macOS "app freezes after sleep/wake, must Force-Quit" reports (#8539) for users with remote/SSH sessions.
On wake, remote/SSH runtimes reconnect in a staggered burst — each host coming back online flips
onlineRuntimeEnvKeyin the sidebar, and the reconnect effect fired a fullfetchAllWorktrees()per host. Each call bumpssortEpochfor every repo → a full sidebar + tab-tree remount. With K hosts and N repos that's K×N synchronous remounts stacked on the renderer main thread, and the window wedges. (It's then unkillable because a hung renderer vetoes the window close — that half is a separate follow-up.)This wraps the reconnect refresh in a single-flight coalescer: the first trigger refreshes immediately (unchanged from today), and any triggers that arrive while a refresh is in flight collapse into one trailing re-run. At any instant at most one refresh runs plus one queued rerun, for any K.
fetchAllWorktrees()and itsfetchWorktreeLineage()follow-up are unchanged — same data, same order, same commit path. Only how often the effect fires changes.ELI5
Your laptop wakes and 20 remote machines reconnect at once. The app used to shout "someone reconnected — reload the entire project list!" 20 times back-to-back, redrawing the whole sidebar 20 times in a row, which locked up the window. Now it says "a bunch reconnected — reload once; if more show up while I'm reloading, reload one more time after." Same end result, no lock-up.
Proof of fix
nwparker/repro-8539-wake-storm): a test against the real store shows a staggered 5-runtime wake firesfetchAllWorktrees5× with 100sortEpochbumps, vs 1× / 20 bumps for a single reconnect — an exact K× amplification with zero coalescing.single-flight-coalescer.test.ts, 6 cases): 10 requests arriving during an in-flight run → exactly 1 leading + 1 trailing run; idle requests still run individually; chained bursts, a synchronous throw, and an async rejection are all handled without wedging.Proof of no regression
fetchAllWorktrees().then(fetchWorktreeLineage)unit is coalesced as-is → lineage ordering and worktree data are identical to today; only redundant repeats are dropped.[onlineRuntimeEnvKey]; the coalescer captures thefetchAllWorktrees/fetchWorktreeLineagestore actions, which are singleton-stable in zustand (verified) — no stale-closure risk.stop()on purpose: a trailing refresh after unmount just updates the global store (harmless, and matches today's non-cancellation of in-flight refreshes), and the persistent ref avoids a React 18 StrictMode-dev pitfall.repoCounteffect is unaffected.oxlint,oxfmt, the renderer TypeScript check, and the unit tests all pass.Scope
Bug A (the freeze) only. The separate "a hung renderer makes the app unkillable" half (the window-close veto) is a follow-up PR — its save-guard state machine is safety-sensitive and shouldn't be bundled here.
Made with Orca 🐋