State, Checkpointing & Multi-Session

Module 8 · Master Course

45 min · Stateless agents are prototypes

The checkpoint substrate

Modules 4 (handoff), 6 (interrupt), 7 (budget recovery) all GESTURED at checkpointing. This module is the formal treatment — the infrastructure that makes HITL, recovery, and multi-session possible.

Five checkpointing patterns

PatternGainsCosts
Git commitsfree rollback, human-readablecode-only; needs repo
LangGraph super-stepsper-node, fine-grainedrequires LangGraph
External filesimple, universalnot atomic; no rollback
DB-backeddurable, queryableinfra; schema migrations
Nonesimplest codecannot resume; every interruption = restart

Atomic writes — the crash-safety primitive

Write to temp file, then rename (atomic on POSIX). The rename is the commit point. A crash at any moment leaves old-or-new, never a half-written mix.
async function atomicCheckpoint(path, state) {
  const tmp = path + ".tmp";
  await fs.writeFile(tmp, JSON.stringify(state));
  await fs.rename(tmp, path);  // ATOMIC on POSIX
}

A half-written checkpoint is WORSE than none — resume from corrupt state = undefined behavior.

Multi-session = checkpoint + handoff

Checkpoint: technical substrate for lossless resume.
Handoff: human-legible summary for the continuation agent's orientation.

Both needed. Checkpoint = the bytes; handoff = the meaning.

Takeaways

  • 5 patterns — git, super-steps, file, DB, none. Choose by use case.
  • Atomic writes — temp + rename. Never half-written.
  • Checkpoint + handoff — technical substrate + human meaning.
  • Session diffing — compare sessions to find behavioral drift.

Next: Module 9 — Verification & Feedback Loops.