Mental model
A durable checkpoint is an explicit, version-stamped execution snapshot stored outside fragile worker RAM that records structured orchestration state, monotonic step numbers, already committed external side effects, remaining resource budgets, and policy/schema hashes—enabling safe deterministic resume after worker crashes, pod scaling, or multi-day human approvals without repeating mutations.
Learning outcomes
- Design lean checkpoint schemas separating compact deterministic workflow state from large external blob artifact references.
- Prevent duplicate external side effects during crash recovery using immutable step idempotency receipts stored inside checkpoints.
- Enforce fencing lease tokens, schema compatibility gates, and consent/TTL expiration checks whenever sleeping runs resume.
Theory
Storing agent progress purely in in-memory Python dictionaries or unbounded raw prompt arrays breaks immediately when multi-minute research jobs hit pod OOM kills or pause 18 hours awaiting executive sign-off. Even persisting raw message logs alone is unsafe: replaying a message thread from crash without tracking committed side-effect boundaries duplicates database writes and billing actions, while omitting schema versions breaks old threads when orchestration code updates mid-flight. Reliable checkpoint architectures govern four fields explicitly:
| Checkpoint Component | What It Stores | Critical Safety Purpose on Resume |
|---|---|---|
Lease & Fencing Epoch (lease_epoch) | Monotonically increasing worker lock counter (seq_num, owner_id) | Prevents split-brain dual workers resuming the identical thread concurrently |
| Committed Side-Effect Log | map<logical_step_id, {idempotency_key, receipt_hash}> | Skips already executed external API mutations cleanly without double billing |
| Reference Artifact Pointers | Object-store URIs + SHA-256 digests (s3://.../doc.json) | Keeps SQL checkpoint rows small instead of bloating DB WAL with 5MB HTML scrapes |
| Schema, Policy & Consent Snapshot | graph_schema_ver, policy_sha256, auth_expires_at | Detects stale incompatible deployments or expired user OAuth/approvals before resuming |
When an executor restarts mid-workflow, it atomically acquires a higher lease_epoch (UPDATE checkpoints SET lease_epoch = lease_epoch + 1 WHERE thread_id = $1 AND lease_epoch = $2), reads committed side-effect keys, verifies permissions and document freshness remain valid, and resumes execution strictly at the first uncommitted node.
pythonfrom dataclasses import dataclass, fieldfrom datetime import datetime, timezone@dataclassclass DurableCheckpoint:thread_id: strseq_num: intlease_epoch: intschema_version: strpolicy_sha256: strcommitted_effects: dict[str, str] = field(default_factory=dict) # step_key -> external receipt IDremaining_budget_usd: float = 1.0expires_at_iso: str = "2027-01-01T00:00:00+00:00"def validate_resume_eligibility(ckpt: DurableCheckpoint,expected_schema: str,active_policy_sha: str,now_iso: str,) -> tuple[bool, str]:"""Block unsafe replay across schema upgrades, revoked policies, or expired threads."""if ckpt.schema_version != expected_schema:return False, f"incompatible_schema:{ckpt.schema_version}"if ckpt.policy_sha256 != active_policy_sha:return False, "policy_revision_changed_requires_recheck"if now_iso >= ckpt.expires_at_iso:return False, "checkpoint_ttl_expired"if ckpt.remaining_budget_usd <= 0.0:return False, "budget_exhausted"return True, "ok"
Trade-offs
Fine-grained node-by-node durable PostgreSQL or Redis checkpointing minimizes wasted token spend and lost work on crashes cleanly, enabling effortless time-travel debugging and human-in-the-loop suspensions lasting days—yet introduces write-amplification serialization costs on every superstep and mandates disciplined migration handlers across graph versions. Coarse milestone-only checkpointing lowers DB write load cleanly for cheap deterministic tasks, while sacrificing fine resume precision whenever intermediate expensive tool calls abort unexpectedly.
Failure modes and misconceptions
- Saving Raw Messages Without Committed Tool Receipts: Replaying a crashed prompt thread triggers duplicate email notifications, Jira comments, or refund payouts cleanly every crash.
- Unbounded Raw Blob Serialization: Stuffing multi-megabyte HTML scrapes or image tensors straight into Postgres JSONB checkpoints exhausts DB storage and spikes serialization stalls.
- Resuming Without Fencing Leases: Allowing an old stalled worker and a newly promoted worker both to advance the same
thread_idcorrupts graph state simultaneously. - Blind Replay Across Security Policy Upgrades: Resuming an old pre-approved checkpoint days later using credentials or policy thresholds revoked in the interim.
Decision scenario
A multi-hour enterprise diligence workflow executes three external SaaS enrichment calls, crashes on worker pod OOM during step 4, and must also support pausing cleanly across weekend human review. Architect checkpoint compaction, side-effect receipt logging, fencing tokens, and consent expiry checks cleanly.
Why must durable agent checkpoints persist committed external side-effect keys separately from conversational prompt history?