Skip to main content

SessionCoordinator

Struct SessionCoordinator 

Source
pub struct SessionCoordinator { /* private fields */ }

Implementations§

Source§

impl SessionCoordinator

Source

pub fn new( dir: &Path, cwd: &str, compaction_config: CompactionConfig, model: impl Into<String>, ) -> Result<Self>

Source

pub fn open_existing( path: PathBuf, session_id: String, existing_entries: &[SessionEntry], prior_agent_message_count: usize, compaction_config: CompactionConfig, model: impl Into<String>, ) -> Result<Self>

Open an existing session file for appending (resume).

existing_entries are the prior session entries already loaded by the caller via SessionReader::read_all. Only entries on the active branch (determined by the last Leaf pointer) are replayed into the internal compaction buffer — matching the ordering used by reconstruct_context for the Agent’s message buffer. Legacy sessions without Leaf entries fall back to file-order replay.

Compaction entries are honored by replaying their semantics: the kept tail (entries from first_kept_entry_id onward, persisted before the marker) is preserved, the summary occupies a synthetic slot at index 0 of the post-compaction agent buffer, and indices are rebuilt to match the runtime layout [summary, ...kept_tail, ...post_marker]. If first_kept_entry_id cannot be located among the already-replayed entries (corrupt or forward-incompatible session), the buffer is reset entirely — matching the legacy defensive behavior.

Source

pub fn on_turn_end( &mut self, new_messages: &[AgentMessage], usage: &Usage, turn_start_agent_index: usize, ) -> Result<Option<CompactionReason>, Error>

Persist only the new messages from a completed turn.

new_messages should contain only the messages produced during this turn (not the full conversation history). The caller is responsible for slicing appropriately. turn_start_agent_index is the index in the Agent’s full message buffer where new_messages[0] lives.

Returns Ok(Some(CompactionReason)) if compaction should be triggered (the caller should emit CompactionStart, then call execute_compaction). Returns Ok(None) if no compaction is needed. Returns Err if a session write failed.

Source

pub fn execute_compaction( &mut self, reason: CompactionReason, ) -> Result<Option<CompactionResultOutput>, Error>

Execute compaction after on_turn_end returned Some(reason). The caller should emit CompactionStart before calling this and CompactionEnd afterwards.

Returns Err if the compaction marker could not be persisted — in this case the in-memory state is left unchanged (no buffer replacement, no watermark advance) so the session file stays consistent with the runtime.

Source

pub fn on_turn_end_simple( &mut self, new_messages: &[AgentMessage], usage: &Usage, ) -> Result<Option<CompactionResultOutput>, Error>

Backwards-compatible variant used by tests that don’t track Agent indices. Assumes new_messages are appended starting at the current message count. Runs compaction inline if needed (no separate event emission).

Source

pub fn session_id(&self) -> &str

Source

pub fn session_path(&self) -> &Path

Source

pub fn usage(&self) -> &CumulativeUsage

Source

pub fn compaction_engine(&self) -> &CompactionEngine

Source

pub fn compaction_entries(&self) -> &[Entry]

Read-only view of the entries currently tracked for compaction. Exposed for tests that need to assert resume correctness.

Source

pub fn append_leaf(&mut self, entry_id: &str) -> Result<(), Error>

Append a Leaf pointer marking the selected active branch tip.

Source

pub fn cost_summary(&self) -> Option<CostBreakdown>

Compute the cost summary from the accumulated usage and the model pricing table. Returns None if no pricing is known for the model.

Source

pub fn model(&self) -> &str

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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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