Track 03 · Agents & toolsLesson 07 of 12
Workflows that survive restarts
Durable execution for processes that run for days through outages and deploys.
- Lesson library · reference
- 40 min read
- 75 min hands-on
- Pro
What you'll be able to do
01- Explain why an agent process that waits for days breaks on restarts, deploys and outages, and what durable execution does about it: event history, replay and durable timers.
- Separate a long-running agent process into deterministic workflow code and activities, and place every model call, tool call and clock read on the correct side.
- Implement a Temporal workflow with per-activity timeouts and retry policies, a signal for incoming documents, an update for human approval, a query for status, and a multi-day timeout.
- Diagnose a non-determinism failure from a replay and choose a safe versioning strategy for workflow code that has executions in flight.
- Design idempotency keys and compensation (sagas) so retries and partial failures never duplicate or orphan an external action.
- Choose between Temporal and its alternatives for a customer's estate, and defend the choice to a platform owner.
Before you start
- The agent loop, written by hand: the bounded loop that becomes one activity here.
- Retries, fallbacks and failing gracefully: retries, timeouts and idempotency inside the agent. The README teaches 09 before this concept.
- Tools with scoped, auditable access: token refresh and why credentials never live in state.
- Approval gates and bounded autonomy: the gate design that this concept makes durable.
- Comfortable with Python
asyncioand dataclasses.
The short version
Prior-authorisation intake waits: days for a fax, hours for a nurse's approval. A process that holds that wait in memory (a sleeping thread, an asyncio task, a polling loop) loses its place when the pod restarts, the deploy rolls or the region fails. Durable execution persists every step. You write the process as workflow code that only orchestrates, and put every side effect (model calls, tool calls, emails) in activities. The engine records each activity's result in an event history. After a crash, a new worker replays the workflow code against the history: completed steps return their recorded results instead of running again. For replay to work, workflow code must be deterministic: no wall clock, no randomness, no I/O, no LLM calls. Fourteen-day timers, signals and updates that deliver documents and approvals, and status queries all become durable. Activities still run at least once, so writes still need idempotency keys.
Key takeaways:
- Workflow code decides; activities do. Every model call is an activity.
- Replay re-runs your workflow code from the start against recorded results; any difference in the commands it issues is a non-determinism error.
- Waits are durable timers and signals, not sleeping processes. A case waiting 14 days costs nothing while it waits.
- Changing workflow code with executions in flight is a versioning problem. Test it with replay before you deploy.
- Durable execution gives you exactly-once orchestration, not exactly-once side effects. Idempotency keys and compensation remain your job.
Pro lesson
The rest of this lesson is in Pro.
The mental model, worked example, field note, failure table, exercise and self-check, with the voice tutor.
- Every stage and specialisation, in full
- Every lab and every role project
- Halden weeks 2–10, on your record
- Every drill, live in the playground
- All solutions, plus the server judge
- Lab Assistant and every Teach with AI