Repository navigation
perf(runtime): arm the WS-server heartbeat only while clients are connected - #9885
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughWebSocket heartbeat management now tracks active connections and starts monitoring when the first connection arrives. It seeds connection liveness, stops monitoring after the final connection closes, and clears tracking during shutdown. Heartbeat startup performs an immediate probe. Tests cover timer lifecycle, idempotent error and close cleanup, repeated probing, and termination of an unresponsive client. 🚥 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 |
Co-authored-by: Orca <help@stably.ai>
Arming the heartbeat on the first accepted connection started a fresh interval, so the first liveness ping was a full interval (~15s) out — a socket that died right after connecting went unprobed for that window. Run one sweep synchronously in start() so the first ping goes out at arm time; the seeded socket is pinged (never reaped on the arm sweep) and reaped on the next tick only if it never pongs. Tests updated for the earlier first probe. Co-authored-by: Orca <help@stably.ai>
6413052 to
282938f
Compare
…nected (stablyai#9885) * perf(runtime): idle websocket heartbeat without clients Co-authored-by: Orca <help@stably.ai> * fix(runtime): probe immediately when the WS heartbeat arms Arming the heartbeat on the first accepted connection started a fresh interval, so the first liveness ping was a full interval (~15s) out — a socket that died right after connecting went unprobed for that window. Run one sweep synchronously in start() so the first ping goes out at arm time; the seeded socket is pinged (never reaped on the arm sweep) and reaped on the next tick only if it never pongs. Tests updated for the earlier first probe. Co-authored-by: Orca <help@stably.ai> --------- Co-authored-by: Orca <help@stably.ai>
What
The runtime WebSocket server (
orca serve/ a paired runtime host) started a 15s heartbeat interval as soon as it began listening and kept it firing forever — even with zero connected clients, sweeping an empty client set every 15s (~0.067 main-process wakeups/sec wasted whenever the server listens with no phone/client attached).Fix: arm the heartbeat on the first accepted connection (0→1) and stop it after the last one closes (1→0). A
heartbeatConnectionsset tracks accepted sockets; each socket is seeded alive before arming so a fresh first socket survives its initial sweep. Transport shutdown stops the heartbeat and clears the set. Thewss.clientssweep authority while armed is unchanged.ELI5
The host kept doing a 15-second "everyone still there?" roll call even when nobody was connected. Now the roll call only runs while at least one device is actually connected.
Proof of zero regression
wss.clients).noteAlive'd at accept.ws-transport.test.ts+remote-runtime-server-heartbeat.test.ts— zero-client idle (no timer), first-client arm + alive seed, no double-arm on subsequent clients, last-client stop, re-arm after reconnect, error/close race finalization, and unchanged dead-client detection with ≥1 client.typecheck:nodeclean.Proof of perf improvement
Removes 0.067 main-process wakeups/sec whenever the runtime server is listening with no client attached (the common
orca serveidle state) — the tests assert no interval is armed with zero connections.Made with Orca 🐋