pub struct SessionState {
pub id: String,
pub created_at: String,
pub title: Option<String>,
pub runtime: Arc<Mutex<AgentRuntime>>,
pub plan_approval_gate: Arc<PlanApprovalGate>,
pub interrupt_token: Arc<Mutex<Option<CancellationToken>>>,
pub non_system_message_count: Arc<AtomicUsize>,
pub last_active_ms: Arc<AtomicU64>,
pub prompt_tokens: Arc<AtomicU64>,
pub completion_tokens: Arc<AtomicU64>,
}Expand description
Internal session state (not directly serialized to clients).
The AgentRuntime owns the transcript; this struct adds HTTP-layer
metadata (id, created_at) and the broadcast channel for SSE clients.
Fields§
§id: String§created_at: String§title: Option<String>Optional human-readable title, settable via PATCH /sessions/:id.
runtime: Arc<Mutex<AgentRuntime>>Runtime is wrapped in a per-session Mutex so concurrent HTTP requests for the same session are serialized without blocking the global lock.
plan_approval_gate: Arc<PlanApprovalGate>Shared gate for plan-mode approval. Stored here so HTTP handlers can approve/reject without taking the runtime Mutex (which may be held by a running agent turn).
interrupt_token: Arc<Mutex<Option<CancellationToken>>>Goal-170: cancellation token for the currently running agent turn.
POST /sessions/:id/interrupt cancels this token, which causes
the kernel to exit with FinishReason::Cancelled at the next step
boundary. Replaced with a fresh token at the start of every turn.
non_system_message_count: Arc<AtomicUsize>Approximate non-system message count, updated atomically as messages
are appended. Allows list_sessions to read the count without taking
the runtime Mutex (which may be held by a running agent turn).
last_active_ms: Arc<AtomicU64>Milliseconds since [SESSION_EPOCH] when this session was last active.
Updated atomically on every message. Used by the session reaper.
prompt_tokens: Arc<AtomicU64>Cumulative prompt tokens consumed in this session (all turns combined).
completion_tokens: Arc<AtomicU64>Cumulative completion tokens generated in this session.