Skip to main content

TurnContext

Struct TurnContext 

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

Current turn’s ordered fact state. All mutation goes through the three controlled doors (append_input / append_model_output / append_tool_results) plus seal; there is no second &mut seam — fields are private by design. The only projection the fact machine offers is the lossless frame(); policy-shaped materialization lives in causa_runtime::budget::FramePolicy::materialize, so context never depends on harness policy and never awaits behavior.

Implementations§

Source§

impl TurnContext

Source

pub fn new(turn_id: TurnId) -> Self

Creates an empty, open turn with version 0.

Source

pub fn is_sealed(&self) -> bool

Returns whether the turn has been sealed.

Source

pub fn blocks(&self) -> &[ContextBlock]

Borrows the committed fact blocks in commit order.

Source

pub fn version(&self) -> ContextVersion

Returns the current ContextVersion (count of canonical fact commits).

Source

pub fn turn_id(&self) -> TurnId

Returns the turn’s id.

Source

pub fn lifecycle(&self) -> TurnLifecycle

Returns the current lifecycle state.

Source

pub fn snapshot_blocks(&self) -> Vec<ContextBlock>

Returns an owned copy of the committed blocks in commit order.

Source

pub fn append_input( &mut self, text: TextPayload, source: impl Into<String>, ) -> Result<BlockId, ContextError>

Host door: admit one single-text message — the one-part sugar over TurnContext::append_parts. The kernel does not interpret the source label; role assignment is the renderer’s job.

Source

pub fn append_parts( &mut self, parts: Vec<ContentPart>, source: impl Into<String>, ) -> Result<BlockId, ContextError>

Host door for one logical message’s mixed content (caption + media, multi-image, text runs): the ordered parts commit as ONE fact block. Atomic — all-or-nothing validation, exactly one version bump, contiguous sequences. Stamps source verbatim on the envelope. Empty parts are rejected; media parts carry references only.

Source

pub fn append_model_output( &mut self, invocation: InvocationId, response: &ModelResponse, stop_reason: ModelStopReason, ) -> Result<AppliedModelOutput, ContextError>

Model door: record the model’s response as facts. Borrows the response so the caller keeps the envelope for its own traces; usage and reasoning are deliberately caller-retained and never enter the fact state. Tool call ids are generated exactly once and returned in the receipt as the execution handoff.

Source

pub fn append_tool_results( &mut self, results: Vec<ToolResultPayload>, ) -> Result<Vec<BlockId>, ContextError>

Tool door: commit tool results. Canonical commit order is the paired call’s block order (the model’s original draft order), so two drivers submitting the same logical results in different completion orders produce identical snapshots. Batch completeness is runner policy; the kernel enforces pairing only.

Source

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

Lossless canonical projection: the committed facts, ordered, with the deterministic frame identity. Frame-materialization policy (budget, compaction) is NOT applied here — the fact machine never awaits behavior; the execution stack materializes policy-shaped frames through causa_runtime::budget::FramePolicy::materialize, which replaces only this frame’s block list.

Source

pub fn seal(&mut self)

Terminal lifecycle transition, owned by the driver: seal when the turn is over. Sealed turns reject every append operation; the kernel guarantees no post-terminal mutation. Conversation-level history eligibility is a driver stamp, not this marker.

Source

pub fn from_validated_blocks( turn_id: TurnId, blocks: Vec<ContextBlock>, version: ContextVersion, ) -> Result<Self, ContextError>

Rebuilds an open turn from a validated block log — the reload path behind the serde bridge. Sequence monotonicity, id agreement, and tool pairing are validated before construction; the next sequence continues densely after the given blocks.

Source

pub fn validate_blocks( turn_id: &TurnId, blocks: &[ContextBlock], ) -> Result<(), ContextError>

The structural validation behind from_validated_blocks, callable without constructing a throwaway machine — replay paths validate snapshots in place. The runtime’s session replay (ConversationState::from_history) also validates committed snapshots through this entry, so every reload path shares one validator.

Source

pub fn snapshot(&self) -> TurnSnapshot

Projects the current state into an immutable TurnSnapshot — the canonical wire shape for persistence. Session ordering is NOT part of the snapshot: the runtime’s session aggregate assigns the HistoryEntry sequence at commit.

Trait Implementations§

Source§

impl Clone for TurnContext

Source§

fn clone(&self) -> TurnContext

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 TurnContext

Source§

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

Formats the value using the given formatter. 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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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.