Prepare Epiphany for Yggdrasil supervision
This commit is contained in:
parent
f023695234
commit
916af1822f
10 changed files with 1004 additions and 14 deletions
|
|
@ -18,6 +18,7 @@ use epiphany_core::EpiphanyLocalVerseContext;
|
|||
use epiphany_core::EpiphanyProcessObservation as ProcessObservation;
|
||||
use epiphany_core::MemorySemanticProjectionInput;
|
||||
use epiphany_core::agent_memory_semantic_projection_input;
|
||||
use epiphany_core::authenticate_epiphany_cultmesh_semantic_projector_launch;
|
||||
use epiphany_core::epiphany_cultmesh_daemon_poke_intent_from_status;
|
||||
use epiphany_core::epiphany_cultmesh_daemon_poke_receipt_for_intent;
|
||||
use epiphany_core::idunn_recover_memory_semantic_projection_from_cultmesh;
|
||||
|
|
@ -48,16 +49,22 @@ use epiphany_core::write_epiphany_cultmesh_daemon_service_lifecycle_receipt;
|
|||
use epiphany_core::write_epiphany_cultmesh_managed_service_policy;
|
||||
use epiphany_core::write_epiphany_cultmesh_semantic_projector_service_policy;
|
||||
use epiphany_core::write_epiphany_cultmesh_workspace_coverage_projector_service_policy;
|
||||
use epiphany_core::{
|
||||
EpiphanyAggregateRuntimeHealthInput, derive_epiphany_aggregate_runtime_health,
|
||||
publish_idunn_daemon_health_rudp,
|
||||
};
|
||||
use epiphany_core::{EpiphanyPackagedReleaseEntry, authenticate_epiphany_packaged_release};
|
||||
use epiphany_core::{
|
||||
ProcessInstanceIdentity, ProcessInstanceObservation,
|
||||
WORKSPACE_COVERAGE_PROCESS_LAUNCH_SCHEMA_VERSION, WorkspaceCoverageManagedProcessLaunchEntry,
|
||||
WorkspaceCoverageProcessBootstrap, authenticate_workspace_coverage_provider_heartbeat,
|
||||
WorkspaceCoverageProcessBootstrap, authenticate_workspace_coverage_managed_process_launch,
|
||||
authenticate_workspace_coverage_provider_heartbeat,
|
||||
authenticate_workspace_coverage_termination_with_envelope_digest, capture_process_instance,
|
||||
current_workspace_coverage_recovery_target,
|
||||
load_latest_workspace_coverage_managed_process_launch,
|
||||
load_latest_workspace_coverage_provider_heartbeat,
|
||||
load_workspace_coverage_process_termination_observation, native_boot_identity,
|
||||
open_default_host_identity, recover_workspace_coverage_projection,
|
||||
observe_process_instance, open_default_host_identity, recover_workspace_coverage_projection,
|
||||
sign_workspace_coverage_launch, workspace_coverage_host_identity_record_digest,
|
||||
write_workspace_coverage_managed_process_launch, write_workspace_coverage_process_bootstrap,
|
||||
write_workspace_coverage_process_termination_observation,
|
||||
|
|
@ -72,6 +79,7 @@ use sha2::Digest;
|
|||
use sha2::Sha256;
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::net::SocketAddr;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::Command;
|
||||
use std::process::Stdio;
|
||||
|
|
@ -85,6 +93,14 @@ const SEMANTIC_PROJECTOR_EXECUTOR_ID: &str = "epiphany-memory-semantic-projector
|
|||
const WORKSPACE_COVERAGE_PROJECTOR_SERVICE_ID: &str =
|
||||
"epiphany-workspace-coverage-projector-service";
|
||||
const WORKSPACE_COVERAGE_PROJECTOR_EXECUTOR_ID: &str = "epiphany-workspace-coverage-projector";
|
||||
const AGGREGATE_HEARTBEAT_FRESH_SECONDS: i64 = 180;
|
||||
|
||||
enum ManagedServiceLineage {
|
||||
Current,
|
||||
Pending,
|
||||
Stale(String),
|
||||
LegacyV1,
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
use std::os::windows::process::CommandExt;
|
||||
|
|
@ -793,6 +809,7 @@ fn managed_service_serve(args: Args) -> Result<()> {
|
|||
service_args.service_id = policy.service_id.clone();
|
||||
managed_service_reconcile(service_args)?;
|
||||
}
|
||||
publish_managed_service_iteration_health(&args, &release, &policies);
|
||||
println!(
|
||||
"{}",
|
||||
serde_json::to_string_pretty(&json!({
|
||||
|
|
@ -814,6 +831,300 @@ fn managed_service_serve(args: Args) -> Result<()> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn publish_managed_service_iteration_health(
|
||||
args: &Args,
|
||||
release: &EpiphanyPackagedReleaseEntry,
|
||||
policies: &[EpiphanyCultMeshManagedServicePolicyEntry],
|
||||
) {
|
||||
let (Some(endpoint), Some(daemon_id), Some(health_contract)) = (
|
||||
args.idunn_rudp_health,
|
||||
args.idunn_daemon.as_deref(),
|
||||
args.idunn_health_contract.as_deref(),
|
||||
) else {
|
||||
return;
|
||||
};
|
||||
let required = [
|
||||
SEMANTIC_PROJECTOR_SERVICE_ID,
|
||||
WORKSPACE_COVERAGE_PROJECTOR_SERVICE_ID,
|
||||
];
|
||||
let expected = required.len();
|
||||
let mut current = 0_usize;
|
||||
let mut contradictions = Vec::new();
|
||||
for service_id in required {
|
||||
let Some(policy) = policies
|
||||
.iter()
|
||||
.find(|policy| policy.service_id == service_id)
|
||||
else {
|
||||
continue;
|
||||
};
|
||||
if !policy.enabled || policy.restart_mode == "never" {
|
||||
continue;
|
||||
}
|
||||
match managed_service_lineage(args, release, policy) {
|
||||
Ok(ManagedServiceLineage::Current) => current += 1,
|
||||
Ok(ManagedServiceLineage::Pending) => {}
|
||||
Ok(ManagedServiceLineage::LegacyV1) => contradictions.push(format!(
|
||||
"{}: legacy v1 launch awaits typed retirement",
|
||||
policy.service_id
|
||||
)),
|
||||
Ok(ManagedServiceLineage::Stale(reason)) => {
|
||||
contradictions.push(format!("{}: {reason}", policy.service_id))
|
||||
}
|
||||
Err(error) => contradictions.push(format!("{}: {error:#}", policy.service_id)),
|
||||
}
|
||||
}
|
||||
let health = derive_epiphany_aggregate_runtime_health(EpiphanyAggregateRuntimeHealthInput {
|
||||
daemon_id: daemon_id.to_string(),
|
||||
health_contract: health_contract.to_string(),
|
||||
observed_at: Utc::now().to_rfc3339_opts(chrono::SecondsFormat::Secs, true),
|
||||
release_authenticated: true,
|
||||
expected_service_count: expected,
|
||||
current_service_count: current,
|
||||
contradictions,
|
||||
});
|
||||
match health.and_then(|mut health| {
|
||||
let witness_sha256 = epiphany_packaged_release_witness_sha256(release)?;
|
||||
health.detail.push_str(&format!(
|
||||
" releaseId={} witnessSha256={} sourceCommit={}",
|
||||
release.release_id, witness_sha256, release.source_commit_sha
|
||||
));
|
||||
publish_idunn_daemon_health_rudp(endpoint, "epiphany-daemon-supervisor", &health)
|
||||
}) {
|
||||
Ok(()) => {}
|
||||
Err(error) => eprintln!("Epiphany could not publish aggregate Idunn health: {error:#}"),
|
||||
}
|
||||
}
|
||||
|
||||
fn managed_service_lineage(
|
||||
args: &Args,
|
||||
release: &EpiphanyPackagedReleaseEntry,
|
||||
policy: &EpiphanyCultMeshManagedServicePolicyEntry,
|
||||
) -> Result<ManagedServiceLineage> {
|
||||
let (_, policy_digest) = load_epiphany_cultmesh_managed_service_policy_with_digest(
|
||||
&args.store,
|
||||
args.runtime_id.clone(),
|
||||
&policy.service_id,
|
||||
)?
|
||||
.with_context(|| {
|
||||
format!(
|
||||
"managed service policy disappeared for {}",
|
||||
policy.service_id
|
||||
)
|
||||
})?;
|
||||
if policy.service_id == WORKSPACE_COVERAGE_PROJECTOR_SERVICE_ID {
|
||||
let Some(launch) = load_latest_workspace_coverage_managed_process_launch(
|
||||
&args.store,
|
||||
args.runtime_id.clone(),
|
||||
)?
|
||||
else {
|
||||
return Ok(ManagedServiceLineage::Pending);
|
||||
};
|
||||
let host = open_default_host_identity()?;
|
||||
let launch = authenticate_workspace_coverage_managed_process_launch(
|
||||
&args.store,
|
||||
args.runtime_id.clone(),
|
||||
&launch.launch_id,
|
||||
host.entry(),
|
||||
)?;
|
||||
if launch.policy_envelope_digest != policy_digest {
|
||||
return Ok(ManagedServiceLineage::Stale(
|
||||
"workspace child launch disagrees with current policy digest".into(),
|
||||
));
|
||||
}
|
||||
let expected = fs::canonicalize(epiphany_packaged_release_binary_path(
|
||||
release,
|
||||
"workspace-coverage-projector",
|
||||
)?)?;
|
||||
if fs::canonicalize(&launch.process_executable_path)? != expected {
|
||||
return Ok(ManagedServiceLineage::Stale(
|
||||
"workspace child executable is outside current packaged release".into(),
|
||||
));
|
||||
}
|
||||
let Some(heartbeat) = load_latest_workspace_coverage_provider_heartbeat(
|
||||
&args.store,
|
||||
args.runtime_id.clone(),
|
||||
&launch.launch_id,
|
||||
)?
|
||||
else {
|
||||
return Ok(ManagedServiceLineage::Pending);
|
||||
};
|
||||
let heartbeat = authenticate_workspace_coverage_provider_heartbeat(
|
||||
&args.store,
|
||||
args.runtime_id.clone(),
|
||||
&heartbeat.heartbeat_id,
|
||||
host.entry(),
|
||||
)?;
|
||||
if heartbeat.status != "ready" || !timestamp_is_fresh(&heartbeat.observed_at_utc)? {
|
||||
return Ok(ManagedServiceLineage::Pending);
|
||||
}
|
||||
let identity = ProcessInstanceIdentity {
|
||||
process_id: launch.process_id,
|
||||
creation_token: launch.process_creation_token,
|
||||
created_at_rfc3339: launch.process_created_at_rfc3339,
|
||||
executable_path: PathBuf::from(launch.process_executable_path),
|
||||
};
|
||||
return Ok(
|
||||
if observe_process_instance(&identity) == ProcessInstanceObservation::ExactAlive {
|
||||
ManagedServiceLineage::Current
|
||||
} else {
|
||||
ManagedServiceLineage::Pending
|
||||
},
|
||||
);
|
||||
}
|
||||
let Some(receipt) = load_latest_epiphany_cultmesh_daemon_service_lifecycle_receipt_for_service(
|
||||
&args.store,
|
||||
args.runtime_id.clone(),
|
||||
&policy.service_id,
|
||||
)?
|
||||
else {
|
||||
return Ok(ManagedServiceLineage::Pending);
|
||||
};
|
||||
if receipt.schema_version == "epiphany.cultmesh.daemon_service_lifecycle_receipt.v1" {
|
||||
return Ok(ManagedServiceLineage::LegacyV1);
|
||||
}
|
||||
if receipt.managed_policy_id != policy.policy_id
|
||||
|| receipt.managed_policy_digest != policy_digest
|
||||
|| receipt.command != policy.command
|
||||
|| receipt.args != policy.args
|
||||
|| receipt.cwd != policy.cwd
|
||||
{
|
||||
lifecycle_process_identity(&receipt)?;
|
||||
return Ok(ManagedServiceLineage::Stale(
|
||||
"alive child lineage disagrees with current managed policy".into(),
|
||||
));
|
||||
}
|
||||
if policy.service_id == SEMANTIC_PROJECTOR_SERVICE_ID {
|
||||
authenticate_epiphany_cultmesh_semantic_projector_launch(
|
||||
&args.store,
|
||||
args.runtime_id.clone(),
|
||||
&receipt.receipt_id,
|
||||
)?;
|
||||
let expected = fs::canonicalize(epiphany_packaged_release_binary_path(
|
||||
release,
|
||||
"semantic-projector",
|
||||
)?)?;
|
||||
if fs::canonicalize(&receipt.command)? != expected {
|
||||
lifecycle_process_identity(&receipt)?;
|
||||
return Ok(ManagedServiceLineage::Stale(
|
||||
"semantic child executable is outside current packaged release".into(),
|
||||
));
|
||||
}
|
||||
let heartbeat = load_latest_epiphany_cultmesh_daemon_heartbeat(
|
||||
&args.store,
|
||||
args.runtime_id.clone(),
|
||||
&receipt.provider_daemon_id,
|
||||
)?;
|
||||
let launch_completed = receipt
|
||||
.completed_at_utc
|
||||
.as_deref()
|
||||
.context("semantic launch receipt has no spawn completion time")?;
|
||||
if !semantic_heartbeat_is_ready(
|
||||
heartbeat.as_ref(),
|
||||
&receipt.receipt_id,
|
||||
launch_completed,
|
||||
Utc::now(),
|
||||
)? {
|
||||
return Ok(ManagedServiceLineage::Pending);
|
||||
}
|
||||
}
|
||||
let identity = lifecycle_process_identity(&receipt)?;
|
||||
Ok(
|
||||
if observe_process_instance(&identity) == ProcessInstanceObservation::ExactAlive {
|
||||
ManagedServiceLineage::Current
|
||||
} else {
|
||||
ManagedServiceLineage::Pending
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
fn lifecycle_process_identity(
|
||||
receipt: &EpiphanyCultMeshDaemonServiceLifecycleReceiptEntry,
|
||||
) -> Result<ProcessInstanceIdentity> {
|
||||
process_identity_from_parts(
|
||||
receipt.process_id,
|
||||
receipt.process_creation_token,
|
||||
receipt.process_created_at_rfc3339.clone(),
|
||||
&receipt.process_executable_path,
|
||||
)
|
||||
}
|
||||
|
||||
fn process_identity_from_parts(
|
||||
process_id: Option<u32>,
|
||||
creation_token: u64,
|
||||
created_at_rfc3339: Option<String>,
|
||||
executable_path: &str,
|
||||
) -> Result<ProcessInstanceIdentity> {
|
||||
if creation_token == 0 || executable_path.trim().is_empty() {
|
||||
anyhow::bail!("launch receipt has no authenticated process-instance identity");
|
||||
}
|
||||
Ok(ProcessInstanceIdentity {
|
||||
process_id: process_id.context("launch receipt has no process id")?,
|
||||
creation_token,
|
||||
created_at_rfc3339,
|
||||
executable_path: PathBuf::from(executable_path),
|
||||
})
|
||||
}
|
||||
|
||||
fn replacement_process_identity(
|
||||
lineage: &ManagedServiceLineage,
|
||||
receipt: &EpiphanyCultMeshDaemonServiceLifecycleReceiptEntry,
|
||||
) -> Result<Option<ProcessInstanceIdentity>> {
|
||||
replacement_identity_from_parts(
|
||||
lineage,
|
||||
receipt.process_id,
|
||||
receipt.process_creation_token,
|
||||
receipt.process_created_at_rfc3339.clone(),
|
||||
&receipt.process_executable_path,
|
||||
)
|
||||
}
|
||||
|
||||
fn replacement_identity_from_parts(
|
||||
lineage: &ManagedServiceLineage,
|
||||
process_id: Option<u32>,
|
||||
creation_token: u64,
|
||||
created_at_rfc3339: Option<String>,
|
||||
executable_path: &str,
|
||||
) -> Result<Option<ProcessInstanceIdentity>> {
|
||||
match lineage {
|
||||
ManagedServiceLineage::Stale(_) => process_identity_from_parts(
|
||||
process_id,
|
||||
creation_token,
|
||||
created_at_rfc3339,
|
||||
executable_path,
|
||||
)
|
||||
.map(Some),
|
||||
ManagedServiceLineage::Current
|
||||
| ManagedServiceLineage::Pending
|
||||
| ManagedServiceLineage::LegacyV1 => Ok(None),
|
||||
}
|
||||
}
|
||||
|
||||
fn timestamp_is_fresh(value: &str) -> Result<bool> {
|
||||
timestamp_is_fresh_at(value, Utc::now())
|
||||
}
|
||||
|
||||
fn semantic_heartbeat_is_ready(
|
||||
heartbeat: Option<&epiphany_core::EpiphanyCultMeshDaemonHeartbeatEventEntry>,
|
||||
lifecycle_receipt_id: &str,
|
||||
launch_completed_at: &str,
|
||||
now: DateTime<Utc>,
|
||||
) -> Result<bool> {
|
||||
let Some(heartbeat) = heartbeat else {
|
||||
return Ok(false);
|
||||
};
|
||||
Ok(heartbeat.status == "ready"
|
||||
&& heartbeat.startup_lifecycle_receipt_id == lifecycle_receipt_id
|
||||
&& DateTime::parse_from_rfc3339(&heartbeat.heartbeat_at)?
|
||||
> DateTime::parse_from_rfc3339(launch_completed_at)?
|
||||
&& timestamp_is_fresh_at(&heartbeat.heartbeat_at, now)?)
|
||||
}
|
||||
|
||||
fn timestamp_is_fresh_at(value: &str, now: DateTime<Utc>) -> Result<bool> {
|
||||
let observed = DateTime::parse_from_rfc3339(value)?.with_timezone(&Utc);
|
||||
let age = now.signed_duration_since(observed);
|
||||
Ok(age >= Duration::zero() && age <= Duration::seconds(AGGREGATE_HEARTBEAT_FRESH_SECONDS))
|
||||
}
|
||||
|
||||
fn service_plan(args: Args) -> Result<()> {
|
||||
let brake = load_epiphany_cultmesh_swarm_brake(&args.store, args.runtime_id.clone())?;
|
||||
assert_swarm_brake_allows_service_lifecycle_entry(brake.as_ref())?;
|
||||
|
|
@ -988,6 +1299,25 @@ fn service_launch_internal(
|
|||
let mut child = command
|
||||
.spawn()
|
||||
.with_context(|| format!("failed to launch service {}", command_path.display()))?;
|
||||
let generic_process_identity = if coverage_launch.is_none() {
|
||||
let identity = match capture_process_instance(child.id()) {
|
||||
Ok(identity) => identity,
|
||||
Err(error) => {
|
||||
let _ = child.kill();
|
||||
let _ = child.wait();
|
||||
return Err(error)
|
||||
.context("failed to capture exact managed-service process identity");
|
||||
}
|
||||
};
|
||||
if identity.executable_path != command_path.canonicalize()? {
|
||||
let _ = child.kill();
|
||||
let _ = child.wait();
|
||||
anyhow::bail!("spawned managed-service executable disagrees with launch command");
|
||||
}
|
||||
Some(identity)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
if let Some((
|
||||
policy,
|
||||
policy_digest,
|
||||
|
|
@ -1133,6 +1463,11 @@ fn service_launch_internal(
|
|||
.as_ref()
|
||||
.map(|path| path.display().to_string()),
|
||||
);
|
||||
if let Some(identity) = generic_process_identity {
|
||||
receipt.process_creation_token = identity.creation_token;
|
||||
receipt.process_created_at_rfc3339 = identity.created_at_rfc3339;
|
||||
receipt.process_executable_path = identity.executable_path.display().to_string();
|
||||
}
|
||||
if let Some((policy_id, policy_digest, receipt_id, executable_sha256, executor_id)) =
|
||||
reserved_launch
|
||||
{
|
||||
|
|
@ -1277,6 +1612,50 @@ fn write_managed_service_policy(args: Args) -> Result<()> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn retire_legacy_lifecycle_receipt(
|
||||
args: &Args,
|
||||
legacy: &EpiphanyCultMeshDaemonServiceLifecycleReceiptEntry,
|
||||
) -> Result<bool> {
|
||||
let process_id = legacy
|
||||
.process_id
|
||||
.context("legacy launch receipt has no process id")?;
|
||||
let observation = observe_process(process_id)?;
|
||||
let mut retirement = service_lifecycle_receipt(
|
||||
args,
|
||||
"retire-legacy-launch",
|
||||
if observation == ProcessObservation::Alive {
|
||||
"operator-action-required"
|
||||
} else {
|
||||
"retired"
|
||||
},
|
||||
legacy.command.clone(),
|
||||
legacy.args.clone(),
|
||||
Some(process_id),
|
||||
None,
|
||||
Utc::now(),
|
||||
Some(Utc::now()),
|
||||
Some(format!("receipt://{}", legacy.receipt_id)),
|
||||
);
|
||||
retirement.notes = vec![
|
||||
format!("Retires read-only v1 lifecycle receipt {}.", legacy.receipt_id),
|
||||
"Legacy PID state never authorizes termination; owner-controlled stop is required before v2 relaunch."
|
||||
.into(),
|
||||
];
|
||||
if observation == ProcessObservation::Alive {
|
||||
let identity = capture_process_instance(process_id)
|
||||
.context("failed to observe legacy process incarnation for non-killing retirement")?;
|
||||
retirement.process_creation_token = identity.creation_token;
|
||||
retirement.process_created_at_rfc3339 = identity.created_at_rfc3339;
|
||||
retirement.process_executable_path = identity.executable_path.display().to_string();
|
||||
}
|
||||
write_epiphany_cultmesh_daemon_service_lifecycle_receipt(
|
||||
&args.store,
|
||||
args.runtime_id.clone(),
|
||||
retirement,
|
||||
)?;
|
||||
Ok(observation == ProcessObservation::Alive)
|
||||
}
|
||||
|
||||
fn semantic_projector_service_policy(mut args: Args) -> Result<()> {
|
||||
if args.service_command.is_some() {
|
||||
anyhow::bail!(
|
||||
|
|
@ -1539,12 +1918,58 @@ fn managed_service_reconcile(mut args: Args) -> Result<()> {
|
|||
.into_iter()
|
||||
.filter(|receipt| receipt.service_id == args.service_id)
|
||||
.max_by(|left, right| left.started_at_utc.cmp(&right.started_at_utc));
|
||||
let observation = latest
|
||||
.as_ref()
|
||||
.and_then(|receipt| receipt.process_id)
|
||||
.map(observe_process)
|
||||
.transpose()?
|
||||
.unwrap_or(ProcessObservation::Missing);
|
||||
let mut legacy_retirement_released = false;
|
||||
if let Some(receipt) = latest.as_ref()
|
||||
&& receipt.schema_version == "epiphany.cultmesh.daemon_service_lifecycle_receipt.v1"
|
||||
&& retire_legacy_lifecycle_receipt(&args, receipt)?
|
||||
{
|
||||
return Ok(());
|
||||
}
|
||||
if let Some(receipt) = latest.as_ref()
|
||||
&& receipt.action == "retire-legacy-launch"
|
||||
&& receipt.status == "operator-action-required"
|
||||
{
|
||||
let identity = lifecycle_process_identity(receipt)?;
|
||||
if matches!(
|
||||
observe_process_instance(&identity),
|
||||
ProcessInstanceObservation::ExactAlive
|
||||
| ProcessInstanceObservation::Inaccessible
|
||||
| ProcessInstanceObservation::Indeterminate { .. }
|
||||
) {
|
||||
println!(
|
||||
"Legacy managed-service launch {} awaits owner-controlled stop before v2 relaunch.",
|
||||
receipt.receipt_id
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
legacy_retirement_released = true;
|
||||
}
|
||||
let mut observation = if legacy_retirement_released {
|
||||
ProcessObservation::Missing
|
||||
} else {
|
||||
latest
|
||||
.as_ref()
|
||||
.and_then(|receipt| receipt.process_id)
|
||||
.map(observe_process)
|
||||
.transpose()?
|
||||
.unwrap_or(ProcessObservation::Missing)
|
||||
};
|
||||
if observation == ProcessObservation::Alive
|
||||
&& let Some(release) = pinned_release.as_ref()
|
||||
{
|
||||
let lineage = managed_service_lineage(&args, release, &policy).with_context(|| {
|
||||
format!("failed to authenticate {} child lineage", policy.service_id)
|
||||
})?;
|
||||
if let Some(identity) = replacement_process_identity(
|
||||
&lineage,
|
||||
latest
|
||||
.as_ref()
|
||||
.context("alive managed service has no lifecycle receipt")?,
|
||||
)? {
|
||||
terminate_native_process_instance(&identity)?;
|
||||
observation = ProcessObservation::Missing;
|
||||
}
|
||||
}
|
||||
if !policy.enabled || policy.restart_mode == "never" {
|
||||
println!(
|
||||
"{}",
|
||||
|
|
@ -1629,6 +2054,25 @@ fn managed_service_reconcile(mut args: Args) -> Result<()> {
|
|||
service_launch(args)
|
||||
}
|
||||
|
||||
fn terminate_native_process_instance(identity: &ProcessInstanceIdentity) -> Result<()> {
|
||||
if observe_process_instance(identity) != ProcessInstanceObservation::ExactAlive {
|
||||
anyhow::bail!("stale managed-service process identity drifted before termination");
|
||||
}
|
||||
let process_id = identity.process_id;
|
||||
#[cfg(windows)]
|
||||
let status = Command::new("taskkill")
|
||||
.args(["/PID", &process_id.to_string(), "/T", "/F"])
|
||||
.status()?;
|
||||
#[cfg(not(windows))]
|
||||
let status = Command::new("kill")
|
||||
.args(["-TERM", &process_id.to_string()])
|
||||
.status()?;
|
||||
if !status.success() {
|
||||
anyhow::bail!("failed to terminate stale managed-service process {process_id}");
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn reconcile_workspace_coverage_projector(
|
||||
mut args: Args,
|
||||
policy: EpiphanyCultMeshManagedServicePolicyEntry,
|
||||
|
|
@ -2990,6 +3434,9 @@ fn service_lifecycle_receipt(
|
|||
managed_policy_digest: String::new(),
|
||||
provider_daemon_id: String::new(),
|
||||
startup_correlation_id: String::new(),
|
||||
process_creation_token: 0,
|
||||
process_created_at_rfc3339: None,
|
||||
process_executable_path: String::new(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -3477,6 +3924,99 @@ mod semantic_projector_authority_tests {
|
|||
r#"C:\Mind\state.cc "two words""#
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn idunn_health_configuration_is_explicit_and_all_or_none() {
|
||||
let endpoint: SocketAddr = "127.0.0.1:17870".parse().unwrap();
|
||||
assert!(validate_idunn_health_options(None, None, None).is_ok());
|
||||
assert!(
|
||||
validate_idunn_health_options(
|
||||
Some(&endpoint),
|
||||
Some("yggdrasil-epiphany"),
|
||||
Some("epiphany.cultnet-rudp-runtime-health"),
|
||||
)
|
||||
.is_ok()
|
||||
);
|
||||
assert!(validate_idunn_health_options(Some(&endpoint), None, None).is_err());
|
||||
assert!(validate_idunn_health_options(None, Some("epiphany"), None).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stale_child_replacement_fails_closed_and_revalidates_process_identity() {
|
||||
assert!(process_identity_from_parts(Some(7), 0, None, "projector").is_err());
|
||||
assert!(process_identity_from_parts(Some(7), 9, None, "").is_err());
|
||||
let identity = process_identity_from_parts(Some(7), 9, None, "projector").unwrap();
|
||||
assert_eq!(identity.process_id, 7);
|
||||
assert!(
|
||||
replacement_identity_from_parts(&ManagedServiceLineage::Pending, Some(7), 0, None, "",)
|
||||
.unwrap()
|
||||
.is_none()
|
||||
);
|
||||
assert!(
|
||||
replacement_identity_from_parts(
|
||||
&ManagedServiceLineage::LegacyV1,
|
||||
Some(7),
|
||||
0,
|
||||
None,
|
||||
"",
|
||||
)
|
||||
.unwrap()
|
||||
.is_none()
|
||||
);
|
||||
assert!(
|
||||
replacement_identity_from_parts(
|
||||
&ManagedServiceLineage::Stale("policy mismatch".into()),
|
||||
Some(7),
|
||||
0,
|
||||
None,
|
||||
"",
|
||||
)
|
||||
.is_err()
|
||||
);
|
||||
|
||||
let mut live = capture_process_instance(std::process::id()).unwrap();
|
||||
live.creation_token = live.creation_token.saturating_add(1);
|
||||
assert!(matches!(
|
||||
observe_process_instance(&live),
|
||||
ProcessInstanceObservation::Replaced { .. }
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn aggregate_heartbeat_freshness_has_a_bounded_authority_window() {
|
||||
let now = DateTime::parse_from_rfc3339("2026-07-16T12:03:00Z")
|
||||
.unwrap()
|
||||
.with_timezone(&Utc);
|
||||
assert!(timestamp_is_fresh_at("2026-07-16T12:00:00Z", now).unwrap());
|
||||
assert!(!timestamp_is_fresh_at("2026-07-16T11:59:59Z", now).unwrap());
|
||||
assert!(!timestamp_is_fresh_at("2026-07-16T12:03:01Z", now).unwrap());
|
||||
|
||||
let heartbeat = epiphany_core::EpiphanyCultMeshDaemonHeartbeatEventEntry {
|
||||
schema_version: "epiphany.cultmesh.daemon_heartbeat_event.v0".into(),
|
||||
heartbeat_id: "heartbeat".into(),
|
||||
daemon_id: SEMANTIC_PROJECTOR_EXECUTOR_ID.into(),
|
||||
cluster_id: "local".into(),
|
||||
provider_incarnation: "provider".into(),
|
||||
sequence: 1,
|
||||
status: "ready".into(),
|
||||
heartbeat_at: "2026-07-16T12:02:00Z".into(),
|
||||
private_state_exposed: false,
|
||||
startup_lifecycle_receipt_id: "receipt".into(),
|
||||
};
|
||||
assert!(
|
||||
!semantic_heartbeat_is_ready(None, "receipt", "2026-07-16T12:00:00Z", now).unwrap()
|
||||
);
|
||||
assert!(
|
||||
semantic_heartbeat_is_ready(Some(&heartbeat), "receipt", "2026-07-16T12:00:00Z", now,)
|
||||
.unwrap()
|
||||
);
|
||||
let mut alien = heartbeat.clone();
|
||||
alien.startup_lifecycle_receipt_id = "other".into();
|
||||
assert!(
|
||||
!semantic_heartbeat_is_ready(Some(&alien), "receipt", "2026-07-16T12:00:00Z", now,)
|
||||
.unwrap()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
|
|
@ -3525,6 +4065,9 @@ struct Args {
|
|||
task_restart_count: u32,
|
||||
release_id: Option<String>,
|
||||
release_witness_sha256: Option<String>,
|
||||
idunn_rudp_health: Option<SocketAddr>,
|
||||
idunn_daemon: Option<String>,
|
||||
idunn_health_contract: Option<String>,
|
||||
}
|
||||
|
||||
impl Args {
|
||||
|
|
@ -3575,6 +4118,9 @@ impl Args {
|
|||
let mut fatal_log = None;
|
||||
let mut release_id = None;
|
||||
let mut release_witness_sha256 = None;
|
||||
let mut idunn_rudp_health = None;
|
||||
let mut idunn_daemon = None;
|
||||
let mut idunn_health_contract = None;
|
||||
|
||||
while let Some(arg) = values.next() {
|
||||
match arg.as_str() {
|
||||
|
|
@ -3753,6 +4299,24 @@ impl Args {
|
|||
.context("missing --release-witness-sha256 value")?,
|
||||
);
|
||||
}
|
||||
"--idunn-rudp-health" => {
|
||||
idunn_rudp_health = Some(
|
||||
values
|
||||
.next()
|
||||
.context("missing --idunn-rudp-health value")?
|
||||
.parse()?,
|
||||
);
|
||||
}
|
||||
"--idunn-daemon" => {
|
||||
idunn_daemon = Some(values.next().context("missing --idunn-daemon value")?);
|
||||
}
|
||||
"--idunn-health-contract" => {
|
||||
idunn_health_contract = Some(
|
||||
values
|
||||
.next()
|
||||
.context("missing --idunn-health-contract value")?,
|
||||
);
|
||||
}
|
||||
other => anyhow::bail!("unknown argument {other:?}"),
|
||||
}
|
||||
}
|
||||
|
|
@ -3857,6 +4421,11 @@ impl Args {
|
|||
if !matches!(restart_mode.as_str(), "always" | "on-failure" | "never") {
|
||||
anyhow::bail!("--restart-mode must be always, on-failure, or never");
|
||||
}
|
||||
validate_idunn_health_options(
|
||||
idunn_rudp_health.as_ref(),
|
||||
idunn_daemon.as_deref(),
|
||||
idunn_health_contract.as_deref(),
|
||||
)?;
|
||||
|
||||
Ok(Self {
|
||||
command,
|
||||
|
|
@ -3903,6 +4472,35 @@ impl Args {
|
|||
task_restart_count,
|
||||
release_id,
|
||||
release_witness_sha256,
|
||||
idunn_rudp_health,
|
||||
idunn_daemon,
|
||||
idunn_health_contract,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn validate_idunn_health_options(
|
||||
endpoint: Option<&SocketAddr>,
|
||||
daemon_id: Option<&str>,
|
||||
health_contract: Option<&str>,
|
||||
) -> Result<()> {
|
||||
let fields = [
|
||||
endpoint.is_some(),
|
||||
daemon_id.is_some(),
|
||||
health_contract.is_some(),
|
||||
];
|
||||
if fields.into_iter().any(|present| present) && !fields.into_iter().all(|present| present) {
|
||||
anyhow::bail!(
|
||||
"--idunn-rudp-health, --idunn-daemon, and --idunn-health-contract are all-or-none"
|
||||
);
|
||||
}
|
||||
for (label, value) in [
|
||||
("--idunn-daemon", daemon_id),
|
||||
("--idunn-health-contract", health_contract),
|
||||
] {
|
||||
if value.is_some_and(|value| value.trim().is_empty()) {
|
||||
anyhow::bail!("{label} cannot be empty");
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -203,6 +203,9 @@ fn run(root: &Path) -> Result<()> {
|
|||
managed_policy_digest: policy_digest,
|
||||
provider_daemon_id: PROJECTOR.into(),
|
||||
startup_correlation_id: receipt_id.clone(),
|
||||
process_creation_token: 1,
|
||||
process_created_at_rfc3339: None,
|
||||
process_executable_path: projector.display().to_string(),
|
||||
},
|
||||
)?;
|
||||
let stdout = child
|
||||
|
|
|
|||
|
|
@ -2013,6 +2013,9 @@ fn run_cli() -> Result<()> {
|
|||
managed_policy_digest: String::new(),
|
||||
provider_daemon_id: String::new(),
|
||||
startup_correlation_id: String::new(),
|
||||
process_creation_token: 0,
|
||||
process_created_at_rfc3339: None,
|
||||
process_executable_path: String::new(),
|
||||
};
|
||||
let readiness_follow_up_row = receipt_directory_service_lifecycle_row(
|
||||
"cluster-service-lifecycle",
|
||||
|
|
@ -7988,6 +7991,9 @@ mod lifecycle_projection_tests {
|
|||
managed_policy_digest: String::new(),
|
||||
provider_daemon_id: String::new(),
|
||||
startup_correlation_id: String::new(),
|
||||
process_creation_token: 0,
|
||||
process_created_at_rfc3339: None,
|
||||
process_executable_path: String::new(),
|
||||
preflight_witness_id: String::new(),
|
||||
required_document_types: Vec::new(),
|
||||
schema_preflight_passed: false,
|
||||
|
|
|
|||
|
|
@ -268,10 +268,8 @@ pub fn append_modeling_repo_model_shape_context(
|
|||
));
|
||||
context.push_str("existingDomains:\n");
|
||||
for domain in &snapshot.domains {
|
||||
let profile = serde_json::to_string(&domain.profile)
|
||||
.map_err(|error| format!("failed to encode RepoModel domain profile: {error}"))?;
|
||||
let lifecycle = serde_json::to_string(&domain.lifecycle)
|
||||
.map_err(|error| format!("failed to encode RepoModel domain lifecycle: {error}"))?;
|
||||
let profile = debug_variant_snake_case(domain.profile);
|
||||
let lifecycle = debug_variant_snake_case(domain.lifecycle);
|
||||
context.push_str(&format!(
|
||||
"- id={} profile={} lifecycle={} title={}\n",
|
||||
domain.id, profile, lifecycle, domain.title
|
||||
|
|
@ -282,6 +280,18 @@ pub fn append_modeling_repo_model_shape_context(
|
|||
Ok(context)
|
||||
}
|
||||
|
||||
fn debug_variant_snake_case(value: impl std::fmt::Debug) -> String {
|
||||
let name = format!("{value:?}");
|
||||
let mut output = String::with_capacity(name.len() + 4);
|
||||
for (index, character) in name.chars().enumerate() {
|
||||
if character.is_ascii_uppercase() && index > 0 {
|
||||
output.push('_');
|
||||
}
|
||||
output.push(character.to_ascii_lowercase());
|
||||
}
|
||||
output
|
||||
}
|
||||
|
||||
pub fn append_modeling_work_loop_telemetry_context(
|
||||
mut context: String,
|
||||
runtime_store_path: &Path,
|
||||
|
|
|
|||
|
|
@ -164,7 +164,7 @@ pub const EPIPHANY_CULTMESH_DAEMON_SCHEDULER_RECEIPT_LATEST_KEY: &str =
|
|||
pub const EPIPHANY_CULTMESH_DAEMON_SERVICE_LIFECYCLE_RECEIPT_TYPE: &str =
|
||||
"epiphany.cultmesh.daemon_service_lifecycle_receipt";
|
||||
pub const EPIPHANY_CULTMESH_DAEMON_SERVICE_LIFECYCLE_RECEIPT_SCHEMA_VERSION: &str =
|
||||
"epiphany.cultmesh.daemon_service_lifecycle_receipt.v1";
|
||||
"epiphany.cultmesh.daemon_service_lifecycle_receipt.v2";
|
||||
pub const EPIPHANY_CULTMESH_DAEMON_SERVICE_LIFECYCLE_RECEIPT_LATEST_KEY: &str =
|
||||
"epiphany-local/daemon-service-lifecycle-receipt/latest";
|
||||
pub const EPIPHANY_CULTMESH_MANAGED_SERVICE_POLICY_TYPE: &str =
|
||||
|
|
@ -1480,6 +1480,12 @@ pub struct EpiphanyCultMeshDaemonServiceLifecycleReceiptEntry {
|
|||
pub provider_daemon_id: String,
|
||||
#[cultcache(key = 26, default)]
|
||||
pub startup_correlation_id: String,
|
||||
#[cultcache(key = 27, default)]
|
||||
pub process_creation_token: u64,
|
||||
#[cultcache(key = 28, default)]
|
||||
pub process_created_at_rfc3339: Option<String>,
|
||||
#[cultcache(key = 29, default)]
|
||||
pub process_executable_path: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, DatabaseEntry)]
|
||||
|
|
@ -5014,6 +5020,8 @@ fn validate_semantic_projector_launch_receipt(
|
|||
|| receipt.action != "launch"
|
||||
|| receipt.status != "launched"
|
||||
|| receipt.process_id.is_none()
|
||||
|| receipt.process_creation_token == 0
|
||||
|| receipt.process_executable_path.trim().is_empty()
|
||||
|| receipt.exit_code.is_some()
|
||||
|| receipt.completed_at_utc.is_none()
|
||||
|| !receipt.executable_sha256.starts_with("sha256-")
|
||||
|
|
@ -8243,6 +8251,9 @@ mod tests {
|
|||
managed_policy_digest: policy_digest,
|
||||
provider_daemon_id: "epiphany-memory-semantic-projector".into(),
|
||||
startup_correlation_id: "9f63fa72-a2e1-4ca5-9c1a-9292b7798891".into(),
|
||||
process_creation_token: 1,
|
||||
process_created_at_rfc3339: None,
|
||||
process_executable_path: "C:\\epiphany\\semantic-projector.exe".into(),
|
||||
};
|
||||
let written = write_epiphany_cultmesh_daemon_service_lifecycle_receipt(
|
||||
&store,
|
||||
|
|
@ -8382,6 +8393,9 @@ mod tests {
|
|||
managed_policy_digest: "sha256-dead-authority".into(),
|
||||
provider_daemon_id: EPIPHANY_WORKSPACE_COVERAGE_PROJECTOR_DAEMON_ID.into(),
|
||||
startup_correlation_id: receipt_id.into(),
|
||||
process_creation_token: 1,
|
||||
process_created_at_rfc3339: None,
|
||||
process_executable_path: "C:\\epiphany\\semantic-projector.exe".into(),
|
||||
};
|
||||
let mut wrong_provider = receipt.clone();
|
||||
wrong_provider.receipt_id = "f6d454dd-3765-44cb-930a-bae0d47487aa".into();
|
||||
|
|
@ -9000,6 +9014,9 @@ mod tests {
|
|||
managed_policy_digest: String::new(),
|
||||
provider_daemon_id: String::new(),
|
||||
startup_correlation_id: String::new(),
|
||||
process_creation_token: 0,
|
||||
process_created_at_rfc3339: None,
|
||||
process_executable_path: String::new(),
|
||||
};
|
||||
let mut second = first.clone();
|
||||
second.receipt_id = "service-lifecycle-second".to_string();
|
||||
|
|
@ -9162,6 +9179,9 @@ mod tests {
|
|||
managed_policy_digest: String::new(),
|
||||
provider_daemon_id: String::new(),
|
||||
startup_correlation_id: String::new(),
|
||||
process_creation_token: 0,
|
||||
process_created_at_rfc3339: None,
|
||||
process_executable_path: String::new(),
|
||||
};
|
||||
assert!(
|
||||
write_epiphany_cultmesh_daemon_service_lifecycle_receipt(
|
||||
|
|
@ -9224,6 +9244,9 @@ mod tests {
|
|||
managed_policy_digest: String::new(),
|
||||
provider_daemon_id: String::new(),
|
||||
startup_correlation_id: String::new(),
|
||||
process_creation_token: 0,
|
||||
process_created_at_rfc3339: None,
|
||||
process_executable_path: String::new(),
|
||||
},
|
||||
]);
|
||||
let runbook_check = report
|
||||
|
|
@ -11827,6 +11850,9 @@ mod tests {
|
|||
managed_policy_digest: policy_digest,
|
||||
provider_daemon_id: "epiphany-memory-semantic-projector".into(),
|
||||
startup_correlation_id: "f32666a9-94ce-47c5-b2bd-7d18624dfe9b".into(),
|
||||
process_creation_token: 1,
|
||||
process_created_at_rfc3339: None,
|
||||
process_executable_path: "C:\\epiphany\\semantic-projector.exe".into(),
|
||||
};
|
||||
write_epiphany_cultmesh_daemon_service_lifecycle_receipt(
|
||||
&verse,
|
||||
|
|
|
|||
287
epiphany-core/src/idunn_runtime_health.rs
Normal file
287
epiphany-core/src/idunn_runtime_health.rs
Normal file
|
|
@ -0,0 +1,287 @@
|
|||
use anyhow::{Context, Result, anyhow, bail};
|
||||
use cultnet_rs::{
|
||||
CultNetMessage, CultNetRawDocumentRecord, CultNetRawPayloadEncoding,
|
||||
CultNetRudpSocketTransportConnection, CultNetRudpSocketTransportOptions, CultNetWireContract,
|
||||
encode_cultnet_message_to_vec,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::net::{SocketAddr, UdpSocket};
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
pub const IDUNN_DAEMON_HEALTH_TYPE: &str = "idunn.daemon_health";
|
||||
pub const IDUNN_DAEMON_HEALTH_SCHEMA_VERSION: &str = "idunn.daemon_health.v1";
|
||||
pub const EPIPHANY_IDUNN_RUNTIME_HEALTH_CONTRACT: &str = "epiphany.cultnet-rudp-runtime-health";
|
||||
pub const CULTNET_RUDP_PROTOCOL_ID: &str = "cultnet.transport.rudp.v0";
|
||||
const IDUNN_HEALTH_RUDP_CONNECTION_ID: u32 = 0x4944_554e;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct IdunnDaemonHealthDocument {
|
||||
pub daemon_id: String,
|
||||
pub state: String,
|
||||
pub detail: String,
|
||||
pub observed_at: String,
|
||||
pub health_contract: String,
|
||||
pub publication_source: String,
|
||||
pub transport: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct EpiphanyAggregateRuntimeHealthInput {
|
||||
pub daemon_id: String,
|
||||
pub health_contract: String,
|
||||
pub observed_at: String,
|
||||
pub release_authenticated: bool,
|
||||
pub expected_service_count: usize,
|
||||
pub current_service_count: usize,
|
||||
pub contradictions: Vec<String>,
|
||||
}
|
||||
|
||||
pub fn derive_epiphany_aggregate_runtime_health(
|
||||
input: EpiphanyAggregateRuntimeHealthInput,
|
||||
) -> Result<IdunnDaemonHealthDocument> {
|
||||
require_id(&input.daemon_id, "Idunn daemon id")?;
|
||||
require_id(&input.health_contract, "Idunn health contract")?;
|
||||
require_id(&input.observed_at, "Idunn health observation time")?;
|
||||
if input.expected_service_count == 0 {
|
||||
bail!("aggregate runtime health requires at least one managed service");
|
||||
}
|
||||
if input.current_service_count > input.expected_service_count {
|
||||
bail!("current managed service count exceeds the expected service count");
|
||||
}
|
||||
|
||||
let (state, detail) = if !input.contradictions.is_empty() {
|
||||
(
|
||||
"failed",
|
||||
format!(
|
||||
"Epiphany runtime authority is contradictory: {}",
|
||||
input.contradictions.join("; ")
|
||||
),
|
||||
)
|
||||
} else if !input.release_authenticated {
|
||||
(
|
||||
"failed",
|
||||
"Epiphany packaged release authentication failed.".to_string(),
|
||||
)
|
||||
} else if input.current_service_count != input.expected_service_count {
|
||||
(
|
||||
"degraded",
|
||||
format!(
|
||||
"Epiphany is reconciling managed services: {}/{} have current authenticated lineage.",
|
||||
input.current_service_count, input.expected_service_count
|
||||
),
|
||||
)
|
||||
} else {
|
||||
(
|
||||
"active",
|
||||
format!(
|
||||
"Epiphany packaged release and all {} managed services have current authenticated lineage.",
|
||||
input.expected_service_count
|
||||
),
|
||||
)
|
||||
};
|
||||
|
||||
Ok(IdunnDaemonHealthDocument {
|
||||
daemon_id: input.daemon_id,
|
||||
state: state.to_string(),
|
||||
detail,
|
||||
observed_at: input.observed_at,
|
||||
health_contract: input.health_contract,
|
||||
publication_source: "daemon-published".to_string(),
|
||||
transport: CULTNET_RUDP_PROTOCOL_ID.to_string(),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn publish_idunn_daemon_health_rudp(
|
||||
endpoint: SocketAddr,
|
||||
source_runtime_id: &str,
|
||||
health: &IdunnDaemonHealthDocument,
|
||||
) -> Result<()> {
|
||||
validate_health_document(health)?;
|
||||
require_id(source_runtime_id, "health publisher runtime id")?;
|
||||
let message = CultNetMessage::DocumentPutRaw {
|
||||
message_id: format!(
|
||||
"epiphany-health:{}:{}",
|
||||
health.daemon_id,
|
||||
health.observed_at.replace(':', "-")
|
||||
),
|
||||
document: CultNetRawDocumentRecord {
|
||||
schema_id: IDUNN_DAEMON_HEALTH_TYPE.to_string(),
|
||||
record_key: health.daemon_id.clone(),
|
||||
stored_at: health.observed_at.clone(),
|
||||
payload_encoding: CultNetRawPayloadEncoding::Messagepack,
|
||||
payload: rmp_serde::to_vec(health).context("encoding Idunn daemon health")?,
|
||||
source_runtime_id: Some(source_runtime_id.to_string()),
|
||||
source_agent_id: None,
|
||||
source_role: Some("daemon-health-publisher".to_string()),
|
||||
tags: Some(vec![CULTNET_RUDP_PROTOCOL_ID.to_string()]),
|
||||
},
|
||||
};
|
||||
let bind = if endpoint.is_ipv4() {
|
||||
"0.0.0.0:0"
|
||||
} else {
|
||||
"[::]:0"
|
||||
};
|
||||
let socket = UdpSocket::bind(bind)
|
||||
.with_context(|| format!("binding Epiphany Idunn RUDP sender at {bind}"))?;
|
||||
socket.set_read_timeout(Some(Duration::from_millis(100)))?;
|
||||
let mut transport =
|
||||
CultNetRudpSocketTransportConnection::new(CultNetRudpSocketTransportOptions::client(
|
||||
source_runtime_id,
|
||||
socket,
|
||||
endpoint,
|
||||
IDUNN_HEALTH_RUDP_CONNECTION_ID,
|
||||
))?;
|
||||
transport.connect(Vec::new())?;
|
||||
let deadline = Instant::now() + Duration::from_millis(500);
|
||||
while !transport.connected() {
|
||||
let _ = transport.receive_once()?;
|
||||
transport.poll_resends()?;
|
||||
if Instant::now() >= deadline {
|
||||
return Err(anyhow!(
|
||||
"timed out connecting Epiphany health publisher to {endpoint}"
|
||||
));
|
||||
}
|
||||
}
|
||||
let payload = encode_cultnet_message_to_vec(&message, CultNetWireContract::CultNetSchemaV0)
|
||||
.context("encoding Idunn health CultNet message")?;
|
||||
transport
|
||||
.send("schema", payload)
|
||||
.with_context(|| format!("sending Epiphany Idunn health to {endpoint}"))
|
||||
}
|
||||
|
||||
fn validate_health_document(health: &IdunnDaemonHealthDocument) -> Result<()> {
|
||||
require_id(&health.daemon_id, "Idunn daemon id")?;
|
||||
require_id(&health.health_contract, "Idunn health contract")?;
|
||||
require_id(&health.observed_at, "Idunn health observation time")?;
|
||||
if !matches!(health.state.as_str(), "active" | "degraded" | "failed") {
|
||||
bail!("unsupported Idunn daemon health state");
|
||||
}
|
||||
if health.publication_source != "daemon-published"
|
||||
|| health.transport != CULTNET_RUDP_PROTOCOL_ID
|
||||
{
|
||||
bail!("Idunn daemon health publication authority is invalid");
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn require_id(value: &str, label: &str) -> Result<()> {
|
||||
if value.trim().is_empty() {
|
||||
bail!("{label} is required");
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use cultnet_rs::decode_cultnet_message_from_slice;
|
||||
use std::thread;
|
||||
|
||||
fn input(current: usize) -> EpiphanyAggregateRuntimeHealthInput {
|
||||
EpiphanyAggregateRuntimeHealthInput {
|
||||
daemon_id: "yggdrasil-epiphany".into(),
|
||||
health_contract: EPIPHANY_IDUNN_RUNTIME_HEALTH_CONTRACT.into(),
|
||||
observed_at: "2026-07-16T00:00:00Z".into(),
|
||||
release_authenticated: true,
|
||||
expected_service_count: 2,
|
||||
current_service_count: current,
|
||||
contradictions: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn aggregate_health_requires_every_current_lineage() {
|
||||
assert_eq!(
|
||||
derive_epiphany_aggregate_runtime_health(input(2))
|
||||
.unwrap()
|
||||
.state,
|
||||
"active"
|
||||
);
|
||||
assert_eq!(
|
||||
derive_epiphany_aggregate_runtime_health(input(1))
|
||||
.unwrap()
|
||||
.state,
|
||||
"degraded"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn aggregate_health_fails_authenticated_contradictions() {
|
||||
let mut value = input(2);
|
||||
value
|
||||
.contradictions
|
||||
.push("semantic child uses stale policy".into());
|
||||
let health = derive_epiphany_aggregate_runtime_health(value).unwrap();
|
||||
assert_eq!(health.state, "failed");
|
||||
assert!(health.detail.contains("stale policy"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn semantic_sight_cannot_substitute_for_runtime_lineage() {
|
||||
let health = derive_epiphany_aggregate_runtime_health(input(0)).unwrap();
|
||||
assert_ne!(health.state, "active");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn health_document_rejects_alien_publication_authority() {
|
||||
let mut health = derive_epiphany_aggregate_runtime_health(input(2)).unwrap();
|
||||
health.publication_source = "probe".into();
|
||||
assert!(validate_health_document(&health).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rudp_publisher_emits_exact_messagepack_health_document() {
|
||||
let socket = UdpSocket::bind("127.0.0.1:0").unwrap();
|
||||
socket
|
||||
.set_read_timeout(Some(Duration::from_millis(100)))
|
||||
.unwrap();
|
||||
let endpoint = socket.local_addr().unwrap();
|
||||
let server = thread::spawn(move || {
|
||||
let mut transport = CultNetRudpSocketTransportConnection::new(
|
||||
CultNetRudpSocketTransportOptions::server(
|
||||
"idunn-test",
|
||||
socket,
|
||||
IDUNN_HEALTH_RUDP_CONNECTION_ID,
|
||||
),
|
||||
)
|
||||
.unwrap();
|
||||
let deadline = Instant::now() + Duration::from_secs(2);
|
||||
loop {
|
||||
if let Some(frame) = transport.receive_once().unwrap() {
|
||||
return decode_cultnet_message_from_slice(
|
||||
&frame.payload,
|
||||
CultNetWireContract::CultNetSchemaV0,
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
transport.poll_resends().unwrap();
|
||||
assert!(Instant::now() < deadline, "health frame timed out");
|
||||
}
|
||||
});
|
||||
let health = derive_epiphany_aggregate_runtime_health(input(2)).unwrap();
|
||||
publish_idunn_daemon_health_rudp(endpoint, "epiphany-daemon-supervisor", &health).unwrap();
|
||||
let CultNetMessage::DocumentPutRaw { document, .. } = server.join().unwrap() else {
|
||||
panic!("publisher emitted a non-document message")
|
||||
};
|
||||
assert_eq!(document.schema_id, IDUNN_DAEMON_HEALTH_TYPE);
|
||||
assert_eq!(document.record_key, health.daemon_id);
|
||||
assert_eq!(
|
||||
document.payload_encoding,
|
||||
CultNetRawPayloadEncoding::Messagepack
|
||||
);
|
||||
let decoded: IdunnDaemonHealthDocument = rmp_serde::from_slice(&document.payload).unwrap();
|
||||
assert_eq!(decoded, health);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rudp_publisher_fails_closed_when_idunn_does_not_accept() {
|
||||
let reserved = UdpSocket::bind("127.0.0.1:0").unwrap();
|
||||
let endpoint = reserved.local_addr().unwrap();
|
||||
drop(reserved);
|
||||
let health = derive_epiphany_aggregate_runtime_health(input(2)).unwrap();
|
||||
assert!(
|
||||
publish_idunn_daemon_health_rudp(endpoint, "epiphany-daemon-supervisor", &health,)
|
||||
.is_err()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -17,6 +17,7 @@ mod eyes_gateway;
|
|||
mod hands_gateway;
|
||||
mod heartbeat_state;
|
||||
mod host_identity;
|
||||
mod idunn_runtime_health;
|
||||
mod memory_graph;
|
||||
mod mind_gateway;
|
||||
mod organ_dependencies;
|
||||
|
|
@ -47,6 +48,12 @@ mod workspace_coverage_projector_service;
|
|||
mod workspace_retrieval_coverage;
|
||||
|
||||
pub use agent_launch::EPIPHANY_IMAGINATION_OWNER_ROLE;
|
||||
pub use idunn_runtime_health::{
|
||||
CULTNET_RUDP_PROTOCOL_ID, EPIPHANY_IDUNN_RUNTIME_HEALTH_CONTRACT,
|
||||
EpiphanyAggregateRuntimeHealthInput, IDUNN_DAEMON_HEALTH_SCHEMA_VERSION,
|
||||
IDUNN_DAEMON_HEALTH_TYPE, IdunnDaemonHealthDocument,
|
||||
derive_epiphany_aggregate_runtime_health, publish_idunn_daemon_health_rudp,
|
||||
};
|
||||
pub use agent_launch::EPIPHANY_IMAGINATION_ROLE_BINDING_ID;
|
||||
pub use agent_launch::EPIPHANY_MIND_OWNER_ROLE;
|
||||
pub use agent_launch::EPIPHANY_MIND_ROLE_BINDING_ID;
|
||||
|
|
|
|||
|
|
@ -2137,3 +2137,56 @@ two existing live tests remain intentionally ignored. Next: commit/push the
|
|||
CultCache submodule and parent changes, package a new witnessed release, deploy
|
||||
it, then derive the first live whole-repository projection. Reboot/logon remains
|
||||
permission-bound and requires explicit live operator approval.
|
||||
|
||||
## Yggdrasil live-deployment authority map (2026-07-16)
|
||||
|
||||
Live Epiphany deployment proof belongs on new Yggdrasil, not Starfire. The live
|
||||
host already runs Idunn (`idunn-yggdrasil.service`), Bifrost, Odin/Hermodr,
|
||||
Qdrant, and GPU-backed Ollama locally. Epiphany is not yet deployable there:
|
||||
there is no Epiphany Idunn target, ops manifest/unit, immutable release body, or
|
||||
daemon-owned aggregate `idunn.daemon_health.v1` publication.
|
||||
|
||||
Two ownership gaps must close before the target is enabled. Epiphany's semantic
|
||||
projection health is component sight and cannot stand in for whole-runtime
|
||||
health; the managed-service supervisor must join the authenticated packaged
|
||||
release with current semantic and workspace-coverage child lineage and publish
|
||||
one explicit CultNet/RUDP health contract. Separately, Bifrost's real GitHub
|
||||
crossing receipts are not consumed by Idunn: Idunn currently observes
|
||||
`origin/main` as desired revision without proving that Bifrost authorized that
|
||||
exact commit. The new chain is Bifrost exact repository/ref/SHA authority ->
|
||||
Idunn frozen deployment request/artifact -> guarded ops actuator -> immutable
|
||||
release and deployed manifest -> daemon-published runtime health. Branch
|
||||
movement, actuator environment variables, process liveness, and component
|
||||
health are forbidden substitutes.
|
||||
|
||||
The intended Ygg body uses `/srv/build/Epiphany` as Idunn's mutable upstream
|
||||
clone, immutable application releases below `/srv/epiphany/app/releases`, an
|
||||
immutable deployed source Body below `/srv/epiphany/source/releases`, canonical
|
||||
state below `/var/lib/gamecult/epiphany`, local Qdrant at `127.0.0.1:6333`, and
|
||||
local Ollama at `127.0.0.1:11434`. Actual publication must cross live Bifrost;
|
||||
actual deployment must be requested through live Idunn. Manual SSH deployment
|
||||
is not acceptable evidence. No host reboot is authorized.
|
||||
|
||||
Source implementation now closes the Epiphany-owned half. The managed-service
|
||||
supervisor publishes exact `idunn.daemon_health.v1` over CultNet/RUDP only
|
||||
after joining the authenticated packaged release with the exact two reserved
|
||||
projectors. Semantic and workspace lineage require current policy, the exact
|
||||
packaged executable, launch-time process incarnation, correlated ready
|
||||
heartbeat, and bounded freshness. Proven stale v2 lineage may be replaced only
|
||||
through its persisted process identity; authentication uncertainty cannot kill.
|
||||
Legacy v1 lifecycle receipts are read-only and enter a typed non-killing
|
||||
retirement path before a v2 launch. Full library verification is 475 passed,
|
||||
2 intentional live-endpoint ignores.
|
||||
|
||||
The adjacent source bodies are also prepared. Bifrost main commit `3bd250f`
|
||||
publishes `bifrost.repository_release_authority.v1`, binds one canonical
|
||||
repository/ref/SHA to a completed crossing receipt and exact GitHub proof, and
|
||||
forbids simultaneous live authorities for the same ref. Odin's Ygg worktree
|
||||
adds a scoped `yggdrasil-epiphany` target, selects the unique live Bifrost
|
||||
authority rather than branch head, freezes it through deployment request and
|
||||
artifact state, and revalidates at the privileged actuator boundary. The ops
|
||||
body builds exact initialized source through a separate builder identity,
|
||||
root-seals immutable source/application releases, starts Epiphany against
|
||||
Ygg-local Qdrant and Ollama, requires post-candidate Idunn RUDP acceptance, and
|
||||
only then publishes the v2 deployment witness. These source bodies are not yet
|
||||
live on Ygg; bootstrap and deployment remain the next phase.
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -737,4 +737,4 @@ current_status:
|
|||
- The 2026-07-16 deployability audit replaced `notes/epiphany-swarm-readiness-plan.md`'s obsolete June queue with the live evidence matrix. Brake, initiative recovery, Persona speech eligibility, memory lifecycle, CultNet-first operation, and branch-local Hands/Soul/Mind gates are landed. The installed after-login host is operational and real Mind/Modeling semantic queries pass against Yggdrasil, but it is not yet deployable as one proven machine: installed binaries predate recovery commit `34802407`; mutable sibling lookup permits mixed build generations; Mind lacks the race-bounded whole-repository readiness join; and reboot/logon lineage remains permission-bound. Health, heartbeat, Task Scheduler state, Qdrant existence, legacy retrieval Ready, and Eve/Gjallar rows cannot substitute for either query admission or repository readiness. Sight surfaces no longer publish the foreign constant `queryAdmission=false`; they report only facts they observe.
|
||||
- Release `sha256-c94109f94ee42c1257089830f399cb87cd5ad672772c274194371995ce4df923` is the first deployed immutable sibling generation. Native packaging builds from detached exact source commit `dd80f4a51c18425a6665710698a357be61154abf`, initializes pinned submodules, uses the tracked lockfile under `--locked`, and publishes four exact binaries plus a typed CultCache witness/head only after atomic directory publication and byte verification. Task Scheduler pins release id/digest and the witnessed supervisor path; Idunn reauthenticates the complete set and reserved policy role paths. Current-boot proof: reconciler PID 21228 launched direct child 22736; witnessed Mind/Modeling queries ranked semantically; killing that exact-path child caused Idunn to launch PID 19748 with receipt `86a42d51-9930-4b5d-9e61-e74c82a0d808`, ready heartbeat `4fc91977-b635-474b-812b-c364847e2b4b`, and witnessed executable digest `sha256-1060dd64e8c2b520ec8744b67e8306db04a6618d463fc2117c352adf9e30e6b0`. This closes current-boot artifact generation and recurrence, not reboot/logon survival.
|
||||
- Release `sha256-6f9ab4848207a110e7e3836f41e6a74c0f463369ad4b04ce2d0d3831a6b262ae` packages repository-readiness source commit `360dcb433dda9599fca14282592608d26b8b6cc8`; witnessed Idunn PID 29476 directly owns witnessed projector PID 22840 with launch receipt `50879209-b65f-4411-ae3f-6f647d37bf42` and ready heartbeat `134df620-9e20-4220-ad4e-117ea4ca8188`. Deployment exposed receipt-v2 migration pressure: v1 receipts became correctly ineligible, but the old Succeeded pulse shortcut kept both partitions idle. The shortcut is now cut in source. Valid v2 terminal evidence derives Ready; an exact same-obligation succeeded claim opens Repair only after its consumed grant/recovery authority and exact succeeded attempt are authenticated. Failed repair retries through execute at the next epoch. Forged predecessor authority cannot be laundered by a repair grant.
|
||||
next_action: Commit and package the authenticated semantic receipt-v2 repair, deploy the successor witnessed release, prove Mind/Modeling semantic ranking, then derive the first live Mind repository-readiness projection. Also repair Idunn's alive-child reconciliation so policy/release path drift forces typed replacement instead of requiring an operator exact-PID termination. Do not run the final reboot/logon proof without explicit live operator approval.
|
||||
next_action: Build the first live deployment only on Yggdrasil. Close the authority chain in order: Epiphany supervisor publishes aggregate daemon-owned Idunn RUDP health and replaces stale child lineage; Bifrost emits exact repository/ref/commit release authority; Idunn validates and freezes that authority before either automatic or manual deployment; gamecult-ops installs the immutable Epiphany release/state/service body and deployed-revision witness. Then publish through Bifrost, request deployment through Idunn, and prove local Ygg Body, Mind, Qdrant, Ollama, health, and deployment receipts. Local Starfire execution is development-only. Do not reboot any host without explicit live operator approval.
|
||||
|
|
|
|||
Reference in a new issue