Part 1 of 5 · 2 min read
Overview
Why this matters for agents
Agents run for minutes to days and wait on people and slow tools. Without durable state, every deploy or crash restarts the work and repeats its side effects (module 6). Interviewers probe whether you know the trade-offs of checkpointing, not just that it exists.
About the example, and what is real
Real: the code in code/mini-durable (the three stores, a pure apply, replay, a migration chain, a stale-resume simulation) and its 14 tests. Assumed: each step adds a 300-byte message; byte size is the length of the JSON; a premise is invalidated at 2 percent per hour; the "model" is a seeded random choice. Not real: no database, no framework, no network, no real checkpointer. In the stale-resume test, re-validation gives 0 percent false actions by construction: it shows the cost of not checking, not that checking is free (it costs a read and a possible re-plan).
Definitions
Checkpoint, snapshot, event log
- Checkpoint: a saved point from which a run can resume.
- Snapshot: the whole state at that point.
- Event log (event sourcing): an append-only list of changes; state is rebuilt by applying them in order.
Replay, deterministic, time travel, fork
- Replay: rebuilding state by re-applying recorded events.
- Deterministic: the same inputs always give the same result;
applymust be, and a live model call is not. - Time travel: loading an earlier checkpoint to inspect or re-run from it.
- Fork: continuing from an earlier checkpoint on a new branch, leaving the original untouched.
Schema version, migration, stale state
- Schema version: a number stored with the state saying which shape it has.
- Migration: a function that upgrades state from one version to the next.
- Stale state: saved assumptions that the outside world has since changed.
Storage models
A snapshot is the simplest and resumes instantly, but writes the whole state each time. A log writes only the change but must replay it. A hybrid takes a snapshot every k events.