Spawned
An actor framework for Rust, inspired by Erlang/OTP, built so that its guarantees
are verified once and inherited by every application, and so that concurrency
tests replay exactly.
Why Spawned
More and more code is written by LLMs and reviewed by people who did not write it. Concurrency is where that goes wrong: each call site looks plausible, and the bugs live in how the call sites interact. Spawned matters for two reasons.
The guarantees are verified once, centrally. Nobody can model-check and fuzz every hand-rolled Tokio pattern in an application. One framework can be. Message ordering, request outcomes, links, monitors, exit reasons, supervision and shutdown are written down in a semantics contract. They are checked by:
- TLA+ models (with Apalache proofs of the safety invariants);
- trace validation of the real code against those models;
- Loom;
- a deterministic simulator;
- a coverage-guided scenario fuzzer;
- failpoints, sanitizers, Kani and mutation testing;
- the ethrex and ethlambda test suites in CI.
Every application built on Spawned inherits that work instead of redoing it. TESTING.md describes each layer.
Tests are deterministic. Under --cfg spawned_sim, async tests written with #[spawned_concurrency::sim_test] run on a seeded, single-threaded simulator with virtual time, across many schedules. A failure prints its seed and a decision tape. The tape replays the exact interleaving and is shrunk to a minimal one. With raw Tokio, the same race shows up as a flaky CI run that nobody can reproduce. The simulator covers tasks mode. Code that calls tokio::spawn or tokio::time directly, instead of going through Spawned, cannot run on it. See what the simulator does not model.
Project Status
Spawned is actively maintained and used in production. It powers the concurrency layer of ethrex (Ethereum L1/L2 execution client) and ethlambda (Lean Ethereum consensus client), both developed by LambdaClass.
The core API is stable, so periods without commits are expected (they mean things are working, not that the project is abandoned). New features land as those projects need them (see the roadmap). Bug reports, questions, and pull requests are welcome and get answered.
Quick Example
Define a protocol, implement it on an actor, and call it:
// protocols.rs — define the message interface
use spawned_concurrency::Response;
use spawned_concurrency::protocol;
#[derive(Debug, Clone, PartialEq)]
pub enum FindResult {
Found { value: String },
NotFound,
}
#[protocol]
pub trait NameServerProtocol: Send + Sync {
fn add(&self, key: String, value: String) -> Response<()>;
fn find(&self, key: String) -> Response<FindResult>;
}
// server.rs — implement the actor
use std::collections::HashMap;
use spawned_concurrency::tasks::{Actor, Context, Handler};
use spawned_concurrency::actor;
use crate::protocols::name_server_protocol::{Add, Find};
use crate::protocols::{FindResult, NameServerProtocol};
pub struct NameServer {
inner: HashMap<String, String>,
}
#[actor(protocol = NameServerProtocol)]
impl NameServer {
pub fn new() -> Self {
NameServer { inner: HashMap::new() }
}
#[request_handler]
async fn handle_add(&mut self, msg: Add, _ctx: &Context<Self>) {
self.inner.insert(msg.key, msg.value);
}
#[request_handler]
async fn handle_find(&mut self, msg: Find, _ctx: &Context<Self>) -> FindResult {
match self.inner.get(&msg.key) {
Some(value) => FindResult::Found { value: value.clone() },
None => FindResult::NotFound,
}
}
}
// main.rs — use it
use protocols::{FindResult, NameServerProtocol};
use spawned_concurrency::tasks::ActorStart as _;
use spawned_rt::tasks as rt;
fn main() {
rt::run(async {
let ns = NameServer::new().start();
ns.add("Joe".into(), "At Home".into()).await.unwrap();
let result = ns.find("Joe".into()).await.unwrap();
assert_eq!(result, FindResult::Found { value: "At Home".to_string() });
})
}
No message enums, no manual dispatch — just define a trait, implement the handlers, and call methods directly on the actor reference.
For every feature (timers, type erasure, registry, backends, links, supervision, metrics and more), see the Guide.
Documentation
| Document |
Contents |
| Guide |
The user guide: lifecycle, messaging, execution modes and backends, timers, registry, links, execution groups, supervision and metrics |
| Examples |
Every feature mapped to a runnable example |
| Migration |
Upgrade notes per version |
| Changelog |
Release history |
| Roadmap |
Planned work and the ranked backlog |
| Semantics |
Every guarantee Spawned gives (messages, requests, lifecycle, links, supervision, shutdown, timers, panics), what checks it, and what is not guaranteed |
| Testing |
Test suites, verification layers and the formal model |
| Design |
Active design contracts |
| Research |
Research notes behind roadmap items: virtual actors, systematic testing, Ethereum client testing, request semantics |
| Benchmarks |
Running the benchmark harness |
Archive at efba2434 |
Archived designs, reviews, research notes and raw experiment data (not maintained) |
Features
- Verified semantics — every guarantee is written down in the semantics contract and checked by TLA+ models, trace validation, Loom, the simulator, fuzzing and the client test suites
- Deterministic simulation testing —
#[spawned_concurrency::sim_test] runs your async actor tests over many seeded schedules with virtual time; a failure replays exactly from its seed or decision tape
- Protocol macros —
#[protocol] generates message types, blanket impls, and type-erased refs from a trait definition
- Actor macros —
#[actor] generates impl Actor and Handler<M> impls from annotated methods
- Dual execution modes — async/tokio (
tasks) or blocking OS threads (threads) with the same API
- Type-erased protocol refs —
XRef types let actors communicate through protocol interfaces without knowing concrete types
- Actor registry — global name-based registry for discovering actors at runtime
- Timers —
send_after and send_interval for delayed and periodic messages
- Signal handling —
send_message_on to deliver messages on cancellation token signals
- Backend selection — async runtime, blocking thread pool, or dedicated OS thread (tasks mode)
How It Works
Protocols define the message interface for an actor. #[protocol] on a trait generates one message struct per method, a type-erased reference type (XRef), and blanket implementations that let any ActorRef<A> call the protocol methods directly — as long as A implements the right handlers.
The return type on each protocol method determines the message kind:
Response<T> — request (both modes), caller uses .await.unwrap() (tasks) or .unwrap() (threads)
Result<(), ActorError> — fire-and-forget send (both modes), returns the send result
- No return /
-> () — fire-and-forget send (both modes), discards the send result
Actors implement message handlers with #[actor]. Each handler method is annotated with #[request_handler] (answers with its return value), #[send_handler]