Skip to main content

appcore_supervisor/
snapshot.rs

1// =============================================================================
2//        #######
3//     ###       ###     F: snapshot.rs
4//    ##   ## ##   ##    P: AppCore-Runtime
5//         ## ##
6//                       C: 2026/07/24 13:18:47 by dnettoRaw
7//    ##   ## ##   ##    U: 2026/07/24 13:18:47 by dnettoRaw
8//      ###########      S: 1.0.1-rc.8
9// =============================================================================
10
11//! Immutable supervisor, service, watchdog, and executor diagnostics.
12
13use crate::{
14    RestartState, ServiceActivationState, ServiceHealth, ServiceRuntimeState, WatchdogState,
15};
16
17/// Immutable diagnostic snapshot for one managed service.
18#[derive(Debug, Clone, PartialEq, Eq)]
19pub struct ServiceSnapshot {
20    /// Stable service identifier.
21    pub name: String,
22    /// Current supervisor health.
23    pub health: ServiceHealth,
24    /// Required service dependency identifiers.
25    pub dependencies: Vec<String>,
26    /// Human-readable dependency requirements in matching order.
27    pub dependency_requirements: Vec<String>,
28    /// Installation activation state.
29    pub activation: ServiceActivationState,
30    /// Whether lifecycle actions are enabled.
31    pub enabled: bool,
32    /// Whether deployment configuration exists.
33    pub configured: bool,
34    /// Whether the service may currently own its resource.
35    pub running: bool,
36    /// Concrete execution state.
37    pub runtime_state: ServiceRuntimeState,
38    /// Current restart state.
39    pub restart_state: RestartState,
40    /// Total restarts scheduled since supervisor creation.
41    pub restart_count: u64,
42    /// Whether an operator must explicitly recover the service.
43    pub operator_required: bool,
44    /// Whether automatic lifecycle actions are disabled.
45    pub quarantined: bool,
46    /// Whether this service affects overall Runtime health.
47    pub critical: bool,
48}
49
50/// Immutable watchdog progress exposed to health consumers.
51#[derive(Debug, Clone, PartialEq, Eq)]
52pub struct WatchdogSnapshot {
53    /// Current watchdog state.
54    pub state: WatchdogState,
55    /// Most recent reconciliation start or completion time.
56    pub last_reconcile_at_ms: u64,
57    /// Most recent completed reconciliation time.
58    pub last_progress_at_ms: u64,
59    /// Number of completed reconciliation cycles.
60    pub reconcile_sequence: u64,
61    /// Elapsed time without completed reconciliation.
62    pub stalled_for_ms: u64,
63    /// Whether every enabled critical service is ready or healthy.
64    pub critical_services_healthy: bool,
65    /// Whether watchdog enforcement is enabled.
66    pub enabled: bool,
67    /// Configured stall timeout.
68    pub stall_timeout_ms: u64,
69}
70
71impl WatchdogSnapshot {
72    /// Reports whether progress is currently trustworthy.
73    pub fn is_healthy(&self) -> bool {
74        !self.enabled || self.state == WatchdogState::Healthy
75    }
76}
77
78/// Immutable bounded restart-executor diagnostics.
79#[derive(Debug, Clone, PartialEq, Eq)]
80pub struct RestartExecutorSnapshot {
81    /// Whether workers and queue remain available.
82    pub healthy: bool,
83    /// Number of restart actions currently queued or executing.
84    pub pending: u64,
85    /// Configured queue capacity.
86    pub queue_capacity: usize,
87    /// Configured worker count.
88    pub worker_count: usize,
89}
90
91/// Complete result consumed by `appcore doctor` and diagnostics.
92#[derive(Debug, Clone, PartialEq, Eq)]
93pub struct SupervisorDiagnosis {
94    /// Whether every required dependency exists and the graph is acyclic.
95    pub graph_valid: bool,
96    /// Controlled graph or policy issues.
97    pub issues: Vec<String>,
98    /// Deterministically ordered service snapshots.
99    pub services: Vec<ServiceSnapshot>,
100    /// Reconciliation progress and watchdog health.
101    pub watchdog: WatchdogSnapshot,
102    /// Restart worker and queue health.
103    pub restart_executor: RestartExecutorSnapshot,
104}