From 478fb923a9a4dd561b18258f3f92ef03d8b189db Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Mon, 17 Aug 2026 21:00:39 +0200 Subject: [PATCH] Complete keyed Body Modeling lifecycle --- .../src/bin/epiphany-mvp-coordinator.rs | 41 +++ epiphany-core/src/bin/epiphany-mvp-status.rs | 2 + epiphany-core/src/coordinator_acceptance.rs | 69 +--- epiphany-core/src/current_work.rs | 341 +++++++++++++----- epiphany-core/src/resident_self.rs | 87 ++++- epiphany-core/src/runtime_spine.rs | 2 + epiphany-core/src/surfaces/coordinator.rs | 31 ++ .../src/surfaces/coordinator_contract.rs | 2 + 8 files changed, 436 insertions(+), 139 deletions(-) diff --git a/epiphany-core/src/bin/epiphany-mvp-coordinator.rs b/epiphany-core/src/bin/epiphany-mvp-coordinator.rs index df4dccda..a0801cf1 100644 --- a/epiphany-core/src/bin/epiphany-mvp-coordinator.rs +++ b/epiphany-core/src/bin/epiphany-mvp-coordinator.rs @@ -787,6 +787,43 @@ fn run_coordinator(args: &Args) -> Result { "reviewResearchResult" | "reviewModelingResult" | "reviewVerificationResult" => { let role_id = role_id_for_coordinator_action(&action) .ok_or_else(|| anyhow!("unsupported review action {action}"))?; + if role_id == "modeling" + && let Some(job_id) = + epiphany_core::current_body_modeling_review_job_id(&runtime_store)? + { + let result = + epiphany_core::runtime_role_worker_result(&runtime_store, &job_id)? + .ok_or_else(|| { + anyhow!("Body Modeling review lost its typed result") + })?; + push_event( + &mut step, + json!({"type": "bodyModelingResult", "roleId": role_id, "result": result}), + ); + if !args.auto_review { + final_action = json!({ + "action": "reviewModelingResult", + "reason": "The exact Body Modeling result awaits keyed Mind admission.", + "runtimeJobId": job_id, + }); + append_operator_step_jsonl(&steps_path, &step)?; + steps.push(step); + break; + } + let accepted = epiphany_core::accept_body_modeling_result( + &runtime_store, + &job_id, + &now(), + )?; + push_event( + &mut step, + json!({"type": "bodyModelingAccept", "roleId": role_id, "commit": accepted}), + ); + final_status = collect_coordinator_status(&runtime_store, &thread_id)?; + append_operator_step_jsonl(&steps_path, &step)?; + steps.push(step); + continue; + } let result = read_role_result(&runtime_store, &thread_id, role_id)?; push_event( &mut step, @@ -1028,6 +1065,7 @@ fn run_coordinator(args: &Args) -> Result { final_action = json!({ "action": wait_action_for_role(role_id), "reason": result["note"], + "runtimeJobId": worker_job_id, }); append_operator_step_jsonl(&steps_path, &step)?; steps.push(step); @@ -1037,6 +1075,7 @@ fn run_coordinator(args: &Args) -> Result { final_action = json!({ "action": review_action_for_role(role_id), "reason": result["note"], + "runtimeJobId": worker_job_id, }); append_operator_step_jsonl(&steps_path, &step)?; steps.push(step); @@ -1174,6 +1213,7 @@ fn run_coordinator(args: &Args) -> Result { .get("release-manifest-digest") .cloned(), resident_executable_digest: args.resident_binding.get("executable-digest").cloned(), + final_runtime_job_id: final_action["runtimeJobId"].as_str().map(str::to_string), }; finalize_coordinator_run(&runtime_store, &coordinator_run_receipt)?; let runtime_status = runtime_spine_status(&runtime_store)?; @@ -1300,6 +1340,7 @@ fn failed_coordinator_run_receipt( .get("release-manifest-digest") .cloned(), resident_executable_digest: args.resident_binding.get("executable-digest").cloned(), + final_runtime_job_id: None, } } diff --git a/epiphany-core/src/bin/epiphany-mvp-status.rs b/epiphany-core/src/bin/epiphany-mvp-status.rs index 7f3b4a65..c94c6554 100644 --- a/epiphany-core/src/bin/epiphany-mvp-status.rs +++ b/epiphany-core/src/bin/epiphany-mvp-status.rs @@ -551,6 +551,8 @@ fn run_native_status(args: &Args, include_auxiliary_status: bool) -> Result {} diff --git a/epiphany-core/src/current_work.rs b/epiphany-core/src/current_work.rs index 15513bc2..574d5084 100644 --- a/epiphany-core/src/current_work.rs +++ b/epiphany-core/src/current_work.rs @@ -19,12 +19,21 @@ pub const BODY_MODELING_LAUNCH_BINDING_SCHEMA_VERSION: &str = pub struct EpiphanyCurrentWorkProjection { pub mind_projection_digest: String, pub body_modeling: Option, + pub body_modeling_action: Option, pub research_continuation_action: Option, pub frontier_planning_stage: RepoFrontierPlanningLifecycleStage, pub proposal_modeling_request: Option, pub hands_frontier_ready: bool, } +#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub enum EpiphanyBodyModelingContinuationAction { + Launch, + Wait, + Review, +} + #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct EpiphanyBodyModelingWorkProjection { pub work_id: String, @@ -258,7 +267,7 @@ pub fn unresolved_body_modeling_work( pub fn project_current_work(store_path: impl AsRef) -> Result { let store_path = store_path.as_ref(); let mind = crate::assemble_mind_view(store_path)?; - let body_modeling = match ( + let (body_modeling, body_modeling_action) = match ( mind.repository_body_observation.clone(), mind.repo_model.as_ref(), ) { @@ -275,11 +284,17 @@ pub fn project_current_work(store_path: impl AsRef) -> Result(&work.work_id)?, )?; match unresolved { - Some(work) if !body_modeling_work_is_covered(&cache, &work.work_id)? => Some(work), - _ => None, + Some(work) => { + let action = body_modeling_continuation_action(&cache, &work.work_id)?; + ( + (action == EpiphanyBodyModelingContinuationAction::Launch).then_some(work), + Some(action), + ) + } + None => (None, None), } } - (None, None) | (Some(_), None) => None, + (None, None) | (Some(_), None) => (None, None), (None, Some(_)) => { return Err(anyhow!( "current work has a RepoModel but no admitted repository Body observation" @@ -289,6 +304,7 @@ pub fn project_current_work(store_path: impl AsRef) -> Result) -> Result Result { - for binding in cache.get_all::()? { - if binding.work_id != work_id { - continue; +fn body_modeling_continuation_action( + cache: &CultCache, + work_id: &str, +) -> 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 { + return Ok(EpiphanyBodyModelingContinuationAction::Launch); + }; + let job = cache + .get::(&binding.job_id)? + .ok_or_else(|| anyhow!("Body Modeling launch binding lost its runtime job"))?; + Ok(match job.status { + crate::EpiphanyRuntimeJobStatus::Failed | crate::EpiphanyRuntimeJobStatus::Cancelled => { + EpiphanyBodyModelingContinuationAction::Launch } - let job = cache - .get::(&binding.job_id)? - .ok_or_else(|| anyhow!("Body Modeling launch binding lost its runtime job"))?; - if !matches!( - job.status, - crate::EpiphanyRuntimeJobStatus::Failed | crate::EpiphanyRuntimeJobStatus::Cancelled - ) { - return Ok(true); + crate::EpiphanyRuntimeJobStatus::Completed => { + if cache + .get::(&binding.job_id)? + .is_some() + { + EpiphanyBodyModelingContinuationAction::Review + } else { + EpiphanyBodyModelingContinuationAction::Wait + } } + _ => EpiphanyBodyModelingContinuationAction::Wait, + }) +} + +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_continuation_action( + &cache, + &binding.work_id, + )?)) +} + +pub fn current_body_modeling_review_job_id(store_path: impl AsRef) -> Result> { + let store_path = store_path.as_ref(); + if crate::project_current_work(store_path)?.body_modeling_action + != Some(EpiphanyBodyModelingContinuationAction::Review) + { + return Ok(None); + } + let mut cache = crate::runtime_spine_cache(store_path)?; + cache.pull_all_backing_stores()?; + let work = current_body_modeling_work(store_path)?; + let mut bindings = cache + .get_all::()? + .into_iter() + .filter(|binding| binding.work_id == work.work_id) + .collect::>(); + bindings.sort_by_key(|binding| binding.attempt_ordinal); + Ok(bindings.last().map(|binding| binding.job_id.clone())) +} + +pub fn accept_body_modeling_result( + store_path: impl AsRef, + job_id: &str, + accepted_at: &str, +) -> Result { + let store_path = store_path.as_ref(); + let mut cache = crate::runtime_spine_cache(store_path)?; + cache.pull_all_backing_stores()?; + let job = cache + .get::(job_id)? + .ok_or_else(|| anyhow!("Body Modeling acceptance lost its runtime job"))?; + if job.status != crate::EpiphanyRuntimeJobStatus::Completed { + return Err(anyhow!("Body Modeling runtime job is not completed")); + } + let result = cache + .get::(job_id)? + .ok_or_else(|| anyhow!("Body Modeling acceptance lost its typed result"))?; + if result.role_id != "modeling" + || result.proposal_modeling_request_id.is_some() + || result.claim_repair_request_id.is_some() + || result.repo_frontier_modeling_request_id.is_some() + { + return Err(anyhow!("result is not baseline Body Modeling authority")); + } + let proposal = result.repo_model_mutation_proposal()?; + if proposal.is_none() + && !matches!( + result.verdict.as_str(), + "checkpoint-ready" | "regather-needed" + ) + { + return Err(anyhow!( + "Body Modeling result requiring RepoModel change has no mutation proposal" + )); + } + let mut strong_reads = Vec::new(); + let mut writes = Vec::new(); + if let Some(proposal) = proposal.as_ref() { + if proposal.proposal_id != format!("repo-model-mutation-proposal-{job_id}") { + return Err(anyhow!( + "Body Modeling mutation proposal identity is not runtime-owned" + )); + } + let plan = crate::plan_repo_model_mutation(store_path, proposal)?; + strong_reads = plan.strong_reads; + writes = plan.writes; + } + let disposition = if proposal.is_some() { + "modeled" + } else { + result.verdict.as_str() + }; + writes.push(body_modeling_decision_envelope( + store_path, + &result, + disposition, + accepted_at, + )?); + match crate::commit_mind_mutation( + store_path, + &result.decision_context_id, + "Modeling.body_projection", + strong_reads, + writes, + accepted_at, + )? { + crate::EpiphanyMindCommitOutcome::Committed(receipt) => Ok(receipt), + crate::EpiphanyMindCommitOutcome::Conflict { + document_identities, + } => Err(anyhow!( + "Body Modeling admission lost exact keyed reads: {document_identities:?}" + )), } - Ok(false) } pub fn launch_current_body_modeling_work( @@ -666,11 +823,25 @@ mod tests { assert_eq!(crate::repository_body_read_counters(), (0, 0)); let current_work = project_current_work(&store)?; assert_eq!(current_work.body_modeling, Some(projected_work.clone())); + assert_eq!( + current_work.body_modeling_action, + Some(EpiphanyBodyModelingContinuationAction::Launch) + ); assert_eq!( current_work.mind_projection_digest, crate::assemble_mind_view(&store)?.projection_digest ); assert_eq!(crate::repository_body_read_counters(), (0, 0)); + let resident_pressure = crate::resident_self_body_modeling_pressure(&store, 1)? + .expect("unresolved Body work must create Resident Self pressure"); + assert_eq!( + resident_pressure.provenance_ref, + format!( + "{}{}", + crate::RESIDENT_SELF_BODY_MODELING_PROVENANCE_PREFIX, + projected_work.work_id + ) + ); let scheduled = launch_current_body_modeling_work( &store, EpiphanyBodyModelingLaunchOptions { @@ -680,7 +851,13 @@ mod tests { )?; assert_eq!(scheduled.work_id, projected_work.work_id); assert_eq!(scheduled.attempt_ordinal, 0); - assert!(project_current_work(&store)?.body_modeling.is_none()); + let scheduled_work = project_current_work(&store)?; + assert!(scheduled_work.body_modeling.is_none()); + assert_eq!( + scheduled_work.body_modeling_action, + Some(EpiphanyBodyModelingContinuationAction::Wait) + ); + assert!(crate::resident_self_body_modeling_pressure(&store, 2)?.is_none()); let mut scheduled_cache = crate::runtime_spine_cache(&store)?; scheduled_cache.pull_all_backing_stores()?; assert!( @@ -711,63 +888,11 @@ mod tests { .is_err() ); assert_eq!(crate::repository_body_read_counters(), (0, 0)); - let document = - crate::EpiphanyWorkerLaunchDocument::Role(crate::EpiphanyRoleWorkerLaunchDocument { - thread_id: "creation-thread".into(), - role_id: "modeling".into(), - state_revision: 99, - objective: Some("obsolete aggregate objective".into()), - dynamic_prompt_context: None, - repository_body_observation_basis: Some(body.clone()), - proposal_modeling_context: None, - claim_repair_context: None, - frontier_planning_context: None, - frontier_research_context: None, - frontier_plan_mind_context: None, - imagination_consideration_context: None, - 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 = crate::EpiphanyRuntimeWorkerLaunchRequest { - schema_version: crate::RUNTIME_WORKER_LAUNCH_REQUEST_SCHEMA_VERSION.into(), - job_id: "body-job".into(), - binding_id: crate::EPIPHANY_MODELING_ROLE_BINDING_ID.into(), - role: crate::EPIPHANY_MODELING_OWNER_ROLE.into(), - authority_scope: "epiphany.role.modeling".into(), - instruction: "Model the Body".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: Default::default(), - organ_launch_contract: crate::default_launch_organ_contract( - "epiphany.role.modeling", - "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: None, - repo_frontier_modeling_request_id: None, - repo_frontier_research_request_id: None, - repo_frontier_verdict_modeling_authority_msgpack: None, - }; let mut cache = crate::runtime_spine_cache(&store)?; - cache.put(&launch.job_id, &launch)?; + cache.pull_all_backing_stores()?; + let launch = cache + .get::("body-scheduled-job")? + .unwrap(); let reasoning_basis = crate::worker_reasoning_basis(&store, &launch)?; crate::put_reasoning_basis(&store, &reasoning_basis)?; let mut native = epiphany_model_adapter::EpiphanyModelRequest::new( @@ -821,23 +946,61 @@ mod tests { admitted_model_direction_consideration_result_msgpack: None, decision_context_id: context.context_id, }; - let envelope = body_modeling_decision_envelope( - &store, - &result, - "checkpoint-ready", - "2026-08-17T00:00:02Z", - )?; - crate::mind_documents::validate_mind_write_envelope(&envelope)?; - let receipt: EpiphanyBodyModelingDecisionReceipt = - rmp_serde::from_slice(&envelope.payload)?; - assert_eq!(receipt.body_basis, body); + cache.put(&result.job_id, &result)?; + let mut job = cache + .get::(&result.job_id)? + .unwrap(); + job.status = crate::EpiphanyRuntimeJobStatus::Completed; + job.updated_at = "2026-08-17T00:00:04Z".into(); + cache.put(&job.job_id, &job)?; assert_eq!( - receipt.repo_model_projection_digest, - crate::assemble_repo_model_view(&store)?.projection_digest + project_current_work(&store)?.body_modeling_action, + Some(EpiphanyBodyModelingContinuationAction::Review) + ); + let continuation = crate::EpiphanyCoordinatorRunReceipt { + schema_version: crate::COORDINATOR_RUN_RECEIPT_SCHEMA_VERSION.into(), + receipt_id: "body-continuation".into(), + session_id: crate::EPIPHANY_RUNTIME_ROOT_SESSION_ID.into(), + thread_id: "transport-thread".into(), + mode: "execute".into(), + status: "planned".into(), + final_action: "waitForModelingResult".into(), + final_reason: None, + step_count: 1, + created_at: "2026-08-17T00:00:04Z".into(), + model_provider: None, + runtime_store: store.display().to_string(), + artifact_refs: Vec::new(), + sealed_artifact_refs: Vec::new(), + metadata: Default::default(), + resident_grant_id: None, + resident_launch_digest: None, + resident_policy_digest: None, + resident_argv_digest: None, + resident_objective_digest: None, + resident_release_commit: None, + resident_release_manifest_digest: None, + resident_executable_digest: None, + final_runtime_job_id: Some(result.job_id.clone()), + }; + assert_eq!( + crate::resident_self::resident_self_safe_continuation_action(&store, &continuation)?, + Some("reviewModelingResult".into()) + ); + let receipt = accept_body_modeling_result(&store, &result.job_id, "2026-08-17T00:00:05Z")?; + assert_eq!( + receipt.authority, + crate::EpiphanyMindCommitAuthority::ModelDecisionContext { + decision_context_id: result.decision_context_id.clone(), + } + ); + let completed_work = project_current_work(&store)?; + assert!(completed_work.body_modeling.is_none()); + assert!(completed_work.body_modeling_action.is_none()); + assert!( + crate::resident_self::resident_self_safe_continuation_action(&store, &continuation)? + .is_none() ); - let mut cache = crate::runtime_spine_cache(&store)?; - cache.put(&receipt.work_id, &receipt)?; - assert!(project_current_work(&store)?.body_modeling.is_none()); assert_eq!(crate::repository_body_read_counters(), (0, 0)); Ok(()) } diff --git a/epiphany-core/src/resident_self.rs b/epiphany-core/src/resident_self.rs index 7f4e96bf..1b7a2d2b 100644 --- a/epiphany-core/src/resident_self.rs +++ b/epiphany-core/src/resident_self.rs @@ -16,6 +16,8 @@ pub const RESIDENT_SELF_COORDINATOR_CONTINUATION_PRESSURE_KIND: &str = "coordinator-internal-continuation"; pub const RESIDENT_SELF_ATLAS_MODELING_PRESSURE_KIND: &str = "atlas-impact-modeling"; pub const RESIDENT_SELF_ATLAS_SOUL_PRESSURE_KIND: &str = "atlas-impact-soul"; +pub const RESIDENT_SELF_BODY_MODELING_PRESSURE_KIND: &str = "body-modeling"; +pub const RESIDENT_SELF_BODY_MODELING_PROVENANCE_PREFIX: &str = "cultcache://body-modeling-work/"; pub const RESIDENT_SELF_ATLAS_IMPACT_PROVENANCE_PREFIX: &str = "cultcache://atlas-impact-proposal/"; pub const RESIDENT_SELF_ATLAS_NO_HANDS_AUTHORITY_CLAUSE: &str = "This wake grants no Hands authority."; @@ -65,6 +67,7 @@ impl ResidentSelfPressure { | "imagination-consideration" | "imagination-proposal" | "repo-frontier-proposal-modeling" + | RESIDENT_SELF_BODY_MODELING_PRESSURE_KIND | RESIDENT_SELF_ATLAS_MODELING_PRESSURE_KIND | RESIDENT_SELF_ATLAS_SOUL_PRESSURE_KIND | RESIDENT_SELF_COORDINATOR_CONTINUATION_PRESSURE_KIND @@ -103,6 +106,18 @@ impl ResidentSelfPressure { )); } } + if self.kind == RESIDENT_SELF_BODY_MODELING_PRESSURE_KIND { + let work_id = self + .provenance_ref + .strip_prefix(RESIDENT_SELF_BODY_MODELING_PROVENANCE_PREFIX) + .filter(|value| !value.trim().is_empty()) + .ok_or_else(|| anyhow!("Body Modeling pressure lost its exact work identity"))?; + if self.pressure_id != format!("body-modeling-{work_id}") { + return Err(anyhow!( + "Body Modeling pressure identity does not match its work" + )); + } + } Ok(()) } @@ -687,7 +702,9 @@ pub fn resident_cognitive_runtime_id(runtime_store: &Path) -> Result { fn resident_self_atlas_required_action(pressure_kind: &str) -> Option<&'static str> { match pressure_kind { - RESIDENT_SELF_ATLAS_MODELING_PRESSURE_KIND => Some("launchModeling"), + RESIDENT_SELF_ATLAS_MODELING_PRESSURE_KIND | RESIDENT_SELF_BODY_MODELING_PRESSURE_KIND => { + Some("launchModeling") + } RESIDENT_SELF_ATLAS_SOUL_PRESSURE_KIND => Some("launchVerification"), _ => None, } @@ -1163,6 +1180,12 @@ pub fn ingest_resident_self_domain_pressure( let requested_at = chrono::DateTime::::from_timestamp_millis(now_millis as i64) .ok_or_else(|| anyhow!("resident consideration timestamp is out of range"))? .to_rfc3339(); + if let Some(pressure) = resident_self_body_modeling_pressure(runtime_store, now_millis)? { + inserted += usize::from(enqueue_resident_self_pressure_idempotent( + resident_store, + &pressure, + )?); + } if let Some(request) = crate::commit_admitted_model_direction_consideration_request(runtime_store, &requested_at)? { @@ -1239,6 +1262,28 @@ pub fn ingest_resident_self_domain_pressure( Ok(inserted) } +pub fn resident_self_body_modeling_pressure( + runtime_store: &Path, + now_millis: u64, +) -> Result> { + Ok(crate::project_current_work(runtime_store)? + .body_modeling + .map(|work| ResidentSelfPressure { + schema_version: RESIDENT_SELF_PRESSURE_SCHEMA_VERSION.into(), + pressure_id: format!("body-modeling-{}", work.work_id), + kind: RESIDENT_SELF_BODY_MODELING_PRESSURE_KIND.into(), + provenance_ref: format!( + "{RESIDENT_SELF_BODY_MODELING_PROVENANCE_PREFIX}{}", + work.work_id + ), + objective: "Launch the exact unresolved repository Body Modeling obligation; no Hands, Persona, deployment, or external consequence.".into(), + created_at_millis: now_millis, + status: "pending".into(), + consumed_by_grant_id: None, + private_state_exposed: false, + })) +} + fn role_projection_is_terminal_for_continuation( runtime_store: &Path, thread_id: &str, @@ -1302,6 +1347,26 @@ pub(crate) fn resident_self_safe_continuation_action( .map(|action| action.as_str().to_string()), ); } + if matches!( + receipt.final_action.as_str(), + "launchModeling" | "waitForModelingResult" | "reviewModelingResult" + ) { + if let Some(job_id) = receipt.final_runtime_job_id.as_deref() { + if let Some(action) = + crate::body_modeling_continuation_action_for_job(runtime_store, job_id)? + { + return Ok(match action { + crate::EpiphanyBodyModelingContinuationAction::Launch => { + Some("launchModeling".to_string()) + } + crate::EpiphanyBodyModelingContinuationAction::Wait => None, + crate::EpiphanyBodyModelingContinuationAction::Review => { + Some("reviewModelingResult".to_string()) + } + }); + } + } + } let direct = matches!( receipt.final_action.as_str(), "launchModeling" @@ -3418,6 +3483,26 @@ mod atlas_pressure_tests { Ok(()) } + #[test] + fn body_modeling_pressure_is_keyed_by_exact_work() -> Result<()> { + let pressure = ResidentSelfPressure { + schema_version: RESIDENT_SELF_PRESSURE_SCHEMA_VERSION.into(), + pressure_id: "body-modeling-body-work-1".into(), + kind: RESIDENT_SELF_BODY_MODELING_PRESSURE_KIND.into(), + provenance_ref: format!("{RESIDENT_SELF_BODY_MODELING_PROVENANCE_PREFIX}body-work-1"), + objective: "Launch exact Body work".into(), + created_at_millis: 1, + status: "pending".into(), + consumed_by_grant_id: None, + private_state_exposed: false, + }; + pressure.validate()?; + let mut hostile = pressure; + hostile.pressure_id = "body-modeling-body-work-2".into(); + assert!(hostile.validate().is_err()); + Ok(()) + } + #[test] fn atlas_pressure_cannot_wake_an_active_or_prepared_coordinator() -> Result<()> { let active_store = test_store("active"); diff --git a/epiphany-core/src/runtime_spine.rs b/epiphany-core/src/runtime_spine.rs index 0879f838..d1cc332a 100644 --- a/epiphany-core/src/runtime_spine.rs +++ b/epiphany-core/src/runtime_spine.rs @@ -863,6 +863,8 @@ pub struct EpiphanyCoordinatorRunReceipt { pub resident_release_manifest_digest: Option, #[cultcache(key = 22, default)] pub resident_executable_digest: Option, + #[cultcache(key = 23, default)] + pub final_runtime_job_id: Option, } #[derive(Clone, Debug, PartialEq, Eq, DatabaseEntry)] diff --git a/epiphany-core/src/surfaces/coordinator.rs b/epiphany-core/src/surfaces/coordinator.rs index 0d894061..1118ddbb 100644 --- a/epiphany-core/src/surfaces/coordinator.rs +++ b/epiphany-core/src/surfaces/coordinator.rs @@ -96,6 +96,7 @@ pub fn derive_coordinator_status( frontier_planning_stage: input.frontier_planning_stage, proposal_modeling_request_ready: input.proposal_modeling_request_ready, body_modeling_work_ready: input.body_modeling_work_ready, + body_modeling_review_ready: input.body_modeling_review_ready, }); EpiphanyCoordinatorStatus { decision, @@ -706,6 +707,17 @@ pub fn recommend_coordinator_action( ); } + if input.body_modeling_review_ready { + return build( + EpiphanyCoordinatorAction::ReviewModelingResult, + Some(EpiphanyCoordinatorRoleId::Modeling), + Some(EpiphanyCoordinatorSceneAction::RoleResult), + true, + false, + "The exact Body Modeling attempt has a terminal typed result awaiting keyed Mind admission.", + ); + } + if input.body_modeling_work_ready { return build( EpiphanyCoordinatorAction::LaunchModeling, @@ -1378,6 +1390,7 @@ mod tests { frontier_planning_stage: RepoFrontierPlanningLifecycleStage::Unavailable, proposal_modeling_request_ready: false, body_modeling_work_ready: false, + body_modeling_review_ready: false, } } @@ -1481,6 +1494,24 @@ mod tests { assert!(decision.can_auto_run); } + #[test] + fn terminal_body_work_routes_keyed_mind_review() { + let decision = recommend_coordinator_action(EpiphanyCoordinatorInput { + body_modeling_review_ready: true, + ..input() + }); + assert_eq!( + decision.action, + EpiphanyCoordinatorAction::ReviewModelingResult + ); + assert_eq!( + decision.target_role, + Some(EpiphanyCoordinatorRoleId::Modeling) + ); + assert!(decision.requires_review); + assert!(!decision.can_auto_run); + } + fn finding( runtime_result_id: &str, runtime_job_id: &str, diff --git a/epiphany-core/src/surfaces/coordinator_contract.rs b/epiphany-core/src/surfaces/coordinator_contract.rs index ea5559cb..38ae4628 100644 --- a/epiphany-core/src/surfaces/coordinator_contract.rs +++ b/epiphany-core/src/surfaces/coordinator_contract.rs @@ -167,6 +167,7 @@ pub struct EpiphanyCoordinatorInput { /// True when an explicitly selected user proposal has no Modeling launch. pub proposal_modeling_request_ready: bool, pub body_modeling_work_ready: bool, + pub body_modeling_review_ready: bool, } #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] @@ -219,6 +220,7 @@ pub struct EpiphanyCoordinatorStatusInput { pub frontier_planning_stage: RepoFrontierPlanningLifecycleStage, pub proposal_modeling_request_ready: bool, pub body_modeling_work_ready: bool, + pub body_modeling_review_ready: bool, } #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]