1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//! One owner per conversation: the session aggregate that accepts work and
//! drives it through the execution stack.
//!
//! A [`Session`] owns one
//! [`ConversationState`](crate::conversation::ConversationState) plus an
//! already-assembled [`TurnRunner`](crate::driver::TurnRunner) /
//! [`TurnRunOptions`](crate::config::TurnRunOptions); cloneable
//! [`SessionHandle`]s 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`](crate::conversation::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`.
pub use ;
pub use SessionHandle;
pub use ;
pub use ;