Skip to main content

SessionStore

Struct SessionStore 

Source
pub struct SessionStore {
    pub session_queue: Arc<SessionActorQueue>,
    /* private fields */
}

Fields§

§session_queue: Arc<SessionActorQueue>

Implementations§

Source§

impl SessionStore

Source

pub fn new(max_sessions: usize, session_queue: Arc<SessionActorQueue>) -> Self

Source

pub async fn insert( &self, id: String, session: RpcSession, ) -> Result<(), &'static str>

Source

pub async fn get_agent(&self, id: &str) -> Option<Arc<Mutex<Agent>>>

Source

pub async fn touch(&self, id: &str)

Source

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.

Source

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.

Source

pub async fn get_overrides(&self, id: &str) -> Option<SessionOverrides>

Source

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.

Source

pub async fn insert_upload(&self, session_id: &str, entry: UploadEntry)

Insert (or overwrite) an upload entry in the session’s index.

Source

pub async fn get_workspace_dir(&self, session_id: &str) -> Option<String>

Get the workspace directory for a session.

Source

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).

Source

pub async fn seed_history(&self, id: &str, msgs: &[ChatMessage])

Source

pub async fn seed_conversation_history( &self, id: &str, msgs: Vec<ConversationMessage>, )

Source

pub async fn chat_mode(&self, id: &str) -> Option<ChatMode>

Source

pub async fn history_len(&self, id: &str) -> Option<usize>

Source

pub async fn history_slice_from( &self, id: &str, from: usize, ) -> Option<Vec<ConversationMessage>>

Source

pub async fn remove(&self, id: &str) -> bool

Source

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.

Source

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.

Source

pub async fn list_ids(&self) -> Vec<String>

Source

pub fn register_cancel_token(&self, id: &str, token: CancellationToken) -> u64

Source

pub fn remove_cancel_token(&self, id: &str, generation: u64)

Source

pub fn cancel_session(&self, id: &str) -> bool

Source

pub fn has_inflight_turn(&self, id: &str) -> bool

Returns true if a cancel token is registered — i.e. a turn is in flight.

Source

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.

Source

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.

Source

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.

Source

pub async fn count(&self) -> usize

Source

pub async fn count_by_agent(&self) -> HashMap<String, usize>

Count active sessions grouped by agent alias.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,