Repository navigation
perf(web): pause the runtime heartbeat while the window is hidden - #9883
Conversation
📝 WalkthroughWalkthroughThe WebSocket heartbeat now uses a visibility-aware interval with explicit cleanup. When the document becomes visible, heartbeat timestamps and pending probe state are re-baselined. Tests add deterministic timer and document-event mocks and cover hidden intervals, visibility restoration, stale-gap handling, visible cadence, and cleanup on client close. 🚥 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 |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/renderer/src/web/web-runtime-client.ts (1)
767-787: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd a "why" comment for the non-obvious
runOnVisibleinstall-time semantics.
installWindowVisibilityIntervalinvokesrunOnVisiblesynchronously not only on hidden→visible transitions but also immediately on everystartHeartbeat()install (perstart()inwindow-visibility-interval.ts). That meansrebaselineHeartbeat()fires on every fresh connect/reconnect too, not just after being hidden — non-obvious from readingstartHeartbeat()/rebaselineHeartbeat()alone.📝 Suggested comment
private startHeartbeat(): void { this.clearHeartbeatTimer() + // Why: runOnVisible fires both on this initial install (while visible) and on every + // hidden→visible transition, so rebaselineHeartbeat() also runs on fresh connects — + // harmless since those timestamps are already fresh from the handshake. this.heartbeatCleanup = installWindowVisibilityInterval({ run: () => this.runHeartbeatTick(), runOnVisible: () => this.rebaselineHeartbeat(), intervalMs: HEARTBEAT_INTERVAL_MS }) }As per coding guidelines,
**/*.{ts,tsx}: "For non-obvious TypeScript code, add a concise comment explaining why the constraint exists, not how the code works."Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 14d90801-941f-4fa3-bb4e-a3d9d0068e95
📒 Files selected for processing (2)
src/renderer/src/web/web-runtime-client-heartbeat.test.tssrc/renderer/src/web/web-runtime-client.ts
Co-authored-by: Orca <[email protected]>
…t re-arm The visible re-arm rebaselined lastInboundFrameAt=now, so a socket that went silent while the window was hidden looked freshly-heard-from and its death was masked for another full idle window (~25s). Move the fresh-connect baseline into startHeartbeat (the real 'we just connected' moment) and have the visible re-arm only reset the tick clock + clear an in-flight probe, preserving lastInboundFrameAt so the next visible tick probes a stale connection promptly and closes if unanswered. Co-authored-by: Orca <[email protected]>
d2aecfd to
8141b2e
Compare
…ablyai#9883) * perf(web): pause runtime heartbeat while hidden Co-authored-by: Orca <[email protected]> * fix(web): preserve inbound-liveness baseline across a hidden heartbeat re-arm The visible re-arm rebaselined lastInboundFrameAt=now, so a socket that went silent while the window was hidden looked freshly-heard-from and its death was masked for another full idle window (~25s). Move the fresh-connect baseline into startHeartbeat (the real 'we just connected' moment) and have the visible re-arm only reset the tick clock + clear an in-flight probe, preserving lastInboundFrameAt so the next visible tick probes a stale connection promptly and closes if unanswered. Co-authored-by: Orca <[email protected]> --------- Co-authored-by: Orca <[email protected]>
What
The web-runtime client (browser-paired runtime) kept a 10s heartbeat interval armed even while the window was hidden — waking every 10s to do nothing (~0.1 renderer wakeups/sec wasted while hidden).
Fix: route the heartbeat through
installWindowVisibilityIntervalso it stops while the window is hidden and re-arms on becoming visible. On re-arm it rebaselines liveness (lastInboundFrameAt/lastHeartbeatTickAt/ outstanding-probe timestamp) so a long hidden gap isn't misread as a dead connection. The visible-idle probe cadence (~one every ~30s, from the 10s tick + 25s idle threshold) is unchanged.ELI5
When Orca's browser-paired runtime connection was open but the window was hidden, it kept pinging every 10 seconds to check the connection was alive. Now it pauses while hidden and, when you come back, first re-syncs its "last seen" clock so it doesn't wrongly think the connection died while you were away.
Proof of zero regression
lastInboundFrameAtregardless of visibility.web-runtime-client-heartbeat.test.ts12/12 — hidden disarm, visible re-arm + rebaseline, rapid-toggle single-arm, no false dead connection after a long hidden gap, unchanged visible cadence, teardown cleanup.typecheck:webclean.Proof of perf improvement
Removes ~0.1 renderer wakeups/sec while the window is hidden with a web-runtime connection open; the tests assert the interval is disarmed while hidden and re-armed (with rebaseline) on visible.
Made with Orca 🐋