diff --git a/epiphany-core/src/bin/epiphany-swarm.rs b/epiphany-core/src/bin/epiphany-swarm.rs index 4dee8218..a1e1fa2c 100644 --- a/epiphany-core/src/bin/epiphany-swarm.rs +++ b/epiphany-core/src/bin/epiphany-swarm.rs @@ -157,18 +157,15 @@ fn retain_runtime_receipts(args: &Args, state: &ResidentSelfState) -> Result<()> fn retain_runtime_worker_attempts(args: &Args) -> Result<()> { let live_request_ids = live_resident_self_typed_request_ids(&args.state_store)?; - let archived_at = Utc::now().to_rfc3339(); retain_failed_runtime_worker_attempts( &args.policy.runtime_store, args.retained_runtime_worker_attempts, &live_request_ids, - &archived_at, )?; retain_fulfilled_runtime_worker_attempts( &args.policy.runtime_store, args.retained_runtime_worker_attempts, &live_request_ids, - &archived_at, )?; Ok(()) } diff --git a/epiphany-core/src/reasoning_context.rs b/epiphany-core/src/reasoning_context.rs index 3b64adfa..70f70241 100644 --- a/epiphany-core/src/reasoning_context.rs +++ b/epiphany-core/src/reasoning_context.rs @@ -710,7 +710,7 @@ impl EpiphanyDecisionTerminalRecords { self.model_pass_failures .sort_by(|left, right| left.failure_id.cmp(&right.failure_id)); self.archived_worker_attempts - .sort_by(|left, right| left.archive_id.cmp(&right.archive_id)); + .sort_by(|left, right| left.job_id.cmp(&right.job_id)); self.persona_stage_receipts .sort_by(|left, right| left.receipt_id.cmp(&right.receipt_id)); self.persona_effect_documents @@ -2754,14 +2754,10 @@ mod tests { ); let archived = crate::EpiphanyArchivedRuntimeWorkerAttempt { schema_version: crate::ARCHIVED_RUNTIME_WORKER_ATTEMPT_SCHEMA_VERSION.into(), - archive_id: "pass-1".into(), job_id: "pass-1".into(), request_kind: "proposal-modeling".into(), request_id: "proposal-request-1".into(), terminal_process_status: "terminal-failure".into(), - archived_at: "2026-08-14T00:00:04Z".into(), - retired_type_counts: Default::default(), - retired_envelope_count: 1, retired_chain_digest: "sha256:historical-family".into(), decision: Some(crate::EpiphanyArchivedRuntimeWorkerDecision { decision_context_id: context.context_id.clone(), @@ -2769,7 +2765,7 @@ mod tests { job_results: vec![terminal_result], }), }; - archive_cache.put(&archived.archive_id, &archived)?; + archive_cache.put(&archived.job_id, &archived)?; let before_archived_audit = backing.pull_all()?; let archived_audit = audit_decision_context(&store, &context.context_id)?; assert!( diff --git a/epiphany-core/src/runtime_spine.rs b/epiphany-core/src/runtime_spine.rs index edaa3af8..d7f4f932 100644 --- a/epiphany-core/src/runtime_spine.rs +++ b/epiphany-core/src/runtime_spine.rs @@ -89,7 +89,7 @@ pub const RUNTIME_TOOL_EXECUTION_BINDING_TYPE: &str = "epiphany.runtime.tool_exe pub const RUNTIME_WORKER_LAUNCH_REQUEST_TYPE: &str = "epiphany.runtime.worker_launch_request"; pub const RUNTIME_WORKER_PROCESS_CLAIM_TYPE: &str = "epiphany.runtime.worker_process_claim.v0"; pub const ARCHIVED_RUNTIME_WORKER_ATTEMPT_TYPE: &str = - "epiphany.runtime.archived_worker_attempt.v1"; + "epiphany.runtime.archived_worker_attempt.v2"; pub const RUNTIME_ROLE_WORKER_RESULT_TYPE: &str = "epiphany.runtime.role_worker_result"; pub const RUNTIME_REORIENT_WORKER_RESULT_TYPE: &str = "epiphany.runtime.reorient_worker_result"; pub const RUNTIME_JOB_RESULT_TYPE: &str = "epiphany.runtime.job_result"; @@ -97,7 +97,7 @@ pub const COORDINATOR_RUN_RECEIPT_TYPE: &str = "epiphany.coordinator_run_receipt pub const RUNTIME_IDENTITY_KEY: &str = "self"; pub const RUNTIME_SWARM_BINDING_KEY: &str = "runtime-swarm-binding"; pub const RUNTIME_SWARM_BINDING_SCHEMA_VERSION: &str = "epiphany.runtime.swarm_binding.v1"; -pub const RUNTIME_SPINE_SCHEMA_VERSION: &str = "epiphany.runtime_spine.v12"; +pub const RUNTIME_SPINE_SCHEMA_VERSION: &str = "epiphany.runtime_spine.v13"; pub const EPIPHANY_RUNTIME_ROOT_SESSION_ID: &str = "epiphany-main"; pub const RUNTIME_MODEL_EXECUTION_BINDING_SCHEMA_VERSION: &str = "epiphany.runtime.model_execution_binding.v0"; @@ -109,7 +109,7 @@ pub const RUNTIME_WORKER_LAUNCH_REQUEST_SCHEMA_VERSION: &str = pub const RUNTIME_WORKER_PROCESS_CLAIM_SCHEMA_VERSION: &str = "epiphany.runtime.worker_process_claim.v0"; pub const ARCHIVED_RUNTIME_WORKER_ATTEMPT_SCHEMA_VERSION: &str = - "epiphany.runtime.archived_worker_attempt.v1"; + "epiphany.runtime.archived_worker_attempt.v2"; pub const RUNTIME_ROLE_WORKER_RESULT_SCHEMA_VERSION: &str = "epiphany.runtime.role_worker_result.v4"; pub const RUNTIME_REORIENT_WORKER_RESULT_SCHEMA_VERSION: &str = @@ -344,31 +344,23 @@ pub struct EpiphanyRuntimeWorkerProcessClaim { #[derive(Clone, Debug, PartialEq, DatabaseEntry)] #[cultcache( - type = "epiphany.runtime.archived_worker_attempt.v1", + type = "epiphany.runtime.archived_worker_attempt.v2", schema = "EpiphanyArchivedRuntimeWorkerAttempt" )] pub struct EpiphanyArchivedRuntimeWorkerAttempt { #[cultcache(key = 0)] pub schema_version: String, #[cultcache(key = 1)] - pub archive_id: String, - #[cultcache(key = 2)] pub job_id: String, - #[cultcache(key = 3)] + #[cultcache(key = 2)] pub request_kind: String, - #[cultcache(key = 4)] + #[cultcache(key = 3)] pub request_id: String, - #[cultcache(key = 5)] + #[cultcache(key = 4)] pub terminal_process_status: String, - #[cultcache(key = 6)] - pub archived_at: String, - #[cultcache(key = 7)] - pub retired_type_counts: BTreeMap, - #[cultcache(key = 8)] - pub retired_envelope_count: u64, - #[cultcache(key = 9)] + #[cultcache(key = 5)] pub retired_chain_digest: String, - #[cultcache(key = 10)] + #[cultcache(key = 6)] pub decision: Option, } @@ -5000,7 +4992,6 @@ pub(crate) fn runtime_typed_request_fulfillment( } if let Some(attempt) = archived_matches.first() { if attempt.schema_version != ARCHIVED_RUNTIME_WORKER_ATTEMPT_SCHEMA_VERSION - || attempt.archive_id != attempt.job_id || attempt.request_kind != request.kind() || !crate::WorkerProcessStatus::parse(&attempt.terminal_process_status)? .is_fulfilled_terminal() @@ -8950,19 +8941,15 @@ fn archive_runtime_worker_attempt( store_path: impl AsRef, job_id: &str, live_resident_request_ids: &BTreeSet, - archived_at: &str, fulfilled: bool, ) -> Result { validate_non_empty(job_id, "archived worker attempt job id")?; - chrono::DateTime::parse_from_rfc3339(archived_at) - .map_err(|error| anyhow!("worker attempt archive timestamp is invalid: {error}"))?; let store_path = store_path.as_ref(); let mut cache = runtime_spine_cache(store_path)?; cache.pull_all_backing_stores()?; require_identity(&cache)?; if let Some(existing) = cache.get::(job_id)? { if existing.schema_version != ARCHIVED_RUNTIME_WORKER_ATTEMPT_SCHEMA_VERSION - || existing.archive_id != job_id || existing.job_id != job_id || !existing.retired_chain_digest.starts_with("sha256:") { @@ -9163,11 +9150,9 @@ fn archive_runtime_worker_attempt( { return Err(anyhow!("worker attempt archive lost its exact core family")); } - let mut counts = BTreeMap::new(); let mut digest = Sha256::new(); digest.update(b"epiphany-archived-worker-attempt-root"); for entry in &deletions { - *counts.entry(entry.r#type.clone()).or_default() += 1; for bytes in [ entry.r#type.as_bytes(), entry.key.as_bytes(), @@ -9179,14 +9164,10 @@ fn archive_runtime_worker_attempt( } let tombstone = EpiphanyArchivedRuntimeWorkerAttempt { schema_version: ARCHIVED_RUNTIME_WORKER_ATTEMPT_SCHEMA_VERSION.into(), - archive_id: job_id.into(), job_id: job_id.into(), request_kind: request_kind.into(), request_id: request_id.into(), terminal_process_status: claim.status, - archived_at: archived_at.into(), - retired_type_counts: counts, - retired_envelope_count: deletions.len() as u64, retired_chain_digest: format!("sha256:{:x}", digest.finalize()), decision, }; @@ -9208,8 +9189,7 @@ pub fn retain_failed_runtime_worker_attempts( store_path: impl AsRef, retain_recent: usize, live_resident_request_ids: &BTreeSet, - archived_at: &str, -) -> Result> { +) -> Result<()> { let store_path = store_path.as_ref(); let mut cache = runtime_spine_cache(store_path)?; cache.pull_all_backing_stores()?; @@ -9260,27 +9240,22 @@ pub fn retain_failed_runtime_worker_attempts( .cmp(&a.terminal_at) .then(b.job_id.cmp(&a.job_id)) }); - candidates - .into_iter() - .skip(retain_recent.max(1)) - .map(|claim| { - archive_runtime_worker_attempt( - store_path, - &claim.job_id, - live_resident_request_ids, - archived_at, - false, - ) - }) - .collect() + for claim in candidates.into_iter().skip(retain_recent.max(1)) { + archive_runtime_worker_attempt( + store_path, + &claim.job_id, + live_resident_request_ids, + false, + )?; + } + Ok(()) } pub fn retain_fulfilled_runtime_worker_attempts( store_path: impl AsRef, retain_recent: usize, live_resident_request_ids: &BTreeSet, - archived_at: &str, -) -> Result> { +) -> Result<()> { let store_path = store_path.as_ref(); let mut cache = runtime_spine_cache(store_path)?; cache.pull_all_backing_stores()?; @@ -9338,19 +9313,10 @@ pub fn retain_fulfilled_runtime_worker_attempts( .cmp(&a.terminal_at) .then(b.job_id.cmp(&a.job_id)) }); - candidates - .into_iter() - .skip(retain_recent.max(1)) - .map(|claim| { - archive_runtime_worker_attempt( - store_path, - &claim.job_id, - live_resident_request_ids, - archived_at, - true, - ) - }) - .collect() + for claim in candidates.into_iter().skip(retain_recent.max(1)) { + archive_runtime_worker_attempt(store_path, &claim.job_id, live_resident_request_ids, true)?; + } + Ok(()) } fn coordinator_completion_summary(receipt: &EpiphanyCoordinatorRunReceipt) -> String {