Move retrieval host seam to app-server

This commit is contained in:
Meta Vens 2026-05-19 13:59:48 +01:00
commit 69d9762d81
5 changed files with 70 additions and 44 deletions

View file

@ -4,7 +4,6 @@ use codex_app_server_protocol::ThreadEpiphanyRetrieveResponse;
use codex_app_server_protocol::ThreadEpiphanyRetrieveResult;
use codex_app_server_protocol::ThreadEpiphanyRetrieveResultKind;
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;
@ -31,13 +30,15 @@ pub fn map_epiphany_retrieve_response(
})
}
pub async fn index_thread_epiphany_retrieval(
thread: &CodexThread,
pub async fn index_epiphany_retrieval_for_paths(
workspace_root: PathBuf,
codex_home: PathBuf,
force_full_rebuild: bool,
) -> anyhow::Result<ThreadEpiphanyIndexResponse> {
let index_summary = index_thread_epiphany_retrieval_state(thread, force_full_rebuild)
.await
.and_then(map_epiphany_retrieve_index_summary)?;
let index_summary =
index_epiphany_retrieval_state_for_paths(workspace_root, codex_home, force_full_rebuild)
.await
.and_then(map_epiphany_retrieve_index_summary)?;
Ok(ThreadEpiphanyIndexResponse { index_summary })
}
@ -49,10 +50,10 @@ pub fn normalize_thread_epiphany_retrieve_query(
normalize_epiphany_retrieve_query(query, limit, path_prefixes).map_err(str::to_string)
}
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;
pub async fn epiphany_retrieval_state_for_paths(
workspace_root: PathBuf,
codex_home: PathBuf,
) -> EpiphanyRetrievalState {
let fallback_workspace_root = workspace_root.clone();
let fallback_codex_home = codex_home.clone();
tokio::task::spawn_blocking(move || {
@ -64,13 +65,11 @@ pub async fn thread_epiphany_retrieval_state(thread: &CodexThread) -> EpiphanyRe
})
}
pub async fn index_thread_epiphany_retrieval_state(
thread: &CodexThread,
pub async fn index_epiphany_retrieval_state_for_paths(
workspace_root: PathBuf,
codex_home: PathBuf,
force_full_rebuild: bool,
) -> anyhow::Result<EpiphanyRetrievalState> {
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 || {
index_workspace(&workspace_root, codex_home.as_path(), force_full_rebuild)
})
@ -78,13 +77,11 @@ pub async fn index_thread_epiphany_retrieval_state(
.map_err(|err| anyhow::anyhow!("epiphany index worker failed: {err}"))?
}
pub async fn retrieve_thread_epiphany(
thread: &CodexThread,
pub async fn retrieve_epiphany_for_paths(
workspace_root: PathBuf,
codex_home: PathBuf,
query: EpiphanyRetrieveQuery,
) -> anyhow::Result<CoreEpiphanyRetrieveResponse> {
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 || {
retrieve_workspace(&workspace_root, codex_home.as_path(), query)
})

View file

@ -10,7 +10,7 @@ use codex_protocol::protocol::InitialHistory;
use epiphany_core::write_thread_state;
use tracing::warn;
use crate::retrieve::thread_epiphany_retrieval_state;
use crate::retrieve::epiphany_retrieval_state_for_paths;
pub async fn load_epiphany_state_from_rollout_path(
rollout_path: &Path,
@ -35,7 +35,10 @@ pub async fn live_thread_epiphany_state(thread: &CodexThread) -> Option<Epiphany
if let Some(state) = epiphany_state.as_mut()
&& state.retrieval.is_none()
{
state.retrieval = Some(thread_epiphany_retrieval_state(thread).await);
let config = thread.config_snapshot().await;
let codex_home = thread.codex_home().await;
state.retrieval =
Some(epiphany_retrieval_state_for_paths(config.cwd.to_path_buf(), codex_home).await);
}
if let Some(state) = epiphany_state.as_ref() {
let config = thread.config_snapshot().await;

View file

@ -19,7 +19,7 @@ use epiphany_codex_bridge::mutation_service::launch_epiphany_job_on_thread;
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::retrieve::epiphany_retrieval_state_for_paths;
use epiphany_codex_bridge::state::client_visible_live_thread_epiphany_state;
use tokio::sync::Mutex;
use tracing::warn;
@ -39,8 +39,10 @@ pub(crate) async fn maybe_run_epiphany_coordinator_automation_for_turn_boundary(
return;
};
let retrieval_override = thread_epiphany_retrieval_state(thread.as_ref()).await;
let config_snapshot = thread.config_snapshot().await;
let codex_home = thread.codex_home().await;
let retrieval_override =
epiphany_retrieval_state_for_paths(config_snapshot.cwd.to_path_buf(), codex_home).await;
epiphany_invalidation_manager
.ensure_thread_watch(&thread_id_text, &config_snapshot.cwd)
.await;

View file

@ -2,6 +2,7 @@ use codex_app_server_protocol::*;
use codex_core::CodexThread;
use codex_protocol::ThreadId;
use codex_protocol::error::CodexErr;
use codex_protocol::protocol::EpiphanyRetrievalState;
use codex_protocol::protocol::EpiphanyThreadState;
use epiphany_codex_bridge::invalidation::epiphany_freshness_watcher_snapshot;
use epiphany_codex_bridge::launch::EPIPHANY_REORIENT_LAUNCH_BINDING_ID;
@ -17,8 +18,8 @@ use epiphany_codex_bridge::mutation_service::interrupt_thread_epiphany_job;
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_codex_bridge::retrieve::epiphany_retrieval_state_for_paths;
use epiphany_codex_bridge::retrieve::index_epiphany_retrieval_for_paths;
use std::sync::Arc;
use super::CodexMessageProcessor;
@ -398,8 +399,14 @@ impl CodexMessageProcessor {
None => return,
};
let response = match index_thread_epiphany_retrieval(thread.as_ref(), force_full_rebuild)
.await
let config = thread.config_snapshot().await;
let codex_home = thread.codex_home().await;
let response = match index_epiphany_retrieval_for_paths(
config.cwd.to_path_buf(),
codex_home,
force_full_rebuild,
)
.await
{
Ok(response) => response,
Err(err) => {
@ -691,3 +698,9 @@ impl CodexMessageProcessor {
.await;
}
}
async fn thread_epiphany_retrieval_state(thread: &CodexThread) -> EpiphanyRetrievalState {
let config = thread.config_snapshot().await;
let codex_home = thread.codex_home().await;
epiphany_retrieval_state_for_paths(config.cwd.to_path_buf(), codex_home).await
}

View file

@ -1,12 +1,14 @@
use codex_app_server_protocol::*;
use codex_core::CodexThread;
use codex_protocol::ThreadId;
use codex_protocol::protocol::EpiphanyRetrievalState;
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::epiphany_retrieval_state_for_paths;
use epiphany_codex_bridge::retrieve::map_epiphany_retrieve_response;
use epiphany_codex_bridge::retrieve::normalize_thread_epiphany_retrieve_query;
use epiphany_codex_bridge::retrieve::retrieve_thread_epiphany;
use epiphany_codex_bridge::retrieve::thread_epiphany_retrieval_state;
use epiphany_codex_bridge::retrieve::retrieve_epiphany_for_paths;
use epiphany_codex_bridge::view::EpiphanyFreshnessResponseInput;
use epiphany_codex_bridge::view::EpiphanyReorientResultResponseInput;
use epiphany_codex_bridge::view::EpiphanyRoleResultResponseInput;
@ -440,20 +442,23 @@ impl CodexMessageProcessor {
}
};
let response = match retrieve_thread_epiphany(thread.as_ref(), query)
.await
.and_then(map_epiphany_retrieve_response)
{
Ok(response) => response,
Err(err) => {
self.send_internal_error(
request_id,
format!("failed to retrieve Epiphany results for {thread_uuid}: {err}"),
)
.await;
return;
}
};
let config = thread.config_snapshot().await;
let codex_home = thread.codex_home().await;
let response =
match retrieve_epiphany_for_paths(config.cwd.to_path_buf(), codex_home, query)
.await
.and_then(map_epiphany_retrieve_response)
{
Ok(response) => response,
Err(err) => {
self.send_internal_error(
request_id,
format!("failed to retrieve Epiphany results for {thread_uuid}: {err}"),
)
.await;
return;
}
};
self.outgoing.send_response(request_id, response).await;
}
@ -561,3 +566,9 @@ impl CodexMessageProcessor {
self.outgoing.send_response(request_id, response).await;
}
}
async fn thread_epiphany_retrieval_state(thread: &CodexThread) -> EpiphanyRetrievalState {
let config = thread.config_snapshot().await;
let codex_home = thread.codex_home().await;
epiphany_retrieval_state_for_paths(config.cwd.to_path_buf(), codex_home).await
}