Rebuild Idunn semantic projector authority
This commit is contained in:
parent
05f11df79a
commit
fd7ff60adc
11 changed files with 2223 additions and 581 deletions
|
|
@ -1,17 +1,20 @@
|
|||
use anyhow::Context;
|
||||
use anyhow::Result;
|
||||
use chrono::Utc;
|
||||
use epiphany_core::EPIPHANY_CULTMESH_DAEMON_HEARTBEAT_EVENT_SCHEMA_VERSION;
|
||||
use epiphany_core::EPIPHANY_CULTMESH_DAEMON_STATUS_SCHEMA_VERSION;
|
||||
use epiphany_core::EpiphanyCultMeshDaemonHeartbeatEventEntry;
|
||||
use epiphany_core::EpiphanyCultMeshDaemonStatusEntry;
|
||||
use epiphany_core::load_epiphany_cultmesh_cluster_topology;
|
||||
use epiphany_core::load_epiphany_cultmesh_daemon_liveness;
|
||||
use epiphany_core::publish_epiphany_cultmesh_provider_state;
|
||||
use epiphany_core::write_epiphany_cultmesh_daemon_heartbeat_event;
|
||||
use epiphany_core::write_epiphany_cultmesh_daemon_status;
|
||||
use serde_json::json;
|
||||
use std::env;
|
||||
use std::path::PathBuf;
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
use uuid::Uuid;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let args = Args::parse()?;
|
||||
|
|
@ -39,7 +42,10 @@ fn serve(args: Args) -> Result<()> {
|
|||
print_output(&args, "serveComplete", written)
|
||||
}
|
||||
|
||||
fn write_heartbeat(args: &Args, iteration: u64) -> Result<EpiphanyCultMeshDaemonStatusEntry> {
|
||||
fn write_heartbeat(
|
||||
args: &Args,
|
||||
iteration: u64,
|
||||
) -> Result<EpiphanyCultMeshDaemonHeartbeatEventEntry> {
|
||||
let topology = load_epiphany_cultmesh_cluster_topology(&args.store, args.runtime_id.clone())?;
|
||||
let cluster = topology
|
||||
.into_iter()
|
||||
|
|
@ -55,52 +61,76 @@ fn write_heartbeat(args: &Args, iteration: u64) -> Result<EpiphanyCultMeshDaemon
|
|||
args.runtime_id.clone(),
|
||||
&args.daemon_id,
|
||||
)?;
|
||||
let current = load_epiphany_cultmesh_daemon_liveness(&args.store, args.runtime_id.clone())?
|
||||
.into_iter()
|
||||
.map(|(_, status)| status)
|
||||
.find(|status| status.daemon_id == args.daemon_id)
|
||||
.unwrap_or_else(|| EpiphanyCultMeshDaemonStatusEntry {
|
||||
let heartbeat_at = Utc::now().to_rfc3339();
|
||||
let heartbeat = new_heartbeat_event(
|
||||
args,
|
||||
&cluster.daemon_id,
|
||||
&cluster.cluster_id,
|
||||
iteration,
|
||||
heartbeat_at,
|
||||
);
|
||||
let written = write_epiphany_cultmesh_daemon_heartbeat_event(
|
||||
&args.store,
|
||||
args.runtime_id.clone(),
|
||||
heartbeat,
|
||||
)?;
|
||||
|
||||
// Compatibility sight for readers not yet migrated to heartbeat events. It is
|
||||
// derived after the provider-owned event and cannot mint heartbeat authority.
|
||||
write_epiphany_cultmesh_daemon_status(
|
||||
&args.store,
|
||||
args.runtime_id.clone(),
|
||||
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: "unknown".to_string(),
|
||||
last_heartbeat_utc: "unknown".to_string(),
|
||||
status: written.status.clone(),
|
||||
last_heartbeat_utc: written.heartbeat_at.clone(),
|
||||
supported_actions: vec![
|
||||
"inspectStatus".to_string(),
|
||||
"pokeDaemon".to_string(),
|
||||
"watchHeartbeat".to_string(),
|
||||
],
|
||||
operator_action: "pokeDaemon".to_string(),
|
||||
operator_action: "none".to_string(),
|
||||
private_state_exposed: false,
|
||||
notes: vec![
|
||||
"Initial status constructed by the owning cluster daemon from persisted topology."
|
||||
"Display-only compatibility projection derived from the provider heartbeat event."
|
||||
.to_string(),
|
||||
format!("Source heartbeat id: {}", written.heartbeat_id),
|
||||
],
|
||||
});
|
||||
let mut next = current.clone();
|
||||
next.status = "ready".to_string();
|
||||
next.last_heartbeat_utc = Utc::now().to_rfc3339();
|
||||
next.operator_action = if next.status == "ready" {
|
||||
"none".to_string()
|
||||
} else {
|
||||
"pokeDaemon".to_string()
|
||||
};
|
||||
next.private_state_exposed = false;
|
||||
next.notes = vec![
|
||||
"Heartbeat published by epiphany-cluster-daemon; local Verse status is liveness projection, not private daemon memory.".to_string(),
|
||||
format!("Daemon body domain: {}", current.body_domain),
|
||||
format!("Heartbeat iteration: {iteration}"),
|
||||
];
|
||||
write_epiphany_cultmesh_daemon_status(&args.store, args.runtime_id.clone(), next)
|
||||
},
|
||||
)?;
|
||||
Ok(written)
|
||||
}
|
||||
|
||||
fn new_heartbeat_event(
|
||||
args: &Args,
|
||||
daemon_id: &str,
|
||||
cluster_id: &str,
|
||||
iteration: u64,
|
||||
heartbeat_at: String,
|
||||
) -> EpiphanyCultMeshDaemonHeartbeatEventEntry {
|
||||
EpiphanyCultMeshDaemonHeartbeatEventEntry {
|
||||
schema_version: EPIPHANY_CULTMESH_DAEMON_HEARTBEAT_EVENT_SCHEMA_VERSION.to_string(),
|
||||
heartbeat_id: Uuid::new_v4().to_string(),
|
||||
daemon_id: daemon_id.to_string(),
|
||||
cluster_id: cluster_id.to_string(),
|
||||
provider_incarnation: args.provider_incarnation.clone(),
|
||||
sequence: iteration.saturating_add(1),
|
||||
status: "ready".to_string(),
|
||||
heartbeat_at,
|
||||
private_state_exposed: false,
|
||||
startup_lifecycle_receipt_id: args.startup_lifecycle_receipt_id.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
fn print_output(
|
||||
args: &Args,
|
||||
status: &str,
|
||||
written: Vec<EpiphanyCultMeshDaemonStatusEntry>,
|
||||
written: Vec<EpiphanyCultMeshDaemonHeartbeatEventEntry>,
|
||||
) -> Result<()> {
|
||||
let latest = written
|
||||
.last()
|
||||
|
|
@ -115,7 +145,10 @@ fn print_output(
|
|||
"daemonId": latest.daemon_id,
|
||||
"clusterId": latest.cluster_id,
|
||||
"daemonStatus": latest.status,
|
||||
"lastHeartbeatUtc": latest.last_heartbeat_utc,
|
||||
"heartbeatId": latest.heartbeat_id,
|
||||
"providerIncarnation": latest.provider_incarnation,
|
||||
"sequence": latest.sequence,
|
||||
"lastHeartbeatUtc": latest.heartbeat_at,
|
||||
"heartbeatCount": written.len(),
|
||||
"intervalSeconds": args.interval_seconds,
|
||||
"maxIterations": args.max_iterations,
|
||||
|
|
@ -132,6 +165,8 @@ struct Args {
|
|||
daemon_id: String,
|
||||
interval_seconds: u64,
|
||||
max_iterations: u64,
|
||||
provider_incarnation: String,
|
||||
startup_lifecycle_receipt_id: String,
|
||||
}
|
||||
|
||||
impl Args {
|
||||
|
|
@ -143,6 +178,9 @@ impl Args {
|
|||
let mut daemon_id = None;
|
||||
let mut interval_seconds = 60_u64;
|
||||
let mut max_iterations = 1_u64;
|
||||
let mut provider_incarnation = None;
|
||||
let mut startup_lifecycle_receipt_id =
|
||||
env::var("EPIPHANY_STARTUP_LIFECYCLE_RECEIPT_ID").unwrap_or_default();
|
||||
|
||||
while let Some(arg) = values.next() {
|
||||
match arg.as_str() {
|
||||
|
|
@ -165,6 +203,18 @@ impl Args {
|
|||
.context("missing --max-iterations value")?
|
||||
.parse()?;
|
||||
}
|
||||
"--provider-incarnation" => {
|
||||
provider_incarnation = Some(
|
||||
values
|
||||
.next()
|
||||
.context("missing --provider-incarnation value")?,
|
||||
)
|
||||
}
|
||||
"--startup-lifecycle-receipt-id" => {
|
||||
startup_lifecycle_receipt_id = values
|
||||
.next()
|
||||
.context("missing --startup-lifecycle-receipt-id value")?
|
||||
}
|
||||
other => anyhow::bail!("unknown argument {other:?}"),
|
||||
}
|
||||
}
|
||||
|
|
@ -177,6 +227,47 @@ impl Args {
|
|||
daemon_id,
|
||||
interval_seconds,
|
||||
max_iterations,
|
||||
provider_incarnation: provider_incarnation
|
||||
.unwrap_or_else(|| Uuid::new_v4().to_string()),
|
||||
startup_lifecycle_receipt_id,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn process_heartbeat_events_keep_one_incarnation_and_increment_sequence() {
|
||||
let args = Args {
|
||||
command: "serve".to_string(),
|
||||
store: PathBuf::from("unused.ccmp"),
|
||||
runtime_id: "runtime-test".to_string(),
|
||||
daemon_id: "daemon-test".to_string(),
|
||||
interval_seconds: 1,
|
||||
max_iterations: 2,
|
||||
provider_incarnation: "incarnation-test".to_string(),
|
||||
startup_lifecycle_receipt_id: "receipt-test".to_string(),
|
||||
};
|
||||
let first = new_heartbeat_event(
|
||||
&args,
|
||||
"daemon-test",
|
||||
"cluster-test",
|
||||
0,
|
||||
"2026-07-15T12:00:00Z".to_string(),
|
||||
);
|
||||
let second = new_heartbeat_event(
|
||||
&args,
|
||||
"daemon-test",
|
||||
"cluster-test",
|
||||
1,
|
||||
"2026-07-15T12:00:01Z".to_string(),
|
||||
);
|
||||
assert_eq!(first.provider_incarnation, second.provider_incarnation);
|
||||
assert_eq!(first.sequence, 1);
|
||||
assert_eq!(second.sequence, 2);
|
||||
assert_ne!(first.heartbeat_id, second.heartbeat_id);
|
||||
assert_eq!(first.startup_lifecycle_receipt_id, "receipt-test");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,10 +16,14 @@ use epiphany_core::EpiphanyCultMeshSwarmBrakeEntry;
|
|||
use epiphany_core::EpiphanyLocalVerseContext;
|
||||
use epiphany_core::EpiphanyProcessObservation as ProcessObservation;
|
||||
use epiphany_core::EpiphanyServiceExecutionAuditReport;
|
||||
use epiphany_core::MemorySemanticProjectionInput;
|
||||
use epiphany_core::agent_memory_semantic_projection_input;
|
||||
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::idunn_acquire_memory_semantic_projection_for_local_supervisor;
|
||||
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;
|
||||
|
|
@ -29,6 +33,7 @@ use epiphany_core::load_epiphany_cultmesh_status;
|
|||
use epiphany_core::load_epiphany_cultmesh_swarm_brake;
|
||||
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::seed_epiphany_local_verse_context;
|
||||
use epiphany_core::write_epiphany_cultmesh_daemon_poke_intent;
|
||||
use epiphany_core::write_epiphany_cultmesh_daemon_poke_receipt;
|
||||
|
|
@ -130,12 +135,82 @@ fn main() -> Result<()> {
|
|||
"windows-service-start" | "service-start" => windows_service_control(args, "start"),
|
||||
"windows-service-stop" | "service-stop" => windows_service_control(args, "stop"),
|
||||
"policy" | "write-policy" => write_policy(args),
|
||||
"semantic-acquire" => semantic_acquire(args),
|
||||
"semantic-recover" => semantic_recover(args),
|
||||
other => anyhow::bail!(
|
||||
"unknown command {other:?}; use reconcile, tick, serve, service-plan, service-launch, service-runbook, repo-work-service-audit, cluster-service-runbook, cluster-service-install-plan, cluster-service-audit, cluster-service-start, cluster-service-stop, cluster-service-execution-readiness, cluster-service-execution-runbook, cluster-service-execution-audit, windows-service-install, windows-service-execution-readiness, windows-service-execution-runbook, windows-service-execution-audit, service-execution-audit-smoke, windows-service-reconcile, windows-service-status, windows-service-start, windows-service-stop, or policy"
|
||||
"unknown command {other:?}; use reconcile, tick, serve, service-plan, service-launch, service-runbook, repo-work-service-audit, cluster-service-runbook, cluster-service-install-plan, cluster-service-audit, cluster-service-start, cluster-service-stop, cluster-service-execution-readiness, cluster-service-execution-runbook, cluster-service-execution-audit, windows-service-install, windows-service-execution-readiness, windows-service-execution-runbook, windows-service-execution-audit, service-execution-audit-smoke, windows-service-reconcile, windows-service-status, windows-service-start, windows-service-stop, policy, semantic-acquire, or semantic-recover"
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
fn semantic_projection_input(args: &Args) -> Result<(MemorySemanticProjectionInput, &Path)> {
|
||||
match (&args.agent_store, &args.runtime_store) {
|
||||
(Some(path), None) => Ok((agent_memory_semantic_projection_input(path)?, path)),
|
||||
(None, Some(path)) => Ok((runtime_modeling_semantic_projection_input(path)?, path)),
|
||||
_ => anyhow::bail!(
|
||||
"semantic projector commands require exactly one of --agent-store or --runtime-store"
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
fn required<'a>(value: &'a Option<String>, flag: &str) -> Result<&'a str> {
|
||||
value.as_deref().with_context(|| format!("missing {flag}"))
|
||||
}
|
||||
|
||||
fn semantic_acquire(args: Args) -> Result<()> {
|
||||
let (input, store) = semantic_projection_input(&args)?;
|
||||
let purpose = required(&args.semantic_purpose, "--purpose")?;
|
||||
if !matches!(purpose, "execute" | "repair") {
|
||||
anyhow::bail!("--purpose must be execute or repair");
|
||||
}
|
||||
let acquisition = idunn_acquire_memory_semantic_projection_for_local_supervisor(
|
||||
store,
|
||||
&input,
|
||||
required(&args.executor_id, "--executor-id")?,
|
||||
purpose,
|
||||
&Utc::now().to_rfc3339(),
|
||||
)?;
|
||||
println!(
|
||||
"{}",
|
||||
serde_json::to_string_pretty(&json!({
|
||||
"grantId": acquisition.grant.grant_id,
|
||||
"claimId": acquisition.claim.claim_id,
|
||||
"epoch": acquisition.claim.epoch,
|
||||
"executorId": acquisition.claim.executor_id,
|
||||
"purpose": purpose,
|
||||
"privateStateExposed": false
|
||||
}))?
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn semantic_recover(args: Args) -> Result<()> {
|
||||
let (input, store) = semantic_projection_input(&args)?;
|
||||
let (authorization, claim) = idunn_recover_memory_semantic_projection_from_cultmesh(
|
||||
&args.store,
|
||||
args.runtime_id.clone(),
|
||||
store,
|
||||
&input,
|
||||
required(&args.expected_claim_id, "--expected-claim-id")?,
|
||||
required(&args.executor_id, "--executor-id")?,
|
||||
required(&args.receipt_id, "--receipt-id")?,
|
||||
required(&args.provider_heartbeat_id, "--provider-heartbeat-id")?,
|
||||
&Utc::now().to_rfc3339(),
|
||||
)?;
|
||||
println!(
|
||||
"{}",
|
||||
serde_json::to_string_pretty(&json!({
|
||||
"authorizationId": authorization.authorization_id,
|
||||
"claimId": claim.claim_id,
|
||||
"epoch": claim.epoch,
|
||||
"executorId": claim.executor_id,
|
||||
"executorIncarnation": claim.executor_incarnation,
|
||||
"privateStateExposed": false
|
||||
}))?
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn require_supervisor_bootstrap(args: &Args) -> Result<()> {
|
||||
load_epiphany_cultmesh_status(&args.store, args.runtime_id.clone())?
|
||||
.with_context(|| {
|
||||
|
|
@ -2667,7 +2742,7 @@ fn reconcile_daemon_status(
|
|||
)?;
|
||||
|
||||
let attempted_at = Utc::now();
|
||||
let restart_output = run_restart_command(policy)?;
|
||||
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 {
|
||||
|
|
@ -3344,9 +3419,16 @@ fn service_lifecycle_receipt(
|
|||
}
|
||||
}
|
||||
|
||||
fn run_restart_command(policy: &EpiphanyCultMeshDaemonRestartPolicyEntry) -> Result<RestartOutput> {
|
||||
fn run_restart_command(
|
||||
policy: &EpiphanyCultMeshDaemonRestartPolicyEntry,
|
||||
lifecycle_receipt_id: &str,
|
||||
) -> Result<RestartOutput> {
|
||||
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);
|
||||
}
|
||||
|
|
@ -3499,6 +3581,38 @@ mod provider_status_ownership_tests {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod semantic_projector_authority_tests {
|
||||
#[test]
|
||||
fn supervisor_owns_idunn_incarnations_and_exact_evidence_selection() {
|
||||
let source = include_str!("epiphany-daemon-supervisor.rs");
|
||||
let issuer_flag = ["--issuer", "-incarnation"].concat();
|
||||
let executor_flag = ["--executor", "-incarnation"].concat();
|
||||
assert!(!source.contains(&issuer_flag));
|
||||
assert!(!source.contains(&executor_flag));
|
||||
let evidence_id_flag = ["--lifecycle", "-evidence-id"].concat();
|
||||
let evidence_hash_flag = ["--lifecycle", "-evidence-hash"].concat();
|
||||
assert!(!source.contains(&evidence_id_flag));
|
||||
assert!(!source.contains(&evidence_hash_flag));
|
||||
assert!(source.contains("--receipt-id"));
|
||||
assert!(source.contains("--provider-heartbeat-id"));
|
||||
assert!(source.contains("idunn_acquire_memory_semantic_projection_for_local_supervisor"));
|
||||
assert!(source.contains("idunn_recover_memory_semantic_projection_from_cultmesh"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn recovery_command_only_rotates_claim_authority() {
|
||||
let source = include_str!("epiphany-daemon-supervisor.rs");
|
||||
let start = source.find("fn semantic_recover(args: Args)").unwrap();
|
||||
let tail = &source[start..];
|
||||
let end = tail.find("\nfn ").unwrap_or(tail.len());
|
||||
let body = &tail[..end];
|
||||
assert!(body.contains("idunn_recover_memory_semantic_projection_from_cultmesh"));
|
||||
assert!(!body.contains("execute_memory_semantic_projection"));
|
||||
assert!(!body.contains("MemorySemanticIndexConfig"));
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct Args {
|
||||
command: String,
|
||||
|
|
@ -3538,6 +3652,12 @@ struct Args {
|
|||
artifact_ref: Option<String>,
|
||||
stdout_artifact: Option<PathBuf>,
|
||||
stderr_artifact: Option<PathBuf>,
|
||||
agent_store: Option<PathBuf>,
|
||||
runtime_store: Option<PathBuf>,
|
||||
executor_id: Option<String>,
|
||||
semantic_purpose: Option<String>,
|
||||
expected_claim_id: Option<String>,
|
||||
provider_heartbeat_id: Option<String>,
|
||||
}
|
||||
|
||||
impl Args {
|
||||
|
|
@ -3581,6 +3701,12 @@ impl Args {
|
|||
let mut artifact_ref = None;
|
||||
let mut stdout_artifact = None;
|
||||
let mut stderr_artifact = None;
|
||||
let mut agent_store = None;
|
||||
let mut runtime_store = None;
|
||||
let mut executor_id = None;
|
||||
let mut semantic_purpose = None;
|
||||
let mut expected_claim_id = None;
|
||||
let mut provider_heartbeat_id = None;
|
||||
|
||||
while let Some(arg) = values.next() {
|
||||
match arg.as_str() {
|
||||
|
|
@ -3723,6 +3849,33 @@ impl Args {
|
|||
values.next().context("missing --stderr-artifact value")?,
|
||||
));
|
||||
}
|
||||
"--agent-store" => {
|
||||
agent_store = Some(PathBuf::from(
|
||||
values.next().context("missing --agent-store value")?,
|
||||
))
|
||||
}
|
||||
"--runtime-store" => {
|
||||
runtime_store = Some(PathBuf::from(
|
||||
values.next().context("missing --runtime-store value")?,
|
||||
))
|
||||
}
|
||||
"--executor-id" => {
|
||||
executor_id = Some(values.next().context("missing --executor-id value")?)
|
||||
}
|
||||
"--purpose" => {
|
||||
semantic_purpose = Some(values.next().context("missing --purpose value")?)
|
||||
}
|
||||
"--expected-claim-id" => {
|
||||
expected_claim_id =
|
||||
Some(values.next().context("missing --expected-claim-id value")?)
|
||||
}
|
||||
"--provider-heartbeat-id" => {
|
||||
provider_heartbeat_id = Some(
|
||||
values
|
||||
.next()
|
||||
.context("missing --provider-heartbeat-id value")?,
|
||||
)
|
||||
}
|
||||
other => anyhow::bail!("unknown argument {other:?}"),
|
||||
}
|
||||
}
|
||||
|
|
@ -3804,6 +3957,8 @@ impl Args {
|
|||
| "service-start"
|
||||
| "windows-service-stop"
|
||||
| "service-stop"
|
||||
| "semantic-acquire"
|
||||
| "semantic-recover"
|
||||
) =>
|
||||
{
|
||||
"*".to_string()
|
||||
|
|
@ -3858,6 +4013,12 @@ impl Args {
|
|||
artifact_ref,
|
||||
stdout_artifact,
|
||||
stderr_artifact,
|
||||
agent_store,
|
||||
runtime_store,
|
||||
executor_id,
|
||||
semantic_purpose,
|
||||
expected_claim_id,
|
||||
provider_heartbeat_id,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,12 +18,12 @@ fn main() -> Result<()> {
|
|||
match command.as_str() {
|
||||
"index" => {
|
||||
let (input, source_store) = options.load_projection_input()?;
|
||||
let executor_id = options
|
||||
.executor_id
|
||||
let claim_id = options
|
||||
.claim_id
|
||||
.as_deref()
|
||||
.ok_or_else(|| usage_error("index requires --executor-id <id>"))?;
|
||||
.ok_or_else(|| usage_error("index requires --claim-id <id>"))?;
|
||||
let receipt =
|
||||
execute_memory_semantic_projection(source_store, &input, executor_id, &config)?;
|
||||
execute_memory_semantic_projection(source_store, &input, claim_id, &config)?;
|
||||
print_receipt(&receipt, source_store)?;
|
||||
}
|
||||
"health" => {
|
||||
|
|
@ -82,7 +82,7 @@ struct Options {
|
|||
graph_store: Option<PathBuf>,
|
||||
runtime_store: Option<PathBuf>,
|
||||
agent_store: Option<PathBuf>,
|
||||
executor_id: Option<String>,
|
||||
claim_id: Option<String>,
|
||||
local_verse_store: Option<PathBuf>,
|
||||
runtime_id: String,
|
||||
provider_incarnation: Option<String>,
|
||||
|
|
@ -100,7 +100,7 @@ impl Options {
|
|||
graph_store: None,
|
||||
runtime_store: None,
|
||||
agent_store: None,
|
||||
executor_id: None,
|
||||
claim_id: None,
|
||||
local_verse_store: None,
|
||||
runtime_id: "epiphany-memory-semantic".to_string(),
|
||||
provider_incarnation: None,
|
||||
|
|
@ -121,7 +121,7 @@ impl Options {
|
|||
"--graph-store" => options.graph_store = Some(PathBuf::from(value()?)),
|
||||
"--runtime-store" => options.runtime_store = Some(PathBuf::from(value()?)),
|
||||
"--agent-store" => options.agent_store = Some(PathBuf::from(value()?)),
|
||||
"--executor-id" => options.executor_id = Some(value()?),
|
||||
"--claim-id" => options.claim_id = Some(value()?),
|
||||
"--local-verse-store" => options.local_verse_store = Some(PathBuf::from(value()?)),
|
||||
"--runtime-id" => options.runtime_id = value()?,
|
||||
"--provider-incarnation" => options.provider_incarnation = Some(value()?),
|
||||
|
|
@ -235,7 +235,7 @@ fn parse_profile(value: &str) -> Result<epiphany_core::EpiphanyMemoryProfile> {
|
|||
|
||||
fn usage_error(message: &str) -> anyhow::Error {
|
||||
anyhow!(
|
||||
"{message}\nusage: epiphany-memory-semantic <index|context|health> (--runtime-store <path>|--agent-store <path>|--graph-store <path>) [--swarm-id <id>] --partition <mind|modeling> [--executor-id <id>] [--local-verse-store <path> --runtime-id <id> --provider-incarnation <id>] [--text <query>] [--query-id <id>] [--budget <n>] [--profile <profile>]"
|
||||
"{message}\nusage: epiphany-memory-semantic <index|context|health> (--runtime-store <path>|--agent-store <path>|--graph-store <path>) [--swarm-id <id>] --partition <mind|modeling> [--claim-id <id>] [--local-verse-store <path> --runtime-id <id> --provider-incarnation <id>] [--text <query>] [--query-id <id>] [--budget <n>] [--profile <profile>]"
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,10 @@ use cultmesh_rs::CultMeshNodeOptions;
|
|||
use cultmesh_rs::cultmesh_documents;
|
||||
use serde::Serialize;
|
||||
use serde_json::Value;
|
||||
use sha2::Digest;
|
||||
use sha2::Sha256;
|
||||
use std::path::Path;
|
||||
use uuid::Uuid;
|
||||
|
||||
pub const EPIPHANY_CULTMESH_STATUS_TYPE: &str = "epiphany.cultmesh.status";
|
||||
pub const EPIPHANY_CULTMESH_STATUS_SCHEMA_VERSION: &str = "epiphany.cultmesh.status.v0";
|
||||
|
|
@ -124,6 +127,10 @@ pub const EPIPHANY_CULTMESH_EVE_SURFACE_STATE_SCHEMA_VERSION: &str =
|
|||
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";
|
||||
|
|
@ -1218,6 +1225,34 @@ pub struct EpiphanyCultMeshDaemonStatusEntry {
|
|||
pub notes: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, DatabaseEntry)]
|
||||
#[cultcache(
|
||||
type = "epiphany.cultmesh.daemon_heartbeat_event",
|
||||
schema = "EpiphanyCultMeshDaemonHeartbeatEventEntry"
|
||||
)]
|
||||
pub struct EpiphanyCultMeshDaemonHeartbeatEventEntry {
|
||||
#[cultcache(key = 0)]
|
||||
pub schema_version: String,
|
||||
#[cultcache(key = 1)]
|
||||
pub heartbeat_id: String,
|
||||
#[cultcache(key = 2)]
|
||||
pub daemon_id: String,
|
||||
#[cultcache(key = 3)]
|
||||
pub cluster_id: String,
|
||||
#[cultcache(key = 4)]
|
||||
pub provider_incarnation: String,
|
||||
#[cultcache(key = 5)]
|
||||
pub sequence: u64,
|
||||
#[cultcache(key = 6)]
|
||||
pub status: String,
|
||||
#[cultcache(key = 7)]
|
||||
pub heartbeat_at: String,
|
||||
#[cultcache(key = 8)]
|
||||
pub private_state_exposed: bool,
|
||||
#[cultcache(key = 9, default)]
|
||||
pub startup_lifecycle_receipt_id: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, DatabaseEntry)]
|
||||
#[cultcache(
|
||||
type = "epiphany.cultmesh.daemon_poke_intent",
|
||||
|
|
@ -2584,6 +2619,7 @@ cultmesh_documents!(EpiphanyCultMeshDocuments {
|
|||
EpiphanyCultMeshEveConnectionReceiptEntry => EPIPHANY_CULTMESH_EVE_CONNECTION_RECEIPT_SCHEMA_VERSION,
|
||||
EpiphanyCultMeshEveSurfaceStateEntry => EPIPHANY_CULTMESH_EVE_SURFACE_STATE_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,
|
||||
|
|
@ -3950,6 +3986,18 @@ pub fn load_latest_epiphany_cultmesh_daemon_poke_intent(
|
|||
node.get(EPIPHANY_CULTMESH_DAEMON_POKE_INTENT_LATEST_KEY)
|
||||
}
|
||||
|
||||
pub fn load_epiphany_cultmesh_daemon_poke_intent(
|
||||
store_path: impl AsRef<Path>,
|
||||
runtime_id: impl Into<String>,
|
||||
intent_id: &str,
|
||||
) -> Result<Option<EpiphanyCultMeshDaemonPokeIntentEntry>> {
|
||||
if intent_id.trim().is_empty() {
|
||||
return Err(anyhow!("daemon poke intent identity is required"));
|
||||
}
|
||||
let node = open_epiphany_cultmesh_node(store_path, runtime_id)?;
|
||||
node.get(&epiphany_cultmesh_daemon_poke_intent_key(intent_id))
|
||||
}
|
||||
|
||||
pub fn load_latest_epiphany_cultmesh_daemon_poke_receipt(
|
||||
store_path: impl AsRef<Path>,
|
||||
runtime_id: impl Into<String>,
|
||||
|
|
@ -3958,6 +4006,18 @@ pub fn load_latest_epiphany_cultmesh_daemon_poke_receipt(
|
|||
node.get(EPIPHANY_CULTMESH_DAEMON_POKE_RECEIPT_LATEST_KEY)
|
||||
}
|
||||
|
||||
pub fn load_epiphany_cultmesh_daemon_poke_receipt(
|
||||
store_path: impl AsRef<Path>,
|
||||
runtime_id: impl Into<String>,
|
||||
receipt_id: &str,
|
||||
) -> Result<Option<EpiphanyCultMeshDaemonPokeReceiptEntry>> {
|
||||
if receipt_id.trim().is_empty() {
|
||||
return Err(anyhow!("daemon poke receipt identity is required"));
|
||||
}
|
||||
let node = open_epiphany_cultmesh_node(store_path, runtime_id)?;
|
||||
node.get(&epiphany_cultmesh_daemon_poke_receipt_key(receipt_id))
|
||||
}
|
||||
|
||||
pub fn write_epiphany_cultmesh_daemon_restart_policy(
|
||||
store_path: impl AsRef<Path>,
|
||||
runtime_id: impl Into<String>,
|
||||
|
|
@ -7000,6 +7060,288 @@ pub fn write_epiphany_cultmesh_daemon_status(
|
|||
Ok(written)
|
||||
}
|
||||
|
||||
fn epiphany_cultmesh_daemon_heartbeat_event_key(heartbeat_id: &str) -> String {
|
||||
format!("epiphany-local/daemon-heartbeat/event/{heartbeat_id}")
|
||||
}
|
||||
|
||||
fn epiphany_cultmesh_daemon_heartbeat_latest_key(daemon_id: &str) -> String {
|
||||
format!("epiphany-local/daemon-heartbeat/{daemon_id}/latest")
|
||||
}
|
||||
|
||||
pub fn write_epiphany_cultmesh_daemon_heartbeat_event(
|
||||
store_path: impl AsRef<Path>,
|
||||
runtime_id: impl Into<String>,
|
||||
event: EpiphanyCultMeshDaemonHeartbeatEventEntry,
|
||||
) -> Result<EpiphanyCultMeshDaemonHeartbeatEventEntry> {
|
||||
validate_daemon_heartbeat_event(&event)?;
|
||||
let store_path = store_path.as_ref();
|
||||
let runtime_id = runtime_id.into();
|
||||
let event_key = epiphany_cultmesh_daemon_heartbeat_event_key(&event.heartbeat_id);
|
||||
let latest_key = epiphany_cultmesh_daemon_heartbeat_latest_key(&event.daemon_id);
|
||||
let backing = SingleFileMessagePackBackingStore::new(store_path);
|
||||
|
||||
for _ in 0..8 {
|
||||
let node = open_epiphany_cultmesh_node(store_path, runtime_id.clone())?;
|
||||
if let Some(existing) = node.get::<EpiphanyCultMeshDaemonHeartbeatEventEntry>(&event_key)? {
|
||||
return if existing == event {
|
||||
Ok(existing)
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"immutable daemon heartbeat identity collision for {:?}",
|
||||
event.heartbeat_id
|
||||
))
|
||||
};
|
||||
}
|
||||
let latest = node.get::<EpiphanyCultMeshDaemonHeartbeatEventEntry>(&latest_key)?;
|
||||
let advances_latest = match latest.as_ref() {
|
||||
Some(current) => daemon_heartbeat_advances(current, &event)?,
|
||||
None => true,
|
||||
};
|
||||
let event_envelope = node.cache().prepare_entry(&event_key, &event)?.0;
|
||||
let mut replacements = vec![event_envelope];
|
||||
let mut expected = Vec::new();
|
||||
if advances_latest {
|
||||
if let Some(envelope) = node
|
||||
.cache()
|
||||
.get_envelope::<EpiphanyCultMeshDaemonHeartbeatEventEntry>(&latest_key)?
|
||||
{
|
||||
expected.push(envelope);
|
||||
}
|
||||
replacements.push(node.cache().prepare_entry(&latest_key, &event)?.0);
|
||||
}
|
||||
if backing.compare_and_swap_batch(&expected, replacements)? {
|
||||
return Ok(event);
|
||||
}
|
||||
}
|
||||
Err(anyhow!(
|
||||
"daemon heartbeat latest advanced during publication"
|
||||
))
|
||||
}
|
||||
|
||||
pub fn load_epiphany_cultmesh_daemon_heartbeat_event(
|
||||
store_path: impl AsRef<Path>,
|
||||
runtime_id: impl Into<String>,
|
||||
heartbeat_id: &str,
|
||||
) -> Result<Option<EpiphanyCultMeshDaemonHeartbeatEventEntry>> {
|
||||
validate_heartbeat_identifier("heartbeat", heartbeat_id)?;
|
||||
open_epiphany_cultmesh_node(store_path, runtime_id)?
|
||||
.get(&epiphany_cultmesh_daemon_heartbeat_event_key(heartbeat_id))
|
||||
}
|
||||
|
||||
pub fn load_latest_epiphany_cultmesh_daemon_heartbeat(
|
||||
store_path: impl AsRef<Path>,
|
||||
runtime_id: impl Into<String>,
|
||||
daemon_id: &str,
|
||||
) -> Result<Option<EpiphanyCultMeshDaemonHeartbeatEventEntry>> {
|
||||
validate_heartbeat_identifier("daemon", daemon_id)?;
|
||||
open_epiphany_cultmesh_node(store_path, runtime_id)?
|
||||
.get(&epiphany_cultmesh_daemon_heartbeat_latest_key(daemon_id))
|
||||
}
|
||||
|
||||
pub fn idunn_acquire_memory_semantic_projection_for_local_supervisor(
|
||||
canonical_store: impl AsRef<Path>,
|
||||
input: &crate::MemorySemanticProjectionInput,
|
||||
executor_id: &str,
|
||||
purpose: &str,
|
||||
acquired_at: &str,
|
||||
) -> Result<crate::MemorySemanticProjectorAcquisition> {
|
||||
crate::memory_graph::semantic_projector::idunn_acquire_memory_semantic_projection(
|
||||
canonical_store,
|
||||
input,
|
||||
executor_id,
|
||||
&format!("executor-{}", Uuid::new_v4()),
|
||||
purpose,
|
||||
&format!("idunn-{}", Uuid::new_v4()),
|
||||
acquired_at,
|
||||
)
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn idunn_recover_memory_semantic_projection_from_cultmesh(
|
||||
verse_store: impl AsRef<Path>,
|
||||
runtime_id: impl Into<String>,
|
||||
canonical_store: impl AsRef<Path>,
|
||||
input: &crate::MemorySemanticProjectionInput,
|
||||
expected_claim_id: &str,
|
||||
replacement_executor_id: &str,
|
||||
lifecycle_receipt_id: &str,
|
||||
provider_heartbeat_id: &str,
|
||||
recovered_at: &str,
|
||||
) -> Result<(
|
||||
crate::MemorySemanticProjectorRecoveryAuthorization,
|
||||
crate::MemorySemanticProjectionClaim,
|
||||
)> {
|
||||
let verse_store = verse_store.as_ref();
|
||||
let runtime_id = runtime_id.into();
|
||||
let canonical_store = canonical_store.as_ref();
|
||||
crate::observe_memory_semantic_projection(canonical_store, input)?;
|
||||
|
||||
let node = open_epiphany_cultmesh_node(verse_store, runtime_id)?;
|
||||
let receipt_key = epiphany_cultmesh_daemon_poke_receipt_key(lifecycle_receipt_id);
|
||||
let receipt = node
|
||||
.get::<EpiphanyCultMeshDaemonPokeReceiptEntry>(&receipt_key)?
|
||||
.ok_or_else(|| anyhow!("Idunn recovery lifecycle receipt is absent"))?;
|
||||
validate_daemon_poke_receipt(&receipt)?;
|
||||
if receipt.receipt_id != lifecycle_receipt_id
|
||||
|| receipt.target_daemon_id != "epiphany-memory-semantic-projector"
|
||||
|| receipt.status != "restart-succeeded"
|
||||
|| receipt.resulting_status != "awaiting-provider-heartbeat"
|
||||
{
|
||||
return Err(anyhow!(
|
||||
"Idunn recovery requires the exact successful awaiting-heartbeat receipt"
|
||||
));
|
||||
}
|
||||
|
||||
let intent_key = epiphany_cultmesh_daemon_poke_intent_key(&receipt.intent_id);
|
||||
let intent = node
|
||||
.get::<EpiphanyCultMeshDaemonPokeIntentEntry>(&intent_key)?
|
||||
.ok_or_else(|| anyhow!("Idunn recovery lifecycle intent is absent"))?;
|
||||
validate_daemon_poke_intent(&intent)?;
|
||||
if intent.intent_id != receipt.intent_id
|
||||
|| intent.target_daemon_id != receipt.target_daemon_id
|
||||
|| intent.target_cluster_id != receipt.target_cluster_id
|
||||
{
|
||||
return Err(anyhow!("Idunn recovery lifecycle chain disagrees"));
|
||||
}
|
||||
|
||||
let heartbeat_key = epiphany_cultmesh_daemon_heartbeat_event_key(provider_heartbeat_id);
|
||||
let heartbeat = node
|
||||
.get::<EpiphanyCultMeshDaemonHeartbeatEventEntry>(&heartbeat_key)?
|
||||
.ok_or_else(|| anyhow!("Idunn recovery provider heartbeat is absent"))?;
|
||||
validate_daemon_heartbeat_event(&heartbeat)?;
|
||||
if heartbeat.heartbeat_id != provider_heartbeat_id
|
||||
|| heartbeat.daemon_id != receipt.target_daemon_id
|
||||
|| heartbeat.cluster_id != receipt.target_cluster_id
|
||||
|| heartbeat.status != "ready"
|
||||
|| heartbeat.startup_lifecycle_receipt_id != receipt.receipt_id
|
||||
{
|
||||
return Err(anyhow!("Idunn recovery provider heartbeat disagrees"));
|
||||
}
|
||||
let receipt_completed = DateTime::parse_from_rfc3339(&receipt.completed_at_utc)?;
|
||||
let heartbeat_at = DateTime::parse_from_rfc3339(&heartbeat.heartbeat_at)?;
|
||||
if heartbeat_at <= receipt_completed {
|
||||
return Err(anyhow!(
|
||||
"Idunn recovery heartbeat must follow lifecycle completion"
|
||||
));
|
||||
}
|
||||
|
||||
let intent_digest =
|
||||
cultmesh_envelope_digest::<EpiphanyCultMeshDaemonPokeIntentEntry>(&node, &intent_key)?;
|
||||
let receipt_digest =
|
||||
cultmesh_envelope_digest::<EpiphanyCultMeshDaemonPokeReceiptEntry>(&node, &receipt_key)?;
|
||||
let heartbeat_digest = cultmesh_envelope_digest::<EpiphanyCultMeshDaemonHeartbeatEventEntry>(
|
||||
&node,
|
||||
&heartbeat_key,
|
||||
)?;
|
||||
let evidence =
|
||||
crate::memory_graph::semantic_projector::idunn_semantic_recovery_evidence_from_cultmesh(
|
||||
canonical_store,
|
||||
input,
|
||||
expected_claim_id,
|
||||
&format!("idunn-{}", Uuid::new_v4()),
|
||||
&intent.intent_id,
|
||||
&intent_digest,
|
||||
&receipt.receipt_id,
|
||||
&receipt_digest,
|
||||
&receipt.completed_at_utc,
|
||||
&heartbeat.heartbeat_id,
|
||||
&heartbeat_digest,
|
||||
&heartbeat.provider_incarnation,
|
||||
&heartbeat.heartbeat_at,
|
||||
&heartbeat.startup_lifecycle_receipt_id,
|
||||
)?;
|
||||
crate::memory_graph::semantic_projector::idunn_recover_memory_semantic_projection(
|
||||
canonical_store,
|
||||
input,
|
||||
expected_claim_id,
|
||||
replacement_executor_id,
|
||||
&heartbeat.provider_incarnation,
|
||||
&evidence,
|
||||
recovered_at,
|
||||
)
|
||||
}
|
||||
|
||||
fn cultmesh_envelope_digest<T: DatabaseEntry>(node: &CultMeshNode, key: &str) -> Result<String> {
|
||||
let envelope = node
|
||||
.cache()
|
||||
.get_envelope::<T>(key)?
|
||||
.ok_or_else(|| anyhow!("authenticated CultMesh evidence envelope disappeared"))?;
|
||||
let mut digest = Sha256::new();
|
||||
digest.update(envelope.r#type.as_bytes());
|
||||
digest.update([0]);
|
||||
digest.update(envelope.key.as_bytes());
|
||||
digest.update([0]);
|
||||
digest.update(&envelope.payload);
|
||||
Ok(format!("sha256-{:x}", digest.finalize()))
|
||||
}
|
||||
|
||||
fn daemon_heartbeat_advances(
|
||||
current: &EpiphanyCultMeshDaemonHeartbeatEventEntry,
|
||||
candidate: &EpiphanyCultMeshDaemonHeartbeatEventEntry,
|
||||
) -> Result<bool> {
|
||||
validate_daemon_heartbeat_event(current)?;
|
||||
let current_time = DateTime::parse_from_rfc3339(¤t.heartbeat_at)?;
|
||||
let candidate_time = DateTime::parse_from_rfc3339(&candidate.heartbeat_at)?;
|
||||
if current.provider_incarnation == candidate.provider_incarnation {
|
||||
if candidate.sequence > current.sequence && candidate_time < current_time {
|
||||
return Err(anyhow!(
|
||||
"daemon heartbeat time regressed within provider incarnation"
|
||||
));
|
||||
}
|
||||
if candidate.sequence <= current.sequence {
|
||||
return Ok(false);
|
||||
}
|
||||
}
|
||||
Ok(
|
||||
(candidate_time, candidate.sequence, &candidate.heartbeat_id)
|
||||
> (current_time, current.sequence, ¤t.heartbeat_id),
|
||||
)
|
||||
}
|
||||
|
||||
fn validate_daemon_heartbeat_event(
|
||||
event: &EpiphanyCultMeshDaemonHeartbeatEventEntry,
|
||||
) -> Result<()> {
|
||||
if event.schema_version != EPIPHANY_CULTMESH_DAEMON_HEARTBEAT_EVENT_SCHEMA_VERSION {
|
||||
return Err(anyhow!("unsupported daemon heartbeat schema"));
|
||||
}
|
||||
validate_heartbeat_identifier("heartbeat", &event.heartbeat_id)?;
|
||||
validate_heartbeat_identifier("daemon", &event.daemon_id)?;
|
||||
validate_heartbeat_identifier("cluster", &event.cluster_id)?;
|
||||
validate_heartbeat_identifier("provider incarnation", &event.provider_incarnation)?;
|
||||
if !event.startup_lifecycle_receipt_id.is_empty() {
|
||||
validate_heartbeat_identifier(
|
||||
"startup lifecycle receipt",
|
||||
&event.startup_lifecycle_receipt_id,
|
||||
)?;
|
||||
}
|
||||
if event.sequence == 0 {
|
||||
return Err(anyhow!("daemon heartbeat sequence must be positive"));
|
||||
}
|
||||
if !matches!(event.status.as_str(), "ready" | "degraded" | "stopping") {
|
||||
return Err(anyhow!("invalid daemon heartbeat status"));
|
||||
}
|
||||
DateTime::parse_from_rfc3339(&event.heartbeat_at)
|
||||
.context("daemon heartbeat requires RFC3339 heartbeat_at")?;
|
||||
if event.private_state_exposed {
|
||||
return Err(anyhow!("daemon heartbeat must not expose private state"));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn validate_heartbeat_identifier(label: &str, value: &str) -> Result<()> {
|
||||
if value.is_empty()
|
||||
|| value.len() > 128
|
||||
|| !value
|
||||
.bytes()
|
||||
.all(|byte| byte.is_ascii_alphanumeric() || matches!(byte, b'-' | b'_' | b'.'))
|
||||
{
|
||||
return Err(anyhow!(
|
||||
"daemon heartbeat requires a bounded opaque {label} id"
|
||||
));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn validate_daemon_status(status: &EpiphanyCultMeshDaemonStatusEntry) -> Result<()> {
|
||||
if status.private_state_exposed {
|
||||
return Err(anyhow!("daemon statuses must not expose private state"));
|
||||
|
|
@ -7752,12 +8094,14 @@ mod tests {
|
|||
)?;
|
||||
assert_eq!(pending.status, "pending");
|
||||
|
||||
let claim = crate::memory_graph::semantic_projector::claim_memory_semantic_projection(
|
||||
let claim = idunn_acquire_memory_semantic_projection_for_local_supervisor(
|
||||
&canonical,
|
||||
input.obligation(),
|
||||
&input,
|
||||
"executor-a",
|
||||
"execute",
|
||||
"2026-07-15T12:01:00Z",
|
||||
)?;
|
||||
)?
|
||||
.claim;
|
||||
let raw_receipt = crate::MemorySemanticIndexReceipt {
|
||||
schema_version: crate::MEMORY_SEMANTIC_INDEX_RECEIPT_SCHEMA_VERSION.to_string(),
|
||||
receipt_id: "receipt-four-state".to_string(),
|
||||
|
|
@ -7800,18 +8144,14 @@ mod tests {
|
|||
assert_eq!(ready.status, "ready");
|
||||
assert!(ready.query_eligible_display_only);
|
||||
|
||||
let terminal_claim = crate::MemorySemanticProjectionClaim {
|
||||
status: "succeeded".to_string(),
|
||||
completed_at: Some("2026-07-15T12:02:01Z".to_string()),
|
||||
..claim.clone()
|
||||
};
|
||||
let repair = crate::memory_graph::semantic_projector::reopen_succeeded_projection_claim(
|
||||
let repair = idunn_acquire_memory_semantic_projection_for_local_supervisor(
|
||||
&canonical,
|
||||
&terminal_claim,
|
||||
input.obligation(),
|
||||
&input,
|
||||
"executor-b",
|
||||
"repair",
|
||||
"2026-07-15T12:03:00Z",
|
||||
)?;
|
||||
)?
|
||||
.claim;
|
||||
crate::memory_graph::semantic_projector::fail_memory_semantic_projection_claim(
|
||||
&canonical,
|
||||
&repair.claim_id,
|
||||
|
|
@ -10659,6 +10999,201 @@ mod tests {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn heartbeat_event(
|
||||
heartbeat_id: &str,
|
||||
incarnation: &str,
|
||||
sequence: u64,
|
||||
heartbeat_at: &str,
|
||||
) -> EpiphanyCultMeshDaemonHeartbeatEventEntry {
|
||||
EpiphanyCultMeshDaemonHeartbeatEventEntry {
|
||||
schema_version: EPIPHANY_CULTMESH_DAEMON_HEARTBEAT_EVENT_SCHEMA_VERSION.to_string(),
|
||||
heartbeat_id: heartbeat_id.to_string(),
|
||||
daemon_id: "daemon-test".to_string(),
|
||||
cluster_id: "cluster-test".to_string(),
|
||||
provider_incarnation: incarnation.to_string(),
|
||||
sequence,
|
||||
status: "ready".to_string(),
|
||||
heartbeat_at: heartbeat_at.to_string(),
|
||||
private_state_exposed: false,
|
||||
startup_lifecycle_receipt_id: String::new(),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn daemon_heartbeat_events_are_immutable_and_advance_latest_monotonically() -> Result<()> {
|
||||
let temp = tempfile::tempdir()?;
|
||||
let store = temp.path().join("daemon-heartbeats.ccmp");
|
||||
let first = heartbeat_event("heartbeat-1", "incarnation-a", 1, "2026-07-15T12:00:00Z");
|
||||
write_epiphany_cultmesh_daemon_heartbeat_event(&store, "runtime-test", first.clone())?;
|
||||
assert_eq!(
|
||||
load_epiphany_cultmesh_daemon_heartbeat_event(&store, "runtime-test", "heartbeat-1")?,
|
||||
Some(first.clone())
|
||||
);
|
||||
|
||||
let delayed = heartbeat_event(
|
||||
"heartbeat-delayed",
|
||||
"incarnation-a",
|
||||
1,
|
||||
"2026-07-15T11:59:59Z",
|
||||
);
|
||||
write_epiphany_cultmesh_daemon_heartbeat_event(&store, "runtime-test", delayed)?;
|
||||
assert_eq!(
|
||||
load_latest_epiphany_cultmesh_daemon_heartbeat(&store, "runtime-test", "daemon-test")?,
|
||||
Some(first.clone())
|
||||
);
|
||||
|
||||
let restarted = heartbeat_event("heartbeat-2", "incarnation-b", 1, "2026-07-15T12:00:01Z");
|
||||
write_epiphany_cultmesh_daemon_heartbeat_event(&store, "runtime-test", restarted.clone())?;
|
||||
assert_eq!(
|
||||
load_latest_epiphany_cultmesh_daemon_heartbeat(&store, "runtime-test", "daemon-test")?,
|
||||
Some(restarted)
|
||||
);
|
||||
|
||||
let mut collision = first.clone();
|
||||
collision.status = "degraded".to_string();
|
||||
assert!(
|
||||
write_epiphany_cultmesh_daemon_heartbeat_event(&store, "runtime-test", collision)
|
||||
.expect_err("heartbeat identity is immutable")
|
||||
.to_string()
|
||||
.contains("identity collision")
|
||||
);
|
||||
let mut private = heartbeat_event(
|
||||
"heartbeat-private",
|
||||
"incarnation-b",
|
||||
2,
|
||||
"2026-07-15T12:00:02Z",
|
||||
);
|
||||
private.private_state_exposed = true;
|
||||
assert!(
|
||||
write_epiphany_cultmesh_daemon_heartbeat_event(&store, "runtime-test", private)
|
||||
.expect_err("private heartbeat must be refused")
|
||||
.to_string()
|
||||
.contains("must not expose private state")
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn semantic_recovery_requires_exact_correlated_restart_heartbeat_and_is_single_use()
|
||||
-> Result<()> {
|
||||
let temp = tempfile::tempdir()?;
|
||||
let canonical = temp.path().join("canonical.msgpack");
|
||||
let verse = temp.path().join("verse.ccmp");
|
||||
let input = semantic_health_input(&canonical, "swarm-recovery", "mind", 1)?;
|
||||
let claim = idunn_acquire_memory_semantic_projection_for_local_supervisor(
|
||||
&canonical,
|
||||
&input,
|
||||
"executor-old",
|
||||
"execute",
|
||||
"2026-07-15T12:00:00Z",
|
||||
)?
|
||||
.claim;
|
||||
let status = EpiphanyCultMeshDaemonStatusEntry {
|
||||
schema_version: EPIPHANY_CULTMESH_DAEMON_STATUS_SCHEMA_VERSION.to_string(),
|
||||
daemon_id: "epiphany-memory-semantic-projector".to_string(),
|
||||
cluster_id: "local".to_string(),
|
||||
body_domain: "semantic-projection".to_string(),
|
||||
daemon_surface_id: "daemon.semantic-projector".to_string(),
|
||||
eve_surface_id: "eve.semantic-projector".to_string(),
|
||||
status: "stale".to_string(),
|
||||
last_heartbeat_utc: "2026-07-15T12:00:01Z".to_string(),
|
||||
supported_actions: vec!["pokeDaemon".to_string()],
|
||||
operator_action: "restart".to_string(),
|
||||
private_state_exposed: false,
|
||||
notes: Vec::new(),
|
||||
};
|
||||
let mut intent = epiphany_cultmesh_daemon_poke_intent_from_status(
|
||||
"semantic-restart-intent-1",
|
||||
"idunn",
|
||||
&status,
|
||||
"fence exact abandoned semantic projector claim",
|
||||
);
|
||||
intent.requested_at_utc = "2026-07-15T12:01:00Z".to_string();
|
||||
write_epiphany_cultmesh_daemon_poke_intent(&verse, "runtime-test", intent.clone())?;
|
||||
let mut receipt = epiphany_cultmesh_daemon_poke_receipt_for_intent(
|
||||
"semantic-restart-receipt-1",
|
||||
&intent,
|
||||
"restart-succeeded",
|
||||
"awaiting-provider-heartbeat",
|
||||
"process://semantic-projector/exit/0",
|
||||
);
|
||||
receipt.attempted_at_utc = "2026-07-15T12:01:00Z".to_string();
|
||||
receipt.completed_at_utc = "2026-07-15T12:02:00Z".to_string();
|
||||
write_epiphany_cultmesh_daemon_poke_receipt(&verse, "runtime-test", receipt.clone())?;
|
||||
|
||||
let unrelated = EpiphanyCultMeshDaemonHeartbeatEventEntry {
|
||||
schema_version: EPIPHANY_CULTMESH_DAEMON_HEARTBEAT_EVENT_SCHEMA_VERSION.to_string(),
|
||||
heartbeat_id: "semantic-heartbeat-unrelated".to_string(),
|
||||
daemon_id: status.daemon_id.clone(),
|
||||
cluster_id: status.cluster_id.clone(),
|
||||
provider_incarnation: "provider-new".to_string(),
|
||||
sequence: 1,
|
||||
status: "ready".to_string(),
|
||||
heartbeat_at: "2026-07-15T12:03:00Z".to_string(),
|
||||
private_state_exposed: false,
|
||||
startup_lifecycle_receipt_id: String::new(),
|
||||
};
|
||||
write_epiphany_cultmesh_daemon_heartbeat_event(&verse, "runtime-test", unrelated)?;
|
||||
assert!(
|
||||
idunn_recover_memory_semantic_projection_from_cultmesh(
|
||||
&verse,
|
||||
"runtime-test",
|
||||
&canonical,
|
||||
&input,
|
||||
&claim.claim_id,
|
||||
"executor-new",
|
||||
&receipt.receipt_id,
|
||||
"semantic-heartbeat-unrelated",
|
||||
"2026-07-15T12:04:00Z",
|
||||
)
|
||||
.is_err()
|
||||
);
|
||||
|
||||
let correlated = EpiphanyCultMeshDaemonHeartbeatEventEntry {
|
||||
heartbeat_id: "semantic-heartbeat-correlated".to_string(),
|
||||
sequence: 2,
|
||||
startup_lifecycle_receipt_id: receipt.receipt_id.clone(),
|
||||
..heartbeat_event(
|
||||
"semantic-heartbeat-template",
|
||||
"provider-new",
|
||||
2,
|
||||
"2026-07-15T12:03:00Z",
|
||||
)
|
||||
};
|
||||
let mut correlated = correlated;
|
||||
correlated.daemon_id = status.daemon_id;
|
||||
correlated.cluster_id = status.cluster_id;
|
||||
write_epiphany_cultmesh_daemon_heartbeat_event(&verse, "runtime-test", correlated.clone())?;
|
||||
let (_, recovered) = idunn_recover_memory_semantic_projection_from_cultmesh(
|
||||
&verse,
|
||||
"runtime-test",
|
||||
&canonical,
|
||||
&input,
|
||||
&claim.claim_id,
|
||||
"executor-new",
|
||||
&receipt.receipt_id,
|
||||
&correlated.heartbeat_id,
|
||||
"2026-07-15T12:04:00Z",
|
||||
)?;
|
||||
assert_eq!(recovered.epoch, claim.epoch + 1);
|
||||
assert_eq!(recovered.executor_incarnation, "provider-new");
|
||||
assert!(
|
||||
idunn_recover_memory_semantic_projection_from_cultmesh(
|
||||
&verse,
|
||||
"runtime-test",
|
||||
&canonical,
|
||||
&input,
|
||||
&recovered.claim_id,
|
||||
"executor-third",
|
||||
&receipt.receipt_id,
|
||||
&correlated.heartbeat_id,
|
||||
"2026-07-15T12:05:00Z",
|
||||
)
|
||||
.is_err()
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bifrost_mirrors_name_arrival_order_without_rewriting_storage_keys() {
|
||||
let source = include_str!("cultmesh_integration.rs");
|
||||
|
|
|
|||
|
|
@ -224,6 +224,8 @@ pub use cultmesh_integration::EPIPHANY_CULTMESH_CONTINUITY_CONTRACT_TYPE;
|
|||
pub use cultmesh_integration::EPIPHANY_CULTMESH_COORDINATOR_RUN_RECEIPT_LATEST_KEY;
|
||||
pub use cultmesh_integration::EPIPHANY_CULTMESH_COORDINATOR_RUN_RECEIPT_SCHEMA_VERSION;
|
||||
pub use cultmesh_integration::EPIPHANY_CULTMESH_COORDINATOR_RUN_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;
|
||||
|
|
@ -337,6 +339,7 @@ pub use cultmesh_integration::EpiphanyCultMeshBifrostPublicProofPublicationRecei
|
|||
pub use cultmesh_integration::EpiphanyCultMeshClusterTopologyEntry;
|
||||
pub use cultmesh_integration::EpiphanyCultMeshContinuityContractEntry;
|
||||
pub use cultmesh_integration::EpiphanyCultMeshCoordinatorRunReceiptEntry;
|
||||
pub use cultmesh_integration::EpiphanyCultMeshDaemonHeartbeatEventEntry;
|
||||
pub use cultmesh_integration::EpiphanyCultMeshDaemonPokeIntentEntry;
|
||||
pub use cultmesh_integration::EpiphanyCultMeshDaemonPokeReceiptEntry;
|
||||
pub use cultmesh_integration::EpiphanyCultMeshDaemonRestartPolicyEntry;
|
||||
|
|
@ -426,6 +429,8 @@ 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::idunn_acquire_memory_semantic_projection_for_local_supervisor;
|
||||
pub use cultmesh_integration::idunn_recover_memory_semantic_projection_from_cultmesh;
|
||||
pub use cultmesh_integration::load_arrival_latest_epiphany_cultmesh_bifrost_artifact_acceptance_receipt;
|
||||
pub use cultmesh_integration::load_arrival_latest_epiphany_cultmesh_bifrost_body_change_publication_intent;
|
||||
pub use cultmesh_integration::load_arrival_latest_epiphany_cultmesh_bifrost_body_change_publication_receipt;
|
||||
|
|
@ -434,7 +439,10 @@ pub use cultmesh_integration::load_arrival_latest_epiphany_cultmesh_bifrost_gith
|
|||
pub use cultmesh_integration::load_arrival_latest_epiphany_cultmesh_bifrost_metrics_receipt;
|
||||
pub use cultmesh_integration::load_arrival_latest_epiphany_cultmesh_bifrost_public_proof_publication_receipt;
|
||||
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_poke_intent;
|
||||
pub use cultmesh_integration::load_epiphany_cultmesh_daemon_poke_receipt;
|
||||
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_receipts;
|
||||
|
|
@ -456,6 +464,7 @@ pub use cultmesh_integration::load_epiphany_cultmesh_status;
|
|||
pub use cultmesh_integration::load_epiphany_cultmesh_swarm_brake;
|
||||
pub use cultmesh_integration::load_latest_epiphany_cultmesh_agent_state_soa_summary;
|
||||
pub use cultmesh_integration::load_latest_epiphany_cultmesh_coordinator_run_receipt;
|
||||
pub use cultmesh_integration::load_latest_epiphany_cultmesh_daemon_heartbeat;
|
||||
pub use cultmesh_integration::load_latest_epiphany_cultmesh_daemon_poke_intent;
|
||||
pub use cultmesh_integration::load_latest_epiphany_cultmesh_daemon_poke_receipt;
|
||||
pub use cultmesh_integration::load_latest_epiphany_cultmesh_daemon_scheduler_receipt;
|
||||
|
|
@ -500,6 +509,7 @@ pub use cultmesh_integration::write_epiphany_cultmesh_bifrost_metrics_receipt;
|
|||
pub use cultmesh_integration::write_epiphany_cultmesh_bifrost_public_proof_publication_receipt;
|
||||
pub use cultmesh_integration::write_epiphany_cultmesh_continuity_contracts;
|
||||
pub use cultmesh_integration::write_epiphany_cultmesh_coordinator_run_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;
|
||||
|
|
@ -639,6 +649,8 @@ pub use memory_graph::MEMORY_SEMANTIC_INDEX_RECEIPT_SCHEMA_VERSION;
|
|||
pub use memory_graph::MEMORY_SEMANTIC_PROJECTION_ATTEMPT_SCHEMA_VERSION;
|
||||
pub use memory_graph::MEMORY_SEMANTIC_PROJECTION_CLAIM_SCHEMA_VERSION;
|
||||
pub use memory_graph::MEMORY_SEMANTIC_PROJECTION_OBLIGATION_SCHEMA_VERSION;
|
||||
pub use memory_graph::MEMORY_SEMANTIC_PROJECTOR_EXECUTOR_GRANT_SCHEMA_VERSION;
|
||||
pub use memory_graph::MEMORY_SEMANTIC_PROJECTOR_RECOVERY_AUTHORIZATION_SCHEMA_VERSION;
|
||||
pub use memory_graph::MemorySemanticIndexConfig;
|
||||
pub use memory_graph::MemorySemanticIndexReceipt;
|
||||
pub use memory_graph::MemorySemanticProjectionAttempt;
|
||||
|
|
@ -650,6 +662,9 @@ pub use memory_graph::MemorySemanticProjectionObligation;
|
|||
pub use memory_graph::MemorySemanticProjectionObservation;
|
||||
pub use memory_graph::MemorySemanticProjectionReadiness;
|
||||
pub use memory_graph::MemorySemanticProjectionSourceHead;
|
||||
pub use memory_graph::MemorySemanticProjectorAcquisition;
|
||||
pub use memory_graph::MemorySemanticProjectorExecutorGrant;
|
||||
pub use memory_graph::MemorySemanticProjectorRecoveryAuthorization;
|
||||
pub use memory_graph::RepoFrontierAdoptedPlan;
|
||||
pub use memory_graph::RepoFrontierItem;
|
||||
pub use memory_graph::RepoFrontierStatus;
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ pub const MEMORY_SEMANTIC_INDEX_RECEIPT_SCHEMA_VERSION: &str =
|
|||
pub const MEMORY_SEMANTIC_PROJECTION_OBLIGATION_SCHEMA_VERSION: &str =
|
||||
"gamecult.epiphany.memory_semantic_projection_obligation.v0";
|
||||
pub const MEMORY_SEMANTIC_PROJECTION_ATTEMPT_SCHEMA_VERSION: &str =
|
||||
"gamecult.epiphany.memory_semantic_projection_attempt.v0";
|
||||
"gamecult.epiphany.memory_semantic_projection_attempt.v1";
|
||||
const MODELING_COLLECTION_DEFAULT: &str = "epiphany_modeling_v1";
|
||||
const MIND_COLLECTION_DEFAULT: &str = "epiphany_mind_v1";
|
||||
const QUERY_LIMIT_MAX: usize = 64;
|
||||
|
|
@ -159,6 +159,16 @@ pub struct MemorySemanticProjectionAttempt {
|
|||
pub status: String,
|
||||
#[cultcache(key = 6)]
|
||||
pub error: Option<String>,
|
||||
#[cultcache(key = 7)]
|
||||
pub claim_id: String,
|
||||
#[cultcache(key = 8)]
|
||||
pub claim_epoch: u64,
|
||||
#[cultcache(key = 9)]
|
||||
pub executor_id: String,
|
||||
#[cultcache(key = 10)]
|
||||
pub executor_incarnation: String,
|
||||
#[cultcache(key = 11)]
|
||||
pub authority_id: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
|
|
@ -356,6 +366,11 @@ pub fn validate_memory_semantic_projection_attempt(
|
|||
}
|
||||
if attempt.attempt_id.trim().is_empty()
|
||||
|| attempt.obligation_id.trim().is_empty()
|
||||
|| attempt.claim_id.trim().is_empty()
|
||||
|| attempt.claim_epoch == 0
|
||||
|| attempt.executor_id.trim().is_empty()
|
||||
|| attempt.executor_incarnation.trim().is_empty()
|
||||
|| attempt.authority_id.trim().is_empty()
|
||||
|| attempt.started_at.trim().is_empty()
|
||||
|| chrono::DateTime::parse_from_rfc3339(&attempt.started_at).is_err()
|
||||
|| attempt
|
||||
|
|
@ -367,6 +382,14 @@ pub fn validate_memory_semantic_projection_attempt(
|
|||
"semantic projection attempt is missing identity or time"
|
||||
));
|
||||
}
|
||||
if attempt.completed_at.as_deref().is_some_and(|completed_at| {
|
||||
chrono::DateTime::parse_from_rfc3339(completed_at).ok()
|
||||
< chrono::DateTime::parse_from_rfc3339(&attempt.started_at).ok()
|
||||
}) {
|
||||
return Err(anyhow!(
|
||||
"semantic projection attempt completes before it starts"
|
||||
));
|
||||
}
|
||||
match attempt.status.as_str() {
|
||||
"running" if attempt.completed_at.is_none() && attempt.error.is_none() => Ok(()),
|
||||
"failed" if attempt.completed_at.is_some() && attempt.error.is_some() => Ok(()),
|
||||
|
|
@ -1347,6 +1370,11 @@ mod tests {
|
|||
completed_at: Some("2026-07-15T10:00:31Z".to_string()),
|
||||
status: "failed".to_string(),
|
||||
error: Some("qdrant unavailable".to_string()),
|
||||
claim_id: "claim-7".to_string(),
|
||||
claim_epoch: 1,
|
||||
executor_id: "executor-a".to_string(),
|
||||
executor_incarnation: "executor-a-incarnation".to_string(),
|
||||
authority_id: "authority-a".to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
Reference in a new issue