From 881b2b1a7ec3e7c83d1cd298acf5313c987b4a0c Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Fri, 7 Aug 2026 14:14:26 +0100 Subject: [PATCH] Route native frontier planning through Self --- .../src/bin/epiphany-mvp-coordinator.rs | 208 +++++++++++++++ epiphany-core/src/bin/epiphany-mvp-status.rs | 9 + epiphany-core/src/coordinator_launch.rs | 85 +++++++ epiphany-core/src/lib.rs | 8 +- epiphany-core/src/repo_model_gateway.rs | 29 +++ epiphany-core/src/runtime_spine.rs | 236 +++++++++++++++++- epiphany-core/src/surfaces/coordinator.rs | 191 +++++++++++++- notes/epiphany-current-algorithmic-map.md | 15 +- notes/fresh-workspace-handoff.md | 18 +- state/map.yaml | 12 +- 10 files changed, 780 insertions(+), 31 deletions(-) diff --git a/epiphany-core/src/bin/epiphany-mvp-coordinator.rs b/epiphany-core/src/bin/epiphany-mvp-coordinator.rs index 5ee7f087..6c32f0f1 100644 --- a/epiphany-core/src/bin/epiphany-mvp-coordinator.rs +++ b/epiphany-core/src/bin/epiphany-mvp-coordinator.rs @@ -518,6 +518,12 @@ fn run_coordinator(args: &Args) -> Result { break; } if action == "awaitFrontierProposal" + || matches!( + action.as_str(), + "waitForImaginationResult" + | "waitForMindPlanResult" + | "reviewFrontierPlanningFailure" + ) || (is_stop_action(&action) && !args.auto_review && !is_result_review_action(&action)) { append_operator_step_jsonl(&steps_path, &step)?; @@ -527,6 +533,127 @@ fn run_coordinator(args: &Args) -> Result { let revision = state_revision(&status); match action.as_str() { + "startFrontierPlanning" => { + let request = epiphany_core::select_and_commit_repo_frontier_planning_request( + &runtime_store, + &now(), + )?; + push_event( + &mut step, + json!({"type": "frontierPlanningRequest", "request": request}), + ); + final_status = collect_coordinator_status(&runtime_store, &thread_id)?; + } + "launchImagination" => { + let lifecycle = + epiphany_core::runtime_repo_frontier_planning_lifecycle(&runtime_store)?; + let request_id = lifecycle.planning_request_id.as_deref().ok_or_else(|| { + anyhow!("launchImagination requires a current planning request") + })?; + let launch = launch_frontier_imagination( + &runtime_store, + &local_verse_store, + &thread_id, + revision, + args.max_runtime_seconds, + request_id, + )?; + let worker_job_id = worker_job_id_from_launch(&launch)?; + push_event( + &mut step, + json!({"type": "frontierImaginationLaunch", "launch": status_cli::sanitize_for_operator(launch), "runtimeJobId": worker_job_id}), + ); + let worker_run = launch_worker_runtime_detached( + &model_runtime_bin, + &tool_adapter_bin, + &args.model_provider, + &runtime_store, + &codex_home, + &mcp_config, + &cwd, + &worker_job_id, + "imagination-frontier-planning", + index, + &artifact_dir, + args.max_runtime_seconds, + args.auto_tools, + )?; + push_event( + &mut step, + json!({"type": "workerRuntime", "roleId": "imagination", "run": worker_run}), + ); + final_status = collect_coordinator_status(&runtime_store, &thread_id)?; + } + "requestMindPlanReview" => { + let lifecycle = + epiphany_core::runtime_repo_frontier_planning_lifecycle(&runtime_store)?; + let result_id = lifecycle.imagination_result_id.as_deref().ok_or_else(|| { + anyhow!("requestMindPlanReview requires a typed Imagination result") + })?; + let request = epiphany_core::commit_repo_frontier_plan_mind_request( + &runtime_store, + result_id, + &now(), + )?; + push_event( + &mut step, + json!({"type": "frontierPlanMindRequest", "request": request}), + ); + final_status = collect_coordinator_status(&runtime_store, &thread_id)?; + } + "launchMindPlanReview" => { + let lifecycle = + epiphany_core::runtime_repo_frontier_planning_lifecycle(&runtime_store)?; + let request_id = lifecycle.mind_request_id.as_deref().ok_or_else(|| { + anyhow!("launchMindPlanReview requires a current Mind request") + })?; + let launch = launch_frontier_mind( + &runtime_store, + &thread_id, + revision, + args.max_runtime_seconds, + request_id, + )?; + let worker_job_id = worker_job_id_from_launch(&launch)?; + push_event( + &mut step, + json!({"type": "frontierMindLaunch", "launch": status_cli::sanitize_for_operator(launch), "runtimeJobId": worker_job_id}), + ); + let worker_run = launch_worker_runtime_detached( + &model_runtime_bin, + &tool_adapter_bin, + &args.model_provider, + &runtime_store, + &codex_home, + &mcp_config, + &cwd, + &worker_job_id, + "mind-frontier-plan-review", + index, + &artifact_dir, + args.max_runtime_seconds, + args.auto_tools, + )?; + push_event( + &mut step, + json!({"type": "workerRuntime", "roleId": "mind", "run": worker_run}), + ); + final_status = collect_coordinator_status(&runtime_store, &thread_id)?; + } + "commitFrontierPlanDecision" => { + let lifecycle = + epiphany_core::runtime_repo_frontier_planning_lifecycle(&runtime_store)?; + let result_id = lifecycle.mind_result_id.as_deref().ok_or_else(|| { + anyhow!("commitFrontierPlanDecision requires a typed Mind result") + })?; + let decision = + epiphany_core::commit_repo_frontier_plan_decision(&runtime_store, result_id)?; + push_event( + &mut step, + json!({"type": "frontierPlanDecision", "decision": decision}), + ); + final_status = collect_coordinator_status(&runtime_store, &thread_id)?; + } "reviewResearchResult" | "reviewModelingResult" | "reviewVerificationResult" => { let role_id = role_id_for_coordinator_action(&action) .ok_or_else(|| anyhow!("unsupported review action {action}"))?; @@ -1207,6 +1334,84 @@ fn launch_role( })) } +fn launch_frontier_imagination( + runtime_store: &Path, + local_verse_store: &Path, + thread_id: &str, + expected_revision: Option, + max_runtime_seconds: u64, + planning_request_id: &str, +) -> Result { + let service = epiphany_core::EpiphanyCoordinatorService::new(runtime_store); + let state = service + .state()? + .ok_or_else(|| anyhow!("cannot launch Imagination without native coordinator state"))?; + let role = epiphany_core::EpiphanyRoleResultRoleId::Imagination; + let context = epiphany_core::render_launch_dynamic_prompt_context( + runtime_store, + local_verse_store, + &state, + epiphany_core::role_launch_context_focus(&state, epiphany_core::epiphany_role_label(role)), + ) + .map_err(anyhow::Error::msg)?; + let mut request = epiphany_core::build_epiphany_role_launch_request_with_dynamic_context( + thread_id, + role, + expected_revision.and_then(|value| u64::try_from(value).ok()), + Some(max_runtime_seconds), + &state, + Some(context), + ) + .map_err(anyhow::Error::msg)?; + request.frontier_planning_request_id = Some(planning_request_id.to_string()); + launch_job_value(&service, thread_id, &state, &request) +} + +fn launch_frontier_mind( + runtime_store: &Path, + thread_id: &str, + expected_revision: Option, + max_runtime_seconds: u64, + mind_request_id: &str, +) -> Result { + let service = epiphany_core::EpiphanyCoordinatorService::new(runtime_store); + let state = service + .state()? + .ok_or_else(|| anyhow!("cannot launch Mind without native coordinator state"))?; + let request = epiphany_core::build_epiphany_frontier_plan_mind_launch_request( + thread_id, + expected_revision.and_then(|value| u64::try_from(value).ok()), + Some(max_runtime_seconds), + &state, + mind_request_id.to_string(), + ) + .map_err(anyhow::Error::msg)?; + launch_job_value(&service, thread_id, &state, &request) +} + +fn launch_job_value( + service: &epiphany_core::EpiphanyCoordinatorService, + thread_id: &str, + state: &epiphany_state_model::EpiphanyThreadState, + request: &epiphany_core::EpiphanyJobLaunchRequest, +) -> Result { + let launched = service.launch_job( + thread_id, + state, + request, + format!("epiphany-heartbeat-launch-{}", Uuid::new_v4()), + Uuid::new_v4().to_string(), + now(), + )?; + Ok(json!({ + "bindingId": launched.binding_id, + "launcherJobId": launched.launcher_job_id, + "backendJobId": launched.backend_job_id, + "revision": launched.epiphany_state.revision, + "state": launched.epiphany_state, + })) +} + fn accept_role( runtime_store: &Path, thread_id: &str, @@ -1823,6 +2028,9 @@ fn is_stop_action(action: &str) -> bool { | "regatherManually" | "reviewModelingResult" | "reviewVerificationResult" + | "reviewFrontierPlanningFailure" + | "waitForImaginationResult" + | "waitForMindPlanResult" ) } diff --git a/epiphany-core/src/bin/epiphany-mvp-status.rs b/epiphany-core/src/bin/epiphany-mvp-status.rs index 44730cda..222f4524 100644 --- a/epiphany-core/src/bin/epiphany-mvp-status.rs +++ b/epiphany-core/src/bin/epiphany-mvp-status.rs @@ -41,6 +41,7 @@ use epiphany_core::recommend_crrc_action; use epiphany_core::recommend_reorientation; use epiphany_core::runtime_has_actionable_eyes_frontier; use epiphany_core::runtime_has_actionable_hands_frontier; +use epiphany_core::runtime_has_actionable_imagination_frontier; use epiphany_core::runtime_job_snapshot; use epiphany_state_model::EpiphanyThreadState; use serde_json::Value; @@ -460,6 +461,12 @@ fn run_native_status(args: &Args, include_auxiliary_status: bool) -> Result Result Result { let (store, _) = crate::runtime_spine::tests::claim_challenge_fixture(root, suffix, "Imagination")?; + assert_eq!( + crate::runtime_repo_frontier_planning_lifecycle(&store)?.stage, + crate::RepoFrontierPlanningLifecycleStage::Ready + ); let planning = crate::select_and_commit_repo_frontier_planning_request( &store, "2026-07-15T09:00:02Z", @@ -1347,6 +1351,10 @@ pub(crate) mod tests { &result.result_id, "2026-07-15T09:00:05Z", )?; + assert_eq!( + crate::runtime_repo_frontier_planning_lifecycle(&store)?.stage, + crate::RepoFrontierPlanningLifecycleStage::MindLaunchReady + ); Ok((store, planning, result, request)) } @@ -1484,6 +1492,10 @@ pub(crate) mod tests { "2026-07-15T09:00:05Z", ) .map_err(|error| anyhow!("commit frontier Mind request: {error}"))?; + assert_eq!( + crate::runtime_repo_frontier_planning_lifecycle(store)?.stage, + crate::RepoFrontierPlanningLifecycleStage::MindLaunchReady + ); let mut cache = coordinator_acceptance_cache(store)?; cache.pull_all_backing_stores()?; let state = cache @@ -2293,6 +2305,10 @@ pub(crate) mod tests { let (store, state, launch, planning) = frontier_planning_launch_fixture(root.path(), "mind-adopt") .map_err(|error| anyhow!("build frontier planning launch fixture: {error}"))?; + assert_eq!( + crate::runtime_repo_frontier_planning_lifecycle(&store)?.stage, + crate::RepoFrontierPlanningLifecycleStage::ImaginationLaunchReady + ); let plan = plan_coordinator_job_launch( &state, &launch, @@ -2309,13 +2325,25 @@ pub(crate) mod tests { "2026-07-15T09:00:03Z".into(), ) .map_err(|error| anyhow!("commit frontier Imagination launch: {error}"))?; + assert_eq!( + crate::runtime_repo_frontier_planning_lifecycle(&store)?.stage, + crate::RepoFrontierPlanningLifecycleStage::ImaginationRunning + ); let result = frontier_planning_result(&planning, "backend-mind-adopt", "2026-07-15T09:00:04Z")?; put_runtime_role_worker_result(&store, &result) .map_err(|error| anyhow!("persist frontier Imagination result: {error}"))?; + assert_eq!( + crate::runtime_repo_frontier_planning_lifecycle(&store)?.stage, + crate::RepoFrontierPlanningLifecycleStage::ImaginationResultReady + ); let mind_result = launch_frontier_mind_result(&store, &result, RepoFrontierPlanDecision::Adopt, "adopt") .map_err(|error| anyhow!("launch frontier Mind result: {error}"))?; + assert_eq!( + crate::runtime_repo_frontier_planning_lifecycle(&store)?.stage, + crate::RepoFrontierPlanningLifecycleStage::MindResultReady + ); let before = runtime_current_repo_model(&store)?.expect("pre-Adopt model"); let mut illicit_item = before @@ -2337,6 +2365,15 @@ pub(crate) mod tests { let decision = commit_repo_frontier_plan_decision(&store, &mind_result.result_id) .map_err(|error| anyhow!("commit frontier plan decision: {error}"))?; + let terminal = crate::runtime_repo_frontier_planning_lifecycle(&store)?; + assert_eq!( + terminal.stage, + crate::RepoFrontierPlanningLifecycleStage::Terminal + ); + assert_eq!( + terminal.decision_id.as_deref(), + Some(decision.decision_id.as_str()) + ); let retry = commit_repo_frontier_plan_decision(&store, &mind_result.result_id) .map_err(|error| anyhow!("replay frontier plan decision: {error}"))?; assert_eq!(retry, decision); @@ -2802,6 +2839,15 @@ pub(crate) mod tests { let before = std::fs::read(&store)?; let before_model = runtime_current_repo_model(&store)?.unwrap(); let receipt = commit_repo_frontier_plan_decision(&store, &mind_result.result_id)?; + let lifecycle = crate::runtime_repo_frontier_planning_lifecycle(&store)?; + assert_eq!( + lifecycle.stage, + crate::RepoFrontierPlanningLifecycleStage::Terminal + ); + assert_eq!( + lifecycle.decision_id.as_deref(), + Some(receipt.decision_id.as_str()) + ); assert!(receipt.model_admission_receipt_id.is_empty()); assert_eq!(runtime_current_repo_model(&store)?.unwrap(), before_model); assert!(select_and_commit_repo_frontier_route(&store, "2026-07-15T09:00:06Z").is_err()); @@ -2814,6 +2860,45 @@ pub(crate) mod tests { Ok(()) } + #[test] + fn frontier_planning_worker_failure_is_not_mistaken_for_running() -> Result<()> { + let root = tempfile::tempdir()?; + let (store, state, launch, planning) = + frontier_planning_launch_fixture(root.path(), "worker-failure")?; + let job_id = "backend-frontier-worker-failure"; + let plan = plan_coordinator_job_launch( + &state, + &launch, + &store, + "launcher-frontier-worker-failure".into(), + job_id.into(), + )?; + commit_coordinator_job_launch( + &store, + &planning.thread_id, + &state, + &launch, + &plan, + "2026-07-15T09:00:03Z".into(), + )?; + let mut failed = frontier_planning_result(&planning, job_id, "2026-07-15T09:00:04Z")?; + failed.frontier_planning_request_id = None; + 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)?; + + let lifecycle = crate::runtime_repo_frontier_planning_lifecycle(&store)?; + assert_eq!( + lifecycle.stage, + crate::RepoFrontierPlanningLifecycleStage::ImaginationFailed + ); + assert_eq!( + lifecycle.imagination_result_id.as_deref(), + Some(failed.result_id.as_str()) + ); + Ok(()) + } + #[test] fn operator_review_uses_current_mind_candidate_and_canonical_terminal_transitions() -> Result<()> { diff --git a/epiphany-core/src/lib.rs b/epiphany-core/src/lib.rs index a5675d37..f58afa78 100644 --- a/epiphany-core/src/lib.rs +++ b/epiphany-core/src/lib.rs @@ -1055,22 +1055,24 @@ pub use runtime_spine::runtime_hands_commit_receipt; pub use runtime_spine::runtime_hands_patch_receipt; pub use runtime_spine::runtime_hands_pr_receipt; pub use runtime_spine::runtime_hands_receipt_chain_after; -pub use runtime_spine::runtime_has_actionable_hands_frontier; pub use runtime_spine::runtime_has_actionable_eyes_frontier; +pub use runtime_spine::runtime_has_actionable_hands_frontier; +pub use runtime_spine::runtime_has_actionable_imagination_frontier; pub use runtime_spine::runtime_hello_frame; pub use runtime_spine::runtime_job_snapshot; pub use runtime_spine::runtime_latest_hands_receipt_chain_after; pub use runtime_spine::runtime_mind_gateway_review; pub use runtime_spine::runtime_mind_state_commit_receipt; -pub use runtime_spine::runtime_repo_model_admission_receipt; -pub use runtime_spine::runtime_repo_model_admission_review; pub use runtime_spine::runtime_modeling_semantic_projection_input; pub use runtime_spine::runtime_registered_document_types; pub use runtime_spine::runtime_reorient_worker_result; +pub use runtime_spine::runtime_repo_frontier_planning_lifecycle; pub use runtime_spine::runtime_repo_frontier_proposal_modeling_request; pub use runtime_spine::runtime_repo_frontier_route; pub use runtime_spine::runtime_repo_frontier_verification_request; pub use runtime_spine::runtime_repo_frontier_work_proposal; +pub use runtime_spine::runtime_repo_model_admission_receipt; +pub use runtime_spine::runtime_repo_model_admission_review; pub use runtime_spine::runtime_role_worker_result; pub use runtime_spine::runtime_schema_catalog_response; pub use runtime_spine::runtime_soul_verdict_receipt; diff --git a/epiphany-core/src/repo_model_gateway.rs b/epiphany-core/src/repo_model_gateway.rs index a3552928..74563951 100644 --- a/epiphany-core/src/repo_model_gateway.rs +++ b/epiphany-core/src/repo_model_gateway.rs @@ -558,6 +558,35 @@ pub enum RepoFrontierPlanDecision { Hold, } +#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub enum RepoFrontierPlanningLifecycleStage { + Unavailable, + Ready, + ImaginationLaunchReady, + ImaginationRunning, + ImaginationFailed, + ImaginationResultReady, + MindLaunchReady, + MindRunning, + MindFailed, + MindResultReady, + Terminal, +} + +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RepoFrontierPlanningLifecycle { + pub stage: RepoFrontierPlanningLifecycleStage, + pub planning_request_id: Option, + pub imagination_job_id: Option, + pub imagination_result_id: Option, + pub mind_request_id: Option, + pub mind_job_id: Option, + pub mind_result_id: Option, + pub decision_id: Option, +} + #[derive(Debug, Clone, PartialEq, Eq, DatabaseEntry)] #[cultcache( type = "epiphany.self.repo_frontier_plan_mind_request", diff --git a/epiphany-core/src/runtime_spine.rs b/epiphany-core/src/runtime_spine.rs index 3831f58f..d9c67b05 100644 --- a/epiphany-core/src/runtime_spine.rs +++ b/epiphany-core/src/runtime_spine.rs @@ -79,7 +79,8 @@ use crate::repo_model_gateway::{ RepoFrontierNextOrgan, RepoFrontierPlanCandidate, RepoFrontierPlanDecision, RepoFrontierPlanDecisionReceipt, RepoFrontierPlanMindDecision, RepoFrontierPlanMindLaunchBinding, RepoFrontierPlanMindRequest, - RepoFrontierPlanningLaunchBinding, RepoFrontierPlanningRequest, + RepoFrontierPlanningLaunchBinding, RepoFrontierPlanningLifecycle, + RepoFrontierPlanningLifecycleStage, RepoFrontierPlanningRequest, RepoFrontierProposalModelingLaunchBinding, RepoFrontierProposalModelingRequest, RepoFrontierRoute, RepoFrontierVerdictDisposition, RepoFrontierWorkProposal, RepoModelAdmissionReceipt, RepoModelAdmissionReview, RepoModelClaimChallenge, @@ -6078,6 +6079,225 @@ pub fn runtime_has_actionable_eyes_frontier(runtime_store: impl AsRef) -> runtime_has_actionable_frontier_for_organ(runtime_store, "Eyes") } +/// Read-only Self signal for proposal planning. It uses the same eligibility +/// predicate as the planning-request committer, including unchallenged target +/// claims, so status cannot advertise authority that the commit path rejects. +pub fn runtime_has_actionable_imagination_frontier( + runtime_store: impl AsRef, +) -> Result { + let runtime_store = runtime_store.as_ref(); + let mut cache = runtime_spine_cache(runtime_store)?; + cache.pull_all_backing_stores()?; + require_identity(&cache)?; + let Some(entry) = cache.get::(crate::MEMORY_GRAPH_KEY)? else { + return Ok(false); + }; + crate::validate_memory_graph_entry(&entry)?; + let model = entry.snapshot()?; + let model_hash = crate::memory_graph_model_hash(&model)?; + let admission_count = cache + .get_all::()? + .into_iter() + .filter(|receipt| { + crate::repo_model_admission_receipt_schema_supported( + &receipt.schema_version, + &receipt.contract, + ) && receipt.admitted_revision == model.model_revision + && receipt.admitted_hash == model_hash + }) + .count(); + let challenges = current_repo_model_claim_challenges(&cache, &model, &model_hash)?; + Ok(admission_count == 1 && actionable_imagination_frontier_item(&model, &challenges).is_some()) +} + +/// Read-only Self projection over the existing typed frontier-planning chain. +/// It never creates a request or decision; each mutating stage remains owned by +/// its established commit primitive. +pub fn runtime_repo_frontier_planning_lifecycle( + runtime_store: impl AsRef, +) -> Result { + let runtime_store = runtime_store.as_ref(); + let mut cache = runtime_spine_cache(runtime_store)?; + cache.pull_all_backing_stores()?; + require_identity(&cache)?; + let empty = |stage| RepoFrontierPlanningLifecycle { + stage, + planning_request_id: None, + imagination_job_id: None, + imagination_result_id: None, + mind_request_id: None, + mind_job_id: None, + mind_result_id: None, + decision_id: None, + }; + let decisions = cache.get_all::()?; + let mut active_requests = Vec::new(); + let mut terminal_current_requests = Vec::new(); + for request in cache.get_all::()? { + if validate_current_repo_frontier_planning_request(&cache, &request).is_ok() { + if let Some(decision) = decisions + .iter() + .find(|decision| decision.planning_request_id == request.request_id) + { + terminal_current_requests.push((request, decision)); + } else { + active_requests.push(request); + } + } + } + active_requests.sort_by(|a, b| { + a.requested_at + .cmp(&b.requested_at) + .then_with(|| a.request_id.cmp(&b.request_id)) + }); + if active_requests.len() > 1 { + return Err(anyhow!( + "Self found multiple nonterminal current frontier planning requests" + )); + } + if terminal_current_requests.len() > 1 { + return Err(anyhow!( + "Self found multiple terminal decisions for current frontier planning authority" + )); + } + let Some(request) = active_requests.pop() else { + if let Some((request, decision)) = terminal_current_requests.pop() { + return Ok(RepoFrontierPlanningLifecycle { + decision_id: Some(decision.decision_id.clone()), + planning_request_id: Some(request.request_id), + ..empty(RepoFrontierPlanningLifecycleStage::Terminal) + }); + } + if runtime_has_actionable_imagination_frontier(runtime_store)? { + return Ok(empty(RepoFrontierPlanningLifecycleStage::Ready)); + } + let latest_terminal = decisions.iter().max_by(|a, b| { + a.decided_at + .cmp(&b.decided_at) + .then_with(|| a.decision_id.cmp(&b.decision_id)) + }); + return Ok(if let Some(decision) = latest_terminal { + RepoFrontierPlanningLifecycle { + decision_id: Some(decision.decision_id.clone()), + planning_request_id: Some(decision.planning_request_id.clone()), + ..empty(RepoFrontierPlanningLifecycleStage::Terminal) + } + } else { + empty(RepoFrontierPlanningLifecycleStage::Unavailable) + }); + }; + let mut lifecycle = RepoFrontierPlanningLifecycle { + stage: RepoFrontierPlanningLifecycleStage::ImaginationLaunchReady, + planning_request_id: Some(request.request_id.clone()), + imagination_job_id: None, + imagination_result_id: None, + mind_request_id: None, + mind_job_id: None, + mind_result_id: None, + decision_id: None, + }; + let imagination_launches = cache + .get_all::()? + .into_iter() + .filter(|binding| binding.planning_request_id == request.request_id) + .collect::>(); + if imagination_launches.len() > 1 { + return Err(anyhow!( + "Self found multiple Imagination launches for one planning request" + )); + } + if let Some(binding) = imagination_launches.first() { + lifecycle.imagination_job_id = Some(binding.job_id.clone()); + } + let imagination_results = cache + .get_all::()? + .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()) + }) + .collect::>(); + if imagination_results.len() > 1 { + return Err(anyhow!( + "Self found multiple immutable Imagination results for one planning request" + )); + } + let Some(imagination_result) = imagination_results.first() else { + if lifecycle.imagination_job_id.is_some() { + lifecycle.stage = RepoFrontierPlanningLifecycleStage::ImaginationRunning; + } + return Ok(lifecycle); + }; + lifecycle.imagination_job_id = Some(imagination_result.job_id.clone()); + lifecycle.imagination_result_id = Some(imagination_result.result_id.clone()); + if imagination_result.frontier_planning_request_id.as_deref() + != Some(request.request_id.as_str()) + { + lifecycle.stage = RepoFrontierPlanningLifecycleStage::ImaginationFailed; + return Ok(lifecycle); + } + let mind_requests = cache + .get_all::()? + .into_iter() + .filter(|mind| mind.imagination_result_id == imagination_result.result_id) + .collect::>(); + if mind_requests.len() > 1 { + return Err(anyhow!( + "Self found multiple Mind requests for one Imagination result" + )); + } + let Some(mind_request) = mind_requests.first() else { + lifecycle.stage = RepoFrontierPlanningLifecycleStage::ImaginationResultReady; + return Ok(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 + .get_all::()? + .into_iter() + .filter(|binding| binding.mind_request_id == mind_request.request_id) + .collect::>(); + if mind_launches.len() > 1 { + return Err(anyhow!( + "Self found multiple Mind launches for one planning request" + )); + } + if let Some(binding) = mind_launches.first() { + lifecycle.mind_job_id = Some(binding.job_id.clone()); + } + let mind_results = cache + .get_all::()? + .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()) + }) + .collect::>(); + if mind_results.len() > 1 { + return Err(anyhow!( + "Self found multiple immutable Mind results for one planning request" + )); + } + let Some(mind_result) = mind_results.first() else { + if lifecycle.mind_job_id.is_some() { + lifecycle.stage = RepoFrontierPlanningLifecycleStage::MindRunning; + } + return Ok(lifecycle); + }; + lifecycle.mind_job_id = Some(mind_result.job_id.clone()); + lifecycle.mind_result_id = Some(mind_result.result_id.clone()); + if mind_result.frontier_plan_mind_request_id.as_deref() + != Some(mind_request.request_id.as_str()) + { + lifecycle.stage = RepoFrontierPlanningLifecycleStage::MindFailed; + return Ok(lifecycle); + } + lifecycle.stage = RepoFrontierPlanningLifecycleStage::MindResultReady; + Ok(lifecycle) +} + fn runtime_has_actionable_frontier_for_organ( runtime_store: impl AsRef, organ: &str, @@ -6105,13 +6325,8 @@ fn runtime_has_actionable_frontier_for_organ( .count(); let challenges = current_repo_model_claim_challenges(&cache, &model, &model_hash)?; Ok(admission_count == 1 - && actionable_frontier_item_for_organ( - &model, - &challenges, - organ, - organ == "Hands", - ) - .is_some()) + && actionable_frontier_item_for_organ(&model, &challenges, organ, organ == "Hands") + .is_some()) } pub fn put_runtime_reorient_worker_result( @@ -6683,10 +6898,7 @@ pub fn put_repo_frontier_verification_request( || command.runtime_job_id != intent.runtime_job_id || commit.runtime_job_id != intent.runtime_job_id || patch.changed_paths != commit.changed_paths - || !consequence_paths_within_authority( - &patch.changed_paths, - &authority.requested_paths, - ) + || !consequence_paths_within_authority(&patch.changed_paths, &authority.requested_paths) || !adopted_plan_consequence_is_exact { return Err(anyhow!( diff --git a/epiphany-core/src/surfaces/coordinator.rs b/epiphany-core/src/surfaces/coordinator.rs index 609cf797..92963fb9 100644 --- a/epiphany-core/src/surfaces/coordinator.rs +++ b/epiphany-core/src/surfaces/coordinator.rs @@ -7,6 +7,7 @@ use super::EpiphanyReorientAction; use super::EpiphanyReorientFindingInterpretation; use super::EpiphanyRoleBoardLane; use super::EpiphanyRoleFindingInterpretation; +use crate::RepoFrontierPlanningLifecycleStage; use epiphany_state_model::EpiphanyThreadState; use serde::Deserialize; use serde::Serialize; @@ -67,6 +68,14 @@ pub enum EpiphanyCoordinatorAction { ReviewVerificationResult, ContinueImplementation, AwaitFrontierProposal, + StartFrontierPlanning, + LaunchImagination, + WaitForImaginationResult, + RequestMindPlanReview, + LaunchMindPlanReview, + WaitForMindPlanResult, + CommitFrontierPlanDecision, + ReviewFrontierPlanningFailure, } #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] @@ -156,6 +165,9 @@ pub struct EpiphanyCoordinatorInput { /// True only when the canonical runtime RepoModel has exactly one current /// admission and an Active, dependency-ready Eyes frontier item. pub eyes_frontier_ready: bool, + /// Read-only projection of the single typed Imagination -> Mind planning + /// lifecycle. Self may advance it, but only Mind's result can decide adoption. + pub frontier_planning_stage: RepoFrontierPlanningLifecycleStage, } #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] @@ -201,6 +213,7 @@ pub struct EpiphanyCoordinatorStatusInput { pub reorient_finding_accepted: bool, pub hands_frontier_ready: bool, pub eyes_frontier_ready: bool, + pub frontier_planning_stage: RepoFrontierPlanningLifecycleStage, } #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] @@ -304,6 +317,7 @@ pub fn derive_coordinator_status( reorient_finding_accepted: input.reorient_finding_accepted, hands_frontier_ready: input.hands_frontier_ready, eyes_frontier_ready: input.eyes_frontier_ready, + frontier_planning_stage: input.frontier_planning_stage, }); EpiphanyCoordinatorStatus { decision, @@ -786,6 +800,101 @@ pub fn recommend_coordinator_action( ); } + match input.frontier_planning_stage { + RepoFrontierPlanningLifecycleStage::Ready => { + return build( + EpiphanyCoordinatorAction::StartFrontierPlanning, + Some(EpiphanyCoordinatorRoleId::Imagination), + None, + false, + true, + "Mind has admitted one actionable Imagination frontier; commit its typed planning request before launching a worker.", + ); + } + RepoFrontierPlanningLifecycleStage::ImaginationLaunchReady => { + return build( + EpiphanyCoordinatorAction::LaunchImagination, + Some(EpiphanyCoordinatorRoleId::Imagination), + Some(EpiphanyCoordinatorSceneAction::RoleLaunch), + false, + true, + "A current frontier planning request is committed; launch Imagination against that exact authority.", + ); + } + RepoFrontierPlanningLifecycleStage::ImaginationRunning => { + return build( + EpiphanyCoordinatorAction::WaitForImaginationResult, + Some(EpiphanyCoordinatorRoleId::Imagination), + Some(EpiphanyCoordinatorSceneAction::RoleResult), + false, + false, + "The frontier-bound Imagination worker is running; wait for its typed result.", + ); + } + RepoFrontierPlanningLifecycleStage::ImaginationFailed => { + return build( + EpiphanyCoordinatorAction::ReviewFrontierPlanningFailure, + Some(EpiphanyCoordinatorRoleId::Imagination), + Some(EpiphanyCoordinatorSceneAction::RoleResult), + true, + false, + "The frontier-bound Imagination worker terminated without a valid typed candidate; review the immutable failure before creating new authority.", + ); + } + RepoFrontierPlanningLifecycleStage::ImaginationResultReady => { + return build( + EpiphanyCoordinatorAction::RequestMindPlanReview, + None, + None, + false, + true, + "Imagination produced a typed frontier plan; commit the dedicated Mind review request without adopting it.", + ); + } + RepoFrontierPlanningLifecycleStage::MindLaunchReady => { + return build( + EpiphanyCoordinatorAction::LaunchMindPlanReview, + None, + Some(EpiphanyCoordinatorSceneAction::RoleLaunch), + false, + true, + "The typed Mind review request is committed; launch the dedicated admission reviewer.", + ); + } + RepoFrontierPlanningLifecycleStage::MindRunning => { + return build( + EpiphanyCoordinatorAction::WaitForMindPlanResult, + None, + Some(EpiphanyCoordinatorSceneAction::RoleResult), + false, + false, + "Mind is reviewing the proposed frontier plan; wait for its typed decision result.", + ); + } + RepoFrontierPlanningLifecycleStage::MindFailed => { + return build( + EpiphanyCoordinatorAction::ReviewFrontierPlanningFailure, + None, + Some(EpiphanyCoordinatorSceneAction::RoleResult), + true, + false, + "The dedicated Mind reviewer terminated without a valid typed judgment; review the immutable failure before any plan decision.", + ); + } + RepoFrontierPlanningLifecycleStage::MindResultReady => { + return build( + EpiphanyCoordinatorAction::CommitFrontierPlanDecision, + None, + None, + false, + true, + "Mind returned a typed frontier-plan judgment; atomically commit that decision as the sole adoption authority.", + ); + } + RepoFrontierPlanningLifecycleStage::Unavailable + | RepoFrontierPlanningLifecycleStage::Terminal => {} + } + if input.signals.research_result_status == EpiphanyCoordinatorRoleResultStatus::Completed && !input.research_result_accepted { @@ -1273,7 +1382,15 @@ pub fn coordinator_automation_action( | EpiphanyCoordinatorAction::LaunchVerification | EpiphanyCoordinatorAction::ReviewVerificationResult | EpiphanyCoordinatorAction::ContinueImplementation - | EpiphanyCoordinatorAction::AwaitFrontierProposal => { + | EpiphanyCoordinatorAction::AwaitFrontierProposal + | EpiphanyCoordinatorAction::StartFrontierPlanning + | EpiphanyCoordinatorAction::LaunchImagination + | EpiphanyCoordinatorAction::WaitForImaginationResult + | EpiphanyCoordinatorAction::RequestMindPlanReview + | EpiphanyCoordinatorAction::LaunchMindPlanReview + | EpiphanyCoordinatorAction::WaitForMindPlanResult + | EpiphanyCoordinatorAction::CommitFrontierPlanDecision + | EpiphanyCoordinatorAction::ReviewFrontierPlanningFailure => { EpiphanyCoordinatorAutomationAction::None } } @@ -1380,6 +1497,78 @@ mod tests { reorient_finding_accepted: false, hands_frontier_ready: false, eyes_frontier_ready: false, + frontier_planning_stage: RepoFrontierPlanningLifecycleStage::Unavailable, + } + } + + #[test] + fn typed_frontier_planning_lifecycle_preempts_generic_regather() { + let cases = [ + ( + RepoFrontierPlanningLifecycleStage::Ready, + EpiphanyCoordinatorAction::StartFrontierPlanning, + Some(EpiphanyCoordinatorRoleId::Imagination), + true, + ), + ( + RepoFrontierPlanningLifecycleStage::ImaginationLaunchReady, + EpiphanyCoordinatorAction::LaunchImagination, + Some(EpiphanyCoordinatorRoleId::Imagination), + true, + ), + ( + RepoFrontierPlanningLifecycleStage::ImaginationRunning, + EpiphanyCoordinatorAction::WaitForImaginationResult, + Some(EpiphanyCoordinatorRoleId::Imagination), + false, + ), + ( + RepoFrontierPlanningLifecycleStage::ImaginationFailed, + EpiphanyCoordinatorAction::ReviewFrontierPlanningFailure, + Some(EpiphanyCoordinatorRoleId::Imagination), + false, + ), + ( + RepoFrontierPlanningLifecycleStage::ImaginationResultReady, + EpiphanyCoordinatorAction::RequestMindPlanReview, + None, + true, + ), + ( + RepoFrontierPlanningLifecycleStage::MindLaunchReady, + EpiphanyCoordinatorAction::LaunchMindPlanReview, + None, + true, + ), + ( + RepoFrontierPlanningLifecycleStage::MindRunning, + EpiphanyCoordinatorAction::WaitForMindPlanResult, + None, + false, + ), + ( + RepoFrontierPlanningLifecycleStage::MindFailed, + EpiphanyCoordinatorAction::ReviewFrontierPlanningFailure, + None, + false, + ), + ( + RepoFrontierPlanningLifecycleStage::MindResultReady, + EpiphanyCoordinatorAction::CommitFrontierPlanDecision, + None, + true, + ), + ]; + + for (stage, expected_action, expected_role, can_auto_run) in cases { + let decision = recommend_coordinator_action(EpiphanyCoordinatorInput { + recommendation: recommendation(EpiphanyCrrcAction::RegatherManually), + frontier_planning_stage: stage, + ..input() + }); + assert_eq!(decision.action, expected_action); + assert_eq!(decision.target_role, expected_role); + assert_eq!(decision.can_auto_run, can_auto_run); } } diff --git a/notes/epiphany-current-algorithmic-map.md b/notes/epiphany-current-algorithmic-map.md index 877d46bb..60164caa 100644 --- a/notes/epiphany-current-algorithmic-map.md +++ b/notes/epiphany-current-algorithmic-map.md @@ -1140,9 +1140,18 @@ persists its launch binding. `commit_repo_frontier_plan_mind_request` binds the immutable Imagination result and candidate to a dedicated Mind request; `EPIPHANY_MIND_ROLE_BINDING_ID` owns that review launch. `commit_repo_frontier_plan_decision` then revalidates the entire causal chain and -atomically adopts or refuses it against the current model. The MVP coordinator -does not yet route these stages. Therefore the missing authority is Self -orchestration, not another planning store, generic role patch, or adapter. +atomically adopts or refuses it against the current model. + +Self now observes this chain through +`runtime_repo_frontier_planning_lifecycle`, a read-only projection whose stages +are derived from the canonical request, launch bindings, immutable worker +results, Mind request, and decision receipt. The MVP coordinator advances each +stage only through the established commit primitive: select planning, launch +exclusive Imagination, request Mind review, launch the dedicated reviewer, and +commit Mind's decision. Failed Imagination or Mind jobs become explicit review +stages rather than remaining indistinguishable from running jobs. A terminal +Hold or Refuse suppresses immediate replanning of the same current authority. +This code path is locally proven but still requires exact packaged live proof. The autonomous proposal crossing is source-grounded in `runtime_spine.rs`, `admitted_model_direction_consideration.rs`, diff --git a/notes/fresh-workspace-handoff.md b/notes/fresh-workspace-handoff.md index d8812f57..7a6ed513 100644 --- a/notes/fresh-workspace-handoff.md +++ b/notes/fresh-workspace-handoff.md @@ -158,22 +158,28 @@ v22 is a preserved routing-deadlock witness: an explicitly selected corrective proposal could not preempt the failed verdict-incorporation route. Do not grind or mutate v22. -Eyes, Imagination, Persona consequence, Continuity crash/restart/closure, +Eyes, live packaged Imagination, Persona consequence, Continuity crash/restart/closure, retention, long-duration resource behavior, and Linux/Yggdrasil cognition are still unproven. ## Next action -Keep v23 live and v22 sealed as the deadlock witness. Wire native packaged Self -through the existing typed Imagination lifecycle: frontier planning selection, -exclusive Imagination launch, result review, dedicated Mind decision launch, -and atomic adoption/refusal. Do not create a second planning substrate. +Keep v23 live and v22 sealed as the deadlock witness. The local implementation +now gives packaged Self a read-only typed lifecycle projection plus explicit MVP +actions for planning selection, exclusive Imagination launch, Mind review +request/launch, and atomic decision commit. The full adoption timeline, +Hold/Refuse terminal behavior, worker failure projection, all 19 coordinator +tests, and all 14 MVP coordinator tests pass. Commit and package this pass, then +create legitimate live Imagination pressure through the existing proposal and +proposal-Modeling path. Prove the exact package advances v23 through Imagination +and dedicated Mind without overrides or a second planning substrate. ## Immediate re-entry 1. Run `cargo run --manifest-path .\epiphany-core\Cargo.toml --bin epiphany-state -- status`. 2. Read `state/map.yaml` and this handoff. -3. Confirm git HEAD and the exact 6f019cf8 published witness above. +3. Confirm git HEAD, the exact 6f019cf8 published witness above, and whether the + native Imagination implementation has been committed and packaged. 4. Treat v22 as evidence, not active authority. Replace this document when state changes. Old attempts belong in evidence and diff --git a/state/map.yaml b/state/map.yaml index 04545fb5..ba22896a 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -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. Fresh v23 completed the typed proposal-to-Mind-to-Hands-to-Soul-to-Modeling circuit and accepted an Eyes packet from a challenged frontier. Exact 148d4527 proved packaged Self derives routing status in-process with heartbeat, Persona, and Void projections omitted. Exact 6f019cf8 proved the single-use Research-to-Modeling route: packaged Self launched Modeling from accepted Eyes context without borrowing the obsolete Soul frontier route, Mind accepted the first valid result, modelingResultAcceptedAfterResearch became true, and repeated Self steps did not relaunch it. The accepted Modeling result retained the honest source wound: current-body non-bypass release-auth enforcement is still ungrounded. Native Imagination routing is now the active build target; Persona consequence, Continuity recovery, retention, long-duration pacing, and Linux/Yggdrasil cognition remain open. + summary: Epiphany is a supervised engineering alpha on Starfire, not deployment-ready. Fresh v23 completed the typed proposal-to-Mind-to-Hands-to-Soul-to-Modeling circuit and accepted an Eyes packet from a challenged frontier. Exact 148d4527 proved packaged Self derives routing status in-process with heartbeat, Persona, and Void projections omitted. Exact 6f019cf8 proved the single-use Research-to-Modeling route. Native Self/MVP Imagination orchestration is now implemented locally as a typed read-only lifecycle over the existing planning, launch, result, Mind-request, and decision receipts. Focused adoption, Hold/Refuse, failure, coordinator, and MVP tests pass; exact packaged live proof remains open. Persona consequence, Continuity recovery, retention, long-duration pacing, and Linux/Yggdrasil cognition remain open. operational_state: - local_worktree: state_refresh_after_exact_6f019cf8_live_proof + local_worktree: native_imagination_orchestration_implemented_uncommitted 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: v23 holds accepted Eyes, reorientation, and causal Modeling evidence. The packet grounds topology fail-closure and the authenticated 2dd25341 Hands receipt, but not the current-body enforcement path that makes release authentication non-bypassable; the accepted Modeling result correctly preserved that wound. Exact 6f019cf8 closes the Research-to-Modeling routing gap. Native Imagination routing, Persona consequence, Continuity crash/restart/closure, retention, long-duration behavior, and Linux/Yggdrasil cognition remain open. - next_action: Wire the existing typed Imagination frontier-planning lifecycle into packaged Self/MVP orchestration: select the current actionable Imagination frontier, launch the exclusive typed Imagination request, review its result, launch the dedicated Mind decision worker, and atomically adopt or reject through the existing decision primitive. Do not invent a parallel planning store or relaunch the sealed Eyes work. Preserve v22 and retain ea475aac/84f00929 as release-integrity witnesses. + unresolved_authority: v23 holds accepted Eyes, reorientation, and causal Modeling evidence. The packet grounds topology fail-closure and the authenticated 2dd25341 Hands receipt, but not the current-body enforcement path that makes release authentication non-bypassable; the accepted Modeling result correctly preserved that wound. Exact 6f019cf8 closes the Research-to-Modeling routing gap. Native Imagination orchestration is implemented but not yet proven from an exact authenticated package on live v23. Persona consequence, Continuity crash/restart/closure, retention, long-duration behavior, and Linux/Yggdrasil cognition remain open. + next_action: Commit and package the native Imagination lifecycle pass, publish its authenticated release, then create legitimate v23 Imagination pressure through the existing typed proposal and proposal-Modeling path. Run packaged Self without overrides and prove planning selection, exclusive Imagination launch, dedicated Mind review, and atomic terminal decision. Do not create a new store or mutate v22. active_subgoals: - Prove Persona, Self, Eyes, Modeling, Imagination, Hands, Soul, Mind, Continuity, and nervous-system behavior individually. @@ -63,10 +63,10 @@ active_subgoals: organ_readiness: persona: partial; authenticated feedback transport is live, but public cognition and speech consequence still need a fresh end-to-end proof. - self: partial; proposal recovery, Mind admission, Hands routing, Soul routing, verdict incorporation, proposal preemption, challenge-aware Eyes routing, in-process status ownership, and single-use Research-to-Modeling routing are live. Native Imagination orchestration is pending. + self: partial; proposal recovery, Mind admission, Hands routing, Soul routing, verdict incorporation, proposal preemption, challenge-aware Eyes routing, in-process status ownership, and single-use Research-to-Modeling routing are live. Native Imagination orchestration is locally implemented and test-proven; packaged live proof is pending. eyes: proven for one bounded challenged-claim circuit; exact 84f00929 launched Research and Mind accepted the first source-gap packet with typed evidence/checkpoint, exact 148d4527 accepted its causal reorientation, and exact 6f019cf8 proved downstream Modeling consumption. modeling: proven for the current bounded circuit; proposal-bound source inspection, Mind admission, exact routed identity preservation, and first-valid verdict incorporation completed without retry churn. Broader Body-map coverage remains open. - imagination: unproven in the current campaign; the planning substrate is empty. + imagination: unproven live in the current campaign; the typed lifecycle and MVP route are locally implemented, while v23 still needs legitimate proposal-derived planning pressure. hands: proven for bounded consequences; native patch, command, commit, push, and typed receipts bind reviewed path ceilings to exact changed-path subsets. soul: proven for the current bounded consequence; the exact 2dd25341 release launched Soul, produced an accepted pass verdict grounded in focused and full-library receipts, and routed verdict incorporation. mind: partial; RepoModel admission, thread-state admission, gateway review, state commit, and first-valid verdict incorporation are live; broader stale or overstated frontier correction remains open.