Skip to main content

Module session

Module session 

Source
Expand description

One owner per conversation: the session aggregate that accepts work and drives it through the execution stack.

A Session owns one ConversationState plus an already-assembled TurnRunner / TurnRunOptions; cloneable SessionHandles submit, observe, wait, resume, and cancel. The session is the coordination layer around the driver (accept → begin/append → run → commit/abort/retain → notify); it neither duplicates the model loop nor exposes a writable ConversationState.

§Observable behaviour

  • One active work, no queue: while a work is Accepted / Running / Paused, submit returns SessionError::Busy naming it.
  • Stable identity: each work gets a fresh TurnId at acceptance, never reused, even after an interrupt.
  • Local request-key dedup, checked before the busy and closed guards: same key and parts returns the original WorkReceipt (even after the owner closed), same key with different parts is SessionError::Conflict, and a rejected submit keeps the key free.
  • Bounded retention: SessionConfig::retained_work_capacity bounds the registry; finished results stay observable across later works.
  • One writable state: it moves into the worker task while a work runs.
  • Completed commits into history; Interrupted keeps the real facts plus cause and stays out of history; Paused keeps the complete outcome for an explicit resume. Observations include an independent copy of its crate::driver::PausePoint and the revision needed to decide it.
  • A panic, runner rejection, or dropped worker publishes WorkState::Faulted with the reason and refuses new work.
  • resume continues a paused work after validating the work’s paused revision and the request; a rejected request executes nothing and leaves the paused material untouched. cancel fires the work’s own control token (a racing completion keeps its result, a paused work is terminated in place with its continuation retained, and a terminal work is not rewritten). shutdown stops acceptance, winds down the running work, and retains material for inspection.
  • Dropping the owner stops acceptance and fires the active work’s cancellation token; retained observations stay readable.
  • checkpoint exports a versioned SessionCheckpoint only from an idle or paused session (Busy while a work is accepted / running, refused once faulted; a closed session still exports, recording closed). SessionCheckpoint::restore validates the version, the assembled configuration description, and the material’s internal consistency before registering — a rejection hands back the original envelope and the by-value inputs, and a successful restore calls no model or tool. Saved request keys replay their original receipts (different arguments still conflict), identity allocation continues from the saved progress, and a restored pause still needs an explicit resume under its remaining — never re-granted — deadline. Opening a conversation from history stays a different operation: it rebuilds no dedup table.

Multi-session coordination, materials, and model tools are not here.

§Runtime

SessionHandle::submit spawns the worker on the ambient Tokio runtime. If that runtime drops the task, even before its first poll, surviving handles observe Faulted and the owner can still shut down. The lost task’s complete execution material cannot be recovered by this mechanism.

§Layout

This root file is the index only: types holds the public value vocabulary, owner the Session anchor, handle the SessionHandle entry, the private execution core the registry and worker, and checkpoint the versioned save envelope (SessionCheckpoint) its restore consumes. Convention is foo.rs + foo/, never mod.rs.

Structs§

CancelReceipt
Acceptance receipt for a cancel — the work it targeted and what the cancel did to it.
SavedCancelKey
One accepted cancel under its request key, saved for replay.
SavedResumeKey
One accepted resume under its request key, saved for replay.
SavedSubmitKey
One accepted submit under its request key, saved for replay.
SavedWork
One retained work’s saved view: everything observe reported plus the absolute deadline.
Session
The session owner: one per conversation, held by the harness.
SessionBuildRejection
Returned by Session::new when the supplied state is not idle.
SessionCheckpoint
The complete save envelope of one session — everything restore needs beyond freshly assembled capabilities, at an explicit format version.
SessionConfig
Session coordination configuration — not a mirror of TurnRunOptions.
SessionConfigDescription
The comparable description of one assembled configuration: the plain-data projection of TurnRunOptions plus the session coordination config.
SessionHandle
A cloneable operation entry for one Session.
SessionRestoreRejection
A rejected restore: the reason plus everything the caller handed in, returned untouched — the original checkpoint included. Nothing was registered; correcting the input and retrying costs nothing.
SubmitRequest
One submission: the caller-scoped idempotency key plus the new task’s content parts.
WaitOutcome
The result of a finite wait: one consistent snapshot plus why the wait ended.
WorkObservation
A snapshot of one work’s published state.
WorkReceipt
Acceptance receipt for a submit — the assigned work and the revision it was accepted at.
WorkRef
Identity of one accepted work: the conversation plus the turn id the session assigned at acceptance.

Enums§

CancelOutcome
What a cancel actually did to the work.
CheckpointPhase
The saved conversation phase: the idle state, or the complete paused outcome plus the work ref it belongs to.
FinishedKind
How a terminal work ended — the two terminal TurnResult shapes, kept as (or inside) the driver’s own vocabulary rather than copied into new types. Serialized snake_case, matching the envelope’s other enums (WorkState, CancelOutcome) rather than the driver’s TurnResult casing — the envelope is its own wire shape.
SessionError
Rejections of the session operations.
WaitEnd
Why a SessionHandle::wait returned.
WorkState
The session’s management view of a work.

Constants§

SESSION_CHECKPOINT_VERSION
The envelope format version written by Session::checkpoint.