Skip to main content

Session

Struct Session 

Source
pub struct Session {
Show 20 fields pub id: String, pub title: String, pub name: Option<String>, pub model: String, pub thinking_level: String, pub system_prompt: Option<String>, pub created_at: DateTime<Utc>, pub updated_at: DateTime<Utc>, pub total_input_tokens: u64, pub total_output_tokens: u64, pub session_cost: f64, pub message_count: usize, pub parent_session: Option<String>, pub compacted_into: Option<String>, pub env: Option<Vec<(String, String)>>, pub env_stripped: Vec<String>, pub api_messages: Vec<SharedMessage>, pub abort_context: Option<String>, pub prompt_provenance: Option<PromptProvenance>, pub compaction: Option<CompactionRecord>,
}

Fields§

§id: String§title: String§name: Option<String>§model: String§thinking_level: String§system_prompt: Option<String>§created_at: DateTime<Utc>§updated_at: DateTime<Utc>§total_input_tokens: u64§total_output_tokens: u64§session_cost: f64§message_count: usize

Persisted listing hint: api_messages.len() at save time. Declared BEFORE api_messages so it lands in the header that read_session_header reads without touching the message array. Not authoritative in memory — use api_messages.len(); refreshed by session_journal::save_session_in_dir. Legacy files → 0.

§parent_session: Option<String>

ID of the session this was compacted from (backward link). Declared before api_messages so read_session_header sees it (F24).

§compacted_into: Option<String>

ID of the session created by compacting this one (forward link). Declared before api_messages so read_session_header sees it (F24).

§env: Option<Vec<(String, String)>>

Session environment snapshot (names+values, secrets stripped). Declared before api_messages so read_session_header sees it. Belt-and-braces: values for secret keys are scrubbed on save even if a future client forgets to strip.

§env_stripped: Vec<String>

Names of env vars stripped as secrets (T5, names only, never values). Declared before api_messages so read_session_header sees it.

§api_messages: Vec<SharedMessage>§abort_context: Option<String>

Legacy: the “ABORT CONTEXT” recap older Synaps saved for an interrupted turn, to prepend to the next user message. Never written now (an interrupted turn is real history plus a marker, agent_engine::engine::interrupt) and never injected: a session that still carries one is migrated when it is loaded (recap dropped, marker appended).

§prompt_provenance: Option<PromptProvenance>§compaction: Option<CompactionRecord>

Typed compaction summary provenance (spec §9.3). Present on sessions produced by (or updated in place by) a compaction transition.

Implementations§

Source§

impl Session

Source

pub fn new( model: &str, thinking_level: &str, system_prompt: Option<&str>, ) -> Self

Source

pub fn from_compaction_record( parent: &Session, summary_text: &str, record: CompactionRecord, ) -> Self

Create a successor session from a compaction transition (spec §9.3). The summary enters context through the canonical sanitized rendering (crate::compaction::compaction_context_messages); the parent’s system prompt stays TYPED metadata — the successor’s system_prompt field and the provenance record — never plain user text.

Source

pub fn auto_title(&mut self)

Set title from the first user message if not already set

Source

pub async fn save(&self) -> Result<()>

Persist this session under the configured persistence mode (session_persistence config key; default is the unchanged legacy JSON path — see Task 35 / crate::core::session_journal).

Source

pub async fn save_durable(&self) -> Result<()>

Publish a full context checkpoint and wait for durable persistence. Captures the destination and configured mode BEFORE spawning blocking work. Unlike save, journal mode always replaces the snapshot here.

On success the snapshot file AND its containing directory have been fsynced (also newly created directory ancestry). Snapshot publication is the logical commit: errors from directory sync or journal cleanup can occur AFTER it is visible, and do not imply rollback. Callers must stop inference on ANY error and reload/retry rather than assume the old head survived. Dropping this future does not cancel blocking I/O.

Async saves to the same destination/session are ordered in-process, including blocking writers whose awaiter was dropped. Callers still own ordering of logical session mutations; this is not a multi-process transaction. Durable saves fail closed on non-Unix platforms; fsync guarantees still depend on the underlying filesystem/device.

Source

pub async fn recover_durable(id: &str) -> Result<Self>

Resolve an ambiguous head without racing an older detached writer. Read and durable re-publication share the same save-order guard. A successful read alone must not clear a failed directory-sync barrier.

Source

pub fn load(id: &str) -> Result<Self>

Source

pub fn load_from_dir(dir: &Path, id: &str) -> Result<Self>

Canonical backward-compatible host load for a caller-selected sessions directory. Both legacy snapshots and journal-backed sessions resolve through the same journal overlay implementation.

Source

pub fn info(&self) -> SessionInfo

Source

pub fn set_name(&mut self, name: &str) -> Result<()>

Assign a name to this session. Validates name, enforces uniqueness across sessions, and rejects collisions with existing chain names. Idempotent: re-applying the current name is a no-op.

Source

pub fn clear_name(&mut self)

Trait Implementations§

Source§

impl Clone for Session

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Session

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Session

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for Session

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

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> 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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