State Machine
Session phases and transitions.
Phases
created → pending → active → complete
→ failed
→ expiredTransitions
| From | To | Trigger |
|---|---|---|
created | pending | First WebSocket connection (client or worker) |
created | expired | Session timeout before any connection |
pending | active | Second WebSocket connection (both roles connected) |
pending | failed | Worker sends worker.fail or unrecoverable error |
pending | expired | Session timeout with only one side connected |
active | complete | Worker sends worker.complete |
active | failed | Worker sends worker.fail or unrecoverable error |
active | expired | Session timeout (alarm) |
Connection flags
Connection state is tracked separately from phase:
clientConnected— Whether the client SDK is currently connectedworkerConnected— Whether the worker is currently connected
A disconnection does not change the phase. The session remains in its current phase until a terminal transition occurs.
Terminal states
complete, failed, and expired are terminal. Once a session reaches a terminal state:
- No further commands are accepted
- WebSocket connections may be closed
- The session state is preserved for retrieval
Next steps
- Sessions — Session lifecycle overview
- WebSocket Connection — Connection management
Last updated on