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: 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<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
impl Session
pub fn new( model: &str, thinking_level: &str, system_prompt: Option<&str>, ) -> Self
Sourcepub fn from_compaction_record(
parent: &Session,
summary_text: &str,
record: CompactionRecord,
) -> Self
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.
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<()>
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).
Sourcepub async fn save_durable(&self) -> Result<()>
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.
Sourcepub async fn recover_durable(id: &str) -> Result<Self>
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.
pub fn load(id: &str) -> Result<Self>
Sourcepub fn load_from_dir(dir: &Path, id: &str) -> Result<Self>
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.
pub fn info(&self) -> SessionInfo
Sourcepub fn set_name(&mut self, name: &str) -> Result<()>
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.