Skip to main content

Runtime

Struct Runtime 

Source
pub struct Runtime {
    pub storage: Arc<dyn StorageBackend>,
    pub registry: Arc<SessionRegistry>,
    pub log_store: Arc<LogStore>,
    /* private fields */
}

Fields§

§storage: Arc<dyn StorageBackend>§registry: Arc<SessionRegistry>§log_store: Arc<LogStore>

Implementations§

Source§

impl Runtime

Source

pub fn new( storage: Arc<dyn StorageBackend>, registry: Arc<SessionRegistry>, log_store: Arc<LogStore>, ) -> Self

Source

pub fn with_mode_registry( storage: Arc<dyn StorageBackend>, registry: Arc<SessionRegistry>, log_store: Arc<LogStore>, mode_registry: Arc<ModeRegistry>, ) -> Self

Source

pub fn with_registries( storage: Arc<dyn StorageBackend>, registry: Arc<SessionRegistry>, log_store: Arc<LogStore>, mode_registry: Arc<ModeRegistry>, policy_registry: Arc<PolicyRegistry>, ) -> Self

Source

pub fn registered_mode_names(&self) -> Vec<String>

Returns all mode names the runtime can handle (standards-track + extensions). Used by Initialize and GetManifest to advertise full capability.

Source

pub fn standard_mode_descriptors(&self) -> Vec<ModeDescriptor>

Returns only standards-track mode descriptors for ListModes.

Source

pub fn extension_mode_descriptors(&self) -> Vec<ModeDescriptor>

Returns only extension mode descriptors for ListExtModes.

Source

pub fn register_extension( &self, descriptor: ModeDescriptor, ) -> Result<(), String>

Source

pub fn unregister_extension(&self, mode: &str) -> Result<(), String>

Source

pub fn promote_mode( &self, mode: &str, new_name: Option<&str>, ) -> Result<String, String>

Source

pub fn subscribe_mode_changes(&self) -> Receiver<()>

Source

pub fn mode_registry(&self) -> &Arc<ModeRegistry>

Source

pub fn register_policy( &self, definition: PolicyDefinition, ) -> Result<(), String>

Source

pub fn unregister_policy(&self, policy_id: &str) -> Result<(), String>

Source

pub fn get_policy(&self, policy_id: &str) -> Option<PolicyDefinition>

Source

pub fn list_policies(&self, mode_filter: Option<&str>) -> Vec<PolicyDefinition>

Source

pub fn subscribe_policy_changes(&self) -> Receiver<()>

Source

pub fn policy_registry(&self) -> &Arc<PolicyRegistry>

Source

pub fn metrics(&self) -> &Arc<RuntimeMetrics>

Source

pub fn subscribe_session_stream(&self, session_id: &str) -> Receiver<Envelope>

Source

pub fn subscribe_signals(&self) -> Receiver<Envelope>

Source

pub fn subscribe_session_lifecycle(&self) -> Receiver<SessionLifecycleEvent>

Source

pub async fn get_session_envelopes_after( &self, session_id: &str, after_sequence: u64, ) -> Result<Vec<Envelope>, u64>

RFC-MACP-0006 §3.2: Replay accepted envelopes from the session log for passive subscribe, strictly after after_sequence (1-based accepted ordinal, exclusive; 0 = from the start). Err(base) when the requested range was discarded by log compaction — the caller must surface an explicit error, not silently skip missing history.

Source

pub async fn process( &self, env: &Envelope, max_open_sessions: Option<usize>, ) -> Result<ProcessResult, MacpError>

Source

pub async fn get_session_checked(&self, session_id: &str) -> Option<Session>

Source

pub async fn cancel_session( &self, session_id: &str, reason: &str, cancelled_by: &str, ) -> Result<ProcessResult, MacpError>

Cancel a session. The cancelled_by parameter MUST be the authenticated sender of the CancelSession RPC (RFC-MACP-0001 Section 7.3: CancelSession is a Core control-plane message; mode authorization does not apply).

Source

pub async fn suspend_session( &self, session_id: &str, reason: &str, suspended_by: &str, ) -> Result<ProcessResult, MacpError>

Suspend an Open session (RFC-MACP-0001 §7.5). Appends a SessionSuspend annotation, transitions Open -> Suspended, and emits a lifecycle event. The session’s TTL is banked and restored on resume.

Source

pub async fn resume_session( &self, session_id: &str, reason: &str, resumed_by: &str, ) -> Result<ProcessResult, MacpError>

Resume a Suspended session (RFC-MACP-0001 §7.5), banking the suspended duration into the TTL deadline. If the MAX_SUSPEND_MS cap is exceeded, the session is force-expired instead.

Source

pub async fn cleanup_expired_sessions(&self)

Expire all sessions that have exceeded their TTL. Called by the background cleanup task to proactively transition stale sessions without waiting for the next incoming message.

Source

pub async fn gc_disk_sessions(&self, retention_secs: u64) -> usize

Delete terminal sessions’ durable data older than retention_secs (opt-in via MACP_SESSION_DISK_RETENTION_SECS). Before this existed, storage.delete_session had no callers at all: disk grew without bound and every restart reloaded every session ever completed. Enumerates STORAGE (not memory — eviction may already have dropped the registry entry), deletes the session’s snapshot+log, and clears any in-memory remnants. Returns the number of sessions deleted.

Source

pub async fn evict_stale_sessions(&self, retention_secs: u64)

Evict resolved/expired sessions older than retention_secs from memory: the registry entry, the in-memory log cache, AND the stream broadcast channel (all three previously grew for the process lifetime; the log cache and stream bus were never evicted at all). Sessions remain queryable from durable storage after eviction.

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Same for T

Source§

type Output = T

Should always be Self
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.
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