Repair frontier planning failure recovery

This commit is contained in:
Meta Vens 2026-08-08 08:56:03 +01:00
commit a6c2387213
10 changed files with 801 additions and 64 deletions

View file

@ -567,10 +567,9 @@ fn run_coordinator(args: &Args) -> Result<Value> {
if action == "awaitFrontierProposal"
|| matches!(
action.as_str(),
"waitForImaginationResult"
| "waitForMindPlanResult"
| "reviewFrontierPlanningFailure"
"waitForImaginationResult" | "waitForMindPlanResult"
)
|| (action == "reviewFrontierPlanningFailure" && !args.supersede_failed_results)
|| (is_stop_action(&action) && !args.auto_review && !is_result_review_action(&action))
{
append_operator_step_jsonl(&steps_path, &step)?;
@ -580,6 +579,45 @@ fn run_coordinator(args: &Args) -> Result<Value> {
let revision = state_revision(&status);
match action.as_str() {
"reviewFrontierPlanningFailure" => {
let lifecycle =
epiphany_core::runtime_repo_frontier_planning_lifecycle(&runtime_store)?;
let (result_id, job_id, role_id, binding_id) = match lifecycle.stage {
epiphany_core::RepoFrontierPlanningLifecycleStage::ImaginationFailed => (
lifecycle.imagination_result_id.as_deref(),
lifecycle.imagination_job_id.as_deref(),
"imagination",
epiphany_core::EPIPHANY_IMAGINATION_ROLE_BINDING_ID,
),
epiphany_core::RepoFrontierPlanningLifecycleStage::MindFailed => (
lifecycle.mind_result_id.as_deref(),
lifecycle.mind_job_id.as_deref(),
"mindAdmissionReview",
epiphany_core::EPIPHANY_MIND_ROLE_BINDING_ID,
),
_ => return Err(anyhow!("frontier planning failure review stage changed")),
};
let result_id = result_id.ok_or_else(|| {
anyhow!("frontier planning failure review requires a typed result")
})?;
let job_id = job_id.ok_or_else(|| {
anyhow!("frontier planning failure review requires a launch job")
})?;
let reviewed = supersede_frontier_planning_failure(
&runtime_store,
&thread_id,
revision,
result_id,
job_id,
role_id,
binding_id,
)?;
push_event(
&mut step,
json!({"type": "frontierPlanningFailureReview", "review": status_cli::sanitize_for_operator(reviewed)}),
);
final_status = collect_coordinator_status(&runtime_store, &thread_id)?;
}
"startFrontierPlanning" => {
let request = epiphany_core::select_and_commit_repo_frontier_planning_request(
&runtime_store,
@ -1731,6 +1769,64 @@ fn supersede_role_result(
}))
}
fn supersede_frontier_planning_failure(
runtime_store: &Path,
thread_id: &str,
expected_revision: Option<i64>,
result_id: &str,
job_id: &str,
role_id: &str,
binding_id: &str,
) -> Result<Value> {
let service = epiphany_core::EpiphanyCoordinatorService::new(runtime_store);
let state = service
.state()?
.ok_or_else(|| anyhow!("planning failure review requires coordinator state"))?;
if let Some(existing) = state
.acceptance_receipts
.iter()
.find(|receipt| receipt.result_id == result_id)
{
if existing.job_id == job_id
&& existing.binding_id == binding_id
&& existing.surface == "roleFailureReview"
&& existing.role_id == role_id
&& existing.status == "superseded"
{
return Ok(json!({"revision": state.revision, "receipt": existing, "changed": false}));
}
return Err(anyhow!(
"planning failure already has conflicting review authority"
));
}
let receipt = epiphany_state_model::EpiphanyAcceptanceReceipt {
id: format!("frontier-planning-failure-review-{}", Uuid::new_v4()),
result_id: result_id.to_string(),
job_id: job_id.to_string(),
binding_id: binding_id.to_string(),
surface: "roleFailureReview".to_string(),
role_id: role_id.to_string(),
status: "superseded".to_string(),
accepted_at: now(),
accepted_observation_id: None,
accepted_evidence_id: None,
summary: Some(
"Reviewed non-executable frontier Imagination failure; Self may schedule one next immutable attempt."
.to_string(),
),
};
let applied = service.apply_state_update(
thread_id,
epiphany_core::EpiphanyStateUpdate {
expected_revision: expected_revision.and_then(|value| u64::try_from(value).ok()),
acceptance_receipts: vec![receipt.clone()],
..Default::default()
},
None,
)?;
Ok(json!({"revision": applied.revision, "receipt": receipt, "changed": true}))
}
fn default_binding_id_for_role(role_id: &str) -> String {
match role_id {
"imagination" => epiphany_core::EPIPHANY_IMAGINATION_ROLE_BINDING_ID.to_string(),

View file

@ -151,7 +151,7 @@ fn commit_coordinator_job_launch_in_cache(
};
let frontier_planning_launch =
if let Some(request_id) = request.frontier_planning_request_id.as_deref() {
let (planning, identity) =
let (planning, identity, attempt_ordinal, superseded_failure_result_id) =
validate_frontier_planning_launch(cache, current_state, request, request_id)?;
let projection = RepoFrontierPlanningContextProjection::from_request(&planning);
match &mut effective_launch_document {
@ -172,7 +172,13 @@ fn commit_coordinator_job_launch_in_cache(
}
}
let bytes = rmp_serde::to_vec_named(&effective_launch_document)?;
Some((planning, identity, format!("{:x}", Sha256::digest(bytes))))
Some((
planning,
identity,
format!("{:x}", Sha256::digest(bytes)),
attempt_ordinal,
superseded_failure_result_id,
))
} else {
None
};
@ -253,8 +259,14 @@ fn commit_coordinator_job_launch_in_cache(
};
let frontier_plan_mind_launch =
if let Some(request_id) = request.frontier_plan_mind_request_id.as_deref() {
let (mind_request, planning, candidate, identity) =
validate_frontier_plan_mind_launch(cache, current_state, request, request_id)?;
let (
mind_request,
planning,
candidate,
identity,
attempt_ordinal,
superseded_failure_result_id,
) = validate_frontier_plan_mind_launch(cache, current_state, request, request_id)?;
let projection =
RepoFrontierPlanMindContextProjection::new(&mind_request, &planning, &candidate);
match &mut effective_launch_document {
@ -278,7 +290,13 @@ fn commit_coordinator_job_launch_in_cache(
"{:x}",
Sha256::digest(rmp_serde::to_vec_named(&effective_launch_document)?)
);
Some((mind_request, identity, hash))
Some((
mind_request,
identity,
hash,
attempt_ordinal,
superseded_failure_result_id,
))
} else {
None
};
@ -396,10 +414,25 @@ fn commit_coordinator_job_launch_in_cache(
.0,
);
}
if let Some((planning, identity, worker_launch_document_sha256)) = frontier_planning_launch {
if let Some((
planning,
identity,
worker_launch_document_sha256,
attempt_ordinal,
superseded_failure_result_id,
)) = frontier_planning_launch
{
let binding_record_id = if attempt_ordinal == 0 {
format!("repo-frontier-planning-launch-{}", planning.request_id)
} else {
format!(
"repo-frontier-planning-launch-{}-attempt-{attempt_ordinal}",
planning.request_id
)
};
let launch_binding = RepoFrontierPlanningLaunchBinding {
schema_version: REPO_FRONTIER_PLANNING_LAUNCH_BINDING_SCHEMA_VERSION.into(),
binding_record_id: format!("repo-frontier-planning-launch-{}", planning.request_id),
binding_record_id,
planning_request_id: planning.request_id,
job_id: plan.backend_job_id.clone(),
binding_id: request.binding_id.clone(),
@ -408,6 +441,8 @@ fn commit_coordinator_job_launch_in_cache(
launched_at: created_at.clone(),
worker_launch_document_sha256,
contract: REPO_FRONTIER_PLANNING_LAUNCH_BINDING_CONTRACT.into(),
attempt_ordinal,
superseded_failure_result_id,
};
if cache
.get::<RepoFrontierPlanningLaunchBinding>(&launch_binding.binding_record_id)?
@ -450,14 +485,25 @@ fn commit_coordinator_job_launch_in_cache(
}
batch.push(cache.prepare_entry(&binding.binding_record_id, &binding)?.0);
}
if let Some((mind_request, identity, worker_launch_document_sha256)) = frontier_plan_mind_launch
if let Some((
mind_request,
identity,
worker_launch_document_sha256,
attempt_ordinal,
superseded_failure_result_id,
)) = frontier_plan_mind_launch
{
let binding_record_id = if attempt_ordinal == 0 {
format!("repo-frontier-plan-mind-launch-{}", mind_request.request_id)
} else {
format!(
"repo-frontier-plan-mind-launch-{}-attempt-{attempt_ordinal}",
mind_request.request_id
)
};
let binding = RepoFrontierPlanMindLaunchBinding {
schema_version: REPO_FRONTIER_PLAN_MIND_LAUNCH_BINDING_SCHEMA_VERSION.into(),
binding_record_id: format!(
"repo-frontier-plan-mind-launch-{}",
mind_request.request_id
),
binding_record_id,
mind_request_id: mind_request.request_id,
job_id: plan.backend_job_id.clone(),
binding_id: request.binding_id.clone(),
@ -466,6 +512,8 @@ fn commit_coordinator_job_launch_in_cache(
launched_at: created_at.clone(),
worker_launch_document_sha256,
contract: REPO_FRONTIER_PLAN_MIND_LAUNCH_BINDING_CONTRACT.into(),
attempt_ordinal,
superseded_failure_result_id,
};
if cache
.get::<RepoFrontierPlanMindLaunchBinding>(&binding.binding_record_id)?
@ -654,6 +702,8 @@ fn validate_frontier_plan_mind_launch(
RepoFrontierPlanningRequest,
RepoFrontierPlanCandidate,
EpiphanyRuntimeIdentity,
u64,
Option<String>,
)> {
if launch.owner_role != EPIPHANY_MIND_OWNER_ROLE
|| launch.binding_id != EPIPHANY_MIND_ROLE_BINDING_ID
@ -680,14 +730,66 @@ fn validate_frontier_plan_mind_launch(
{
return Err(anyhow!("Mind launch provenance mismatch"));
}
if cache
let persisted_state = persisted.state()?;
let mut launches = cache
.get_all::<RepoFrontierPlanMindLaunchBinding>()?
.iter()
.any(|b| b.mind_request_id == request_id)
{
return Err(anyhow!("Mind request already bound"));
.into_iter()
.filter(|binding| binding.mind_request_id == request_id)
.collect::<Vec<_>>();
launches.sort_by_key(|binding| binding.attempt_ordinal);
for (expected, binding) in launches.iter().enumerate() {
if binding.attempt_ordinal != expected as u64 {
return Err(anyhow!("Mind planning attempts must be contiguous"));
}
}
Ok((request, planning, candidate, identity))
let superseded_failure_result_id = if let Some(latest) = launches.last() {
let results = cache
.get_all::<EpiphanyRuntimeRoleWorkerResult>()?
.into_iter()
.filter(|result| result.job_id == latest.job_id)
.collect::<Vec<_>>();
if results.len() != 1 {
return Err(anyhow!("Mind retry requires one typed prior result"));
}
let failure = &results[0];
if !failure.role_id.eq_ignore_ascii_case("mindAdmissionReview")
|| failure.frontier_plan_mind_request_id.is_some()
|| failure.frontier_plan_mind_decision_msgpack.is_some()
|| failure.item_error.as_deref().is_none_or(str::is_empty)
{
return Err(anyhow!(
"Mind retry requires a non-executable typed failure"
));
}
let reviewed = persisted_state
.acceptance_receipts
.iter()
.filter(|receipt| {
receipt.result_id == failure.result_id
&& receipt.job_id == failure.job_id
&& receipt.binding_id == EPIPHANY_MIND_ROLE_BINDING_ID
&& receipt.surface == "roleFailureReview"
&& receipt.role_id == "mindAdmissionReview"
&& receipt.status == "superseded"
})
.count();
if reviewed != 1 {
return Err(anyhow!("Mind retry requires one explicit failure review"));
}
Some(failure.result_id.clone())
} else {
None
};
let attempt_ordinal = u64::try_from(launches.len())
.map_err(|_| anyhow!("Mind planning attempt ordinal overflow"))?;
Ok((
request,
planning,
candidate,
identity,
attempt_ordinal,
superseded_failure_result_id,
))
}
fn validate_frontier_planning_launch(
@ -695,7 +797,12 @@ fn validate_frontier_planning_launch(
state: &EpiphanyThreadState,
launch: &EpiphanyJobLaunchRequest,
request_id: &str,
) -> Result<(RepoFrontierPlanningRequest, EpiphanyRuntimeIdentity)> {
) -> Result<(
RepoFrontierPlanningRequest,
EpiphanyRuntimeIdentity,
u64,
Option<String>,
)> {
if match &launch.launch_document {
EpiphanyWorkerLaunchDocument::Role(document) => {
document.frontier_planning_context.is_some()
@ -732,16 +839,69 @@ fn validate_frontier_planning_launch(
"frontier planning launch provenance binding mismatch"
));
}
if cache
let mut launches = cache
.get_all::<RepoFrontierPlanningLaunchBinding>()?
.iter()
.any(|binding| binding.planning_request_id == request_id)
{
return Err(anyhow!(
"frontier planning request is already bound to a launch"
));
.into_iter()
.filter(|binding| binding.planning_request_id == request_id)
.collect::<Vec<_>>();
launches.sort_by_key(|binding| binding.attempt_ordinal);
for (expected, binding) in launches.iter().enumerate() {
if binding.attempt_ordinal != expected as u64 {
return Err(anyhow!(
"frontier planning attempts must be contiguous and monotonic"
));
}
}
Ok((planning, identity))
let superseded_failure_result_id = if let Some(latest) = launches.last() {
let results = cache
.get_all::<EpiphanyRuntimeRoleWorkerResult>()?
.into_iter()
.filter(|result| result.job_id == latest.job_id)
.collect::<Vec<_>>();
if results.len() != 1 {
return Err(anyhow!(
"frontier planning retry requires exactly one typed prior attempt result"
));
}
let failure = &results[0];
if !failure.role_id.eq_ignore_ascii_case("imagination")
|| failure.frontier_planning_request_id.is_some()
|| failure.frontier_plan_candidate_msgpack.is_some()
|| failure.item_error.as_deref().is_none_or(str::is_empty)
{
return Err(anyhow!(
"frontier planning retry requires a non-executable typed prior failure"
));
}
let reviewed = persisted_state_value
.acceptance_receipts
.iter()
.filter(|receipt| {
receipt.result_id == failure.result_id
&& receipt.job_id == failure.job_id
&& receipt.binding_id == EPIPHANY_IMAGINATION_ROLE_BINDING_ID
&& receipt.surface == "roleFailureReview"
&& receipt.role_id == "imagination"
&& receipt.status == "superseded"
})
.collect::<Vec<_>>();
if reviewed.len() != 1 {
return Err(anyhow!(
"frontier planning retry requires exactly one explicit failure review"
));
}
Some(failure.result_id.clone())
} else {
None
};
let attempt_ordinal = u64::try_from(launches.len())
.map_err(|_| anyhow!("frontier planning attempt ordinal overflow"))?;
Ok((
planning,
identity,
attempt_ordinal,
superseded_failure_result_id,
))
}
fn validate_imagination_consideration_launch(
@ -2886,6 +3046,19 @@ pub(crate) mod tests {
failed.frontier_plan_candidate_msgpack = None;
failed.item_error = Some("model runtime failed before producing a candidate".into());
put_runtime_role_worker_result(&store, &failed)?;
crate::complete_runtime_job(
&store,
crate::RuntimeSpineJobResultOptions {
result_id: format!("runtime-failure-{job_id}"),
job_id: job_id.into(),
completed_at: "2026-07-15T09:00:04Z".into(),
verdict: "failed".into(),
summary: "Model runtime rejected the planning candidate.".into(),
next_safe_move: "Review before retry.".into(),
evidence_refs: Vec::new(),
artifact_refs: Vec::new(),
},
)?;
let lifecycle = crate::runtime_repo_frontier_planning_lifecycle(&store)?;
assert_eq!(
@ -2896,6 +3069,251 @@ pub(crate) mod tests {
lifecycle.imagination_result_id.as_deref(),
Some(failed.result_id.as_str())
);
let service = crate::EpiphanyCoordinatorService::new(&store);
let current = service.state()?.expect("current coordinator state");
let mut retry_launch = build_epiphany_role_launch_request(
&planning.thread_id,
EpiphanyRoleResultRoleId::Imagination,
Some(current.revision),
Some(60),
&current,
)
.map_err(|error| anyhow!(error))?;
retry_launch.frontier_planning_request_id = Some(planning.request_id.clone());
assert!(
plan_coordinator_job_launch(
&current,
&retry_launch,
&store,
"launcher-frontier-worker-retry-before-review".into(),
"backend-frontier-worker-retry-before-review".into(),
)
.is_err(),
"failure alone must not authorize retry"
);
let review = epiphany_state_model::EpiphanyAcceptanceReceipt {
id: "frontier-planning-failure-review-test".into(),
result_id: failed.result_id.clone(),
job_id: failed.job_id.clone(),
binding_id: EPIPHANY_IMAGINATION_ROLE_BINDING_ID.into(),
surface: "roleFailureReview".into(),
role_id: "imagination".into(),
status: "superseded".into(),
accepted_at: "2026-07-15T09:00:05Z".into(),
accepted_observation_id: None,
accepted_evidence_id: None,
summary: Some("Operator reviewed immutable planning failure.".into()),
};
service.apply_state_update(
&planning.thread_id,
crate::EpiphanyStateUpdate {
expected_revision: Some(current.revision),
acceptance_receipts: vec![review],
..Default::default()
},
None,
)?;
assert_eq!(
crate::runtime_repo_frontier_planning_lifecycle(&store)?.stage,
crate::RepoFrontierPlanningLifecycleStage::ImaginationLaunchReady
);
let current = service.state()?.expect("reviewed coordinator state");
let mut retry_launch = build_epiphany_role_launch_request(
&planning.thread_id,
EpiphanyRoleResultRoleId::Imagination,
Some(current.revision),
Some(60),
&current,
)
.map_err(|error| anyhow!(error))?;
retry_launch.frontier_planning_request_id = Some(planning.request_id.clone());
let retry_job_id = "backend-frontier-worker-retry";
let retry_plan = plan_coordinator_job_launch(
&current,
&retry_launch,
&store,
"launcher-frontier-worker-retry".into(),
retry_job_id.into(),
)?;
commit_coordinator_job_launch(
&store,
&planning.thread_id,
&current,
&retry_launch,
&retry_plan,
"2026-07-15T09:00:06Z".into(),
)?;
let mut cache = coordinator_acceptance_cache(&store)?;
cache.pull_all_backing_stores()?;
let mut attempts = cache
.get_all::<RepoFrontierPlanningLaunchBinding>()?
.into_iter()
.filter(|binding| binding.planning_request_id == planning.request_id)
.collect::<Vec<_>>();
attempts.sort_by_key(|binding| binding.attempt_ordinal);
assert_eq!(attempts.len(), 2);
assert_eq!(attempts[0].attempt_ordinal, 0);
assert_eq!(attempts[1].attempt_ordinal, 1);
assert_eq!(
attempts[1].superseded_failure_result_id.as_deref(),
Some(failed.result_id.as_str())
);
assert_eq!(attempts[1].job_id, retry_job_id);
Ok(())
}
#[test]
fn frontier_mind_failure_requires_review_and_preserves_retry_attempts() -> Result<()> {
let root = tempfile::tempdir()?;
let (store, _, imagination_result, mind_request) =
operator_review_candidate_fixture(root.path(), "mind-worker-failure")?;
let service = crate::EpiphanyCoordinatorService::new(&store);
let state = service.state()?.expect("current coordinator state");
let launch = crate::build_epiphany_frontier_plan_mind_launch_request(
&mind_request.thread_id,
Some(state.revision),
Some(60),
&state,
mind_request.request_id.clone(),
)
.map_err(|error| anyhow!(error))?;
let job_id = "backend-frontier-mind-worker-failure";
let plan = plan_coordinator_job_launch(
&state,
&launch,
&store,
"launcher-frontier-mind-worker-failure".into(),
job_id.into(),
)?;
commit_coordinator_job_launch(
&store,
&mind_request.thread_id,
&state,
&launch,
&plan,
"2026-07-15T09:00:06Z".into(),
)?;
let mut failed = imagination_result;
failed.result_id = "frontier-mind-worker-failure".into();
failed.job_id = job_id.into();
failed.role_id = "mindAdmissionReview".into();
failed.verdict = "runtime-error".into();
failed.frontier_planning_request_id = None;
failed.frontier_plan_candidate_msgpack = None;
failed.frontier_plan_mind_request_id = None;
failed.frontier_plan_mind_decision_msgpack = None;
failed.item_error = Some("model runtime failed before judging the candidate".into());
put_runtime_role_worker_result(&store, &failed)?;
crate::complete_runtime_job(
&store,
crate::RuntimeSpineJobResultOptions {
result_id: format!("runtime-failure-{job_id}"),
job_id: job_id.into(),
completed_at: "2026-07-15T09:00:07Z".into(),
verdict: "failed".into(),
summary: "Model runtime failed before Mind judgment.".into(),
next_safe_move: "Review before retry.".into(),
evidence_refs: Vec::new(),
artifact_refs: Vec::new(),
},
)?;
assert_eq!(
crate::runtime_repo_frontier_planning_lifecycle(&store)?.stage,
crate::RepoFrontierPlanningLifecycleStage::MindFailed
);
let state = service.state()?.expect("failed coordinator state");
let retry_launch = crate::build_epiphany_frontier_plan_mind_launch_request(
&mind_request.thread_id,
Some(state.revision),
Some(60),
&state,
mind_request.request_id.clone(),
)
.map_err(|error| anyhow!(error))?;
assert!(
plan_coordinator_job_launch(
&state,
&retry_launch,
&store,
"launcher-frontier-mind-retry-before-review".into(),
"backend-frontier-mind-retry-before-review".into(),
)
.is_err(),
"Mind failure alone must not authorize retry"
);
service.apply_state_update(
&mind_request.thread_id,
crate::EpiphanyStateUpdate {
expected_revision: Some(state.revision),
acceptance_receipts: vec![epiphany_state_model::EpiphanyAcceptanceReceipt {
id: "frontier-mind-failure-review-test".into(),
result_id: failed.result_id.clone(),
job_id: failed.job_id.clone(),
binding_id: EPIPHANY_MIND_ROLE_BINDING_ID.into(),
surface: "roleFailureReview".into(),
role_id: "mindAdmissionReview".into(),
status: "superseded".into(),
accepted_at: "2026-07-15T09:00:08Z".into(),
accepted_observation_id: None,
accepted_evidence_id: None,
summary: Some("Operator reviewed immutable Mind failure.".into()),
}],
..Default::default()
},
None,
)?;
assert_eq!(
crate::runtime_repo_frontier_planning_lifecycle(&store)?.stage,
crate::RepoFrontierPlanningLifecycleStage::MindLaunchReady
);
let state = service.state()?.expect("reviewed coordinator state");
let retry_launch = crate::build_epiphany_frontier_plan_mind_launch_request(
&mind_request.thread_id,
Some(state.revision),
Some(60),
&state,
mind_request.request_id.clone(),
)
.map_err(|error| anyhow!(error))?;
let retry_job_id = "backend-frontier-mind-worker-retry";
let retry_plan = plan_coordinator_job_launch(
&state,
&retry_launch,
&store,
"launcher-frontier-mind-worker-retry".into(),
retry_job_id.into(),
)?;
commit_coordinator_job_launch(
&store,
&mind_request.thread_id,
&state,
&retry_launch,
&retry_plan,
"2026-07-15T09:00:09Z".into(),
)?;
let mut cache = coordinator_acceptance_cache(&store)?;
cache.pull_all_backing_stores()?;
let mut attempts = cache
.get_all::<RepoFrontierPlanMindLaunchBinding>()?
.into_iter()
.filter(|binding| binding.mind_request_id == mind_request.request_id)
.collect::<Vec<_>>();
attempts.sort_by_key(|binding| binding.attempt_ordinal);
assert_eq!(attempts.len(), 2);
assert_eq!(attempts[0].attempt_ordinal, 0);
assert_eq!(attempts[1].attempt_ordinal, 1);
assert_eq!(
attempts[1].superseded_failure_result_id.as_deref(),
Some(failed.result_id.as_str())
);
assert_eq!(attempts[1].job_id, retry_job_id);
Ok(())
}

View file

@ -508,6 +508,10 @@ pub struct RepoFrontierPlanningLaunchBinding {
pub worker_launch_document_sha256: String,
#[cultcache(key = 9)]
pub contract: String,
#[cultcache(key = 10, default)]
pub attempt_ordinal: u64,
#[cultcache(key = 11, default)]
pub superseded_failure_result_id: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Eq, DatabaseEntry)]
@ -665,6 +669,10 @@ pub struct RepoFrontierPlanMindLaunchBinding {
pub worker_launch_document_sha256: String,
#[cultcache(key = 9)]
pub contract: String,
#[cultcache(key = 10, default)]
pub attempt_ordinal: u64,
#[cultcache(key = 11, default)]
pub superseded_failure_result_id: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]

View file

@ -2000,7 +2000,9 @@ pub fn put_runtime_role_worker_result(
let bindings = cache
.get_all::<RepoFrontierPlanningLaunchBinding>()?
.into_iter()
.filter(|binding| binding.planning_request_id == request.request_id)
.filter(|binding| {
binding.planning_request_id == request.request_id && binding.job_id == result.job_id
})
.collect::<Vec<_>>();
if bindings.len() != 1 {
return Err(anyhow!(
@ -2251,7 +2253,9 @@ pub fn put_runtime_role_worker_result(
let bindings = cache
.get_all::<RepoFrontierPlanMindLaunchBinding>()?
.into_iter()
.filter(|b| b.mind_request_id == request.request_id)
.filter(|binding| {
binding.mind_request_id == request.request_id && binding.job_id == result.job_id
})
.collect::<Vec<_>>();
if bindings.len() != 1 {
return Err(anyhow!(
@ -6336,26 +6340,26 @@ pub fn runtime_repo_frontier_planning_lifecycle(
mind_result_id: None,
decision_id: None,
};
let imagination_launches = cache
let mut imagination_launches = cache
.get_all::<RepoFrontierPlanningLaunchBinding>()?
.into_iter()
.filter(|binding| binding.planning_request_id == request.request_id)
.collect::<Vec<_>>();
if imagination_launches.len() > 1 {
return Err(anyhow!(
"Self found multiple Imagination launches for one planning request"
));
imagination_launches.sort_by_key(|binding| binding.attempt_ordinal);
for (expected, binding) in imagination_launches.iter().enumerate() {
if binding.attempt_ordinal != expected as u64 {
return Err(anyhow!(
"Self found noncontiguous frontier planning attempt identity"
));
}
}
if let Some(binding) = imagination_launches.first() {
if let Some(binding) = imagination_launches.last() {
lifecycle.imagination_job_id = Some(binding.job_id.clone());
}
let imagination_results = cache
.get_all::<EpiphanyRuntimeRoleWorkerResult>()?
.into_iter()
.filter(|result| {
result.frontier_planning_request_id.as_deref() == Some(request.request_id.as_str())
|| lifecycle.imagination_job_id.as_deref() == Some(result.job_id.as_str())
})
.filter(|result| lifecycle.imagination_job_id.as_deref() == Some(result.job_id.as_str()))
.collect::<Vec<_>>();
if imagination_results.len() > 1 {
return Err(anyhow!(
@ -6373,7 +6377,43 @@ pub fn runtime_repo_frontier_planning_lifecycle(
if imagination_result.frontier_planning_request_id.as_deref()
!= Some(request.request_id.as_str())
{
lifecycle.stage = RepoFrontierPlanningLifecycleStage::ImaginationFailed;
if !imagination_result
.role_id
.eq_ignore_ascii_case("imagination")
|| imagination_result
.item_error
.as_deref()
.is_none_or(str::is_empty)
|| imagination_result.frontier_plan_candidate_msgpack.is_some()
{
return Err(anyhow!(
"Self found malformed typed frontier planning failure"
));
}
let reviewed = cache
.get::<crate::EpiphanyThreadStateEntry>(crate::THREAD_STATE_KEY)?
.ok_or_else(|| anyhow!("planning failure review requires thread state"))?
.state()?
.acceptance_receipts
.into_iter()
.filter(|receipt| {
receipt.result_id == imagination_result.result_id
&& receipt.job_id == imagination_result.job_id
&& receipt.binding_id == EPIPHANY_IMAGINATION_ROLE_BINDING_ID
&& receipt.surface == "roleFailureReview"
&& receipt.role_id == "imagination"
&& receipt.status == "superseded"
})
.count();
lifecycle.stage = if reviewed == 1 {
RepoFrontierPlanningLifecycleStage::ImaginationLaunchReady
} else if reviewed == 0 {
RepoFrontierPlanningLifecycleStage::ImaginationFailed
} else {
return Err(anyhow!(
"Self found conflicting frontier planning failure reviews"
));
};
return Ok(lifecycle);
}
let mind_requests = cache
@ -6393,27 +6433,24 @@ pub fn runtime_repo_frontier_planning_lifecycle(
validate_repo_frontier_plan_mind_request(&cache, mind_request)?;
lifecycle.mind_request_id = Some(mind_request.request_id.clone());
lifecycle.stage = RepoFrontierPlanningLifecycleStage::MindLaunchReady;
let mind_launches = cache
let mut mind_launches = cache
.get_all::<RepoFrontierPlanMindLaunchBinding>()?
.into_iter()
.filter(|binding| binding.mind_request_id == mind_request.request_id)
.collect::<Vec<_>>();
if mind_launches.len() > 1 {
return Err(anyhow!(
"Self found multiple Mind launches for one planning request"
));
mind_launches.sort_by_key(|binding| binding.attempt_ordinal);
for (expected, binding) in mind_launches.iter().enumerate() {
if binding.attempt_ordinal != expected as u64 {
return Err(anyhow!("Self found noncontiguous Mind attempt identity"));
}
}
if let Some(binding) = mind_launches.first() {
if let Some(binding) = mind_launches.last() {
lifecycle.mind_job_id = Some(binding.job_id.clone());
}
let mind_results = cache
.get_all::<EpiphanyRuntimeRoleWorkerResult>()?
.into_iter()
.filter(|result| {
result.frontier_plan_mind_request_id.as_deref()
== Some(mind_request.request_id.as_str())
|| lifecycle.mind_job_id.as_deref() == Some(result.job_id.as_str())
})
.filter(|result| lifecycle.mind_job_id.as_deref() == Some(result.job_id.as_str()))
.collect::<Vec<_>>();
if mind_results.len() > 1 {
return Err(anyhow!(
@ -6431,7 +6468,36 @@ pub fn runtime_repo_frontier_planning_lifecycle(
if mind_result.frontier_plan_mind_request_id.as_deref()
!= Some(mind_request.request_id.as_str())
{
lifecycle.stage = RepoFrontierPlanningLifecycleStage::MindFailed;
if !mind_result
.role_id
.eq_ignore_ascii_case("mindAdmissionReview")
|| mind_result.item_error.as_deref().is_none_or(str::is_empty)
|| mind_result.frontier_plan_mind_decision_msgpack.is_some()
{
return Err(anyhow!("Self found malformed typed Mind failure"));
}
let reviewed = cache
.get::<crate::EpiphanyThreadStateEntry>(crate::THREAD_STATE_KEY)?
.ok_or_else(|| anyhow!("Mind failure review requires thread state"))?
.state()?
.acceptance_receipts
.into_iter()
.filter(|receipt| {
receipt.result_id == mind_result.result_id
&& receipt.job_id == mind_result.job_id
&& receipt.binding_id == EPIPHANY_MIND_ROLE_BINDING_ID
&& receipt.surface == "roleFailureReview"
&& receipt.role_id == "mindAdmissionReview"
&& receipt.status == "superseded"
})
.count();
lifecycle.stage = if reviewed == 1 {
RepoFrontierPlanningLifecycleStage::MindLaunchReady
} else if reviewed == 0 {
RepoFrontierPlanningLifecycleStage::MindFailed
} else {
return Err(anyhow!("Self found conflicting Mind failure reviews"));
};
return Ok(lifecycle);
}
lifecycle.stage = RepoFrontierPlanningLifecycleStage::MindResultReady;

View file

@ -2067,6 +2067,7 @@ dependencies = [
"epiphany-openai-adapter",
"epiphany-state-model",
"epiphany-tool-adapter",
"fs2",
"ignore",
"libc",
"postgres",

View file

@ -30,6 +30,7 @@ use epiphany_openai_runtime::default_codex_home;
use epiphany_openai_runtime::default_options;
use epiphany_openai_runtime::ensure_openai_runtime_ready;
use epiphany_openai_runtime::fail_worker_job;
use epiphany_openai_runtime::failed_frontier_planning_role_result;
use epiphany_openai_runtime::load_worker_launch_request;
use epiphany_openai_runtime::record_openai_events;
use epiphany_openai_runtime::run_model_turn;
@ -596,6 +597,12 @@ fn fail_worker_for_runtime_error(
error: String,
) -> Result<serde_json::Value> {
let summary = format!("Worker runtime failed before producing usable output: {error}");
let launch = load_worker_launch_request(store_path, job_id)?;
if epiphany_core::runtime_role_worker_result(store_path, job_id)?.is_none()
&& let Some(role_failure) = failed_frontier_planning_role_result(&launch, &error)?
{
epiphany_core::put_runtime_role_worker_result(store_path, &role_failure)?;
}
let result = fail_worker_and_openai_jobs(
store_path,
job_id,

View file

@ -1607,6 +1607,9 @@ fn role_worker_result_from_ingress(
let (frontier_plan_candidate_msgpack, frontier_plan_candidate_error) = if let Some(ingress) =
result.frontier_plan_candidate.as_ref()
{
let mut safe_paths = clean_string_vec(&ingress.safe_paths);
safe_paths.sort();
safe_paths.dedup();
let mut candidate = epiphany_core::RepoFrontierPlanCandidate {
schema_version: epiphany_core::REPO_FRONTIER_PLAN_CANDIDATE_SCHEMA_VERSION.to_string(),
candidate_id: String::new(),
@ -1615,7 +1618,7 @@ fn role_worker_result_from_ingress(
model_hash: ingress.model_hash.clone(),
frontier_item_id: ingress.frontier_item_id.clone(),
frontier_item_hash: ingress.frontier_item_hash.clone(),
safe_paths: clean_string_vec(&ingress.safe_paths),
safe_paths,
action: ingress.action.trim().to_string(),
command: ingress.command.trim().to_string(),
checks: clean_string_vec(&ingress.checks),
@ -1825,6 +1828,66 @@ fn role_worker_result_from_ingress(
}
}
/// Projects a model-adapter failure into the typed faculty result consumed by
/// Self's frontier-planning lifecycle. The generic runtime job remains the
/// process/transport receipt; this document states only that the exact launched
/// faculty produced no executable candidate or Mind judgment.
pub fn failed_frontier_planning_role_result(
launch_request: &EpiphanyRuntimeWorkerLaunchRequest,
error: &str,
) -> Result<Option<EpiphanyRuntimeRoleWorkerResult>> {
if launch_request.frontier_planning_request_id.is_none()
&& launch_request.frontier_plan_mind_request_id.is_none()
{
return Ok(None);
}
let document = launch_request.launch_document()?;
let EpiphanyWorkerLaunchDocument::Role(document) = document else {
return Err(anyhow!(
"frontier planning failure projection requires a role launch"
));
};
let summary = format!("Worker runtime failed before producing usable output: {error}");
Ok(Some(EpiphanyRuntimeRoleWorkerResult {
schema_version: epiphany_core::RUNTIME_ROLE_WORKER_RESULT_SCHEMA_VERSION.to_string(),
result_id: format!("result-worker-{}", launch_request.job_id),
job_id: launch_request.job_id.clone(),
role_id: document.role_id,
verdict: "runtime-error".to_string(),
summary: summary.clone(),
next_safe_move: "Review the immutable planning failure before authorizing another attempt."
.to_string(),
checkpoint_summary: None,
scratch_summary: None,
files_inspected: Vec::new(),
frontier_node_ids: Vec::new(),
evidence_ids: Vec::new(),
artifact_refs: Vec::new(),
open_questions: Vec::new(),
evidence_gaps: Vec::new(),
risks: Vec::new(),
state_patch_msgpack: None,
self_patch_msgpack: None,
item_error: Some(error.trim().to_string()),
metadata: std::collections::BTreeMap::new(),
repo_model_patch_msgpack: None,
verification_request_id: None,
frontier_route_id: None,
repo_frontier_modeling_request_id: None,
proposal_modeling_request_id: None,
claim_repair_request_id: None,
frontier_planning_request_id: None,
frontier_plan_candidate_msgpack: None,
frontier_plan_mind_request_id: None,
frontier_plan_mind_decision_msgpack: None,
repository_body_observation_basis: document.repository_body_observation_basis,
imagination_consideration_request_id: None,
imagination_consideration_candidate_msgpack: None,
admitted_model_direction_consideration_request_id: None,
admitted_model_direction_consideration_result_msgpack: None,
}))
}
fn reorient_worker_result_from_ingress(
launch_request: &EpiphanyRuntimeWorkerLaunchRequest,
result_id: &str,
@ -2028,7 +2091,7 @@ mod tests {
"model_hash":"model-hash",
"frontier_item_id":"frontier-1",
"frontier_item_hash":"frontier-hash",
"safe_paths":["src"],
"safe_paths":["tests","src","src"],
"action":"Implement the bounded cut.",
"command":"cargo test --lib",
"checks":["focused test passes"],
@ -2088,6 +2151,72 @@ mod tests {
candidate.schema_version,
epiphany_core::REPO_FRONTIER_PLAN_CANDIDATE_SCHEMA_VERSION
);
assert_eq!(candidate.safe_paths, ["src", "tests"]);
Ok(())
}
#[test]
fn frontier_planning_runtime_error_projects_non_executable_typed_failure() -> Result<()> {
let document =
EpiphanyWorkerLaunchDocument::Role(epiphany_core::EpiphanyRoleWorkerLaunchDocument {
thread_id: "thread-1".into(),
role_id: "imagination".into(),
state_revision: 1,
objective: Some("Plan one frontier.".into()),
dynamic_prompt_context: None,
repository_body_observation_basis: None,
proposal_modeling_context: None,
claim_repair_context: None,
frontier_planning_context: None,
frontier_plan_mind_context: None,
imagination_consideration_context: None,
admitted_model_direction_consideration_context: 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 = EpiphanyRuntimeWorkerLaunchRequest {
schema_version: epiphany_core::RUNTIME_WORKER_LAUNCH_REQUEST_SCHEMA_VERSION.into(),
job_id: "planning-job-failed".into(),
binding_id: epiphany_core::EPIPHANY_IMAGINATION_ROLE_BINDING_ID.into(),
role: epiphany_core::EPIPHANY_IMAGINATION_OWNER_ROLE.into(),
authority_scope: "epiphany.role.imagination".into(),
instruction: "plan".into(),
output_contract_id: epiphany_core::ROLE_WORKER_OUTPUT_CONTRACT_ID.into(),
document_kind: "role".into(),
launch_document_msgpack: rmp_serde::to_vec_named(&document)?,
metadata: std::collections::BTreeMap::new(),
organ_launch_contract: epiphany_core::default_launch_organ_contract(
"epiphany.role.imagination",
"role",
epiphany_core::ROLE_WORKER_OUTPUT_CONTRACT_ID,
),
proposal_modeling_request_id: None,
claim_repair_request_id: None,
frontier_planning_request_id: Some("planning-request-1".into()),
frontier_plan_mind_request_id: None,
imagination_consideration_request_id: None,
admitted_model_direction_consideration_request_id: None,
};
let failed = failed_frontier_planning_role_result(&launch, "candidate mismatch")?
.expect("typed planning failure");
assert_eq!(failed.job_id, launch.job_id);
assert_eq!(failed.role_id, "imagination");
assert_eq!(failed.item_error.as_deref(), Some("candidate mismatch"));
assert!(failed.frontier_planning_request_id.is_none());
assert!(failed.frontier_plan_candidate_msgpack.is_none());
assert!(failed.state_patch_msgpack.is_none());
assert!(failed.repo_model_patch_msgpack.is_none());
Ok(())
}

View file

@ -128,6 +128,18 @@ identity/cargo validator error, while frontier lifecycle remains
`imaginationRunning` with no typed result. This independent reproduction rules
out a one-off detached-process race. Do not create v48: planning cannot adopt
the repair because the failure is before the typed result Self needs to review
or retry planning. The next lawful move is explicit operator authorization for
a labeled supervisor intervention to repair typed failure projection and retry
semantics, followed by packaging and a new clean dogfood run.
or retry planning.
The operator explicitly authorized proactive intervention in corrupted
Epiphany runtime state, with receipts. The labeled supervisor intervention is
now implemented in source. The OpenAI runtime canonicalizes set-shaped safe
paths before identity validation and persists a non-executable typed role
failure beside the generic failed runtime job. Self owns explicit reviewed
supersession and creates monotonic immutable retry bindings for both
Imagination planning and dedicated Mind judgment; failure alone cannot retry,
old attempts remain evidence, and candidate/decision cargo is forbidden on the
failure projection. Focused core, coordinator, and runtime tests pass,
including symmetric Imagination and Mind failure/review/retry proofs. The next
move is commit/push, one exact incremental authenticated package, and a fresh
route-free live proof. v46 and v47 remain sealed and must not be repaired in
place.

Binary file not shown.

View file

@ -34,9 +34,9 @@ invariants:
- Evidence and git retain history; this map retains only state that changes future decisions.
current_status:
summary: Epiphany is a supervised engineering alpha on Starfire, not deployment-ready. Exact ecfff489 packages as sha256-6e5cd9827ab6a659c8a29f1147daf8ebec52ea3d148a16905a1401c539059d79 with witness sha256-8d53746348eecf2afd2a5def5539dfb544e260104fb33e3e7d0eec83573ce3dc. Fresh v44 proves proposal Modeling, canonical Imagination, dedicated Mind adoption, and exact Hands gating without overrides. Hands inspection then falsified the adopted path ceiling: it omits the status-composition owner required by the checkpoint repair. v46 and independently reconstructed v47 both accepted route-free proposal Modeling, then canonical Imagination failed the same candidate identity/cargo validation. Each generic runtime job failed without a typed role failure, leaving Self falsely at imaginationRunning. Persona consequence, retention, endurance, and Linux/Yggdrasil cognition remain open.
summary: Epiphany is a supervised engineering alpha on Starfire, not deployment-ready. Exact ecfff489 packages as sha256-6e5cd9827ab6a659c8a29f1147daf8ebec52ea3d148a16905a1401c539059d79 with witness sha256-8d53746348eecf2afd2a5def5539dfb544e260104fb33e3e7d0eec83573ce3dc. Fresh v44 proves proposal Modeling, canonical Imagination, dedicated Mind adoption, and exact Hands gating without overrides. v46 and independently reconstructed v47 are sealed negative evidence for the planning failure seam. The operator explicitly authorized a labeled supervisor intervention. The repair now canonicalizes set-shaped planning ingress, projects exact non-executable typed failures beside generic failed jobs, and lets Self schedule immutable Imagination or Mind retry attempts only after exact reviewed supersession. Focused tests pass; exact packaging and fresh route-free proof remain. Persona consequence, retention, endurance, and Linux/Yggdrasil cognition remain open.
operational_state:
local_worktree: clean_at_388c49bc_incremental_release_policy
local_worktree: supervisor_intervention_planning_failure_retry_ready_for_commit
operator_wireguard: restored
yggdrasil: canonical_small_public_crossing_body
starfire: temporary_epiphany_cognition_body
@ -52,8 +52,8 @@ current_status:
bifrost_feedback_crossing: authenticated_transport_only
yggdrasil_epiphany_services: absent
resident_physiology: heartbeat_and_self_running
unresolved_authority: v44 proved the native planning circuit and exact Hands gate. The adopted plan omitted epiphany-core/src/bin/epiphany-mvp-status.rs, so truthful implementation is forbidden. The cataloged Hands action-refusal receipt has no typed persistence or route-lifecycle transition. v46 additionally proved that a malformed frontier Imagination candidate can fail the generic runtime job without persisting the typed role failure that Self's planning lifecycle consumes; the failed launch then remains projected as running and cannot be retried lawfully.
next_action: Preserve v46 and v47 as independent negative evidence. The planning circuit cannot adopt its own repair because malformed Imagination output fails before the typed role result that Self requires for failure review or retry. Obtain explicit operator authorization for a labeled supervisor intervention that makes the worker adapter persist a non-executable typed Imagination failure alongside the generic failed job and adds lawful planning retry or supersession. Then package that repair, reconstruct a fresh route-free run, and resume Hands relinquishment planning with the actual gateway, CLI, runtime-spine, status-composition, and app-server owners. After implementation, replay sealed v44 and prove CRRC, accepted Reorientation, Continuity recovery, and Soul closure.
unresolved_authority: v44 proved the native planning circuit and exact Hands gate. The adopted plan omitted epiphany-core/src/bin/epiphany-mvp-status.rs, so truthful implementation is forbidden. The cataloged Hands action-refusal receipt has no typed persistence or route-lifecycle transition. The v46/v47 planning-failure seam is repaired in source but not yet proven through an authenticated release and fresh live run.
next_action: Commit and push the receipted supervisor intervention, build one exact authenticated release using the stable incremental cache, and reconstruct a fresh route-free run. Prove malformed planning output writes both terminal receipts, Self exposes a reviewed retry rather than false running state, and canonical planning proceeds through Imagination and Mind. Then resume Hands relinquishment planning with the actual gateway, CLI, runtime-spine, status-composition, and app-server owners. After implementation, replay sealed v44 and prove CRRC, accepted Reorientation, Continuity recovery, and Soul closure.
active_subgoals:
- Prove Persona, Self, Eyes, Modeling, Imagination, Hands, Soul, Mind, Continuity, and nervous-system behavior individually.