pub struct StorageBackedSessionStore { /* private fields */ }Expand description
A session store backed by persistent storage with an in-memory cache.
All reads hit the cache first. All writes go to both the cache and the underlying storage backend. On construction, the cache is warmed from storage to handle process restarts.
Implementations§
Source§impl StorageBackedSessionStore
impl StorageBackedSessionStore
Sourcepub async fn new(
storage: Arc<dyn StorageSessionStore>,
) -> Result<Self, StorageError>
pub async fn new( storage: Arc<dyn StorageSessionStore>, ) -> Result<Self, StorageError>
Create a new storage-backed session store.
Loads all existing sessions from storage into the in-memory cache.
Sourcepub async fn create(&self, req: CreateSessionRequest) -> TaskSession
pub async fn create(&self, req: CreateSessionRequest) -> TaskSession
Create a new task session and return it.
Sourcepub async fn use_session(
&self,
session_id: SessionId,
tool_name: &str,
) -> Result<TaskSession, SessionError>
pub async fn use_session( &self, session_id: SessionId, tool_name: &str, ) -> Result<TaskSession, SessionError>
Record a tool call against the session, checking all constraints.
Sourcepub async fn use_session_batch(
&self,
session_id: SessionId,
tool_names: &[&str],
) -> Result<TaskSession, SessionError>
pub async fn use_session_batch( &self, session_id: SessionId, tool_names: &[&str], ) -> Result<TaskSession, SessionError>
Atomically validate and record a batch of tool calls against the session.
Acquires the write lock once, validates ALL tools against
the whitelist and budget, and only increments calls_made by the full
batch count if every tool passes. If any tool fails validation, no
budget is consumed for any of them.
Sourcepub async fn close(
&self,
session_id: SessionId,
) -> Result<TaskSession, SessionError>
pub async fn close( &self, session_id: SessionId, ) -> Result<TaskSession, SessionError>
Close a session, preventing further use.
Sourcepub async fn get(
&self,
session_id: SessionId,
) -> Result<TaskSession, SessionError>
pub async fn get( &self, session_id: SessionId, ) -> Result<TaskSession, SessionError>
Get a session by ID without modifying it.
Sourcepub async fn list_all(&self) -> Vec<TaskSession>
pub async fn list_all(&self) -> Vec<TaskSession>
List all sessions currently in the store.
Sourcepub async fn count_active_for_agent(&self, agent_id: Uuid) -> u64
pub async fn count_active_for_agent(&self, agent_id: Uuid) -> u64
Count the number of active sessions for a given agent.
P0: Used to enforce per-agent concurrent session caps.
Sourcepub async fn close_sessions_for_agent(&self, agent_id: Uuid) -> usize
pub async fn close_sessions_for_agent(&self, agent_id: Uuid) -> usize
Close all active sessions belonging to a specific agent.
Called during agent deactivation.
Sourcepub async fn cleanup_expired(&self) -> usize
pub async fn cleanup_expired(&self) -> usize
Remove expired sessions from cache and storage. Returns the number removed.
Trait Implementations§
Source§impl Clone for StorageBackedSessionStore
impl Clone for StorageBackedSessionStore
Source§fn clone(&self) -> StorageBackedSessionStore
fn clone(&self) -> StorageBackedSessionStore
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more