Skip to content

Add automatic WebSocket reconnection with exponential backoff #595

@EhabY

Description

@EhabY

WebSocket streams occasionally drop due to client network loss or server-side interruptions. Today, many parts of the app rely on one-way WebSockets for push updates, and a closed socket isn’t re-established unless the user refreshes the window. This leads to stale UIs (e.g., the agent metadata status bar showing an unknown error) until a manual reload.

2025-09-25 17:27:02.604 [warning] Failed to query metadata: WebSocket closed unexpectedly: undefined undefined

Proposal:
Introduce an automatic reconnection policy for all one-way WebSocket clients:

  • Reconnect with exponential backoff + jitter, capped (e.g., 250ms → 1s → 2s … up to 30s).
  • Stop retrying on non-recoverable close codes (auth errors, 4xx) and surface a clear message.
  • Resume prior subscriptions/state on reconnect; reset backoff after stable activity.
  • Log reconnection attempts.

Expected outcome:
Sockets recover transparently from transient failures; users don’t need to refresh to restore live updates.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions