Skip to main content

ConversationState

Struct ConversationState 

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

Session-level controlled operations over the kernel’s facts:

  • begin_turn admits a fresh active turn (rejects concurrent active and turn-id collisions with committed history);
  • seal_turn is the only stamping path — for Completed/Interrupted it seals the active TurnContext and records the outcome in one step (invariant sealed_result ∈ {Completed, Interrupted} ⇒ active.is_sealed()); for Paused it records the stamp while the active TurnContext stays open, so a later resume_turn can continue it (invariant sealed_result == Paused ⇒ active is open);
  • commit is the exactly-once transition into history: it alone assigns the TurnSequence (as a HistoryEntry), rejects anything not sealed-and-Completed (Paused gets the dedicated TurnPaused rejection), and clears the active slot — a repeated commit therefore lands on UnknownTurn (rejection, not idempotence);
  • abort_turn discards the active turn in any state (open, paused, sealed); history is untouched either way, and an aborted turn’s id may be reused.

The single active slot, completed-only admission, and commit-time ordering are this component’s defaults — a custom host composes the kernel facts differently without touching them.

Implementations§

Source§

impl ConversationState

Source

pub fn new(conversation_id: ConversationId) -> Self

A fresh, empty session: no history, no active turn, version zero.

Source

pub fn next_turn_sequence(&self) -> TurnSequence

The next TurnSequence the session will assign on commit. Derived from history.last() + 1 so the source of truth is history; there is no in-memory field to drift. TurnSequence(0) if empty.

Source

pub fn begin_turn( &mut self, turn_id: TurnId, ) -> Result<&mut TurnContext, ConversationError>

Admit a fresh active turn. Rejects while any active exists (sealed ones must be committed or aborted first) and when the id collides with committed history — an aborted turn’s id is reusable.

Source

pub fn seal_turn( &mut self, turn_id: TurnId, result: SealedResult, ) -> Result<(), ConversationError>

The only stamping path. Completed/Interrupted seal the active TurnContext and record the outcome atomically; Paused records the stamp while the turn stays open — the driver-owned counterpart of TurnContext::seal, deliberately withheld for resumable pauses.

Source

pub fn active_turn(&self) -> Option<&TurnContext>

Read-only view of the active turn.

Source

pub fn sealed_result(&self) -> Option<SealedResult>

The eligibility stamp, if any (Some(Paused) marks a resumable turn).

Source

pub fn active_turn_mut(&mut self) -> Option<&mut TurnContext>

Mutable view of the active turn — the host’s door access for append_input before running.

Source

pub fn commit( &mut self, turn_id: TurnId, ) -> Result<HistoryEntry, ConversationError>

Exactly-once commit: requires the turn id to match the active slot, the turn to be sealed, and the stamp to read Completed. Assigns the next TurnSequence, appends the HistoryEntry to history, and clears the active slot. Rejection (not idempotence): after the first commit the slot is empty, so a repeated commit returns UnknownTurn.

Source

pub fn abort_turn( &mut self, turn_id: TurnId, ) -> Result<TurnContext, ConversationError>

Discard the active turn in any state (open, paused, sealed-completed, sealed-interrupted). History is untouched; the returned TurnContext is for caller inspection only (no reopen/unseal). An aborted turn’s id may be reused by a later begin_turn.

Source

pub fn frame( &self, round_id: RoundId, ) -> Result<ContextFrame, ConversationError>

Lossless merged view: committed history (sequence ascending, blocks in BlockSequence order) followed by the active turn’s blocks, under the Conversation scope identity. Sync and policy-free by design — budget, selection and compaction over the merged view orchestrate through the policy layer and never mutate facts. The only failure source is a missing active turn.

Source

pub fn runner_parts( &mut self, ) -> (&ConversationId, Vec<TurnSnapshot>, Option<&mut TurnContext>)

Borrow-split for a conversation driver’s consume/return flow: the conversation id and committed history are read while the active turn is driven mutably. Stamping still goes through the public seal_turn afterwards, so no second &mut seam exists.

Source

pub fn from_history( conversation_id: ConversationId, entries: Vec<HistoryEntry>, ) -> Result<Self, ConversationError>

Validated replay path: rebuild a session from committed history entries. The active slot starts empty (live paths never enter here); ConversationVersion resets to zero (replay is a fresh load). Validation runs the shared validate_history closed set — any violation maps to ConversationError::InvalidSequence so callers never touch ContextError.

Source

pub fn history(&self) -> &[HistoryEntry]

Committed history in ascending TurnSequence order.

Source

pub fn history_len(&self) -> usize

Number of committed entries in history.

Source

pub fn version(&self) -> ConversationVersion

The ConversationVersion, ticked at every controlled transition (begin_turn / commit / abort_turn); zero for a fresh or replayed session.

Source

pub fn conversation_id(&self) -> &ConversationId

The session’s identity.

Trait Implementations§

Source§

impl Clone for ConversationState

Source§

fn clone(&self) -> ConversationState

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 ConversationState

Source§

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

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

impl<'de> Deserialize<'de> for ConversationState

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 ConversationState

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