Skip to main content

nmbrs_runtime/
lib.rs

1// Copyright 2024-2026 Jonathan Shook
2// SPDX-License-Identifier: Apache-2.0
3
4//! # nmbrs-runtime
5//!
6//! Workload execution runtime for nmbrs. Owns the async dispatch
7//! loop, the adapter trait that workload backends implement, op
8//! sequencing across stanzas, error-handler integration, observer
9//! callbacks, and the runner that ties everything together.
10//!
11//! This is the integration crate — it depends on every other
12//! `nb-*` library and is depended on by `nmbrs` (and by every
13//! persona binary). External consumers shouldn't usually need to
14//! reach into it directly; the public-facing path is `nmbrs run`
15//! or [`runner::run`].
16//!
17//! ## Pieces
18//!
19//! - [`adapter::DriverAdapter`] — the trait every workload
20//!   backend implements. CQL, HTTP, stdout, testkit, plotter, and
21//!   user-supplied adapters all register via the inventory
22//!   pattern in `adapters`.
23//! - [`activity::Activity`] — one running concurrency unit. Owns
24//!   the cycle source, the op sequencer, the fiber pool, the
25//!   error router, and the metrics scope. Multiple activities
26//!   can run concurrently within one phase.
27//! - [`runner::run`] / [`runner::run_with_observer`] — orchestrate
28//!   the whole session: parse
29//!   workload, build component tree, route metrics, walk the
30//!   scenario tree, supervise activities.
31//! - [`scope_tree`] / [`scene_tree`] — the canonical scenario-
32//!   tree shape and the runtime presentation surface (SRD 18b).
33//! - `scheduler` — `schedule=` CLI param parses to a
34//!   `scheduler::ScheduleSpec`; the `scheduler::TreeScheduler`
35//!   walks the tree and forks concurrent siblings via
36//!   `tokio::JoinSet` + `Semaphore` based on per-level limits.
37//! - [`observer::RunObserver`] — lifecycle callbacks (phase
38//!   start / progress / complete / fail). The TUI is one
39//!   implementor; stderr is the default.
40//! - [`bindings`] / [`scope`] — workload bindings → Polydat Kernel
41//!   compilation, with cache-and-rebind across phase iterations.
42//!
43//! ## Out of scope
44//!
45//! - Polydat DSL parsing and compilation: see [`polydat`].
46//! - Workload YAML parsing: see [`nmbrs_workload`].
47//! - Component tree, instruments, cadence reporter: see
48//!   [`nmbrs_metrics`].
49//! - Rate limiting: see [`nmbrs_rate`].
50//! - Error handler primitives: see [`nmbrs_errorhandler`].
51//!
52//! ## See also
53//!
54//! - SRD 29 (`docs/SRD/29_execution_engine.md`) — the engine
55//!   front door: this crate's public contract surface, the
56//!   load-bearing axioms, and the SRD ↔ module map.
57//! - SRD 01 (`docs/SRD/01_system_overview.md`) — overall
58//!   architecture.
59//! - SRD 18b — scenario-tree, scope-tree, scheduler.
60//! - SRD 22 (`docs/SRD/22_op_sequencing.md`) — op sequencing
61//!   and stanza model.
62//! - SRD 30 (`docs/SRD/30_adapter_interface.md`) — adapter
63//!   trait surface.
64
65// Polydat node registrations that need nmbrs-runtime's runtime
66// services (component tree + controls + fiber context). Moved out
67// of polydat itself so polydat can publish standalone — see
68// `polydat_nodes/mod.rs` for the rationale.
69pub mod activity;
70pub mod adapter;
71pub(crate) mod adapters;
72pub mod bindings;
73pub mod checkpoint;
74/// SRD-92 / ExecUnification Step 5a — the unified child-stream contract
75/// (`ChildSource` + `Realizability`). Additive; callers land in 5b+.
76pub(crate) mod child_source;
77pub mod concurrent;
78pub mod control_catalog;
79pub(crate) mod daemon_pool;
80/// Boolean `NMBRS_DEBUG_*` developer switches.
81pub mod debug_env;
82pub(crate) mod describe;
83pub(crate) mod error_policy;
84pub mod exec_events;
85pub mod execution_context;
86pub(crate) mod executor;
87pub mod fiber_engine;
88pub(crate) mod fiber_pool;
89pub mod fixture;
90/// Lifecycle event vocabulary: the kind-tag [`lifecycle::EventType`]
91/// and its [`lifecycle::SubjectKind`], shared by the readout
92/// binder and the checkpoint log.
93pub mod lifecycle;
94pub mod log_sink;
95pub mod observer;
96pub mod op_modifier;
97pub mod opseq;
98/// SRD-86 — the optimizer service boundary: the `Optimizer`/`Objective`
99/// contract + registry the phase-execution driver uses, defined here in the
100/// core with no dependency on any algorithm crate. Public so algorithm crates
101/// (e.g. `nmbrs-optimizers`) can register against it and the CLI can discover.
102pub mod optimize;
103pub mod output_channel;
104pub(crate) mod params;
105/// Phase-end trigger registry — content-agnostic callbacks
106/// that fire after every phase completion or failure. Used by
107/// the `watch=plots` / `watch=report` CLI flags to keep an
108/// external view (plot image, report html) up-to-date as the
109/// run progresses.
110pub mod phase_end_triggers;
111pub(crate) mod phase_filter;
112/// SRD-76 phase outcome disposition (structured
113/// per-phase status + error list).
114pub mod phase_outcome;
115/// SRD-71 P3 phase-scoped CLI parameter overrides
116/// (`<phase-pattern>.<param>=<value>`).
117pub(crate) mod phase_params;
118pub mod polydat_nodes;
119pub(crate) mod profiler;
120pub(crate) mod readout_context;
121pub mod readouts;
122/// SRD-77 refine plan — pre-computed skip set + next-execution
123/// id, derived from a session's prior `phase_outcomes` rows.
124/// The runner builds one when `nmbrs refine` re-attaches to an
125/// existing session; the executor's phase-walk gate checks it
126/// before dispatching each phase's per-cycle work.
127pub mod refine_plan;
128pub(crate) mod relevancy;
129pub mod resource_pool;
130pub mod runner;
131pub mod scene_tree;
132pub(crate) mod scheduler;
133pub mod scope;
134pub(crate) mod scope_elision;
135pub mod scope_kernel;
136pub mod scope_synth;
137pub mod scope_tree;
138pub mod session;
139pub mod session_signals;
140pub(crate) mod stop_conditions;
141pub mod suggest;
142pub mod synthesis;
143pub mod sysmon;
144pub mod throttle;
145pub mod timeval;
146pub(crate) mod trace_router;
147pub mod validation;
148pub mod wires;
149pub mod workload_lint;
150pub(crate) mod workload_shell;
151pub(crate) mod wrapper_registrations;
152pub mod wrapper_registry;
153pub mod wrapper_resolver;
154pub mod wrappers;
155/// SRD-100 P2 — the per-phase status builder, re-exported for the display
156/// consumer (nmbrs-tui) that now folds `active_phases` and renders each
157/// phase's status line itself (the module otherwise stays crate-private).
158pub use readout_context::{build_inline_refresh_context, is_internal_counter};
159pub mod report_anchor;
160
161/// A scratch-name suffix unique across parallel tests and processes:
162/// parallel tests can read the same clock tick, so the pid and a
163/// per-process sequence keep their directories apart.
164#[cfg(test)]
165pub(crate) fn scratch_suffix() -> String {
166    use std::sync::atomic::{AtomicU64, Ordering};
167    static SEQ: AtomicU64 = AtomicU64::new(0);
168    let n = std::time::SystemTime::now()
169        .duration_since(std::time::UNIX_EPOCH)
170        .unwrap()
171        .as_nanos();
172    let seq = SEQ.fetch_add(1, Ordering::Relaxed);
173    format!("{}-{n:x}-{seq}", std::process::id())
174}