feat(std): add supervision, router, and registries
Adds the std crate on top of the core runtime: Supervisor with RestartPolicy
(Permanent/Transient/Temporary) and SupervisorStrategy (OneForOne/OneForAll/
RestForOne), Router with RoutingStrategy, name/monitor/group registries, StdExtension,
and Ctx/Runtime extension traits. Also extends core (worker, actor, delivery identity
hashing, config, stats), adds a fuzz target, a proptest suite, expands runtime_api
tests, and adds cfuzz cycle notes + benchmarks.
Signed-off-by: Zachery Aaron Shores-Chmielewski <zacheryasc@gmail.com>
2026-02-13 07:11:24 +00:00
|
|
|
use std::any::Any;
|
|
|
|
|
|
2026-02-20 17:34:43 +00:00
|
|
|
use crate::actor::{ActorAddress, Environment, ExitValue, StopReason};
|
feat(std): add supervision, router, and registries
Adds the std crate on top of the core runtime: Supervisor with RestartPolicy
(Permanent/Transient/Temporary) and SupervisorStrategy (OneForOne/OneForAll/
RestForOne), Router with RoutingStrategy, name/monitor/group registries, StdExtension,
and Ctx/Runtime extension traits. Also extends core (worker, actor, delivery identity
hashing, config, stats), adds a fuzz target, a proptest suite, expands runtime_api
tests, and adds cfuzz cycle notes + benchmarks.
Signed-off-by: Zachery Aaron Shores-Chmielewski <zacheryasc@gmail.com>
2026-02-13 07:11:24 +00:00
|
|
|
|
|
|
|
|
/// Extension hook for runtime lifecycle events.
|
|
|
|
|
///
|
|
|
|
|
/// Stored as `Arc<dyn RuntimeExtension>` in the Runtime. Workers access it
|
|
|
|
|
/// via TickContext. Ctx methods that need registry access downcast to the
|
|
|
|
|
/// concrete type via `as_any()`.
|
|
|
|
|
///
|
|
|
|
|
/// Core calls these methods at appropriate tick phases:
|
|
|
|
|
/// - `on_actor_death`: called during phase 7 (cleanup_dead) with newly dead actors
|
|
|
|
|
/// - `cleanup_dead`: called during phase 7 to clean up extension state
|
|
|
|
|
pub trait RuntimeExtension: Send + Sync {
|
|
|
|
|
/// Called during phase 7 (cleanup_dead) for each dead actor.
|
|
|
|
|
/// Returns (destination, message) pairs for death notifications.
|
|
|
|
|
/// The core delivers these through normal routing (pending_local or transfer queue).
|
|
|
|
|
fn on_actor_death(
|
|
|
|
|
&self,
|
2026-02-20 17:34:43 +00:00
|
|
|
dead: &[(ActorAddress, StopReason, Option<ExitValue>)],
|
feat(std): add supervision, router, and registries
Adds the std crate on top of the core runtime: Supervisor with RestartPolicy
(Permanent/Transient/Temporary) and SupervisorStrategy (OneForOne/OneForAll/
RestForOne), Router with RoutingStrategy, name/monitor/group registries, StdExtension,
and Ctx/Runtime extension traits. Also extends core (worker, actor, delivery identity
hashing, config, stats), adds a fuzz target, a proptest suite, expands runtime_api
tests, and adds cfuzz cycle notes + benchmarks.
Signed-off-by: Zachery Aaron Shores-Chmielewski <zacheryasc@gmail.com>
2026-02-13 07:11:24 +00:00
|
|
|
) -> Vec<(ActorAddress, Box<dyn Any + Send>)>;
|
|
|
|
|
|
2026-06-24 11:04:39 +00:00
|
|
|
/// Clean up extension state for dead actors.
|
feat(std): add supervision, router, and registries
Adds the std crate on top of the core runtime: Supervisor with RestartPolicy
(Permanent/Transient/Temporary) and SupervisorStrategy (OneForOne/OneForAll/
RestForOne), Router with RoutingStrategy, name/monitor/group registries, StdExtension,
and Ctx/Runtime extension traits. Also extends core (worker, actor, delivery identity
hashing, config, stats), adds a fuzz target, a proptest suite, expands runtime_api
tests, and adds cfuzz cycle notes + benchmarks.
Signed-off-by: Zachery Aaron Shores-Chmielewski <zacheryasc@gmail.com>
2026-02-13 07:11:24 +00:00
|
|
|
fn cleanup_dead(&self, dead: &[ActorAddress]);
|
|
|
|
|
|
2026-02-20 17:34:43 +00:00
|
|
|
/// Called for each newly spawned actor, before it enters the pool.
|
2026-06-24 11:04:39 +00:00
|
|
|
/// Extensions can enrich the actor's environment.
|
2026-02-20 17:34:43 +00:00
|
|
|
/// `child` is the address of the newly spawned actor.
|
|
|
|
|
/// `parent` is the address of the spawning actor, or `None` for runtime-spawned actors.
|
|
|
|
|
/// `uptime_ms` is milliseconds since runtime creation.
|
|
|
|
|
/// Default: no-op (returns env unchanged).
|
2026-06-23 15:42:28 +00:00
|
|
|
fn on_spawn(
|
|
|
|
|
&self,
|
|
|
|
|
child: ActorAddress,
|
|
|
|
|
parent: Option<ActorAddress>,
|
|
|
|
|
env: Environment,
|
|
|
|
|
uptime_ms: u64,
|
|
|
|
|
) -> Environment {
|
2026-02-20 17:34:43 +00:00
|
|
|
let _ = (child, parent, uptime_ms);
|
|
|
|
|
env
|
|
|
|
|
}
|
|
|
|
|
|
feat(std): add supervision, router, and registries
Adds the std crate on top of the core runtime: Supervisor with RestartPolicy
(Permanent/Transient/Temporary) and SupervisorStrategy (OneForOne/OneForAll/
RestForOne), Router with RoutingStrategy, name/monitor/group registries, StdExtension,
and Ctx/Runtime extension traits. Also extends core (worker, actor, delivery identity
hashing, config, stats), adds a fuzz target, a proptest suite, expands runtime_api
tests, and adds cfuzz cycle notes + benchmarks.
Signed-off-by: Zachery Aaron Shores-Chmielewski <zacheryasc@gmail.com>
2026-02-13 07:11:24 +00:00
|
|
|
/// Downcast support for Ctx extension traits.
|
|
|
|
|
fn as_any(&self) -> &dyn Any;
|
fix: mild refactor and test coverage (#37)
Extract the timer wheel and watch registry from the worker into a reusable std-extension crate, generalize the worker around a RuntimeExtension factory, and decompose the monolithic runtime test file into focused suites.
- crates/std: extract TimerWheel (deterministic tick-counted one-shot/interval timers) and WatchRegistry (target-to-watcher death-notification index) out of src/worker.rs into reusable modules
- crates/std: add Ctx extension traits (CtxMonitoring, CtxNaming, CtxWatching, CtxTimers) and Runtime extension traits (RuntimeNaming, RuntimeWatching, RuntimeGroups) wiring monitor/name/watch/timer/group support
- src/worker.rs: replace the hard-coded timer/watch fields with a generic RuntimeExtension factory and add route_to_pool_or_remote for message routing (local pool, then cross-worker address map, then external inboxes)
- tests: split the 4622-line tests/runtime_api.rs into focused suites (actor_lifecycle, message_delivery, runtime_stress, std_extension) plus a shared tests/common/mod.rs harness, and drop watch_api.rs
- benches/fuzz: add runtime_benchmarks and adjust the runtime fuzz target
- tools/docs: add fn_complexity.py and loc_analysis.py analysis scripts and refresh the runtime and worker-thread docs
Signed-off-by: Zachery Aaron Shores-Chmielewski <zacheryasc@gmail.com>
2026-02-13 15:00:53 +00:00
|
|
|
|
|
|
|
|
/// Create a per-worker extension instance. Called once per worker during init.
|
|
|
|
|
///
|
|
|
|
|
/// Unlike `RuntimeExtension` (shared across all workers), each worker owns
|
|
|
|
|
/// its own `WorkerExtension` instance for per-worker state like timer wheels.
|
|
|
|
|
fn create_worker_extension(&self) -> Option<Box<dyn WorkerExtension>> {
|
|
|
|
|
None
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Per-worker extension state, created by [`RuntimeExtension::create_worker_extension`].
|
|
|
|
|
///
|
|
|
|
|
/// Each worker owns its own instance. Core calls these methods during tick phases:
|
|
|
|
|
/// - `on_tick`: phase 2.5 — before tick_all, returns messages to deliver
|
|
|
|
|
/// - `handle_request`: phase 5.5 — processes deferred requests from handlers
|
|
|
|
|
/// - `gc_dead`: after cleanup_dead — removes state for dead actors
|
|
|
|
|
pub trait WorkerExtension: Send {
|
2026-02-25 11:11:03 +00:00
|
|
|
/// Returns `true` if this extension has pending work (e.g., active timers).
|
|
|
|
|
/// Used by the fast idle path to avoid unnecessary ticks.
|
2026-06-23 15:42:28 +00:00
|
|
|
fn has_pending_work(&self) -> bool {
|
|
|
|
|
false
|
|
|
|
|
}
|
2026-02-25 11:11:03 +00:00
|
|
|
|
fix: mild refactor and test coverage (#37)
Extract the timer wheel and watch registry from the worker into a reusable std-extension crate, generalize the worker around a RuntimeExtension factory, and decompose the monolithic runtime test file into focused suites.
- crates/std: extract TimerWheel (deterministic tick-counted one-shot/interval timers) and WatchRegistry (target-to-watcher death-notification index) out of src/worker.rs into reusable modules
- crates/std: add Ctx extension traits (CtxMonitoring, CtxNaming, CtxWatching, CtxTimers) and Runtime extension traits (RuntimeNaming, RuntimeWatching, RuntimeGroups) wiring monitor/name/watch/timer/group support
- src/worker.rs: replace the hard-coded timer/watch fields with a generic RuntimeExtension factory and add route_to_pool_or_remote for message routing (local pool, then cross-worker address map, then external inboxes)
- tests: split the 4622-line tests/runtime_api.rs into focused suites (actor_lifecycle, message_delivery, runtime_stress, std_extension) plus a shared tests/common/mod.rs harness, and drop watch_api.rs
- benches/fuzz: add runtime_benchmarks and adjust the runtime fuzz target
- tools/docs: add fn_complexity.py and loc_analysis.py analysis scripts and refresh the runtime and worker-thread docs
Signed-off-by: Zachery Aaron Shores-Chmielewski <zacheryasc@gmail.com>
2026-02-13 15:00:53 +00:00
|
|
|
/// Called each tick before tick_all. Returns messages to deliver.
|
|
|
|
|
fn on_tick(&mut self) -> Vec<(ActorAddress, Box<dyn Any + Send>)>;
|
|
|
|
|
|
|
|
|
|
/// Process a deferred request posted during handle() via `post_worker_request`.
|
|
|
|
|
fn handle_request(&mut self, request: Box<dyn Any + Send>);
|
|
|
|
|
|
|
|
|
|
/// Clean up state for dead actors.
|
|
|
|
|
fn gc_dead(&mut self, dead: &[ActorAddress]);
|
feat(std): add supervision, router, and registries
Adds the std crate on top of the core runtime: Supervisor with RestartPolicy
(Permanent/Transient/Temporary) and SupervisorStrategy (OneForOne/OneForAll/
RestForOne), Router with RoutingStrategy, name/monitor/group registries, StdExtension,
and Ctx/Runtime extension traits. Also extends core (worker, actor, delivery identity
hashing, config, stats), adds a fuzz target, a proptest suite, expands runtime_api
tests, and adds cfuzz cycle notes + benchmarks.
Signed-off-by: Zachery Aaron Shores-Chmielewski <zacheryasc@gmail.com>
2026-02-13 07:11:24 +00:00
|
|
|
}
|