pub struct CoherenceMonitor { /* private fields */ }Expand description
Tracks per-run trajectory state and reports coherence divergences.
Construct once at gateway / worker boot, wrap in Arc, and feed it the
run’s audit events as they stream in. Mirrors the sibling-monitor pattern
used by super::behavioral_drift::BehavioralDriftMonitor.
Implementations§
Source§impl CoherenceMonitor
impl CoherenceMonitor
Sourcepub async fn is_tracked(&self, run_id: &RunId) -> bool
pub async fn is_tracked(&self, run_id: &RunId) -> bool
Whether this monitor holds any state for the given run — primarily for tests.
Sourcepub async fn clear_run(&self, run_id: &RunId)
pub async fn clear_run(&self, run_id: &RunId)
Drop all trajectory state for a completed run to free memory.
Sourcepub async fn observe_event(
&self,
run_id: &RunId,
event: &TrajectoryEvent,
config: &CoherenceConfig,
) -> Option<CoherenceSpan>
pub async fn observe_event( &self, run_id: &RunId, event: &TrajectoryEvent, config: &CoherenceConfig, ) -> Option<CoherenceSpan>
Ingest the next trajectory event for run_id. Returns Some the
instant this event completes a divergence (a closure action while a
blocking fact is still open), so the caller can surface it mid-run.
Sourcepub fn scan_trajectory(
run_id: &str,
events: &[TrajectoryEvent],
config: &CoherenceConfig,
) -> Vec<CoherenceSpan>
pub fn scan_trajectory( run_id: &str, events: &[TrajectoryEvent], config: &CoherenceConfig, ) -> Vec<CoherenceSpan>
Replay a whole trajectory statelessly and collect every divergence.
Convenience for post-hoc analysis and tests — shares the exact same
detection core as Self::observe_event.