Use typed freshness for reorient policy

This commit is contained in:
Meta Vens 2026-05-19 16:58:37 +01:00
commit 5551e35c18
4 changed files with 48 additions and 34 deletions

View file

@ -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,

View file

@ -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<EpiphanyFreshnessWatcherSnapshot<'_>>,
token_usage_info: Option<&EpiphanyTokenUsageSnapshot>,
) -> BridgeResult<EpiphanyReorientLaunchApplied> {
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!(

View file

@ -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,
}
}

View file

@ -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)
};