feat(realtime): resilient realtime transport — unified reconnection, heartbeat and backpressure - #1145
Merged
RUKAYAT-CODER merged 1 commit intoAug 21, 2026
Conversation
…beat and backpressure (rinafcode#1143) Introduce a transport-agnostic ConnectionSupervisor (src/lib/realtime/connectionSupervisor.ts) that all realtime transports delegate their lifecycle to: exponential backoff with full jitter, shared heartbeat with ping-timeout detection, a bounded outbound queue with documented drop-oldest/block backpressure, inbound sequence tracking with catch-up, a resubscribe registry for rooms/subscriptions, and reconnection metrics plus alerts with graceful degradation to offline mode via the service worker. Refactor socket.io (websocketManager), the notification WebSocket and GraphQL subscriptions to use the supervisor, expose a single useRealtimeConnection status object adopted by useWebSocket, useCollaboration and useRealTimeAnalytics, and wire the synchronization engine to backfill state after a reconnect gap.
Contributor
|
Thank you for contributing to the project. |
zakariyaufarida5-wq
added a commit
to zakariyaufarida5-wq/teachLink_web
that referenced
this pull request
Aug 21, 2026
…concile sync engine Keeps the deterministic offline-sync reconciliation while adopting the realtime reconnect catch-up broadcast added in rinafcode#1143/rinafcode#1145.
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.
Summary
This PR resolves #1143 — a cross-cutting refactor of the realtime layer.
The realtime layer was fragmented across three independent implementations (
src/lib/websocketManager.ts,src/lib/notifications/socket.ts,src/lib/graphql/subscriptions.ts), each with its own connect/reconnect loop, inconsistent backoff, no shared heartbeat and no backpressure. Messages emitted while disconnected were silently dropped, and store convergence could permanently miss events from the reconnect gap.Changes
src/lib/realtime/connectionSupervisor.ts(new): transport-agnosticConnectionSupervisorproviding a unified lifecycle — connect, exponential backoff with full jitter, heartbeat with ping-timeout detection, a single unifiedConnectionStatusshape, a bounded outbound queue with documenteddrop-oldest/blockbackpressure, inbound sequence tracking with catch-up, a resubscribe registry, and reconnection metrics (reconnect_attempt,reconnect_success,heartbeat_timeout,queue_dropped,realtime_offline) with an alert threshold. Once max attempts are exceeded it degrades to offline mode, signalled through the service worker.src/lib/websocketManager.ts: delegates connect/reconnect/heartbeat/queue to the supervisor; addssend()(queued, ordered) andjoinRoom()(auto re-join after reconnect) while keeping the existing public API.src/lib/notifications/socket.ts: delegates lifecycle to the supervisor; same public API and status shape.src/lib/graphql/subscriptions.ts: drives the graphql-ws socket through the supervisor with lazy connect and automatic re-subscribe of registered subscriptions after reconnect; exposessubscribeRealtime().src/hooks/useRealtimeConnection.ts(new): single unified connection status hook, adopted byuseWebSocket,useCollaborationanduseRealTimeAnalytics.src/store/synchronizationEngine.ts: consumes the supervisor'sonReconnectcatch-up hook to re-broadcast state after a reconnect gap.src/lib/monitoring/metrics.ts/alerts.ts: realtime metric helper and alert on repeated reconnect failure / heartbeat timeout.src/serviceWorker.ts+public/sw.js: handle theREALTIME_OFFLINEsignal and broadcast it to clients.src/constants/app.constants.ts: realtime constants (backoff, heartbeat, queue, offline event).src/lib/realtime/__tests__/connectionSupervisor.test.tscovering backoff-with-jitter scheduling, heartbeat-timeout-triggered reconnect, queue flush ordering, drop-oldest/block policies, sequence-gap catch-up, resubscribe after a drop, and offline degradation. Also fixed a pre-existing mock constructibility bug insrc/lib/graphql/subscriptions.test.tsthat failed under Node 24.Acceptance criteria
Closes #1143