From acd8144f52606562653891ffa9000cd1fb5c5b86 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Tue, 19 May 2026 17:08:10 +0100 Subject: [PATCH] Return typed reorient launch results --- epiphany-codex-bridge/src/cultnet.rs | 7 + epiphany-codex-bridge/src/mutation_service.rs | 20 +-- .../epiphany_mutation_routes.rs | 125 +++++++++++++++++- 3 files changed, 136 insertions(+), 16 deletions(-) diff --git a/epiphany-codex-bridge/src/cultnet.rs b/epiphany-codex-bridge/src/cultnet.rs index f12e4759..25540b00 100644 --- a/epiphany-codex-bridge/src/cultnet.rs +++ b/epiphany-codex-bridge/src/cultnet.rs @@ -9,6 +9,13 @@ pub use epiphany_core::EpiphanyPressure; pub use epiphany_core::EpiphanyPressureBasis; pub use epiphany_core::EpiphanyPressureLevel; pub use epiphany_core::EpiphanyPressureStatus; +pub use epiphany_core::EpiphanyReorientAction; +pub use epiphany_core::EpiphanyReorientCheckpointStatus; +pub use epiphany_core::EpiphanyReorientDecision; +pub use epiphany_core::EpiphanyReorientFreshnessStatus; +pub use epiphany_core::EpiphanyReorientPressureLevel; +pub use epiphany_core::EpiphanyReorientReason; +pub use epiphany_core::EpiphanyReorientStateStatus; pub use epiphany_core::EpiphanyRetrievalFreshnessStatus; pub use epiphany_state_model::EpiphanyJobKind; use serde::Deserialize; diff --git a/epiphany-codex-bridge/src/mutation_service.rs b/epiphany-codex-bridge/src/mutation_service.rs index 80f33a40..a368209d 100644 --- a/epiphany-codex-bridge/src/mutation_service.rs +++ b/epiphany-codex-bridge/src/mutation_service.rs @@ -3,10 +3,8 @@ use chrono::Utc; use std::path::Path; use std::path::PathBuf; -use codex_app_server_protocol::ThreadEpiphanyReorientDecision; use codex_app_server_protocol::ThreadEpiphanyReorientFinding; use codex_app_server_protocol::ThreadEpiphanyReorientSource; -use codex_app_server_protocol::ThreadEpiphanyReorientStateStatus; use codex_app_server_protocol::ThreadEpiphanyRoleFinding; use codex_app_server_protocol::ThreadEpiphanyRoleId; use codex_app_server_protocol::ThreadEpiphanyStateUpdatedField; @@ -17,6 +15,8 @@ use epiphany_core::EpiphanyJobLaunchRequest; use epiphany_core::EpiphanyJobLaunchResult; use epiphany_core::EpiphanyJobView; use epiphany_core::EpiphanyPromotionInput; +use epiphany_core::EpiphanyReorientDecision; +use epiphany_core::EpiphanyReorientStateStatus; use epiphany_core::EpiphanyStateUpdate; use epiphany_core::EpiphanyTokenUsageSnapshot; use epiphany_core::RuntimeSpineHeartbeatJobOptions; @@ -54,7 +54,6 @@ use crate::pressure::derive_epiphany_pressure; use crate::reorient::EpiphanyFreshnessWatcherSnapshot; use crate::reorient::derive_epiphany_freshness_view; use crate::reorient::derive_epiphany_reorient; -use crate::reorient::map_epiphany_reorient; use crate::runtime_results::load_completed_epiphany_reorient_finding; use crate::runtime_results::load_completed_epiphany_role_finding; use uuid::Uuid; @@ -135,9 +134,9 @@ pub struct EpiphanyReorientLaunchApplied { pub launcher_job_id: String, pub backend_job_id: String, pub source: ThreadEpiphanyReorientSource, - pub state_status: ThreadEpiphanyReorientStateStatus, + pub state_status: EpiphanyReorientStateStatus, pub state_revision: Option, - pub decision: ThreadEpiphanyReorientDecision, + pub decision: EpiphanyReorientDecision, pub revision: u64, pub changed_fields: Vec, pub epiphany_state: EpiphanyThreadState, @@ -584,14 +583,7 @@ pub async fn launch_thread_epiphany_reorient( 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, - &freshness.retrieval, - &freshness.graph, - &freshness.watcher, - ); - let (_core_state_status, launch_decision) = derive_epiphany_reorient( + let (state_status, decision) = derive_epiphany_reorient( state, &pressure, &freshness.retrieval, @@ -618,7 +610,7 @@ pub async fn launch_thread_epiphany_reorient( max_runtime_seconds, state, checkpoint, - &launch_decision, + &decision, ); let changed_fields = epiphany_job_launch_changed_fields(); let launched = launch_epiphany_job_on_thread(thread, launch_request).await?; diff --git a/vendor/codex/codex-rs/app-server/src/codex_message_processor/epiphany_mutation_routes.rs b/vendor/codex/codex-rs/app-server/src/codex_message_processor/epiphany_mutation_routes.rs index a5c56cc3..c5a70f8b 100644 --- a/vendor/codex/codex-rs/app-server/src/codex_message_processor/epiphany_mutation_routes.rs +++ b/vendor/codex/codex-rs/app-server/src/codex_message_processor/epiphany_mutation_routes.rs @@ -6,6 +6,13 @@ use codex_protocol::protocol::EpiphanyThreadState; use epiphany_codex_bridge::cultnet::EpiphanyJobKind; use epiphany_codex_bridge::cultnet::EpiphanyJobStatus; use epiphany_codex_bridge::cultnet::EpiphanyJobView; +use epiphany_codex_bridge::cultnet::EpiphanyReorientAction; +use epiphany_codex_bridge::cultnet::EpiphanyReorientCheckpointStatus; +use epiphany_codex_bridge::cultnet::EpiphanyReorientDecision; +use epiphany_codex_bridge::cultnet::EpiphanyReorientFreshnessStatus; +use epiphany_codex_bridge::cultnet::EpiphanyReorientPressureLevel; +use epiphany_codex_bridge::cultnet::EpiphanyReorientReason; +use epiphany_codex_bridge::cultnet::EpiphanyReorientStateStatus; use epiphany_codex_bridge::error::EpiphanyBridgeError; use epiphany_codex_bridge::invalidation::epiphany_freshness_watcher_snapshot; use epiphany_codex_bridge::launch::EPIPHANY_REORIENT_LAUNCH_BINDING_ID; @@ -305,9 +312,9 @@ impl CodexMessageProcessor { ThreadEpiphanyReorientLaunchResponse { thread_id: thread_uuid.to_string(), source: applied.source, - state_status: applied.state_status, + state_status: thread_epiphany_reorient_state_status(applied.state_status), state_revision: applied.state_revision, - decision: applied.decision, + decision: thread_epiphany_reorient_decision(applied.decision), revision: applied.revision, changed_fields: changed_fields.clone(), epiphany_state: epiphany_state.clone(), @@ -756,6 +763,120 @@ fn thread_epiphany_job_from_surface( } } +fn thread_epiphany_reorient_state_status( + status: EpiphanyReorientStateStatus, +) -> ThreadEpiphanyReorientStateStatus { + match status { + EpiphanyReorientStateStatus::Missing => ThreadEpiphanyReorientStateStatus::Missing, + EpiphanyReorientStateStatus::Ready => ThreadEpiphanyReorientStateStatus::Ready, + } +} + +fn thread_epiphany_reorient_decision( + decision: EpiphanyReorientDecision, +) -> ThreadEpiphanyReorientDecision { + ThreadEpiphanyReorientDecision { + action: match decision.action { + EpiphanyReorientAction::Resume => ThreadEpiphanyReorientAction::Resume, + EpiphanyReorientAction::Regather => ThreadEpiphanyReorientAction::Regather, + }, + checkpoint_status: match decision.checkpoint_status { + EpiphanyReorientCheckpointStatus::Missing => { + ThreadEpiphanyReorientCheckpointStatus::Missing + } + EpiphanyReorientCheckpointStatus::ResumeReady => { + ThreadEpiphanyReorientCheckpointStatus::ResumeReady + } + EpiphanyReorientCheckpointStatus::RegatherRequired => { + ThreadEpiphanyReorientCheckpointStatus::RegatherRequired + } + }, + checkpoint_id: decision.checkpoint_id, + pressure_level: match decision.pressure_level { + EpiphanyReorientPressureLevel::Unknown => ThreadEpiphanyPressureLevel::Unknown, + EpiphanyReorientPressureLevel::Low => ThreadEpiphanyPressureLevel::Low, + EpiphanyReorientPressureLevel::Medium => ThreadEpiphanyPressureLevel::Elevated, + EpiphanyReorientPressureLevel::High => ThreadEpiphanyPressureLevel::High, + EpiphanyReorientPressureLevel::Critical => ThreadEpiphanyPressureLevel::Critical, + }, + retrieval_status: thread_epiphany_reorient_retrieval_status(decision.retrieval_status), + graph_status: thread_epiphany_reorient_graph_status(decision.graph_status), + watcher_status: thread_epiphany_reorient_watcher_status(decision.watcher_status), + reasons: decision + .reasons + .into_iter() + .map(thread_epiphany_reorient_reason) + .collect(), + checkpoint_dirty_paths: decision.checkpoint_dirty_paths, + checkpoint_changed_paths: decision.checkpoint_changed_paths, + active_frontier_node_ids: decision.active_frontier_node_ids, + next_action: decision.next_action, + note: decision.note, + } +} + +fn thread_epiphany_reorient_retrieval_status( + status: EpiphanyReorientFreshnessStatus, +) -> ThreadEpiphanyRetrievalFreshnessStatus { + match status { + EpiphanyReorientFreshnessStatus::Unknown => ThreadEpiphanyRetrievalFreshnessStatus::Missing, + EpiphanyReorientFreshnessStatus::Clean => ThreadEpiphanyRetrievalFreshnessStatus::Ready, + EpiphanyReorientFreshnessStatus::Dirty => ThreadEpiphanyRetrievalFreshnessStatus::Indexing, + EpiphanyReorientFreshnessStatus::Stale | EpiphanyReorientFreshnessStatus::Changed => { + ThreadEpiphanyRetrievalFreshnessStatus::Stale + } + } +} + +fn thread_epiphany_reorient_graph_status( + status: EpiphanyReorientFreshnessStatus, +) -> ThreadEpiphanyGraphFreshnessStatus { + match status { + EpiphanyReorientFreshnessStatus::Unknown => ThreadEpiphanyGraphFreshnessStatus::Missing, + EpiphanyReorientFreshnessStatus::Clean => ThreadEpiphanyGraphFreshnessStatus::Ready, + EpiphanyReorientFreshnessStatus::Dirty + | EpiphanyReorientFreshnessStatus::Stale + | EpiphanyReorientFreshnessStatus::Changed => ThreadEpiphanyGraphFreshnessStatus::Stale, + } +} + +fn thread_epiphany_reorient_watcher_status( + status: EpiphanyReorientFreshnessStatus, +) -> ThreadEpiphanyInvalidationStatus { + match status { + EpiphanyReorientFreshnessStatus::Unknown => ThreadEpiphanyInvalidationStatus::Unavailable, + EpiphanyReorientFreshnessStatus::Clean => ThreadEpiphanyInvalidationStatus::Clean, + EpiphanyReorientFreshnessStatus::Dirty + | EpiphanyReorientFreshnessStatus::Stale + | EpiphanyReorientFreshnessStatus::Changed => ThreadEpiphanyInvalidationStatus::Changed, + } +} + +fn thread_epiphany_reorient_reason( + reason: EpiphanyReorientReason, +) -> ThreadEpiphanyReorientReason { + match reason { + EpiphanyReorientReason::MissingState => ThreadEpiphanyReorientReason::MissingState, + EpiphanyReorientReason::MissingCheckpoint => { + ThreadEpiphanyReorientReason::MissingCheckpoint + } + EpiphanyReorientReason::CheckpointReady => ThreadEpiphanyReorientReason::CheckpointReady, + EpiphanyReorientReason::CheckpointRequestedRegather => { + ThreadEpiphanyReorientReason::CheckpointRequestedRegather + } + EpiphanyReorientReason::CheckpointPathsDirty => { + ThreadEpiphanyReorientReason::CheckpointPathsDirty + } + EpiphanyReorientReason::CheckpointPathsChanged => { + ThreadEpiphanyReorientReason::CheckpointPathsChanged + } + EpiphanyReorientReason::FrontierChanged => ThreadEpiphanyReorientReason::FrontierChanged, + EpiphanyReorientReason::UnanchoredCheckpointWhileStateStale => { + ThreadEpiphanyReorientReason::UnanchoredCheckpointWhileStateStale + } + } +} + async fn thread_epiphany_retrieval_state(thread: &CodexThread) -> EpiphanyRetrievalState { let config = thread.config_snapshot().await; let codex_home = thread.codex_home().await;