Skip to main content

pe_graph/
snapshot.rs

1//! State snapshots for checkpoint inspection and time travel.
2//!
3//! A `StateSnapshot` captures the full state of a graph execution at a
4//! specific superstep, along with metadata for resumption and debugging.
5
6use pe_core::State;
7use std::time::SystemTime;
8
9/// Complete snapshot of graph execution state at a point in time.
10///
11/// Used for:
12/// - Human-in-the-loop: show state to human before they decide to resume
13/// - Time travel: inspect or resume from any past checkpoint
14/// - Debugging: see what the state looked like at each superstep
15///
16/// # Example
17///
18/// ```ignore
19/// let snapshot = graph.get_state("thread-1").await?;
20/// if let Some(snap) = snapshot {
21///     println!("Step {}: next nodes = {:?}", snap.step, snap.next_nodes);
22/// }
23/// ```
24/// NOTE: `#[non_exhaustive]` — will grow with metadata, branch info, etc.
25#[derive(Debug, Clone)]
26#[non_exhaustive]
27pub struct StateSnapshot<S: State> {
28    /// The full state at this checkpoint.
29    pub state: S,
30
31    /// Unique identifier for this checkpoint.
32    pub checkpoint_id: String,
33
34    /// Which superstep this was taken at.
35    pub step: u32,
36
37    /// Thread this checkpoint belongs to.
38    pub thread_id: String,
39
40    /// The checkpoint this one was derived from (if any).
41    pub parent_checkpoint_id: Option<String>,
42
43    /// When this checkpoint was created.
44    pub created_at: SystemTime,
45
46    /// Which nodes are scheduled to run next.
47    /// Empty if the graph completed or hit recursion limit.
48    pub next_nodes: Vec<String>,
49}