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,submitreturnsSessionError::Busynaming it. - Stable identity: each work gets a fresh
TurnIdat 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 isSessionError::Conflict, and a rejected submit keeps the key free. - Bounded retention:
SessionConfig::retained_work_capacitybounds the registry; finished results stay observable across later works. - One writable state: it moves into the worker task while a work runs.
Completedcommits into history;Interruptedkeeps the real facts plus cause and stays out of history;Pausedkeeps the complete outcome for an explicitresume. Observations include an independent copy of itscrate::driver::PausePointand the revision needed to decide it.- A panic, runner rejection, or dropped worker publishes
WorkState::Faultedwith the reason and refuses new work. resumecontinues a paused work after validating the work’s paused revision and the request; a rejected request executes nothing and leaves the paused material untouched.cancelfires 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).shutdownstops 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.
checkpointexports a versionedSessionCheckpointonly from an idle or paused session (Busywhile a work is accepted / running, refused once faulted; a closed session still exports, recordingclosed).SessionCheckpoint::restorevalidates 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 explicitresumeunder 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§
- Cancel
Receipt - Acceptance receipt for a cancel — the work it targeted and what the cancel did to it.
- Saved
Cancel Key - One accepted cancel under its request key, saved for replay.
- Saved
Resume Key - One accepted resume under its request key, saved for replay.
- Saved
Submit Key - One accepted submit under its request key, saved for replay.
- Saved
Work - One retained work’s saved view: everything
observereported plus the absolute deadline. - Session
- The session owner: one per conversation, held by the harness.
- Session
Build Rejection - Returned by
Session::newwhen the supplied state is not idle. - Session
Checkpoint - The complete save envelope of one session — everything restore needs beyond freshly assembled capabilities, at an explicit format version.
- Session
Config - Session coordination configuration — not a mirror of
TurnRunOptions. - Session
Config Description - The comparable description of one assembled configuration: the plain-data
projection of
TurnRunOptionsplus the session coordination config. - Session
Handle - A cloneable operation entry for one
Session. - Session
Restore Rejection - 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.
- Submit
Request - One submission: the caller-scoped idempotency key plus the new task’s content parts.
- Wait
Outcome - The result of a finite wait: one consistent snapshot plus why the wait ended.
- Work
Observation - A snapshot of one work’s published state.
- Work
Receipt - 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§
- Cancel
Outcome - What a
cancelactually did to the work. - Checkpoint
Phase - The saved conversation phase: the idle state, or the complete paused outcome plus the work ref it belongs to.
- Finished
Kind - How a terminal work ended — the two terminal
TurnResultshapes, 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’sTurnResultcasing — the envelope is its own wire shape. - Session
Error - Rejections of the session operations.
- WaitEnd
- Why a
SessionHandle::waitreturned. - Work
State - The session’s management view of a work.
Constants§
- SESSION_
CHECKPOINT_ VERSION - The envelope format version written by
Session::checkpoint.