diff --git a/epiphany-core/src/lib.rs b/epiphany-core/src/lib.rs index bc5f5cb0..b6b637bb 100644 --- a/epiphany-core/src/lib.rs +++ b/epiphany-core/src/lib.rs @@ -1019,6 +1019,8 @@ pub use runtime_spine::RuntimeSpineJobOptions; pub use runtime_spine::RuntimeSpineJobResultOptions; pub use runtime_spine::RuntimeSpineSessionClosureOptions; pub use runtime_spine::RuntimeSpineSessionOptions; +pub use runtime_spine::RuntimeTypedFulfillmentEvidence; +pub use runtime_spine::RuntimeTypedRequestRef; pub use runtime_spine::amend_repo_frontier_execution; pub use runtime_spine::append_runtime_event; pub use runtime_spine::bind_runtime_repository_domain; @@ -1113,6 +1115,7 @@ pub use runtime_spine::runtime_spine_status; pub use runtime_spine::runtime_substrate_gate_repo_access_grant_receipt; pub use runtime_spine::runtime_swarm_binding; pub use runtime_spine::runtime_tool_invocation_statuses; +pub use runtime_spine::runtime_typed_request_fulfillment; pub use runtime_spine::runtime_worker_launch_body_basis; pub use runtime_spine::runtime_worker_launch_request; pub use runtime_spine::select_and_commit_repo_frontier_planning_request; diff --git a/epiphany-core/src/resident_self.rs b/epiphany-core/src/resident_self.rs index 6485f563..8fdcb312 100644 --- a/epiphany-core/src/resident_self.rs +++ b/epiphany-core/src/resident_self.rs @@ -1207,25 +1207,14 @@ pub fn verify_resident_self_grant_fulfillment( let grant = state_cache(resident_store)? .get::(grant_id)? .ok_or_else(|| anyhow!("resident Self fulfillment check lost its grant"))?; - let mut runtime = crate::runtime_spine_cache(runtime_store)?; - runtime.pull_all_backing_stores()?; - let worker_results = runtime.get_all::()?; - match grant.pressure_kind.as_str() { + let request = match grant.pressure_kind.as_str() { "repo-frontier-proposal-modeling" => { let request_id = grant .provenance_ref .strip_prefix("cultcache://repo-frontier-proposal-modeling/") .filter(|value| !value.trim().is_empty()) .ok_or_else(|| anyhow!("proposal Modeling grant lost exact request provenance"))?; - Ok( - if worker_results.iter().any(|result| { - result.proposal_modeling_request_id.as_deref() == Some(request_id) - }) { - ResidentSelfGrantFulfillment::Fulfilled - } else { - ResidentSelfGrantFulfillment::Pending - }, - ) + Some(crate::RuntimeTypedRequestRef::ProposalModeling(request_id)) } "admitted-model-direction-consideration" => { let request_id = grant @@ -1233,31 +1222,9 @@ pub fn verify_resident_self_grant_fulfillment( .strip_prefix("cultcache://admitted-model-direction-consideration/") .filter(|value| !value.trim().is_empty()) .ok_or_else(|| anyhow!("model direction grant lost exact request provenance"))?; - let request = runtime - .get::(request_id)? - .ok_or_else(|| anyhow!("model direction fulfillment request is missing"))?; - for worker_result in worker_results.iter().filter(|result| { - result - .admitted_model_direction_consideration_request_id - .as_deref() - == Some(request_id) - }) { - let result = worker_result - .admitted_model_direction_consideration_result()? - .ok_or_else(|| anyhow!("model direction worker result lost typed companion"))?; - crate::validate_admitted_model_direction_consideration_result(&request, &result)?; - if runtime - .get::(&result.result_id)? - .as_ref() - != Some(&result) - { - return Err(anyhow!( - "model direction worker result lost its persisted typed companion" - )); - } - return Ok(ResidentSelfGrantFulfillment::Fulfilled); - } - Ok(ResidentSelfGrantFulfillment::Pending) + Some(crate::RuntimeTypedRequestRef::AdmittedModelDirection( + request_id, + )) } "imagination-consideration" => { let request_id = grant @@ -1267,38 +1234,22 @@ pub fn verify_resident_self_grant_fulfillment( .ok_or_else(|| { anyhow!("Imagination consideration grant lost exact request provenance") })?; - let request = runtime - .get::(request_id)? - .ok_or_else(|| { - anyhow!("Imagination consideration fulfillment request is missing") - })?; - for worker_result in worker_results.iter().filter(|result| { - result.imagination_consideration_request_id.as_deref() == Some(request_id) - }) { - let candidate = worker_result - .imagination_consideration_candidate()? - .ok_or_else(|| anyhow!("Imagination worker result lost typed candidate"))?; - crate::validate_imagination_consideration_candidate(&request, &candidate)?; - if candidate.candidate_id - != crate::imagination_consideration_candidate_id_for_launch( - request_id, - &worker_result.job_id, - ) - || runtime - .get::(&candidate.candidate_id)? - .as_ref() - != Some(&candidate) - { - return Err(anyhow!( - "Imagination worker result lost its exact persisted candidate" - )); - } - return Ok(ResidentSelfGrantFulfillment::Fulfilled); - } - Ok(ResidentSelfGrantFulfillment::Pending) + Some(crate::RuntimeTypedRequestRef::ImaginationConsideration( + request_id, + )) } - _ => Ok(ResidentSelfGrantFulfillment::Fulfilled), - } + _ => None, + }; + let Some(request) = request else { + return Ok(ResidentSelfGrantFulfillment::Fulfilled); + }; + Ok( + if crate::runtime_typed_request_fulfillment(runtime_store, request)?.is_some() { + ResidentSelfGrantFulfillment::Fulfilled + } else { + ResidentSelfGrantFulfillment::Pending + }, + ) } pub fn settle_resident_self_exited_coordinator( @@ -2399,7 +2350,42 @@ mod tests { thread_id: &str, ) -> Result<()> { seed_runtime_identity(store, runtime_id)?; - let cache = crate::runtime_spine_cache(store)?; + let mut cache = crate::runtime_spine_cache(store)?; + cache.pull_all_backing_stores()?; + let mut model = crate::EpiphanyMemoryGraphSnapshot::default(); + model.model_revision = 1; + let model_hash = crate::memory_graph_model_hash(&model)?; + cache.put( + crate::MEMORY_GRAPH_KEY, + &crate::EpiphanyMemoryGraphEntry::from_snapshot(&model)?, + )?; + cache.put( + "model-admission-1", + &crate::RepoModelAdmissionReceipt { + schema_version: crate::REPO_MODEL_ADMISSION_RECEIPT_SCHEMA_VERSION.into(), + receipt_id: "model-admission-1".into(), + review_id: "review-model-1".into(), + result_id: None, + patch_id: "patch-model-1".into(), + patch_sha256: "sha256:patch-model-1".into(), + previous_revision: 0, + previous_hash: "sha256:previous-model".into(), + admitted_revision: model.model_revision, + admitted_hash: model_hash.clone(), + admitted_at: "2026-07-18T00:00:00Z".into(), + contract: crate::REPO_MODEL_ADMISSION_CONTRACT.into(), + purpose: crate::RepoModelPatchPurpose::Evolution, + frontier_route_id: String::new(), + verification_request_id: String::new(), + soul_verdict_receipt_id: String::new(), + frontier_modeling_request_id: String::new(), + proposal_modeling_request_id: String::new(), + claim_repair_request_id: String::new(), + frontier_plan_decision_id: String::new(), + repository_body_observation_basis: None, + admission_source: None, + }, + )?; let request = crate::AdmittedModelDirectionConsiderationRequest { schema_version: crate::ADMITTED_MODEL_DIRECTION_CONSIDERATION_REQUEST_SCHEMA_VERSION .into(), @@ -2407,7 +2393,7 @@ mod tests { runtime_id: runtime_id.into(), thread_id: thread_id.into(), model_revision: 1, - model_hash: "sha256:model-1".into(), + model_hash, model_admission_receipt_id: "model-admission-1".into(), previous_terminal_result_id: None, requested_at: "2026-07-18T00:00:00Z".into(), @@ -2457,6 +2443,166 @@ mod tests { admitted_model_direction_consideration_result_msgpack: None, } } + + fn admit_test_model_direction_result( + store: &Path, + request: &crate::AdmittedModelDirectionConsiderationRequest, + result: &crate::AdmittedModelDirectionConsiderationResult, + job_id: &str, + ) -> Result<()> { + let document = + crate::EpiphanyWorkerLaunchDocument::Role(crate::EpiphanyRoleWorkerLaunchDocument { + thread_id: request.thread_id.clone(), + role_id: "imagination".into(), + state_revision: 0, + objective: None, + dynamic_prompt_context: None, + repository_body_observation_basis: None, + proposal_modeling_context: None, + claim_repair_context: None, + frontier_planning_context: None, + frontier_plan_mind_context: None, + imagination_consideration_context: None, + admitted_model_direction_consideration_context: Some( + crate::AdmittedModelDirectionConsiderationContextProjection::new( + request, + &crate::EpiphanyMemoryGraphSnapshot::default(), + ), + ), + active_subgoal_id: None, + active_subgoals: Vec::new(), + active_graph_node_ids: Vec::new(), + investigation_checkpoint: None, + scratch: None, + invariants: Vec::new(), + graphs: None, + recent_evidence: Vec::new(), + recent_observations: Vec::new(), + graph_frontier: None, + graph_checkpoint: None, + planning: None, + churn: None, + }); + let launch = crate::EpiphanyRuntimeWorkerLaunchRequest { + schema_version: crate::RUNTIME_WORKER_LAUNCH_REQUEST_SCHEMA_VERSION.into(), + job_id: job_id.into(), + binding_id: crate::EPIPHANY_IMAGINATION_ROLE_BINDING_ID.into(), + role: crate::EPIPHANY_IMAGINATION_OWNER_ROLE.into(), + authority_scope: "imagination".into(), + instruction: "Test exact admitted model direction consideration.".into(), + output_contract_id: crate::ROLE_WORKER_OUTPUT_CONTRACT_ID.into(), + document_kind: "role".into(), + launch_document_msgpack: rmp_serde::to_vec_named(&document)?, + metadata: BTreeMap::new(), + organ_launch_contract: crate::default_launch_organ_contract( + "imagination", + "role", + crate::ROLE_WORKER_OUTPUT_CONTRACT_ID, + ), + proposal_modeling_request_id: None, + claim_repair_request_id: None, + frontier_planning_request_id: None, + frontier_plan_mind_request_id: None, + imagination_consideration_request_id: None, + admitted_model_direction_consideration_request_id: Some(request.request_id.clone()), + repo_frontier_modeling_request_id: None, + repo_frontier_verdict_modeling_authority_msgpack: None, + }; + let mut cache = crate::runtime_spine_cache(store)?; + cache.put(job_id, &launch)?; + let mut worker = role_worker_result(job_id, "imagination"); + worker.admitted_model_direction_consideration_request_id = Some(request.request_id.clone()); + worker.admitted_model_direction_consideration_result_msgpack = + Some(rmp_serde::to_vec_named(result)?); + crate::put_runtime_role_worker_result(store, &worker) + } + + fn admit_test_imagination_candidate( + store: &Path, + request: &crate::ImaginationConsiderationRequest, + model: &crate::EpiphanyMemoryGraphSnapshot, + candidate: &crate::ImaginationConsiderationCandidate, + job_id: &str, + ) -> Result<()> { + let document = + crate::EpiphanyWorkerLaunchDocument::Role(crate::EpiphanyRoleWorkerLaunchDocument { + thread_id: request.thread_id.clone(), + role_id: "imagination".into(), + state_revision: 0, + objective: None, + dynamic_prompt_context: None, + repository_body_observation_basis: None, + proposal_modeling_context: None, + claim_repair_context: None, + frontier_planning_context: None, + frontier_plan_mind_context: None, + imagination_consideration_context: Some( + crate::ImaginationConsiderationContextProjection::new(request, model), + ), + admitted_model_direction_consideration_context: None, + active_subgoal_id: None, + active_subgoals: Vec::new(), + active_graph_node_ids: Vec::new(), + investigation_checkpoint: None, + scratch: None, + invariants: Vec::new(), + graphs: None, + recent_evidence: Vec::new(), + recent_observations: Vec::new(), + graph_frontier: None, + graph_checkpoint: None, + planning: None, + churn: None, + }); + let launch_document_msgpack = rmp_serde::to_vec_named(&document)?; + let launch = crate::EpiphanyRuntimeWorkerLaunchRequest { + schema_version: crate::RUNTIME_WORKER_LAUNCH_REQUEST_SCHEMA_VERSION.into(), + job_id: job_id.into(), + binding_id: crate::EPIPHANY_IMAGINATION_ROLE_BINDING_ID.into(), + role: crate::EPIPHANY_IMAGINATION_OWNER_ROLE.into(), + authority_scope: "imagination".into(), + instruction: "Test exact feedback consideration.".into(), + output_contract_id: crate::ROLE_WORKER_OUTPUT_CONTRACT_ID.into(), + document_kind: "role".into(), + launch_document_msgpack: launch_document_msgpack.clone(), + metadata: BTreeMap::new(), + organ_launch_contract: crate::default_launch_organ_contract( + "imagination", + "role", + crate::ROLE_WORKER_OUTPUT_CONTRACT_ID, + ), + proposal_modeling_request_id: None, + claim_repair_request_id: None, + frontier_planning_request_id: None, + frontier_plan_mind_request_id: None, + imagination_consideration_request_id: Some(request.request_id.clone()), + admitted_model_direction_consideration_request_id: None, + repo_frontier_modeling_request_id: None, + repo_frontier_verdict_modeling_authority_msgpack: None, + }; + let binding = crate::ImaginationConsiderationLaunchBinding { + schema_version: crate::IMAGINATION_CONSIDERATION_LAUNCH_BINDING_SCHEMA_VERSION.into(), + binding_record_id: format!("imagination-consideration-launch-{}", request.request_id), + request_id: request.request_id.clone(), + job_id: job_id.into(), + binding_id: crate::EPIPHANY_IMAGINATION_ROLE_BINDING_ID.into(), + runtime_id: request.runtime_id.clone(), + thread_id: request.thread_id.clone(), + launched_at: "2026-07-18T00:00:01Z".into(), + worker_launch_document_sha256: format!( + "{:x}", + Sha256::digest(&launch_document_msgpack) + ), + }; + let mut cache = crate::runtime_spine_cache(store)?; + cache.put(job_id, &launch)?; + cache.put(&binding.binding_record_id, &binding)?; + let mut worker = role_worker_result(job_id, "imagination"); + worker.imagination_consideration_request_id = Some(request.request_id.clone()); + worker.imagination_consideration_candidate_msgpack = + Some(rmp_serde::to_vec_named(candidate)?); + crate::put_runtime_role_worker_result(store, &worker) + } fn coordinator_receipt_for_lease( lease: &ResidentSelfTurnLease, runtime_store: &Path, @@ -2771,16 +2917,23 @@ mod tests { ); assert!(pending_resident_self_acks(&store)?.is_empty()); - let runtime = crate::runtime_spine_cache(&policy.runtime_store)?; + let mut runtime = crate::runtime_spine_cache(&policy.runtime_store)?; + runtime.pull_all_backing_stores()?; + let request = runtime + .get::("request-model-1")? + .expect("model direction request"); let result = crate::AdmittedModelDirectionConsiderationResult { schema_version: crate::ADMITTED_MODEL_DIRECTION_CONSIDERATION_RESULT_SCHEMA_VERSION .into(), - result_id: "result-model-1".into(), + result_id: crate::admitted_model_direction_consideration_result_id_for_launch( + &request.request_id, + "job-model-1", + ), request_id: "request-model-1".into(), runtime_id: "cognitive-runtime".into(), thread_id: "implementation-thread-1".into(), model_revision: 1, - model_hash: "sha256:model-1".into(), + model_hash: request.model_hash.clone(), model_admission_receipt_id: "model-admission-1".into(), disposition: crate::AdmittedModelDirectionDisposition::Hold, summary: "Hold while the current admitted direction remains coherent.".into(), @@ -2792,14 +2945,7 @@ mod tests { proposal_only: true, terminal: true, }; - let (result_entry, _) = runtime.prepare_entry(&result.result_id, &result)?; - SingleFileMessagePackBackingStore::new(&policy.runtime_store).push(&result_entry)?; - let mut worker = role_worker_result("job-model-1", "imagination"); - worker.admitted_model_direction_consideration_request_id = Some("request-model-1".into()); - worker.admitted_model_direction_consideration_result_msgpack = - Some(rmp_serde::to_vec_named(&result)?); - let (worker_entry, _) = runtime.prepare_entry(&worker.job_id, &worker)?; - SingleFileMessagePackBackingStore::new(&policy.runtime_store).push(&worker_entry)?; + admit_test_model_direction_result(&policy.runtime_store, &request, &result, "job-model-1")?; assert_eq!( settle_resident_self_exited_coordinator( &store, @@ -3014,16 +3160,23 @@ mod tests { ResidentSelfGrantFulfillment::Pending ); - let runtime = crate::runtime_spine_cache(&runtime_store)?; + let mut runtime = crate::runtime_spine_cache(&runtime_store)?; + runtime.pull_all_backing_stores()?; + let request = runtime + .get::("request-model-fulfillment")? + .expect("model direction request"); let result = crate::AdmittedModelDirectionConsiderationResult { schema_version: crate::ADMITTED_MODEL_DIRECTION_CONSIDERATION_RESULT_SCHEMA_VERSION .into(), - result_id: "result-model-fulfillment".into(), + result_id: crate::admitted_model_direction_consideration_result_id_for_launch( + &request.request_id, + "job-model-fulfillment", + ), request_id: "request-model-fulfillment".into(), runtime_id: "test-runtime".into(), thread_id: "implementation-thread-1".into(), model_revision: 1, - model_hash: "sha256:model-1".into(), + model_hash: request.model_hash.clone(), model_admission_receipt_id: "model-admission-1".into(), disposition: crate::AdmittedModelDirectionDisposition::Hold, summary: "Hold while the current admitted direction remains coherent.".into(), @@ -3035,23 +3188,12 @@ mod tests { proposal_only: true, terminal: true, }; - let (entry, _) = runtime.prepare_entry(&result.result_id, &result)?; - SingleFileMessagePackBackingStore::new(&runtime_store).push(&entry)?; - assert_eq!( - verify_resident_self_grant_fulfillment( - &resident_store, - &runtime_store, - &grant.grant_id, - )?, - ResidentSelfGrantFulfillment::Pending - ); - let mut worker = role_worker_result("job-model-fulfillment", "imagination"); - worker.admitted_model_direction_consideration_request_id = - Some("request-model-fulfillment".into()); - worker.admitted_model_direction_consideration_result_msgpack = - Some(rmp_serde::to_vec_named(&result)?); - let (worker_entry, _) = runtime.prepare_entry(&worker.job_id, &worker)?; - SingleFileMessagePackBackingStore::new(&runtime_store).push(&worker_entry)?; + admit_test_model_direction_result( + &runtime_store, + &request, + &result, + "job-model-fulfillment", + )?; assert_eq!( verify_resident_self_grant_fulfillment( &resident_store, @@ -3069,6 +3211,39 @@ mod tests { let resident_store = temp.path().join("resident-self.cc"); let runtime_store = temp.path().join("runtime.cc"); let runtime = crate::runtime_spine_cache(&runtime_store)?; + let mut model = crate::EpiphanyMemoryGraphSnapshot::default(); + model.model_revision = 1; + let model_hash = crate::memory_graph_model_hash(&model)?; + let model_entry = crate::EpiphanyMemoryGraphEntry::from_snapshot(&model)?; + let receipt = crate::RepoModelAdmissionReceipt { + schema_version: crate::REPO_MODEL_ADMISSION_RECEIPT_SCHEMA_VERSION.into(), + receipt_id: "model-admission-1".into(), + review_id: "review-model-1".into(), + result_id: None, + patch_id: "patch-model-1".into(), + patch_sha256: "sha256:patch-model-1".into(), + previous_revision: 0, + previous_hash: "sha256:previous-model".into(), + admitted_revision: model.model_revision, + admitted_hash: model_hash.clone(), + admitted_at: "2026-07-18T00:00:00Z".into(), + contract: crate::REPO_MODEL_ADMISSION_CONTRACT.into(), + purpose: crate::RepoModelPatchPurpose::Evolution, + frontier_route_id: String::new(), + verification_request_id: String::new(), + soul_verdict_receipt_id: String::new(), + frontier_modeling_request_id: String::new(), + proposal_modeling_request_id: String::new(), + claim_repair_request_id: String::new(), + frontier_plan_decision_id: String::new(), + repository_body_observation_basis: None, + admission_source: None, + }; + let (model_entry, _) = runtime.prepare_entry(crate::MEMORY_GRAPH_KEY, &model_entry)?; + let (receipt_entry, _) = runtime.prepare_entry(&receipt.receipt_id, &receipt)?; + let mut backing = SingleFileMessagePackBackingStore::new(&runtime_store); + backing.push(&model_entry)?; + backing.push(&receipt_entry)?; let request = crate::ImaginationConsiderationRequest { schema_version: crate::IMAGINATION_CONSIDERATION_REQUEST_SCHEMA_VERSION.into(), request_id: "request-imagination-fulfillment".into(), @@ -3084,7 +3259,7 @@ mod tests { repository: "GameCult/Epiphany".into(), persona_id: "epiphany".into(), model_revision: 1, - model_hash: "sha256:model-1".into(), + model_hash, model_admission_receipt_id: "model-admission-1".into(), routing_policy_id: "routing-policy-1".into(), question: crate::ImaginationConsiderationQuestion::CompareWithCurrentBodyAndSuggestCoherentOptions, @@ -3170,12 +3345,13 @@ mod tests { )?, ResidentSelfGrantFulfillment::Pending ); - let mut worker = role_worker_result(worker_job_id, "imagination"); - worker.imagination_consideration_request_id = Some(request.request_id.clone()); - worker.imagination_consideration_candidate_msgpack = - Some(rmp_serde::to_vec_named(&candidate)?); - let (worker_entry, _) = runtime.prepare_entry(&worker.job_id, &worker)?; - SingleFileMessagePackBackingStore::new(&runtime_store).push(&worker_entry)?; + admit_test_imagination_candidate( + &runtime_store, + &request, + &model, + &candidate, + worker_job_id, + )?; assert_eq!( verify_resident_self_grant_fulfillment( &resident_store, @@ -3490,13 +3666,14 @@ mod tests { worker.proposal_modeling_request_id = Some("selection-1".into()); let (entry, _) = runtime_cache.prepare_entry(&worker.job_id, &worker)?; SingleFileMessagePackBackingStore::new(&runtime_store).push(&entry)?; - assert_eq!( + assert!( verify_resident_self_grant_fulfillment( &resident_store, &runtime_store, &grant.grant_id, - )?, - ResidentSelfGrantFulfillment::Fulfilled + ) + .is_err(), + "an echo-only proposal result without its immutable worker launch is hostile, not fulfilled" ); assert_eq!( diff --git a/epiphany-core/src/runtime_spine.rs b/epiphany-core/src/runtime_spine.rs index 228af542..f90c1551 100644 --- a/epiphany-core/src/runtime_spine.rs +++ b/epiphany-core/src/runtime_spine.rs @@ -1,9 +1,5 @@ use crate::EpiphanyWorkerLaunchDocument; use crate::RepoFrontierPlanMindContextProjection; -use crate::runtime_store_backend::{ - RuntimeSpineBackingStore as SingleFileMessagePackBackingStore, - runtime_spine_backing_store, -}; use crate::agent_launch::{ EPIPHANY_IMAGINATION_OWNER_ROLE, EPIPHANY_IMAGINATION_ROLE_BINDING_ID, EPIPHANY_MIND_OWNER_ROLE, EPIPHANY_MIND_ROLE_BINDING_ID, EPIPHANY_MODELING_OWNER_ROLE, @@ -94,6 +90,9 @@ use crate::repo_model_gateway::{ RepoModelClaimChallenge, RepoModelClaimRepairFrontierRef, RepoModelClaimRepairLaunchBinding, RepoModelClaimRepairRequest, RepoModelMigrationReceipt, RuntimeRepositoryDomainBinding, }; +use crate::runtime_store_backend::{ + RuntimeSpineBackingStore as SingleFileMessagePackBackingStore, runtime_spine_backing_store, +}; use crate::soul_gateway::SoulVerdictReceipt; use crate::soul_gateway::*; use crate::state_ledger::STATE_LEDGER_SCHEMA_VERSION; @@ -2554,6 +2553,330 @@ pub fn runtime_role_worker_result( cache.get::(job_id) } +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum RuntimeTypedRequestRef<'a> { + ProposalModeling(&'a str), + ImaginationConsideration(&'a str), + AdmittedModelDirection(&'a str), +} + +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct RuntimeTypedFulfillmentEvidence { + pub job_id: String, + pub result_id: String, + pub request_id: String, +} + +fn validate_proposal_modeling_worker_fulfillment( + cache: &CultCache, + result: &EpiphanyRuntimeRoleWorkerResult, +) -> Result<()> { + let request_id = result + .proposal_modeling_request_id + .as_deref() + .ok_or_else(|| anyhow!("proposal Modeling fulfillment lost request echo"))?; + if !result.role_id.eq_ignore_ascii_case("modeling") || result.item_error.is_some() { + return Err(anyhow!( + "proposal Modeling fulfillment requires a successful Modeling result" + )); + } + let patch: crate::RepoModelPatch = rmp_serde::from_slice( + result + .repo_model_patch_msgpack + .as_deref() + .ok_or_else(|| anyhow!("proposal Modeling fulfillment lost RepoModel patch"))?, + ) + .context("decode proposal Modeling fulfillment RepoModel patch")?; + if patch.purpose != crate::RepoModelPatchPurpose::Evolution { + return Err(anyhow!( + "proposal Modeling fulfillment requires an Evolution patch" + )); + } + let request = cache + .get::(request_id)? + .ok_or_else(|| anyhow!("proposal Modeling fulfillment request is missing"))?; + validate_repo_frontier_proposal_modeling_request(&request)?; + let proposal = cache + .get::(&request.proposal_id)? + .ok_or_else(|| anyhow!("proposal Modeling fulfillment proposal is missing"))?; + validate_repo_frontier_work_proposal(&proposal)?; + if proposal.source_kind == crate::RepoFrontierProposalSourceKind::Imagination { + validate_autonomous_proposal_binding(cache, &proposal)?; + } + let bindings = cache + .get_all::()? + .into_iter() + .filter(|binding| binding.job_id == result.job_id) + .collect::>(); + if bindings.len() != 1 { + return Err(anyhow!( + "proposal Modeling fulfillment requires exactly one launch binding" + )); + } + let binding = &bindings[0]; + let launch = cache + .get::(&result.job_id)? + .ok_or_else(|| anyhow!("proposal Modeling fulfillment worker launch is missing"))?; + let document = launch.launch_document()?; + let projection = match &document { + EpiphanyWorkerLaunchDocument::Role(document) => document.proposal_modeling_context.as_ref(), + EpiphanyWorkerLaunchDocument::Reorient(_) => None, + }; + let identity = require_identity(cache)?; + let thread = cache + .get::(crate::THREAD_STATE_KEY)? + .ok_or_else(|| anyhow!("proposal Modeling fulfillment thread state is missing"))?; + thread.state()?; + let payload = rmp_serde::to_vec_named(&( + &proposal.title, + &proposal.body, + &proposal.desired_outcome, + &proposal.constraints, + &proposal.scope_hints, + &proposal.evidence_refs, + ))?; + let proposal_payload_sha256 = format!("{:x}", Sha256::digest(payload)); + let expected_projection = crate::RepoFrontierProposalModelingContextProjection { + schema_version: crate::REPO_FRONTIER_PROPOSAL_MODELING_CONTEXT_SCHEMA_VERSION.into(), + contract: crate::REPO_FRONTIER_PROPOSAL_MODELING_CONTEXT_CONTRACT.into(), + request_id: request.request_id.clone(), + proposal_id: proposal.proposal_id.clone(), + proposal_payload_sha256: proposal.payload_sha256.clone(), + runtime_id: request.runtime_id.clone(), + thread_id: request.thread_id.clone(), + repository: request.repository.clone(), + workspace: request.workspace.clone(), + source_kind: proposal.source_kind, + source_actor: proposal.source_actor.clone(), + source_ref: proposal.source_ref.clone(), + title: proposal.title.clone(), + body: proposal.body.clone(), + desired_outcome: proposal.desired_outcome.clone(), + constraints: proposal.constraints.clone(), + scope_hints: proposal.scope_hints.clone(), + evidence_refs: proposal.evidence_refs.clone(), + private_state_included: proposal.private_state_included, + model_revision: patch.base_revision, + model_hash: patch.base_hash.clone(), + }; + let launch_sha256 = format!("{:x}", Sha256::digest(&launch.launch_document_msgpack)); + let mismatches = [ + ( + "request.payload", + request.proposal_payload_sha256 != proposal.payload_sha256, + ), + ( + "proposal.payload", + proposal.payload_sha256 != proposal_payload_sha256, + ), + ("request.runtime", request.runtime_id != identity.runtime_id), + ("request.thread", request.thread_id != thread.thread_id), + ( + "request.repository", + request.repository != proposal.repository, + ), + ("request.workspace", request.workspace != proposal.workspace), + ( + "binding.id", + binding.binding_record_id + != format!("repo-frontier-proposal-modeling-launch-{}", result.job_id), + ), + ( + "binding.schema", + binding.schema_version != REPO_FRONTIER_PROPOSAL_MODELING_LAUNCH_BINDING_SCHEMA_VERSION, + ), + ( + "binding.contract", + binding.contract != REPO_FRONTIER_PROPOSAL_MODELING_LAUNCH_BINDING_CONTRACT, + ), + ( + "binding.request", + binding.proposal_modeling_request_id != request.request_id, + ), + ( + "binding.proposal", + binding.proposal_id != proposal.proposal_id, + ), + ( + "binding.payload", + binding.proposal_payload_sha256 != proposal.payload_sha256, + ), + ("binding.job", binding.job_id != result.job_id), + ( + "binding.role", + binding.binding_id != EPIPHANY_MODELING_ROLE_BINDING_ID, + ), + ("binding.runtime", binding.runtime_id != identity.runtime_id), + ("binding.thread", binding.thread_id != thread.thread_id), + ( + "binding.time", + chrono::DateTime::parse_from_rfc3339(&binding.launched_at).is_err(), + ), + ( + "binding.hash", + binding.worker_launch_document_sha256 != launch_sha256, + ), + ( + "launch.schema", + launch.schema_version != RUNTIME_WORKER_LAUNCH_REQUEST_SCHEMA_VERSION, + ), + ("launch.job", launch.job_id != result.job_id), + ("launch.binding", launch.binding_id != binding.binding_id), + ("launch.role", launch.role != EPIPHANY_MODELING_OWNER_ROLE), + ( + "launch.request", + launch.proposal_modeling_request_id.as_deref() != Some(request.request_id.as_str()), + ), + ( + "launch.projection", + projection != Some(&expected_projection), + ), + ] + .into_iter() + .filter_map(|(name, failed)| failed.then_some(name)) + .collect::>(); + if !mismatches.is_empty() { + return Err(anyhow!( + "proposal Modeling fulfillment provenance mismatch: {}", + mismatches.join(", ") + )); + } + let upserts = patch + .operations + .iter() + .filter_map(|operation| match operation { + crate::RepoModelPatchOperation::UpsertFrontier { item } => Some(item), + _ => None, + }) + .collect::>(); + let frontier_operations = patch + .operations + .iter() + .filter(|operation| { + matches!( + operation, + crate::RepoModelPatchOperation::UpsertFrontier { .. } + | crate::RepoModelPatchOperation::ReviseFrontier { .. } + | crate::RepoModelPatchOperation::RetireFrontier { .. } + ) + }) + .count(); + if !result + .evidence_ids + .iter() + .any(|id| id == &proposal.proposal_id) + || frontier_operations != 1 + || upserts.len() != 1 + || !upserts[0] + .evidence_refs + .iter() + .any(|id| id == &proposal.proposal_id) + || upserts[0].source_scope.is_empty() + || !safe_sorted_unique_paths(&upserts[0].source_scope) + || upserts[0].status != crate::RepoFrontierStatus::Active + || !matches!( + upserts[0].recommended_next_organ.as_str(), + "Hands" | "Eyes" | "Imagination" + ) + || (proposal.source_kind == crate::RepoFrontierProposalSourceKind::Imagination + && (upserts[0].recommended_next_organ != "Imagination" + || upserts[0].adopted_plan.is_some())) + { + return Err(anyhow!( + "proposal Modeling fulfillment result is not one safe proposal-citing routeable frontier" + )); + } + Ok(()) +} + +pub fn runtime_typed_request_fulfillment( + store_path: impl AsRef, + request: RuntimeTypedRequestRef<'_>, +) -> Result> { + let store_path = store_path.as_ref(); + let request_id = match request { + RuntimeTypedRequestRef::ProposalModeling(id) + | RuntimeTypedRequestRef::ImaginationConsideration(id) + | RuntimeTypedRequestRef::AdmittedModelDirection(id) => id, + }; + validate_non_empty(request_id, "typed fulfillment request id")?; + let mut cache = runtime_spine_cache(store_path)?; + cache.pull_all_backing_stores()?; + let matches = cache + .get_all::()? + .into_iter() + .filter(|result| match request { + RuntimeTypedRequestRef::ProposalModeling(_) => { + result.proposal_modeling_request_id.as_deref() == Some(request_id) + } + RuntimeTypedRequestRef::ImaginationConsideration(_) => { + result.imagination_consideration_request_id.as_deref() == Some(request_id) + } + RuntimeTypedRequestRef::AdmittedModelDirection(_) => { + result + .admitted_model_direction_consideration_request_id + .as_deref() + == Some(request_id) + } + }) + .collect::>(); + if matches.is_empty() { + return Ok(None); + } + if matches.len() != 1 { + return Err(anyhow!( + "typed fulfillment request has multiple terminal worker claimants" + )); + } + let result = &matches[0]; + if result.item_error.is_some() { + return Err(anyhow!( + "typed fulfillment claimant terminated with an item error" + )); + } + // This is the runtime admission owner. Replaying an already persisted + // immutable result performs the same full validation without writing. + put_runtime_role_worker_result(store_path, result)?; + match request { + RuntimeTypedRequestRef::ProposalModeling(_) => { + validate_proposal_modeling_worker_fulfillment(&cache, result)?; + } + RuntimeTypedRequestRef::ImaginationConsideration(_) => { + let candidate = result + .imagination_consideration_candidate()? + .ok_or_else(|| anyhow!("Imagination fulfillment lost typed candidate"))?; + if cache + .get::(&candidate.candidate_id)? + .as_ref() + != Some(&candidate) + { + return Err(anyhow!( + "Imagination fulfillment lost its persisted typed candidate" + )); + } + } + RuntimeTypedRequestRef::AdmittedModelDirection(_) => { + let direction = result + .admitted_model_direction_consideration_result()? + .ok_or_else(|| anyhow!("model direction fulfillment lost typed result"))?; + if cache + .get::(&direction.result_id)? + .as_ref() + != Some(&direction) + { + return Err(anyhow!( + "model direction fulfillment lost its persisted typed result" + )); + } + } + } + Ok(Some(RuntimeTypedFulfillmentEvidence { + job_id: result.job_id.clone(), + result_id: result.result_id.clone(), + request_id: request_id.to_string(), + })) +} + pub fn ensure_runtime_repo_model( runtime_store: impl AsRef, legacy_memory_store: impl AsRef, @@ -3161,263 +3484,19 @@ pub fn commit_repo_model_admission( }) .count(); let request_id = if let Some(request_id) = echoed { - let request = cache - .get::(request_id)? - .ok_or_else(|| { - anyhow!("proposal Evolution requires exact selection request") - })?; - validate_repo_frontier_proposal_modeling_request(&request)?; - let proposal = cache - .get::(&request.proposal_id)? - .ok_or_else(|| anyhow!("proposal Evolution requires exact proposal"))?; - validate_repo_frontier_work_proposal(&proposal)?; - if proposal.source_kind == crate::RepoFrontierProposalSourceKind::Imagination { - validate_autonomous_proposal_binding(&cache, &proposal)?; - } - let launch_bindings = cache - .get_all::()? - .into_iter() - .filter(|binding| binding.job_id == result.job_id) - .collect::>(); - if launch_bindings.len() != 1 { - return Err(anyhow!( - "proposal Evolution requires exactly one coordinator launch binding for its job" - )); - } - let launch_binding = &launch_bindings[0]; - let worker_launch = cache - .get::(&result.job_id)? - .ok_or_else(|| { - anyhow!("proposal Evolution requires its runtime worker launch request") - })?; - let worker_launch_document = worker_launch.launch_document()?; - let launch_projection = match &worker_launch_document { - EpiphanyWorkerLaunchDocument::Role(document) => { - document.proposal_modeling_context.as_ref() - } - EpiphanyWorkerLaunchDocument::Reorient(_) => None, - }; - let identity = require_identity(&cache)?; - let thread = cache - .get::(crate::THREAD_STATE_KEY)? - .ok_or_else(|| { - anyhow!("proposal Evolution requires authoritative thread state") - })?; - thread.state()?; - let content = rmp_serde::to_vec_named(&( - &proposal.title, - &proposal.body, - &proposal.desired_outcome, - &proposal.constraints, - &proposal.scope_hints, - &proposal.evidence_refs, - ))?; - let payload_hash = format!("{:x}", Sha256::digest(content)); - let expected_projection = crate::RepoFrontierProposalModelingContextProjection { - schema_version: crate::REPO_FRONTIER_PROPOSAL_MODELING_CONTEXT_SCHEMA_VERSION - .into(), - contract: crate::REPO_FRONTIER_PROPOSAL_MODELING_CONTEXT_CONTRACT.into(), - request_id: request.request_id.clone(), - proposal_id: proposal.proposal_id.clone(), - proposal_payload_sha256: proposal.payload_sha256.clone(), - runtime_id: request.runtime_id.clone(), - thread_id: request.thread_id.clone(), - repository: request.repository.clone(), - workspace: request.workspace.clone(), - source_kind: proposal.source_kind, - source_actor: proposal.source_actor.clone(), - source_ref: proposal.source_ref.clone(), - title: proposal.title.clone(), - body: proposal.body.clone(), - desired_outcome: proposal.desired_outcome.clone(), - constraints: proposal.constraints.clone(), - scope_hints: proposal.scope_hints.clone(), - evidence_refs: proposal.evidence_refs.clone(), - private_state_included: proposal.private_state_included, - model_revision: patch.base_revision, - model_hash: patch.base_hash.clone(), - }; - let launch_document_sha256 = format!( - "{:x}", - Sha256::digest(&worker_launch.launch_document_msgpack) - ); - let mismatches = [ - ( - "request.schema", - request.schema_version - != REPO_FRONTIER_PROPOSAL_MODELING_REQUEST_SCHEMA_VERSION, - ), - ( - "request.contract", - request.contract != REPO_FRONTIER_PROPOSAL_MODELING_REQUEST_CONTRACT, - ), - ( - "proposal.schema", - proposal.schema_version != REPO_FRONTIER_WORK_PROPOSAL_SCHEMA_VERSION, - ), - ( - "proposal.contract", - proposal.contract != REPO_FRONTIER_WORK_PROPOSAL_CONTRACT, - ), - ("proposal.private", proposal.private_state_included), - ( - "request.payload", - request.proposal_payload_sha256 != proposal.payload_sha256, - ), - ("proposal.payload", proposal.payload_sha256 != payload_hash), - ( - "request.proposal_runtime", - request.runtime_id != proposal.runtime_id, - ), - ("request.runtime", request.runtime_id != identity.runtime_id), - ( - "request.proposal_thread", - request.thread_id != proposal.thread_id, - ), - ("request.thread", request.thread_id != thread.thread_id), - ( - "request.repository", - request.repository != proposal.repository, - ), - ("request.workspace", request.workspace != proposal.workspace), - ( - "binding.id", - launch_binding.binding_record_id - != format!("repo-frontier-proposal-modeling-launch-{}", result.job_id), - ), - ( - "binding.schema", - launch_binding.schema_version - != REPO_FRONTIER_PROPOSAL_MODELING_LAUNCH_BINDING_SCHEMA_VERSION, - ), - ( - "binding.contract", - launch_binding.contract - != REPO_FRONTIER_PROPOSAL_MODELING_LAUNCH_BINDING_CONTRACT, - ), - ( - "binding.request", - launch_binding.proposal_modeling_request_id != request.request_id, - ), - ( - "binding.proposal", - launch_binding.proposal_id != proposal.proposal_id, - ), - ( - "binding.payload", - launch_binding.proposal_payload_sha256 != proposal.payload_sha256, - ), - ("binding.job", launch_binding.job_id != result.job_id), - ( - "binding.role", - launch_binding.binding_id != EPIPHANY_MODELING_ROLE_BINDING_ID, - ), - ( - "binding.runtime", - launch_binding.runtime_id != identity.runtime_id, - ), - ( - "binding.thread", - launch_binding.thread_id != thread.thread_id, - ), - ( - "binding.launched_at", - chrono::DateTime::parse_from_rfc3339(&launch_binding.launched_at).is_err(), - ), - ( - "binding.launch_document_hash", - launch_binding.worker_launch_document_sha256 != launch_document_sha256, - ), - ( - "launch.schema", - worker_launch.schema_version - != RUNTIME_WORKER_LAUNCH_REQUEST_SCHEMA_VERSION, - ), - ("launch.job", worker_launch.job_id != result.job_id), - ( - "launch.binding", - worker_launch.binding_id != launch_binding.binding_id, - ), - ( - "launch.role", - worker_launch.role != EPIPHANY_MODELING_OWNER_ROLE, - ), - ( - "launch.request", - worker_launch.proposal_modeling_request_id.as_deref() - != Some(request.request_id.as_str()), - ), - ( - "launch.projection", - launch_projection != Some(&expected_projection), - ), - ( - "launch.model_base", - expected_projection.model_revision != patch.base_revision - || expected_projection.model_hash != patch.base_hash, - ), - ] - .into_iter() - .filter_map(|(name, failed)| failed.then_some(name)) - .collect::>(); - if !mismatches.is_empty() { - return Err(anyhow!( - "proposal Evolution provenance binding mismatch: {}", - mismatches.join(", ") - )); - } + validate_proposal_modeling_worker_fulfillment(&cache, &result)?; if cache .get_all::()? .iter() .any(|receipt| { - receipt.proposal_modeling_request_id == request.request_id + receipt.proposal_modeling_request_id == request_id && (receipt.review_id != review.review_id || receipt.result_id.as_deref() != Some(result.result_id.as_str())) }) { return Err(anyhow!("proposal Modeling request already incorporated")); } - if !result_evidence.iter().any(|id| id == &proposal.proposal_id) - || frontier_operation_count != 1 - || upserts.len() != 1 - || !upserts[0] - .evidence_refs - .iter() - .any(|id| id == &proposal.proposal_id) - { - return Err(anyhow!( - "proposal Evolution requires one proposal-citing frontier upsert and exact evidence" - )); - } - if upserts[0].source_scope.is_empty() - || !safe_sorted_unique_paths(&upserts[0].source_scope) - { - return Err(anyhow!( - "proposal Evolution frontier source_scope must be non-empty, safe relative paths in strict lexicographic order with no duplicates" - )); - } - if upserts[0].status != crate::RepoFrontierStatus::Active { - return Err(anyhow!( - "proposal Evolution frontier must be active so accepted unresolved work is immediately routeable" - )); - } - if !matches!( - upserts[0].recommended_next_organ.as_str(), - "Hands" | "Eyes" | "Imagination" - ) { - return Err(anyhow!( - "proposal Evolution frontier recommended_next_organ must be one exact routeable organ: Hands, Eyes, or Imagination" - )); - } - if proposal.source_kind == crate::RepoFrontierProposalSourceKind::Imagination - && (upserts[0].recommended_next_organ != "Imagination" - || upserts[0].adopted_plan.is_some()) - { - return Err(anyhow!( - "autonomous proposal Modeling may admit only an unadopted Imagination-planning frontier; Mind alone may adopt a plan before Hands" - )); - } - request.request_id + request_id.to_string() } else { validate_ordinary_modeling_frontier_transition( &result.verdict, @@ -8735,9 +8814,7 @@ pub fn retain_coordinator_run_receipts( || head.private_state_exposed || !head.retired_chain_digest.starts_with("sha256:") { - return Err(anyhow!( - "coordinator run receipt retention head is invalid" - )); + return Err(anyhow!("coordinator run receipt retention head is invalid")); } } let snapshot = cache.snapshot_envelopes(); @@ -8794,13 +8871,13 @@ pub fn retain_coordinator_run_receipts( retained_at: retained_at.into(), private_state_exposed: false, }; - let (replacement, _) = cache.prepare_entry( - COORDINATOR_RUN_RECEIPT_RETENTION_HEAD_KEY, - &head, - )?; - if !runtime_spine_backing_store(store_path)? - .replace_and_delete_if_snapshot_unchanged(&snapshot, vec![replacement], &deletions)? - { + let (replacement, _) = + cache.prepare_entry(COORDINATOR_RUN_RECEIPT_RETENTION_HEAD_KEY, &head)?; + if !runtime_spine_backing_store(store_path)?.replace_and_delete_if_snapshot_unchanged( + &snapshot, + vec![replacement], + &deletions, + )? { return Err(anyhow!( "coordinator run receipt retention lost its snapshot fence" )); @@ -10520,20 +10597,24 @@ pub(crate) mod tests { &[&valid], &evidence, )?; - assert!(validate_ordinary_modeling_frontier_transition( - "checkpoint-update-needed", - 0, - &[], - &evidence, - ) - .is_err()); - assert!(validate_ordinary_modeling_frontier_transition( - "checkpoint-ready", - 1, - &[&valid], - &evidence, - ) - .is_err()); + assert!( + validate_ordinary_modeling_frontier_transition( + "checkpoint-update-needed", + 0, + &[], + &evidence, + ) + .is_err() + ); + assert!( + validate_ordinary_modeling_frontier_transition( + "checkpoint-ready", + 1, + &[&valid], + &evidence, + ) + .is_err() + ); let mut hands = valid.clone(); hands.recommended_next_organ = "Hands".into(); @@ -10547,13 +10628,15 @@ pub(crate) mod tests { let mut ungrounded = valid.clone(); ungrounded.evidence_refs = vec!["other-evidence".into()]; for hostile in [&hands, &adopted, &blocked, &ungrounded] { - assert!(validate_ordinary_modeling_frontier_transition( - "checkpoint-update-needed", - 1, - &[hostile], - &evidence, - ) - .is_err()); + assert!( + validate_ordinary_modeling_frontier_transition( + "checkpoint-update-needed", + 1, + &[hostile], + &evidence, + ) + .is_err() + ); } Ok(()) } @@ -10836,6 +10919,73 @@ pub(crate) mod tests { Ok((store, result, review)) } + #[test] + fn typed_proposal_fulfillment_reuses_runtime_admission_and_refuses_hostile_claimants() + -> Result<()> { + let root = tempfile::tempdir()?; + let (store, result, _) = proposal_admission_fixture(root.path(), "typed-fulfillment")?; + let request_id = result + .proposal_modeling_request_id + .clone() + .expect("proposal request echo"); + assert_eq!( + runtime_typed_request_fulfillment( + &store, + RuntimeTypedRequestRef::ProposalModeling(&request_id), + )?, + None + ); + + put_runtime_role_worker_result(&store, &result)?; + let evidence = runtime_typed_request_fulfillment( + &store, + RuntimeTypedRequestRef::ProposalModeling(&request_id), + )? + .expect("authenticated proposal fulfillment"); + assert_eq!(evidence.job_id, result.job_id); + assert_eq!(evidence.result_id, result.result_id); + assert_eq!(evidence.request_id, request_id); + + let hostile_store = root.path().join("typed-fulfillment-hostile.cc"); + std::fs::copy(&store, &hostile_store)?; + let mut hostile_cache = runtime_spine_cache(&hostile_store)?; + hostile_cache.pull_all_backing_stores()?; + let mut binding = hostile_cache + .get_all::()? + .into_iter() + .find(|binding| binding.job_id == result.job_id) + .expect("proposal launch binding"); + binding.worker_launch_document_sha256 = "00".repeat(32); + let binding_id = binding.binding_record_id.clone(); + overwrite_test_entry(&hostile_store, &binding_id, &binding)?; + let before = std::fs::read(&hostile_store)?; + assert!( + runtime_typed_request_fulfillment( + &hostile_store, + RuntimeTypedRequestRef::ProposalModeling(&request_id), + ) + .is_err() + ); + assert_eq!(std::fs::read(&hostile_store)?, before); + + let duplicate_store = root.path().join("typed-fulfillment-duplicate.cc"); + std::fs::copy(&store, &duplicate_store)?; + let mut duplicate = result.clone(); + duplicate.job_id = "duplicate-job".into(); + duplicate.result_id = "duplicate-result".into(); + overwrite_test_entry(&duplicate_store, &duplicate.job_id, &duplicate)?; + let before = std::fs::read(&duplicate_store)?; + assert!( + runtime_typed_request_fulfillment( + &duplicate_store, + RuntimeTypedRequestRef::ProposalModeling(&request_id), + ) + .is_err() + ); + assert_eq!(std::fs::read(&duplicate_store)?, before); + Ok(()) + } + fn claim_repair_admission_fixture( root: &Path, suffix: &str, @@ -13837,8 +13987,8 @@ pub(crate) mod tests { } #[test] - fn coordinator_run_receipt_retention_preserves_authority_and_cannot_resurrect_work( - ) -> Result<()> { + fn coordinator_run_receipt_retention_preserves_authority_and_cannot_resurrect_work() + -> Result<()> { let temp = tempdir()?; let store = temp.path().join("runtime.msgpack"); initialize_runtime_spine( @@ -13892,13 +14042,8 @@ pub(crate) mod tests { .into_iter() .filter(|entry| entry.r#type != EpiphanyCoordinatorRunReceipt::TYPE) .collect::>(); - let head = retain_coordinator_run_receipts( - &store, - 1, - &preserved, - "2026-05-06T00:10:00Z", - )? - .expect("two receipts should be retired"); + let head = retain_coordinator_run_receipts(&store, 1, &preserved, "2026-05-06T00:10:00Z")? + .expect("two receipts should be retired"); assert_eq!(head.revision, 1); assert_eq!(head.retired_receipt_count, 2); assert_eq!( @@ -13928,9 +14073,7 @@ pub(crate) mod tests { assert_eq!(unrelated_after, unrelated_before); assert!( cache - .get::( - COORDINATOR_RUN_RECEIPT_RETENTION_HEAD_KEY, - )? + .get::(COORDINATOR_RUN_RECEIPT_RETENTION_HEAD_KEY,)? .is_none(), "the retention head must not deserialize as runnable receipt authority" ); @@ -13943,13 +14086,8 @@ pub(crate) mod tests { Some(&head) ); assert!( - retain_coordinator_run_receipts( - &store, - 1, - &preserved, - "2026-05-06T00:11:00Z", - )? - .is_none(), + retain_coordinator_run_receipts(&store, 1, &preserved, "2026-05-06T00:11:00Z",)? + .is_none(), "a stable retained set must not rewrite the head" ); Ok(()) @@ -13997,13 +14135,8 @@ pub(crate) mod tests { }, )?; } - retain_coordinator_run_receipts( - &store, - 0, - &BTreeSet::new(), - "2026-05-06T00:10:00Z", - )? - .expect("the older receipt should be retired"); + retain_coordinator_run_receipts(&store, 0, &BTreeSet::new(), "2026-05-06T00:10:00Z")? + .expect("the older receipt should be retired"); let receipts = coordinator_run_receipts(&store)?; assert_eq!(receipts.len(), 1); assert_eq!(receipts[0].receipt_id, "receipt-2");