Skip to main content

Node

Struct Node 

Source
pub struct Node { /* private fields */ }
Expand description

Constructed BB Node ready to drive ML work. Produced by [bytesandbrains::install] — by the time the host holds one, the engine has resolved its dispatch table, registered every bound concrete, and installed the target function as the root graph.

Implementations§

Source§

impl Node

Source

pub fn with_config(self, cfg: NodeConfig) -> Self

Override the default NodeConfig (the cycle / async / outbound caps). Must be called before [crate::install] for the new caps to apply at build time.

Source§

impl Node

Source

pub fn snapshot(&self) -> Result<NodeSnapshot, SnapshotError>

Capture the snapshottable state. refuses to proceed when the bus still carries un-drained events that a restore would silently drop or re-fire stale; callers drive Node::poll to quiescence first and retry.

Source

pub fn restore(&mut self, snap: NodeSnapshot) -> Result<(), RestoreError>

Restore a Node’s state from a snapshot.

Source

pub fn clear(&mut self)

Reset transient runtime state without dropping the bound components or installed graphs.

Source

pub fn incarnation(&self) -> u64

Current incarnation count. Bumped on every restore().

Source

pub fn loaded_modules(&self) -> Vec<&str>

Names of every module registered at construction time.

Source

pub fn linked_components(&self) -> Vec<&ComponentHandle>

References to every owned component handle.

Source

pub fn peer_id(&self) -> PeerId

Local peer identity.

Source

pub fn execution_state(&self, exec_id: ExecId) -> Option<&ExecutionState>

Read-only execution-state lookup.

Source

pub fn pending_async_count(&self) -> usize

Number of AsyncSuspended Ops currently awaiting completion.

Source

pub fn engine_stats(&self) -> EngineStats

Snapshot of the engine’s hot-path counters.

Source

pub fn model(&self) -> Option<Arc<ModelProto>>

The compiled ModelProto the Node was installed with, or None if the Node was built internally by a crate-private path that bypassed [crate::install] (the public entry point always sets a model). Returns a shared Arc so callers can read per-target metadata without cloning the proto.

Source

pub fn slot(&self, slot_name: &str) -> Option<ComponentRef>

Look up the ComponentRef bound at slot_name in the engine’s generic slot registry. Returns None when no slot of that name is bound.

Source

pub fn slots_iter(&self) -> impl Iterator<Item = (&str, ComponentRef)>

Iterate every (slot_name, ComponentRef) pair bound in the engine’s slot registry.

Source

pub fn roles_for(&self, cref: ComponentRef) -> HashSet<ComponentRole>

Inventory-declared roles for a registered component. Read from the per-Engine component_roles map populated by ensure_ready from crate::registry::roles_for_component(T::TYPE_NAME). Returns the empty set when the component wasn’t registered via a #[derive(bb::<Role>)] chain (test fixtures that hand-implement role traits surface here as empty).

Source

pub fn block_peer(&mut self, peer: PeerId)

Add peer to the inbound + outbound blocklist.

Source

pub fn unblock_peer(&mut self, peer: PeerId)

Remove peer from the blocklist.

Source

pub fn set_allowlist(&mut self, allowlist: Option<HashSet<PeerId>>)

Configure an allowlist for inbound + outbound delivery.

Source

pub fn peer_health(&self, peer: PeerId) -> Option<PeerHealth>

Per-peer health snapshot.

Source

pub fn resolve_peer_addresses(&self, peer: PeerId) -> Option<Vec<Address>>

Resolve a PeerId to its ordered address list (cloned).

Source

pub fn set_telemetry_tap<F>(&mut self, tap: F)
where F: FnMut(&EngineStep) + 'static,

Install an EngineStep observer onto the live Node.

Source

pub fn add_peer( &mut self, peer: PeerId, addresses: Vec<Address>, ) -> Result<(), AddressBookError>

Announce a peer with one or more reachable addresses.

Source

pub fn ingress_handle(&self) -> IngressQueueRef

Concern 2 - cheap-clone handle to the shared IngressQueue. Used by off-thread transport / clock adapters to push events into the Node.

Source

pub fn config(&self) -> &NodeConfig

Read-only view on the registered NodeConfig.

Source

pub fn peer_address(&self) -> Address

First entry of the local-address bag, or [Address::empty] when none registered. The AddressBook entry for self.peer_id() is the source of truth.

Source

pub fn local_addresses(&self) -> &[Address]

Ordered local-address bag for this Node. Reads directly from the AddressBook entry keyed by self.peer_id(); returns an empty slice when the Node was installed with no addresses or the bag was pruned to zero entries.

Source

pub fn add_local_address( &mut self, address: Address, ) -> Result<(), AddressBookError>

Append address to the local-address bag. Creates the AddressBook entry if none exists; idempotent on duplicates.

Source

pub fn forget_local_address( &mut self, address: &Address, ) -> Result<(), AddressBookError>

Prune address from the local-address bag. Errors when no entry exists; succeeds (no-op) when the bag has no matching address.

Source

pub fn run_bootstrap( &mut self, target: BootstrapTarget<'_>, ) -> Result<Vec<EngineStep>, BootstrapError>

Drive bootstrap targets to completion. Returns every EngineStep the bootstrap path emitted, including each drained phase’s BootstrapComplete or the yielding WaitingOnBootstrap. Idempotent: a Node whose bootstrap already completed (or a Node with no install-order recording) returns an empty vec.

Variant semantics:

  • BootstrapTarget::All arms + seeds the install-order queue, then polls until every queued target reaches BootstrapComplete or one suspends on an async completion. Equivalent to the F4 host kick.
  • BootstrapTarget::ModuleNames / BootstrapTarget::ModuleRequests validate target names + input formals atomically — the whole batch rejects with BootstrapError::UnknownTarget / BootstrapError::AlreadyTransitivelyQueued / BootstrapError::UnknownInput / BootstrapError::MissingInput before any staging happens. On success the framework copies each request’s borrowed &[u8] inputs into engine-owned storage (Principle 1a: caller slices may drop the moment this call returns), then drives the staged bodies to completion.
  • BootstrapTarget::Slots resolves each slot to a registered Component bootstrap, validates the whole batch atomically, then fires each in slice order through the dispatcher. The drain loop runs after all slots fire so synchronous Immediate dispatches retire inline and async ones surface WaitingOnBootstrap.

On async suspension the host posts the matured completion via the ingress and re-invokes run_bootstrap to drain the resumed op.

Body-phase ops touching a locked ComponentRef do not fire during this call; the is_op_locked gate in pop_frontier_fireable keeps them parked until the bootstrap in-flight set drops.

Source

pub fn bootstrap_status(&self) -> BootstrapStatus

Snapshot of the engine’s bootstrap lifecycle. Returns BootstrapStatus::Idle when no bootstrap is queued or in-flight, Running when at least one bootstrap is in-flight (the body gate is parking touched ops), and WaitingForInput when the install-order queue still has unseeded targets or host-staged requests sit on pending_requests / waiting. Pure read — does not advance any queue.

Source

pub fn poll(&mut self, cx: &mut Context<'_>) -> Poll<Vec<EngineStep>>

Drive one poll cycle. Returns Pending when the engine drains to quiescence (the ingress waker is registered with cx); otherwise yields the steps the engine made progress on. Construction-time validation lives in crate::node::Node’s installation path (see bytesandbrains::install) and surfaces InstallError before the first poll.

Source

pub fn deliver_inbound( &mut self, src_peer: PeerId, bytes: &[u8], ) -> Result<(), DeliveryError>

Decode and push inbound wire bytes onto the ingress queue. Routes through EnvelopeCodec::decode_capped so malformed, schema-mismatched, or oversize buffers fail with DeliveryError::InvalidEnvelope BEFORE any prost allocation. The transport layer supplies src_peer so the engine can consult PeerGovernor::check_inbound before routing.

Source

pub fn deliver_event( &mut self, module: &str, input: &str, value_bytes: &[u8], ) -> Result<(), DeliveryError>

Push an app-event onto the ingress queue.

Per Principle 1a (docs/internal/superpowers/specs/2026-06-24-engine-boundary-fallibility-and-backend-owned-tensors.md) the byte payload crosses the engine boundary as a BORROWED slice: the framework caps value_bytes.len() against NodeConfig::max_app_event_bytes, charges the length against NodeConfig::ingress_byte_budget, fallibly reserves a fresh framework-owned Vec<u8>, and copies the caller’s bytes in. The caller may free value_bytes the moment this call returns. Cap / budget / alloc failures return a synchronous DeliveryError::* AND publish a matching InfraEvent::AppIngressError on the bus for observers.

Source

pub fn invoke( &mut self, module: &str, inputs: &[(&str, &[u8])], ) -> Result<ExecId, DeliveryError>

Invoke a Module with the given pre-encoded inputs.

Inputs cross as borrowed &[(&str, &[u8])] per Principle 1a; the framework caps count + cumulative bytes, charges against ingress_byte_budget, and per-input fallibly reserves + copies into framework-owned Vec<u8> storage. Any failure releases prior charges and emits the matching InfraEvent::AppIngressError.

Trait Implementations§

Source§

impl Debug for Node

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Node

§

impl !Send for Node

§

impl !Sync for Node

§

impl !UnwindSafe for Node

§

impl Freeze for Node

§

impl Unpin for Node

§

impl UnsafeUnpin for Node

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more