Expose service execution audit anatomy

This commit is contained in:
Meta Vens 2026-06-18 16:01:21 +01:00
commit fc993b7be4
9 changed files with 284 additions and 194 deletions

View file

@ -11,8 +11,10 @@ use epiphany_core::EpiphanyCultMeshDaemonSchedulerReceiptEntry;
use epiphany_core::EpiphanyCultMeshDaemonServiceLifecycleReceiptEntry;
use epiphany_core::EpiphanyCultMeshDaemonStatusEntry;
use epiphany_core::EpiphanyLocalVerseContext;
use epiphany_core::epiphany_cluster_service_execution_audit_report;
use epiphany_core::epiphany_cultmesh_daemon_poke_intent_from_status;
use epiphany_core::epiphany_cultmesh_daemon_poke_receipt_for_intent;
use epiphany_core::epiphany_service_execution_audit_report;
use epiphany_core::load_epiphany_cultmesh_daemon_restart_policy;
use epiphany_core::load_epiphany_cultmesh_daemon_service_lifecycle_receipts;
use epiphany_core::query_epiphany_local_verse_context;
@ -1087,7 +1089,7 @@ fn windows_service_execution_audit(args: Args) -> Result<()> {
.into_iter()
.filter(|receipt| receipt.service_id == args.service_id)
.collect::<Vec<_>>();
let report = service_execution_audit_report(&receipts);
let report = epiphany_service_execution_audit_report(&receipts);
let receipt = service_lifecycle_receipt(
&args,
"windows-service-execution-audit",
@ -1168,7 +1170,7 @@ fn windows_service_execution_audit_smoke(args: Args) -> Result<()> {
.into_iter()
.filter(|receipt| receipt.service_id == args.service_id)
.collect::<Vec<_>>();
let complete_report = service_execution_audit_report(&receipts);
let complete_report = epiphany_service_execution_audit_report(&receipts);
if complete_report.status != "complete"
|| complete_report.missing_count != 0
|| complete_report.failed_count != 0
@ -1200,7 +1202,7 @@ fn windows_service_execution_audit_smoke(args: Args) -> Result<()> {
.into_iter()
.filter(|receipt| receipt.service_id == args.service_id)
.collect::<Vec<_>>();
let incomplete_report = service_execution_audit_report(&receipts);
let incomplete_report = epiphany_service_execution_audit_report(&receipts);
if incomplete_report.status != "incomplete" || incomplete_report.failed_count == 0 {
anyhow::bail!("service execution audit smoke failed to reject drifted reconcile receipt");
}
@ -1316,7 +1318,7 @@ fn cluster_windows_service_execution_audit(args: Args) -> Result<()> {
.into_iter()
.filter(|receipt| receipt.service_id == args.service_id)
.collect::<Vec<_>>();
let report = cluster_service_execution_audit_report(&receipts);
let report = epiphany_cluster_service_execution_audit_report(&receipts);
let receipt = service_lifecycle_receipt(
&args,
"cluster-windows-service-execution-audit",
@ -1370,7 +1372,7 @@ fn cluster_windows_service_execution_audit_smoke(args: Args) -> Result<()> {
),
("cluster-windows-service-install", "installed"),
("cluster-windows-service-start", "start-requested"),
("cluster-windows-service-audit", "complete"),
("cluster-windows-service-execution-audit", "complete"),
("cluster-windows-service-stop", "stop-requested"),
] {
let receipt = service_lifecycle_receipt(
@ -1398,7 +1400,7 @@ fn cluster_windows_service_execution_audit_smoke(args: Args) -> Result<()> {
.into_iter()
.filter(|receipt| receipt.service_id == args.service_id)
.collect::<Vec<_>>();
let complete_report = cluster_service_execution_audit_report(&receipts);
let complete_report = epiphany_cluster_service_execution_audit_report(&receipts);
if complete_report.status != "complete"
|| complete_report.missing_count != 0
|| complete_report.failed_count != 0
@ -1410,10 +1412,10 @@ fn cluster_windows_service_execution_audit_smoke(args: Args) -> Result<()> {
}
let incomplete = service_lifecycle_receipt(
&args,
"cluster-windows-service-audit",
"cluster-windows-service-execution-audit",
"incomplete",
"smoke".to_string(),
vec!["cluster-windows-service-audit".to_string()],
vec!["cluster-windows-service-execution-audit".to_string()],
None,
Some(0),
started_at,
@ -1432,7 +1434,7 @@ fn cluster_windows_service_execution_audit_smoke(args: Args) -> Result<()> {
.into_iter()
.filter(|receipt| receipt.service_id == args.service_id)
.collect::<Vec<_>>();
let incomplete_report = cluster_service_execution_audit_report(&receipts);
let incomplete_report = epiphany_cluster_service_execution_audit_report(&receipts);
if incomplete_report.status != "incomplete" || incomplete_report.failed_count == 0 {
anyhow::bail!(
"cluster service execution audit smoke failed to reject incomplete audit receipt"
@ -2711,182 +2713,6 @@ fn service_lifecycle_receipt(
}
}
fn service_execution_audit_report(
receipts: &[EpiphanyCultMeshDaemonServiceLifecycleReceiptEntry],
) -> ServiceExecutionAuditReport {
let expected = [
("windows-service-execution-runbook", &["written"][..]),
(
"windows-service-execution-readiness",
&["elevated-ready"][..],
),
("windows-service-install", &["installed"][..]),
("windows-service-start", &["start-requested"][..]),
(
"windows-service-status",
&["running", "present", "stopped"][..],
),
("windows-service-reconcile", &["in-sync"][..]),
("windows-service-stop", &["stop-requested"][..]),
];
let mut checks = Vec::new();
let mut missing_count = 0_usize;
let mut failed_count = 0_usize;
let mut private_state_exposed = false;
for (action, allowed_statuses) in expected {
let receipt = latest_lifecycle_receipt_for_action(receipts, action);
let (receipt_id, observed_status, ok, sealed) = match receipt {
Some(receipt) => {
let status_ok = allowed_statuses
.iter()
.any(|allowed| *allowed == receipt.status);
(
Some(receipt.receipt_id.clone()),
Some(receipt.status.clone()),
status_ok,
!receipt.private_state_exposed,
)
}
None => {
missing_count += 1;
(None, None, false, true)
}
};
if !ok {
failed_count += 1;
}
if !sealed {
private_state_exposed = true;
}
checks.push(json!({
"action": action,
"allowedStatuses": allowed_statuses,
"receiptId": receipt_id,
"observedStatus": observed_status,
"ok": ok,
"privateStateSealed": sealed,
}));
}
let status = if missing_count == 0 && failed_count == 0 && !private_state_exposed {
"complete"
} else {
"incomplete"
}
.to_string();
ServiceExecutionAuditReport {
status,
receipt_count: receipts.len(),
missing_count,
failed_count,
private_state_exposed,
checks,
}
}
fn cluster_service_execution_audit_report(
receipts: &[EpiphanyCultMeshDaemonServiceLifecycleReceiptEntry],
) -> ServiceExecutionAuditReport {
let expected = [
(
"cluster-windows-service-execution-runbook",
&["written"][..],
),
(
"cluster-windows-service-execution-readiness",
&["elevated-ready"][..],
),
("cluster-windows-service-install", &["installed"][..]),
("cluster-windows-service-start", &["start-requested"][..]),
("cluster-windows-service-audit", &["complete"][..]),
("cluster-windows-service-stop", &["stop-requested"][..]),
];
let mut checks = Vec::new();
let mut missing_count = 0_usize;
let mut failed_count = 0_usize;
let mut private_state_exposed = false;
for (action, allowed_statuses) in expected {
let receipt = latest_lifecycle_receipt_for_action(receipts, action);
let (receipt_id, observed_status, ok, sealed) = match receipt {
Some(receipt) => {
let status_ok = allowed_statuses
.iter()
.any(|allowed| *allowed == receipt.status);
(
Some(receipt.receipt_id.clone()),
Some(receipt.status.clone()),
status_ok,
!receipt.private_state_exposed,
)
}
None => {
missing_count += 1;
(None, None, false, true)
}
};
if !ok {
failed_count += 1;
}
if !sealed {
private_state_exposed = true;
}
checks.push(json!({
"action": action,
"allowedStatuses": allowed_statuses,
"receiptId": receipt_id,
"observedStatus": observed_status,
"ok": ok,
"privateStateSealed": sealed,
}));
}
let status = if missing_count == 0 && failed_count == 0 && !private_state_exposed {
"complete"
} else {
"incomplete"
}
.to_string();
ServiceExecutionAuditReport {
status,
receipt_count: receipts.len(),
missing_count,
failed_count,
private_state_exposed,
checks,
}
}
fn latest_lifecycle_receipt_for_action<'a>(
receipts: &'a [EpiphanyCultMeshDaemonServiceLifecycleReceiptEntry],
action: &str,
) -> Option<&'a EpiphanyCultMeshDaemonServiceLifecycleReceiptEntry> {
receipts
.iter()
.filter(|receipt| receipt.action == action)
.max_by(|left, right| {
lifecycle_receipt_sort_key(left).cmp(&lifecycle_receipt_sort_key(right))
})
}
fn lifecycle_receipt_sort_key(
receipt: &EpiphanyCultMeshDaemonServiceLifecycleReceiptEntry,
) -> (&str, &str) {
(
receipt
.completed_at_utc
.as_deref()
.unwrap_or(receipt.started_at_utc.as_str()),
receipt.receipt_id.as_str(),
)
}
struct ServiceExecutionAuditReport {
status: String,
receipt_count: usize,
missing_count: usize,
failed_count: usize,
private_state_exposed: bool,
checks: Vec<Value>,
}
fn run_restart_command(policy: &EpiphanyCultMeshDaemonRestartPolicyEntry) -> Result<RestartOutput> {
let mut command = Command::new(&policy.restart_command);
command.args(&policy.restart_args);

View file

@ -22,7 +22,9 @@ use epiphany_core::EpiphanyCultMeshOdinAdvertisementEntry;
use epiphany_core::EpiphanyCultMeshSwarmBrakeEntry;
use epiphany_core::EpiphanyCultMeshWorkLoopTelemetryEntry;
use epiphany_core::EpiphanyLocalVerseContext;
use epiphany_core::EpiphanyServiceExecutionAuditCheck;
use epiphany_core::default_epiphany_cultmesh_swarm_brake;
use epiphany_core::epiphany_cluster_service_execution_audit_report;
use epiphany_core::epiphany_cultmesh_agent_state_soa_summary_from_entry;
use epiphany_core::epiphany_cultmesh_bifrost_body_change_publication_intent;
use epiphany_core::epiphany_cultmesh_bifrost_body_change_publication_receipt_for_intent;
@ -2413,9 +2415,33 @@ fn main() -> Result<()> {
.service_lifecycle_attention_tui_rows
.iter()
.any(|row| row.contains("artifact=external-ref"))
|| service_overview.service_execution_failed_check_count == 0
|| service_overview.service_execution_missing_check_count == 0
|| !service_overview
.service_execution_failed_check_rows
.iter()
.any(|check| {
check.action == "cluster-windows-service-execution-readiness"
&& check.observed_status.is_none()
&& !check.ok
&& check.private_state_sealed
})
|| !service_overview
.service_execution_failed_check_rows
.iter()
.any(|check| {
check.action == "cluster-windows-service-execution-audit"
&& check.observed_status.as_deref() == Some("incomplete")
&& !check.ok
&& check.private_state_sealed
})
|| !service_overview
.service_execution_failed_check_tui_rows
.iter()
.any(|row| row.contains("cluster-windows-service-execution-audit=incomplete"))
{
anyhow::bail!(
"local Verse query smoke did not expose sealed service lifecycle readback plus elevated operator runbook action rows"
"local Verse query smoke did not expose sealed service lifecycle readback plus service execution failed-check anatomy"
);
}
let missing_runbook_row = ReceiptDirectoryRow {
@ -2800,6 +2826,10 @@ struct SwarmOverviewReport {
tool_host_attention_tui_rows: Vec<String>,
service_lifecycle_attention_rows: Vec<ReceiptDirectoryRow>,
service_lifecycle_attention_tui_rows: Vec<String>,
service_execution_failed_check_count: usize,
service_execution_missing_check_count: usize,
service_execution_failed_check_rows: Vec<EpiphanyServiceExecutionAuditCheck>,
service_execution_failed_check_tui_rows: Vec<String>,
topology_report: ClusterTopologyReport,
daemon_report: DaemonLivenessReport,
surface_report: EveSurfaceReport,
@ -2863,6 +2893,10 @@ struct SwarmOverviewOutput {
tool_host_attention_tui_rows: Vec<String>,
service_lifecycle_attention_count: usize,
service_lifecycle_attention_rows: Vec<ReceiptDirectoryRow>,
service_execution_failed_check_count: usize,
service_execution_missing_check_count: usize,
service_execution_failed_check_rows: Vec<EpiphanyServiceExecutionAuditCheck>,
service_execution_failed_check_tui_rows: Vec<String>,
policy_covered_count: usize,
policy_enabled_count: usize,
policy_disabled_count: usize,
@ -2919,6 +2953,10 @@ impl SwarmOverviewOutput {
tool_host_attention_tui_rows: report.tool_host_attention_tui_rows,
service_lifecycle_attention_count: report.service_lifecycle_attention_rows.len(),
service_lifecycle_attention_rows: report.service_lifecycle_attention_rows,
service_execution_failed_check_count: report.service_execution_failed_check_count,
service_execution_missing_check_count: report.service_execution_missing_check_count,
service_execution_failed_check_rows: report.service_execution_failed_check_rows,
service_execution_failed_check_tui_rows: report.service_execution_failed_check_tui_rows,
policy_covered_count: report.policy_report.covered_count,
policy_enabled_count: report.policy_report.enabled_count,
policy_disabled_count: report.policy_report.disabled_count,
@ -2967,6 +3005,10 @@ struct SwarmTriageOutput {
service_lifecycle_attention_count: usize,
service_lifecycle_attention_rows: Vec<ReceiptDirectoryRow>,
service_lifecycle_attention_tui_rows: Vec<String>,
service_execution_failed_check_count: usize,
service_execution_missing_check_count: usize,
service_execution_failed_check_rows: Vec<EpiphanyServiceExecutionAuditCheck>,
service_execution_failed_check_tui_rows: Vec<String>,
poked_daemon_count: usize,
pokes: Vec<serde_json::Value>,
commands: serde_json::Value,
@ -3018,6 +3060,10 @@ impl SwarmTriageOutput {
service_lifecycle_attention_count: report.service_lifecycle_attention_rows.len(),
service_lifecycle_attention_rows: report.service_lifecycle_attention_rows,
service_lifecycle_attention_tui_rows: report.service_lifecycle_attention_tui_rows,
service_execution_failed_check_count: report.service_execution_failed_check_count,
service_execution_missing_check_count: report.service_execution_missing_check_count,
service_execution_failed_check_rows: report.service_execution_failed_check_rows,
service_execution_failed_check_tui_rows: report.service_execution_failed_check_tui_rows,
poked_daemon_count,
pokes,
commands: json!({
@ -3646,6 +3692,23 @@ fn load_swarm_overview_report(args: &Args) -> Result<SwarmOverviewReport> {
.iter()
.map(receipt_directory_tui_row)
.collect::<Vec<_>>();
let cluster_lifecycle_receipts = lifecycle_receipts
.iter()
.filter(|receipt| receipt.service_id == "epiphany-cluster-daemon-services")
.cloned()
.collect::<Vec<_>>();
let service_execution_audit =
epiphany_cluster_service_execution_audit_report(&cluster_lifecycle_receipts);
let service_execution_failed_check_rows = service_execution_audit
.checks
.iter()
.filter(|check| !check.ok || !check.private_state_sealed)
.cloned()
.collect::<Vec<_>>();
let service_execution_failed_check_tui_rows = service_execution_failed_check_rows
.iter()
.map(service_execution_audit_check_tui_row)
.collect::<Vec<_>>();
let liveness_status =
if daemon_report.non_ready_count == 0 && tool_report.host_attention_count == 0 {
"ready".to_string()
@ -3770,6 +3833,7 @@ fn load_swarm_overview_report(args: &Args) -> Result<SwarmOverviewReport> {
.any(|row| row.private_state_exposed)
|| tool_report.rows.iter().any(|row| row.private_state_exposed)
|| policy_report.private_state_exposed
|| service_execution_audit.private_state_exposed
|| service_lifecycle_rows
.iter()
.any(|row| row.private_state_exposed);
@ -3791,6 +3855,10 @@ fn load_swarm_overview_report(args: &Args) -> Result<SwarmOverviewReport> {
tool_host_attention_tui_rows,
service_lifecycle_attention_rows,
service_lifecycle_attention_tui_rows,
service_execution_failed_check_count: service_execution_audit.failed_count,
service_execution_missing_check_count: service_execution_audit.missing_count,
service_execution_failed_check_rows,
service_execution_failed_check_tui_rows,
topology_report,
daemon_report,
surface_report,
@ -4316,6 +4384,21 @@ fn receipt_directory_tui_row(row: &ReceiptDirectoryRow) -> String {
)
}
fn service_execution_audit_check_tui_row(check: &EpiphanyServiceExecutionAuditCheck) -> String {
let observed_status = check.observed_status.as_deref().unwrap_or("missing");
let receipt_id = check.receipt_id.as_deref().unwrap_or("missing");
let allowed_statuses = check.allowed_statuses.join("|");
let seal_status = if check.private_state_sealed {
"sealed"
} else {
"private-state-exposed"
};
format!(
"{}={} | allowed={} | receipt={} | {}",
check.action, observed_status, allowed_statuses, receipt_id, seal_status
)
}
fn receipt_directory_row_needs_attention(row: &ReceiptDirectoryRow) -> bool {
if row.private_state_exposed {
return true;

View file

@ -1117,6 +1117,163 @@ pub struct EpiphanyCultMeshDaemonServiceLifecycleReceiptEntry {
pub notes: Vec<String>,
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct EpiphanyServiceExecutionAuditCheck {
pub action: String,
pub allowed_statuses: Vec<String>,
pub receipt_id: Option<String>,
pub observed_status: Option<String>,
pub ok: bool,
pub private_state_sealed: bool,
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct EpiphanyServiceExecutionAuditReport {
pub status: String,
pub receipt_count: usize,
pub missing_count: usize,
pub failed_count: usize,
pub private_state_exposed: bool,
pub checks: Vec<EpiphanyServiceExecutionAuditCheck>,
}
pub fn epiphany_service_execution_audit_report(
receipts: &[EpiphanyCultMeshDaemonServiceLifecycleReceiptEntry],
) -> EpiphanyServiceExecutionAuditReport {
epiphany_service_execution_audit_report_for_expected(
receipts,
&[
("windows-service-execution-runbook", &["written"][..]),
(
"windows-service-execution-readiness",
&["elevated-ready"][..],
),
("windows-service-install", &["installed"][..]),
("windows-service-start", &["start-requested"][..]),
(
"windows-service-status",
&["running", "present", "stopped"][..],
),
("windows-service-reconcile", &["in-sync"][..]),
("windows-service-stop", &["stop-requested"][..]),
],
)
}
pub fn epiphany_cluster_service_execution_audit_report(
receipts: &[EpiphanyCultMeshDaemonServiceLifecycleReceiptEntry],
) -> EpiphanyServiceExecutionAuditReport {
epiphany_service_execution_audit_report_for_expected(
receipts,
&[
(
"cluster-windows-service-execution-runbook",
&["written"][..],
),
(
"cluster-windows-service-execution-readiness",
&["elevated-ready"][..],
),
("cluster-windows-service-install", &["installed"][..]),
("cluster-windows-service-start", &["start-requested"][..]),
("cluster-windows-service-execution-audit", &["complete"][..]),
("cluster-windows-service-stop", &["stop-requested"][..]),
],
)
}
fn epiphany_service_execution_audit_report_for_expected(
receipts: &[EpiphanyCultMeshDaemonServiceLifecycleReceiptEntry],
expected: &[(&str, &[&str])],
) -> EpiphanyServiceExecutionAuditReport {
let mut checks = Vec::new();
let mut missing_count = 0_usize;
let mut failed_count = 0_usize;
let mut private_state_exposed = false;
for (action, allowed_statuses) in expected {
let receipt = latest_lifecycle_receipt_for_action(receipts, action);
let (receipt_id, observed_status, ok, sealed) = match receipt {
Some(receipt) => {
let status_ok = allowed_statuses
.iter()
.any(|allowed| *allowed == receipt.status);
(
Some(receipt.receipt_id.clone()),
Some(receipt.status.clone()),
status_ok,
!receipt.private_state_exposed,
)
}
None => {
missing_count += 1;
(None, None, false, true)
}
};
if !ok {
failed_count += 1;
}
if !sealed {
private_state_exposed = true;
}
checks.push(EpiphanyServiceExecutionAuditCheck {
action: (*action).to_string(),
allowed_statuses: allowed_statuses
.iter()
.map(|status| (*status).to_string())
.collect(),
receipt_id,
observed_status,
ok,
private_state_sealed: sealed,
});
}
let status = if missing_count == 0 && failed_count == 0 && !private_state_exposed {
"complete"
} else {
"incomplete"
}
.to_string();
EpiphanyServiceExecutionAuditReport {
status,
receipt_count: receipts.len(),
missing_count,
failed_count,
private_state_exposed,
checks,
}
}
fn latest_lifecycle_receipt_for_action<'a>(
receipts: &'a [EpiphanyCultMeshDaemonServiceLifecycleReceiptEntry],
action: &str,
) -> Option<&'a EpiphanyCultMeshDaemonServiceLifecycleReceiptEntry> {
receipts
.iter()
.filter(|receipt| receipt.action == action)
.max_by(|left, right| {
lifecycle_receipt_sort_key(left).cmp(&lifecycle_receipt_sort_key(right))
})
}
fn lifecycle_receipt_sort_key(
receipt: &EpiphanyCultMeshDaemonServiceLifecycleReceiptEntry,
) -> (&str, &str) {
(
receipt
.completed_at_utc
.as_deref()
.unwrap_or(receipt.started_at_utc.as_str()),
receipt.receipt_id.as_str(),
)
}
#[derive(Clone, Debug, PartialEq, Eq, DatabaseEntry)]
#[cultcache(
type = "epiphany.cultmesh.swarm_brake",

View file

@ -265,8 +265,11 @@ pub use cultmesh_integration::EpiphanyCultMeshWorkLoopTelemetryEntry;
pub use cultmesh_integration::EpiphanyLocalVerseContext;
pub use cultmesh_integration::EpiphanyLocalVerseContractSummary;
pub use cultmesh_integration::EpiphanyLocalVerseWorkLoopSummary;
pub use cultmesh_integration::EpiphanyServiceExecutionAuditCheck;
pub use cultmesh_integration::EpiphanyServiceExecutionAuditReport;
pub use cultmesh_integration::default_epiphany_cultmesh_operator_status;
pub use cultmesh_integration::default_epiphany_cultmesh_swarm_brake;
pub use cultmesh_integration::epiphany_cluster_service_execution_audit_report;
pub use cultmesh_integration::epiphany_cultmesh_agent_state_soa_summary_from_entry;
pub use cultmesh_integration::epiphany_cultmesh_bifrost_body_change_publication_intent;
pub use cultmesh_integration::epiphany_cultmesh_bifrost_body_change_publication_receipt_for_intent;
@ -297,6 +300,7 @@ pub use cultmesh_integration::epiphany_cultmesh_soul_contracts;
pub use cultmesh_integration::epiphany_cultmesh_substrate_gate_contracts;
pub use cultmesh_integration::epiphany_cultmesh_verse_policies;
pub use cultmesh_integration::epiphany_local_verse_work_loop_summary;
pub use cultmesh_integration::epiphany_service_execution_audit_report;
pub use cultmesh_integration::load_epiphany_cultmesh_cluster_topology;
pub use cultmesh_integration::load_epiphany_cultmesh_daemon_liveness;
pub use cultmesh_integration::load_epiphany_cultmesh_daemon_restart_policy;