Ignore stale WebSocket lifecycle events after reconnect#2372
Conversation
- Gate protocol lifecycle callbacks on the active session - Prevent old sockets from mutating connection state after reconnect - Add regression coverage for stale close handling
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
ApprovabilityVerdict: Approved Straightforward bug fix that adds session ID tracking to prevent stale WebSocket lifecycle events from being processed after reconnection. The change is self-contained, includes comprehensive tests, and has no side effects outside the WebSocket transport layer. You can customize Macroscope's approvability policy. Learn more. |
What Changed
Why
UI Changes
Checklist
Note
Medium Risk
Touches core WebSocket transport/protocol lifecycle handling and reconnect behavior; a mistake could suppress legitimate connection state updates or mask errors.
Overview
Prevents old WebSocket sessions from updating connection/error state after a
WsTransport.reconnect()by introducing anisActiveguard on protocol lifecycle callbacks.WsTransportnow assigns a per-session id and passes anisActivepredicate intocreateWsRpcProtocolLayer, while tests add regression coverage ensuring a stale socketclosedoes not triggeronCloseor overwrite the current connection status.Reviewed by Cursor Bugbot for commit 3f6bcd8. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Ignore stale WebSocket lifecycle events after reconnect in
WsTransportnextSessionId/activeSessionId) inWsTransportso each connection attempt gets a unique session ID.isActive(): booleanhook to theWsProtocolLifecycleHandlersinterface inprotocol.ts;onAttempt,onOpen,onError, andonCloseare skipped whenisActive()returns false.isActivereturns false, so any late-arriving lifecycle events (e.g. aclosefrom the old socket) are silently ignored instead of mutating connection state.onClosecalls from updating connection status after a reconnect.Macroscope summarized 3f6bcd8.