From d89c5cc5a07c89a6c4257726456ec0aee52080fc Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Mon, 18 May 2026 06:52:38 +0100 Subject: [PATCH] Move memory graph loading into bridge state --- epiphany-codex-bridge/src/mutation_service.rs | 15 +------ epiphany-codex-bridge/src/state.rs | 16 +++++++ notes/fresh-workspace-handoff.md | 1 + state/ledgers.msgpack | Bin 144832 -> 145124 bytes state/map.yaml | 4 +- .../epiphany_read_routes.rs | 39 ++++++++---------- 6 files changed, 38 insertions(+), 37 deletions(-) diff --git a/epiphany-codex-bridge/src/mutation_service.rs b/epiphany-codex-bridge/src/mutation_service.rs index f5e8676b..81a3b393 100644 --- a/epiphany-codex-bridge/src/mutation_service.rs +++ b/epiphany-codex-bridge/src/mutation_service.rs @@ -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, 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, actual_revision: u64, diff --git a/epiphany-codex-bridge/src/state.rs b/epiphany-codex-bridge/src/state.rs index c7b03aae..ded3938d 100644 --- a/epiphany-codex-bridge/src/state.rs +++ b/epiphany-codex-bridge/src/state.rs @@ -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, 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, diff --git a/notes/fresh-workspace-handoff.md b/notes/fresh-workspace-handoff.md index b1122d85..e3dda54c 100644 --- a/notes/fresh-workspace-handoff.md +++ b/notes/fresh-workspace-handoff.md @@ -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. diff --git a/state/ledgers.msgpack b/state/ledgers.msgpack index ab11e9ee17297e952a8cfdfa70d792a3de63e65c..0d8c37bf2b83b6524090b03089b78748f7f1e6db 100644 GIT binary patch delta 267 zcmX@`n&Zh^jtR<4W~(-;PGe;3Xx_uvzK4-<`yNK7cgCVEi%N=j8W|Xw=^B{o8d`)H zm|B?{O;_}0)X}~9&^Nyu#v?IdHLlE zDXBTB=|H_uGYb++GW0>F04+?;NX*MjE>_6QD=q;VsF0tgkYAn$v{AveAhQ4{S*cKv aT2!0~l+8;9IVU|cS+8LWx|ghsOrrn>WnoDG delta 53 zcmaFzmgB%{jtR<4rfnNlr!g|NH}7F=-^0kbeGenkJ7ckiEk*`LX1WHZx`q}Z2Bub~ J237`!Q2-^F5tje} diff --git a/state/map.yaml b/state/map.yaml index cc5a9805..c5835399 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -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. 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 9024f3b1..10ba8e38 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 @@ -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, 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()) }