pub struct Session {Show 22 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 keepwarm_cost: f64,
pub keepwarm_tokens: KeepwarmTokens,
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<Arc<Value>>,
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§keepwarm_cost: f64Prompt-cache keep-warm spend (task #444), already INCLUDED in
session_cost; persisted so a resumed/reloaded session still labels
it. Absent (0) on sessions that never kept warm.
SNAPSHOT-ONLY: never journaled. The v2 journal’s SessionMeta is
deny_unknown_fields, so a new field there would make an older build
(0.10.1) treat every meta record as a torn tail and truncate the
session; the .json snapshot tolerates unknown fields. In journal
mode the label is therefore as of the last snapshot (slightly stale
until the next one); load clamps it to session_cost.
keepwarm_tokens: KeepwarmTokensKeep-warm ping tokens, already INCLUDED in the token totals.
SNAPSHOT-ONLY, like keepwarm_cost; clamped on load to the totals
that survive a reload.
message_count: usizePersisted 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<Arc<Value>>§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
impl Session
Sourcepub fn clamp_keepwarm_to_totals(&mut self)
pub fn clamp_keepwarm_to_totals(&mut self)
The keep-warm labels are a subset of the totals; a journal replay can leave them (snapshot-only) ahead of totals that were reset since, so clamp them back under. Never raises anything.
Source§impl Session
impl Session
pub fn new( model: &str, thinking_level: &str, system_prompt: Option<&str>, ) -> Session
Sourcepub fn from_compaction_record(
parent: &Session,
summary_text: &str,
record: CompactionRecord,
) -> Session
pub fn from_compaction_record( parent: &Session, summary_text: &str, record: CompactionRecord, ) -> Session
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.
Sourcepub fn auto_title(&mut self)
pub fn auto_title(&mut self)
Set title from the first user message if not already set
Sourcepub async fn save(&self) -> Result<(), Error>
pub async fn save(&self) -> Result<(), Error>
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).
Sourcepub async fn save_durable(&self) -> Result<(), Error>
pub async fn save_durable(&self) -> Result<(), Error>
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.
Sourcepub async fn recover_durable(id: &str) -> Result<Session, Error>
pub async fn recover_durable(id: &str) -> Result<Session, Error>
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.
pub fn load(id: &str) -> Result<Session, Error>
Sourcepub fn load_from_dir(dir: &Path, id: &str) -> Result<Session, Error>
pub fn load_from_dir(dir: &Path, id: &str) -> Result<Session, Error>
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.
pub fn info(&self) -> SessionInfo
Sourcepub fn set_name(&mut self, name: &str) -> Result<(), Error>
pub fn set_name(&mut self, name: &str) -> Result<(), Error>
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.
pub fn clear_name(&mut self)
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Session
impl<'de> Deserialize<'de> for Session
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Session, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Session, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Serialize for Session
impl Serialize for Session
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Auto Trait Implementations§
impl Freeze for Session
impl RefUnwindSafe for Session
impl Send for Session
impl Sync for Session
impl Unpin for Session
impl UnsafeUnpin for Session
impl UnwindSafe for Session
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§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