Resume on the Model the Run Started With: a Run Record That Pins the Model Id, the Prompt Version and the Notes
A run starts on claude-sonnet-5-5, the worker stops, and the team switches the default to claude-haiku-5-5. Resumed on the default, the run changes model silently and drops a reasoning block. A run record that pins the model id and prompt version resumes on the right model, migrates on purpose, and refuses a retired one.
What you will learn
- Store the model id and the prompt version in the run record when a run starts
- Resume an interrupted run on the record's model, never on the current default
- Migrate a run to a new model and prompt on purpose, and keep the old pair in the record
- Keep learned facts as notes outside the messages so a model switch can't drop them
Before you start
- Durable agent runs with checkpoints
- Pinning Claude model ids
A support agent is in the middle of a long ticket. Then the worker stops: a deploy, a restart, a crash. While it waits, the team changes the default model. When the worker comes back, which model does the run continue on?
If the code just reads "the default", the answer is: a different one from the model the run started on, and nobody notices. In durable agent runs we saved the step and the messages so a run survives a restart. Here we add the two things a resume also needs to keep: the model id and the prompt version.
The model changes while the run waits
Ticket T-201 starts on claude-sonnet-5-5. The worker is interrupted. While it waits, the team switches the default to claude-haiku-5-5. The worker restarts and resumes on the default; the record is never asked.
Now the model has changed silently. Earlier reasoning blocks can be dropped, answers drift from step one, and nobody can tell why. A restart is not the only risk: the resume can quietly land on a different model.
A handover note kept with the dish
Think of a kitchen at the end of a shift.
- The handover note sits with the dish. It says which oven and which recipe version. That's the run record.
- A new cook with no note uses whatever oven is free, and the dish comes out different. That's a resume on the default.
- A change on purpose: taste first, then write the change on the note. That's a migration.
The note travels with the dish, so any cook can carry on, on the same oven or on a new one chosen on purpose.
What one record holds
The record for T-201 after its first tool turn has six fields. The run printed it as model claude-sonnet-5-5, prompt v1, step 1, notes 1.
| Field | Value | Why it's there |
|---|---|---|
| ticket_id | T-201 | Which run this is |
| model | claude-sonnet-5-5 | Pinned when the run starts |
| prompt_version | v1 | The prompt this run was written for |
| step | 1 | Tool turns done |
| messages | 3 | The conversation; can be trimmed or dropped on a model change |
| notes | customer prefers email | Memory kept outside the conversation |
A restart reads this one file and needs nothing from the process that stopped.
run_record.py: the whole idea
The project runs on a stand-in model (the Anthropic SDK on an httpx mock transport), so no API key is needed and the replies are test replies.
"""Run record: the checkpoint carries the model id and the prompt version the run started with."""
import json, pathlib
STATE = pathlib.Path(__file__).parent / "state"
RETIRED = {"claude-old-snapshot"}
def start(ticket_id, model, prompt_version):
return {"ticket_id": ticket_id, "model": model,
"prompt_version": prompt_version, "step": 0,
"messages": [], "notes": []}
def save(rec):
STATE.mkdir(exist_ok=True)
path = STATE / f"{rec['ticket_id']}.json"
path.write_text(json.dumps(rec), encoding="utf-8")
def load(ticket_id):
f = STATE / f"{ticket_id}.json"
return json.loads(f.read_text(encoding="utf-8")) if f.exists() else None
def model_for(rec):
if rec["model"] in RETIRED:
raise RuntimeError(f"{rec['model']} is retired: migrate on purpose")
return rec["model"]
def migrate(rec, model, prompt_version):
rec["migrated_from"] = [rec["model"], rec["prompt_version"]]
rec["model"], rec["prompt_version"] = model, prompt_version
return rec
startpins the model id and the prompt version when the run begins, and gives the notes their own list beside the messages.model_foranswers from the record, never from the default.- If the pinned model is retired,
model_forrefuses. It doesn't retry, it doesn't fall back to the default, and it doesn't guess. migratechanges both values on purpose and keeps the old pair inmigrated_from, so the change can be read later.
claude-old-snapshot is a made-up stand-in id. It stands for any model the Claude docs list as retired.
One run, four resumes
run_all.py starts T-201, saves the record, then copies it so each resume starts from the same interrupted run (T-202 and T-203 are those copies). Then it changes the default and resumes four ways:
DEFAULT_MODEL = "claude-haiku-5-5" # the team changed the default while the runs were interrupted
# A: resume on the default (the mistake)
rec = run_record.load("T-201")
agent.step(rec, client, DEFAULT_MODEL)
# B: resume on the record
rec = run_record.load("T-202")
agent.step(rec, client, run_record.model_for(rec))
# C: migrate on purpose, then resume
rec = run_record.migrate(run_record.load("T-203"), "claude-opus-5-5", "v2")
run_record.save(rec)
agent.step(rec, client, run_record.model_for(rec))
# D: an old run pinned to a retired model
old = run_record.start("T-204", "claude-old-snapshot", "v1")
run_record.model_for(old) # raises RuntimeError
That's an excerpt with the log lines taken out. Here is what the full run printed:
run 1: T-201 starts on claude-sonnet-5-5, then the worker is interrupted
record saved | model claude-sonnet-5-5, prompt v1, step 1, notes 1
the default model is now claude-haiku-5-5
resume A: T-201 on the default model
record says claude-sonnet-5-5 | resumed on claude-haiku-5-5 | model changed silently
claude-haiku-5-5 | prompt v1 | reasoning blocks kept 0, dropped 1 | notes 1
resume B: T-202 on the model in the record
record says claude-sonnet-5-5 | resumed on claude-sonnet-5-5 | model unchanged
claude-sonnet-5-5 | prompt v1 | reasoning blocks kept 1, dropped 0 | notes 1
test model reply: I emailed Carla her invoice.
resume C: T-203 migrated on purpose
migrated claude-sonnet-5-5, v1 -> claude-opus-5-5, v2
claude-opus-5-5 | prompt v2 | reasoning blocks kept 1, dropped 0 | notes 1
test model reply: I emailed Carla her invoice.
resume D: an old run pinned to a retired model
refused | claude-old-snapshot is retired: migrate on purpose
- A resumed on Haiku while the record said Sonnet. One reasoning block was dropped. The note stayed, because it lives outside the messages.
- B asked the record: same model, the block kept.
- C moved from Sonnet and v1 to Opus and v2 on purpose, and the block was still read.
- D found a retired model and refused with a clear message, before any call.
Why a switch can drop context
Two things can change under a running agent.
A model switch. The lecture's example follows the Claude docs page on thinking ("Switching models mid-conversation"): Opus 5.5 reads the reasoning blocks Sonnet 5.5 wrote, while Haiku 5.5 does not, so earlier reasoning is dropped. In the project a small table in stand_in.py plays that rule, and the block signatures are made up. The docs also say to pass thinking blocks back unchanged rather than strip them. And a prompt or tool schema written for one model needs testing on the next one before you move (see thinking blocks in the Messages API).
The life of a model. Active, then deprecated, then retired. Requests to a retired model fail. Every model id is a pinned snapshot, so pin the id and don't follow a default. The app-level side of this (one exact id in config, a golden-set replay before switching) is in pinning Claude model ids and upgrading safely. This article is the same rule applied to one run that outlives its process.
Why the notes sit outside the messages
Look at resume A again: one block dropped, notes 1. The messages are the part that can be trimmed, compacted, or lose blocks when the model changes. The fact "customer prefers email" was kept in notes, and prompt v2 even puts the notes into the system text (Known facts: {notes}). Whatever the model does with the history, that fact comes back.
Common mistakes
- Resuming on the newest default. The model changes silently, as resume A showed.
- Stripping the thinking blocks to make a switch "safe". The docs say to pass them back unchanged.
- Keeping memory only in the conversation. A trim or a model change can lose it. Keep facts in their own field.
- Falling back to the default when the pinned model is retired. That's another silent switch. Refuse and migrate on purpose.
- Migrating without writing it down. Keep the old model and prompt version in the record so the change can be traced.
Quick recap
| Rule | In the code | In the run |
|---|---|---|
| Pin the model id and prompt version at start | start() | sonnet-5-5, v1 |
| Resume on the record's model | model_for() | B: unchanged, 1 block kept |
| Migrate on purpose and record it | migrate() | C: sonnet v1 to opus v2 |
| Refuse a retired model | RETIRED check | D: refused |
| Keep notes outside the messages | notes field | notes 1 in every resume |
Try it yourself
Add a resume E: the record says Sonnet, and someone wants to move the run to Haiku because it's cheaper. Write it as a migration, not as a default. Before you run it, predict the reasoning-block line it prints and whether the note survives.
Related course on Udemy
Claude Certified Developer - Professional (CCDV-P) Exam Prep
Claude agents in production: reliability, observability, evals, cost, guardrails and fleets.View on Udemy ↗: Claude Certified Developer - Professional (CCDV-P) Exam Prep (paid course, opens in a new tab)Related posts
The Claude Messages API: Your First Call, Field by Field
One request in, one Message out. The four fields of a Messages API call (model, max_tokens, system, messages), how to read content blocks, stop_reason and usage, and why every turn resends the history.
Claude Tool Use: How tool_use and tool_result Work in the Messages API
Follow one order question through Claude's tool round trip: define a tool, read the tool_use block, run your own function and send a matching tool_result back, including parallel calls and is_error.
Claude Client SDKs Wrap One REST API: Raw HTTP, Python, TypeScript and Async Calls Compared
Every Claude client SDK wraps the same REST request: a POST to /v1/messages with a JSON body. See it built by hand, through the Python and TypeScript SDKs, as typed errors, and as async calls that wait together.
Anthropic SDK Timeouts, Retries and Error Classes: Configure the Client Once, Then Give 429, 529, 400 and Timeouts Their Own Move
Configure the Anthropic SDK client (timeout, max_retries, with_options, async, pagination), see which errors it retries by itself, then repair a retry wrapper so a 429, a 529, a 400 and a timeout each get the move the docs support.
