feat: Expose TokenManager with lifecycle APIs for session management#6126
Open
timon0305 wants to merge 2 commits intoreflex-dev:mainfrom
Open
feat: Expose TokenManager with lifecycle APIs for session management#6126timon0305 wants to merge 2 commits intoreflex-dev:mainfrom
timon0305 wants to merge 2 commits intoreflex-dev:mainfrom
Conversation
Contributor
Greptile OverviewGreptile SummaryThis PR exposes Key integration point is Confidence Score: 3/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Client
participant SIO as EventNamespace
participant TM as TokenManager
Client->>SIO: websocket connect (sid, token in query)
alt token provided
SIO->>TM: link_token_to_sid(token, sid)
SIO->>TM: _notify_connect(actual_token, sid)
else no token
SIO-->>Client: warn (no token)
end
Note over Client,SIO: During session lifetime, app may run background events
Client->>SIO: websocket disconnect (sid)
SIO->>TM: _notify_disconnect(disconnect_token, sid)
SIO->>TM: disconnect_token(disconnect_token, sid) (async task)
TM-->>TM: remove token<->sid mappings
|
masenf
reviewed
Feb 12, 2026
Collaborator
masenf
left a comment
There was a problem hiding this comment.
this is good, but lets remove the on token connect methods for now, since they won't work reliably across instances
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.
All Submissions:
Type of change
New Feature Submission:
Changes To Core Features:
Description
Exposes
rx.get_token_manager()with new lifecycle APIs for handling client/session lifecycle within background events, as requested in #5669.New APIs on
TokenManager:session_is_connected(sid)token_is_connected(client_token)when_session_disconnects(sid)asyncio.Eventset on disconnectwhen_token_disconnects(client_token)asyncio.Eventset on disconnectwhen_token_connects(client_token)asyncio.Eventset on connectPublic accessor:
rx.get_token_manager()— returns the activeTokenManageror raisesRuntimeErrorFiles changed (4):
reflex/utils/token_manager.py— Added lifecycle methods, notification hooks,get_token_manager(), and_TokenNotConnectedErrorreflex/app.py— Wired_notify_connect()/_notify_disconnect()intoEventNamespace.on_connect/on_disconnectreflex/__init__.py— Exposedget_token_managervia lazy loader mappingtests/units/utils/test_token_manager.py— Added 19 new tests covering all lifecycle APIsExample usage:
Test results:
closes #5669