From 8dbfcf6365218d0c07882c25b376fa2bbda9007b Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Mon, 24 Aug 2026 02:20:01 +0200 Subject: [PATCH] Delete final duplicate launch bindings --- .../src/bin/epiphany-mvp-coordinator.rs | 10 +- epiphany-core/src/current_work.rs | 496 +++++++++--------- .../src/imagination_consideration.rs | 28 - epiphany-core/src/lib.rs | 31 +- epiphany-core/src/reorientation_work.rs | 203 ++++--- epiphany-core/src/runtime_spine.rs | 50 +- 6 files changed, 397 insertions(+), 421 deletions(-) diff --git a/epiphany-core/src/bin/epiphany-mvp-coordinator.rs b/epiphany-core/src/bin/epiphany-mvp-coordinator.rs index 43855ce9..4264ecf1 100644 --- a/epiphany-core/src/bin/epiphany-mvp-coordinator.rs +++ b/epiphany-core/src/bin/epiphany-mvp-coordinator.rs @@ -1161,17 +1161,13 @@ fn run_coordinator(args: &Args) -> Result { } else if role_id == "modeling" && status["currentWork"]["bodyModeling"].is_object() { - let binding = epiphany_core::launch_current_body_modeling_work( + let job_id = epiphany_core::launch_current_body_modeling_work( &runtime_store, - epiphany_core::EpiphanyBodyModelingLaunchOptions { - job_id: Uuid::new_v4().to_string(), - created_at: now(), - }, + &now(), )?; json!({ "bindingId": epiphany_core::EPIPHANY_MODELING_ROLE_BINDING_ID, - "backendJobId": binding.job_id, - "bodyModelingLaunchBinding": binding, + "backendJobId": job_id, }) } else if role_id == "modeling" && status["currentWork"]["frontierVerdictModeling"].is_object() diff --git a/epiphany-core/src/current_work.rs b/epiphany-core/src/current_work.rs index 67a41b62..c952c553 100644 --- a/epiphany-core/src/current_work.rs +++ b/epiphany-core/src/current_work.rs @@ -14,8 +14,6 @@ use crate::RepoFrontierResearchContinuationAction; pub const BODY_MODELING_DECISION_RECEIPT_SCHEMA_VERSION: &str = "epiphany.mind.body_modeling_decision.v1"; -pub const BODY_MODELING_LAUNCH_BINDING_SCHEMA_VERSION: &str = - "epiphany.runtime.body_modeling_launch.v1"; pub const AGENT_PASS_ADMISSION_REFUSAL_SCHEMA_VERSION: &str = "epiphany.mind.agent_pass_admission_refusal.v1"; @@ -233,36 +231,6 @@ pub struct EpiphanyBodyModelingCurrentWorkProjection { pub attempt: EpiphanyAgentPassAttemptProjection, } -#[derive(Clone, Debug, PartialEq, Eq, DatabaseEntry)] -#[cultcache( - type = "epiphany.runtime.body_modeling_launch.v1", - schema = "EpiphanyBodyModelingLaunchBinding" -)] -pub struct EpiphanyBodyModelingLaunchBinding { - #[cultcache(key = 0)] - pub schema_version: String, - #[cultcache(key = 1)] - pub binding_record_id: String, - #[cultcache(key = 2)] - pub work_id: String, - #[cultcache(key = 3)] - pub job_id: String, - #[cultcache(key = 4)] - pub attempt_ordinal: u64, - #[cultcache(key = 5)] - pub body_document_sha256: String, - #[cultcache(key = 6)] - pub observed_repo_model_projection_digest: String, - #[cultcache(key = 7)] - pub launched_at: String, -} - -#[derive(Clone, Debug, PartialEq, Eq)] -pub struct EpiphanyBodyModelingLaunchOptions { - pub job_id: String, - pub created_at: String, -} - #[derive(Clone, Debug, PartialEq, Eq)] pub struct EpiphanyProposalModelingLaunchOptions { pub created_at: String, @@ -373,7 +341,6 @@ impl EpiphanyBodyModelingDecisionReceipt { pub(crate) fn register_current_work_types(cache: &mut CultCache) -> Result<()> { cache.register_entry_type::()?; - cache.register_entry_type::()?; cache.register_entry_type::()?; Ok(()) } @@ -482,7 +449,7 @@ pub fn project_current_work(store_path: impl AsRef) -> Result Some(EpiphanyBodyModelingCurrentWorkProjection { - attempt: body_modeling_attempt(&cache, &work.work_id)?, + attempt: body_modeling_attempt(&cache, &work)?, work, }), None => None, @@ -532,7 +499,7 @@ fn consideration_attempt( Ok(EpiphanyAgentPassAttemptProjection::from_job(&job, false)) } -fn consideration_attempt_ordinal(request_id: &str, job_id: &str) -> Result { +pub(crate) fn consideration_attempt_ordinal(request_id: &str, job_id: &str) -> Result { let prefix = format!("consideration-{request_id}-attempt-"); job_id .strip_prefix(&prefix) @@ -547,7 +514,7 @@ fn current_imagination_consideration_work( let model_basis = crate::repo_model_documents::assemble_repo_model_view_from_cache(cache)?.reasoning_basis(); let candidates = cache.get_all::()?; - let bindings = cache.get_all::()?; + let launches = cache.get_all::()?; let mut requests = cache.get_all::()?; requests.sort_by(|left, right| left.request_id.cmp(&right.request_id)); let mut work = Vec::new(); @@ -561,22 +528,32 @@ fn current_imagination_consideration_work( continue; } crate::validate_current_imagination_consideration_request(cache, &request)?; - let mut launches = bindings + let mut job_ids = launches .iter() - .filter(|binding| binding.request_id == request.request_id) - .map(|binding| { + .filter(|launch| { + launch.imagination_consideration_request_id.as_deref() + == Some(request.request_id.as_str()) + }) + .map(|launch| { Ok(( - consideration_attempt_ordinal(&request.request_id, &binding.job_id)?, - binding.job_id.clone(), + consideration_attempt_ordinal(&request.request_id, &launch.job_id)?, + launch.job_id.clone(), )) }) .collect::>>()?; - launches.sort_by_key(|(ordinal, _)| *ordinal); - let launches = launches + job_ids.sort_by_key(|(ordinal, _)| *ordinal); + for (expected, (ordinal, _)) in job_ids.iter().enumerate() { + if *ordinal != expected { + return Err(anyhow!( + "Persona feedback consideration has noncontiguous attempt identity" + )); + } + } + let job_ids = job_ids .into_iter() .map(|(_, job_id)| job_id) .collect::>(); - let attempt = consideration_attempt(cache, &launches)?; + let attempt = consideration_attempt(cache, &job_ids)?; work.push(EpiphanyImaginationConsiderationWorkProjection { request, attempt }); } Ok(work) @@ -819,30 +796,87 @@ fn current_frontier_verdict_modeling_work( Ok(None) } +fn body_modeling_attempt_ordinal(work_id: &str, job_id: &str) -> Result { + let prefix = format!("{work_id}-attempt-"); + job_id + .strip_prefix(&prefix) + .ok_or_else(|| anyhow!("Body Modeling job identity is not canonical"))? + .parse::() + .map_err(|_| anyhow!("Body Modeling attempt ordinal is invalid")) +} + +fn body_modeling_launches( + cache: &CultCache, + work: &EpiphanyBodyModelingWorkProjection, +) -> Result> { + let prefix = format!("{}-attempt-", work.work_id); + let mut launches = cache + .get_all::()? + .into_iter() + .filter(|launch| launch.job_id.starts_with(&prefix)) + .map(|launch| { + let ordinal = body_modeling_attempt_ordinal(&work.work_id, &launch.job_id)?; + let document = launch.launch_document()?; + let role = match &document { + crate::EpiphanyWorkerLaunchDocument::Role(role) => role, + crate::EpiphanyWorkerLaunchDocument::Reorient(_) => { + return Err(anyhow!("Body Modeling launch used reorientation authority")); + } + }; + if launch.schema_version != crate::RUNTIME_WORKER_LAUNCH_REQUEST_SCHEMA_VERSION + || launch.role != crate::EPIPHANY_MODELING_OWNER_ROLE + || launch.binding_id != crate::EPIPHANY_MODELING_ROLE_BINDING_ID + || document.thread_id() != launch.job_id + || role.role_id != "modeling" + || role.repository_body_observation_basis.as_ref() != Some(&work.body_basis) + || launch.proposal_modeling_request_id.is_some() + || launch.repo_frontier_modeling_request_id.is_some() + || launch.frontier_planning_request_id.is_some() + || launch.frontier_plan_mind_request_id.is_some() + || launch.imagination_consideration_request_id.is_some() + || launch + .admitted_model_direction_consideration_request_id + .is_some() + || launch.repo_frontier_research_request_id.is_some() + || launch.repo_frontier_verification_request_id.is_some() + { + return Err(anyhow!( + "Body Modeling immutable launch crossed family authority" + )); + } + Ok((ordinal, launch)) + }) + .collect::>>()?; + launches.sort_by_key(|(ordinal, _)| *ordinal); + for (expected, (ordinal, _)) in launches.iter().enumerate() { + if *ordinal != expected { + return Err(anyhow!( + "Body Modeling request has noncontiguous attempt identity" + )); + } + } + Ok(launches) +} + fn body_modeling_attempt( cache: &CultCache, - work_id: &str, + work: &EpiphanyBodyModelingWorkProjection, ) -> Result { - let mut bindings = cache - .get_all::()? - .into_iter() - .filter(|binding| binding.work_id == work_id) - .collect::>(); - bindings.sort_by_key(|binding| binding.attempt_ordinal); - let Some(binding) = bindings.last() else { + let launches = body_modeling_launches(cache, work)?; + let Some((_, launch)) = launches.last() else { return Ok(EpiphanyAgentPassAttemptProjection::unattempted()); }; let job = cache - .get::(&binding.job_id)? - .ok_or_else(|| anyhow!("Body Modeling launch binding lost its runtime job"))?; - let result = cache.get::(&binding.job_id)?; + .get::(&launch.job_id)? + .ok_or_else(|| anyhow!("Body Modeling launch lost its runtime job"))?; + let result = cache.get::(&launch.job_id)?; let reviewable = result.is_some(); let admission_refusals = cache.get_all::()?; let admission_refused = result.as_ref().is_some_and(|result| { admission_refusals.iter().any(|refusal| { refusal.pass_family == EpiphanyAgentPassFamily::BodyModeling - && refusal.request_id == work_id - && refusal.job_id == binding.job_id + && refusal.request_id == work.work_id + && refusal.job_id == launch.job_id && refusal.result_id == result.result_id && refusal.decision_context_id == result.decision_context_id }) @@ -850,7 +884,7 @@ fn body_modeling_attempt( if admission_refused { return Ok(EpiphanyAgentPassAttemptProjection::with( EpiphanyAgentPassContinuationAction::Launch, - Some(binding.job_id.clone()), + Some(launch.job_id.clone()), )); } Ok(EpiphanyAgentPassAttemptProjection::from_job( @@ -1008,30 +1042,10 @@ pub fn body_modeling_continuation_action_for_job( store_path: impl AsRef, job_id: &str, ) -> Result> { - let mut cache = crate::runtime_spine_cache(store_path)?; - cache.pull_all_backing_stores()?; - let bindings = cache - .get_all::()? - .into_iter() - .filter(|binding| binding.job_id == job_id) - .collect::>(); - let [binding] = bindings.as_slice() else { - if bindings.is_empty() { - return Ok(None); - } - return Err(anyhow!( - "runtime job has multiple Body Modeling launch bindings" - )); - }; - if cache - .get::(&binding.work_id)? - .is_some() - { - return Ok(None); - } - Ok(Some( - body_modeling_attempt(&cache, &binding.work_id)?.action, - )) + Ok(project_current_work(store_path)? + .body_modeling + .filter(|work| work.attempt.job_id.as_deref() == Some(job_id)) + .map(|work| work.attempt.action)) } pub fn current_body_modeling_review_job_id(store_path: impl AsRef) -> Result> { @@ -2737,68 +2751,76 @@ fn launch_consideration_work( .get::(crate::RUNTIME_IDENTITY_KEY)? .ok_or_else(|| anyhow!("consideration launch requires runtime identity"))?; let model = crate::repo_model_documents::assemble_repo_model_view_from_cache(&cache)?; - let (attempt_ordinal, dynamic_prompt_context, imagination_context, direction_context) = - match launch { - ConsiderationLaunch::PersonaFeedback(request) => { - crate::validate_current_imagination_consideration_request(&cache, request)?; - let current = current_imagination_consideration_work(&cache)? - .into_iter() - .find(|work| work.request.request_id == request.request_id) - .ok_or_else(|| anyhow!("Persona feedback consideration is not current"))?; - if current.attempt.action != EpiphanyAgentPassContinuationAction::Launch { - return Err(anyhow!("Persona feedback consideration is not launchable")); - } - let ordinal = cache - .get_all::()? - .into_iter() - .filter(|binding| binding.request_id == request.request_id) - .count(); - ( - ordinal, - crate::render_imagination_consideration_prompt(request)?, - Some(crate::ImaginationConsiderationContextProjection::new( - request, &model, - )), - None, - ) - } - ConsiderationLaunch::AdmittedModelDirection(request) => { - crate::validate_current_admitted_model_direction_consideration_request( - &cache, request, - )?; - let current = current_admitted_model_direction_consideration_work(&cache)? - .filter(|work| work.request.request_id == request.request_id) - .ok_or_else(|| { - anyhow!("admitted model direction consideration is not current") - })?; - if current.attempt.action != EpiphanyAgentPassContinuationAction::Launch { - return Err(anyhow!( - "admitted model direction consideration is not launchable" - )); - } - let ordinal = cache - .get_all::()? - .into_iter() - .filter(|worker| { - worker - .admitted_model_direction_consideration_request_id - .as_deref() - == Some(request.request_id.as_str()) - }) - .count(); - ( - ordinal, - crate::render_admitted_model_direction_consideration_prompt(request), - None, - Some( - crate::AdmittedModelDirectionConsiderationContextProjection::new( - request, &model, - ), - ), - ) - } - }; let request_id = launch.request_id().to_string(); + let is_feedback = matches!(launch, ConsiderationLaunch::PersonaFeedback(_)); + let mut prior_launches = cache + .get_all::()? + .into_iter() + .filter(|worker| { + if is_feedback { + worker.imagination_consideration_request_id.as_deref() == Some(request_id.as_str()) + } else { + worker + .admitted_model_direction_consideration_request_id + .as_deref() + == Some(request_id.as_str()) + } + }) + .map(|worker| { + Ok(( + consideration_attempt_ordinal(&request_id, &worker.job_id)?, + worker, + )) + }) + .collect::>>()?; + prior_launches.sort_by_key(|(ordinal, _)| *ordinal); + for (expected, (ordinal, _)) in prior_launches.iter().enumerate() { + if *ordinal != expected { + return Err(anyhow!("consideration has noncontiguous attempt identity")); + } + } + let attempt_ordinal = prior_launches.len(); + let (dynamic_prompt_context, imagination_context, direction_context) = match launch { + ConsiderationLaunch::PersonaFeedback(request) => { + crate::validate_current_imagination_consideration_request(&cache, request)?; + let current = current_imagination_consideration_work(&cache)? + .into_iter() + .find(|work| work.request.request_id == request.request_id) + .ok_or_else(|| anyhow!("Persona feedback consideration is not current"))?; + if current.attempt.action != EpiphanyAgentPassContinuationAction::Launch { + return Err(anyhow!("Persona feedback consideration is not launchable")); + } + ( + crate::render_imagination_consideration_prompt(request)?, + Some(crate::ImaginationConsiderationContextProjection::new( + request, &model, + )), + None, + ) + } + ConsiderationLaunch::AdmittedModelDirection(request) => { + crate::validate_current_admitted_model_direction_consideration_request( + &cache, request, + )?; + let current = current_admitted_model_direction_consideration_work(&cache)? + .filter(|work| work.request.request_id == request.request_id) + .ok_or_else(|| anyhow!("admitted model direction consideration is not current"))?; + if current.attempt.action != EpiphanyAgentPassContinuationAction::Launch { + return Err(anyhow!( + "admitted model direction consideration is not launchable" + )); + } + ( + crate::render_admitted_model_direction_consideration_prompt(request), + None, + Some( + crate::AdmittedModelDirectionConsiderationContextProjection::new( + request, &model, + ), + ), + ) + } + }; let job_id = format!("consideration-{request_id}-attempt-{attempt_ordinal}"); let launch_document = crate::EpiphanyWorkerLaunchDocument::Role(crate::EpiphanyRoleWorkerLaunchDocument { @@ -2823,7 +2845,6 @@ fn launch_consideration_work( } .to_string(); let output_contract_id = launch_document.output_contract_id().to_string(); - let is_feedback = matches!(launch, ConsiderationLaunch::PersonaFeedback(_)); let prepared = crate::prepare_runtime_spine_heartbeat_job( &cache, crate::RuntimeSpineHeartbeatJobOptions { @@ -2874,42 +2895,11 @@ fn launch_consideration_work( &cache, launch.model_source_documents(), )?); - let mut companions = Vec::new(); - if let ConsiderationLaunch::PersonaFeedback(request) = launch { - let worker = prepared - .iter() - .find(|envelope| { - envelope.r#type == crate::EpiphanyRuntimeWorkerLaunchRequest::TYPE - && envelope.key == job_id - }) - .ok_or_else(|| anyhow!("consideration launch preparation lost its worker"))?; - let worker: crate::EpiphanyRuntimeWorkerLaunchRequest = - rmp_serde::from_slice(&worker.payload)?; - let binding_record_id = format!( - "imagination-consideration-launch-{}-attempt-{attempt_ordinal}", - request.request_id - ); - companions.push( + for (_, worker) in &prior_launches { + expected.push( cache - .prepare_entry( - &binding_record_id, - &crate::ImaginationConsiderationLaunchBinding { - schema_version: - crate::IMAGINATION_CONSIDERATION_LAUNCH_BINDING_SCHEMA_VERSION.into(), - binding_record_id: binding_record_id.clone(), - request_id: request.request_id.clone(), - job_id: job_id.clone(), - binding_id: crate::EPIPHANY_IMAGINATION_ROLE_BINDING_ID.into(), - runtime_id: request.runtime_id.clone(), - thread_id: request.thread_id.clone(), - launched_at: created_at.into(), - worker_launch_document_sha256: format!( - "{:x}", - Sha256::digest(&worker.launch_document_msgpack) - ), - }, - )? - .0, + .get_envelope::(&worker.job_id)? + .ok_or_else(|| anyhow!("consideration retry lost its prior launch envelope"))?, ); } commit_current_work_launch( @@ -2917,7 +2907,7 @@ fn launch_consideration_work( &cache, expected, prepared, - companions, + Vec::new(), "consideration", )?; Ok(job_id) @@ -2961,14 +2951,11 @@ pub fn launch_current_admitted_model_direction_consideration_work( pub fn launch_current_body_modeling_work( store_path: impl AsRef, - options: EpiphanyBodyModelingLaunchOptions, -) -> Result { + created_at: &str, +) -> Result { let store_path = store_path.as_ref(); - if options.job_id.trim().is_empty() - || chrono::DateTime::parse_from_rfc3339(&options.created_at).is_err() - { - return Err(anyhow!("Body Modeling launch options are invalid")); - } + chrono::DateTime::parse_from_rfc3339(created_at) + .map_err(|_| anyhow!("Body Modeling launch time is invalid"))?; let mind = crate::assemble_mind_view(store_path)?; let body_basis = mind .repository_body_observation @@ -2990,7 +2977,7 @@ pub fn launch_current_body_modeling_work( cache.get::(&work.work_id)?, )? .is_none() - || body_modeling_attempt(&cache, &work.work_id)?.action + || body_modeling_attempt(&cache, &work)?.action != EpiphanyAgentPassContinuationAction::Launch { return Err(anyhow!("Mind has no launchable Body Modeling work")); @@ -3004,20 +2991,12 @@ pub fn launch_current_body_modeling_work( }) .cloned() .ok_or_else(|| anyhow!("Body Modeling launch lost its admitted Body source"))?; - let attempt_ordinal = cache - .get_all::()? - .into_iter() - .filter(|binding| binding.work_id == work.work_id) - .map(|binding| binding.attempt_ordinal) - .max() - .map_or(0, |ordinal| ordinal + 1); - let binding_record_id = format!( - "body-modeling-launch-{}-attempt-{attempt_ordinal}", - work.work_id - ); + let prior_launches = body_modeling_launches(&cache, &work)?; + let attempt_ordinal = prior_launches.len(); + let job_id = format!("{}-attempt-{attempt_ordinal}", work.work_id); let launch_document = crate::EpiphanyWorkerLaunchDocument::Role(crate::EpiphanyRoleWorkerLaunchDocument { - thread_id: binding_record_id.clone(), + thread_id: job_id.clone(), role_id: "modeling".into(), objective: None, dynamic_prompt_context: None, @@ -3042,7 +3021,7 @@ pub fn launch_current_body_modeling_work( objective: "Model the admitted repository Body".into(), coordinator_note: "Keyed Mind current-work launch transaction opened this session." .into(), - job_id: options.job_id.clone(), + job_id: job_id.clone(), role: crate::EPIPHANY_MODELING_OWNER_ROLE.into(), binding_id: crate::EPIPHANY_MODELING_ROLE_BINDING_ID.into(), authority_scope: authority_scope.clone(), @@ -3057,27 +3036,17 @@ pub fn launch_current_body_modeling_work( repo_frontier_modeling_request_id: None, repo_frontier_research_request_id: None, repo_frontier_verification_request_id: None, - created_at: options.created_at.clone(), + created_at: created_at.into(), }, )?; - let binding = EpiphanyBodyModelingLaunchBinding { - schema_version: BODY_MODELING_LAUNCH_BINDING_SCHEMA_VERSION.into(), - binding_record_id, - work_id: work.work_id, - job_id: options.job_id, - attempt_ordinal, - body_document_sha256: body_source.payload_sha256.clone(), - observed_repo_model_projection_digest: work.repo_model_basis.projection_digest.clone(), - launched_at: options.created_at.clone(), - }; let grant = crate::substrate_gate::substrate_gate_repo_access_grant_for_worker( - format!("substrate-grant-{}", binding.job_id), - binding.job_id.clone(), + format!("substrate-grant-{job_id}"), + job_id.clone(), crate::EPIPHANY_MODELING_ROLE_BINDING_ID.into(), crate::EPIPHANY_MODELING_OWNER_ROLE.into(), authority_scope, false, - options.created_at, + created_at.into(), ); let snapshot = cache.snapshot_envelopes(); let mut expected = Vec::new(); @@ -3093,18 +3062,55 @@ pub fn launch_current_body_modeling_work( expected.push(envelope.clone()); } } + for (_, launch) in &prior_launches { + expected.push( + cache + .get_envelope::(&launch.job_id)? + .ok_or_else(|| anyhow!("Body Modeling retry lost its prior launch envelope"))?, + ); + } + if let Some((_, latest)) = prior_launches.last() { + expected.push( + cache + .get_envelope::(&latest.job_id)? + .ok_or_else(|| anyhow!("Body Modeling retry lost its prior job envelope"))?, + ); + if let Some(result) = cache.get::(&latest.job_id)? { + expected.push( + cache + .get_envelope::(&latest.job_id)? + .ok_or_else(|| anyhow!("Body Modeling retry lost its result envelope"))?, + ); + if let Some(refusal) = cache + .get_all::()? + .into_iter() + .find(|refusal| { + refusal.pass_family == EpiphanyAgentPassFamily::BodyModeling + && refusal.request_id == work.work_id + && refusal.job_id == latest.job_id + && refusal.result_id == result.result_id + && refusal.decision_context_id == result.decision_context_id + }) + { + expected.push( + cache + .get_envelope::(&refusal.refusal_id)? + .ok_or_else(|| { + anyhow!("Body Modeling retry lost its admission refusal envelope") + })?, + ); + } + } + } commit_current_work_launch( store_path, &cache, expected, prepared, - vec![ - cache.prepare_entry(&binding.binding_record_id, &binding)?.0, - cache.prepare_entry(&grant.receipt_id, &grant)?.0, - ], + vec![cache.prepare_entry(&grant.receipt_id, &grant)?.0], "Body Modeling", )?; - Ok(binding) + Ok(job_id) } pub fn launch_current_proposal_modeling_work( @@ -3702,15 +3708,8 @@ mod tests { ); assert_eq!(crate::repository_body_read_counters(), (0, 0)); assert_current_work_reentry_is_read_only(&store, ¤t_work)?; - let scheduled = launch_current_body_modeling_work( - &store, - EpiphanyBodyModelingLaunchOptions { - job_id: "body-scheduled-job".into(), - created_at: "2026-08-17T00:00:02Z".into(), - }, - )?; - assert_eq!(scheduled.work_id, projected_work.work_id); - assert_eq!(scheduled.attempt_ordinal, 0); + let scheduled = launch_current_body_modeling_work(&store, "2026-08-17T00:00:02Z")?; + assert_eq!(scheduled, format!("{}-attempt-0", projected_work.work_id)); let scheduled_work = project_current_work(&store)?; assert_eq!( scheduled_work @@ -3719,7 +3718,7 @@ mod tests { .map(|work| (work.attempt.action, work.attempt.job_id.as_deref())), Some(( EpiphanyAgentPassContinuationAction::Wait, - Some("body-scheduled-job") + Some(scheduled.as_str()) )) ); let resident_policy = crate::ResidentSelfPolicy { @@ -3766,31 +3765,22 @@ mod tests { ); assert!( scheduled_cache - .get::("body-scheduled-job")? + .get::(&scheduled)? .is_some() ); assert!( scheduled_cache - .get::( - "substrate-grant-body-scheduled-job" - )? + .get::(&format!( + "substrate-grant-{scheduled}" + ))? .is_some() ); - assert!( - launch_current_body_modeling_work( - &store, - EpiphanyBodyModelingLaunchOptions { - job_id: "body-scheduled-job-duplicate".into(), - created_at: "2026-08-17T00:00:03Z".into(), - }, - ) - .is_err() - ); + assert!(launch_current_body_modeling_work(&store, "2026-08-17T00:00:03Z").is_err()); assert_eq!(crate::repository_body_read_counters(), (0, 0)); let mut cache = crate::runtime_spine_cache(&store)?; cache.pull_all_backing_stores()?; let failed_launch = cache - .get::("body-scheduled-job")? + .get::(&scheduled)? .expect("scheduled Body launch exists"); drop(cache); let failed_basis = crate::worker_reasoning_basis(&store, &failed_launch)?; @@ -3851,7 +3841,7 @@ mod tests { let mut death_cache = crate::runtime_spine_cache(&store)?; death_cache.pull_all_backing_stores()?; let death = death_cache - .get::("result-worker-death-body-scheduled-job")? + .get::(&format!("result-worker-death-{scheduled}"))? .expect("worker death emits its terminal runtime result"); assert_eq!(death.verdict, "failed"); let death_context = death @@ -3873,7 +3863,7 @@ mod tests { .map(|work| (work.attempt.action, work.attempt.job_id.as_deref())), Some(( EpiphanyAgentPassContinuationAction::Launch, - Some("body-scheduled-job") + Some(scheduled.as_str()) )) ); assert_ne!( @@ -3901,18 +3891,12 @@ mod tests { "/launchModeling" ) ); - let retried = launch_current_body_modeling_work( - &store, - EpiphanyBodyModelingLaunchOptions { - job_id: "body-retry-job".into(), - created_at: "2026-08-17T00:00:04Z".into(), - }, - )?; - assert_eq!(retried.attempt_ordinal, 1); + let retried = launch_current_body_modeling_work(&store, "2026-08-17T00:00:04Z")?; + assert_eq!(retried, format!("{}-attempt-1", projected_work.work_id)); let mut cache = crate::runtime_spine_cache(&store)?; cache.pull_all_backing_stores()?; let launch = cache - .get::("body-retry-job")? + .get::(&retried)? .unwrap(); crate::reset_repository_body_read_counters(); let reasoning_basis = crate::worker_reasoning_basis(&store, &launch)?; diff --git a/epiphany-core/src/imagination_consideration.rs b/epiphany-core/src/imagination_consideration.rs index 2f303540..05f5548e 100644 --- a/epiphany-core/src/imagination_consideration.rs +++ b/epiphany-core/src/imagination_consideration.rs @@ -8,8 +8,6 @@ pub const REQUEST_SCHEMA: &str = "epiphany.self.imagination_consideration_reques pub const REQUEST_CONTRACT: &str = "epiphany.imagination_consideration_request.v1"; pub const CANDIDATE_SCHEMA: &str = "epiphany.imagination.consideration_candidate.v1"; pub const CANDIDATE_CONTRACT: &str = "epiphany.imagination_consideration_candidate.v1"; -pub const LAUNCH_BINDING_SCHEMA: &str = - "epiphany.coordinator.imagination_consideration_launch_binding.v0"; pub const REVIEW_REQUEST_SCHEMA: &str = "epiphany.self.imagination_consideration_review_request.v0"; #[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] @@ -149,32 +147,6 @@ pub struct ImaginationConsiderationCandidate { pub data_classification: String, } -#[derive(Clone, Debug, PartialEq, Eq, DatabaseEntry)] -#[cultcache( - type = "epiphany.coordinator.imagination_consideration_launch_binding", - schema = "ImaginationConsiderationLaunchBinding" -)] -pub struct ImaginationConsiderationLaunchBinding { - #[cultcache(key = 0)] - pub schema_version: String, - #[cultcache(key = 1)] - pub binding_record_id: String, - #[cultcache(key = 2)] - pub request_id: String, - #[cultcache(key = 3)] - pub job_id: String, - #[cultcache(key = 4)] - pub binding_id: String, - #[cultcache(key = 5)] - pub runtime_id: String, - #[cultcache(key = 6)] - pub thread_id: String, - #[cultcache(key = 7)] - pub launched_at: String, - #[cultcache(key = 8)] - pub worker_launch_document_sha256: String, -} - #[derive(Clone, Debug, PartialEq, Eq, DatabaseEntry)] #[cultcache( type = "epiphany.self.imagination_consideration_review_request", diff --git a/epiphany-core/src/lib.rs b/epiphany-core/src/lib.rs index 8f380c45..2d543236 100644 --- a/epiphany-core/src/lib.rs +++ b/epiphany-core/src/lib.rs @@ -100,11 +100,11 @@ pub use cultmesh_integration::EPIPHANY_CANONICAL_SWARM_BRAKE_ID; pub use cultmesh_integration::EPIPHANY_CANONICAL_SWARM_BRAKE_OWNER; pub use cultmesh_integration::{ EPIPHANY_CULTMESH_SWARM_BRAKE_KEY, EPIPHANY_CULTMESH_SWARM_BRAKE_SCHEMA_VERSION, - EPIPHANY_CULTMESH_SWARM_BRAKE_TYPE, EpiphanyCultMeshDocuments, - EpiphanyCultMeshSwarmBrakeEntry, canonical_epiphany_swarm_brake_protected_surfaces, - default_epiphany_cultmesh_swarm_brake, engage_epiphany_cultmesh_swarm_brake, - load_epiphany_cultmesh_swarm_brake, open_epiphany_cultmesh_node, - release_epiphany_cultmesh_swarm_brake, write_epiphany_cultmesh_swarm_brake, + EPIPHANY_CULTMESH_SWARM_BRAKE_TYPE, EpiphanyCultMeshDocuments, EpiphanyCultMeshSwarmBrakeEntry, + canonical_epiphany_swarm_brake_protected_surfaces, default_epiphany_cultmesh_swarm_brake, + engage_epiphany_cultmesh_swarm_brake, load_epiphany_cultmesh_swarm_brake, + open_epiphany_cultmesh_node, release_epiphany_cultmesh_swarm_brake, + write_epiphany_cultmesh_swarm_brake, }; pub use current_work::*; @@ -138,11 +138,10 @@ pub use imagination_consideration::{ CANDIDATE_CONTRACT as IMAGINATION_CONSIDERATION_CANDIDATE_CONTRACT, CANDIDATE_SCHEMA as IMAGINATION_CONSIDERATION_CANDIDATE_SCHEMA_VERSION, ImaginationConsiderationCandidate, ImaginationConsiderationDisposition, - ImaginationConsiderationLaunchBinding, ImaginationConsiderationQuestion, - ImaginationConsiderationRequest, ImaginationConsiderationReviewRequest, - ImaginationConsiderationReviewRoute, ImaginationOptionDraft, - LAUNCH_BINDING_SCHEMA as IMAGINATION_CONSIDERATION_LAUNCH_BINDING_SCHEMA_VERSION, - QuotedPersonaFeedbackEvidence, REQUEST_CONTRACT as IMAGINATION_CONSIDERATION_REQUEST_CONTRACT, + ImaginationConsiderationQuestion, ImaginationConsiderationRequest, + ImaginationConsiderationReviewRequest, ImaginationConsiderationReviewRoute, + ImaginationOptionDraft, QuotedPersonaFeedbackEvidence, + REQUEST_CONTRACT as IMAGINATION_CONSIDERATION_REQUEST_CONTRACT, REQUEST_SCHEMA as IMAGINATION_CONSIDERATION_REQUEST_SCHEMA_VERSION, candidate_id_for_launch as imagination_consideration_candidate_id_for_launch, commit_request as commit_imagination_consideration_request, @@ -176,13 +175,11 @@ pub use persona_discord_crossing::*; pub use persona_discord_permit::*; pub use persona_feedback_admission::{ BIFROST_PERSONA_FEEDBACK_ADMISSION_SCHEMA_VERSION, BIFROST_PERSONA_FEEDBACK_DELIVERY_TYPE, - BifrostPersonaFeedbackAdmission, - LOCAL_PERSONA_FEEDBACK_SCHEMA_VERSION, LocalAdmittedPersonaFeedback, - PERSONA_FEEDBACK_SOCIAL_ADMISSION_SCHEMA_VERSION, PersonaFeedbackPacket, - PersonaFeedbackSocialAdmissionReceipt, admit_persona_feedback_to_social, + BifrostPersonaFeedbackAdmission, LOCAL_PERSONA_FEEDBACK_SCHEMA_VERSION, + LocalAdmittedPersonaFeedback, PERSONA_FEEDBACK_SOCIAL_ADMISSION_SCHEMA_VERSION, + PersonaFeedbackPacket, PersonaFeedbackSocialAdmissionReceipt, admit_persona_feedback_to_social, admitted_persona_feedback, import_bifrost_persona_feedback_deliveries, - persona_feedback_ready_for_cognition, - validate_persona_feedback_store_separation, + persona_feedback_ready_for_cognition, validate_persona_feedback_store_separation, }; pub use persona_social_state::*; pub use persona_turn::PERSONA_INTERPRETER_EFFECT_DOCUMENT_SCHEMA_VERSION; @@ -325,8 +322,8 @@ pub use runtime_spine::runtime_hands_command_receipt; pub use runtime_spine::runtime_hands_commit_receipt; pub use runtime_spine::runtime_hands_patch_receipt; pub(crate) use runtime_spine::runtime_has_actionable_hands_frontier; -pub use runtime_spine::runtime_job_snapshot; pub use runtime_spine::runtime_identity; +pub use runtime_spine::runtime_job_snapshot; pub use runtime_spine::runtime_registered_document_types; pub(crate) use runtime_spine::runtime_reorient_worker_result; pub use runtime_spine::runtime_repo_frontier_planning_lifecycle; diff --git a/epiphany-core/src/reorientation_work.rs b/epiphany-core/src/reorientation_work.rs index 588f5441..24d3b009 100644 --- a/epiphany-core/src/reorientation_work.rs +++ b/epiphany-core/src/reorientation_work.rs @@ -9,8 +9,6 @@ use crate::{ }; pub const REORIENTATION_REQUEST_SCHEMA_VERSION: &str = "epiphany.self.reorientation_request.v1"; -pub const REORIENTATION_LAUNCH_BINDING_SCHEMA_VERSION: &str = - "epiphany.runtime.reorientation_launch.v1"; pub const MIND_REORIENTATION_DECISION_SCHEMA_VERSION: &str = "epiphany.mind.reorientation_decision.v1"; pub const MIND_REORIENTATION_PASS_FAILURE_SCHEMA_VERSION: &str = @@ -48,26 +46,6 @@ pub struct EpiphanyReorientationRequest { pub requested_at: String, } -#[derive(Clone, Debug, PartialEq, Eq, DatabaseEntry)] -#[cultcache( - type = "epiphany.runtime.reorientation_launch.v1", - schema = "EpiphanyReorientationLaunchBinding" -)] -pub struct EpiphanyReorientationLaunchBinding { - #[cultcache(key = 0)] - pub schema_version: String, - #[cultcache(key = 1)] - pub binding_id: String, - #[cultcache(key = 2)] - pub request_id: String, - #[cultcache(key = 3)] - pub job_id: String, - #[cultcache(key = 4)] - pub attempt_ordinal: u64, - #[cultcache(key = 5)] - pub launched_at: String, -} - #[derive(Clone, Debug, PartialEq, Eq, DatabaseEntry)] #[cultcache( type = "epiphany.mind.reorientation_decision.v1", @@ -210,6 +188,81 @@ pub fn request_current_reorientation( Ok(request) } +fn reorientation_attempt_ordinal(request_id: &str, job_id: &str) -> Result { + let prefix = format!("reorientation-{request_id}-attempt-"); + job_id + .strip_prefix(&prefix) + .ok_or_else(|| anyhow!("reorientation job identity is not canonical"))? + .parse::() + .map_err(|_| anyhow!("reorientation attempt ordinal is invalid")) +} + +fn reorientation_launch_document( + launch: &crate::EpiphanyRuntimeWorkerLaunchRequest, +) -> Result { + let document = match launch.launch_document()? { + crate::EpiphanyWorkerLaunchDocument::Reorient(document) => document, + crate::EpiphanyWorkerLaunchDocument::Role(_) => { + return Err(anyhow!("reorientation owner carried a role launch")); + } + }; + if launch.schema_version != crate::RUNTIME_WORKER_LAUNCH_REQUEST_SCHEMA_VERSION + || launch.role != crate::EPIPHANY_REORIENT_OWNER_ROLE + || launch.binding_id != crate::EPIPHANY_REORIENT_LAUNCH_BINDING_ID + || document.schema_version != "epiphany.reorientation_launch_projection.v1" + || document.request_id.trim().is_empty() + || document.creation_thread_id != launch.job_id + || launch.proposal_modeling_request_id.is_some() + || launch.frontier_planning_request_id.is_some() + || launch.frontier_plan_mind_request_id.is_some() + || launch.imagination_consideration_request_id.is_some() + || launch + .admitted_model_direction_consideration_request_id + .is_some() + || launch.repo_frontier_modeling_request_id.is_some() + || launch.repo_frontier_research_request_id.is_some() + || launch.repo_frontier_verification_request_id.is_some() + { + return Err(anyhow!( + "reorientation immutable launch crossed family authority" + )); + } + reorientation_attempt_ordinal(&document.request_id, &launch.job_id)?; + Ok(document) +} + +fn reorientation_launches( + cache: &CultCache, + request_id: &str, +) -> Result> { + let mut launches = Vec::new(); + for launch in cache + .get_all::()? + .into_iter() + .filter(|launch| { + launch.role == crate::EPIPHANY_REORIENT_OWNER_ROLE + || launch.binding_id == crate::EPIPHANY_REORIENT_LAUNCH_BINDING_ID + }) + { + let document = reorientation_launch_document(&launch)?; + if document.request_id == request_id { + launches.push(( + reorientation_attempt_ordinal(request_id, &launch.job_id)?, + launch, + )); + } + } + launches.sort_by_key(|(ordinal, _)| *ordinal); + for (expected, (ordinal, _)) in launches.iter().enumerate() { + if *ordinal != expected { + return Err(anyhow!( + "reorientation request has noncontiguous attempt identity" + )); + } + } + Ok(launches) +} + pub(crate) fn current_reorientation_work( cache: &CultCache, ) -> Result> { @@ -225,33 +278,28 @@ pub(crate) fn current_reorientation_work( { continue; } - let mut bindings = cache - .get_all::()? - .into_iter() - .filter(|binding| binding.request_id == request.request_id) - .collect::>(); - bindings.sort_by_key(|binding| binding.attempt_ordinal); - let Some(binding) = bindings.last() else { + let launches = reorientation_launches(cache, &request.request_id)?; + let Some((_, launch)) = launches.last() else { return Ok(Some(EpiphanyReorientationWorkProjection { request, attempt: crate::EpiphanyAgentPassAttemptProjection::unattempted(), })); }; let job = cache - .get::(&binding.job_id)? + .get::(&launch.job_id)? .ok_or_else(|| anyhow!("reorientation launch lost its runtime job"))?; - let result = cache.get::(&binding.job_id)?; + let result = cache.get::(&launch.job_id)?; let action = match job.status { EpiphanyRuntimeJobStatus::Completed if result.is_some() => { EpiphanyAgentPassContinuationAction::Review } EpiphanyRuntimeJobStatus::Failed => { - let terminal = exact_runtime_job_result(cache, &binding.job_id)?; + let terminal = exact_runtime_job_result(cache, &launch.job_id)?; match terminal.decision_context_id.as_deref() { Some(context_id) if failures.iter().any(|failure| { failure.request_id == request.request_id - && failure.job_id == binding.job_id + && failure.job_id == launch.job_id && failure.runtime_result_id == terminal.result_id && failure.decision_context_id == context_id }) => @@ -269,7 +317,7 @@ pub(crate) fn current_reorientation_work( request, attempt: crate::EpiphanyAgentPassAttemptProjection::with( action, - Some(binding.job_id.clone()), + Some(launch.job_id.clone()), ), })); } @@ -283,13 +331,12 @@ pub fn record_reorientation_pass_failure( let store_path = store_path.as_ref(); let mut cache = crate::runtime_spine_cache(store_path)?; cache.pull_all_backing_stores()?; - let binding = cache - .get_all::()? - .into_iter() - .find(|binding| binding.job_id == job_id) - .ok_or_else(|| anyhow!("reorientation failure has no exact launch binding"))?; + let launch = cache + .get::(job_id)? + .ok_or_else(|| anyhow!("reorientation failure has no immutable launch"))?; + let launch_document = reorientation_launch_document(&launch)?; let request = cache - .get::(&binding.request_id)? + .get::(&launch_document.request_id)? .ok_or_else(|| anyhow!("reorientation failure lost its request"))?; validate_reorientation_request_intrinsic(&request)?; let job = cache @@ -349,10 +396,6 @@ pub fn record_reorientation_pass_failure( EpiphanyReorientationRequest::TYPE, request.request_id.as_str(), ), - ( - EpiphanyReorientationLaunchBinding::TYPE, - binding.binding_id.as_str(), - ), (crate::EpiphanyRuntimeWorkerLaunchRequest::TYPE, job_id), (crate::EpiphanyRuntimeJob::TYPE, job_id), ( @@ -408,11 +451,8 @@ pub fn launch_current_reorientation_work( return Err(anyhow!("reorientation request is not launchable")); } validate_reorientation_request_current(&cache, &work.request)?; - let attempt_ordinal = cache - .get_all::()? - .into_iter() - .filter(|binding| binding.request_id == work.request.request_id) - .count() as u64; + let prior_launches = reorientation_launches(&cache, &work.request.request_id)?; + let attempt_ordinal = prior_launches.len(); let job_id = format!( "reorientation-{}-attempt-{attempt_ordinal}", work.request.request_id @@ -450,28 +490,56 @@ pub fn launch_current_reorientation_work( created_at: created_at.into(), }, )?; - let binding = EpiphanyReorientationLaunchBinding { - schema_version: REORIENTATION_LAUNCH_BINDING_SCHEMA_VERSION.into(), - binding_id: format!("reorientation-launch-{job_id}"), - request_id: work.request.request_id.clone(), - job_id: job_id.clone(), - attempt_ordinal, - launched_at: created_at.into(), - }; - let expected = exact_source_envelopes(&cache, &work.request.source_documents)? + let mut expected = exact_source_envelopes(&cache, &work.request.source_documents)? .into_iter() .chain( cache .get_envelope::(&work.request.request_id)? .into_iter(), ) - .collect(); + .collect::>(); + for (_, launch) in &prior_launches { + expected.push( + cache + .get_envelope::(&launch.job_id)? + .ok_or_else(|| anyhow!("reorientation retry lost its prior launch envelope"))?, + ); + } + if let Some((_, latest)) = prior_launches.last() { + expected.push( + cache + .get_envelope::(&latest.job_id)? + .ok_or_else(|| anyhow!("reorientation retry lost its prior job envelope"))?, + ); + for failure in cache + .get_all::()? + .into_iter() + .filter(|failure| { + failure.request_id == work.request.request_id && failure.job_id == latest.job_id + }) + { + expected.push( + cache + .get_envelope::( + &failure.failure_id, + )? + .ok_or_else(|| anyhow!("reorientation retry lost its failure envelope"))?, + ); + expected.push( + cache + .get_envelope::(&failure.runtime_result_id)? + .ok_or_else(|| { + anyhow!("reorientation retry lost its terminal result envelope") + })?, + ); + } + } crate::current_work::commit_current_work_launch( store_path, &cache, expected, prepared, - vec![cache.prepare_entry(&binding.binding_id, &binding)?.0], + Vec::new(), "reorientation", )?; Ok(job_id) @@ -487,13 +555,12 @@ pub fn accept_reorientation_result( let store_path = store_path.as_ref(); let mut cache = crate::runtime_spine_cache(store_path)?; cache.pull_all_backing_stores()?; - let binding = cache - .get_all::()? - .into_iter() - .find(|binding| binding.job_id == job_id) - .ok_or_else(|| anyhow!("reorientation result has no exact launch binding"))?; + let launch = cache + .get::(job_id)? + .ok_or_else(|| anyhow!("reorientation result has no immutable launch"))?; + let launch_document = reorientation_launch_document(&launch)?; let request = cache - .get::(&binding.request_id)? + .get::(&launch_document.request_id)? .ok_or_else(|| anyhow!("reorientation result lost its request"))?; validate_reorientation_request_intrinsic(&request)?; let job = cache @@ -567,10 +634,6 @@ pub fn accept_reorientation_result( EpiphanyReorientationRequest::TYPE, request.request_id.as_str(), ), - ( - EpiphanyReorientationLaunchBinding::TYPE, - binding.binding_id.as_str(), - ), (crate::EpiphanyRuntimeWorkerLaunchRequest::TYPE, job_id), (crate::EpiphanyRuntimeJob::TYPE, job_id), (crate::EpiphanyRuntimeReorientWorkerResult::TYPE, job_id), diff --git a/epiphany-core/src/runtime_spine.rs b/epiphany-core/src/runtime_spine.rs index 182b6d12..6d027d0d 100644 --- a/epiphany-core/src/runtime_spine.rs +++ b/epiphany-core/src/runtime_spine.rs @@ -88,7 +88,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.v18"; +pub const RUNTIME_SPINE_SCHEMA_VERSION: &str = "epiphany.runtime_spine.v19"; 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"; @@ -864,7 +864,6 @@ fn runtime_spine_schema_cache() -> Result { cache.register_entry_type::()?; cache.register_entry_type::()?; cache.register_entry_type::()?; - cache.register_entry_type::()?; cache.register_entry_type::()?; cache.register_entry_type::()?; cache.register_entry_type::()?; @@ -872,7 +871,6 @@ fn runtime_spine_schema_cache() -> Result { cache.register_entry_type::()?; cache.register_entry_type::()?; cache.register_entry_type::()?; - cache.register_entry_type::()?; cache.register_entry_type::()?; cache.register_entry_type::()?; cache.register_entry_type::()?; @@ -4448,17 +4446,6 @@ pub fn put_runtime_role_worker_result( "consideration candidate identity was not assigned by exact launch" )); } - let bindings = cache - .get_all::()? - .into_iter() - .filter(|binding| binding.request_id == request_id && binding.job_id == result.job_id) - .collect::>(); - if bindings.len() != 1 { - return Err(anyhow!( - "consideration result requires one exact attempt binding" - )); - } - let binding = &bindings[0]; let worker = cache .get::(&result.job_id)? .ok_or_else(|| anyhow!("consideration result requires worker launch"))?; @@ -4469,15 +4456,13 @@ pub fn put_runtime_role_worker_result( } EpiphanyWorkerLaunchDocument::Reorient(_) => None, }; - let launch_hash = format!("{:x}", Sha256::digest(&worker.launch_document_msgpack)); - if binding.job_id != result.job_id - || binding.binding_id != EPIPHANY_IMAGINATION_ROLE_BINDING_ID - || binding.runtime_id != request.runtime_id - || binding.thread_id != request.thread_id - || binding.worker_launch_document_sha256 != launch_hash + crate::current_work::consideration_attempt_ordinal(request_id, &result.job_id)?; + if worker.schema_version != RUNTIME_WORKER_LAUNCH_REQUEST_SCHEMA_VERSION + || worker.job_id != result.job_id || worker.role != EPIPHANY_IMAGINATION_OWNER_ROLE || worker.binding_id != EPIPHANY_IMAGINATION_ROLE_BINDING_ID || worker.imagination_consideration_request_id.as_deref() != Some(request_id) + || document.thread_id() != result.job_id || projection.map(|projection| &projection.request) != Some(&request) || projection.map(|projection| projection.model.reasoning_basis()) != Some(crate::EpiphanyRepoModelBasis { @@ -8622,7 +8607,6 @@ fn validate_archivable_typed_worker_launch( } let document = launch.launch_document()?; let identity = require_identity(cache)?; - let launch_sha256 = format!("{:x}", Sha256::digest(&launch.launch_document_msgpack)); match request_kind { "proposal-modeling" => { validate_proposal_modeling_launch_carrier( @@ -8726,15 +8710,6 @@ fn validate_archivable_typed_worker_launch( { return Err(anyhow!("archived Imagination launch request is invalid")); } - let bindings = cache - .get_all::()? - .into_iter() - .filter(|binding| binding.job_id == launch.job_id) - .collect::>(); - if bindings.len() != 1 { - return Err(anyhow!("archived Imagination launch requires one binding")); - } - let binding = &bindings[0]; let projection = match &document { EpiphanyWorkerLaunchDocument::Role(document) => { document.imagination_consideration_context.as_ref() @@ -8743,11 +8718,8 @@ fn validate_archivable_typed_worker_launch( } .ok_or_else(|| anyhow!("archived Imagination launch lost its context"))?; if request.runtime_id != identity.runtime_id - || binding.request_id != request.request_id - || binding.binding_id != EPIPHANY_IMAGINATION_ROLE_BINDING_ID - || binding.runtime_id != request.runtime_id - || binding.thread_id != request.thread_id - || binding.worker_launch_document_sha256 != launch_sha256 + || launch.job_id.trim().is_empty() + || document.thread_id() != launch.job_id || projection.request != request || projection.model.reasoning_basis() != (crate::EpiphanyRepoModelBasis { @@ -8936,12 +8908,6 @@ fn archive_runtime_worker_attempt( } } let snapshot = cache.snapshot_envelopes(); - let imagination_bindings = cache - .get_all::()? - .into_iter() - .filter(|item| item.job_id == job_id) - .map(|item| item.binding_record_id) - .collect::>(); let worker_job_results = cache .get_all::()? .into_iter() @@ -8992,8 +8958,6 @@ fn archive_runtime_worker_attempt( || (entry.r#type == EpiphanyRuntimeJob::TYPE && entry.key == job_id) || (entry.r#type == EpiphanyRuntimeJobResult::TYPE && job_results.contains(&entry.key)) - || (entry.r#type == crate::ImaginationConsiderationLaunchBinding::TYPE - && imagination_bindings.contains(&entry.key)) }) .cloned() .collect::>();