Move memory graph loading into bridge state

This commit is contained in:
Meta Vens 2026-05-18 06:52:38 +01:00
commit d89c5cc5a0
6 changed files with 38 additions and 37 deletions

View file

@ -19,7 +19,6 @@ use codex_protocol::protocol::EpiphanyThreadState;
use codex_protocol::protocol::TokenUsageInfo as CoreTokenUsageInfo;
use epiphany_core::EpiphanyJobInterruptRequest;
use epiphany_core::EpiphanyJobLaunchRequest;
use epiphany_core::EpiphanyMemoryGraphSnapshot;
use epiphany_core::EpiphanyMemoryPatchReview;
use epiphany_core::EpiphanyMemoryPatchReviewStatus;
use epiphany_core::EpiphanyPromotionInput;
@ -53,6 +52,7 @@ 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 crate::state::client_visible_live_thread_epiphany_state;
use crate::state::load_thread_memory_graph_snapshot;
use crate::state::memory_graph_store_path;
use uuid::Uuid;
@ -523,19 +523,6 @@ pub async fn launch_thread_epiphany_reorient(
})
}
async fn load_thread_memory_graph_snapshot(
thread: &CodexThread,
) -> Result<Option<EpiphanyMemoryGraphSnapshot>, CodexErr> {
let config = thread.config_snapshot().await;
let store_path = memory_graph_store_path(config.cwd.as_path());
load_memory_graph_snapshot(&store_path).map_err(|err| {
CodexErr::InvalidRequest(format!(
"failed to load memory graph store {}: {err}",
store_path.display()
))
})
}
fn validate_expected_revision(
expected_revision: Option<u64>,
actual_revision: u64,

View file

@ -5,8 +5,11 @@ use std::path::PathBuf;
use codex_core::CodexThread;
use codex_core::RolloutRecorder;
use codex_core::latest_epiphany_state_from_rollout_items;
use codex_protocol::error::CodexErr;
use codex_protocol::protocol::EpiphanyThreadState;
use codex_protocol::protocol::InitialHistory;
use epiphany_core::EpiphanyMemoryGraphSnapshot;
use epiphany_core::load_memory_graph_snapshot;
use epiphany_core::write_thread_state;
use tracing::warn;
@ -63,6 +66,19 @@ pub fn memory_graph_store_path(workspace_root: &Path) -> PathBuf {
workspace_root.join("state").join("memory-graph.msgpack")
}
pub async fn load_thread_memory_graph_snapshot(
thread: &CodexThread,
) -> Result<Option<EpiphanyMemoryGraphSnapshot>, CodexErr> {
let config = thread.config_snapshot().await;
let store_path = memory_graph_store_path(config.cwd.as_path());
load_memory_graph_snapshot(&store_path).map_err(|err| {
CodexErr::InvalidRequest(format!(
"failed to load memory graph store {}: {err}",
store_path.display()
))
})
}
pub fn mirror_thread_state_to_workspace(
workspace_root: &Path,
thread_id: &str,

View file

@ -59,6 +59,7 @@ remembers doctrine; the branch remembers the blade.
- Thread start route handling and its async lifecycle task now live in `codex_message_processor/thread_start_routes.rs`; root no longer owns `thread_start_task`.
- Thread config helpers now live in `codex_message_processor/thread_config.rs`: instruction-source loading, thread config override construction, config-load error shaping, and dynamic-tool validation. The pure dynamic-tool validation contract has module-local unit tests.
- 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 read-route memory graph loading now belongs to `epiphany-codex-bridge::state::load_thread_memory_graph_snapshot`. Vendored app-server read routes may decide whether a loaded thread exists, but they no longer own the memory graph store path or load mechanics.
- 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

@ -23,7 +23,9 @@ objective:
JSON may survive only at schema/wire/forensic/quarantine boundaries; and
vendored Codex must be reduced to the smallest OpenAI subscription
auth/model-transport adapter needed to preserve the user's Codex
compatibility.
compatibility. Read-route memory graph loading now lives in
`epiphany-codex-bridge::state`; vendored app-server route code calls that
bridge instead of owning the store path/load mechanics itself.
constraints:
- No frontier-scale training tithe.

View file

@ -5,7 +5,7 @@ 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::state::memory_graph_store_path;
use epiphany_codex_bridge::state::load_thread_memory_graph_snapshot;
use epiphany_codex_bridge::view::EpiphanyFreshnessResponseInput;
use epiphany_codex_bridge::view::EpiphanyReorientResultResponseInput;
use epiphany_codex_bridge::view::EpiphanyRoleResultResponseInput;
@ -24,7 +24,6 @@ use epiphany_codex_bridge::view::map_epiphany_reorient_result_response;
use epiphany_codex_bridge::view::map_epiphany_role_result_response;
use epiphany_codex_bridge::view::map_epiphany_view_response;
use epiphany_core::EpiphanyMemoryGraphSnapshot;
use epiphany_core::load_memory_graph_snapshot;
use epiphany_core::normalize_epiphany_retrieve_query;
use super::CodexMessageProcessor;
@ -57,7 +56,7 @@ impl CodexMessageProcessor {
let loaded_thread = self.thread_manager.get_thread(thread_uuid).await.ok();
let loaded = loaded_thread.is_some();
let memory_graph_snapshot =
match load_thread_memory_graph_snapshot(loaded_thread.as_deref()).await {
match load_optional_thread_memory_graph_snapshot(loaded_thread.as_deref()).await {
Ok(snapshot) => snapshot,
Err(message) => {
self.send_internal_error(request_id, message).await;
@ -239,7 +238,7 @@ impl CodexMessageProcessor {
let loaded_thread = self.thread_manager.get_thread(thread_uuid).await.ok();
let memory_graph_snapshot =
match load_thread_memory_graph_snapshot(loaded_thread.as_deref()).await {
match load_optional_thread_memory_graph_snapshot(loaded_thread.as_deref()).await {
Ok(snapshot) => snapshot,
Err(message) => {
self.send_internal_error(request_id, message).await;
@ -307,7 +306,7 @@ impl CodexMessageProcessor {
let loaded_thread = self.thread_manager.get_thread(thread_uuid).await.ok();
let loaded = loaded_thread.is_some();
let memory_graph_snapshot =
match load_thread_memory_graph_snapshot(loaded_thread.as_deref()).await {
match load_optional_thread_memory_graph_snapshot(loaded_thread.as_deref()).await {
Ok(snapshot) => snapshot,
Err(message) => {
self.send_internal_error(request_id, message).await;
@ -354,7 +353,7 @@ impl CodexMessageProcessor {
let loaded_thread = self.thread_manager.get_thread(thread_uuid).await.ok();
let loaded = loaded_thread.is_some();
let memory_graph_snapshot =
match load_thread_memory_graph_snapshot(loaded_thread.as_deref()).await {
match load_optional_thread_memory_graph_snapshot(loaded_thread.as_deref()).await {
Ok(snapshot) => snapshot,
Err(message) => {
self.send_internal_error(request_id, message).await;
@ -576,13 +575,14 @@ impl CodexMessageProcessor {
}
};
let memory_graph_snapshot = match load_thread_memory_graph_snapshot(Some(&thread)).await {
Ok(snapshot) => snapshot,
Err(message) => {
self.send_internal_error(request_id, message).await;
return;
}
};
let memory_graph_snapshot =
match load_optional_thread_memory_graph_snapshot(Some(&thread)).await {
Ok(snapshot) => snapshot,
Err(message) => {
self.send_internal_error(request_id, message).await;
return;
}
};
let state = match thread.epiphany_state().await {
Some(state) => state,
None => {
@ -614,18 +614,13 @@ impl CodexMessageProcessor {
}
}
async fn load_thread_memory_graph_snapshot(
async fn load_optional_thread_memory_graph_snapshot(
loaded_thread: Option<&CodexThread>,
) -> std::result::Result<Option<EpiphanyMemoryGraphSnapshot>, String> {
let Some(loaded_thread) = loaded_thread else {
return Ok(None);
};
let config_snapshot = loaded_thread.config_snapshot().await;
let store_path = memory_graph_store_path(config_snapshot.cwd.as_path());
load_memory_graph_snapshot(&store_path).map_err(|err| {
format!(
"failed to load Epiphany memory graph store {}: {err}",
store_path.display()
)
})
load_thread_memory_graph_snapshot(loaded_thread)
.await
.map_err(|err| err.to_string())
}