Auto reconnect - typescript sdk - #5927
Open
aasoni wants to merge 2 commits into
Open
Conversation
aasoni
changed the base branch from
master
to
alessandro/auto-reconnect-server-side
September 11, 2026 13:31
aasoni
changed the base branch from
alessandro/auto-reconnect-server-side
to
alessandro/refuse-takeover-for-same-session-and-teardown
September 11, 2026 13:34
aasoni
force-pushed
the
alessandro/auto-reconnect-typescript-sdk
branch
from
September 11, 2026 13:41
c0eecbf to
812ee9b
Compare
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.
Description of Changes
TypeScript SDK: automatic reconnection
Builds reconnection into DbConnection itself, so the connection object, the client cache, table handles and registered callbacks all stay usable across a reconnect and applications manage no replacement objects.
withAutomaticReconnect()enables this. Losing an established connection fires onDisconnect, each failed attempt fires onConnectError, and both now report the number of and delay before the next attempt, or undefined when the SDK will not retry. Retries are unlimited with exponential backoff (1s base, 30s cap, 0.5 jitter), stopping only on disconnect(), a failed initial connection, or a reconnect under a different identity.Each reconnect is a new connection which fires onConnect again. Live subscriptions are replayed in one SubscribeBatch under fresh query set ids, and the results are reconciled against the stale cache with synthesized deletes, so rows unchanged across the outage produce no callbacks and changed rows produce ordinary update or delete callbacks.
A stable client-generated session_id is sent on every connection so the server can teardown the previous connection if still open (idle timeout didn't fire yet) before accepting a new one for the same session.
The token the server issued is saved and reused, keeping the identity stable for anonymous clients;
withTokenProvider()supplies a fresh token when the saved one is close to expiring or was rejected.Calls made while disconnected fail fast with DisconnectedError, and calls in flight when the connection dropped settle with UnknownCallResultError, since they may or may not have run.
Behavior is unchanged for connections which do not opt in.
API and ABI breaking changes
No
Rollback safety impact
Requires #5877 to have been deployed in a previous release
Expected complexity level and risk
3 - Change is limited to the typescript SDK and is opt in only (withAutomaticReconnect and withTokenProvider are the new APIs). Change is large but not overly complex.
Testing
Test app that fakes dropping connections and reconnecting and uses spacetime's own token provider to test token with expiry claim in the reconnect scenario as well.