Move Epiphany retrieval execution into bridge

This commit is contained in:
Meta Vens 2026-05-18 07:08:56 +01:00
commit 10a6e7a491
9 changed files with 68 additions and 62 deletions

View file

@ -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<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 || {
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<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 || {
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<ThreadEpiphanyRetrieveResponse> {
@ -29,8 +76,7 @@ pub async fn index_thread_epiphany_retrieval(
thread: &CodexThread,
force_full_rebuild: bool,
) -> anyhow::Result<ThreadEpiphanyIndexResponse> {
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 })

View file

@ -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<Option<EpiphanyThreadState>, String> {
@ -36,7 +38,7 @@ 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().await);
state.retrieval = Some(thread_epiphany_retrieval_state(thread).await);
}
if let Some(state) = epiphany_state.as_ref() {
let config = thread.config_snapshot().await;

View file

@ -61,6 +61,7 @@ remembers doctrine; the branch remembers the blade.
- Turn control routes now live in `codex_message_processor/turn_routes.rs`: turn start, thread item injection, app-server client info setting, turn steer, turn interrupt, mode normalization, and input-limit validation with module-local unit tests.
- Epiphany memory graph loading and runtime-spine path derivation now belong to `epiphany-codex-bridge::state`. Vendored app-server read routes may decide whether a loaded thread exists, but they no longer own memory graph or runtime-spine store path/load mechanics.
- Epiphany job launch/interrupt policy now belongs to `epiphany-codex-bridge::mutation_service`: heartbeat launch planning, runtime-spine job opening, binding/runtime-link mutation, and interrupt binding cleanup are out of vendored `CodexThread`. `CodexThread` still owns the narrow Codex-session read/update seam for Epiphany state until that persistence seam can be replaced cleanly.
- Epiphany retrieval status, indexing, and retrieval execution now belong to `epiphany-codex-bridge::retrieve`; vendored `CodexThread` only exposes cwd/codex-home host facts for that path.
- Heartbeat durable document/schema types now live in `epiphany-core/src/heartbeat_state/heartbeat_documents.rs`, role/default construction lives in `epiphany-core/src/heartbeat_state/heartbeat_roles.rs`, persistence/validation lives in `epiphany-core/src/heartbeat_state/heartbeat_store.rs`, and status/artifact JSON projection lives in `epiphany-core/src/heartbeat_state/heartbeat_projection.rs`. The root `heartbeat_state.rs` keeps scheduling and Void cognition orchestration for the next cuts. Focused heartbeat tests and `epiphany-core` check pass after the splits.
- Heartbeat role/default and store seams now have module-local unit tests: fixed lane catalog, Ghostlight scene role projection, and typed state/cognition CultCache round-trip. Keep future heartbeat cuts aligned to those seam tests instead of growing root integration-only coverage.
- Heartbeat adaptive pacing now lives in `epiphany-core/src/heartbeat_state/heartbeat_pacing.rs`, including running-turn count and effective cooldown multipliers. It has a module-local unit test for pending-turn counting; root scheduling calls the pacing seam instead of owning pressure/concurrency math directly.

Binary file not shown.

View file

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

View file

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

View file

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

View file

@ -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)
{

View file

@ -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<EpiphanyThreadState> {
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<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;
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<EpiphanyRetrieveResponse> {
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,