Skip to main content

Module scheduler

Module scheduler 

Source
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:

  1. Resolve crate::Value::Cap → FlowId + rights (CapRights)
  2. Stamp Message.sender and attach reply_cap (SEND-only, reused per pair)
  3. 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).

See crate::docs::security and crate::docs::atomic_hop.

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 CapId is the map key, not a field.
ChildSpec
A child the supervisor should start (and possibly restart).
DistributionBridge
Queue the host drains. Share one Arc via crate::RuntimeConfig::distribution.
DownEvent
One monitor firing after the target left the runtime.
Flow
A single flow: VM state, mailbox, and bookkeeping.
FlowHandle
A reference to a spawned flow, returned by super::runtime::Runtime::spawn.
FlowId
Identifier of a flow — Byteflow’s unit of concurrent work.
FlowMetrics
Live counters for one flow (updated only by the worker currently running it).
FlowQuota
HostAwaitCompleter
Host-side async completion channel (one-shot).
HostAwaitRequest
Request handed to HostAwaitBridge::submit.
JitConfigjit
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 / Ask with nothing to read) the parked flow itself.
MailboxBytes
Byte budget for one flow’s inbox, enforced alongside MailboxCapacity.
MailboxCapacity
Logical hop bound for one flow’s inbox.
MailboxConfig
Memory + overflow contract for every mailbox spawned by a crate::Runtime.
MailboxFull
Inbox at one of its logical bounds under OverflowPolicy::Reject.
MailboxStats
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.
MonitorRef
Opaque monitor reference, echoed on the DOWN hop as request_id.
OutboundHop
One authenticated hop waiting for the host to deliver it off-node.
QuotaConfig
Tunables copied onto every newly spawned flow.
RegistryName
Registry key. Interned as Box<str> so lookups do not allocate a String on the happy path when the caller already has a &str.
RemoteFrameDedup
Sliding-window replay filter for crate::Runtime::deliver_frame.
Runtime
A running Byteflow runtime: worker pool + timer thread over one shared Chunk.
RuntimeConfig
Tunables for Runtime::new. Everything has a sensible default via RuntimeConfig::default so the common case is Runtime::new(chunk).
RuntimeMetrics
Runtime-wide counters (design notes §26). Every field is a plain AtomicU64 bumped with Relaxed ordering: these are monitoring counters, not synchronization primitives, so we don’t pay for anything stronger than “eventually visible to a metrics scrape.”
RuntimeMetricsSnapshot
Point-in-time, non-atomic copy of RuntimeMetrics suitable for printing or exporting.
RuntimeSnapshot
Point-in-time runtime view for dashboards and debug tooling.
RuntimeSpawner
A Send + Sync, freely cloneable capability to spawn flows into a Runtime, detached from the Runtime value itself. Exists because super::supervisor::Supervisor needs to respawn flows from a background monitor thread whose lifetime isn’t tied to the Runtime object’s own (which owns non-Sync JoinHandles for its workers).
Supervisor
Host-side child restarter (design notes §15-16).
SupervisorConfig
Tunables for Supervisor::with_config.
ThreadedHostAwait
Runs HostAwaitBridge::submit on a fresh std thread.
WaitEpoch
Identifies one specific park of a flow in its mailbox.

Enums§

AdminError
CapError
Why CapTable::resolve / CapTable::delegate refused.
DelegateError
Delivery
Outcome of pushing a message.
FlowExitReason
Why a flow left the directory. Encoded as Message.payload on system hops.
FlowOutcome
Terminal outcome of a flow, delivered to whoever holds its super::handle::FlowHandle.
HostAwaitError
Errors from HostAwaitCompleter.
JoinError
Why a host-side join refused to wait.
LifecycleError
User-facing lifecycle / naming errors (category A).
LinkError
MailboxFullReason
Which of a mailbox’s two bounds refused a hop.
OverflowPolicy
What happens when a hop would exceed the mailbox’s logical capacity.
QuotaError
RemoteFrameError
Why a remote hop frame was refused.
RestartStrategy
Which siblings die (and later come back) when one child exits.
RuntimeError
Scheduler / host infrastructure error — not a bytecode flow fault.
SendError
Why Runtime::send could not deliver a hop.
SpawnError
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§

HostAwaitBridge
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 is Cap::attenuate; this wrapper only enforces revocation and the native-mask precondition.
fault_count
How many report_fault calls have been made (tests / diagnostics).
finish_host_await
Settle done from a host thread.
flow_id_from_u64
A convenience Pid constructor for embedders that stored a raw u64 (e.g. round-tripped through Value::Pid) and need a FlowId to call APIs that take one.
next_flow_id
Allocate the next id. Tests and host helpers; spawn uses try_next_flow_id so wrap-around cannot mint FlowId::HOST.
report_fault
Record an infrastructure fault (stderr + counter). Does not panic.

Type Aliases§

HostAwaitOp
Opaque host discriminator passed as the HostAwait immediate.