From 77c62fb48804d9fa82c62eb184e9bab8a49c1ecd Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Mon, 18 May 2026 05:57:04 +0100 Subject: [PATCH] Collapse memory graph read adapter --- notes/fresh-workspace-handoff.md | 2 +- state/ledgers.msgpack | Bin 141510 -> 141770 bytes state/map.yaml | 4 +- .../epiphany_read_routes.rs | 106 +++++++----------- 4 files changed, 41 insertions(+), 71 deletions(-) diff --git a/notes/fresh-workspace-handoff.md b/notes/fresh-workspace-handoff.md index 88b295fe..d197c077 100644 --- a/notes/fresh-workspace-handoff.md +++ b/notes/fresh-workspace-handoff.md @@ -39,7 +39,7 @@ remembers doctrine; the branch remembers the blade. - `epiphany-openai-runtime` worker result ingress now parses assistant output directly into typed role/reorient ingress structs selected from the durable launch document, stores nested `statePatch` and `selfPatch` as typed MessagePack in `EpiphanyRuntimeRoleWorkerResult`, and no longer passes worker result data through generic `serde_json::Value`. JSON survives there only as the OpenAI text-output edge before typed deserialization. - Agent self-memory review/application now has typed `AgentSelfPatch` core APIs. JSON-value selfPatch functions are compatibility wrappers for CLI/artifact ingress; native callers should parse once at the edge and then call `review_agent_self_patch_document` / `apply_agent_self_patch_document`. Role-result self-persistence no longer exports a JSON-value reviewer; the live API is `review_role_self_patch_document`. - `epiphany-openai-codex-spine` no longer uses Codex's Responses client, model-provider layer, `codex-api`, `codex-model-provider`, `codex-model-provider-info`, or `codex-protocol` for outbound model requests. It reaches `codex-login` only through `epiphany-openai-auth-spine` so credential loading/refresh stays Codex-compatible while request/status/event/runtime surfaces stay typed Epiphany documents. -- `notes/epiphany-memory-graph-unified-plan.md` is the current memory architecture direction drawn from `Fractal Domains And The Cache That Bites` plus the VoidBot memory scar tissue. The repo semantic architecture/dataflow graph and agent memory are one `EpiphanyMemoryGraph` substrate with repo, role, short-term, incubation, agency, candidate-intervention, and evidence profiles. The first native skeleton is landed: `epiphany-state-model` owns shared graph document types, `epiphany-core::memory_graph` owns stable ids, validation, freshness, context cuts, and CultCache persistence, and `epiphany-memory-graph` can status/validate/context/semantic-context/smoke/index the store. `epiphany-core::semantic_cache` now owns the shared Qdrant/Ollama transport used by workspace retrieval and memory graph indexing, so Qdrant remains a rebuildable contribution cache for typed graph documents, not truth. Runtime role results expose typed `memoryPatchCandidates`; Modeling `roleAccept` applies them to `state/memory-graph.msgpack`; native role/reorientation launches now prefer that persisted memory graph for bounded typed `memoryContext` cuts and only fall back to legacy accepted thread graphs for bootstrap. Reorientation launch no longer carries full `graphs` cargo. The old `thread/epiphany/propose` read route no longer returns replacement `graphs`; it exposes graph growth as typed `memoryPatchCandidates` and withholds frontier updates that depend on unapplied memory growth. Generic `thread/epiphany/update` and `thread/epiphany/promote` now reject `patch.graphs` at the bridge. `thread/epiphany/view`, `thread/epiphany/freshness`, `thread/epiphany/context`, and `thread/epiphany/graphQuery` now prefer the persisted memory graph for loaded threads and project back into legacy graph-shaped response lenses only at the bridge edge. `notes/repo-fractal-dataflow-cache-plan.md` and `notes/agent-memory-fractal-cache-plan.md` are profile plans, not rival organs. +- `notes/epiphany-memory-graph-unified-plan.md` is the current memory architecture direction drawn from `Fractal Domains And The Cache That Bites` plus the VoidBot memory scar tissue. The repo semantic architecture/dataflow graph and agent memory are one `EpiphanyMemoryGraph` substrate with repo, role, short-term, incubation, agency, candidate-intervention, and evidence profiles. The first native skeleton is landed: `epiphany-state-model` owns shared graph document types, `epiphany-core::memory_graph` owns stable ids, validation, freshness, context cuts, and CultCache persistence, and `epiphany-memory-graph` can status/validate/context/semantic-context/smoke/index the store. `epiphany-core::semantic_cache` now owns the shared Qdrant/Ollama transport used by workspace retrieval and memory graph indexing, so Qdrant remains a rebuildable contribution cache for typed graph documents, not truth. Runtime role results expose typed `memoryPatchCandidates`; Modeling `roleAccept` applies them to `state/memory-graph.msgpack`; native role/reorientation launches now prefer that persisted memory graph for bounded typed `memoryContext` cuts and only fall back to legacy accepted thread graphs for bootstrap. Reorientation launch no longer carries full `graphs` cargo. The old `thread/epiphany/propose` read route no longer returns replacement `graphs`; it exposes graph growth as typed `memoryPatchCandidates` and withholds frontier updates that depend on unapplied memory growth. Generic `thread/epiphany/update` and `thread/epiphany/promote` now reject `patch.graphs` at the bridge. `thread/epiphany/view`, `thread/epiphany/freshness`, `thread/epiphany/context`, and `thread/epiphany/graphQuery` now prefer the persisted memory graph for loaded threads through one read-route store adapter and project back into legacy graph-shaped response lenses only at the bridge edge. `notes/repo-fractal-dataflow-cache-plan.md` and `notes/agent-memory-fractal-cache-plan.md` are profile plans, not rival organs. - Durable Epiphany state types now live in root crate `epiphany-state-model`. `codex-protocol` re-exports them only so old rollout/API callers keep compiling; do not add new durable `Epiphany*` state structs under `vendor/codex`. `epiphany-core` imports the native model directly and no longer depends on `codex-protocol`. Pressure derives from native `EpiphanyTokenUsageSnapshot`; Codex token telemetry is mapped at the bridge. Codex rollout/event reconstruction now lives in `codex-core::epiphany_rollout`, where the Codex `RolloutItem` / `EventMsg` types belong. Exact retrieval path matching is native to `epiphany-core`, so `epiphany-core` has no direct vendored Codex crate dependency. - State-update contract proof and job launch/interrupt DTO ownership now live in native `epiphany-core`. The old giant `codex_thread.rs` Epiphany state-update test fixture was cut, and `epiphany-codex-bridge` no longer imports Epiphany job launch request types from `codex_core`; vendored `CodexThread` may call the native mutation/launch law for compatibility, but it must not regain ownership of state-update semantics, heartbeat launch-plan policy, or Epiphany DTOs. - MCP remains JSON because MCP is a JSON protocol. The latest processor cut only moved MCP refresh/OAuth/status/resource/tool-call route handling into `codex_message_processor/mcp_routes.rs`, reducing the root processor to about 8,977 lines; it did not claim MCP payloads are CultNet or make MCP an Epiphany-owned runtime contract. diff --git a/state/ledgers.msgpack b/state/ledgers.msgpack index 44150c3a4c18d91b5915516038bfd0ac347db182..4e86c52e5617b2fd29d07f06c36fbd133caaa0a0 100644 GIT binary patch delta 222 zcmX?hk>k{5jtR<4niDpvPGe-OZQjG!zK4-<`yNK7FKW|QsWXX8H?(Hd^}l)0H#IlE zs8Tm6F*!RmMWHA)5lG~hmZTOd snapshot, - Err(err) => { - self.send_internal_error( - request_id, - format!( - "failed to load Epiphany memory graph store {}: {err}", - store_path.display() - ), - ) - .await; + Err(message) => { + self.send_internal_error(request_id, message).await; return; } - } - } else { - None - }; + }; let thread = match self.read_thread_view(thread_uuid, false).await { Ok(thread) => thread, Err(ThreadReadViewError::InvalidRequest(message)) => { @@ -248,26 +238,14 @@ impl CodexMessageProcessor { }; let loaded_thread = self.thread_manager.get_thread(thread_uuid).await.ok(); - let memory_graph_snapshot = if let Some(loaded_thread) = loaded_thread.as_ref() { - let config_snapshot = loaded_thread.config_snapshot().await; - let store_path = memory_graph_store_path(config_snapshot.cwd.as_path()); - match load_memory_graph_snapshot(&store_path) { + let memory_graph_snapshot = + match load_thread_memory_graph_snapshot(loaded_thread.as_deref()).await { Ok(snapshot) => snapshot, - Err(err) => { - self.send_internal_error( - request_id, - format!( - "failed to load Epiphany memory graph store {}: {err}", - store_path.display() - ), - ) - .await; + Err(message) => { + self.send_internal_error(request_id, message).await; return; } - } - } else { - None - }; + }; let thread = match self.read_thread_view(thread_uuid, false).await { Ok(thread) => thread, Err(ThreadReadViewError::InvalidRequest(message)) => { @@ -328,26 +306,14 @@ impl CodexMessageProcessor { let loaded_thread = self.thread_manager.get_thread(thread_uuid).await.ok(); let loaded = loaded_thread.is_some(); - let memory_graph_snapshot = if let Some(loaded_thread) = loaded_thread.as_ref() { - let config_snapshot = loaded_thread.config_snapshot().await; - let store_path = memory_graph_store_path(config_snapshot.cwd.as_path()); - match load_memory_graph_snapshot(&store_path) { + let memory_graph_snapshot = + match load_thread_memory_graph_snapshot(loaded_thread.as_deref()).await { Ok(snapshot) => snapshot, - Err(err) => { - self.send_internal_error( - request_id, - format!( - "failed to load Epiphany memory graph store {}: {err}", - store_path.display() - ), - ) - .await; + Err(message) => { + self.send_internal_error(request_id, message).await; return; } - } - } else { - None - }; + }; let thread = match self.read_thread_view(thread_uuid, false).await { Ok(thread) => thread, Err(ThreadReadViewError::InvalidRequest(message)) => { @@ -387,26 +353,14 @@ impl CodexMessageProcessor { let loaded_thread = self.thread_manager.get_thread(thread_uuid).await.ok(); let loaded = loaded_thread.is_some(); - let memory_graph_snapshot = if let Some(loaded_thread) = loaded_thread.as_ref() { - let config_snapshot = loaded_thread.config_snapshot().await; - let store_path = memory_graph_store_path(config_snapshot.cwd.as_path()); - match load_memory_graph_snapshot(&store_path) { + let memory_graph_snapshot = + match load_thread_memory_graph_snapshot(loaded_thread.as_deref()).await { Ok(snapshot) => snapshot, - Err(err) => { - self.send_internal_error( - request_id, - format!( - "failed to load Epiphany memory graph store {}: {err}", - store_path.display() - ), - ) - .await; + Err(message) => { + self.send_internal_error(request_id, message).await; return; } - } - } else { - None - }; + }; let thread = match self.read_thread_view(thread_uuid, false).await { Ok(thread) => thread, Err(ThreadReadViewError::InvalidRequest(message)) => { @@ -648,3 +602,19 @@ impl CodexMessageProcessor { self.outgoing.send_response(request_id, response).await; } } + +async fn load_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() + ) + }) +}