2.2 Cross-Session Continuity
Cross-session continuity is the handoff from your previous process to your next process.
The previous session writes a Handoff; the next session accepts it by writing a
Checkpoint or ActionTaken that references the handoff. The chain then shows
both the transfer and the continuation.
The Pattern
- End each session with a
Handoffthought usingThoughtRole::Handoff. - Include done, pending, risks, and the first next step.
- In the next session, query handoffs by project concept.
- Write a continuation checkpoint that references the handoff.
use mentisdb::{
BinaryStorageAdapter, MentisDb, RankedSearchQuery, ThoughtInput,
ThoughtQuery, ThoughtRole, ThoughtType,
};
fn continue_across_sessions() -> io::Result<()> {
let dir = tempfile::tempdir()?;
let adapter = BinaryStorageAdapter::for_chain_key(
dir.path(),
"cookbook-cross-session",
);
let mut chain = MentisDb::open_with_storage(Box::new(adapter))?;
chain.upsert_agent(
"agent-prev",
Some("Previous Agent"),
Some("memory-team"),
Some("Writes handoffs before shutdown"),
None,
)?;
chain.upsert_agent(
"agent-next",
Some("Next Agent"),
Some("memory-team"),
Some("Resumes from durable handoffs"),
None,
)?;
let handoff = chain.append_thought(
"agent-prev",
ThoughtInput::new(
ThoughtType::Handoff,
"Done: reproduced the flaky auth test. Pending: isolate whether cache state or clock skew causes it. First next step: rerun with fixed clock.",
)
.with_role(ThoughtRole::Handoff)
.with_concepts(["auth-flake", "test-debugging"])
.with_tags(["handoff", "session-end"])
.with_importance(0.9),
)?;
let handoff_index = handoff.index;
let candidates = chain.query_ranked(
&RankedSearchQuery::new()
.with_text("Where should I resume the auth flaky test investigation?")
.with_filter(
ThoughtQuery::new()
.with_roles(vec![ThoughtRole::Handoff])
.with_concepts_any(["auth-flake"]),
)
.with_limit(1),
);
assert_eq!(candidates.hits.len(), 1);
let continuation = chain.append_thought(
"agent-next",
ThoughtInput::new(
ThoughtType::Checkpoint,
"Accepted handoff. Starting with fixed-clock rerun before changing cache code.",
)
.with_role(ThoughtRole::Checkpoint)
.with_refs(vec![handoff_index])
.with_concepts(["auth-flake", "resume-point"])
.with_tags(["handoff", "accepted"])
.with_importance(0.85),
)?;
assert_eq!(continuation.refs, vec![handoff_index]);
Ok(())
}
Continuity is a write, not just a read. If the next session only reads a
handoff, the chain cannot later prove that the handoff was accepted or acted on.
What to Include
A good handoff is operational. It names what changed, what is still uncertain, what not to repeat, and the first concrete next step. That makes it useful to both a future human and a future agent.