Skip to main content

SessionStore

Struct SessionStore 

Source
pub struct SessionStore { /* private fields */ }
Expand description

CRUD access to the acp_sessions metadata index.

Implementations§

Source§

impl SessionStore

Source

pub fn new(pool: DbPool) -> Self

Wrap an existing DbPool. zeph-session does not own a dedicated database file — it shares the pool that already owns acp_sessions (migration 013).

Source

pub async fn create(&self, session_id: &str) -> Result<(), SessionError>

Insert a new session row with status = 'active', ignoring the call if the row already exists (idempotent, mirrors the existing create_acp_session pattern).

§Errors

Returns SessionError::Db if the write fails.

Source

pub async fn update_seq( &self, session_id: &str, last_seq: u64, event_count: u64, ) -> Result<(), SessionError>

Update last_seq, event_count, and updated_at after a turn’s events are flushed to the log (INV-SP-1: called only after the log append is durable).

Explicitly bumps updated_at here because the pre-cutover AFTER INSERT ON acp_session_events trigger (migration 017) that used to drive it never fires for post-cutover sessions (spec-068 §12.3 / D-2: acp_session_events is a write target only for legacy pre-cutover sessions) — without this, list_acp_sessions’ “ordered by last activity descending” would silently degrade to “ordered by creation time” for every session created after the cutover.

§Errors

Returns SessionError::Db if the write fails.

Source

pub async fn set_status( &self, session_id: &str, status: SessionStatus, ) -> Result<(), SessionError>

Update the session’s lifecycle status.

§Errors

Returns SessionError::Db if the write fails.

Source

pub async fn set_condensed_seq( &self, session_id: &str, last_condensed_seq: u64, ) -> Result<(), SessionError>

Update the high-water condensation mark (INV-SP-4 non-overlap tracking).

§Errors

Returns SessionError::Db if the write fails.

Source

pub async fn get( &self, session_id: &str, ) -> Result<Option<SessionMetadata>, SessionError>

Fetch a single session’s metadata.

§Errors

Returns SessionError::Db if the query fails.

Source

pub async fn list( &self, filter: &SessionFilter, ) -> Result<Vec<SessionMetadata>, SessionError>

List sessions, most recently updated first.

§Errors

Returns SessionError::Db if the query fails.

Link this session to a ConversationId (raw i64zeph-session does not depend on zeph-memory’s newtype), enforcing the SessionId<->ConversationId bijection (spec §5.2) via the unique partial index added in migration 106.

§Errors

Returns SessionError::Db if the write fails (including a unique-constraint violation when conversation_id is already linked to a different session).

Source

pub async fn get_by_conversation_id( &self, conversation_id: i64, ) -> Result<Option<SessionMetadata>, SessionError>

Look up the session already linked to a ConversationId, if any.

Used at non-ACP channel startup (CLI/TUI/Telegram) to resume the same conversation’s existing session (and its event log) across process restarts, rather than minting a new SessionId every launch (spec §12.2).

§Errors

Returns SessionError::Db if the query fails.

Source

pub async fn record_fork( &self, new_session_id: &str, src_session_id: &str, forked_at_seq: u64, owner: Option<&str>, ) -> Result<(), SessionError>

Record a fork: sets forked_from/forked_at_seq on the child row.

Does not touch the parent’s log (the ForkPoint provenance event is appended by crate::replay’s ForkEngine, which owns the parent’s crate::log::SessionEventLog).

owner stamps owner_key (#5868): ACP’s fork_conversation passes its connection’s owner identity so the freshly forked child is immediately listable by its creator; the CLI’s sessions fork passes None (operator-scoped, unowned — consistent with every other CLI-side session row).

§Errors

Returns SessionError::Db if either write fails.

Source

pub async fn delete(&self, session_id: &str) -> Result<bool, SessionError>

Delete a session’s metadata row. Returns true if a row was deleted.

Does not remove the on-disk event log directory or blobs — callers with access to [session] data_dir are responsible for that (mirrors the separation of concerns between SessionStore and crate::log::SessionEventLog).

§Errors

Returns SessionError::Db if the write fails.

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.

Source§

impl<T> Instrument for T

Source§

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

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

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

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + 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
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + 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.
Source§

impl<T> WithSubscriber for T

Source§

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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