Skip to Content

State Machine

Session phases and transitions.

Phases

created → pending → active → complete → failed → expired

Transitions

FromToTrigger
createdpendingFirst WebSocket connection (client or worker)
createdexpiredSession timeout before any connection
pendingactiveSecond WebSocket connection (both roles connected)
pendingfailedWorker sends worker.fail or unrecoverable error
pendingexpiredSession timeout with only one side connected
activecompleteWorker sends worker.complete
activefailedWorker sends worker.fail or unrecoverable error
activeexpiredSession timeout (alarm)

Connection flags

Connection state is tracked separately from phase:

  • clientConnected — Whether the client SDK is currently connected
  • workerConnected — 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

Last updated on