Guides authoring idiomatic actors with the atomr crate: Msg enums, Actor trait lifecycle hooks, ask vs tell, supervision strategies, and FSM patterns.
Ships in atomr-ai-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
This skill helps you write idiomatic actors against atomr (umbrella
crate atomr on crates.io, imported as atomr).
A atomr actor is state + behavior + a typed mailbox. Each actor:
Msg type (typically an enum),async fn handle(&mut self, ctx, msg),ActorRef<Msg> returned from
ActorSystem::actor_of(...).Tell-style sends are fire-and-forget; ask-style sends return a future resolved by the actor's reply. Failure is supervised by the parent — the actor itself does not catch panics.
Defined in atomr_core::actor::traits; available from the prelude.
use atomr::prelude::*;
#[derive(Default)]
struct Greeter { count: u64 }
#[async_trait]
impl Actor for Greeter {
type Msg = String;
async fn handle(&mut self, _ctx: &mut Context<Self>, msg: String) {
self.count += 1;
println!("hi {msg} (#{count})", count = self.count);
}
// Optional lifecycle hooks (defaults are no-ops):
async fn pre_start(&mut self, _ctx: &mut Context<Self>) {}
async fn post_stop(&mut self, _ctx: &mut Context<Self>) {}
async fn pre_restart(&mut self, _ctx: &mut Context<Self>, _err: &str) {}
async fn post_restart(&mut self, _ctx: &mut Context<Self>, _err: &str) {}
fn supervisor_strategy(&self) -> SupervisorStrategy {
SupervisorStrategy::default()
}
}
Keep in mind:
Actor: Sized + Send + 'static and Msg: Send + 'static.handle is async. Long-running work blocks this actor's mailbox —
spawn a child or pipe a future via pattern::pipe_to for parallelism.pre_restart runs on the dying instance; post_restart runs on the
fresh one. Clean up handles in post_stop.enum per actor. It documents the protocol and lets
the compiler enforce exhaustiveness in handle.pattern::ask which handles the
oneshot for you.Send. Avoid borrowed data; an
ActorRef lives across threads.handle. This keeps messages serializable for
remoting/clustering.enum Cmd {
Get { key: String, reply: tokio::sync::oneshot::Sender<Option<String>> },
Put { key: String, value: String },
}
let system = ActorSystem::create("app", Config::empty()).await?;
let greeter = system.actor_of(Props::create(Greeter::default), "greeter")?;
greeter.tell("world".to_string());
system.terminate().await;
Props::create(F) takes a factory F: Fn() -> A so the supervisor can
re-instantiate the actor on restart. Don't capture mutable state in the
closure — capture Arc-shared dependencies instead.
actor_ref.tell(msg) — fire-and-forget, infallible, fastest path.
Use this for the vast majority of message flows.pattern::ask(actor_ref, msg, timeout) — request/response. Returns
a future resolved by the actor's reply, or a timeout error. The
actor must be authored to send a reply (often via a oneshot inside
the message).Don't ask from inside handle — it blocks the mailbox. Use
pattern::pipe_to to fold an ask's future back into a self-tell.
The default strategy is one-for-one with restart-on-panic. Customize
in supervisor_strategy:
use atomr::prelude::*;
use std::time::Duration;
fn supervisor_strategy(&self) -> SupervisorStrategy {
OneForOneStrategy::new()
.with_max_retries(3)
.with_within(Duration::from_secs(60))
.with_decider(|err| {
if err.contains("transient") { Directive::Restart } else { Directive::Stop }
})
.into()
}
Directives: Resume (drop the message, keep state), Restart (rebuild
state via the factory), Stop (shut the child down), Escalate (defer
the decision to the grandparent).
For protocols with explicit states, prefer the fsm_macro (or the
hand-written FSM pattern in atomr_core::actor) over branching on a
state field inside handle. See crates/atomr-core/src/fsm_macro.rs
and crates/atomr-persistence/src/persistent_fsm.rs for the pattern.
| You need… | Reach for… |
|---|---|
| State that survives restart (event sourcing) | atomr-persistence — see atomr-persistence skill |
| Cross-process / cross-host messaging | atomr-remote |
| Membership, sharding, pub/sub | atomr-cluster* — see atomr-cluster skill |
| Reactive pipelines | atomr-streams |
| Deterministic tests | atomr-testkit — see atomr-testing skill |
For TCP/UDP work, use the IO manager actors rather than touching
sockets directly. TcpManager accepts a Bind { addr } command for
listeners and a Connect { addr } command for outbound connections;
TcpManager::connect(addr) is a convenience helper that wraps the
latter. Both return an ActorRef for the connection actor that owns
the socket and forwards Received / Closed messages.
crates/atomr-core/src/actor/traits.rs — Actor trait definitioncrates/atomr-core/src/supervision.rs — strategies and directivescrates/atomr-core/src/lib.rs — prelude contentsexamples/pingpong/ — minimal tell-loopexamples/fault-tolerance/ — restart semantics + lifecycle hooksdocs/idiomatic-rust.md — design choices behind the APIdocs/architecture.md — runtime structurehandle. Mailbox stalls. Use
pattern::pipe_to to fold the result back as a future message.Props::create. Restart re-runs the
factory; mutable captures violate that contract.Msg. Msg: Send + 'static — own your bytes.handle. Let the supervisor decide.ask where tell would do. ask allocates a oneshot per
call; on hot paths a tell + reply-via-message is cheaper.What SKILL.md sets; muted values are Claude Code's defaults
/atomr-ai-skills:atomr-actor-designfrom atomr-ai-skills
npx claudepluginhub rustakka/atomr --plugin atomr-ai-skills6 skills in this plugin
/atomr-clusterUse when bringing up clustering, sharding, singleton, distributed pub/sub, or distributed-data (CRDT) features in a project that depends on atomr. Covers feature flag selection, seed-node bootstrap, MessageExtractor design for sharding, and DistributedPubSub patterns. Triggers when adding cluster membership, ShardRegion, ShardCoordinator, ClusterSingleton, or Replicator usage./atomr-persistenceUse when adding event sourcing to an actor in a project that depends on atomr. Covers the Eventsourced trait, journals, snapshots, recovery, RecoveryPermitter, AsyncSnapshotter, and choosing a storage adapter (sql / redis / mongodb / cassandra / aws / azure). Triggers when implementing PersistentActor or Eventsourced, configuring a Journal/SnapshotStore, or wiring a backend./atomr-pythonUse when working with atomr's Python bindings — authoring Python actors, choosing a GIL/dispatcher strategy (python-pinned / python-subinterpreter-pool / python-nogil / python-subprocess), using ask/tell from async or sync code, or declaring C-extension subinterpreter compatibility. Triggers when `pip install atomr`, `from atomr import …`, or any Python file calling `ActorSystem`, `Props`, `Actor`, etc./atomr-testingUse when writing tests against atomr actors using atomr-testkit. Covers TestKit, TestProbe (expect_msg / receive_n / expect_no_msg / expect_msg_pf), and the virtual-time TestScheduler. Triggers when authoring `#[tokio::test]` cases that exercise actors, mailboxes, or scheduled timers./atomr-troubleshootingUse when diagnosing failures in a project that depends on atomr. Covers compile-time errors (missing feature flags, wrong prelude), runtime issues (mailbox stalls, restart loops, ask timeouts), and cluster-level problems (split-brain, unreachable members). Triggers on atomr error messages, missing-symbol errors, hangs, or repeated restarts.