From 7a8ad9fcd041026fe19c6ce44637483373c5220e Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Mon, 15 Jun 2026 23:12:39 +0100 Subject: [PATCH] Prefer daemon-published RUDP health --- crates/idunn-daemon/src/main.rs | 119 +++++++++++++++++++++++++++++- crates/odin-core/src/documents.rs | 4 + crates/odin-core/src/idunn.rs | 2 + docs/idunn.md | 8 ++ src/Idunn/README.md | 6 ++ 5 files changed, 135 insertions(+), 4 deletions(-) diff --git a/crates/idunn-daemon/src/main.rs b/crates/idunn-daemon/src/main.rs index 61c99eb..3870b55 100644 --- a/crates/idunn-daemon/src/main.rs +++ b/crates/idunn-daemon/src/main.rs @@ -202,7 +202,8 @@ fn run_target_cycle( observed_at: now.clone(), }; - let health = probe_health(target, options.command_timeout_seconds, &now); + let health = read_fresh_daemon_published_health(options, store_lock, &desired, &now)? + .unwrap_or_else(|| probe_health(target, options.command_timeout_seconds, &now)); let plan = plan_keepalive(&desired, &health, now.clone()); with_store_node(options, store_lock, |node| { @@ -308,9 +309,13 @@ fn run_target_cycle( Ok(()) } -fn with_store_node(options: &CommonOptions, store_lock: &Arc>, write: F) -> Result<()> +fn with_store_node( + options: &CommonOptions, + store_lock: &Arc>, + write: F, +) -> Result where - F: FnOnce(&mut CultMeshNode) -> Result<()>, + F: FnOnce(&mut CultMeshNode) -> Result, { let _store_guard = store_lock .lock() @@ -326,6 +331,57 @@ where write(&mut node) } +fn read_fresh_daemon_published_health( + options: &CommonOptions, + store_lock: &Arc>, + desired: &IdunnDesiredDaemonRecord, + now: &str, +) -> Result> { + with_store_node(options, store_lock, |node| { + let Some(health) = node.get::(&desired.daemon_id)? else { + return Ok(None); + }; + if is_fresh_daemon_published_health(&health, desired, now) { + Ok(Some(health)) + } else { + Ok(None) + } + }) +} + +fn is_fresh_daemon_published_health( + health: &IdunnDaemonHealthRecord, + desired: &IdunnDesiredDaemonRecord, + now: &str, +) -> bool { + if health.daemon_id != desired.daemon_id { + return false; + } + if health.health_contract != desired.health_contract { + return false; + } + if health.publication_source != "daemon-published" { + return false; + } + if health.transport != CULTNET_RUDP_PROTOCOL_ID { + return false; + } + let Some(now_seconds) = parse_unix_timestamp(now) else { + return false; + }; + let Some(observed_seconds) = parse_unix_timestamp(&health.observed_at) else { + return false; + }; + if observed_seconds > now_seconds { + return false; + } + now_seconds.saturating_sub(observed_seconds) <= u64::from(desired.max_silence_seconds) +} + +fn parse_unix_timestamp(value: &str) -> Option { + value.strip_prefix("unix:")?.parse().ok() +} + fn publish_runtime_transport_check( options: &CommonOptions, store_lock: &Arc>, @@ -488,7 +544,9 @@ fn run_rudp_health_ingress_loop( Ok((message, source, transfer_id)) => { let observed_at = timestamp()?; match health_from_rudp_message(&message) { - Ok(health) => { + Ok(mut health) => { + health.publication_source = "daemon-published".to_string(); + health.transport = CULTNET_RUDP_PROTOCOL_ID.to_string(); with_store_node(&options, &store_lock, |node| { node.put(&health.daemon_id, &health)?; Ok(()) @@ -1209,6 +1267,8 @@ fn probe_health( state: "active".to_string(), detail: command_output_detail("health command exited successfully", &output), health_contract: target.health_contract.id.clone(), + publication_source: "compatibility-command".to_string(), + transport: "compatibility.local-command".to_string(), observed_at: observed_at.to_string(), }, Ok(output) => { @@ -1221,6 +1281,8 @@ fn probe_health( state: health_state_from_detail(&detail, target).to_string(), detail, health_contract: target.health_contract.id.clone(), + publication_source: "compatibility-command".to_string(), + transport: "compatibility.local-command".to_string(), observed_at: observed_at.to_string(), } } @@ -1229,6 +1291,8 @@ fn probe_health( state: "failed".to_string(), detail: format!("health command could not run: {error}"), health_contract: target.health_contract.id.clone(), + publication_source: "compatibility-command".to_string(), + transport: "compatibility.local-command".to_string(), observed_at: observed_at.to_string(), }, }, @@ -1237,6 +1301,8 @@ fn probe_health( state: "unknown".to_string(), detail: "no health command was provided".to_string(), health_contract: target.health_contract.id.clone(), + publication_source: "compatibility-command".to_string(), + transport: "compatibility.local-command".to_string(), observed_at: observed_at.to_string(), }, } @@ -1564,6 +1630,49 @@ mod tests { ); } + #[test] + fn fresh_daemon_published_rudp_health_can_replace_probe_health() { + let desired = IdunnDesiredDaemonRecord { + daemon_id: "test-daemon".to_string(), + verse_id: "test.local".to_string(), + name: "Test daemon".to_string(), + enabled: true, + health_command: Some("exit 1".to_string()), + restart_command: Some("restart test".to_string()), + authority: "idunn.local-command".to_string(), + max_silence_seconds: 60, + observed_at: "unix:100".to_string(), + deploy_command: None, + health_contract: "test.cultnet-rudp-health".to_string(), + transport_profile_id: "transport:test-daemon".to_string(), + command_boundary_id: "command-boundary:test-daemon".to_string(), + }; + let mut health = IdunnDaemonHealthRecord { + daemon_id: "test-daemon".to_string(), + state: "active".to_string(), + detail: "daemon published".to_string(), + observed_at: "unix:95".to_string(), + health_contract: "test.cultnet-rudp-health".to_string(), + publication_source: "daemon-published".to_string(), + transport: CULTNET_RUDP_PROTOCOL_ID.to_string(), + }; + + assert!(is_fresh_daemon_published_health( + &health, &desired, "unix:100" + )); + + health.observed_at = "unix:1".to_string(); + assert!(!is_fresh_daemon_published_health( + &health, &desired, "unix:100" + )); + + health.observed_at = "unix:95".to_string(); + health.publication_source = "compatibility-command".to_string(); + assert!(!is_fresh_daemon_published_health( + &health, &desired, "unix:100" + )); + } + #[test] fn runtime_transport_check_proves_rudp_loopback() { let check = runtime_transport_check("2026-06-15T00:00:00Z"); @@ -1581,6 +1690,8 @@ mod tests { detail: "published by daemon".to_string(), observed_at: "2026-06-15T00:00:00Z".to_string(), health_contract: "test.cultnet-rudp-health".to_string(), + publication_source: "daemon-published".to_string(), + transport: CULTNET_RUDP_PROTOCOL_ID.to_string(), }; let message = CultNetMessage::DocumentPutRaw { message_id: "test-health".to_string(), diff --git a/crates/odin-core/src/documents.rs b/crates/odin-core/src/documents.rs index 825ccca..9c626a8 100644 --- a/crates/odin-core/src/documents.rs +++ b/crates/odin-core/src/documents.rs @@ -241,6 +241,10 @@ pub struct IdunnDaemonHealthRecord { pub observed_at: String, #[cultcache(key = 4)] pub health_contract: String, + #[cultcache(key = 5, default)] + pub publication_source: String, + #[cultcache(key = 6, default)] + pub transport: String, } #[derive(Clone, Debug, PartialEq, Eq, DatabaseEntry)] diff --git a/crates/odin-core/src/idunn.rs b/crates/odin-core/src/idunn.rs index 7b1bb37..d30e822 100644 --- a/crates/odin-core/src/idunn.rs +++ b/crates/odin-core/src/idunn.rs @@ -209,6 +209,8 @@ mod tests { detail: "unit probe".to_string(), observed_at: "2026-06-04T00:00:01Z".to_string(), health_contract: "test.command-exit".to_string(), + publication_source: "compatibility-command".to_string(), + transport: "compatibility.local-command".to_string(), } } diff --git a/docs/idunn.md b/docs/idunn.md index 4c3936c..dd7094c 100644 --- a/docs/idunn.md +++ b/docs/idunn.md @@ -117,6 +117,9 @@ idunn.rudp_health_ingress.v1 distinguish process liveness, source deployment freshness, framebuffer composition, telemetry capture, and catalog coherence without mistaking a temporary HTTP/WebSocket/SSH/systemd probe for the real protocol surface. + `idunn.daemon_health.v1` also records `publication_source` and `transport` so + daemon-published RUDP health can be distinguished from compatibility command + evidence. - `idunn.desired_daemon.v1` links to `idunn.daemon_transport_profile.v1` and `idunn.command_boundary.v1` records. The transport profile names the target transport @@ -147,6 +150,11 @@ idunn.rudp_health_ingress.v1 not grant deploy/restart authority and it does not make compatibility probes owners; it is the first daemon-owned health publication path Idunn can consume. +- During each target cycle, fresh daemon-published RUDP health wins over the + local compatibility command. Idunn accepts it only when the daemon id, health + contract, `publication_source=daemon-published`, transport + `cultnet.transport.rudp.v0`, and `max_silence_seconds` freshness window all + match. If any of those fail, the command probe remains fallback evidence. - Idunn publishes the transport migration plan as `idunn.daemon_surgery_plan.v1` records in the keepalive store. Each daemon plan names severity, status, owner, objective, current mechanism, intended diff --git a/src/Idunn/README.md b/src/Idunn/README.md index d5eca5a..3ed15db 100644 --- a/src/Idunn/README.md +++ b/src/Idunn/README.md @@ -185,6 +185,12 @@ started with `--rudp-health-bind none`. It accepts raw them into the keepalive store. That is daemon-owned health publication, not restart/deploy authority. +When a fresh daemon-published RUDP health record exists for a target, Idunn uses +that record for keepalive planning before falling back to the local command +probe. The record must match the daemon id, health contract, RUDP transport, +and freshness window; otherwise the compatibility probe remains fallback +evidence. + The next cuts are updating daemon CultLib dependencies so health and command boundaries publish through `cultnet.transport.rudp.v0`, switching Idunn to those daemon-owned records, promoting the built-in target catalog into Odin-ingested