diff --git a/epiphany-codex-bridge/src/coordinator.rs b/epiphany-codex-bridge/src/coordinator.rs index 437438e3..03bb0c9e 100644 --- a/epiphany-codex-bridge/src/coordinator.rs +++ b/epiphany-codex-bridge/src/coordinator.rs @@ -68,7 +68,7 @@ use crate::mutation::epiphany_modeling_finding_has_reviewable_state_patch; use crate::pressure::derive_epiphany_pressure; use crate::pressure::map_epiphany_pressure; use crate::reorient::EpiphanyFreshnessWatcherSnapshot; -use crate::reorient::map_epiphany_freshness; +use crate::reorient::derive_epiphany_freshness_view; use crate::reorient::map_epiphany_reorient; use crate::runtime_results::load_epiphany_reorient_result_snapshot; use crate::runtime_results::load_epiphany_role_result_snapshot; @@ -404,15 +404,20 @@ pub struct EpiphanyCoordinatorAutomationVerdict { pub async fn select_epiphany_coordinator_automation( input: EpiphanyCoordinatorAutomationInput<'_>, ) -> EpiphanyCoordinatorAutomationVerdict { - let (_state_revision, retrieval, graph, watcher) = map_epiphany_freshness( + let core_freshness = derive_epiphany_freshness_view( Some(input.state), Some(input.retrieval_override), Some(input.watcher_snapshot), ); let core_pressure = derive_epiphany_pressure(input.token_usage_info); let pressure = map_epiphany_pressure(input.token_usage_info); - let (state_status, reorient_decision) = - map_epiphany_reorient(Some(input.state), &core_pressure, &retrieval, &graph, &watcher); + let (state_status, reorient_decision) = map_epiphany_reorient( + Some(input.state), + &core_pressure, + &core_freshness.retrieval, + &core_freshness.graph, + &core_freshness.watcher, + ); if state_status != ThreadEpiphanyReorientStateStatus::Ready { return EpiphanyCoordinatorAutomationVerdict { action: EpiphanyCoordinatorAutomationAction::None, diff --git a/epiphany-codex-bridge/src/mutation_service.rs b/epiphany-codex-bridge/src/mutation_service.rs index 14f7943d..b98f8656 100644 --- a/epiphany-codex-bridge/src/mutation_service.rs +++ b/epiphany-codex-bridge/src/mutation_service.rs @@ -52,7 +52,7 @@ use crate::mutation::state_update_from_thread_patch; use crate::mutation::thread_epiphany_patch_has_state_replacements; use crate::pressure::derive_epiphany_pressure; use crate::reorient::EpiphanyFreshnessWatcherSnapshot; -use crate::reorient::map_epiphany_freshness; +use crate::reorient::derive_epiphany_freshness_view; use crate::reorient::map_epiphany_reorient; use crate::runtime_results::load_completed_epiphany_reorient_finding; use crate::runtime_results::load_completed_epiphany_role_finding; @@ -580,11 +580,16 @@ pub async fn launch_thread_epiphany_reorient( watcher_snapshot: Option>, token_usage_info: Option<&EpiphanyTokenUsageSnapshot>, ) -> BridgeResult { - let (state_revision, retrieval, graph, watcher) = - map_epiphany_freshness(state, retrieval_override, watcher_snapshot); + let freshness = derive_epiphany_freshness_view(state, retrieval_override, watcher_snapshot); + let state_revision = freshness.state_revision; let pressure = derive_epiphany_pressure(token_usage_info); - let (state_status, decision) = - map_epiphany_reorient(state, &pressure, &retrieval, &graph, &watcher); + let (state_status, decision) = map_epiphany_reorient( + state, + &pressure, + &freshness.retrieval, + &freshness.graph, + &freshness.watcher, + ); let state = state.ok_or_else(|| { EpiphanyBridgeError::InvalidRequest(format!( diff --git a/epiphany-codex-bridge/src/reorient.rs b/epiphany-codex-bridge/src/reorient.rs index 31beeb2a..1c2cd2ba 100644 --- a/epiphany-codex-bridge/src/reorient.rs +++ b/epiphany-codex-bridge/src/reorient.rs @@ -165,9 +165,9 @@ fn map_core_epiphany_invalidation_input( pub fn map_epiphany_reorient( state: Option<&EpiphanyThreadState>, pressure: &EpiphanyPressure, - retrieval: &ThreadEpiphanyRetrievalFreshness, - graph: &ThreadEpiphanyGraphFreshness, - watcher: &ThreadEpiphanyInvalidationInput, + retrieval: &CoreEpiphanyRetrievalFreshness, + graph: &CoreEpiphanyGraphFreshness, + watcher: &CoreEpiphanyInvalidationInput, ) -> ( ThreadEpiphanyReorientStateStatus, ThreadEpiphanyReorientDecision, @@ -205,40 +205,40 @@ fn map_core_reorient_pressure_level( } fn map_core_reorient_retrieval_status( - status: ThreadEpiphanyRetrievalFreshnessStatus, + status: CoreEpiphanyRetrievalFreshnessStatus, ) -> CoreEpiphanyReorientFreshnessStatus { match status { - ThreadEpiphanyRetrievalFreshnessStatus::Missing - | ThreadEpiphanyRetrievalFreshnessStatus::Unavailable => { + CoreEpiphanyRetrievalFreshnessStatus::Missing + | CoreEpiphanyRetrievalFreshnessStatus::Unavailable => { CoreEpiphanyReorientFreshnessStatus::Unknown } - ThreadEpiphanyRetrievalFreshnessStatus::Ready => CoreEpiphanyReorientFreshnessStatus::Clean, - ThreadEpiphanyRetrievalFreshnessStatus::Stale => CoreEpiphanyReorientFreshnessStatus::Stale, - ThreadEpiphanyRetrievalFreshnessStatus::Indexing => { + CoreEpiphanyRetrievalFreshnessStatus::Ready => CoreEpiphanyReorientFreshnessStatus::Clean, + CoreEpiphanyRetrievalFreshnessStatus::Stale => CoreEpiphanyReorientFreshnessStatus::Stale, + CoreEpiphanyRetrievalFreshnessStatus::Indexing => { CoreEpiphanyReorientFreshnessStatus::Dirty } } } fn map_core_reorient_graph_status( - status: ThreadEpiphanyGraphFreshnessStatus, + status: CoreEpiphanyGraphFreshnessStatus, ) -> CoreEpiphanyReorientFreshnessStatus { match status { - ThreadEpiphanyGraphFreshnessStatus::Missing => CoreEpiphanyReorientFreshnessStatus::Unknown, - ThreadEpiphanyGraphFreshnessStatus::Ready => CoreEpiphanyReorientFreshnessStatus::Clean, - ThreadEpiphanyGraphFreshnessStatus::Stale => CoreEpiphanyReorientFreshnessStatus::Stale, + CoreEpiphanyGraphFreshnessStatus::Missing => CoreEpiphanyReorientFreshnessStatus::Unknown, + CoreEpiphanyGraphFreshnessStatus::Ready => CoreEpiphanyReorientFreshnessStatus::Clean, + CoreEpiphanyGraphFreshnessStatus::Stale => CoreEpiphanyReorientFreshnessStatus::Stale, } } fn map_core_reorient_watcher_status( - status: ThreadEpiphanyInvalidationStatus, + status: CoreEpiphanyInvalidationStatus, ) -> CoreEpiphanyReorientFreshnessStatus { match status { - ThreadEpiphanyInvalidationStatus::Unavailable => { + CoreEpiphanyInvalidationStatus::Unavailable => { CoreEpiphanyReorientFreshnessStatus::Unknown } - ThreadEpiphanyInvalidationStatus::Clean => CoreEpiphanyReorientFreshnessStatus::Clean, - ThreadEpiphanyInvalidationStatus::Changed => CoreEpiphanyReorientFreshnessStatus::Changed, + CoreEpiphanyInvalidationStatus::Clean => CoreEpiphanyReorientFreshnessStatus::Clean, + CoreEpiphanyInvalidationStatus::Changed => CoreEpiphanyReorientFreshnessStatus::Changed, } } diff --git a/epiphany-codex-bridge/src/view.rs b/epiphany-codex-bridge/src/view.rs index 5ec1165a..7d2dc268 100644 --- a/epiphany-codex-bridge/src/view.rs +++ b/epiphany-codex-bridge/src/view.rs @@ -28,7 +28,6 @@ use crate::pressure::derive_epiphany_pressure; use crate::pressure::map_epiphany_pressure; use crate::reorient::EpiphanyFreshnessWatcherSnapshot; use crate::reorient::derive_epiphany_freshness_view; -use crate::reorient::map_epiphany_freshness; use crate::reorient::map_epiphany_reorient; use crate::runtime_results::load_epiphany_reorient_result_snapshot; use crate::runtime_results::load_epiphany_role_result_snapshot; @@ -179,15 +178,20 @@ pub async fn map_epiphany_view_response( let needs_pressure = epiphany_view_needs_pressure(&lenses); let core_pressure = needs_pressure.then(|| derive_epiphany_pressure(token_usage_info)); let pressure = needs_pressure.then(|| map_epiphany_pressure(token_usage_info)); - let freshness = needs_reorientation_inputs - .then(|| map_epiphany_freshness(state, retrieval_override, watcher_snapshot)); + let core_freshness = needs_reorientation_inputs + .then(|| derive_epiphany_freshness_view(state, retrieval_override, watcher_snapshot)); let (state_revision, reorient_state_status, reorient_decision) = - if let (Some((state_revision, retrieval, graph, watcher)), Some(core_pressure)) = - (freshness.as_ref(), core_pressure.as_ref()) + if let (Some(freshness), Some(core_pressure)) = + (core_freshness.as_ref(), core_pressure.as_ref()) { - let (state_status, decision) = - map_epiphany_reorient(state, core_pressure, retrieval, graph, watcher); - (*state_revision, state_status, Some(decision)) + let (state_status, decision) = map_epiphany_reorient( + state, + core_pressure, + &freshness.retrieval, + &freshness.graph, + &freshness.watcher, + ); + (freshness.state_revision, state_status, Some(decision)) } else { (None, ThreadEpiphanyReorientStateStatus::Missing, None) };