@kaged/session-manager
Pure state machines for session and run lifecycles with limits, error types, and side-effect declarations consumed by the daemon's interpret-effects layer
6
source files
3
test files
~1.8k
lines
✓ 115 pass
tests
pass
typecheck
clean
lint
Test results 115
DEFAULT_SESSION_LIMITS > matches spec defaults
[0.060ms]
checkSessionCreationLimits > allows when both counts are below limits
[0.090ms]
checkSessionCreationLimits > allows at one below project limit
[0.040ms]
checkSessionCreationLimits > throws at project limit
[0.120ms]
checkSessionCreationLimits > throws at operator limit
[0.060ms]
checkSessionCreationLimits > throws above project limit
[0.050ms]
checkSessionCreationLimits > project limit checked first
[0.080ms]
checkSessionCreationLimits > error includes resource, limit, and current
[0.060ms]
checkSessionCreationLimits > respects custom limits
[0.060ms]
checkRunCreationLimits > allows when no active runs
[0.050ms]
checkRunCreationLimits > throws at limit (v0: 1 run per session)
[0.040ms]
checkRunCreationLimits > error resource is runs_per_session
[0.050ms]
checkPtyLimits > allows below limit
[0.050ms]
checkPtyLimits > throws at limit
[0.040ms]
checkPtyLimits > error resource is ptys_per_session
[0.040ms]
checkCheckpointLimits > allows below limit
[0.050ms]
checkCheckpointLimits > throws at limit
[0.030ms]
checkCheckpointLimits > error resource is checkpoints_per_session
[0.050ms]
checkConcurrencyAtSend > allows when both counts are below limits
[0.050ms]
checkConcurrencyAtSend > allows at one below limits
[0.020ms]
checkConcurrencyAtSend > throttled at project limit
[0.030ms]
checkConcurrencyAtSend > throttled at operator limit
[0.030ms]
checkConcurrencyAtSend > project limit checked first
[0.020ms]
checkConcurrencyAtSend > respects custom limits
[0.040ms]
checkConcurrencyAtSend > zero limits throttle immediately
[0.020ms]
LimitExceededError message format > includes resource and counts
[0.030ms]
createRun > creates run in pending state
[0.090ms]
createRun > sets all fields from input
[0.060ms]
run transitions: pending → running (start) > pending + start → running
[0.080ms]
run transitions: pending → running (start) > emits start_processing and emit_run_state
[0.040ms]
run transitions: pending → running (start) > running + start → TransitionError
[0.080ms]
run transitions: pending → running (start) > done + start → TransitionError
[0.030ms]
run transitions: running → done (complete) > running + complete → done
[0.050ms]
run transitions: running → done (complete) > emits persist_completion and emit_run_state
[0.030ms]
run transitions: running → done (complete) > pending + complete → TransitionError
[0.030ms]
run transitions: running → failed (fail) > running + fail → failed
[0.050ms]
run transitions: running → failed (fail) > emits persist_failure with error and emit_run_state
[0.030ms]
run transitions: running → failed (fail) > pending + fail → TransitionError
[0.030ms]
run transitions: running → failed (fail) > done + fail → TransitionError
[0.030ms]
run transitions: running → cancelled (cancel) > running + cancel → cancelled
[0.040ms]
run transitions: running → cancelled (cancel) > emits abort_llm_request, kill_run_subagents, persist_cancellation, emit_run_state
[0.030ms]
run transitions: running → cancelled (cancel) > pending + cancel → TransitionError
[0.030ms]
run transitions: running → cancelled (cancel) > done + cancel → TransitionError
[0.020ms]
run transitions: running → cancelled (cancel) > cancelled + cancel → TransitionError
[0.030ms]
run state machine: terminal states reject all events > done + start → TransitionError
[0.030ms]
run state machine: terminal states reject all events > done + complete → TransitionError
[0.010ms]
run state machine: terminal states reject all events > done + fail → TransitionError
[0.010ms]
run state machine: terminal states reject all events > done + cancel → TransitionError
[0.010ms]
run state machine: terminal states reject all events > failed + start → TransitionError
[0.010ms]
run state machine: terminal states reject all events > failed + complete → TransitionError
[0.010ms]
run state machine: terminal states reject all events > failed + fail → TransitionError
[0.010ms]
run state machine: terminal states reject all events > failed + cancel → TransitionError
[0.010ms]
run state machine: terminal states reject all events > cancelled + start → TransitionError
[0.010ms]
run state machine: terminal states reject all events > cancelled + complete → TransitionError
[0.010ms]
run state machine: terminal states reject all events > cancelled + fail → TransitionError
[0.010ms]
run state machine: terminal states reject all events > cancelled + cancel → TransitionError
[0.010ms]
run state machine: full lifecycle > pending → running → done
[0.030ms]
run state machine: full lifecycle > pending → running → failed
[0.030ms]
run state machine: full lifecycle > pending → running → cancelled
[0.120ms]
createSession > creates session in idle state
[0.120ms]
createSession > sets all fields from input
[0.060ms]
createSession > forkedFrom defaults to null
[0.030ms]
createSession > emits session_created side effect
[0.030ms]
session transitions: idle → running (post_message) > idle + post_message → running
[0.100ms]
session transitions: idle → running (post_message) > emits create_run, start_primary, emit_state
[0.030ms]
session transitions: idle → running (post_message) > running + post_message → TransitionError (409 conflict)
[0.080ms]
session transitions: idle → running (post_message) > queued + post_message → TransitionError (cannot post while queued)
[0.060ms]
session transitions: idle → running (post_message) > paused + post_message → TransitionError
[0.030ms]
session transitions: idle → running (post_message) > ended + post_message → TransitionError
[0.030ms]
session transitions: idle → running (post_message) > failed + post_message → TransitionError
[0.030ms]
session transitions: idle → queued (queue) > idle + queue → queued
[0.050ms]
session transitions: idle → queued (queue) > emits create_run, emit_state
[0.030ms]
session transitions: idle → queued (queue) > running + queue → TransitionError
[0.030ms]
session transitions: idle → queued (queue) > queued + queue → TransitionError
[0.030ms]
session transitions: queued → running (resume_from_queue) > queued + resume_from_queue → running
[0.050ms]
session transitions: queued → running (resume_from_queue) > emits start_primary, emit_state
[0.020ms]
session transitions: queued → running (resume_from_queue) > idle + resume_from_queue → TransitionError
[0.030ms]
session transitions: queued → running (resume_from_queue) > paused + resume_from_queue → TransitionError
[0.030ms]
session transitions: queued → idle (discard_queue) > queued + discard_queue → idle
[0.040ms]
session transitions: queued → idle (discard_queue) > emits cancel_queued_run, supersede_queued_message, emit_state
[0.040ms]
session transitions: queued → idle (discard_queue) > idle + discard_queue → TransitionError
[0.040ms]
session transitions: running → idle (run_completed) > running + run_completed → idle
[0.040ms]
session transitions: running → idle (run_completed) > emits persist_run_result, flush_ws_buffers, emit_state
[0.030ms]
session transitions: running → idle (run_completed) > idle + run_completed → TransitionError
[0.030ms]
session transitions: running → paused (checkpoint) > running + checkpoint → paused
[0.050ms]
session transitions: running → paused (checkpoint) > emits suspend_subagents, capture_checkpoint, emit_state
[0.030ms]
session transitions: running → paused (checkpoint) > model-initiated checkpoint carries reason
[0.100ms]
session transitions: running → paused (checkpoint) > idle + checkpoint → TransitionError
[0.150ms]
session transitions: paused → running/idle (resume) > paused + resume with pending work → running
[0.150ms]
session transitions: paused → running/idle (resume) > resume with pending work emits resume_subagents
[0.090ms]
session transitions: paused → running/idle (resume) > paused + resume with no pending work → idle
[0.030ms]
session transitions: paused → running/idle (resume) > resume with edited prompts emits apply_prompt_edits (pending work)
[0.030ms]
session transitions: paused → running/idle (resume) > resume with edited prompts emits apply_prompt_edits (no pending work)
[0.020ms]
session transitions: paused → running/idle (resume) > idle + resume → TransitionError
[0.050ms]
session transitions: paused → idle (rollback) > paused + rollback → idle
[0.060ms]
session transitions: paused → idle (rollback) > emits kill_post_checkpoint_subagents, supersede_messages_after, emit_state
[0.030ms]
session transitions: paused → idle (rollback) > idle + rollback → TransitionError
[0.050ms]
session transitions: paused → idle (rollback) > running + rollback → TransitionError
[0.030ms]
session transitions: any → ended (end) > idle + end → ended
[0.050ms]
session transitions: any → ended (end) > running + end → ended
[0.010ms]
session transitions: any → ended (end) > paused + end → ended
[0ms]
session transitions: any → ended (end) > failed + end → ended
[0ms]
session transitions: any → ended (end) > end emits kill_subagents, persist_final_state, close_websocket, emit_state
[0.030ms]
session transitions: any → ended (end) > ended + end → TransitionError
[0.030ms]
session transitions: any → failed (fail) > idle + fail → failed
[0.050ms]
session transitions: any → failed (fail) > running + fail → failed
[0.010ms]
session transitions: any → failed (fail) > paused + fail → failed
[0ms]
session transitions: any → failed (fail) > failed + fail → failed
[0ms]
session transitions: any → failed (fail) > fail emits kill_subagents, persist_failure, close_websocket, emit_state
[0.030ms]
session transitions: any → failed (fail) > ended + fail → TransitionError
[0.040ms]
session state machine: multi-step sequences > full lifecycle: create → message → complete → end
[0.060ms]
session state machine: multi-step sequences > checkpoint flow: running → paused → resume → running → complete → idle
[0.050ms]
session state machine: multi-step sequences > rollback flow: running → paused → rollback → idle → message → running
[0.040ms]
session state machine: multi-step sequences > crash recovery: running → fail
[0.030ms]
TransitionError properties > includes from state and event type
[0.060ms]