feat: adaptive WebSocket reconnection with full-jitter backoff. - #81
Merged
elizabetheonoja-art merged 1 commit intoJun 25, 2026
Conversation
…icky recovery (Utility-Protocol#57) Adds an adaptive reconnection stratum for the real-time dashboard WebSocket so a failure cascade costs the operator at most ~3s of data loss instead of a retry storm and lost subscription state. - types/connection.ts: invariants (500ms→30s backoff, 12-attempt cap, 15s/5s heartbeat, 500-frame buffer) plus state/event and recovery-frame types - utils/backoff.ts: capped exponential with AWS full-jitter (overflow-safe) - utils/frameBuffer.ts: 500-slot ring buffer for telemetry replay - services/reconnectMachine.ts: custom FSM (idle/connecting/connected/ reconnecting/recovering/failed) computing the next jittered delay - store/slices/connectionSlice.ts: connection store + useConnectionState hook, with green/yellow/red quality derivation - hooks/useWebSocket.ts: delegates lifecycle to the machine — full-jitter reconnect scheduling, heartbeat ping/pong watchdog, sticky nodeId in sessionStorage, recovery handshake (recovery/recovery_ack) and REST backfill - components/panels/ConnectionStatusBar.tsx: fixed quality bar + terminal-failure banner with retry - unit tests (backoff, frameBuffer, machine, slice) + a fake-socket/fake-timer hook test covering connect, ping/pong, reconnect+recovery+backfill, heartbeat timeout and terminal failure
elizabetheonoja-art
approved these changes
Jun 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adaptive WebSocket Reconnection Stratum (#57)
Closes #57
src/types/connection.tssrc/utils/backoff.tsbackoffCeiling+fullJitterBackoff— AWS-style full jitter (random(0, min(cap, base·2^n))), overflow-safe, injectable RNG.src/utils/frameBuffer.tspush/toArray/drain, evicts oldest, preserves the high-water sequence id across drains.src/services/reconnectMachine.tsidle → connecting → connectedwithreconnecting / recovering / failedbranches; computes the next jittered delay and declares terminal failure after 12 attempts. Pure transitions (the hook owns the timers) → fully unit-testable.src/store/slices/connectionSlice.tsuseConnectionStatehook, with green/yellow/red quality derivation.src/hooks/useWebSocket.tsnodeIdinsessionStorage, recovery handshake (recovery→recovery_ack) replaying the buffer, and REST backfill (GET /ws/replay?from=&to=) when frames were missed. Injectable transport/clock/RNG/storage.src/components/panels/ConnectionStatusBar.tsxtests/unit/*+tests/hooks/useWebSocket.test.ts