diff --git a/epiphany-core/src/bin/epiphany-daemon-supervisor.rs b/epiphany-core/src/bin/epiphany-daemon-supervisor.rs index 0071ceae..ae3b2cea 100644 --- a/epiphany-core/src/bin/epiphany-daemon-supervisor.rs +++ b/epiphany-core/src/bin/epiphany-daemon-supervisor.rs @@ -8,27 +8,17 @@ use cultnet_rs::{ export_service_identity_trust_anchor, open_service_identity_at, }; use ed25519_dalek::SigningKey; -use epiphany_core::EPIPHANY_CULTMESH_DAEMON_RESTART_POLICY_SCHEMA_VERSION; -use epiphany_core::EPIPHANY_CULTMESH_DAEMON_SCHEDULER_RECEIPT_SCHEMA_VERSION; use epiphany_core::EPIPHANY_CULTMESH_DAEMON_SERVICE_LIFECYCLE_RECEIPT_SCHEMA_VERSION; use epiphany_core::EPIPHANY_CULTMESH_MANAGED_SERVICE_POLICY_SCHEMA_VERSION; -use epiphany_core::EpiphanyCultMeshDaemonRestartPolicyEntry; -use epiphany_core::EpiphanyCultMeshDaemonSchedulerReceiptEntry; use epiphany_core::EpiphanyCultMeshDaemonServiceLifecycleReceiptEntry; -use epiphany_core::EpiphanyCultMeshDaemonStatusEntry; use epiphany_core::EpiphanyCultMeshManagedServicePolicyEntry; use epiphany_core::EpiphanyCultMeshSwarmBrakeEntry; -use epiphany_core::EpiphanyLocalVerseContext; use epiphany_core::EpiphanyProcessObservation as ProcessObservation; use epiphany_core::authenticate_epiphany_cultmesh_semantic_projector_launch; use epiphany_core::authenticate_resident_provider; -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; use epiphany_core::load_epiphany_cultmesh_cluster_topology; -use epiphany_core::load_epiphany_cultmesh_daemon_restart_policy; use epiphany_core::load_epiphany_cultmesh_daemon_service_lifecycle_receipts; -use epiphany_core::load_epiphany_cultmesh_daemon_status; use epiphany_core::load_epiphany_cultmesh_managed_service_policies; use epiphany_core::load_epiphany_cultmesh_managed_service_policy; use epiphany_core::load_epiphany_cultmesh_managed_service_policy_with_digest; @@ -37,12 +27,7 @@ use epiphany_core::load_epiphany_packaged_release; use epiphany_core::load_latest_epiphany_cultmesh_daemon_heartbeat; use epiphany_core::load_latest_epiphany_cultmesh_daemon_service_lifecycle_receipt_for_service; use epiphany_core::observe_native_process as observe_process; -use epiphany_core::query_epiphany_local_verse_context; use epiphany_core::runtime_modeling_semantic_projection_input; -use epiphany_core::write_epiphany_cultmesh_daemon_poke_intent; -use epiphany_core::write_epiphany_cultmesh_daemon_poke_receipt; -use epiphany_core::write_epiphany_cultmesh_daemon_restart_policy; -use epiphany_core::write_epiphany_cultmesh_daemon_scheduler_receipt; use epiphany_core::write_epiphany_cultmesh_daemon_service_lifecycle_receipt; use epiphany_core::write_epiphany_cultmesh_semantic_projector_service_policy; use epiphany_core::write_epiphany_cultmesh_workspace_coverage_projector_service_policy; @@ -174,9 +159,6 @@ fn main() -> Result<()> { fn dispatch(args: Args) -> Result<()> { match args.command.as_str() { - "reconcile" | "poke" | "restart" => reconcile(args), - "tick" | "schedule" | "reconcile-all" => tick(args), - "serve" | "loop" | "daemon" => serve(args), "managed-service-serve" | "service-desired-state-serve" => managed_service_serve(args), "managed-service-task-plan" => managed_service_task_install(args, false), "managed-service-task-install" => managed_service_task_install(args, true), @@ -221,10 +203,9 @@ fn dispatch(args: Args) -> Result<()> { | "service-start" | "windows-service-stop" | "service-stop" => refuse_false_windows_scm_authority(), - "policy" | "write-policy" => write_policy(args), "semantic-recover" => semantic_recover(args), other => anyhow::bail!( - "unknown command {other:?}; use reconcile, tick, serve, managed-service-serve, managed-service-task-plan/install/status/start/stop/uninstall, service-plan, service-launch, service-runbook, managed-service-policy, semantic-projector-service-policy, policy, or semantic-recover" + "unknown command {other:?}; use managed-service-serve, managed-service-task-plan/install/status/start/stop/uninstall, service-plan, service-launch, service-runbook, managed-service-policy, semantic-projector-service-policy, workspace-coverage-projector-service-policy, or semantic-recover" ), } } @@ -743,72 +724,6 @@ fn require_supervisor_bootstrap(args: &Args) -> Result<()> { Ok(()) } -fn reconcile(args: Args) -> Result<()> { - require_supervisor_bootstrap(&args)?; - - let daemon_status = load_epiphany_cultmesh_daemon_status( - &args.store, - args.runtime_id.clone(), - &args.daemon_id, - )? - .with_context(|| format!("local Verse has no daemon status for {:?}", args.daemon_id))?; - let brake = load_epiphany_cultmesh_swarm_brake(&args.store, args.runtime_id.clone())?; - - let mut policy = load_policy_or_override(&args, &daemon_status)?; - let output = reconcile_daemon_status( - &args, - brake.as_ref(), - &daemon_status, - &mut policy, - args.force, - false, - false, - )?; - println!("{}", serde_json::to_string_pretty(&output)?); - Ok(()) -} - -fn tick(args: Args) -> Result<()> { - let output = run_tick(&args, 0, None)?; - println!("{}", serde_json::to_string_pretty(&output)?); - Ok(()) -} - -fn serve(args: Args) -> Result<()> { - let mut outputs = Vec::new(); - let mut iteration = 0_u64; - loop { - iteration = iteration.saturating_add(1); - let next_wake = if args.max_iterations == 0 || iteration < args.max_iterations { - Some((Utc::now() + Duration::seconds(args.loop_interval_seconds)).to_rfc3339()) - } else { - None - }; - let output = run_tick(&args, iteration, next_wake)?; - outputs.push(output); - if args.max_iterations != 0 && iteration >= args.max_iterations { - break; - } - std::thread::sleep(std::time::Duration::from_secs( - args.loop_interval_seconds.max(0) as u64, - )); - } - println!( - "{}", - serde_json::to_string_pretty(&json!({ - "status": "serveComplete", - "store": args.store, - "runtimeId": args.runtime_id, - "daemonId": args.daemon_id, - "schedulerId": args.scheduler_id, - "iterations": iteration, - "outputs": outputs, - "privateStateExposed": false, - }))? - ); - Ok(()) -} - fn managed_service_serve(args: Args) -> Result<()> { let (release, _) = pinned_packaged_release(&args, true)?; let expected_supervisor = fs::canonicalize(epiphany_packaged_release_binary_path( @@ -3014,532 +2929,6 @@ fn local_file_sha256(path: &str) -> Option { let digest = Sha256::digest(&bytes); Some(format!("{digest:x}")) } -fn run_tick(args: &Args, iteration: u64, next_wake_utc: Option) -> Result { - let tick_started = Utc::now(); - - require_supervisor_bootstrap(&args)?; - - let context = query_epiphany_local_verse_context(&args.store, args.runtime_id.clone())?; - assert_swarm_brake_allows_scheduler_tick(&context)?; - - let now = Utc::now(); - let mut outcomes = Vec::new(); - let requested_daemon = args.daemon_id.as_str(); - let policies: Vec<_> = context - .daemon_restart_policies - .clone() - .into_iter() - .filter(|policy| requested_daemon == "*" || policy.daemon_id == requested_daemon) - .collect(); - if policies.is_empty() { - anyhow::bail!( - "local Verse has no daemon restart policies matching {:?}", - requested_daemon - ); - } - - for mut policy in policies { - let Some(status) = context - .daemon_statuses - .iter() - .find(|status| status.daemon_id == policy.daemon_id) - .cloned() - else { - outcomes.push(json!({ - "status": "missingStatus", - "policyId": policy.policy_id, - "daemonId": policy.daemon_id, - "privateStateExposed": false, - })); - continue; - }; - if !policy.enabled { - outcomes.push(json!({ - "status": "skipped", - "reason": "policy disabled", - "policyId": policy.policy_id, - "daemonId": policy.daemon_id, - "privateStateExposed": false, - })); - continue; - } - if !reconcile_interval_elapsed(&policy, now)? { - outcomes.push(json!({ - "status": "skipped", - "reason": "reconcile interval not elapsed", - "policyId": policy.policy_id, - "daemonId": policy.daemon_id, - "lastReconcileUtc": policy.last_reconcile_utc, - "privateStateExposed": false, - })); - continue; - } - - let scheduled_status = status; - let heartbeat_stale = daemon_heartbeat_is_stale(&scheduled_status, &policy, now)?; - let mut forced = args.force; - if heartbeat_stale { - forced = true; - } - - match reconcile_daemon_status( - &args, - context.swarm_brake.as_ref(), - &scheduled_status, - &mut policy, - forced, - true, - heartbeat_stale, - ) { - Ok(output) => outcomes.push(output), - Err(error) => outcomes.push(json!({ - "status": "refused", - "reason": error.to_string(), - "policyId": policy.policy_id, - "daemonId": policy.daemon_id, - "privateStateExposed": false, - })), - } - } - - let outcome_count = outcomes.len() as u32; - let restarted_count = count_outcomes(&outcomes, "awaiting-provider-heartbeat"); - let refused_count = count_outcomes(&outcomes, "refused"); - let skipped_count = count_outcomes(&outcomes, "skipped"); - let tick_completed = Utc::now(); - let receipt_id = format!( - "daemon-scheduler-receipt-{}-{}", - sanitize_id(&args.scheduler_id), - iteration - ); - let receipt = EpiphanyCultMeshDaemonSchedulerReceiptEntry { - schema_version: EPIPHANY_CULTMESH_DAEMON_SCHEDULER_RECEIPT_SCHEMA_VERSION.to_string(), - receipt_id, - scheduler_id: args.scheduler_id.clone(), - runtime_id: args.runtime_id.clone(), - daemon_selector: args.daemon_id.clone(), - iteration, - status: "tickComplete".to_string(), - tick_started_utc: tick_started.to_rfc3339(), - tick_completed_utc: tick_completed.to_rfc3339(), - next_wake_utc, - outcome_count, - restarted_count, - refused_count, - skipped_count, - private_state_exposed: false, - notes: vec![ - "Daemon scheduler receipt records one explicit supervisor pulse without exposing private daemon state." - .to_string(), - "Daemon restart decisions remain owned by durable restart policy, liveness status, swarm brake, and cooldown gates." - .to_string(), - ], - }; - let written_receipt = write_epiphany_cultmesh_daemon_scheduler_receipt( - &args.store, - args.runtime_id.clone(), - receipt, - )?; - - Ok(json!({ - "status": "tickComplete", - "store": args.store, - "runtimeId": args.runtime_id, - "daemonId": args.daemon_id, - "schedulerId": args.scheduler_id, - "iteration": iteration, - "schedulerReceiptId": written_receipt.receipt_id, - "outcomeCount": written_receipt.outcome_count, - "restartedCount": written_receipt.restarted_count, - "refusedCount": written_receipt.refused_count, - "skippedCount": written_receipt.skipped_count, - "nextWakeUtc": written_receipt.next_wake_utc, - "outcomes": outcomes, - "privateStateExposed": written_receipt.private_state_exposed, - })) -} - -fn write_policy(args: Args) -> Result<()> { - require_supervisor_bootstrap(&args)?; - - let daemon_status = load_epiphany_cultmesh_daemon_status( - &args.store, - args.runtime_id.clone(), - &args.daemon_id, - )? - .with_context(|| format!("local Verse has no daemon status for {:?}", args.daemon_id))?; - let command = args - .restart_command - .clone() - .context("policy requires --restart-command")?; - let policy = EpiphanyCultMeshDaemonRestartPolicyEntry { - schema_version: EPIPHANY_CULTMESH_DAEMON_RESTART_POLICY_SCHEMA_VERSION.to_string(), - policy_id: args - .policy_id - .clone() - .unwrap_or_else(|| format!("daemon-restart-policy-{}", sanitize_id(&daemon_status.daemon_id))), - daemon_id: daemon_status.daemon_id.clone(), - cluster_id: daemon_status.cluster_id.clone(), - restart_command: command.display().to_string(), - restart_args: args.restart_args.clone(), - cwd: args.cwd.as_ref().map(|path| path.display().to_string()), - cooldown_seconds: args.cooldown_seconds, - backoff_multiplier: args.backoff_multiplier, - failure_count: 0, - last_attempt_utc: None, - last_result_status: "never-attempted".to_string(), - enabled: !args.disabled, - private_state_exposed: false, - notes: vec![ - "Daemon restart policy is local Verse process-control state, not private daemon memory." - .to_string(), - "Supervisor reconciles this policy through typed daemon poke receipts and liveness status." - .to_string(), - ], - reconcile_interval_seconds: args.reconcile_interval_seconds, - heartbeat_stale_seconds: args.heartbeat_stale_seconds, - last_reconcile_utc: None, - }; - let written = write_epiphany_cultmesh_daemon_restart_policy( - &args.store, - args.runtime_id.clone(), - policy, - )?; - println!( - "{}", - serde_json::to_string_pretty(&json!({ - "status": "written", - "store": args.store, - "runtimeId": args.runtime_id, - "policyId": written.policy_id, - "daemonId": written.daemon_id, - "clusterId": written.cluster_id, - "enabled": written.enabled, - "cooldownSeconds": written.cooldown_seconds, - "backoffMultiplier": written.backoff_multiplier, - "reconcileIntervalSeconds": written.reconcile_interval_seconds, - "heartbeatStaleSeconds": written.heartbeat_stale_seconds, - "privateStateExposed": written.private_state_exposed, - }))? - ); - Ok(()) -} - -fn load_policy_or_override( - args: &Args, - daemon_status: &EpiphanyCultMeshDaemonStatusEntry, -) -> Result { - if let Some(command) = args.restart_command.as_ref() { - return Ok(EpiphanyCultMeshDaemonRestartPolicyEntry { - schema_version: EPIPHANY_CULTMESH_DAEMON_RESTART_POLICY_SCHEMA_VERSION.to_string(), - policy_id: args - .policy_id - .clone() - .unwrap_or_else(|| format!("daemon-restart-policy-{}", sanitize_id(&daemon_status.daemon_id))), - daemon_id: daemon_status.daemon_id.clone(), - cluster_id: daemon_status.cluster_id.clone(), - restart_command: command.display().to_string(), - restart_args: args.restart_args.clone(), - cwd: args.cwd.as_ref().map(|path| path.display().to_string()), - cooldown_seconds: args.cooldown_seconds, - backoff_multiplier: args.backoff_multiplier, - failure_count: 0, - last_attempt_utc: None, - last_result_status: "operator-override".to_string(), - enabled: true, - private_state_exposed: false, - notes: vec![ - "Operator supplied this restart command directly; write a daemon restart policy for durable unattended use." - .to_string(), - ], - reconcile_interval_seconds: args.reconcile_interval_seconds, - heartbeat_stale_seconds: args.heartbeat_stale_seconds, - last_reconcile_utc: None, - }); - } - load_epiphany_cultmesh_daemon_restart_policy( - &args.store, - args.runtime_id.clone(), - &daemon_status.daemon_id, - )? - .with_context(|| { - format!( - "daemon {} has no restart policy; use policy --restart-command or pass --restart-command explicitly", - daemon_status.daemon_id - ) - }) -} - -fn reconcile_daemon_status( - args: &Args, - brake: Option<&EpiphanyCultMeshSwarmBrakeEntry>, - daemon_status: &EpiphanyCultMeshDaemonStatusEntry, - policy: &mut EpiphanyCultMeshDaemonRestartPolicyEntry, - force: bool, - scheduled: bool, - observed_heartbeat_stale: bool, -) -> Result { - assert_swarm_brake_allows_daemon_poke(brake, daemon_status)?; - let now = Utc::now(); - let needs_restart = force || daemon_status.status != "ready"; - if !needs_restart { - let provider_proved_recovery = - provider_heartbeat_follows_last_attempt(daemon_status, policy)?; - policy.last_reconcile_utc = Some(now.to_rfc3339()); - if provider_proved_recovery { - policy.failure_count = 0; - policy.last_result_status = "provider-heartbeat-recovered".to_string(); - } else { - policy.last_result_status = "awaiting-provider-heartbeat".to_string(); - } - let written_policy = write_epiphany_cultmesh_daemon_restart_policy( - &args.store, - args.runtime_id.clone(), - policy.clone(), - )?; - return Ok(json!({ - "status": "noop", - "reason": "daemon already ready", - "store": args.store, - "runtimeId": args.runtime_id, - "daemonId": daemon_status.daemon_id, - "daemonStatus": daemon_status.status, - "providerHeartbeatProvedRecovery": provider_proved_recovery, - "policyId": written_policy.policy_id, - "scheduled": scheduled, - "lastReconcileUtc": written_policy.last_reconcile_utc, - "privateStateExposed": false, - })); - } - assert_policy_allows_attempt(policy, now)?; - - let mut reason = args.reason.clone().unwrap_or_else(|| { - if scheduled { - format!( - "Scheduled supervisor reconciliation requested for {} after status {}.", - daemon_status.daemon_id, daemon_status.status - ) - } else { - format!( - "Supervisor restart requested for {} after status {}.", - daemon_status.daemon_id, daemon_status.status - ) - } - }); - if observed_heartbeat_stale { - reason.push_str(&format!( - " Idunn observed a provider heartbeat older than the configured {} second threshold; provider status remains {} pending an authentic heartbeat.", - policy.heartbeat_stale_seconds, daemon_status.status - )); - } - let suffix = if scheduled { "scheduled" } else { "intent" }; - let intent_id = args.intent_id.clone().unwrap_or_else(|| { - format!( - "daemon-supervisor-{}-{}-{}", - suffix, - sanitize_id(&daemon_status.daemon_id), - Uuid::new_v4().simple() - ) - }); - let receipt_id = args - .receipt_id - .clone() - .unwrap_or_else(|| format!("{intent_id}-receipt")); - let intent = epiphany_cultmesh_daemon_poke_intent_from_status( - intent_id, - args.requesting_agent_id.clone(), - daemon_status, - reason, - ); - let written_intent = write_epiphany_cultmesh_daemon_poke_intent( - &args.store, - args.runtime_id.clone(), - intent.clone(), - )?; - - let attempted_at = Utc::now(); - let restart_output = run_restart_command(policy, &receipt_id)?; - let completed_at = Utc::now(); - let resulting_status = restart_lifecycle_observation(&restart_output).to_string(); - let receipt_status = if restart_output.success { - "restart-succeeded" - } else { - "restart-failed" - }; - let artifact_ref = args.artifact_ref.clone().unwrap_or_else(|| { - format!( - "process://{}/exit/{}", - policy.restart_command, - restart_output.exit_code.unwrap_or(-1) - ) - }); - let mut receipt = epiphany_cultmesh_daemon_poke_receipt_for_intent( - receipt_id, - &intent, - receipt_status, - resulting_status.clone(), - artifact_ref, - ); - receipt.attempted_at_utc = attempted_at.to_rfc3339(); - receipt.completed_at_utc = completed_at.to_rfc3339(); - let written_receipt = - write_epiphany_cultmesh_daemon_poke_receipt(&args.store, args.runtime_id.clone(), receipt)?; - - // The durable recovery boundary is command completion, not launch. A - // provider heartbeat emitted while the command was still running cannot - // prove that this lifecycle attempt recovered the daemon. - policy.last_attempt_utc = Some(completed_at.to_rfc3339()); - policy.last_reconcile_utc = Some(now.to_rfc3339()); - policy.last_result_status = resulting_status.clone(); - // A command attempt is not a recovered daemon. Backoff remains under - // pressure until a later provider heartbeat proves this attempt worked. - policy.failure_count = unresolved_attempt_failure_count(policy.failure_count); - let written_policy = write_epiphany_cultmesh_daemon_restart_policy( - &args.store, - args.runtime_id.clone(), - policy.clone(), - )?; - - Ok(json!({ - "status": resulting_status, - "store": args.store, - "runtimeId": args.runtime_id, - "daemonId": daemon_status.daemon_id, - "previousStatus": written_intent.observed_status, - "resultingStatus": written_receipt.resulting_status, - "providerStatus": daemon_status.status, - "providerOperatorAction": daemon_status.operator_action, - "providerLastHeartbeatUtc": daemon_status.last_heartbeat_utc, - "intentId": written_intent.intent_id, - "receiptId": written_receipt.receipt_id, - "exitCode": restart_output.exit_code, - "stdoutBytes": restart_output.stdout_len, - "stderrBytes": restart_output.stderr_len, - "policyId": written_policy.policy_id, - "cooldownSeconds": written_policy.cooldown_seconds, - "failureCount": written_policy.failure_count, - "scheduled": scheduled, - "observedHeartbeatStale": observed_heartbeat_stale, - "heartbeatStaleSeconds": policy.heartbeat_stale_seconds, - "lastReconcileUtc": written_policy.last_reconcile_utc, - "privateStateRequested": written_intent.private_state_requested, - "privateStateExposed": written_receipt.private_state_exposed || daemon_status.private_state_exposed, - })) -} - -fn provider_heartbeat_follows_last_attempt( - daemon_status: &EpiphanyCultMeshDaemonStatusEntry, - policy: &EpiphanyCultMeshDaemonRestartPolicyEntry, -) -> Result { - let Some(last_attempt) = policy.last_attempt_utc.as_deref() else { - return Ok(true); - }; - let attempt = DateTime::parse_from_rfc3339(last_attempt) - .with_context(|| format!("invalid last_attempt_utc in policy {}", policy.policy_id))?; - let heartbeat = - DateTime::parse_from_rfc3339(&daemon_status.last_heartbeat_utc).with_context(|| { - format!( - "invalid last_heartbeat_utc for daemon {}", - daemon_status.daemon_id - ) - })?; - Ok(heartbeat > attempt) -} - -fn restart_lifecycle_observation(output: &RestartOutput) -> &'static str { - if output.success { - // Process creation/exit is Idunn evidence only. The provider must publish - // a later authentic heartbeat before anybody may call it ready. - "awaiting-provider-heartbeat" - } else { - "restart-failed" - } -} - -fn unresolved_attempt_failure_count(current: u32) -> u32 { - current.saturating_add(1) -} - -fn assert_policy_allows_attempt( - policy: &EpiphanyCultMeshDaemonRestartPolicyEntry, - now: DateTime, -) -> Result<()> { - if !policy.enabled { - anyhow::bail!("daemon restart policy {} is disabled", policy.policy_id); - } - let Some(last_attempt) = policy.last_attempt_utc.as_deref() else { - return Ok(()); - }; - let last = DateTime::parse_from_rfc3339(last_attempt) - .with_context(|| format!("invalid last_attempt_utc in policy {}", policy.policy_id))? - .with_timezone(&Utc); - let multiplier = policy - .backoff_multiplier - .saturating_pow(policy.failure_count) - .max(1); - let cooldown_seconds = policy - .cooldown_seconds - .saturating_mul(i64::from(multiplier)); - let next_allowed = last + Duration::seconds(cooldown_seconds); - if now < next_allowed { - anyhow::bail!( - "daemon restart policy {} is cooling down until {}; lastResult={}; failureCount={}", - policy.policy_id, - next_allowed.to_rfc3339(), - policy.last_result_status, - policy.failure_count - ); - } - Ok(()) -} - -fn reconcile_interval_elapsed( - policy: &EpiphanyCultMeshDaemonRestartPolicyEntry, - now: DateTime, -) -> Result { - if policy.reconcile_interval_seconds == 0 { - return Ok(true); - } - let Some(last_reconcile) = policy.last_reconcile_utc.as_deref() else { - return Ok(true); - }; - let last = DateTime::parse_from_rfc3339(last_reconcile) - .with_context(|| format!("invalid last_reconcile_utc in policy {}", policy.policy_id))? - .with_timezone(&Utc); - Ok(now >= last + Duration::seconds(policy.reconcile_interval_seconds)) -} - -fn daemon_heartbeat_is_stale( - daemon_status: &EpiphanyCultMeshDaemonStatusEntry, - policy: &EpiphanyCultMeshDaemonRestartPolicyEntry, - now: DateTime, -) -> Result { - if policy.heartbeat_stale_seconds == 0 { - return Ok(false); - } - let last = DateTime::parse_from_rfc3339(&daemon_status.last_heartbeat_utc) - .with_context(|| { - format!( - "invalid last_heartbeat_utc for daemon {}", - daemon_status.daemon_id - ) - })? - .with_timezone(&Utc); - Ok(now > last + Duration::seconds(policy.heartbeat_stale_seconds)) -} - -fn count_outcomes(outcomes: &[Value], expected_status: &str) -> u32 { - outcomes - .iter() - .filter(|outcome| { - outcome - .get("status") - .and_then(Value::as_str) - .is_some_and(|status| status == expected_status) - }) - .count() as u32 -} - fn service_command_path(args: &Args) -> Result { if let Some(command) = args.service_command.as_ref() { return Ok(command.clone()); @@ -3702,89 +3091,6 @@ fn service_lifecycle_receipt( } } -fn run_restart_command( - policy: &EpiphanyCultMeshDaemonRestartPolicyEntry, - lifecycle_receipt_id: &str, -) -> Result { - let mut command = Command::new(&policy.restart_command); - command.args(&policy.restart_args); - command.env( - "EPIPHANY_STARTUP_LIFECYCLE_RECEIPT_ID", - lifecycle_receipt_id, - ); - if let Some(cwd) = &policy.cwd { - command.current_dir(cwd); - } - #[cfg(windows)] - { - command.creation_flags(0x08000000); - } - let output = command - .output() - .with_context(|| format!("failed to run {}", policy.restart_command))?; - Ok(RestartOutput { - success: output.status.success(), - exit_code: output.status.code(), - stdout_len: output.stdout.len(), - stderr_len: output.stderr.len(), - }) -} - -fn assert_swarm_brake_allows_daemon_poke( - brake: Option<&EpiphanyCultMeshSwarmBrakeEntry>, - daemon: &EpiphanyCultMeshDaemonStatusEntry, -) -> Result<()> { - let Some(brake) = brake else { - return Ok(()); - }; - if brake.status != "engaged" { - return Ok(()); - } - let scope_matches = matches!(brake.scope.as_str(), "swarm" | "all") - || brake - .affected_clusters - .iter() - .any(|affected| affected == &daemon.cluster_id || affected == &daemon.daemon_id); - let surface_matches = brake.protected_surfaces.is_empty() - || brake.protected_surfaces.iter().any(|surface| { - surface == "daemon.lifecycle_poke" || surface == "daemon.*" || surface == "*" - }); - if scope_matches && surface_matches { - anyhow::bail!( - "local Verse swarm brake engaged; refusing daemon supervisor poke for {}; scope={}; protected={}; affected={}; reason={}", - daemon.daemon_id, - brake.scope, - brake.protected_surfaces.join(","), - brake.affected_clusters.join(","), - brake.reason - ); - } - Ok(()) -} - -fn assert_swarm_brake_allows_scheduler_tick(context: &EpiphanyLocalVerseContext) -> Result<()> { - let Some(brake) = context.swarm_brake.as_ref() else { - return Ok(()); - }; - if brake.status != "engaged" { - return Ok(()); - } - let scope_matches = matches!(brake.scope.as_str(), "swarm" | "all"); - let surface_matches = brake.protected_surfaces.is_empty() - || brake.protected_surfaces.iter().any(|surface| { - surface == "heartbeat.scheduler" || surface == "daemon.*" || surface == "*" - }); - if scope_matches && surface_matches { - anyhow::bail!( - "local Verse swarm brake engaged; refusing daemon supervisor scheduler tick; scope={}; protected={}; reason={}", - brake.scope, - brake.protected_surfaces.join(","), - brake.reason - ); - } - Ok(()) -} - fn assert_swarm_brake_allows_service_lifecycle_entry( brake: Option<&EpiphanyCultMeshSwarmBrakeEntry>, ) -> Result<()> { @@ -3820,13 +3126,6 @@ fn sanitize_id(raw: &str) -> String { .collect() } -struct RestartOutput { - success: bool, - exit_code: Option, - stdout_len: usize, - stderr_len: usize, -} - #[cfg(test)] mod provider_status_ownership_tests { use super::*; @@ -3846,23 +3145,6 @@ mod provider_status_ownership_tests { "provider-degraded" ); } - - #[test] - fn successful_command_awaits_provider_heartbeat_instead_of_minting_readiness() { - let exit_zero = RestartOutput { - success: true, - exit_code: Some(0), - stdout_len: 0, - stderr_len: 0, - }; - - let observation = restart_lifecycle_observation(&exit_zero); - - assert_eq!(observation, "awaiting-provider-heartbeat"); - assert_ne!(observation, "ready"); - assert_eq!(unresolved_attempt_failure_count(0), 1); - assert_eq!(unresolved_attempt_failure_count(3), 4); - } } #[cfg(test)] @@ -3887,23 +3169,6 @@ mod service_lifecycle_brake_authority_tests { } } - fn daemon() -> EpiphanyCultMeshDaemonStatusEntry { - EpiphanyCultMeshDaemonStatusEntry { - schema_version: "epiphany.cultmesh.daemon_status.v0".into(), - daemon_id: "epiphany-daemon-hands".into(), - cluster_id: "local".into(), - body_domain: "repo:F:/Projects/Epiphany".into(), - daemon_surface_id: "cultmesh://daemon/hands".into(), - eve_surface_id: "eve://daemon/hands".into(), - status: "degraded".into(), - last_heartbeat_utc: "2026-08-11T00:00:00Z".into(), - supported_actions: vec!["pokeDaemon".into()], - operator_action: "pokeDaemon".into(), - private_state_exposed: false, - notes: Vec::new(), - } - } - #[test] fn cognitive_scheduler_brake_does_not_claim_service_physiology() { let cognitive = brake(&[ @@ -3924,17 +3189,6 @@ mod service_lifecycle_brake_authority_tests { assert!(required_managed_health_services(true).is_empty()); } } - - #[test] - fn daemon_poke_reads_the_narrow_brake_without_weakening_scope() { - let daemon = daemon(); - let cognitive = brake(&["heartbeat.scheduler", "coordinator.run"]); - assert!(assert_swarm_brake_allows_daemon_poke(Some(&cognitive), &daemon).is_ok()); - for surface in ["daemon.lifecycle_poke", "daemon.*", "*"] { - let lifecycle = brake(&[surface]); - assert!(assert_swarm_brake_allows_daemon_poke(Some(&lifecycle), &daemon).is_err()); - } - } } #[cfg(test)] @@ -4127,16 +3381,11 @@ struct Args { store: PathBuf, runtime_id: String, daemon_id: String, - restart_command: Option, - restart_args: Vec, cwd: Option, force: bool, disabled: bool, cooldown_seconds: i64, backoff_multiplier: u32, - reconcile_interval_seconds: i64, - heartbeat_stale_seconds: i64, - requesting_agent_id: String, policy_id: Option, scheduler_id: String, service_id: String, @@ -4149,7 +3398,6 @@ struct Args { max_iterations: u64, wait_child: bool, reason: Option, - intent_id: Option, receipt_id: Option, artifact_ref: Option, stdout_artifact: Option, @@ -4179,21 +3427,16 @@ struct Args { impl Args { fn parse() -> Result { let mut values = env::args().skip(1); - let command = values.next().unwrap_or_else(|| "reconcile".to_string()); + let command = values.next().context("missing supervisor command")?; let mut store = PathBuf::from(".epiphany-run/cultmesh/local-verse.ccmp"); let mut store_explicit = false; let mut runtime_id = "epiphany-local".to_string(); let mut daemon_id = None; - let mut restart_command = None; - let mut restart_args = Vec::new(); let mut cwd = None; let mut force = false; let mut disabled = false; let mut cooldown_seconds = 0_i64; let mut backoff_multiplier = 1_u32; - let mut reconcile_interval_seconds = 0_i64; - let mut heartbeat_stale_seconds = 0_i64; - let mut requesting_agent_id = "epiphany.Self".to_string(); let mut policy_id = None; let mut scheduler_id = "epiphany-daemon-supervisor".to_string(); let mut service_id = "epiphany-daemon-supervisor-service".to_string(); @@ -4206,7 +3449,6 @@ impl Args { let mut max_iterations = 0_u64; let mut wait_child = false; let mut reason = None; - let mut intent_id = None; let mut receipt_id = None; let mut artifact_ref = None; let mut stdout_artifact = None; @@ -4244,14 +3486,6 @@ impl Args { "--daemon-id" => { daemon_id = Some(values.next().context("missing --daemon-id value")?) } - "--restart-command" => { - restart_command = Some(PathBuf::from( - values.next().context("missing --restart-command value")?, - )); - } - "--restart-arg" | "--restart-args" => { - restart_args.push(values.next().context("missing --restart-arg value")?); - } "--cwd" => cwd = Some(PathBuf::from(values.next().context("missing --cwd value")?)), "--force" => force = true, "--disabled" => disabled = true, @@ -4267,23 +3501,6 @@ impl Args { .context("missing --backoff-multiplier value")? .parse()?; } - "--reconcile-interval-seconds" => { - reconcile_interval_seconds = values - .next() - .context("missing --reconcile-interval-seconds value")? - .parse()?; - } - "--heartbeat-stale-seconds" => { - heartbeat_stale_seconds = values - .next() - .context("missing --heartbeat-stale-seconds value")? - .parse()?; - } - "--requesting-agent-id" => { - requesting_agent_id = values - .next() - .context("missing --requesting-agent-id value")?; - } "--policy-id" => { policy_id = Some(values.next().context("missing --policy-id value")?) } @@ -4326,9 +3543,6 @@ impl Args { } "--wait-child" => wait_child = true, "--reason" => reason = Some(values.next().context("missing --reason value")?), - "--intent-id" => { - intent_id = Some(values.next().context("missing --intent-id value")?) - } "--receipt-id" => { receipt_id = Some(values.next().context("missing --receipt-id value")?) } @@ -4583,16 +3797,11 @@ impl Args { store, runtime_id, daemon_id, - restart_command, - restart_args, cwd, force, disabled, cooldown_seconds, backoff_multiplier, - reconcile_interval_seconds, - heartbeat_stale_seconds, - requesting_agent_id, policy_id, scheduler_id, service_id, @@ -4605,7 +3814,6 @@ impl Args { max_iterations, wait_child, reason, - intent_id, receipt_id, artifact_ref, stdout_artifact, diff --git a/epiphany-core/src/cultmesh_integration.rs b/epiphany-core/src/cultmesh_integration.rs index 1ae668e4..d146d9fa 100644 --- a/epiphany-core/src/cultmesh_integration.rs +++ b/epiphany-core/src/cultmesh_integration.rs @@ -44,34 +44,10 @@ use uuid::Uuid; pub const EPIPHANY_CULTMESH_CLUSTER_TOPOLOGY_TYPE: &str = "epiphany.cultmesh.cluster_topology"; pub const EPIPHANY_CULTMESH_CLUSTER_TOPOLOGY_SCHEMA_VERSION: &str = "epiphany.cultmesh.cluster_topology.v0"; -pub const EPIPHANY_CULTMESH_DAEMON_STATUS_TYPE: &str = "epiphany.cultmesh.daemon_status"; -pub const EPIPHANY_CULTMESH_DAEMON_STATUS_SCHEMA_VERSION: &str = - "epiphany.cultmesh.daemon_status.v0"; pub const EPIPHANY_CULTMESH_DAEMON_HEARTBEAT_EVENT_TYPE: &str = "epiphany.cultmesh.daemon_heartbeat_event"; pub const EPIPHANY_CULTMESH_DAEMON_HEARTBEAT_EVENT_SCHEMA_VERSION: &str = "epiphany.cultmesh.daemon_heartbeat_event.v1"; -pub const EPIPHANY_CULTMESH_DAEMON_POKE_INTENT_TYPE: &str = "epiphany.cultmesh.daemon_poke_intent"; -pub const EPIPHANY_CULTMESH_DAEMON_POKE_INTENT_SCHEMA_VERSION: &str = - "epiphany.cultmesh.daemon_poke_intent.v1"; -pub const EPIPHANY_CULTMESH_DAEMON_POKE_INTENT_LATEST_KEY: &str = - "epiphany-local/daemon-poke-intent/latest"; -pub const EPIPHANY_CULTMESH_DAEMON_POKE_RECEIPT_TYPE: &str = - "epiphany.cultmesh.daemon_poke_receipt"; -pub const EPIPHANY_CULTMESH_DAEMON_POKE_RECEIPT_SCHEMA_VERSION: &str = - "epiphany.cultmesh.daemon_poke_receipt.v1"; -pub const EPIPHANY_CULTMESH_DAEMON_POKE_RECEIPT_LATEST_KEY: &str = - "epiphany-local/daemon-poke-receipt/latest"; -pub const EPIPHANY_CULTMESH_DAEMON_RESTART_POLICY_TYPE: &str = - "epiphany.cultmesh.daemon_restart_policy"; -pub const EPIPHANY_CULTMESH_DAEMON_RESTART_POLICY_SCHEMA_VERSION: &str = - "epiphany.cultmesh.daemon_restart_policy.v0"; -pub const EPIPHANY_CULTMESH_DAEMON_SCHEDULER_RECEIPT_TYPE: &str = - "epiphany.cultmesh.daemon_scheduler_receipt"; -pub const EPIPHANY_CULTMESH_DAEMON_SCHEDULER_RECEIPT_SCHEMA_VERSION: &str = - "epiphany.cultmesh.daemon_scheduler_receipt.v0"; -pub const EPIPHANY_CULTMESH_DAEMON_SCHEDULER_RECEIPT_LATEST_KEY: &str = - "epiphany-local/daemon-scheduler-receipt/latest"; 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 = @@ -229,38 +205,6 @@ pub struct EpiphanyCultMeshClusterTopologyEntry { pub notes: Vec, } -#[derive(Clone, Debug, PartialEq, Eq, DatabaseEntry)] -#[cultcache( - type = "epiphany.cultmesh.daemon_status", - schema = "EpiphanyCultMeshDaemonStatusEntry" -)] -pub struct EpiphanyCultMeshDaemonStatusEntry { - #[cultcache(key = 0)] - pub schema_version: String, - #[cultcache(key = 1)] - pub daemon_id: String, - #[cultcache(key = 2)] - pub cluster_id: String, - #[cultcache(key = 3)] - pub body_domain: String, - #[cultcache(key = 4)] - pub daemon_surface_id: String, - #[cultcache(key = 5)] - pub eve_surface_id: String, - #[cultcache(key = 6)] - pub status: String, - #[cultcache(key = 7)] - pub last_heartbeat_utc: String, - #[cultcache(key = 8)] - pub supported_actions: Vec, - #[cultcache(key = 9)] - pub operator_action: String, - #[cultcache(key = 10)] - pub private_state_exposed: bool, - #[cultcache(key = 11)] - pub notes: Vec, -} - #[derive(Clone, Debug, PartialEq, Eq, DatabaseEntry)] #[cultcache( type = "epiphany.cultmesh.daemon_heartbeat_event", @@ -289,160 +233,6 @@ pub struct EpiphanyCultMeshDaemonHeartbeatEventEntry { pub startup_lifecycle_receipt_id: String, } -#[derive(Clone, Debug, PartialEq, Eq, DatabaseEntry)] -#[cultcache( - type = "epiphany.cultmesh.daemon_poke_intent", - schema = "EpiphanyCultMeshDaemonPokeIntentEntry" -)] -pub struct EpiphanyCultMeshDaemonPokeIntentEntry { - #[cultcache(key = 0)] - pub schema_version: String, - #[cultcache(key = 1)] - pub intent_id: String, - #[cultcache(key = 2)] - pub requesting_agent_id: String, - #[cultcache(key = 3)] - pub target_daemon_id: String, - #[cultcache(key = 4)] - pub target_cluster_id: String, - #[cultcache(key = 5)] - pub daemon_surface_id: String, - #[cultcache(key = 6)] - pub eve_surface_id: String, - #[cultcache(key = 7)] - pub reason: String, - #[cultcache(key = 8)] - pub requested_action: String, - #[cultcache(key = 9)] - pub observed_status: String, - #[cultcache(key = 10)] - pub private_state_requested: bool, - #[cultcache(key = 11)] - pub notes: Vec, - #[cultcache(key = 12, default)] - pub observed_last_heartbeat_utc: String, - #[cultcache(key = 13, default)] - pub requested_at_utc: String, -} - -#[derive(Clone, Debug, PartialEq, Eq, DatabaseEntry)] -#[cultcache( - type = "epiphany.cultmesh.daemon_poke_receipt", - schema = "EpiphanyCultMeshDaemonPokeReceiptEntry" -)] -pub struct EpiphanyCultMeshDaemonPokeReceiptEntry { - #[cultcache(key = 0)] - pub schema_version: String, - #[cultcache(key = 1)] - pub receipt_id: String, - #[cultcache(key = 2)] - pub intent_id: String, - #[cultcache(key = 3)] - pub target_daemon_id: String, - #[cultcache(key = 4)] - pub target_cluster_id: String, - #[cultcache(key = 5)] - pub action_taken: String, - #[cultcache(key = 6)] - pub status: String, - #[cultcache(key = 7)] - pub resulting_status: String, - #[cultcache(key = 8)] - pub operator_artifact_ref: String, - #[cultcache(key = 9)] - pub private_state_exposed: bool, - #[cultcache(key = 10)] - pub notes: Vec, - #[cultcache(key = 11, default)] - pub attempted_at_utc: String, - #[cultcache(key = 12, default)] - pub completed_at_utc: String, -} - -#[derive(Clone, Debug, PartialEq, Eq, DatabaseEntry)] -#[cultcache( - type = "epiphany.cultmesh.daemon_restart_policy", - schema = "EpiphanyCultMeshDaemonRestartPolicyEntry" -)] -pub struct EpiphanyCultMeshDaemonRestartPolicyEntry { - #[cultcache(key = 0)] - pub schema_version: String, - #[cultcache(key = 1)] - pub policy_id: String, - #[cultcache(key = 2)] - pub daemon_id: String, - #[cultcache(key = 3)] - pub cluster_id: String, - #[cultcache(key = 4)] - pub restart_command: String, - #[cultcache(key = 5)] - pub restart_args: Vec, - #[cultcache(key = 6)] - pub cwd: Option, - #[cultcache(key = 7)] - pub cooldown_seconds: i64, - #[cultcache(key = 8)] - pub backoff_multiplier: u32, - #[cultcache(key = 9)] - pub failure_count: u32, - #[cultcache(key = 10)] - pub last_attempt_utc: Option, - #[cultcache(key = 11)] - pub last_result_status: String, - #[cultcache(key = 12)] - pub enabled: bool, - #[cultcache(key = 13)] - pub private_state_exposed: bool, - #[cultcache(key = 14)] - pub notes: Vec, - #[cultcache(key = 15)] - pub reconcile_interval_seconds: i64, - #[cultcache(key = 16)] - pub heartbeat_stale_seconds: i64, - #[cultcache(key = 17)] - pub last_reconcile_utc: Option, -} - -#[derive(Clone, Debug, PartialEq, Eq, DatabaseEntry)] -#[cultcache( - type = "epiphany.cultmesh.daemon_scheduler_receipt", - schema = "EpiphanyCultMeshDaemonSchedulerReceiptEntry" -)] -pub struct EpiphanyCultMeshDaemonSchedulerReceiptEntry { - #[cultcache(key = 0)] - pub schema_version: String, - #[cultcache(key = 1)] - pub receipt_id: String, - #[cultcache(key = 2)] - pub scheduler_id: String, - #[cultcache(key = 3)] - pub runtime_id: String, - #[cultcache(key = 4)] - pub daemon_selector: String, - #[cultcache(key = 5)] - pub iteration: u64, - #[cultcache(key = 6)] - pub status: String, - #[cultcache(key = 7)] - pub tick_started_utc: String, - #[cultcache(key = 8)] - pub tick_completed_utc: String, - #[cultcache(key = 9)] - pub next_wake_utc: Option, - #[cultcache(key = 10)] - pub outcome_count: u32, - #[cultcache(key = 11)] - pub restarted_count: u32, - #[cultcache(key = 12)] - pub refused_count: u32, - #[cultcache(key = 13)] - pub skipped_count: u32, - #[cultcache(key = 14)] - pub private_state_exposed: bool, - #[cultcache(key = 15)] - pub notes: Vec, -} - #[derive(Clone, Debug, PartialEq, Eq, DatabaseEntry)] #[cultcache( type = "epiphany.cultmesh.daemon_service_lifecycle_receipt", @@ -740,11 +530,6 @@ pub struct EpiphanyLocalVerseContext { pub verse_policies: Vec, pub global_room_policies: Vec, pub cluster_topology: Vec, - pub daemon_statuses: Vec, - pub latest_daemon_poke_intent: Option, - pub latest_daemon_poke_receipt: Option, - pub daemon_restart_policies: Vec, - pub latest_daemon_scheduler_receipt: Option, pub latest_daemon_service_lifecycle_receipt: Option, pub swarm_brake: Option, @@ -770,12 +555,7 @@ pub struct EpiphanyLocalVerseContractSummary { cultmesh_documents!(EpiphanyCultMeshDocuments { EpiphanyCultMeshClusterTopologyEntry => EPIPHANY_CULTMESH_CLUSTER_TOPOLOGY_SCHEMA_VERSION, - EpiphanyCultMeshDaemonStatusEntry => EPIPHANY_CULTMESH_DAEMON_STATUS_SCHEMA_VERSION, EpiphanyCultMeshDaemonHeartbeatEventEntry => EPIPHANY_CULTMESH_DAEMON_HEARTBEAT_EVENT_SCHEMA_VERSION, - EpiphanyCultMeshDaemonPokeIntentEntry => EPIPHANY_CULTMESH_DAEMON_POKE_INTENT_SCHEMA_VERSION, - EpiphanyCultMeshDaemonPokeReceiptEntry => EPIPHANY_CULTMESH_DAEMON_POKE_RECEIPT_SCHEMA_VERSION, - EpiphanyCultMeshDaemonRestartPolicyEntry => EPIPHANY_CULTMESH_DAEMON_RESTART_POLICY_SCHEMA_VERSION, - EpiphanyCultMeshDaemonSchedulerReceiptEntry => EPIPHANY_CULTMESH_DAEMON_SCHEDULER_RECEIPT_SCHEMA_VERSION, EpiphanyCultMeshDaemonServiceLifecycleReceiptEntry => EPIPHANY_CULTMESH_DAEMON_SERVICE_LIFECYCLE_RECEIPT_SCHEMA_VERSION, EpiphanyCultMeshManagedServicePolicyEntry => EPIPHANY_CULTMESH_MANAGED_SERVICE_POLICY_SCHEMA_VERSION, WorkspaceCoverageManagedProcessLaunchEntry => WORKSPACE_COVERAGE_PROCESS_LAUNCH_SCHEMA_VERSION, @@ -995,232 +775,6 @@ fn bounded_opaque_health_id(value: &str) -> bool { .all(|byte| byte.is_ascii_alphanumeric() || matches!(byte, b'.' | b'_' | b'-' | b':')) } -pub fn epiphany_cultmesh_daemon_poke_intent_from_status( - intent_id: impl Into, - requesting_agent_id: impl Into, - status: &EpiphanyCultMeshDaemonStatusEntry, - reason: impl Into, -) -> EpiphanyCultMeshDaemonPokeIntentEntry { - let requested_at_utc = Utc::now().to_rfc3339(); - EpiphanyCultMeshDaemonPokeIntentEntry { - schema_version: EPIPHANY_CULTMESH_DAEMON_POKE_INTENT_SCHEMA_VERSION.to_string(), - intent_id: intent_id.into(), - requesting_agent_id: requesting_agent_id.into(), - target_daemon_id: status.daemon_id.clone(), - target_cluster_id: status.cluster_id.clone(), - daemon_surface_id: status.daemon_surface_id.clone(), - eve_surface_id: status.eve_surface_id.clone(), - reason: reason.into(), - requested_action: "pokeDaemon".to_string(), - observed_status: status.status.clone(), - private_state_requested: false, - notes: vec![ - "Daemon poke intent is an operator-safe lifecycle action request, not a private Verse inspection.".to_string(), - "The target daemon owns the resulting status; this intent only records the requested poke.".to_string(), - ], - observed_last_heartbeat_utc: status.last_heartbeat_utc.clone(), - requested_at_utc, - } -} - -pub fn epiphany_cultmesh_daemon_poke_receipt_for_intent( - receipt_id: impl Into, - intent: &EpiphanyCultMeshDaemonPokeIntentEntry, - status: impl Into, - resulting_status: impl Into, - operator_artifact_ref: impl Into, -) -> EpiphanyCultMeshDaemonPokeReceiptEntry { - let completed_at_utc = Utc::now().to_rfc3339(); - EpiphanyCultMeshDaemonPokeReceiptEntry { - schema_version: EPIPHANY_CULTMESH_DAEMON_POKE_RECEIPT_SCHEMA_VERSION.to_string(), - receipt_id: receipt_id.into(), - intent_id: intent.intent_id.clone(), - target_daemon_id: intent.target_daemon_id.clone(), - target_cluster_id: intent.target_cluster_id.clone(), - action_taken: intent.requested_action.clone(), - status: status.into(), - resulting_status: resulting_status.into(), - operator_artifact_ref: operator_artifact_ref.into(), - private_state_exposed: false, - notes: vec![ - "Daemon poke receipt records lifecycle intervention proof without exposing private daemon state.".to_string(), - "Follow-up daemon status documents remain the liveness authority.".to_string(), - ], - attempted_at_utc: intent.requested_at_utc.clone(), - completed_at_utc, - } -} - -pub fn write_epiphany_cultmesh_daemon_poke_intent( - store_path: impl AsRef, - runtime_id: impl Into, - intent: EpiphanyCultMeshDaemonPokeIntentEntry, -) -> Result { - validate_daemon_poke_intent(&intent)?; - let store_path = store_path.as_ref(); - let node = open_epiphany_cultmesh_node(store_path, runtime_id)?; - let intent_key = epiphany_cultmesh_daemon_poke_intent_key(&intent.intent_id); - put_immutable_cultmesh_entry_and_advance_latest( - &node, - store_path, - &intent_key, - EPIPHANY_CULTMESH_DAEMON_POKE_INTENT_LATEST_KEY, - &intent, - |entry| &entry.requested_at_utc, - ) -} - -pub fn write_epiphany_cultmesh_daemon_poke_receipt( - store_path: impl AsRef, - runtime_id: impl Into, - receipt: EpiphanyCultMeshDaemonPokeReceiptEntry, -) -> Result { - validate_daemon_poke_receipt(&receipt)?; - let store_path = store_path.as_ref(); - let node = open_epiphany_cultmesh_node(store_path, runtime_id)?; - let receipt_key = epiphany_cultmesh_daemon_poke_receipt_key(&receipt.receipt_id); - put_immutable_cultmesh_entry_and_advance_latest( - &node, - store_path, - &receipt_key, - EPIPHANY_CULTMESH_DAEMON_POKE_RECEIPT_LATEST_KEY, - &receipt, - |entry| &entry.completed_at_utc, - ) -} - -fn put_immutable_cultmesh_entry_and_advance_latest( - node: &CultMeshNode, - store_path: &Path, - identity_key: &str, - latest_key: &str, - value: &T, - event_time: F, -) -> Result -where - T: DatabaseEntry + Clone + PartialEq, - F: Fn(&T) -> &str, -{ - let existing = node.get::(identity_key)?; - if existing.as_ref().is_some_and(|current| current != value) { - return Err(anyhow!( - "immutable CultMesh identity collision for type {:?} key {:?}", - T::TYPE, - identity_key - )); - } - let candidate_time = DateTime::parse_from_rfc3339(event_time(value)) - .context("immutable CultMesh event requires RFC3339 ordering time")?; - let latest = node.get::(latest_key)?; - let advances_latest = match latest.as_ref() { - Some(current) => { - candidate_time - > DateTime::parse_from_rfc3339(event_time(current)) - .context("persisted immutable CultMesh event has invalid ordering time")? - } - None => true, - }; - if existing.is_some() && !advances_latest { - return Ok(existing.expect("existing checked")); - } - - let mut expected = Vec::new(); - if advances_latest && let Some(envelope) = node.cache().get_envelope::(latest_key)? { - expected.push(envelope); - } - let mut replacements = Vec::new(); - if existing.is_none() { - replacements.push(node.cache().prepare_entry(identity_key, value)?.0); - } - if advances_latest { - replacements.push(node.cache().prepare_entry(latest_key, value)?.0); - } - let backing = SingleFileMessagePackBackingStore::new(store_path); - if backing.compare_and_swap_batch(&expected, replacements)? { - return Ok(value.clone()); - } - let refreshed = open_epiphany_cultmesh_node(store_path, node.runtime_id())?; - match refreshed.get::(identity_key)? { - Some(current) - if current == *value - && refreshed - .get::(latest_key)? - .as_ref() - .is_some_and(|latest| { - DateTime::parse_from_rfc3339(event_time(latest)).ok() - >= Some(candidate_time) - }) => - { - Ok(current) - } - Some(_) => Err(anyhow!( - "immutable CultMesh identity collision for type {:?} key {:?}", - T::TYPE, - identity_key - )), - None => Err(anyhow!( - "immutable CultMesh write lost compare-and-swap for type {:?} key {:?}", - T::TYPE, - identity_key - )), - } -} - -pub fn write_epiphany_cultmesh_daemon_restart_policy( - store_path: impl AsRef, - runtime_id: impl Into, - policy: EpiphanyCultMeshDaemonRestartPolicyEntry, -) -> Result { - validate_daemon_restart_policy(&policy)?; - let mut node = open_epiphany_cultmesh_node(store_path, runtime_id)?; - let key = epiphany_cultmesh_daemon_restart_policy_key(&policy.daemon_id); - let written = node.put(key.as_str(), &policy)?; - node.flush()?; - Ok(written) -} - -pub fn load_epiphany_cultmesh_daemon_restart_policy( - store_path: impl AsRef, - runtime_id: impl Into, - daemon_id: &str, -) -> Result> { - let node = open_epiphany_cultmesh_node(store_path, runtime_id)?; - let key = epiphany_cultmesh_daemon_restart_policy_key(daemon_id); - node.get(key.as_str()) -} - -pub fn write_epiphany_cultmesh_daemon_scheduler_receipt( - store_path: impl AsRef, - runtime_id: impl Into, - receipt: EpiphanyCultMeshDaemonSchedulerReceiptEntry, -) -> Result { - validate_daemon_scheduler_receipt(&receipt)?; - let mut node = open_epiphany_cultmesh_node(store_path, runtime_id)?; - let receipt_key = epiphany_cultmesh_daemon_scheduler_receipt_key(&receipt.receipt_id); - let written = node.put(receipt_key.as_str(), &receipt)?; - let current_latest = node.get::( - EPIPHANY_CULTMESH_DAEMON_SCHEDULER_RECEIPT_LATEST_KEY, - )?; - if current_latest.as_ref().is_none_or(|current| { - daemon_scheduler_event_key(&written) >= daemon_scheduler_event_key(current) - }) { - node.put( - EPIPHANY_CULTMESH_DAEMON_SCHEDULER_RECEIPT_LATEST_KEY, - &written, - )?; - } - node.flush()?; - Ok(written) -} - -pub fn load_latest_epiphany_cultmesh_daemon_scheduler_receipt( - store_path: impl AsRef, - runtime_id: impl Into, -) -> Result> { - let node = open_epiphany_cultmesh_node(store_path, runtime_id)?; - node.get(EPIPHANY_CULTMESH_DAEMON_SCHEDULER_RECEIPT_LATEST_KEY) -} - pub fn write_epiphany_cultmesh_daemon_service_lifecycle_receipt( store_path: impl AsRef, runtime_id: impl Into, @@ -1660,105 +1214,6 @@ fn validate_swarm_brake(brake: &EpiphanyCultMeshSwarmBrakeEntry) -> Result<()> { Ok(()) } -fn validate_daemon_poke_intent(intent: &EpiphanyCultMeshDaemonPokeIntentEntry) -> Result<()> { - if intent.private_state_requested { - return Err(anyhow!( - "daemon poke intents must not request private state" - )); - } - if intent.target_daemon_id.trim().is_empty() || intent.target_cluster_id.trim().is_empty() { - return Err(anyhow!( - "daemon poke intents require daemon and cluster ids" - )); - } - if intent.requested_action != "pokeDaemon" { - return Err(anyhow!("daemon poke intents must request pokeDaemon")); - } - if intent.reason.trim().is_empty() { - return Err(anyhow!("daemon poke intents require a reason")); - } - for (label, value) in [ - ( - "observed provider heartbeat", - intent.observed_last_heartbeat_utc.as_str(), - ), - ("request timestamp", intent.requested_at_utc.as_str()), - ] { - DateTime::parse_from_rfc3339(value) - .with_context(|| format!("daemon poke intent requires RFC3339 {label}"))?; - } - Ok(()) -} - -fn validate_daemon_poke_receipt(receipt: &EpiphanyCultMeshDaemonPokeReceiptEntry) -> Result<()> { - if receipt.private_state_exposed { - return Err(anyhow!( - "daemon poke receipts must not expose private state" - )); - } - if receipt.intent_id.trim().is_empty() || receipt.target_daemon_id.trim().is_empty() { - return Err(anyhow!( - "daemon poke receipts require intent and daemon ids" - )); - } - if receipt.action_taken != "pokeDaemon" { - return Err(anyhow!("daemon poke receipts must record pokeDaemon")); - } - if receipt.status.trim().is_empty() || receipt.resulting_status.trim().is_empty() { - return Err(anyhow!("daemon poke receipts require status results")); - } - let attempted = DateTime::parse_from_rfc3339(&receipt.attempted_at_utc) - .context("daemon poke receipt requires RFC3339 attempt timestamp")?; - let completed = DateTime::parse_from_rfc3339(&receipt.completed_at_utc) - .context("daemon poke receipt requires RFC3339 completion timestamp")?; - if completed < attempted { - return Err(anyhow!( - "daemon poke receipt completion cannot precede its attempt" - )); - } - Ok(()) -} - -fn validate_daemon_restart_policy(policy: &EpiphanyCultMeshDaemonRestartPolicyEntry) -> Result<()> { - if policy.private_state_exposed { - return Err(anyhow!( - "daemon restart policies must not expose private state" - )); - } - for (label, value) in [ - ("policy id", policy.policy_id.as_str()), - ("daemon id", policy.daemon_id.as_str()), - ("cluster id", policy.cluster_id.as_str()), - ("restart command", policy.restart_command.as_str()), - ("last result status", policy.last_result_status.as_str()), - ] { - if value.trim().is_empty() { - return Err(anyhow!("daemon restart policy missing {label}")); - } - } - if policy.cooldown_seconds < 0 { - return Err(anyhow!( - "daemon restart policy cooldown_seconds must be non-negative" - )); - } - if policy.backoff_multiplier == 0 { - return Err(anyhow!( - "daemon restart policy backoff_multiplier must be positive" - )); - } - if policy.reconcile_interval_seconds < 0 { - return Err(anyhow!( - "daemon restart policy reconcile_interval_seconds must be non-negative" - )); - } - if policy.heartbeat_stale_seconds < 0 { - return Err(anyhow!( - "daemon restart policy heartbeat_stale_seconds must be non-negative" - )); - } - Ok(()) -} - fn validate_managed_service_policy( policy: &EpiphanyCultMeshManagedServicePolicyEntry, ) -> Result<()> { @@ -1901,56 +1356,6 @@ pub(crate) fn validate_workspace_coverage_projector_managed_service_policy( Ok(()) } -fn validate_daemon_scheduler_receipt( - receipt: &EpiphanyCultMeshDaemonSchedulerReceiptEntry, -) -> Result<()> { - if receipt.private_state_exposed { - return Err(anyhow!( - "daemon scheduler receipts must not expose private state" - )); - } - for (label, value) in [ - ("receipt id", receipt.receipt_id.as_str()), - ("scheduler id", receipt.scheduler_id.as_str()), - ("runtime id", receipt.runtime_id.as_str()), - ("daemon selector", receipt.daemon_selector.as_str()), - ("status", receipt.status.as_str()), - ("tick started", receipt.tick_started_utc.as_str()), - ("tick completed", receipt.tick_completed_utc.as_str()), - ] { - if value.trim().is_empty() { - return Err(anyhow!("daemon scheduler receipt missing {label}")); - } - } - let started_at = DateTime::parse_from_rfc3339(&receipt.tick_started_utc) - .map_err(|error| anyhow!("daemon scheduler receipt has invalid tick start: {error}"))?; - let completed_at = - DateTime::parse_from_rfc3339(&receipt.tick_completed_utc).map_err(|error| { - anyhow!("daemon scheduler receipt has invalid tick completion: {error}") - })?; - if completed_at < started_at { - return Err(anyhow!( - "daemon scheduler receipt tick completed before it started" - )); - } - if let Some(next_wake) = receipt.next_wake_utc.as_deref() { - DateTime::parse_from_rfc3339(next_wake) - .map_err(|error| anyhow!("daemon scheduler receipt has invalid next wake: {error}"))?; - } - Ok(()) -} - -fn daemon_scheduler_event_key( - receipt: &EpiphanyCultMeshDaemonSchedulerReceiptEntry, -) -> (DateTime, u64, &str) { - ( - DateTime::parse_from_rfc3339(&receipt.tick_completed_utc) - .expect("validated scheduler completion timestamp"), - receipt.iteration, - receipt.receipt_id.as_str(), - ) -} - fn validate_daemon_service_lifecycle_receipt( receipt: &EpiphanyCultMeshDaemonServiceLifecycleReceiptEntry, ) -> Result<()> { @@ -2389,20 +1794,6 @@ pub fn query_epiphany_local_verse_context( } } - let mut daemon_statuses = Vec::new(); - for cluster in epiphany_cultmesh_cluster_topology() { - if let Some(loaded) = node.get::(&cluster.daemon_id)? { - daemon_statuses.push(loaded); - } - } - let mut daemon_restart_policies = Vec::new(); - for status in &daemon_statuses { - let key = epiphany_cultmesh_daemon_restart_policy_key(&status.daemon_id); - if let Some(loaded) = node.get::(key.as_str())? { - daemon_restart_policies.push(loaded); - } - } - let mut contract_summaries = Vec::new(); contract_summaries.extend( default_mind_cultnet_contracts() @@ -2453,12 +1844,6 @@ pub fn query_epiphany_local_verse_context( verse_policies, global_room_policies, cluster_topology, - daemon_statuses, - latest_daemon_poke_intent: node.get(EPIPHANY_CULTMESH_DAEMON_POKE_INTENT_LATEST_KEY)?, - latest_daemon_poke_receipt: node.get(EPIPHANY_CULTMESH_DAEMON_POKE_RECEIPT_LATEST_KEY)?, - daemon_restart_policies, - latest_daemon_scheduler_receipt: node - .get(EPIPHANY_CULTMESH_DAEMON_SCHEDULER_RECEIPT_LATEST_KEY)?, latest_daemon_service_lifecycle_receipt: node .get(EPIPHANY_CULTMESH_DAEMON_SERVICE_LIFECYCLE_RECEIPT_LATEST_KEY)?, swarm_brake: node.get(EPIPHANY_CULTMESH_SWARM_BRAKE_KEY)?, @@ -2472,60 +1857,6 @@ pub fn query_epiphany_local_verse_context( }) } -pub fn load_epiphany_cultmesh_daemon_liveness( - store_path: impl AsRef, - runtime_id: impl Into, -) -> Result< - Vec<( - EpiphanyCultMeshClusterTopologyEntry, - EpiphanyCultMeshDaemonStatusEntry, - )>, -> { - let store_path = store_path.as_ref(); - let runtime_id = runtime_id.into(); - let node = open_epiphany_cultmesh_node(store_path, runtime_id.clone())?; - let mut rows = Vec::new(); - for cluster in load_epiphany_cultmesh_cluster_topology(store_path, runtime_id.clone())? { - if let Some(status) = node.get::(&cluster.daemon_id)? { - rows.push((cluster, status)); - } - } - Ok(rows) -} - -pub fn load_epiphany_cultmesh_daemon_status( - store_path: impl AsRef, - runtime_id: impl Into, - daemon_id: &str, -) -> Result> { - let node = open_epiphany_cultmesh_node(store_path, runtime_id)?; - node.get(daemon_id) -} - -pub fn load_epiphany_cultmesh_daemon_restart_policy_directory( - store_path: impl AsRef, - runtime_id: impl Into, -) -> Result< - Vec<( - EpiphanyCultMeshClusterTopologyEntry, - Option, - Option, - )>, -> { - let store_path = store_path.as_ref(); - let runtime_id = runtime_id.into(); - let node = open_epiphany_cultmesh_node(store_path, runtime_id.clone())?; - let mut rows = Vec::new(); - for cluster in load_epiphany_cultmesh_cluster_topology(store_path, runtime_id.clone())? { - let status = node.get::(&cluster.daemon_id)?; - let policy = node.get::( - &epiphany_cultmesh_daemon_restart_policy_key(&cluster.daemon_id), - )?; - rows.push((cluster, status, policy)); - } - Ok(rows) -} - trait IntoLocalVerseContractSummary { fn into_local_verse_summary(self) -> EpiphanyLocalVerseContractSummary; } @@ -2555,22 +1886,6 @@ impl_local_verse_contract_summary!(crate::SoulCultNetContract); impl_local_verse_contract_summary!(crate::ContinuityCultNetContract); impl_local_verse_contract_summary!(EpiphanyCultMeshBifrostContractEntry); -fn epiphany_cultmesh_daemon_poke_intent_key(intent_id: &str) -> String { - format!("epiphany-local/daemon-poke-intent/{intent_id}") -} - -fn epiphany_cultmesh_daemon_poke_receipt_key(receipt_id: &str) -> String { - format!("epiphany-local/daemon-poke-receipt/{receipt_id}") -} - -fn epiphany_cultmesh_daemon_restart_policy_key(daemon_id: &str) -> String { - format!("epiphany-local/daemon-restart-policy/{daemon_id}") -} - -fn epiphany_cultmesh_daemon_scheduler_receipt_key(receipt_id: &str) -> String { - format!("epiphany-local/daemon-scheduler-receipt/{receipt_id}") -} - fn epiphany_cultmesh_daemon_service_lifecycle_receipt_key(receipt_id: &str) -> String { format!("epiphany-local/daemon-service-lifecycle-receipt/{receipt_id}") } @@ -2759,18 +2074,6 @@ pub fn load_epiphany_cultmesh_cluster_topology( Ok(topology) } -pub fn write_epiphany_cultmesh_daemon_status( - store_path: impl AsRef, - runtime_id: impl Into, - status: EpiphanyCultMeshDaemonStatusEntry, -) -> Result { - validate_daemon_status(&status)?; - let mut node = open_epiphany_cultmesh_node(store_path, runtime_id)?; - let written = node.put(status.daemon_id.clone(), &status)?; - node.flush()?; - Ok(written) -} - fn epiphany_cultmesh_daemon_heartbeat_event_key(heartbeat_id: &str) -> String { format!("epiphany-local/daemon-heartbeat/event/{heartbeat_id}") } @@ -3030,27 +2333,6 @@ fn validate_heartbeat_identifier(label: &str, value: &str) -> Result<()> { Ok(()) } -fn validate_daemon_status(status: &EpiphanyCultMeshDaemonStatusEntry) -> Result<()> { - if status.private_state_exposed { - return Err(anyhow!("daemon statuses must not expose private state")); - } - if status.daemon_id.trim().is_empty() || status.cluster_id.trim().is_empty() { - return Err(anyhow!("daemon statuses require daemon and cluster ids")); - } - if status.status.trim().is_empty() { - return Err(anyhow!("daemon statuses require a status")); - } - if status.last_heartbeat_utc.trim().is_empty() { - return Err(anyhow!("daemon statuses require a heartbeat timestamp")); - } - if status.supported_actions.is_empty() { - return Err(anyhow!( - "daemon statuses require supported operator actions" - )); - } - Ok(()) -} - pub fn epiphany_cultmesh_bifrost_contracts() -> Vec { vec![ EpiphanyCultMeshBifrostContractEntry { @@ -3107,27 +2389,6 @@ mod tests { use cultcache_rs::CacheBackingStore; use pretty_assertions::assert_eq; - fn test_daemon_status(daemon_id: &str) -> EpiphanyCultMeshDaemonStatusEntry { - let cluster = epiphany_cultmesh_cluster_topology() - .into_iter() - .find(|cluster| cluster.daemon_id == daemon_id) - .expect("test daemon has declared topology"); - EpiphanyCultMeshDaemonStatusEntry { - schema_version: EPIPHANY_CULTMESH_DAEMON_STATUS_SCHEMA_VERSION.to_string(), - daemon_id: cluster.daemon_id, - cluster_id: cluster.cluster_id, - body_domain: cluster.body_domain, - daemon_surface_id: cluster.daemon_surface_id, - eve_surface_id: cluster.eve_surface_id, - status: "ready".to_string(), - last_heartbeat_utc: "2026-06-17T00:00:00Z".to_string(), - supported_actions: vec!["pokeDaemon".to_string()], - operator_action: "none".to_string(), - private_state_exposed: false, - notes: Vec::new(), - } - } - #[test] fn reserved_semantic_projector_policy_requires_specialized_exact_writer() -> Result<()> { let temp = tempfile::tempdir()?; @@ -3913,77 +3174,6 @@ mod tests { Ok(()) } - #[test] - fn scheduler_latest_mirror_refuses_delayed_replay() -> Result<()> { - let temp = tempfile::tempdir()?; - let store = temp.path().join("epiphany-scheduler-order.ccmp"); - let older = EpiphanyCultMeshDaemonSchedulerReceiptEntry { - schema_version: EPIPHANY_CULTMESH_DAEMON_SCHEDULER_RECEIPT_SCHEMA_VERSION.to_string(), - receipt_id: "scheduler-older".to_string(), - scheduler_id: "epiphany-daemon-supervisor".to_string(), - runtime_id: "epiphany-test".to_string(), - daemon_selector: "*".to_string(), - iteration: 1, - status: "completed".to_string(), - tick_started_utc: "2026-07-13T01:00:00Z".to_string(), - tick_completed_utc: "2026-07-13T01:00:01Z".to_string(), - next_wake_utc: Some("2026-07-13T01:01:01Z".to_string()), - outcome_count: 1, - restarted_count: 0, - refused_count: 0, - skipped_count: 1, - private_state_exposed: false, - notes: Vec::new(), - }; - let mut newer = older.clone(); - newer.receipt_id = "scheduler-newer".to_string(); - newer.iteration = 2; - newer.tick_started_utc = "2026-07-13T02:00:00Z".to_string(); - newer.tick_completed_utc = "2026-07-13T02:00:01Z".to_string(); - newer.next_wake_utc = Some("2026-07-13T02:01:01Z".to_string()); - - write_epiphany_cultmesh_daemon_scheduler_receipt(&store, "epiphany-test", newer.clone())?; - write_epiphany_cultmesh_daemon_scheduler_receipt(&store, "epiphany-test", older)?; - assert_eq!( - load_latest_epiphany_cultmesh_daemon_scheduler_receipt(&store, "epiphany-test")?, - Some(newer) - ); - Ok(()) - } - - #[test] - fn scheduler_receipt_refuses_impossible_time_order() -> Result<()> { - let temp = tempfile::tempdir()?; - let store = temp.path().join("epiphany-scheduler-invalid-time.ccmp"); - let receipt = EpiphanyCultMeshDaemonSchedulerReceiptEntry { - schema_version: EPIPHANY_CULTMESH_DAEMON_SCHEDULER_RECEIPT_SCHEMA_VERSION.to_string(), - receipt_id: "scheduler-invalid".to_string(), - scheduler_id: "epiphany-daemon-supervisor".to_string(), - runtime_id: "epiphany-test".to_string(), - daemon_selector: "*".to_string(), - iteration: 1, - status: "completed".to_string(), - tick_started_utc: "2026-07-13T02:00:00Z".to_string(), - tick_completed_utc: "2026-07-13T01:00:00Z".to_string(), - next_wake_utc: Some("2026-07-13T00:00:00Z".to_string()), - outcome_count: 0, - restarted_count: 0, - refused_count: 0, - skipped_count: 0, - private_state_exposed: false, - notes: Vec::new(), - }; - assert!( - write_epiphany_cultmesh_daemon_scheduler_receipt(&store, "epiphany-test", receipt,) - .is_err() - ); - assert!( - load_latest_epiphany_cultmesh_daemon_scheduler_receipt(&store, "epiphany-test")? - .is_none() - ); - Ok(()) - } - #[test] fn service_lifecycle_receipt_refuses_invalid_or_reversed_time() -> Result<()> { let temp = tempfile::tempdir()?; @@ -4051,29 +3241,6 @@ mod tests { Ok(()) } - #[test] - fn declared_daemon_targets_do_not_materialize_observed_liveness() -> Result<()> { - let temp = tempfile::tempdir()?; - let store = temp.path().join("epiphany-declared-versus-observed.ccmp"); - let topology = write_epiphany_cultmesh_cluster_topology( - &store, - "epiphany-test", - "repo:C:/fixture/Epiphany", - )?; - - assert_eq!(topology.len(), 7); - assert!(load_epiphany_cultmesh_daemon_liveness(&store, "epiphany-test")?.is_empty()); - - let observed = test_daemon_status("epiphany-daemon-self"); - let observed_daemon_id = observed.daemon_id.clone(); - write_epiphany_cultmesh_daemon_status(&store, "epiphany-test", observed)?; - - let liveness = load_epiphany_cultmesh_daemon_liveness(&store, "epiphany-test")?; - assert_eq!(liveness.len(), 1); - assert_eq!(liveness[0].1.daemon_id, observed_daemon_id); - Ok(()) - } - #[test] fn diagnostic_loaders_do_not_materialize_missing_body_state() -> Result<()> { let temp = tempfile::tempdir()?; @@ -4081,15 +3248,6 @@ mod tests { let store = missing_parent.join("missing-local-verse.ccmp"); assert!(load_epiphany_cultmesh_cluster_topology(&store, "epiphany-test")?.is_empty()); - assert_eq!( - load_epiphany_cultmesh_daemon_status(&store, "epiphany-test", "epiphany-daemon-hands")?, - None - ); - assert!(load_epiphany_cultmesh_daemon_liveness(&store, "epiphany-test")?.is_empty()); - assert!( - load_epiphany_cultmesh_daemon_restart_policy_directory(&store, "epiphany-test")? - .is_empty() - ); assert!( !store.exists(), "read-only diagnostic loaders must not create a CultCache store" @@ -4105,148 +3263,6 @@ mod tests { Ok(()) } - #[test] - fn exact_daemon_status_loader_reads_only_the_requested_envelope() -> Result<()> { - let temp = tempfile::tempdir()?; - let store = temp.path().join("epiphany-daemon-status.ccmp"); - let expected = test_daemon_status("epiphany-daemon-hands"); - write_epiphany_cultmesh_daemon_status(&store, "epiphany-test", expected.clone())?; - - assert_eq!( - load_epiphany_cultmesh_daemon_status(&store, "epiphany-test", "epiphany-daemon-hands")?, - Some(expected) - ); - assert_eq!( - load_epiphany_cultmesh_daemon_status( - &store, - "epiphany-test", - "epiphany-daemon-absent" - )?, - None - ); - Ok(()) - } - - #[test] - fn daemon_status_refuses_private_state_exposure() -> Result<()> { - let mut status = test_daemon_status("epiphany-daemon-persona"); - status.private_state_exposed = true; - - let error = - validate_daemon_status(&status).expect_err("private daemon status must be refused"); - assert!(error.to_string().contains("private state")); - Ok(()) - } - - #[test] - fn daemon_poke_identity_is_immutable_and_latest_projection_is_monotonic() -> Result<()> { - let temp = tempfile::tempdir()?; - let store = temp.path().join("epiphany-daemon-poke.ccmp"); - let hands = test_daemon_status("epiphany-daemon-hands"); - write_epiphany_cultmesh_daemon_status(&store, "epiphany-test", hands.clone())?; - let intent = epiphany_cultmesh_daemon_poke_intent_from_status( - "daemon-poke-intent-test", - "epiphany.Self", - &hands, - "Hands daemon missed a heartbeat and needs operator-safe poke.", - ); - let receipt = epiphany_cultmesh_daemon_poke_receipt_for_intent( - "daemon-poke-receipt-test", - &intent, - "completed", - "ready", - "cultmesh://epiphany-local/daemon-poke/test", - ); - - write_epiphany_cultmesh_daemon_poke_intent(&store, "epiphany-test", intent.clone())?; - write_epiphany_cultmesh_daemon_poke_receipt(&store, "epiphany-test", receipt.clone())?; - assert_eq!( - write_epiphany_cultmesh_daemon_poke_intent(&store, "epiphany-test", intent.clone())?, - intent - ); - assert_eq!( - write_epiphany_cultmesh_daemon_poke_receipt(&store, "epiphany-test", receipt.clone())?, - receipt - ); - - let mut colliding_intent = intent.clone(); - colliding_intent.reason = "counterfeit replacement".to_string(); - let error = - write_epiphany_cultmesh_daemon_poke_intent(&store, "epiphany-test", colliding_intent) - .expect_err("non-identical intent identity collision must be refused"); - assert!(error.to_string().contains("identity collision")); - - let mut colliding_receipt = receipt.clone(); - colliding_receipt.resulting_status = "counterfeit-ready".to_string(); - let error = - write_epiphany_cultmesh_daemon_poke_receipt(&store, "epiphany-test", colliding_receipt) - .expect_err("non-identical receipt identity collision must be refused"); - assert!(error.to_string().contains("identity collision")); - - let mut newer_intent = intent.clone(); - newer_intent.intent_id = "daemon-poke-intent-newer".to_string(); - newer_intent.requested_at_utc = "2099-06-17T00:02:00Z".to_string(); - let mut newer_receipt = receipt.clone(); - newer_receipt.receipt_id = "daemon-poke-receipt-newer".to_string(); - newer_receipt.intent_id = newer_intent.intent_id.clone(); - newer_receipt.attempted_at_utc = "2099-06-17T00:02:00Z".to_string(); - newer_receipt.completed_at_utc = "2099-06-17T00:03:00Z".to_string(); - write_epiphany_cultmesh_daemon_poke_intent(&store, "epiphany-test", newer_intent.clone())?; - write_epiphany_cultmesh_daemon_poke_receipt( - &store, - "epiphany-test", - newer_receipt.clone(), - )?; - write_epiphany_cultmesh_daemon_poke_intent(&store, "epiphany-test", intent.clone())?; - write_epiphany_cultmesh_daemon_poke_receipt(&store, "epiphany-test", receipt.clone())?; - let context = query_epiphany_local_verse_context(&store, "epiphany-test")?; - assert_eq!( - context.latest_daemon_poke_intent, - Some(newer_intent) - ); - assert_eq!( - context.latest_daemon_poke_receipt, - Some(newer_receipt) - ); - Ok(()) - } - - #[test] - fn daemon_poke_refuses_private_state_and_wrong_action() -> Result<()> { - let hands = test_daemon_status("epiphany-daemon-hands"); - let mut intent = epiphany_cultmesh_daemon_poke_intent_from_status( - "daemon-poke-intent-private-test", - "epiphany.Self", - &hands, - "Attempt forbidden private daemon poke.", - ); - intent.private_state_requested = true; - let temp = tempfile::tempdir()?; - let store = temp.path().join("epiphany-daemon-poke-refusal.ccmp"); - let error = write_epiphany_cultmesh_daemon_poke_intent(&store, "epiphany-test", intent) - .expect_err("private daemon poke intents must be refused"); - assert!(error.to_string().contains("private state")); - - let intent = epiphany_cultmesh_daemon_poke_intent_from_status( - "daemon-poke-intent-test", - "epiphany.Self", - &hands, - "Attempt malformed receipt.", - ); - let mut receipt = epiphany_cultmesh_daemon_poke_receipt_for_intent( - "daemon-poke-receipt-wrong-action-test", - &intent, - "completed", - "ready", - "cultmesh://epiphany-local/daemon-poke/test", - ); - receipt.action_taken = "inspectStatus".to_string(); - let error = write_epiphany_cultmesh_daemon_poke_receipt(&store, "epiphany-test", receipt) - .expect_err("wrong daemon poke receipt action must be refused"); - assert!(error.to_string().contains("pokeDaemon")); - Ok(()) - } - #[test] fn swarm_brake_round_trips_and_projects_status() -> Result<()> { let temp = tempfile::tempdir()?; diff --git a/epiphany-core/src/lib.rs b/epiphany-core/src/lib.rs index ac16b5e6..290f1fb5 100644 --- a/epiphany-core/src/lib.rs +++ b/epiphany-core/src/lib.rs @@ -145,22 +145,9 @@ pub use cultmesh_integration::EPIPHANY_CULTMESH_BIFROST_GITHUB_PUBLICATION_RECEI pub use cultmesh_integration::EPIPHANY_CULTMESH_BIFROST_GITHUB_PUBLICATION_RECEIPT_TYPE; pub use cultmesh_integration::EPIPHANY_CULTMESH_DAEMON_HEARTBEAT_EVENT_SCHEMA_VERSION; pub use cultmesh_integration::EPIPHANY_CULTMESH_DAEMON_HEARTBEAT_EVENT_TYPE; -pub use cultmesh_integration::EPIPHANY_CULTMESH_DAEMON_POKE_INTENT_LATEST_KEY; -pub use cultmesh_integration::EPIPHANY_CULTMESH_DAEMON_POKE_INTENT_SCHEMA_VERSION; -pub use cultmesh_integration::EPIPHANY_CULTMESH_DAEMON_POKE_INTENT_TYPE; -pub use cultmesh_integration::EPIPHANY_CULTMESH_DAEMON_POKE_RECEIPT_LATEST_KEY; -pub use cultmesh_integration::EPIPHANY_CULTMESH_DAEMON_POKE_RECEIPT_SCHEMA_VERSION; -pub use cultmesh_integration::EPIPHANY_CULTMESH_DAEMON_POKE_RECEIPT_TYPE; -pub use cultmesh_integration::EPIPHANY_CULTMESH_DAEMON_RESTART_POLICY_SCHEMA_VERSION; -pub use cultmesh_integration::EPIPHANY_CULTMESH_DAEMON_RESTART_POLICY_TYPE; -pub use cultmesh_integration::EPIPHANY_CULTMESH_DAEMON_SCHEDULER_RECEIPT_LATEST_KEY; -pub use cultmesh_integration::EPIPHANY_CULTMESH_DAEMON_SCHEDULER_RECEIPT_SCHEMA_VERSION; -pub use cultmesh_integration::EPIPHANY_CULTMESH_DAEMON_SCHEDULER_RECEIPT_TYPE; pub use cultmesh_integration::EPIPHANY_CULTMESH_DAEMON_SERVICE_LIFECYCLE_RECEIPT_LATEST_KEY; pub use cultmesh_integration::EPIPHANY_CULTMESH_DAEMON_SERVICE_LIFECYCLE_RECEIPT_SCHEMA_VERSION; pub use cultmesh_integration::EPIPHANY_CULTMESH_DAEMON_SERVICE_LIFECYCLE_RECEIPT_TYPE; -pub use cultmesh_integration::EPIPHANY_CULTMESH_DAEMON_STATUS_SCHEMA_VERSION; -pub use cultmesh_integration::EPIPHANY_CULTMESH_DAEMON_STATUS_TYPE; pub use cultmesh_integration::EPIPHANY_CULTMESH_GLOBAL_TIER; pub use cultmesh_integration::EPIPHANY_CULTMESH_GLOBAL_VERSE_ID; pub use cultmesh_integration::EPIPHANY_CULTMESH_INTERNAL_TIER; @@ -182,12 +169,7 @@ pub use cultmesh_integration::EpiphanyCultMeshBifrostContractEntry; pub use cultmesh_integration::EpiphanyCultMeshBifrostGithubPublicationReceiptEntry; pub use cultmesh_integration::EpiphanyCultMeshClusterTopologyEntry; pub use cultmesh_integration::EpiphanyCultMeshDaemonHeartbeatEventEntry; -pub use cultmesh_integration::EpiphanyCultMeshDaemonPokeIntentEntry; -pub use cultmesh_integration::EpiphanyCultMeshDaemonPokeReceiptEntry; -pub use cultmesh_integration::EpiphanyCultMeshDaemonRestartPolicyEntry; -pub use cultmesh_integration::EpiphanyCultMeshDaemonSchedulerReceiptEntry; pub use cultmesh_integration::EpiphanyCultMeshDaemonServiceLifecycleReceiptEntry; -pub use cultmesh_integration::EpiphanyCultMeshDaemonStatusEntry; pub use cultmesh_integration::EpiphanyCultMeshDocuments; pub use cultmesh_integration::EpiphanyCultMeshManagedServicePolicyEntry; pub use cultmesh_integration::EpiphanyCultMeshSemanticProjectionHealthEntry; @@ -206,26 +188,19 @@ pub use cultmesh_integration::epiphany_cultmesh_bifrost_body_change_publication_ pub use cultmesh_integration::epiphany_cultmesh_bifrost_contracts; #[cfg(test)] pub use cultmesh_integration::epiphany_cultmesh_bifrost_github_publication_receipt_for_publication; -pub use cultmesh_integration::epiphany_cultmesh_daemon_poke_intent_from_status; -pub use cultmesh_integration::epiphany_cultmesh_daemon_poke_receipt_for_intent; pub use cultmesh_integration::epiphany_global_room_policies; pub use cultmesh_integration::epiphany_verse_policies; pub use cultmesh_integration::idunn_recover_memory_semantic_projection_from_cultmesh; pub use cultmesh_integration::load_epiphany_cultmesh_cluster_topology; pub use cultmesh_integration::load_epiphany_cultmesh_daemon_heartbeat_event; -pub use cultmesh_integration::load_epiphany_cultmesh_daemon_liveness; -pub use cultmesh_integration::load_epiphany_cultmesh_daemon_restart_policy; -pub use cultmesh_integration::load_epiphany_cultmesh_daemon_restart_policy_directory; pub use cultmesh_integration::load_epiphany_cultmesh_daemon_service_lifecycle_receipt; pub use cultmesh_integration::load_epiphany_cultmesh_daemon_service_lifecycle_receipts; -pub use cultmesh_integration::load_epiphany_cultmesh_daemon_status; pub use cultmesh_integration::load_epiphany_cultmesh_managed_service_policies; pub use cultmesh_integration::load_epiphany_cultmesh_managed_service_policy; pub use cultmesh_integration::load_epiphany_cultmesh_managed_service_policy_with_digest; pub use cultmesh_integration::load_epiphany_cultmesh_semantic_projection_health; pub use cultmesh_integration::load_epiphany_cultmesh_swarm_brake; pub use cultmesh_integration::load_latest_epiphany_cultmesh_daemon_heartbeat; -pub use cultmesh_integration::load_latest_epiphany_cultmesh_daemon_scheduler_receipt; pub use cultmesh_integration::load_latest_epiphany_cultmesh_daemon_service_lifecycle_receipt; pub use cultmesh_integration::load_latest_epiphany_cultmesh_daemon_service_lifecycle_receipt_for_service; pub use cultmesh_integration::open_epiphany_cultmesh_node; @@ -240,12 +215,7 @@ pub use cultmesh_integration::write_epiphany_cultmesh_bifrost_contracts; #[cfg(test)] pub use cultmesh_integration::write_epiphany_cultmesh_bifrost_github_publication_receipt; pub use cultmesh_integration::write_epiphany_cultmesh_daemon_heartbeat_event; -pub use cultmesh_integration::write_epiphany_cultmesh_daemon_poke_intent; -pub use cultmesh_integration::write_epiphany_cultmesh_daemon_poke_receipt; -pub use cultmesh_integration::write_epiphany_cultmesh_daemon_restart_policy; -pub use cultmesh_integration::write_epiphany_cultmesh_daemon_scheduler_receipt; pub use cultmesh_integration::write_epiphany_cultmesh_daemon_service_lifecycle_receipt; -pub use cultmesh_integration::write_epiphany_cultmesh_daemon_status; pub use cultmesh_integration::write_epiphany_cultmesh_semantic_projector_service_policy; pub use cultmesh_integration::write_epiphany_cultmesh_swarm_brake; pub use cultmesh_integration::write_epiphany_cultmesh_workspace_coverage_projector_service_policy;