interplane.Get Omega
Read in your language

aien-sovereign-core-mv

AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination.

Brought by drakestapleton

branch main Branches Tags History

aien-sovereign-core-mv / crates / spark-debugger / src / daemon.rs

84 lines · 2793 bytes Raw Blame History
1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2026 Drake Stapleton (AIEN / aien-dev)
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16use aien_localhttp::Client;
17use std::time::Duration;
18use tokio::time::sleep;
19use tracing::{info, warn};
20
21use crate::audit::run_full_audit;
22use crate::reporter::report_incident;
23
24pub async fn run_watchdog_daemon(
25 client: Client,
26 workspace_dir: String,
27 interval_secs: u64,
28) -> Result<(), Box<dyn std::error::Error>> {
29 info!(
30 "[Watchdog] Starting spark-debugger watchdog daemon (interval: {}s)...",
31 interval_secs
32 );
33
34 let mut consecutive_failures = 0;
35
36 loop {
37 let report = run_full_audit(&client, &workspace_dir).await;
38
39 if !report.overall_healthy {
40 consecutive_failures += 1;
41 let mut issues = Vec::new();
42 for s in &report.services {
43 if !s.reachable {
44 issues.push(format!("Service {} unreachable at {}", s.name, s.endpoint));
45 }
46 }
47 if !report.invariants.passed {
48 issues.push("Vault or unslop invariants violated".to_string());
49 }
50 if !report.build.passed {
51 issues.push(format!(
52 "Workspace build failed with {} errors",
53 report.build.errors.len()
54 ));
55 }
56
57 let summary = issues.join("; ");
58 warn!(
59 "[Watchdog] Audit failed (attempt {}): {}",
60 consecutive_failures, summary
61 );
62
63 if consecutive_failures == 1 || consecutive_failures % 5 == 0 {
64 report_incident(&client, &report, &summary).await;
65 }
66 } else {
67 if consecutive_failures > 0 {
68 info!("[Watchdog] All systems recovered to healthy state.");
69 }
70 consecutive_failures = 0;
71 info!("[Watchdog] All 5 services and workspace invariants OK.");
72 }
73
74 tokio::select! {
75 _ = tokio::signal::ctrl_c() => {
76 info!("[Watchdog] Received termination signal. Halting daemon.");
77 break;
78 }
79 _ = sleep(Duration::from_secs(interval_secs)) => {}
80 }
81 }
82
83 Ok(())
84}