//! Control-bus contracts: service identity, lifecycle states and message formats. //! //! Lifecycle transitions are verified in `proofs/bus_lifecycle.lean` and //! enforced by `vetta-infer-kn` (registry + bus). These are the shared types //! every service speaks; the bus carries control-plane messages only — the //! data plane exchanges UMA memory handles, never tensor copies. /// Stable identity of a registered service (handed out by the registry, two-phase). #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] pub struct ServiceId(pub u32); /// The service kinds of the approved architecture (docs/ARCHITECTURE.md §2). #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub enum ServiceKind { /// `ld` — loader & compiler (dual-step → `.vbundle/`) Loader, /// `cc` — cache & storage (UMA residency, NVMe streaming, Hot/Cold experts) Cache, /// `rt` — operational runtime (CompiledPlan on HIP, zero probes) Runtime, /// `lab` — laboratory runtime (same executor + probe hooks) Lab, /// `sp` — speculative coordinator (lossless verification, Adaptive-K) Spec, /// `nt` — LAN bridge to Lyra Net, /// `tm` — telemetry observer Telemetry, /// `gw` — gateway & CLI (`--serve`, HTTP, `vetta-infer`) Gateway, } /// Lifecycle of one service — mirrors `SvcState` in `proofs/bus_lifecycle.lean`. /// `Stopping` = STOP issued, draining in-flight work; `Stopped` is terminal. #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum ServiceState { Registered, Running, Stopping, Stopped, } /// Typed control-plane payloads. Extended additively as services land; /// unknown-to-a-service payloads are rejected explicitly, never silently. #[derive(Debug, Clone, PartialEq)] pub enum BusPayload { /// Kernel → service: stop accepting new work and drain. Stop, /// Service → kernel: drain complete, resources released (acks `Stop`). StopAck, /// Domain routing hint (e.g. `"lean4"`, `"dante"`) for cache pre-warm. DomainHint(String), } /// One routed control-plane message. #[derive(Debug, Clone, PartialEq)] pub struct BusMsg { pub src: ServiceId, pub dst: ServiceId, pub payload: BusPayload, } #[cfg(test)] mod tests { use super::*; #[test] fn msg_shape() { let m = BusMsg { src: ServiceId(0), dst: ServiceId(1), payload: BusPayload::DomainHint("lean4".into()), }; assert_eq!(m.dst, ServiceId(1)); assert_eq!(m.payload, BusPayload::DomainHint("lean4".into())); } }