Skip to main content

RuntimeConfig

Struct RuntimeConfig 

Source
pub struct RuntimeConfig {
Show 20 fields pub workers: usize, pub quantum: u32, pub mailbox: MailboxConfig, pub max_flows: u32, pub max_ask_waits: u32, pub max_host_awaits: u32, pub max_links: u32, pub max_monitors: u32, pub max_registry_names: u32, pub host_await: Option<Arc<dyn HostAwaitBridge>>, pub remote_dedup_window: u32, pub distribution: Option<Arc<DistributionBridge>>, pub max_runtime_bytes: usize, pub trust: TrustLevel, pub output: Arc<dyn OutputSink>, pub log: Option<Arc<dyn LogSink>>, pub quota: QuotaConfig, pub security_audit: Option<Arc<dyn SecurityAuditSink>>, pub root_authority: RootAuthorityPolicy, pub jit: JitConfig,
}
Expand description

Tunables for Runtime::new. Everything has a sensible default via RuntimeConfig::default so the common case is Runtime::new(chunk).

Fields§

§workers: usize

Number of worker OS threads. Defaults to the number of logical CPUs — one worker per core is the right starting point for a CPU-bound M:N scheduler; embedders running alongside other CPU-heavy work on the same machine may want fewer. 0 is raised to 1: a runtime with no worker cannot run a flow.

§quantum: u32

Instructions a flow runs before being preempted back to the scheduler even if it never hits Yield. 0 is raised to 1. A zero slice returns Yield without executing anything, and the worker would requeue that flow forever.

§mailbox: MailboxConfig

Memory + overflow contract applied to every flow mailbox spawned by this runtime (bytecode Spawn and host spawn). See MailboxConfig / docs/mailbox.md.

§max_flows: u32

Hard cap on concurrently live flows (0 = unlimited). Checked on every host and bytecode spawn.

§max_ask_waits: u32

Hard cap on outstanding Ask / AskTimeout waiters process-wide (0 = unlimited). Each asker holds at most one wait; this bounds the total index size when many flows park against a silent target. See crate::docs::security (DoS) and Self::sandbox.

§max_host_awaits: u32

Hard cap on outstanding HostAwait parkers process-wide (0 = unlimited). Each flow holds at most one await.

§max_links: u32

Hard cap on live process-wide links (0 = unlimited).

Accounting is performed by the link store itself, under the same synchronization that protects the link table.

§max_monitors: u32

Hard cap on live process-wide monitors (0 = unlimited).

Accounting is performed by the monitor store itself.

§max_registry_names: u32

Hard cap on live process-wide registry names (0 = unlimited).

The registry store counts only successfully registered names.

§host_await: Option<Arc<dyn HostAwaitBridge>>

Host async bridge for crate::Opcode::HostAwait. None fails any HostAwait closed. Not a CallNative / std-native slot.

§remote_dedup_window: u32

0 = disabled. When set, Runtime::deliver_frame ignores duplicate (sender, request_id) pairs within the window (at-least-once wire).

§distribution: Option<Arc<DistributionBridge>>

Host queue for crate::Opcode::SendRemote. None fails that opcode. Byteflow does not open sockets; the embedder drains the bridge.

§max_runtime_bytes: usize

Process-wide memory ceiling for heap charges (Str / Bytes register stores and shared crate::HeapStr / crate::HeapBytes). Independent of per-flow crate::QuotaConfig::mem_limit and mailbox byte budgets. Default: 256 MiB.

§trust: TrustLevel

Constant-pool trust for crate::verify_with at runtime construction. Default is crate::TrustLevel::Untrusted (fail closed).

§output: Arc<dyn OutputSink>

Where bytecode print (native index 0) writes when using crate::std_native_table_with. Ignored if you supply your own table.

§log: Option<Arc<dyn LogSink>>

Scheduler diagnostics (ask, finalize, …). None keeps the BYTEFLOW_LOG stderr path and adds no collector. The sink is called inline and must not block or panic.

§quota: QuotaConfig

Per-flow CPU / memory / spawn-send rate budgets.

§security_audit: Option<Arc<dyn SecurityAuditSink>>

Optional security audit sink (capability / quota / module denials). Independent of Self::log; never receives full CapId tokens. Delivery is asynchronous (bounded queue + dedicated thread) so a slow sink cannot stall scheduler workers.

§root_authority: RootAuthorityPolicy

Authority minted for host Runtime::spawn (not bytecode Spawn).

Default RootAuthorityPolicy::TrustedHost preserves historical ROOT + full native mask. Self::sandbox does not change this — use Runtime::spawn_untrusted or set this field explicitly.

§jit: JitConfig
Available on crate feature jit only.

Trace JIT settings (feature = "jit"). Ignored when the feature is off.

Implementations§

Source§

impl RuntimeConfig

Source

pub fn sandbox() -> Self

Opt-in sandbox profile for untrusted modules.

Default RuntimeConfig stays permissive (max_* = 0 unlimited, QuotaConfig::permissive). This profile enables fail-closed process-wide caps and tight per-flow budgets. Trust defaults to [TrustLevel::Untrusted] (inherited from Default) so Cap/Pid/Message constants are rejected at verify time.

Does not change Self::root_authority: host Runtime::spawn still mints trusted ROOT unless you set the policy or call Runtime::spawn_untrusted.

Limits (starting point — tune under load):

  • max_flows = 128 live flows
  • max_ask_waits = 64, max_host_awaits = 128
  • max_runtime_bytes = 64 MiB process heap accounting
  • mailbox: 256 hops / 4 MiB / Reject ( MailboxConfig::DEFAULT )
  • per-flow: QuotaConfig::sandbox
Source

pub fn sandbox_restricted() -> Self

Same process-wide caps as Self::sandbox, but [TrustLevel::Restricted]: still no Cap/Pid/Message in the constant pool; host may grant Caps / natives after admission.

Source

pub fn policy_fingerprint(&self) -> PolicyFingerprint

Stable identity of the security-relevant knobs on this config.

Source

pub fn applies_sandbox_caps(&self) -> bool

True when at least one process-wide sandbox ceiling is armed (max_flows / ask / host-await / runtime bytes tighter than the permissive defaults). Does not imply the chunk was verified as Untrusted — check Self::trust separately.

Trait Implementations§

Source§

impl Clone for RuntimeConfig

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RuntimeConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for RuntimeConfig

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.