A flow is an async def f(ctx, ...) decorated with @flow. Run it with await f.run(...).
A step is any function decorated with @step (sync, async, or a generator for streaming). Calling it inside a flow journals its result.
A journal stores each run as a signed list of entries. On resume(run_id) the flow function runs again from the top; completed steps return their recorded result instantly and execution continues at the first unfinished step.
The one rule: code outside steps must be deterministic. Put I/O, LLM calls, randomness and clocks inside steps, or use ctx.now() / ctx.uuid(). If flow code changes so that replay no longer matches the journal, the run stops with ReplayDivergencebefore running anything new (@flow(strict=False) only reports a divergence event); use ctx.patched() to change code safely.
Concurrency. Tasks created by flow code (asyncio.gather, create_task, TaskGroup) each get their own key scope (t0/, t1/, …) in creation order, so steps inside concurrent branches replay correctly whichever branch finishes first — on every Python version. When one branch suspends, the others keep running (up to drain_timeout, default 10 s) to their own suspension point, and the run wakes at the earliest deadline among them. When a run fails or finishes while branches still run, steps already executing are allowed to finish and are journaled (bounded by the same drain_timeout), no new step starts, and then the remaining branches are cancelled — so nothing that already happened is repeated on resume.
Handled failures stay handled. If flow code catches a StepFailed and carries on, resuming re-raises the same failure (wrapping a ReplayedError) instead of re-running the step. A failure that ended the run is retried on resume. Steps that ran while that failure was being handled (in an except, finally or async with on the way out) don't bind replay order, so a successful retry can take the success path; if such a step is reached again with the same arguments it replays instead of running twice, and with other arguments it runs. To mark a caught failure as not handled when you raise a different error, chain it: raise RuntimeError("payment failed") from e.
TaskGroups work. Durable waits inside an asyncio.TaskGroup suspend the run like any other branch. A branch about to suspend first lets its siblings reach their own durable waits (or finish the step they're in), so every deadline is recorded before the TaskGroup cancels them.
An earlier attempt still running is waited for, not repeated. If a resume finds a step's attempt from an earlier execution still running in this process, the run suspends briefly (PriorAttemptRunning) and then uses that attempt's result.
Nothing runs twice because it couldn't be recorded. If a step's result can't be journaled, the step fails with ResultNotJournaled and is never re-run on resume. State values that can't be journaled are recorded as placeholders (with a state_unserializable event) instead of losing the step.
Run identity is checked.resume() of an unknown id raises UnknownRun; a run id that belongs to another flow raises FlowMismatch; run(...) with different inputs for an existing id raises RunExists. Give a flow a stable identity with @flow(name="checkout") if you might rename the function.
The journal is checked before it is trusted. Every load verifies the run's chain (run id, order, links, signatures), so forged, edited or copied rows raise JournalCorrupt instead of being replayed.
Nested steps and child flows. A @step called from inside another step is a plain call; the outer step's result is the checkpoint. A flow started inside a step (await child.run(..., run_id=idempotency_key())) is its own durable run.
Suspension can't be swallowed.Suspended and ContinueAsNew derive from BaseException, so except Exception in flow code won't catch them.
One executor per run.run/resume hold a per-run lock (in-process for every journal, cross-process for file/SQLite on POSIX, database locks for Postgres). A second caller gets RunLocked.
Inputs are journaled in clear so runs can resume. pylinxi therefore refuses flow inputs, initial state, signals or continue_as_new payloads containing secret-looking keys; pass secrets by reference and load them in a @step(sensitive=True).