From 263ed87738991b2b801081b9fe166204a6e9fa81 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sat, 11 Jul 2026 19:05:05 +0100 Subject: [PATCH] Move result snapshot selection into core --- epiphany-codex-bridge/src/runtime_results.rs | 56 +--------- epiphany-core/src/coordinator_service.rs | 104 +++++++++++++++++++ epiphany-core/src/lib.rs | 2 + notes/fresh-workspace-handoff.md | 7 +- state/ledgers.msgpack | Bin 398976 -> 399217 bytes 5 files changed, 113 insertions(+), 56 deletions(-) diff --git a/epiphany-codex-bridge/src/runtime_results.rs b/epiphany-codex-bridge/src/runtime_results.rs index f5648a54..7774f131 100644 --- a/epiphany-codex-bridge/src/runtime_results.rs +++ b/epiphany-codex-bridge/src/runtime_results.rs @@ -39,30 +39,7 @@ pub async fn load_core_epiphany_role_result_snapshot( role_id: EpiphanyRoleResultRoleId, binding_id: &str, ) -> EpiphanyRoleResultSnapshot { - if let Some(link) = latest_epiphany_runtime_link_for_binding(state, binding_id) { - return load_core_epiphany_role_result_from_runtime_spine_job( - link.runtime_job_id.as_str(), - runtime_store_path, - role_id, - ); - } - - if !state - .job_bindings - .iter() - .any(|binding| binding.id == binding_id) - { - return EpiphanyRoleResultSnapshot { - status: CoreEpiphanyCoordinatorRoleResultStatus::MissingBinding, - finding: None, - note: "No matching Epiphany role specialist binding exists.".to_string(), - }; - } - EpiphanyRoleResultSnapshot { - status: CoreEpiphanyCoordinatorRoleResultStatus::BackendUnavailable, - finding: None, - note: "Role binding has no runtime-spine job id; launch a runtime-linked role worker for typed results.".to_string(), - } + epiphany_core::read_role_result_snapshot(Some(state), runtime_store_path, role_id, binding_id) } pub fn load_completed_core_epiphany_role_finding( @@ -120,36 +97,7 @@ pub async fn load_core_epiphany_reorient_result_snapshot( runtime_store_path: Option<&Path>, binding_id: &str, ) -> EpiphanyReorientResultSnapshot { - let Some(state) = state else { - return EpiphanyReorientResultSnapshot { - status: CoreEpiphanyCrrcResultStatus::MissingState, - finding: None, - note: "No authoritative Epiphany state exists for this thread.".to_string(), - }; - }; - if let Some(link) = latest_epiphany_runtime_link_for_binding(state, binding_id) { - return load_core_epiphany_reorient_result_from_runtime_spine_job( - link.runtime_job_id.as_str(), - runtime_store_path, - ); - } - - if !state - .job_bindings - .iter() - .any(|binding| binding.id == binding_id) - { - return EpiphanyReorientResultSnapshot { - status: CoreEpiphanyCrrcResultStatus::MissingBinding, - finding: None, - note: "No matching Epiphany reorientation worker binding exists.".to_string(), - }; - } - EpiphanyReorientResultSnapshot { - status: CoreEpiphanyCrrcResultStatus::BackendUnavailable, - finding: None, - note: "Reorientation binding has no runtime-spine job id; launch a runtime-linked reorient worker for typed results.".to_string(), - } + epiphany_core::read_reorient_result_snapshot(state, runtime_store_path, binding_id) } pub fn load_completed_core_epiphany_reorient_finding( diff --git a/epiphany-core/src/coordinator_service.rs b/epiphany-core/src/coordinator_service.rs index 740abac0..420f108c 100644 --- a/epiphany-core/src/coordinator_service.rs +++ b/epiphany-core/src/coordinator_service.rs @@ -80,6 +80,32 @@ impl EpiphanyCoordinatorService { load_thread_state(&self.thread_state_store) } + pub fn role_result( + &self, + role_id: EpiphanyRoleResultRoleId, + binding_id: &str, + ) -> Result { + let state = self.state()?; + Ok(read_role_result_snapshot( + state.as_ref(), + Some(&self.runtime_spine_store), + role_id, + binding_id, + )) + } + + pub fn reorient_result( + &self, + binding_id: &str, + ) -> Result { + let state = self.state()?; + Ok(read_reorient_result_snapshot( + state.as_ref(), + Some(&self.runtime_spine_store), + binding_id, + )) + } + pub fn apply_state_update( &self, thread_id: &str, @@ -101,6 +127,84 @@ impl EpiphanyCoordinatorService { } } +pub fn read_role_result_snapshot( + state: Option<&EpiphanyThreadState>, + runtime_store_path: Option<&Path>, + role_id: EpiphanyRoleResultRoleId, + binding_id: &str, +) -> EpiphanyCoordinatorRoleResultSnapshot { + let Some(state) = state else { + return role_snapshot( + role_id, + EpiphanyCoordinatorRoleResultStatus::MissingState, + None, + None, + ); + }; + if let Some(link) = latest_runtime_link(state, binding_id) { + return read_runtime_role_result(runtime_store_path, &link.runtime_job_id, role_id); + } + if state + .job_bindings + .iter() + .any(|binding| binding.id == binding_id) + { + role_snapshot( + role_id, + EpiphanyCoordinatorRoleResultStatus::BackendUnavailable, + None, + Some( + "Role binding has no runtime-spine job id; launch a runtime-linked role worker for typed results.", + ), + ) + } else { + role_snapshot( + role_id, + EpiphanyCoordinatorRoleResultStatus::MissingBinding, + None, + None, + ) + } +} + +pub fn read_reorient_result_snapshot( + state: Option<&EpiphanyThreadState>, + runtime_store_path: Option<&Path>, + binding_id: &str, +) -> EpiphanyCoordinatorReorientResultSnapshot { + let Some(state) = state else { + return reorient_snapshot(EpiphanyCrrcResultStatus::MissingState, None, None); + }; + if let Some(link) = latest_runtime_link(state, binding_id) { + return read_runtime_reorient_result(runtime_store_path, &link.runtime_job_id); + } + if state + .job_bindings + .iter() + .any(|binding| binding.id == binding_id) + { + reorient_snapshot( + EpiphanyCrrcResultStatus::BackendUnavailable, + None, + Some( + "Reorientation binding has no runtime-spine job id; launch a runtime-linked reorient worker for typed results.", + ), + ) + } else { + reorient_snapshot(EpiphanyCrrcResultStatus::MissingBinding, None, None) + } +} + +fn latest_runtime_link<'a>( + state: &'a EpiphanyThreadState, + binding_id: &str, +) -> Option<&'a epiphany_state_model::EpiphanyRuntimeLink> { + state + .runtime_links + .iter() + .find(|link| link.binding_id == binding_id && !link.runtime_job_id.trim().is_empty()) +} + pub fn read_runtime_role_result( runtime_store_path: Option<&Path>, job_id: &str, diff --git a/epiphany-core/src/lib.rs b/epiphany-core/src/lib.rs index 30404e33..dba52b4a 100644 --- a/epiphany-core/src/lib.rs +++ b/epiphany-core/src/lib.rs @@ -124,6 +124,8 @@ pub use coordinator_service::EpiphanyCoordinatorRoleResultSnapshot; pub use coordinator_service::EpiphanyCoordinatorService; pub use coordinator_service::EpiphanyCoordinatorStateApplied; pub use coordinator_service::apply_coordinator_state_update_to_state; +pub use coordinator_service::read_reorient_result_snapshot; +pub use coordinator_service::read_role_result_snapshot; pub use coordinator_service::read_runtime_reorient_result; pub use coordinator_service::read_runtime_role_result; pub use cultcache_rs::CacheBackingStore; diff --git a/notes/fresh-workspace-handoff.md b/notes/fresh-workspace-handoff.md index 30975b1c..76b2cc27 100644 --- a/notes/fresh-workspace-handoff.md +++ b/notes/fresh-workspace-handoff.md @@ -657,8 +657,11 @@ cancelled finding projection, and operator note rendering no longer belong to `epiphany-codex-bridge::runtime_results`. The bridge retains compatibility type aliases and delegates job readback to core. Native coordinator tests and all eight bridge library tests pass, including typed-result enforcement and failed -lifecycle projection. Binding selection and acceptance choreography still live -in the bridge and remain the next extraction seam. +lifecycle projection. Binding selection for role/reorientation result readback +now also lives in core and the concrete service exposes `role_result` and +`reorient_result` over its canonical thread-state/runtime-spine stores. The +bridge delegates snapshot selection. Completed-finding acceptance choreography +and launch still live in the bridge and remain the next extraction seam. Bridge identity correction from 2026-06-22: Epiphany owns swarm execution, repo Body work, branch-local lanes, memory, evidence, and Persona cognition. diff --git a/state/ledgers.msgpack b/state/ledgers.msgpack index 9731bd8cb98a73b48914481fb962760a936aa690..27681ed817167e5fc24ab000ff5675f75c34aa99 100644 GIT binary patch delta 232 zcmZozEAeri#0E)5E>kN5lc-}1Y+`