pub struct SessionStore {
pub session_queue: Arc<SessionActorQueue>,
/* private fields */
}Fields§
§session_queue: Arc<SessionActorQueue>Implementations§
Source§impl SessionStore
impl SessionStore
pub fn new(max_sessions: usize, session_queue: Arc<SessionActorQueue>) -> Self
pub async fn insert( &self, id: String, session: RpcSession, ) -> Result<(), &'static str>
pub async fn get_agent(&self, id: &str) -> Option<Arc<Mutex<Agent>>>
pub async fn touch(&self, id: &str)
Sourcepub async fn set_overrides(
&self,
id: &str,
patch: SessionOverrides,
) -> Option<SessionOverrides>
pub async fn set_overrides( &self, id: &str, patch: SessionOverrides, ) -> Option<SessionOverrides>
Apply overrides to the session and immediately mutate the agent. Returns the merged overrides for confirmation.
Note: model_provider is recorded here but the live provider swap is
driven by the dispatcher via Self::apply_model_provider, because
rebuilding the ModelProvider box needs Config access that the
session store deliberately does not hold.
Sourcepub async fn apply_model_provider(
&self,
id: &str,
model_provider: Box<dyn ModelProvider>,
model_provider_name: String,
) -> bool
pub async fn apply_model_provider( &self, id: &str, model_provider: Box<dyn ModelProvider>, model_provider_name: String, ) -> bool
Swap a freshly built ModelProvider box (and its name) onto the
session’s agent. Called by the dispatcher after it constructs the
box from config, keeping model_provider-build logic out of the store.
pub async fn get_overrides(&self, id: &str) -> Option<SessionOverrides>
Sourcepub async fn get_upload(
&self,
session_id: &str,
ref_id: &str,
) -> Option<UploadEntry>
pub async fn get_upload( &self, session_id: &str, ref_id: &str, ) -> Option<UploadEntry>
Look up an existing upload by ref_id. Returns None if the session
or entry doesn’t exist.
Sourcepub async fn insert_upload(&self, session_id: &str, entry: UploadEntry)
pub async fn insert_upload(&self, session_id: &str, entry: UploadEntry)
Insert (or overwrite) an upload entry in the session’s index.
Sourcepub async fn get_workspace_dir(&self, session_id: &str) -> Option<String>
pub async fn get_workspace_dir(&self, session_id: &str) -> Option<String>
Get the workspace directory for a session.
Sourcepub async fn get_agent_alias(&self, session_id: &str) -> Option<String>
pub async fn get_agent_alias(&self, session_id: &str) -> Option<String>
Get the agent alias bound to a session, if known. Used by the dispatcher to route uploads to the agent’s own workspace dir rather than to the user’s session cwd (which is often a git repo we shouldn’t be writing into).
pub async fn seed_history(&self, id: &str, msgs: &[ChatMessage])
pub async fn seed_conversation_history( &self, id: &str, msgs: Vec<ConversationMessage>, )
pub async fn chat_mode(&self, id: &str) -> Option<ChatMode>
pub async fn history_len(&self, id: &str) -> Option<usize>
pub async fn history_slice_from( &self, id: &str, from: usize, ) -> Option<Vec<ConversationMessage>>
pub async fn remove(&self, id: &str) -> bool
Sourcepub async fn evict_same_mode_sibling(
&self,
tui_id: &str,
chat_mode: &ChatMode,
except_id: &str,
) -> Vec<(String, String)>
pub async fn evict_same_mode_sibling( &self, tui_id: &str, chat_mode: &ChatMode, except_id: &str, ) -> Vec<(String, String)>
Drop every idle session owned by tui_id in the same chat_mode as a
freshly created session, except except_id itself. zerocode keeps one
active session per mode per TUI: creating or loading another session of
that mode abandons the prior one until it is explicitly reloaded, so the
prior agent and its history are dead weight in RSS. Chat and Code
sessions are orthogonal, so a Chat switch must never evict the live Code
session and vice versa.
A session with a registered cancel token has a turn in flight: a spawned
session/prompt task still holds an Arc<Mutex<Agent>> clone, so
removing the map’s strong ref would neither free the agent nor be safe to
trim against, and force-cancelling another TUI’s mid-turn work is exactly
the freeze the reaper guards against. Such sessions are skipped; they
finish their turn and are reclaimed later. Returns the
(session_key, agent_alias) of each session actually dropped, so the
caller can attribute the eviction and knows the agents are freed before
it trims.
Sourcepub async fn session_owner_tui_id(
&self,
session_id: &str,
) -> Option<Option<String>>
pub async fn session_owner_tui_id( &self, session_id: &str, ) -> Option<Option<String>>
Read the owner_tui_id stamp from a session. Returns None if the
session doesn’t exist, Some(None) if it exists but is unowned (e.g.
created by an anonymous connection), Some(Some(id)) if owned by id.
pub async fn list_ids(&self) -> Vec<String>
pub fn register_cancel_token(&self, id: &str, token: CancellationToken) -> u64
pub fn remove_cancel_token(&self, id: &str, generation: u64)
pub fn cancel_session(&self, id: &str) -> bool
Sourcepub fn has_inflight_turn(&self, id: &str) -> bool
pub fn has_inflight_turn(&self, id: &str) -> bool
Returns true if a cancel token is registered — i.e. a turn is in flight.
Sourcepub async fn kill_session(&self, id: &str) -> bool
pub async fn kill_session(&self, id: &str) -> bool
Force-terminate a session: if a turn is in flight, record AdminKill
and fire the cancel token so the verdict site can attribute the cause;
then remove the session from the store.
Returns true if the session existed and was removed, false if not found.
History on disk is NOT touched — this is an in-memory eviction only.
Sourcepub fn record_cancel_cause(&self, id: &str, cause: CancelCause)
pub fn record_cancel_cause(&self, id: &str, cause: CancelCause)
Record the cause for an imminent cancel-token fire. Call immediately before firing so the verdict site can attribute the cancel.
Sourcepub fn take_cancel_cause(&self, id: &str) -> Option<CancelCause>
pub fn take_cancel_cause(&self, id: &str) -> Option<CancelCause>
Drain the recorded cancel cause for a session. Returns None only
when no cancel actually fired (clean completion); every firing path
records before token.cancel(), so Some(_) after a fired token is
the invariant the verdict audit relies on.
pub async fn count(&self) -> usize
Sourcepub async fn count_by_agent(&self) -> HashMap<String, usize>
pub async fn count_by_agent(&self) -> HashMap<String, usize>
Count active sessions grouped by agent alias.
Auto Trait Implementations§
impl !Freeze for SessionStore
impl !RefUnwindSafe for SessionStore
impl Send for SessionStore
impl Sync for SessionStore
impl Unpin for SessionStore
impl UnsafeUnpin for SessionStore
impl !UnwindSafe for SessionStore
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more