---
title: Retries and durability
description: "Choose what a step retries, what fails fast, and how side effects survive a step that runs again."
---

Choose what a step retries, what fails fast, and how side effects survive a step that runs again.

## Steps are the durability boundary

Choose a step boundary where a result should survive a retry and be independently
inspectable. Separate expensive work from external writes when they need different
recovery behavior; keep cheap pure transformations together.

Use the decorated step name in a workflow body to schedule a durable call.
For a direct Python call from a test, a helper, or another step, use
`my_step.fn(...)`, or `await my_step.fn(...)` for an async function. Pass its
original arguments, including `ctx: StepContext` when declared. A direct
`.fn` call inside a step is part of that caller's attempt, with no separate
checkpoint or retry policy; the calling step must declare any connections
that code needs. Calling the decorated name directly raises an error naming
the `.fn` remedy.

To declare another configuration of an existing step, decorate its original
function: `slow = step(key="slow", timeout="1m")(base.fn)`.

`andon workspace validate` also reports direct calls from one decorated step body to
another when the source resolves the target: a same-module step, an imported
step name, or a module-qualified alias. It respects parameter and local
shadowing. Reassigned, ambiguous, and dynamically selected targets are left
to the runtime check. `.fn` calls are ordinary Python calls.

Editor types check workflow calls. A step call takes the step's declared
parameters, without the `StepContext` the platform supplies, and has the
step's result type, awaited for an async step; a workflow call takes the
callee's parameter and has its return type. An editor reads a step whose first
parameter is typed `object` or `Any` as taking the context, so type that
parameter more narrowly. Validation and deployment check every call as well.
`.fn` is the original Python function, including its context parameter and
async return; an editor reads that context parameter as positional.

Each workflow step invocation (and each map element) is checkpointed: on
crash or replay, completed steps return cached values and the body never
re-runs. Consequences:

- **Side effects must be idempotent or safe to repeat.** A step interrupted
  mid-body (worker restart, sandbox channel loss) re-executes from the top on
  the next attempt, so emails, DB writes, and posts inside it can happen again.
  Give connection writes provider idempotency keys where the provider offers
  them.
- **An `HttpApi` connection returns every answer, whatever its status.** Check
  `status` before using `json` or `text`, and raise `StepRetryError` yourself
  for one worth another attempt, such as 429. A `POST`, `PUT`, `PATCH` or
  `DELETE` that got no answer fails the step without spending its retry
  budget, because the API may have applied it. That covers this one failure:
  a step that re-runs for another reason, as above, sends its requests again.
  Look a record up before creating it, so a repeated step finds what an
  earlier attempt wrote.
- **Agent dispatch must be replay-stable.** Replays match cached
  agent inputs and inner model/tool calls against the call sequence and
  verify their identity. Branching on cached model or tool results is
  safe; deriving agent-call order or count from non-checkpointed state is
  not. Avoid unordered iteration, randomness, clocks, race/completion
  order, and unrecorded external reads. Create and consume concurrent
  calls in a fixed order (`asyncio.gather(...)` preserves argument and
  result order), or compute the nondeterministic decision in an upstream
  step. A divergence either fails with a checkpoint mismatch or executes
  a new call, repeating side effects and spend.
- **Return values must serialize.** Each value crossing between step code and
  the platform may serialize to 16 MiB of JSON: a step's arguments and its
  return value, a prompt with its agent inputs, and each tool or connection
  call's arguments and result. Step code holds a value and its serialized form
  in sandbox memory together; hosted sandboxes have 512 MiB. Values stored
  with the run and returned inline by the API are limited to 1 MiB each: the
  workflow's input and output, a called workflow's input, and a wait's `context`
  and `subject`. For larger text, parsed documents, or reports: `await
  ctx.write_artifact(value, filename=...)` and pass the returned `FileRef`
  between steps; `await ctx.read_artifact(ref)` rehydrates it.
- **Prompts are limited by their model.** Before dispatch, the runtime checks
  estimated input, including serialized tool results and output schemas,
  against the model's input/context limits and declared `UsageLimits` token
  budgets. Provider framing and attachments such as PDFs or remote files
  cannot be fully counted locally; the provider enforces the final limit.
  Current models accept 922,000 input tokens, but a call above 272,000 input
  tokens is priced higher for the whole call; `andon logs show` flags it.
  Remove repeated or unused data from prompts before sending more.
- `@step(retry=Retry(retries=N))` retries `StepRetryError` and platform
  failures the runtime marks transient (RPC blips, retriable provider errors);
  ordinary exceptions from your code fail fast on purpose. Wrap
  transient failures your own code encounters: `except
  SomeTransientError as exc: raise StepRetryError(...) from exc`.
- `@step(timeout="10m")` bounds each execution attempt of the step body;
  exceeding it fails the run with a step timeout and tears down the run
  sandbox. Unset steps get the platform default (30m), which is also the
  maximum authored step timeout. Durable waits are outside this body deadline:
  event/review waits use their own timeout, a called workflow runs under its
  own `@workflow(timeout=...)`, and `sleep` lasts until its wake time.
- `@workflow(timeout="40m")` bounds the run's active time: cumulative
  execution across resumptions. The default and maximum are 50m. Provisioning,
  step attempts and in-process retries, canonicalization, serialization, and
  teardown consume the budget; queue time and time parked on an event or review
  wait, a durable sleep, or a called workflow do not.
- A run ends within 14 days of starting, whatever it is waiting on. One limit
  on the run covers sleeps, waits and loops around them. A run that reaches
  it fails with a message naming the limit and what it was waiting on; its
  open waits close and its running child runs are cancelled. Deploy rejects a
  constant sleep `duration` or wait `timeout` longer than 14 days. A wait
  whose timeout falls after the run's last day shows responders that day as
  its deadline, ends with the run, and never reaches its timeout outcome.
  Work that must wait longer ends its run, and a later run continues it.
- Declare `ctx: StepContext` as the first parameter for platform
  capabilities: `ctx.prompt(...)` (one-shot LLM call, `output_type=` for
  a validated model or `output_schema=` for a runtime JSON Schema),
  artifact I/O, `ctx.parse_document(...)`, and `ctx.connect(connection_ref)`
  (grant the same `ConnectionRef` in `@step(connections=[...])`).
- Steps that await anything must be `async def`.
- Annotate every step parameter and the return type; deployment rejects a
  step without them. Write `-> None` for a step that returns nothing.
