A checkpoint can remain valid JSON and still break when an agent resumes. The problem appears when a deploy renames a field, changes a status, or requires a property that did not exist in paused runs.
The safe boundary is simple: persisted state carries a schemaVersion, the runtime migrates known versions before the next decision, and validation rejects any format it cannot explain. That migration happens before calling the model or a tool. The durable execution guide for AI agents covers the choice between queues, checkpoints, and workflows. This article focuses on the compatibility of the document that crosses a deploy.
This article uses a small JavaScript object and a local migration. The fixture does not read a database, call a model, or claim that every framework serializes state in the same way.

Practical summary
- Separate
stateSchemaVersion,agentVersion, andprocessPolicyVersion.- Migrate a known version with an explicit, repeatable function before resuming the run.
- Back up or preserve the original state when migration can lose information.
- Reject future versions, ambiguous fields, expired approvals, and uncertain external effects. Do not ask the model to guess the transformation.
Why does a code change break an old checkpoint?
A checkpoint is a snapshot of state, but the code that reads it defines what that snapshot means. The LangGraph graph migration documentation separates compatible changes from dangerous ones: adding or removing keys can be compatible, while renaming a key makes the saved value disappear for existing threads. An incompatible type change can also break old state.
The JSON does not need to be malformed. An old status may be accepted by the parser and rejected by the current state machine. A missing field can become undefined and later be interpreted as authorization, a completed step, or no work remaining.
The risk grows for interrupted runs. A finished run can often be replayed with a new version without preserving every execution detail. A run waiting for approval or about to execute a tool depends on the identity of its step and the meaning of pending fields. Migration must happen before the runtime chooses the next step.
This boundary is consistent with Pydantic AI Step Persistence, which separates complete snapshots, step events, and a tool-effect ledger. It also appears in OpenAI Agents SDK RunState recovery: when persisted history is ambiguous, recovery fails closed instead of repeating completed work.
Which versions need to be separate?
Do not use one version for different meanings. A record can carry at least these dimensions:
| Field | What changes | Who uses it on resume |
|---|---|---|
stateSchemaVersion |
Checkpoint keys, types, and shape | The migrator and validator |
agentVersion |
Code, prompt, tools, and model used by the run | The executor compatible with the run |
processPolicyVersion |
Business rules, authorization, and approval validity | The gate before an effect |
A new prompt does not necessarily require JSON migration. A new checkpoint key should not be hidden as if it were only an agent version. A policy change can leave JSON structurally valid while invalidating an approval that once allowed an action.
The post on versioning tools without breaking runs covers the first boundary: keeping an executable contract compatible with an in-flight run. The checkpoint schema is another boundary. A run may need the old tool and the new state format at the same time, as long as migration preserves the required meaning.
Use expand, migrate, and contract
A direct swap often requires every worker, queue, and record to change at once. A three-phase window reduces that dependency.
1. Expand the reader
First, make the reader recognize the old and new versions. New fields should have a safe default or be treated as absent until migration fills them. Record how many states still use each version.
Do not treat absence as success. If the next step depends on a field, mark the state incomplete or send it to a migration queue. A silent default is acceptable only when the domain defines that default without ambiguity.
2. Migrate with an explicit transformation
Migration should be deterministic, testable, and idempotent. It may run while loading the checkpoint or in a separate job, but it should produce the same result for the same state.
Record the run identifier, source version, target version, migrator used, and result. Preserve the original document or a recoverable copy when the transformation can lose information. Do not record full prompts, tokens, or secrets just to simplify diagnosis.
3. Contract compatibility
Remove old-format reads only after verifying that no paused runs, delayed messages, or support routines still depend on them. If a state cannot be converted without a business decision, quarantine it and provide a reconciliation path.
The AWS guide to checkpoint-based memory and recovery recommends that long workflows resume from the last known state rather than starting over. That does not make every migration safe. It means the recovery boundary must carry state the runtime can prove.
Lazy migration or batch migration?
Both strategies are useful, but they solve different operational problems.
| Strategy | When to use it | Main risk |
|---|---|---|
| On load | Few active states and a fast transformation | The first resume pays the latency and can expose a faulty migration |
| Batch job | Many states and a need to measure progress | The job competes with workers still reading the old version |
| Temporary compatible reader | Gradual deploy or possible rollback | The window lasts too long and old formats survive without an owner |
| Quarantine | Ambiguous, expired, or untrusted state | The task does not finish automatically, but it does not invent a decision |
With any option, compare the expected version before writing. A migration that reads v1, computes v2, and saves without a condition can overwrite a worker that just updated the same run. Use a transaction, version control, or compare-and-swap according to the storage system.
A Node.js fixture for migrating state
The fixture below uses two small versions. v1 stores proposedAction and a boolean approved. v2 transforms them into pendingAction and approvalStatus. The rule belongs to this fixture. In a real system, every change needs a domain compatibility decision.
import assert from "node:assert/strict";
const CURRENT_SCHEMA = 2;
function migrateV1ToV2(state) {
if (state.schemaVersion !== 1) {
throw new Error("expected checkpoint schema v1");
}
const { schemaVersion, proposedAction, approved, ...rest } = state;
return {
...rest,
schemaVersion: 2,
pendingAction: proposedAction,
approvalStatus: approved ? "approved" : "pending",
};
}
function validateV2(state) {
if (state.schemaVersion !== 2) {
throw new Error("checkpoint is not schema v2");
}
if (typeof state.runId !== "string" || typeof state.pendingAction !== "string") {
throw new Error("v2 checkpoint is missing required fields");
}
if (!["approved", "pending"].includes(state.approvalStatus)) {
throw new Error("v2 checkpoint has an invalid approval status");
}
return state;
}
function migrateCheckpoint(input) {
let state = structuredClone(input);
if (state.schemaVersion > CURRENT_SCHEMA) {
throw new Error("checkpoint schema is newer than this runtime");
}
if (state.schemaVersion === 1) {
state = migrateV1ToV2(state);
}
return validateV2(state);
}
const oldCheckpoint = {
schemaVersion: 1,
runId: "run-17",
proposedAction: "send report",
approved: false,
};
const migrated = migrateCheckpoint(oldCheckpoint);
assert.deepEqual(migrated, {
schemaVersion: 2,
runId: "run-17",
pendingAction: "send report",
approvalStatus: "pending",
});
assert.deepEqual(migrateCheckpoint(migrated), migrated);
assert.throws(
() => migrateCheckpoint({ schemaVersion: 3, runId: "run-18" }),
/newer than this runtime/,
);
console.log("checkpoint migration passed");
Save the block as checkpoint-migration.mjs and run:
node checkpoint-migration.mjs
The test proves three local properties: v1 becomes the expected v2, running migration again does not change the result, and a future version is rejected. It does not prove that the transformation preserves a real business rule, that a database transaction is atomic, or that a framework accepts this document.
What should not be migrated blindly?
Some changes look structural but hide a decision.
- Meaning changed.
approved: truemay mean something different after a policy change. Revalidate authorization, not just the field name. - Pending external effect. A checkpoint may say that a tool started, but not whether it created a ticket, sent a message, or received a response. The post on recovering after a crash covers that reconciliation. Migrating JSON does not confirm the external world.
- Unknown version. An old worker may write a version the current deploy does not know. Stop the run and report the version instead of discarding fields.
- Expired approval. Converting
approvedintoapprovalStatusdoes not extend approval validity. Current policy must decide whether the run asks for consent again. - Large or sensitive data. Do not copy full logs, credentials, or tool results into the checkpoint because the new schema has room for them. Store controlled references when the runtime can rebuild context.
If the transformation requires interpreting text, choose a human step or a reviewable domain routine. A model may suggest a mapping, but it should not be the only authority deciding whether an approved action remains authorized.
How do you verify a migration before deploy?
Test the migrator as data code, not only as part of the agent's happy path:
- Load anonymized real examples from every schema still active.
- Verify that important fields are preserved and defaults have a domain justification.
- Run the same migration twice and compare the result.
- Reject a future version, a missing version, and an incompatible field type.
- Force an interruption between read, migrate, and write. Check that retry does not lose the expected version.
- Test a run waiting for approval, a run with an unknown external effect, and a finished run.
- Measure records per version and define how quarantine will be resolved.
- Roll back the code without deleting original state or accepting a delayed write.
When the framework has its own rules, test documented compatibility too. LangGraph explains that resumed nodes can run again from the start of the function and that effects before an interruption need to be idempotent. A correct migration does not replace that protection.
Method and limits
Samuel Fajreldines is responsible for source selection, the fixture, and the writing. I consulted current documentation from LangGraph, Pydantic AI, the OpenAI Agents SDK, and the AWS Well-Architected Agentic AI Lens on 2026-11-26. I also reviewed results in English, Portuguese, and Spanish and public discussions to recognize vocabulary and objections. Discussions were not used as technical proof.
The fixture was run locally with Node.js and uses only node:assert/strict. It demonstrates a pure in-memory transformation. It is not a PostgreSQL migration, does not measure time, does not test a framework, does not confirm atomicity, and does not prove that a real state can be converted without business review.
I used AI assistance to organize research, review the prose, and prepare the localizations. It did not run a production agent, validate a database, or provide operational experience. When I need continuity across long Codex and Claude Code sessions, I use RemoteCode, a tool I built. That use does not replace migration, validation, or human review.
Conclusion
Treat the checkpoint schema as a data contract. Before resuming the agent, transform known versions with deterministic code, validate the result, and preserve an escape route for states that cannot be explained.
The point is not to migrate every JSON document as soon as a deploy ends. It is to prevent a new worker from treating an old document as if both shared the same meaning. Expand the reader, migrate with evidence, contract compatibility after measuring live states, and pause when the transformation depends on a decision the code cannot prove.
Sources consulted
- LangChain, Graph API overview: state schema, re-execution, and graph migrations, accessed 2026-11-26.
- LangChain, Checkpointing reference, accessed 2026-11-26.
- Pydantic AI, Step Persistence, accessed 2026-11-26.
- OpenAI Agents SDK, Results and RunState recovery, accessed 2026-11-26.
- AWS, Agent memory and state management, accessed 2026-11-26.