From 5f1bea391380ac260be021d7cbd193e984a25150 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Tue, 25 Aug 2026 00:45:10 +0200 Subject: [PATCH] Reuse exact Mind snapshot for fulfillment --- epiphany-core/src/current_work.rs | 9 +++++--- epiphany-core/src/lib.rs | 1 - epiphany-core/src/resident_self.rs | 10 ++++++++- epiphany-core/src/runtime_spine.rs | 33 ++++++++++++++++++------------ 4 files changed, 35 insertions(+), 18 deletions(-) diff --git a/epiphany-core/src/current_work.rs b/epiphany-core/src/current_work.rs index 771cc940..c5cedf07 100644 --- a/epiphany-core/src/current_work.rs +++ b/epiphany-core/src/current_work.rs @@ -1751,8 +1751,9 @@ pub fn accept_frontier_research_result( .ok_or_else(|| anyhow!("frontier Research acceptance lost its launch"))?; let request = crate::runtime_spine::frontier_research_request_for_launch(&cache, &launch)? .ok_or_else(|| anyhow!("frontier Research acceptance lost its exact request"))?; - let fulfillment = crate::runtime_typed_request_fulfillment( + let fulfillment = crate::runtime_spine::runtime_typed_request_fulfillment_from_cache( store_path, + &cache, crate::RuntimeTypedRequestRef::FrontierResearch(&request.request_id), )? .ok_or_else(|| anyhow!("frontier Research result is not exact typed fulfillment"))?; @@ -1955,8 +1956,9 @@ pub fn accept_frontier_verification_result( .ok_or_else(|| anyhow!("frontier Verification acceptance lost its launch"))?; let request = crate::runtime_spine::frontier_verification_request_for_launch(&cache, &launch)? .ok_or_else(|| anyhow!("frontier Verification acceptance lost its exact request"))?; - let fulfillment = crate::runtime_typed_request_fulfillment( + let fulfillment = crate::runtime_spine::runtime_typed_request_fulfillment_from_cache( store_path, + &cache, crate::RuntimeTypedRequestRef::FrontierVerification(&request.request_id), )? .ok_or_else(|| anyhow!("frontier Verification result is not exact typed fulfillment"))?; @@ -2261,8 +2263,9 @@ pub fn accept_proposal_modeling_result( if !result.role_id.eq_ignore_ascii_case("modeling") || role_launch.family_context_count() != 1 { return Err(anyhow!("proposal Modeling result crossed family authority")); } - let evidence = crate::runtime_typed_request_fulfillment( + let evidence = crate::runtime_spine::runtime_typed_request_fulfillment_from_cache( store_path, + &cache, crate::RuntimeTypedRequestRef::ProposalModeling(request_id), )? .ok_or_else(|| anyhow!("proposal Modeling result is not exact typed fulfillment"))?; diff --git a/epiphany-core/src/lib.rs b/epiphany-core/src/lib.rs index c517716d..4e09b5fc 100644 --- a/epiphany-core/src/lib.rs +++ b/epiphany-core/src/lib.rs @@ -270,7 +270,6 @@ pub use runtime_spine::runtime_requested_public_source_refs_for_worker; pub use runtime_spine::runtime_role_worker_result; pub use runtime_spine::runtime_spine_cache; pub(crate) use runtime_spine::runtime_typed_request_attempt_exists; -pub(crate) use runtime_spine::runtime_typed_request_fulfillment; pub use runtime_spine::runtime_worker_launch_request; pub use runtime_spine::runtime_worker_process_claim; pub use runtime_spine::runtime_worker_process_claims; diff --git a/epiphany-core/src/resident_self.rs b/epiphany-core/src/resident_self.rs index 3bd3f1c8..364510fc 100644 --- a/epiphany-core/src/resident_self.rs +++ b/epiphany-core/src/resident_self.rs @@ -1215,8 +1215,16 @@ pub fn verify_resident_self_grant_fulfillment( let Some(request) = request else { return Ok(ResidentSelfGrantFulfillment::Fulfilled); }; + let mut runtime = crate::runtime_spine_cache(runtime_store)?; + runtime.pull_all_backing_stores()?; Ok( - if crate::runtime_typed_request_fulfillment(runtime_store, request)?.is_some() { + if crate::runtime_spine::runtime_typed_request_fulfillment_from_cache( + runtime_store, + &runtime, + request, + )? + .is_some() + { ResidentSelfGrantFulfillment::Fulfilled } else { ResidentSelfGrantFulfillment::Pending diff --git a/epiphany-core/src/runtime_spine.rs b/epiphany-core/src/runtime_spine.rs index e9c06d6c..27d01614 100644 --- a/epiphany-core/src/runtime_spine.rs +++ b/epiphany-core/src/runtime_spine.rs @@ -3391,6 +3391,16 @@ pub fn put_runtime_role_worker_result( result: &EpiphanyRuntimeRoleWorkerResult, ) -> Result<()> { let store_path = store_path.as_ref(); + let mut cache = runtime_spine_cache(store_path)?; + cache.pull_all_backing_stores()?; + put_runtime_role_worker_result_from_cache(store_path, &cache, result) +} + +fn put_runtime_role_worker_result_from_cache( + store_path: &Path, + cache: &CultCache, + result: &EpiphanyRuntimeRoleWorkerResult, +) -> Result<()> { validate_non_empty(&result.job_id, "role worker result job id")?; validate_non_empty(&result.result_id, "role worker result id")?; validate_non_empty(&result.role_id, "role worker result role id")?; @@ -3398,9 +3408,7 @@ pub fn put_runtime_role_worker_result( &result.decision_context_id, "role worker result decision context id", )?; - let mut cache = runtime_spine_cache(store_path)?; - cache.pull_all_backing_stores()?; - require_worker_decision_context(&cache, &result.decision_context_id, &result.job_id)?; + require_worker_decision_context(cache, &result.decision_context_id, &result.job_id)?; let worker_launch = cache .get::(&result.job_id)? .ok_or_else(|| anyhow!("role worker result requires its immutable worker launch"))?; @@ -4096,15 +4104,13 @@ pub(crate) fn validate_proposal_modeling_worker_admission( Ok(()) } -pub(crate) fn runtime_typed_request_fulfillment( - store_path: impl AsRef, +pub(crate) fn runtime_typed_request_fulfillment_from_cache( + store_path: &Path, + cache: &CultCache, request: RuntimeTypedRequestRef<'_>, ) -> Result> { - let store_path = store_path.as_ref(); let request_id = request.request_id(); validate_non_empty(request_id, "typed fulfillment request id")?; - let mut cache = runtime_spine_cache(store_path)?; - cache.pull_all_backing_stores()?; let admission_refusals = cache .get_all::()? .into_iter() @@ -4206,7 +4212,7 @@ pub(crate) fn runtime_typed_request_fulfillment( } // 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)?; + put_runtime_role_worker_result_from_cache(store_path, cache, result)?; match request { RuntimeTypedRequestRef::ProposalModeling(_) => { validate_proposal_modeling_worker_fulfillment(&cache, result)?; @@ -4997,7 +5003,7 @@ pub fn commit_repo_frontier_plan_mind_request( )); } let result = &results[0]; - put_runtime_role_worker_result(runtime_store, result)?; + put_runtime_role_worker_result_from_cache(runtime_store, &cache, result)?; let source_launch = role_launch_document_for_job(&cache, &result.job_id)?; let planning_request_id = source_launch .frontier_planning_context @@ -7894,9 +7900,10 @@ fn archive_runtime_worker_attempt( _ => unreachable!("typed request kind was selected above"), }; let evidence = - runtime_typed_request_fulfillment(store_path, request_ref)?.ok_or_else(|| { - anyhow!("fulfilled worker attempt archive lost authenticated fulfillment") - })?; + runtime_typed_request_fulfillment_from_cache(store_path, &cache, request_ref)? + .ok_or_else(|| { + anyhow!("fulfilled worker attempt archive lost authenticated fulfillment") + })?; if evidence.job_id != job_id || claim.terminal_authority_id.as_deref() != Some(evidence.result_id.as_str()) {