Heuristic:Openclaw Openclaw WebSocket Reconnection And Session Cleanup
| Knowledge Sources | |
|---|---|
| Domains | WebSocket, Connection_Management, Session_Cleanup |
| Last Updated | 2026-02-06 12:00 GMT |
Overview
A reconnection and session cleanup heuristic for WebSocket connections between the Chrome Extension service worker and the Gateway relay server.
Description
When the WebSocket connection between the Chrome Extension background script and the Gateway relay drops (server restart, network disruption, extension service worker suspension), the extension applies a reconnection strategy with exponential backoff and cleans up stale session state.
Reconnection strategy:
- On close or error, attempt reconnection after a delay.
- First retry delay: 500ms, doubling each attempt up to a maximum of 30 seconds.
- On successful reconnection, re-attach any previously connected tabs and re-register sessions with the relay.
Session cleanup:
- When a tab is closed or navigated away, the associated CDP session is detached and removed from internal maps.
- When the relay connection drops, all session state is marked as disconnected (badge shows OFF).
- On reconnection, stale sessions (tabs that closed during disconnection) are pruned before re-attaching active tabs.
Applicability
This heuristic applies to any long-lived WebSocket connection where the server side may restart independently of the client, particularly:
- Chrome Extension service workers (which Chrome may suspend/terminate)
- Gateway relay connections from browser automation tools
- Any bidirectional proxy that maintains session-to-target mappings
Theoretical Basis
Exponential backoff with ceiling: Standard pattern for reconnection to avoid thundering herd on server restart. The ceiling (30s) prevents excessive wait times while the backoff prevents connection storms.
Eager cleanup, lazy re-attach: Sessions are cleaned up immediately on disconnect but re-established lazily (only tabs that are still open get re-attached). This prevents phantom sessions from accumulating.