Execution model
A run is one call that moves a thread forward: RunAsync / run starts it, and a resume, a signal, a wake or a recovery continues it. This page explains what the engine does during that call, and where your handlers run.
A run, step by step
Section titled “A run, step by step”Every run follows the same loop in both engines:
- Wait for a slot, if the run has a run scheduler. Nothing is loaded or written before that.
- Take the lease, if the run has one, before its first save. See Thread leases.
- Load or start. A new run starts at the entry point. Any other run loads the thread’s latest checkpoint and continues at its
next_node. - Check before the node starts: the cancellation token and the hop limit.
- Run an attempt with the last committed state. If a fallible node fails, its recovery policy retries, falls back or fails (Retries and backoff).
- Commit the state the handler returned. A failed attempt’s changes never commit (The commit rule).
- Stop at a boundary. At an interrupt boundary or a wait, the engine saves an
interruptedcheckpoint and returns (Human-in-the-loop). - Route by the first outgoing edge that matches (Edges and routing). With no outgoing edge, the run ends
Completed. - Checkpoint per policy. Only
EveryNodesaves here: arunningcheckpoint before the next node, and acompletedone at the end (When checkpoints are written).
Then the loop returns to step 4. Edge conditions, reducers and subgraph mappers are synchronous and run on the executor, so keep them cheap and free of I/O.
Where handlers run
Section titled “Where handlers run”The engine is async: it runs on tokio in Rust, so a run must be polled inside a tokio runtime, and as tasks in .NET.
| Handler | C# | Rust |
|---|---|---|
| Async | A task the run awaits | A future the run polls on a tokio worker |
| Sync | The thread pool, through Task.Run |
tokio’s blocking pool, through spawn_blocking |
| Inline sync | Not in .NET | The tokio worker, like an async handler |
An async handler holds no thread while it waits on a model call. A sync handler runs off the executor for two reasons: if it blocks, it blocks only its pool thread, not other runs, and the engine can stop waiting for it on a timeout or a cancellation (see Abandoned work). The price is a thread hand-off each way per sync node.
Inline sync handlers in Rust
Section titled “Inline sync handlers in Rust”add_inline_node and add_inline_fallible_node take the same handlers as add_node and add_fallible_node, but run them on the executor, with no hand-off. In exchange, an inline handler:
- Must not block. No I/O, no sleeping, no contended lock, no sync store call, no
block_on. While it runs, it holds a tokio worker, or the whole runtime on a current-thread runtime. Nothing detects a handler that blocks. - Can’t be abandoned.
.compile()refuses a timeout on it. A cancellation that arrives while it runs takes effect when it returns: its result commits, and the run stops before the next node. - Can’t stream. It gets the state and nothing else.
Use them for small CPU-only steps, such as routing or parsing. .NET has no inline nodes.
Cancellation and timeouts
Section titled “Cancellation and timeouts”A run stops early when you cancel it (the CancellationToken you pass to RunAsync, or RunConfig::with_cancellation), when its deadline passes (RunOptions.Deadline / RunConfig::with_deadline), or when a node’s timeout passes (SetTimeout / set_timeout, per attempt). Every attempt, branch and subgraph child gets a child of the run’s token, so a cancellation reaches every depth.
A cancelled run returns Cancelled and saves a cancelled checkpoint at the node that was running, with the state that node started with. A resume continues it there (Statuses). A cancellation isn’t a failure, so no recovery policy sees it. A timeout is a transient failure, so a recovery policy can retry it.
In C#, an OperationCanceledException counts as a cancellation only when the engine’s token was cancelled. In Rust, dropping the future of graph.run(...) isn’t a cancellation: the run stops where it is and saves nothing.
Abandoned work
Section titled “Abandoned work”Cancellation is cooperative. The engine signals the token, then stops waiting. It never waits for a handler it has given up on. That handler is abandoned:
- A .NET async handler sees its token cancelled. If it ignores the token, it runs on unobserved.
- A Rust async handler’s future is dropped. That happens only between polls, so code between two
.awaits runs to the end. - A sync handler can’t see a token. It keeps running on its pool thread.
Its result is discarded, but its side effects still happen, and a retry can start while it still runs. In demo 15, a blocked sync ledger call times out, and the invoice is posted twice. A handler whose side effects must not overlap should be async, honour its token, and use the idempotency key.
Subgraphs and maps aren’t abandoned. They are graphs, so the engine cancels their token and waits while their nodes wind down.
Parallel groups and maps
Section titled “Parallel groups and maps”A parallel group and a map are each one node to the run loop. Inside it:
- Each branch or item is its own task. Async branches hold no thread while they wait. A sync branch gets a thread: its own
LongRunningthread in .NET, a blocking-pool thread in Rust. - Every branch starts from the same state, and can’t see the others’ changes.
- The node limits concurrency. A group runs every branch at once unless you set
MaxConcurrency. A map runs at most 8 items at once by default. - Results merge in a fixed order: declaration order for a group, list order for a map, never the order they finished (Merging parallel results).
- One commit, one hop. The reducer’s result commits once, and under
EveryNodethe node is checkpointed once. Branch and item progress isn’t saved, so a retry, resume or recovery runs them all again.
When a group gives up, for example after a branch fails, it cancels the rest, and the abandonment rules apply. In Rust, a sync branch that hasn’t started yet never starts.
The run scheduler
Section titled “The run scheduler”Without a scheduler, every run starts the moment you call it. A RunScheduler, passed with RunOptions.Scheduler / RunConfig::with_scheduler, bounds how many runs one process has in flight. Limit each process with the run scheduler shows the setup.
- A slot is one run call, from before it loads anything until it returns. Branches, items and subgraph children take no slot. A run in a retry’s backoff or waiting on a model still holds its slot. An interrupted run gives it back, so a waiting thread holds nothing.
- Priority is strict: higher first (
RunOptions.Priority/with_priority, 0 by default), and first come, first served within a priority. Reserved slots keep headroom for high priorities. A running run is never stopped to make room. - Each tenant has a concurrency limit, by a metadata key (
tenantby default). A tenant at its limit doesn’t hold back others.SetTenantLimit/set_tenant_limitchanges a limit at run time, and 0 pauses the tenant. - The queue is bounded (
MaxQueued, 1,024 by default). When it’s full, a newcomer sheds a lower-ranked waiting run, or is refused.
A run that gets no slot returns NotAdmitted, a kind of Failed (StrataError::NotAdmitted in Rust), with a reason: QueueFull, Shed, QueueTimeout, Cancelled, Deadline or Closed. It wrote nothing, not even a run event, so the thread is as it was and you can call again. Each process has its own scheduler. Strata has no limit across replicas.
What the engine costs
Section titled “What the engine costs”The engine’s cost per node is small next to a model call. These figures are from benchmarks/RESULTS.md, on one machine. Performance explains the method and its limits.
- An async node costs about 0.4 µs in both engines at the median. In Rust it was 1.8 µs before
design/38, which made the executor plan each node when the graph compiles and dropped most of its per-node allocations and string formatting. - A sync node in Rust costs 1.1 to 5.5 µs, depending on whether the pool thread is awake for the hand-off. In .NET it costs about 1.4 µs.
- A branch costs about 1.5 µs in Rust and 0.6 µs in .NET, and a map item 2.1 µs and 0.9 µs, because each is a task.
An inline node skips the hand-off and runs the way an async node does. RESULTS.md doesn’t measure inline nodes yet.
One run, one process
Section titled “One run, one process”A run executes in one process, branches and items included. Strata doesn’t split a run across machines. A thread moves between processes only through the store: one process stops at a checkpoint, and another resumes or recovers it. See What Strata leaves to you.
See it run
Section titled “See it run”Each demo exists in C# and in Rust:
- 15-async-and-cancellation: node context, a timeout that becomes a retry, an abandoned sync handler, and cancelled runs resumed. The Rust version adds an inline node. C#, Rust.
- 10-parallel-fan-out: a parallel group, its merge and its retry. C#, Rust.
- 29-run-scheduler: priority, reserved slots, tenant limits and shedding. C#, Rust.
- Durable execution: what survives a crash, recovery and thread leases.
- Threads and checkpoints: what a checkpoint holds and when Strata writes one.
- Performance: the benchmark results and how to run them.