Expand description
M:N flows, mailboxes, timer, supervisor and Runtime.
A flow is Byteflow’s unit of concurrent work (not an OS thread). Flows
exchange Atomic Hops (crate::Value::Message) — never bare scalars
on bytecode Send / Ask.
§Authority boundary
The VM only validates types. This module owns delivery:
- Resolve
crate::Value::Cap→FlowId+ rights (CapRights) - Stamp
Message.senderand attachreply_cap(SEND-only, reused per pair) - Push into the target
Mailbox(bounded; anti lost-wakeup under one mutex)
crate::Value::Pid is identity inside hops, not an ambient address.
Host Runtime::send takes FlowId directly (trusted) and is stamped
like a bytecode hop (sender = 0, reply_cap = NONE).
Re-exports§
pub use crate::bytecode::RestartPolicy;
Structs§
- CapRights
- Fixed-width rights bitset. Keep this an explicit allow-list: every new bit here must be audited against the threat-model doc before production.
- Capability
- One live capability entry. The
CapIdis the map key, not a field. - Child
Spec - A child the supervisor should start (and possibly restart).
- Distribution
Bridge - Queue the host drains. Share one
Arcviacrate::RuntimeConfig::distribution. - Down
Event - One monitor firing after the target left the runtime.
- Flow
- A single flow: VM state, mailbox, and bookkeeping.
- Flow
Handle - A reference to a spawned flow, returned by
super::runtime::Runtime::spawn. - FlowId
- Identifier of a flow — Byteflow’s unit of concurrent work.
- Flow
Metrics - Live counters for one flow (updated only by the worker currently running it).
- Flow
Quota - Host
Await Completer - Host-side async completion channel (one-shot).
- Host
Await Request - Request handed to
HostAwaitBridge::submit. - JitConfig
jit - Trace JIT toggles for
RuntimeConfig(feature = "jit"). - LinkId
- Opaque link identifier returned by
LinkTable::link. - Mailbox
- A flow’s inbox, plus (when the owning flow is blocked on
Receive/ReceiveMatch/Askwith nothing to read) the parked flow itself. - Mailbox
Bytes - Byte budget for one flow’s inbox, enforced alongside
MailboxCapacity. - Mailbox
Capacity - Logical hop bound for one flow’s inbox.
- Mailbox
Config - Memory + overflow contract for every mailbox spawned by a
crate::Runtime. - Mailbox
Full - Inbox at one of its logical bounds under
OverflowPolicy::Reject. - Mailbox
Stats - Per-mailbox counters (Relaxed atomics would over-synchronize a hot inbox). Updated only while the mailbox mutex is held — same critical section as enqueue / park — then copied out for host scrapes.
- Monitor
Ref - Opaque monitor reference, echoed on the
DOWNhop asrequest_id. - Outbound
Hop - One authenticated hop waiting for the host to deliver it off-node.
- Quota
Config - Tunables copied onto every newly spawned flow.
- Registry
Name - Registry key. Interned as
Box<str>so lookups do not allocate aStringon the happy path when the caller already has a&str. - Remote
Frame Dedup - Sliding-window replay filter for
crate::Runtime::deliver_frame. - Runtime
- A running Byteflow runtime: worker pool + timer thread over one shared
Chunk. - Runtime
Config - Tunables for
Runtime::new. Everything has a sensible default viaRuntimeConfig::defaultso the common case isRuntime::new(chunk). - Runtime
Metrics - Runtime-wide counters (design notes §26). Every field is a plain
AtomicU64bumped withRelaxedordering: these are monitoring counters, not synchronization primitives, so we don’t pay for anything stronger than “eventually visible to a metrics scrape.” - Runtime
Metrics Snapshot - Point-in-time, non-atomic copy of
RuntimeMetricssuitable for printing or exporting. - Runtime
Snapshot - Point-in-time runtime view for dashboards and debug tooling.
- Runtime
Spawner - A
Send + Sync, freely cloneable capability to spawn flows into aRuntime, detached from theRuntimevalue itself. Exists becausesuper::supervisor::Supervisorneeds to respawn flows from a background monitor thread whose lifetime isn’t tied to theRuntimeobject’s own (which owns non-SyncJoinHandles for its workers). - Supervisor
- Host-side child restarter (design notes §15-16).
- Supervisor
Config - Tunables for
Supervisor::with_config. - Threaded
Host Await - Runs
HostAwaitBridge::submiton a freshstdthread. - Wait
Epoch - Identifies one specific park of a flow in its mailbox.
Enums§
- Admin
Error - CapError
- Why
CapTable::resolve/CapTable::delegaterefused. - Delegate
Error - Delivery
- Outcome of pushing a message.
- Flow
Exit Reason - Why a flow left the directory. Encoded as
Message.payloadon system hops. - Flow
Outcome - Terminal outcome of a flow, delivered to whoever holds its
super::handle::FlowHandle. - Host
Await Error - Errors from
HostAwaitCompleter. - Join
Error - Why a host-side join refused to wait.
- Lifecycle
Error - User-facing lifecycle / naming errors (category A).
- Link
Error - Mailbox
Full Reason - Which of a mailbox’s two bounds refused a hop.
- Overflow
Policy - What happens when a hop would exceed the mailbox’s logical capacity.
- Quota
Error - Remote
Frame Error - Why a remote hop frame was refused.
- Restart
Strategy - Which siblings die (and later come back) when one child exits.
- Runtime
Error - Scheduler / host infrastructure error — not a bytecode flow fault.
- Send
Error - Why
Runtime::sendcould not deliver a hop. - Spawn
Error - User-facing spawn / load errors (category A in the taxonomy above).
Constants§
- DEFAULT_
QUANTUM - Default instruction budget per scheduling turn (design notes §10).
Chosen as a middle ground: large enough that the per-yield bookkeeping
cost is amortized over meaningful work, small enough that a
pathological
loop {}in one flow can’t visibly stall the others — at 10k simple instructions/turn and even a conservative tens-of-millions of instructions/sec per core, worst-case added latency for a sibling flow is sub-millisecond.
Traits§
- Host
Await Bridge - Embedder hook: schedule host work for
Opcode::HostAwait.
Functions§
- check_
admin - Scheduler-level ops (kill, inspect, quota top-up) all pass this check.
- check_
link - check_
monitor - decode_
frame - Inverse of
encode_frame. The host still decides which bytes are trusted. - encode_
frame - Bytes the host can write on its own socket. No capability leaves the node.
- exec_
delegate - Security gate for
Opcode::Delegate. All authority math isCap::attenuate; this wrapper only enforces revocation and the native-mask precondition. - fault_
count - How many
report_faultcalls have been made (tests / diagnostics). - finish_
host_ await - Settle
donefrom a host thread. - flow_
id_ from_ u64 - A convenience Pid constructor for embedders that stored a raw
u64(e.g. round-tripped throughValue::Pid) and need aFlowIdto call APIs that take one. - next_
flow_ id - Allocate the next id. Tests and host helpers; spawn uses
try_next_flow_idso wrap-around cannot mintFlowId::HOST. - report_
fault - Record an infrastructure fault (stderr + counter). Does not panic.
Type Aliases§
- Host
Await Op - Opaque host discriminator passed as the
HostAwaitimmediate.