Durable execution
Why Everruns persists every step of agent execution to PostgreSQL and runs each session as a leased actor: the guarantees that gives, and the trade-offs.
The word “durable” in “durable agentic harness engine” means a specific thing: recorded execution state survives a process restart, so a turn can recover from its log. This page explains why that matters, how it works, and what it costs.
The problem
Section titled “The problem”An agent turn looks simple from the outside, send a message, get a streamed response. Internally it’s a chain of network calls that each take seconds:
- Call the LLM provider.
- Parse tool calls, dispatch them.
- Wait for each tool to return.
- Call the LLM again with the results.
- …repeat…
Anywhere in that chain, the worker process can crash, the container can be reaped, the network can blip. A naïve implementation loses all the work done so far and forces the user to retry. For a 30-second turn that already burned tokens, this is unacceptable.
The mechanism
Section titled “The mechanism”Everruns treats each session as an actor whose state is its event log. Every message, model response, tool call and tool result is appended to the session’s log in PostgreSQL before anything acts on it. A turn is never held anywhere else: the log is enough to pick it up again.
- Sending a message stores it and marks the session runnable, in one transaction.
- A worker leases the runnable session and runs the whole turn: reason, act, reason again, until the model answers or the turn waits on a person.
- The worker renews its lease every few seconds while the turn runs, and gives it back when the turn ends.
Messages that arrive while a turn runs reach that turn before its next model call. A message that arrives just as the turn ends starts the next turn. A turn waiting on a person (a client-side tool, an approval, a question) holds no worker: the answer is recorded in the log and the session becomes runnable again.
When a worker crashes mid-turn, its lease stops being renewed and expires after about ten seconds. Another worker leases the session, reads the turn’s part of the log and continues the turn where it stopped. The application sees a momentary stall in the SSE stream, then it continues.
Each lease has a fence number. The control plane rejects authoritative writes from a holder whose lease expired or was taken over. The displaced worker stops when it observes lease loss; fencing cannot revoke an external request that was already sent.
Why a custom engine
Section titled “Why a custom engine”The obvious alternative is Temporal (or Cadence, or Restate). Everruns deliberately built its own minimal durable execution instead: session leases and the event log for turns, and everruns-durable, a generic, published Rust crate (task queue, event log, schedules, retries, dead letter queue, circuit breakers) with no agent concepts, for the background work around them. The reasoning:
- Single dependency. PostgreSQL is the only required stateful infrastructure for a single control-plane instance. Multiple control-plane instances need NATS for live event delivery; without it they report degraded polling. Valkey is optional. Operators don’t need to run a second cluster with its own ops story.
- Co-located with the rest of the platform. Workflow events and session events live in the same database, in the same transaction when needed. There’s no eventual consistency between “what happened” and “what was reported.”
- Tight scope. Everruns runs agentic workflows specifically, limited fan-out, short-to-medium duration, well-understood failure modes. We don’t need the full Temporal feature set, and the operational surface area of a tightly-scoped engine is much smaller.
The trade-off: no multi-region replication beyond what PostgreSQL itself offers, no language-agnostic SDK (the engine is a Rust library), no visual workflow designer. For agent execution these are not missed.
Guarantees
Section titled “Guarantees”What durable execution gives you:
- Recorded outcomes survive a crash. If a worker dies, another worker resumes the turn from its log. A model response already recorded is not requested again, and an answer already recorded is not given twice.
- Persisted tool results. Tool calls are persisted by their result, not their attempt, so a tool whose result was recorded is not re-run. A call cut off before its result was recorded runs again only when that is safe: its tool declares it read-only or idempotent, or the call never started. A call that must run at most once does not start until its
tool.startedevent is stored, so a call without one never ran. Any other unfinished call is recorded as interrupted and the model is told its outcome is unknown. Each call also carries an idempotency key that stays the same when it runs again, sent to MCP servers in the request’s_metaasio.everruns/idempotency-key, so a server or gateway that honors it can drop the repeat. - One authoritative lease holder per session. Fenced writes prevent a displaced worker from committing turn events. In-flight external effects still require the tool-specific safeguards below.
- Authoritative history. Reloading a session reads back the same persisted message sequence, which makes traces and exports authoritative.
What it doesn’t give you:
- Idempotence of side effects. A tool that declares itself idempotent is run again after a crash, so if it POSTs to an external API it must make the repeat harmless, for example by forwarding the call’s idempotency key (
ToolContext::idempotency_key). An unfinished tool call with the default at-most-once declaration is not automatically replayed after a recorded start, but a crash after it acted and before its result was recorded leaves its outcome unknown. - Real-time latency guarantees. Persisting durable events adds storage latency and load; ephemeral streaming deltas can bypass PostgreSQL. LLM latency often dominates a turn, but that does not make storage overhead negligible under every workload.
Durability in the Framework
Section titled “Durability in the Framework”Rust applications that embed the Framework share the execution
kernel, but must choose a hosting profile that provides the required recovery
boundary. Engine::new() retains sessions only for that Engine’s lifetime.
Native hosting::SqliteHosting persists admission and session state; register
the exact agent builds and environment factories and run its supervisor for
independent recovery. External hosting supplies its own durable authority and
activation. Legacy LocalConfig storage has a weaker recovery boundary and is
not equivalent to native durable Engine hosting. See Framework
Architecture.
When the database becomes the bottleneck
Section titled “When the database becomes the bottleneck”Everruns is designed to run on a single PostgreSQL primary. Read replicas help for reporting; write-heavy session loads are kept manageable by keeping event payloads compact.
In practice, LLM provider rate limits tend to cap throughput long before the database does.
Further reading
Section titled “Further reading”- The agentic loop, what each step inside a turn looks like.
- Architecture, how the control plane and workers interact.