fix(realtime): refresh tokens in background without dropping the WebSocket connection#200
Merged
noahgsolomon merged 3 commits intomainfrom Feb 25, 2026
Merged
Conversation
…ocket connection The active state had no handler for token expiry, so the scheduled expireToken event was silently dropped and tokens were never refreshed. Instead of tearing down and reconnecting, proactively fetch a fresh token at 90% of its lifetime and update the stored token in-place via a new authenticated transition in the active state. The WebSocket stays open and the fresh token is ready for any future reconnection. Includes retry logic if a background refresh fails.
d7e2baa to
0c3a73a
Compare
drochetti
approved these changes
Feb 25, 2026
Add guards to skip token refresh operations if the state machine is not in the active state. Prevents stale callbacks from spawning parallel refresh loops or sending events after disconnect. Co-authored-by: Cursor <cursoragent@cursor.com>
dazip
approved these changes
Feb 25, 2026
Replace machine.current checks with a generation counter because robot3 creates new machine objects on each transition, making closure-captured references stale.
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.
dqwdqd.mp4
The active state had no handler for token expiry, so the scheduled expireToken event was silently dropped and tokens were never refreshed. Instead of tearing down and reconnecting, proactively fetch a fresh token at 90% of its lifetime and update the stored token in-place via a new authenticated transition in the active state. The WebSocket stays open and the fresh token is ready for any future reconnection. Includes retry logic if a background refresh fails.