-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Simplify and harden session lifecycle with an explicit state machine #1691
Copy link
Copy link
Open
Labels
P2Moderate issues affecting some users, edge cases, potentially valuable featureModerate issues affecting some users, edge cases, potentially valuable featureenhancementRequest for a new feature that's not currently supportedRequest for a new feature that's not currently supportedv2Ideas, requests and plans for v2 of the SDK which will incorporate major changes and fixesIdeas, requests and plans for v2 of the SDK which will incorporate major changes and fixes
Metadata
Metadata
Assignees
Labels
P2Moderate issues affecting some users, edge cases, potentially valuable featureModerate issues affecting some users, edge cases, potentially valuable featureenhancementRequest for a new feature that's not currently supportedRequest for a new feature that's not currently supportedv2Ideas, requests and plans for v2 of the SDK which will incorporate major changes and fixesIdeas, requests and plans for v2 of the SDK which will incorporate major changes and fixes
Description
Summary
Server and client sessions use an internal initialization state machine combined with various flags and manual
AsyncExitStackmanagement. Stateless mode complicates this further by setting an "Initialized" state early as a workaround.This makes the lifecycle hard to reason about and contributes to subtle bugs (e.g., past issues like #756 in stateless mode).
Problems
Proposal
Introduce an explicit session state machine
Represent distinct states as separate types, for example:
UninitializedSessionNegotiatingSessionActiveSessionClosedSessionStatelessSession(for per-request / ephemeral cases)Each state exposes only the operations that are valid in that state, and transitions return the next state type.
Model stateless mode explicitly
StatelessSessiontype with a simpler lifecycle.Centralize resource cleanup
AsyncExitStack.Why this matters
Acceptance criteria
References
No response