pub async fn fork_thread(
checkpointer: &dyn Checkpointer,
spec: ForkSpec,
schema: Option<&StateSchema>,
) -> Result<Checkpoint, ForkError>graph and time-travel only.Expand description
Forks the checkpoint spec.from into the new thread spec.new_thread_id, with the
channels in spec.set overwritten (spec 3.3 §12).
| Carried | Dropped |
|---|---|
| State (with the edits), step, pending nodes, the arrivals of joins still waiting, each governed node’s completed runs | The retry budget, the answered gate, pending writes, finished children, the paused marker and its waiting requests, the run and its step records |
A pause asks again in the fork, and the fork opens its own run when it first runs. The
fork records its Lineage: root is the source’s root, else the source’s thread.
Edits overwrite whole channels and never go through reducers. With schema, each
edited key must be a declared channel and the lineage records checked: true;
without one, only keys the source state holds are accepted and it records
checked: false. The source thread is never written.
§Errors
Returns a ForkError for an unknown id, a pause, a checkpoint with no pending nodes,
an edit that names an undeclared channel or an unknown key, a target thread that
already has checkpoints, or a checkpointer failure.
§Example
use adk_graph::checkpoint::{Checkpointer, MemoryCheckpointer};
use adk_graph::state::{Checkpoint, State};
use adk_graph::time_travel::{ForkSpec, fork_thread};
use serde_json::json;
let checkpointer = MemoryCheckpointer::new();
let state = State::from([("note".to_string(), json!("v1"))]);
let source = Checkpoint::new("t1", state, 1, vec!["send".to_string()]);
checkpointer.save(&source).await?;
let fork = fork_thread(
&checkpointer,
ForkSpec::new(&source.checkpoint_id, "t2").set("note", json!("v2")),
None,
)
.await?;
let lineage = fork.lineage()?.expect("a fork records its lineage");
assert_eq!((lineage.root.as_str(), lineage.checked), ("t1", false));