From 10a6e7a491ab1d64f07aed25afd7b203809bad6a Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Mon, 18 May 2026 07:08:56 +0100 Subject: [PATCH] Move Epiphany retrieval execution into bridge --- epiphany-codex-bridge/src/retrieve.rs | 50 ++++++++++++++- epiphany-codex-bridge/src/state.rs | 4 +- notes/fresh-workspace-handoff.md | 1 + state/ledgers.msgpack | Bin 145691 -> 145984 bytes state/map.yaml | 3 + .../epiphany_automation.rs | 3 +- .../epiphany_mutation_routes.rs | 3 +- .../epiphany_read_routes.rs | 9 +-- .../codex/codex-rs/core/src/codex_thread.rs | 57 ++---------------- 9 files changed, 68 insertions(+), 62 deletions(-) diff --git a/epiphany-codex-bridge/src/retrieve.rs b/epiphany-codex-bridge/src/retrieve.rs index 2c771488..049d85a5 100644 --- a/epiphany-codex-bridge/src/retrieve.rs +++ b/epiphany-codex-bridge/src/retrieve.rs @@ -7,10 +7,57 @@ use codex_app_server_protocol::ThreadEpiphanyRetrieveShardSummary; use codex_core::CodexThread; use codex_protocol::protocol::EpiphanyRetrievalState; use codex_utils_absolute_path::AbsolutePathBuf; +use epiphany_core::EpiphanyRetrieveQuery; use epiphany_core::EpiphanyRetrieveResponse as CoreEpiphanyRetrieveResponse; use epiphany_core::EpiphanyRetrieveResult as CoreEpiphanyRetrieveResult; use epiphany_core::EpiphanyRetrieveResultKind as CoreEpiphanyRetrieveResultKind; +pub async fn thread_epiphany_retrieval_state(thread: &CodexThread) -> EpiphanyRetrievalState { + let config = thread.config_snapshot().await; + let workspace_root = config.cwd.to_path_buf(); + let codex_home = thread.codex_home().await; + let fallback_workspace_root = workspace_root.clone(); + let fallback_codex_home = codex_home.clone(); + tokio::task::spawn_blocking(move || { + epiphany_core::retrieval_state_for_workspace(&workspace_root, codex_home.as_path()) + }) + .await + .unwrap_or_else(|_| { + epiphany_core::retrieval_state_for_workspace( + &fallback_workspace_root, + fallback_codex_home.as_path(), + ) + }) +} + +pub async fn index_thread_epiphany_retrieval_state( + thread: &CodexThread, + force_full_rebuild: bool, +) -> anyhow::Result { + let config = thread.config_snapshot().await; + let workspace_root = config.cwd.to_path_buf(); + let codex_home = thread.codex_home().await; + tokio::task::spawn_blocking(move || { + epiphany_core::index_workspace(&workspace_root, codex_home.as_path(), force_full_rebuild) + }) + .await + .map_err(|err| anyhow::anyhow!("epiphany index worker failed: {err}"))? +} + +pub async fn retrieve_thread_epiphany( + thread: &CodexThread, + query: EpiphanyRetrieveQuery, +) -> anyhow::Result { + let config = thread.config_snapshot().await; + let workspace_root = config.cwd.to_path_buf(); + let codex_home = thread.codex_home().await; + tokio::task::spawn_blocking(move || { + epiphany_core::retrieve_workspace(&workspace_root, codex_home.as_path(), query) + }) + .await + .map_err(|err| anyhow::anyhow!("epiphany retrieval worker failed: {err}"))? +} + pub fn map_epiphany_retrieve_response( response: CoreEpiphanyRetrieveResponse, ) -> anyhow::Result { @@ -29,8 +76,7 @@ pub async fn index_thread_epiphany_retrieval( thread: &CodexThread, force_full_rebuild: bool, ) -> anyhow::Result { - let index_summary = thread - .epiphany_index(force_full_rebuild) + let index_summary = index_thread_epiphany_retrieval_state(thread, force_full_rebuild) .await .and_then(map_epiphany_retrieve_index_summary)?; Ok(ThreadEpiphanyIndexResponse { index_summary }) diff --git a/epiphany-codex-bridge/src/state.rs b/epiphany-codex-bridge/src/state.rs index 22be773d..bbd416bf 100644 --- a/epiphany-codex-bridge/src/state.rs +++ b/epiphany-codex-bridge/src/state.rs @@ -13,6 +13,8 @@ use epiphany_core::load_memory_graph_snapshot; use epiphany_core::write_thread_state; use tracing::warn; +use crate::retrieve::thread_epiphany_retrieval_state; + pub async fn load_epiphany_state_from_rollout_path( rollout_path: &Path, ) -> std::result::Result, String> { @@ -36,7 +38,7 @@ pub async fn live_thread_epiphany_state(thread: &CodexThread) -> Option;tPCuyOr|f~ z&8W@v$ane#X+}}G#2kgN6`b>d3PUoAQWH}Y^76}pDhu+9Q;QYy^KvQ`lFL){lR*k}GxBp&6*BUROBB)) zlS_&f3UW$|6-qKv74i~`ih$Z&3o;8b67wp-_NOWoq!txt7MG;vC8sJBrzYm=HEc05 TFf!9MFx52#x}5{!c*7_F_}fyy delta 53 zcmX@`g=6+7jtR<477sV7PGe;3YTm=xzK4-<`yNInPjj(`Ek*`LX1WHZx`q}Z24+?U J##Y7#Q2-h&5gh;k diff --git a/state/map.yaml b/state/map.yaml index 9e34cb41..caa150a4 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -29,6 +29,9 @@ objective: launch/interrupt policy now lives in `epiphany-codex-bridge::mutation_service`; vendored `CodexThread` remains the narrow Codex-session persistence seam for Epiphany state read/update. + Retrieval status, indexing, and retrieval execution now live in + `epiphany-codex-bridge::retrieve`; vendored Codex supplies cwd/codex-home + host facts rather than owning Epiphany retrieval behavior. constraints: - No frontier-scale training tithe. diff --git a/vendor/codex/codex-rs/app-server/src/codex_message_processor/epiphany_automation.rs b/vendor/codex/codex-rs/app-server/src/codex_message_processor/epiphany_automation.rs index be40d55e..9ae975dc 100644 --- a/vendor/codex/codex-rs/app-server/src/codex_message_processor/epiphany_automation.rs +++ b/vendor/codex/codex-rs/app-server/src/codex_message_processor/epiphany_automation.rs @@ -19,6 +19,7 @@ use epiphany_codex_bridge::mutation_service::launch_thread_epiphany_job; use epiphany_codex_bridge::pressure::map_epiphany_pressure; use epiphany_codex_bridge::pressure::render_epiphany_pre_compaction_checkpoint_intervention; use epiphany_codex_bridge::pressure::should_run_epiphany_pre_compaction_checkpoint_intervention; +use epiphany_codex_bridge::retrieve::thread_epiphany_retrieval_state; use epiphany_codex_bridge::state::runtime_spine_store_path; use tokio::sync::Mutex; use tracing::warn; @@ -38,7 +39,7 @@ pub(crate) async fn maybe_run_epiphany_coordinator_automation_for_turn_boundary( return; }; - let retrieval_override = thread.epiphany_retrieval_state().await; + let retrieval_override = thread_epiphany_retrieval_state(thread.as_ref()).await; let config_snapshot = thread.config_snapshot().await; epiphany_invalidation_manager .ensure_thread_watch(&thread_id_text, &config_snapshot.cwd) 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 012f4ae0..6bccbffc 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 @@ -18,6 +18,7 @@ use epiphany_codex_bridge::mutation_service::launch_thread_epiphany_job; use epiphany_codex_bridge::mutation_service::launch_thread_epiphany_reorient; use epiphany_codex_bridge::mutation_service::launch_thread_epiphany_role; use epiphany_codex_bridge::retrieve::index_thread_epiphany_retrieval; +use epiphany_codex_bridge::retrieve::thread_epiphany_retrieval_state; use epiphany_core::EpiphanyJobLaunchRequest; use std::sync::Arc; @@ -249,7 +250,7 @@ impl CodexMessageProcessor { } }; - let retrieval_override = loaded_thread.epiphany_retrieval_state().await; + let retrieval_override = thread_epiphany_retrieval_state(loaded_thread.as_ref()).await; let config_snapshot = loaded_thread.config_snapshot().await; self.epiphany_invalidation_manager .ensure_thread_watch(&thread_id, &config_snapshot.cwd) diff --git a/vendor/codex/codex-rs/app-server/src/codex_message_processor/epiphany_read_routes.rs b/vendor/codex/codex-rs/app-server/src/codex_message_processor/epiphany_read_routes.rs index 5f885505..694537b3 100644 --- a/vendor/codex/codex-rs/app-server/src/codex_message_processor/epiphany_read_routes.rs +++ b/vendor/codex/codex-rs/app-server/src/codex_message_processor/epiphany_read_routes.rs @@ -4,6 +4,8 @@ use epiphany_codex_bridge::invalidation::epiphany_freshness_watcher_snapshot; use epiphany_codex_bridge::launch::EPIPHANY_REORIENT_LAUNCH_BINDING_ID; use epiphany_codex_bridge::launch::epiphany_role_binding_id; use epiphany_codex_bridge::retrieve::map_epiphany_retrieve_response; +use epiphany_codex_bridge::retrieve::retrieve_thread_epiphany; +use epiphany_codex_bridge::retrieve::thread_epiphany_retrieval_state; use epiphany_codex_bridge::state::load_optional_thread_memory_graph_snapshot; use epiphany_codex_bridge::state::runtime_spine_store_path; use epiphany_codex_bridge::view::EpiphanyFreshnessResponseInput; @@ -86,7 +88,7 @@ impl CodexMessageProcessor { .is_none() { if let Some(loaded_thread) = loaded_thread.as_ref() { - Some(loaded_thread.epiphany_retrieval_state().await) + Some(thread_epiphany_retrieval_state(loaded_thread).await) } else { None } @@ -259,7 +261,7 @@ impl CodexMessageProcessor { }; let retrieval_override = if let Some(loaded_thread) = loaded_thread.as_ref() { - Some(loaded_thread.epiphany_retrieval_state().await) + Some(thread_epiphany_retrieval_state(loaded_thread).await) } else { None }; @@ -482,8 +484,7 @@ impl CodexMessageProcessor { } }; - let response = match thread - .epiphany_retrieve(query) + let response = match retrieve_thread_epiphany(thread.as_ref(), query) .await .and_then(map_epiphany_retrieve_response) { diff --git a/vendor/codex/codex-rs/core/src/codex_thread.rs b/vendor/codex/codex-rs/core/src/codex_thread.rs index 86ca91bd..f645d972 100644 --- a/vendor/codex/codex-rs/core/src/codex_thread.rs +++ b/vendor/codex/codex-rs/core/src/codex_thread.rs @@ -20,7 +20,6 @@ use codex_protocol::models::ResponseInputItem; use codex_protocol::models::ResponseItem; use codex_protocol::openai_models::ReasoningEffort; use codex_protocol::protocol::AskForApproval; -use codex_protocol::protocol::EpiphanyRetrievalState; use codex_protocol::protocol::EpiphanyStateItem; use codex_protocol::protocol::EpiphanyThreadState; use codex_protocol::protocol::Event; @@ -35,8 +34,6 @@ use codex_protocol::protocol::TokenUsageInfo; use codex_protocol::protocol::W3cTraceContext; use codex_protocol::user_input::UserInput; use codex_utils_absolute_path::AbsolutePathBuf; -use epiphany_core::EpiphanyRetrieveQuery; -use epiphany_core::EpiphanyRetrieveResponse; use epiphany_core::EpiphanyStateUpdate; use epiphany_core::apply_epiphany_state_update; use epiphany_core::epiphany_state_update_validation_errors; @@ -324,6 +321,10 @@ impl CodexThread { self.codex.thread_config_snapshot().await } + pub async fn codex_home(&self) -> PathBuf { + self.codex.session.codex_home().await.to_path_buf() + } + pub async fn epiphany_state(&self) -> Option { self.codex.session.epiphany_state().await } @@ -383,56 +384,6 @@ impl CodexThread { Ok(next_state) } - pub async fn epiphany_retrieval_state(&self) -> EpiphanyRetrievalState { - let config = self.codex.thread_config_snapshot().await; - let workspace_root = config.cwd.to_path_buf(); - let codex_home = self.codex.session.codex_home().await; - let fallback_workspace_root = workspace_root.clone(); - let fallback_codex_home = codex_home.clone(); - tokio::task::spawn_blocking(move || { - epiphany_core::retrieval_state_for_workspace(&workspace_root, codex_home.as_path()) - }) - .await - .unwrap_or_else(|_| { - epiphany_core::retrieval_state_for_workspace( - &fallback_workspace_root, - fallback_codex_home.as_path(), - ) - }) - } - - pub async fn epiphany_index( - &self, - force_full_rebuild: bool, - ) -> anyhow::Result { - let config = self.codex.thread_config_snapshot().await; - let workspace_root = config.cwd.to_path_buf(); - let codex_home = self.codex.session.codex_home().await; - tokio::task::spawn_blocking(move || { - epiphany_core::index_workspace( - &workspace_root, - codex_home.as_path(), - force_full_rebuild, - ) - }) - .await - .map_err(|err| anyhow::anyhow!("epiphany index worker failed: {err}"))? - } - - pub async fn epiphany_retrieve( - &self, - query: EpiphanyRetrieveQuery, - ) -> anyhow::Result { - let config = self.codex.thread_config_snapshot().await; - let workspace_root = config.cwd.to_path_buf(); - let codex_home = self.codex.session.codex_home().await; - tokio::task::spawn_blocking(move || { - epiphany_core::retrieve_workspace(&workspace_root, codex_home.as_path(), query) - }) - .await - .map_err(|err| anyhow::anyhow!("epiphany retrieval worker failed: {err}"))? - } - pub async fn read_mcp_resource( &self, server: &str,