LearnNewsExamplesServices
Frontmatter
id8177
titleHarden WebSocket Connection: Backoff & Auto-Reconnect
stateClosed
labels
enhancementaicore
assigneestobiu
createdAtDec 28, 2025, 6:57 PM
updatedAtDec 28, 2025, 7:16 PM
githubUrlhttps://github.com/neomjs/neo/issues/8177
authortobiu
commentsCount1
parentIssue8169
subIssues[]
subIssuesCompleted0
subIssuesTotal0
blockedBy[]
blocking[]
closedAtDec 28, 2025, 7:16 PM

Harden WebSocket Connection: Backoff & Auto-Reconnect

Closed v11.18.0 enhancementaicore
tobiu
tobiu commented on Dec 28, 2025, 6:57 PM

Hardening the WebSocket connection logic is critical for the Neural Link's stability, especially for self-healing scenarios.

Requirements:

  1. Exponential Backoff: Implement a backoff strategy (e.g., 1s, 2s, 4s...) in attemptReconnect to prevent server flooding.
  2. Reset Logic: Ensure reconnectAttempts is reset to 0 upon a successful connection (onOpen).
  3. Events: Fire reconnecting and reconnect_failed events for better observability.
  4. Auto-Reconnect: Trigger reconnection on abnormal closure (onClose with code != 1000), even if no message is being sent.

Target File: src/data/connection/WebSocket.mjs

Goal: Make the WebSocket connection resilient to network blips and server restarts, ensuring the App Worker reliably stays connected to the Neural Link.

tobiu added the enhancement label on Dec 28, 2025, 6:57 PM
tobiu added the ai label on Dec 28, 2025, 6:57 PM
tobiu added the core label on Dec 28, 2025, 6:57 PM
tobiu added parent issue #8169 on Dec 28, 2025, 6:58 PM
tobiu assigned to @tobiu on Dec 28, 2025, 6:59 PM
tobiu referenced in commit f437cd3 - "feat(core): Harden WebSocket connection with configurable backoff and auto-reconnect (#8177) on Dec 28, 2025, 7:15 PM
tobiu
tobiu Dec 28, 2025, 7:15 PM

Input from Gemini 3 Pro Preview:

Implementation Complete

I have hardened the WebSocket connection logic to ensure robustness and self-healing capabilities.

Key Improvements:

  1. Configurable Backoff Strategy: Added backoffStrategy to static config.

    • Default: Exponential backoff Math.min(1000 * Math.pow(2, attempt - 1), 30000) (1s, 2s, 4s... max 30s).
    • Overridable: Can be customized globally via Neo.overwrites or per-instance.
  2. Robust Cleanup:

    • Replaced standard setTimeout with await this.timeout(). This leverages Neo.core.Base's lifecycle management, ensuring pending reconnection attempts are automatically cancelled if the component is destroyed.
    • Added a safety check !me.isDestroyed after the timeout resolves.
  3. Self-Healing:

    • onOpen: Resets reconnectAttempts to 0, providing a fresh retry budget for future disconnects.
    • onClose: Automatically triggers attemptReconnect if the socket closed abnormally (code != 1000), covering server restarts and network drops.
  4. Observability:

    • Added reconnecting event (payload: {attempt, maxAttempts, delay}).
    • Added reconnect_failed event.

This ensures the App Worker maintains a reliable, persistent connection to the Neural Link server.

tobiu closed this issue on Dec 28, 2025, 7:16 PM