Complete keyed Body Modeling lifecycle
This commit is contained in:
parent
da5991fd87
commit
478fb923a9
8 changed files with 436 additions and 139 deletions
|
|
@ -787,6 +787,43 @@ fn run_coordinator(args: &Args) -> Result<Value> {
|
|||
"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<Value> {
|
|||
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<Value> {
|
|||
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<Value> {
|
|||
.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,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -551,6 +551,8 @@ fn run_native_status(args: &Args, include_auxiliary_status: bool) -> Result<Valu
|
|||
frontier_planning_stage: frontier_planning.stage,
|
||||
proposal_modeling_request_ready: pending_proposal.is_some(),
|
||||
body_modeling_work_ready: current_work.body_modeling.is_some(),
|
||||
body_modeling_review_ready: current_work.body_modeling_action
|
||||
== Some(epiphany_core::EpiphanyBodyModelingContinuationAction::Review),
|
||||
});
|
||||
let coordinator_json = coordinator_status_json(&coordinator)?;
|
||||
let tool_invocations = native_tool_invocation_surface(&runtime_store_path)?;
|
||||
|
|
|
|||
|
|
@ -309,74 +309,45 @@ pub fn accept_coordinator_role_finding(
|
|||
if result.result_id != result_id {
|
||||
return Err(anyhow::anyhow!("Modeling finding/result identity mismatch"));
|
||||
}
|
||||
let repository_body_observation_basis = result
|
||||
.repository_body_observation_basis
|
||||
.clone()
|
||||
.ok_or_else(|| {
|
||||
anyhow::anyhow!("Modeling result has no Repository Body observation basis")
|
||||
})?;
|
||||
validate_repository_body_observation_basis(store, &repository_body_observation_basis)?;
|
||||
let proposal = result.repo_model_mutation_proposal()?;
|
||||
let is_body_modeling = result.proposal_modeling_request_id.is_none()
|
||||
&& result.claim_repair_request_id.is_none()
|
||||
&& result.repo_frontier_modeling_request_id.is_none();
|
||||
if proposal.is_none()
|
||||
&& !finding.verdict.as_deref().is_some_and(|verdict| {
|
||||
verdict.eq_ignore_ascii_case("checkpoint-ready")
|
||||
|| verdict.eq_ignore_ascii_case("regather-needed")
|
||||
})
|
||||
{
|
||||
return Err(anyhow::anyhow!(
|
||||
"Modeling result requiring RepoModel change has no semantic mutation proposal"
|
||||
));
|
||||
}
|
||||
let mut strong_reads = Vec::new();
|
||||
let mut writes = Vec::new();
|
||||
if let Some(proposal) = proposal.as_ref() {
|
||||
if is_body_modeling {
|
||||
crate::accept_body_modeling_result(store, job_id, &accepted_at)?;
|
||||
} else {
|
||||
let repository_body_observation_basis = result
|
||||
.repository_body_observation_basis
|
||||
.clone()
|
||||
.ok_or_else(|| {
|
||||
anyhow::anyhow!("Modeling result has no Repository Body observation basis")
|
||||
})?;
|
||||
validate_repository_body_observation_basis(store, &repository_body_observation_basis)?;
|
||||
let proposal = result.repo_model_mutation_proposal()?;
|
||||
if proposal.is_none() {
|
||||
return Err(anyhow::anyhow!(
|
||||
"Modeling result requiring RepoModel change has no semantic mutation proposal"
|
||||
));
|
||||
}
|
||||
let proposal = proposal.expect("checked above");
|
||||
if proposal.proposal_id != format!("repo-model-mutation-proposal-{job_id}") {
|
||||
return Err(anyhow::anyhow!(
|
||||
"Modeling RepoModel mutation proposal identity is not runtime-owned"
|
||||
));
|
||||
}
|
||||
let plan = plan_repo_model_mutation(store, &proposal)?;
|
||||
strong_reads = plan.strong_reads;
|
||||
writes = plan.writes;
|
||||
}
|
||||
if is_body_modeling {
|
||||
let disposition = if proposal.is_some() {
|
||||
"modeled"
|
||||
} else if finding
|
||||
.verdict
|
||||
.as_deref()
|
||||
.is_some_and(|verdict| verdict.eq_ignore_ascii_case("checkpoint-ready"))
|
||||
{
|
||||
"checkpoint-ready"
|
||||
} else {
|
||||
"regather-needed"
|
||||
};
|
||||
writes.push(crate::body_modeling_decision_envelope(
|
||||
store,
|
||||
&result,
|
||||
disposition,
|
||||
&accepted_at,
|
||||
)?);
|
||||
}
|
||||
if !writes.is_empty() {
|
||||
let invariant_owner = if result.proposal_modeling_request_id.is_some() {
|
||||
"Modeling.proposal_frontier"
|
||||
} else if result.claim_repair_request_id.is_some() {
|
||||
"Modeling.claim_repair"
|
||||
} else if result.repo_frontier_modeling_request_id.is_some() {
|
||||
"Modeling.frontier_verdict"
|
||||
} else {
|
||||
"Modeling.body_projection"
|
||||
"Modeling.frontier_verdict"
|
||||
};
|
||||
match commit_mind_mutation(
|
||||
store,
|
||||
&result.decision_context_id,
|
||||
invariant_owner,
|
||||
strong_reads,
|
||||
writes,
|
||||
plan.strong_reads,
|
||||
plan.writes,
|
||||
&accepted_at,
|
||||
)? {
|
||||
EpiphanyMindCommitOutcome::Committed(_) => {}
|
||||
|
|
|
|||
|
|
@ -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<EpiphanyBodyModelingWorkProjection>,
|
||||
pub body_modeling_action: Option<EpiphanyBodyModelingContinuationAction>,
|
||||
pub research_continuation_action: Option<RepoFrontierResearchContinuationAction>,
|
||||
pub frontier_planning_stage: RepoFrontierPlanningLifecycleStage,
|
||||
pub proposal_modeling_request: Option<RepoFrontierProposalModelingRequest>,
|
||||
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<Path>) -> Result<EpiphanyCurrentWorkProjection> {
|
||||
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<Path>) -> Result<EpiphanyCurr
|
|||
cache.get::<EpiphanyBodyModelingDecisionReceipt>(&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<Path>) -> Result<EpiphanyCurr
|
|||
Ok(EpiphanyCurrentWorkProjection {
|
||||
mind_projection_digest: mind.projection_digest,
|
||||
body_modeling,
|
||||
body_modeling_action,
|
||||
research_continuation_action: crate::runtime_repo_frontier_research_lifecycle(store_path)?
|
||||
.continuation_action(),
|
||||
frontier_planning_stage: crate::runtime_repo_frontier_planning_lifecycle(store_path)?.stage,
|
||||
|
|
@ -299,22 +315,163 @@ pub fn project_current_work(store_path: impl AsRef<Path>) -> Result<EpiphanyCurr
|
|||
})
|
||||
}
|
||||
|
||||
fn body_modeling_work_is_covered(cache: &CultCache, work_id: &str) -> Result<bool> {
|
||||
for binding in cache.get_all::<EpiphanyBodyModelingLaunchBinding>()? {
|
||||
if binding.work_id != work_id {
|
||||
continue;
|
||||
fn body_modeling_continuation_action(
|
||||
cache: &CultCache,
|
||||
work_id: &str,
|
||||
) -> Result<EpiphanyBodyModelingContinuationAction> {
|
||||
let mut bindings = cache
|
||||
.get_all::<EpiphanyBodyModelingLaunchBinding>()?
|
||||
.into_iter()
|
||||
.filter(|binding| binding.work_id == work_id)
|
||||
.collect::<Vec<_>>();
|
||||
bindings.sort_by_key(|binding| binding.attempt_ordinal);
|
||||
let Some(binding) = bindings.last() else {
|
||||
return Ok(EpiphanyBodyModelingContinuationAction::Launch);
|
||||
};
|
||||
let job = cache
|
||||
.get::<crate::EpiphanyRuntimeJob>(&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::<crate::EpiphanyRuntimeJob>(&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::<crate::EpiphanyRuntimeRoleWorkerResult>(&binding.job_id)?
|
||||
.is_some()
|
||||
{
|
||||
EpiphanyBodyModelingContinuationAction::Review
|
||||
} else {
|
||||
EpiphanyBodyModelingContinuationAction::Wait
|
||||
}
|
||||
}
|
||||
_ => EpiphanyBodyModelingContinuationAction::Wait,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn body_modeling_continuation_action_for_job(
|
||||
store_path: impl AsRef<Path>,
|
||||
job_id: &str,
|
||||
) -> Result<Option<EpiphanyBodyModelingContinuationAction>> {
|
||||
let mut cache = crate::runtime_spine_cache(store_path)?;
|
||||
cache.pull_all_backing_stores()?;
|
||||
let bindings = cache
|
||||
.get_all::<EpiphanyBodyModelingLaunchBinding>()?
|
||||
.into_iter()
|
||||
.filter(|binding| binding.job_id == job_id)
|
||||
.collect::<Vec<_>>();
|
||||
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::<EpiphanyBodyModelingDecisionReceipt>(&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<Path>) -> Result<Option<String>> {
|
||||
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::<EpiphanyBodyModelingLaunchBinding>()?
|
||||
.into_iter()
|
||||
.filter(|binding| binding.work_id == work.work_id)
|
||||
.collect::<Vec<_>>();
|
||||
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<Path>,
|
||||
job_id: &str,
|
||||
accepted_at: &str,
|
||||
) -> Result<crate::EpiphanyMindCommitReceipt> {
|
||||
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::<crate::EpiphanyRuntimeJob>(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::<crate::EpiphanyRuntimeRoleWorkerResult>(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::<crate::EpiphanyRuntimeWorkerLaunchRequest>("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::<crate::EpiphanyRuntimeJob>(&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(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<String> {
|
|||
|
||||
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::<chrono::Utc>::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<Option<ResidentSelfPressure>> {
|
||||
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");
|
||||
|
|
|
|||
|
|
@ -863,6 +863,8 @@ pub struct EpiphanyCoordinatorRunReceipt {
|
|||
pub resident_release_manifest_digest: Option<String>,
|
||||
#[cultcache(key = 22, default)]
|
||||
pub resident_executable_digest: Option<String>,
|
||||
#[cultcache(key = 23, default)]
|
||||
pub final_runtime_job_id: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, DatabaseEntry)]
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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)]
|
||||
|
|
|
|||
Reference in a new issue