From 17489f466442d9d1a50804e44667a303f90379f0 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Wed, 13 May 2026 10:05:42 +0100 Subject: [PATCH] Move result read projections into bridge --- epiphany-codex-bridge/src/view.rs | 107 ++++++++++++++++ notes/fresh-workspace-handoff.md | 10 +- state/ledgers.msgpack | Bin 90342 -> 90624 bytes state/map.yaml | 2 +- .../epiphany_read_routes.rs | 114 +++--------------- 5 files changed, 136 insertions(+), 97 deletions(-) diff --git a/epiphany-codex-bridge/src/view.rs b/epiphany-codex-bridge/src/view.rs index e8563544..d01e28ea 100644 --- a/epiphany-codex-bridge/src/view.rs +++ b/epiphany-codex-bridge/src/view.rs @@ -21,6 +21,7 @@ use crate::reorient::EpiphanyFreshnessWatcherSnapshot; use crate::reorient::map_epiphany_freshness; use crate::reorient::map_epiphany_reorient; use crate::runtime_results::load_epiphany_reorient_result_snapshot; +use crate::runtime_results::load_epiphany_role_result_snapshot; use crate::scene::map_core_epiphany_scene_action; use crate::scene::map_epiphany_scene; @@ -312,3 +313,109 @@ pub async fn map_epiphany_view_response( lenses, } } + +pub struct EpiphanyRoleResultResponseInput<'a> { + pub thread_id: String, + pub role_id: ThreadEpiphanyRoleId, + pub source: ThreadEpiphanyRolesSource, + pub binding_id: String, + pub state: Option<&'a EpiphanyThreadState>, + pub runtime_store_path: Option<&'a Path>, +} + +pub async fn map_epiphany_role_result_response( + input: EpiphanyRoleResultResponseInput<'_>, +) -> ThreadEpiphanyRoleResultResponse { + let EpiphanyRoleResultResponseInput { + thread_id, + role_id, + source, + binding_id, + state, + runtime_store_path, + } = input; + let Some(state) = state else { + return ThreadEpiphanyRoleResultResponse { + thread_id, + role_id, + source, + state_status: ThreadEpiphanyReorientStateStatus::Missing, + state_revision: None, + binding_id, + status: ThreadEpiphanyRoleResultStatus::MissingState, + job: None, + finding: None, + note: "No authoritative Epiphany state exists for this thread.".to_string(), + }; + }; + + let job = map_epiphany_jobs(Some(state), None) + .into_iter() + .find(|job| job.id == binding_id); + let (status, finding, note) = + load_epiphany_role_result_snapshot(state, runtime_store_path, role_id, &binding_id).await; + + ThreadEpiphanyRoleResultResponse { + thread_id, + role_id, + source, + state_status: ThreadEpiphanyReorientStateStatus::Ready, + state_revision: Some(state.revision), + binding_id, + status, + job, + finding, + note, + } +} + +pub struct EpiphanyReorientResultResponseInput<'a> { + pub thread_id: String, + pub source: ThreadEpiphanyReorientSource, + pub binding_id: String, + pub state: Option<&'a EpiphanyThreadState>, + pub runtime_store_path: Option<&'a Path>, +} + +pub async fn map_epiphany_reorient_result_response( + input: EpiphanyReorientResultResponseInput<'_>, +) -> ThreadEpiphanyReorientResultResponse { + let EpiphanyReorientResultResponseInput { + thread_id, + source, + binding_id, + state, + runtime_store_path, + } = input; + let Some(state) = state else { + return ThreadEpiphanyReorientResultResponse { + thread_id, + source, + state_status: ThreadEpiphanyReorientStateStatus::Missing, + state_revision: None, + binding_id, + status: ThreadEpiphanyReorientResultStatus::MissingState, + job: None, + finding: None, + note: "No authoritative Epiphany state exists for this thread.".to_string(), + }; + }; + + let job = map_epiphany_jobs(Some(state), None) + .into_iter() + .find(|job| job.id == binding_id); + let (status, finding, note) = + load_epiphany_reorient_result_snapshot(Some(state), runtime_store_path, &binding_id).await; + + ThreadEpiphanyReorientResultResponse { + thread_id, + source, + state_status: ThreadEpiphanyReorientStateStatus::Ready, + state_revision: Some(state.revision), + binding_id, + status, + job, + finding, + note, + } +} diff --git a/notes/fresh-workspace-handoff.md b/notes/fresh-workspace-handoff.md index 05dd786c..0cd496b0 100644 --- a/notes/fresh-workspace-handoff.md +++ b/notes/fresh-workspace-handoff.md @@ -703,8 +703,14 @@ parses the thread id, loads live/stored thread state, registers watcher input, fetches token usage, and obtains the runtime-spine store path. The actual lens selection, freshness/pressure/reorient/CRRC/roles/coordinator composition, scene/planning/job projection, and `ThreadEpiphanyViewResponse` construction -now live in `epiphany-codex-bridge::view`. `epiphany_read_routes.rs` is about -722 lines after this cut. The remaining read-route bodies are mostly individual +now live in `epiphany-codex-bridge::view`. The same bridge view module now owns +role/reorient result response construction too: it loads the mapped +runtime-spine status/finding, projects the matching job, and builds +`ThreadEpiphanyRoleResultResponse` / +`ThreadEpiphanyReorientResultResponse`. App-server keeps only role binding +validation, live/stored source selection, runtime-store path lookup, and +response emission for those compatibility verbs. `epiphany_read_routes.rs` is +about 648 lines after these cuts. The remaining read-route bodies are mostly individual legacy read verbs (`roleResult`, `freshness`, `context`, `graphQuery`, `reorientResult`, `retrieve`, `distill`, `propose`) plus host loading and response/error shaping. diff --git a/state/ledgers.msgpack b/state/ledgers.msgpack index 1713a07d5879ef1833093afd592c89388d6902ce..2a195a47ba5515f71049db4742603e66c2197008 100644 GIT binary patch delta 189 zcmaEMkhS3m>jY({#A6#(r!g|VZr;PVeGem}Nc{8#@r;7(mR1I)Rt83sA0E(Rygt3q zlTl={|1S3F%n6Lnk$L&$3i)|Cl?r8vIhiSmC8@>wIr)hx#R^6Fr6s8f$@zIDsTCy( ziFqjsskxaY#XynVg2a-{q|BVml1c@yV1GZ|pa5ruqSWGo{Ji4SVm*bh)S}F^%;_KX l8AX(m6N}RG6_PVjle6_2wip>0nduss>KYn{7(g8r1pt;nLLLAB delta 49 zcmZoT!usqW>jY({gf$ygr!g|VYTm=ReGem}NW56X79#^AGhG8yT|?s#0}CrtQ!8VO FC;-Pi56u7o diff --git a/state/map.yaml b/state/map.yaml index 1256d7c1..4e04841c 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -279,5 +279,5 @@ rejected_paths: reason: making Epiphany cleaner inside Codex still preserves the wrong organ; Codex must be starved down to OpenAI subscription auth/model transport, while Epiphany data and subsystem communication move to typed CultCache/CultNet. current_status: - summary: The Codex starvation pass has five typing receipts, twenty processor cuts, a real physical extraction in `epiphany-codex-bridge`, a source-grounded Codex auth spine inventory, the native `epiphany-openai-adapter` document boundary, a buildable Codex auth/model wrapper in `epiphany-openai-codex-spine`, the first native runtime caller in `epiphany-openai-runtime`, native heartbeat launch planning/job opening in `epiphany-core`, native state-update contract/validation/application in `epiphany-core`, and the route-facing mutation/view/coordinator projection services in `epiphany-codex-bridge`. The bridge owns Codex-facing Epiphany adapters for scene, jobs, context/planning/graph query, retrieval/indexing projection, result projection, runtime-spine result adaptation, launch/prompt doctrine, mutation document mechanics, mutation service update/promote/role-accept/reorient-accept/role-launch/reorient-launch/job-launch/job-interrupt application, live-state projection, pressure/pre-compaction rendering, freshness/reorientation projection, CRRC/coordinator/role-board projection, full `thread/epiphany/view` response construction, coordinator status/view construction, and acceptance/evidence signal helpers. Vendored app-server now retains only `epiphany_invalidation.rs` as a root Epiphany module because watcher lifecycle is still app-server machinery; `codex_message_processor.rs` still contains route dispatch, JSON-RPC response shaping, watcher registration/snapshotting, and notification emission, but its root no longer imports the evacuated Epiphany policy/protocol registry. `epiphany_read_routes.rs` is about 722 lines after the full view-response extraction; `epiphany_mutation_routes.rs` is about 691 lines after the route-load/notification helper cut and index projection move; `epiphany_state_helpers.rs` is down to a 19-line rollout-state loader; and `codex_thread.rs` is about 1,425 lines after state-update law moved native. `epiphany-openai-adapter` defines CultCache `DatabaseEntry` request/event/receipt/auth-status documents with no Codex app-server or generic JSON dependency. `epiphany-openai-codex-spine` projects `AuthManager` / `CodexAuth` into typed `EpiphanyOpenAiAdapterStatus`, maps typed `EpiphanyOpenAiModelRequest` into Codex API `ResponsesApiRequest`, resolves auth/provider through keeper Codex crates, opens HTTP Responses streams through `codex-api`, maps deltas / completion into typed stream events and receipts, and no longer directly depends on `codex-app-server-protocol` just to name auth mode. `epiphany-openai-runtime` writes OpenAI status/request/stream-event/receipt records plus runtime sessions/jobs/results/events into `epiphany-core::runtime_spine_cache`, can emit the assistant text artifact for legacy result consumers, is now the default executor for startup-only repo birth specialists, and now has `run-worker` to load a durable `EpiphanyRuntimeWorkerLaunchRequest`, call the typed OpenAI runtime, persist typed `EpiphanyRuntimeRoleWorkerResult` / `EpiphanyRuntimeReorientWorkerResult` documents, and complete the original heartbeat/specialist runtime job without Codex worker execution; `codex exec` survives only as explicit fallback in repo-birth startup. `epiphany-mvp-coordinator` now invokes `epiphany-openai-runtime run-worker` for launched runtime job ids and no longer creates a second coordinator-owned shadow runtime job/result as a compensator. `epiphany-core::plan_runtime_spine_heartbeat_launch` validates launch contracts/conflicts and projects durable job bindings/runtime links; `epiphany-core::open_runtime_spine_heartbeat_job` owns the initialize-runtime/ensure-session/create-job sequence and now persists `EpiphanyRuntimeWorkerLaunchRequest` CultCache records keyed by runtime job id, with indexed kind/contract fields plus MessagePack-encoded typed launch documents instead of discarding work intent after queue receipt creation; `roleResult` and `reorientResult` now prefer typed worker result documents and fall back only to generic job summaries for older receipts; `epiphany-core::EpiphanyStateUpdate`, `epiphany_state_update_validation_errors`, and `apply_epiphany_state_update` own state-update document shape and mutation law while `codex-core` calls them for compatibility. Vendored `CodexThread::epiphany_launch_job` is now mostly revision check, persistence validation, launch request handoff, and rollout/session writeback for the compatibility route. Vendored `codex-core` no longer has `epiphany_distillation`, `epiphany_promotion`, `epiphany_proposal`, `epiphany_retrieval`, or `epiphany_rollout` husk modules; it re-exports native surfaces from `epiphany-core` directly, and the only rollout adapter left is the real host seam that supplies Codex's turn-boundary predicate. `epiphany-runtime-spine` advertises OpenAI adapter status/model-request/stream-event/receipt CultNet schemas and mutation contracts, so the native caller now has a real storage route instead of only JSON-RPC. MCP itself is correctly JSON at its protocol edge; the target is typed Epiphany intent/result/receipt wrappers around MCP, not replacing MCP JSON. The current OpenAI spine still pulls `codex-api` and a large transport dependency stack, so its next cut is dependency starvation after richer live callers move. + summary: The Codex starvation pass has five typing receipts, twenty-one processor cuts, a real physical extraction in `epiphany-codex-bridge`, a source-grounded Codex auth spine inventory, the native `epiphany-openai-adapter` document boundary, a buildable Codex auth/model wrapper in `epiphany-openai-codex-spine`, the first native runtime caller in `epiphany-openai-runtime`, native heartbeat launch planning/job opening in `epiphany-core`, native state-update contract/validation/application in `epiphany-core`, and the route-facing mutation/view/coordinator projection services in `epiphany-codex-bridge`. The bridge owns Codex-facing Epiphany adapters for scene, jobs, context/planning/graph query, retrieval/indexing projection, result projection, runtime-spine result adaptation, launch/prompt doctrine, mutation document mechanics, mutation service update/promote/role-accept/reorient-accept/role-launch/reorient-launch/job-launch/job-interrupt application, live-state projection, pressure/pre-compaction rendering, freshness/reorientation projection, CRRC/coordinator/role-board projection, full `thread/epiphany/view` response construction, role/reorient result response construction, coordinator status/view construction, and acceptance/evidence signal helpers. Vendored app-server now retains only `epiphany_invalidation.rs` as a root Epiphany module because watcher lifecycle is still app-server machinery; `codex_message_processor.rs` still contains route dispatch, JSON-RPC response shaping, watcher registration/snapshotting, and notification emission, but its root no longer imports the evacuated Epiphany policy/protocol registry. `epiphany_read_routes.rs` is about 648 lines after the full view and result-response extractions; `epiphany_mutation_routes.rs` is about 691 lines after the route-load/notification helper cut and index projection move; `epiphany_state_helpers.rs` is down to a 19-line rollout-state loader; and `codex_thread.rs` is about 1,425 lines after state-update law moved native. `epiphany-openai-adapter` defines CultCache `DatabaseEntry` request/event/receipt/auth-status documents with no Codex app-server or generic JSON dependency. `epiphany-openai-codex-spine` projects `AuthManager` / `CodexAuth` into typed `EpiphanyOpenAiAdapterStatus`, maps typed `EpiphanyOpenAiModelRequest` into Codex API `ResponsesApiRequest`, resolves auth/provider through keeper Codex crates, opens HTTP Responses streams through `codex-api`, maps deltas / completion into typed stream events and receipts, and no longer directly depends on `codex-app-server-protocol` just to name auth mode. `epiphany-openai-runtime` writes OpenAI status/request/stream-event/receipt records plus runtime sessions/jobs/results/events into `epiphany-core::runtime_spine_cache`, can emit the assistant text artifact for legacy result consumers, is now the default executor for startup-only repo birth specialists, and now has `run-worker` to load a durable `EpiphanyRuntimeWorkerLaunchRequest`, call the typed OpenAI runtime, persist typed `EpiphanyRuntimeRoleWorkerResult` / `EpiphanyRuntimeReorientWorkerResult` documents, and complete the original heartbeat/specialist runtime job without Codex worker execution; `codex exec` survives only as explicit fallback in repo-birth startup. `epiphany-mvp-coordinator` now invokes `epiphany-openai-runtime run-worker` for launched runtime job ids and no longer creates a second coordinator-owned shadow runtime job/result as a compensator. `epiphany-core::plan_runtime_spine_heartbeat_launch` validates launch contracts/conflicts and projects durable job bindings/runtime links; `epiphany-core::open_runtime_spine_heartbeat_job` owns the initialize-runtime/ensure-session/create-job sequence and now persists `EpiphanyRuntimeWorkerLaunchRequest` CultCache records keyed by runtime job id, with indexed kind/contract fields plus MessagePack-encoded typed launch documents instead of discarding work intent after queue receipt creation; `roleResult` and `reorientResult` now prefer typed worker result documents and fall back only to generic job summaries for older receipts; `epiphany-core::EpiphanyStateUpdate`, `epiphany_state_update_validation_errors`, and `apply_epiphany_state_update` own state-update document shape and mutation law while `codex-core` calls them for compatibility. Vendored `CodexThread::epiphany_launch_job` is now mostly revision check, persistence validation, launch request handoff, and rollout/session writeback for the compatibility route. Vendored `codex-core` no longer has `epiphany_distillation`, `epiphany_promotion`, `epiphany_proposal`, `epiphany_retrieval`, or `epiphany_rollout` husk modules; it re-exports native surfaces from `epiphany-core` directly, and the only rollout adapter left is the real host seam that supplies Codex's turn-boundary predicate. `epiphany-runtime-spine` advertises OpenAI adapter status/model-request/stream-event/receipt CultNet schemas and mutation contracts, so the native caller now has a real storage route instead of only JSON-RPC. MCP itself is correctly JSON at its protocol edge; the target is typed Epiphany intent/result/receipt wrappers around MCP, not replacing MCP JSON. The current OpenAI spine still pulls `codex-api` and a large transport dependency stack, so its next cut is dependency starvation after richer live callers move. next_action: Move remaining coordinator/runtime execution and operator surfaces off app-server JSON-RPC where possible, then shrink the surviving Codex dependency surface to credential refresh, provider/model routing, and the smallest OpenAI Responses call required for Codex subscription compatibility. 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 ee560d00..7e45224f 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 @@ -8,19 +8,20 @@ use codex_core::distill_observation; use codex_protocol::ThreadId; use epiphany_codex_bridge::context::map_epiphany_context; use epiphany_codex_bridge::context::map_epiphany_graph_query; -use epiphany_codex_bridge::jobs::map_epiphany_jobs; use epiphany_codex_bridge::launch::EPIPHANY_REORIENT_LAUNCH_BINDING_ID; use epiphany_codex_bridge::launch::epiphany_role_binding_id; use epiphany_codex_bridge::reorient::map_epiphany_freshness; use epiphany_codex_bridge::retrieve::map_epiphany_retrieve_response; -use epiphany_codex_bridge::runtime_results::load_epiphany_reorient_result_snapshot; -use epiphany_codex_bridge::runtime_results::load_epiphany_role_result_snapshot; +use epiphany_codex_bridge::view::EpiphanyReorientResultResponseInput; +use epiphany_codex_bridge::view::EpiphanyRoleResultResponseInput; use epiphany_codex_bridge::view::EpiphanyViewResponseInput; use epiphany_codex_bridge::view::default_epiphany_view_lenses; use epiphany_codex_bridge::view::epiphany_view_needs_jobs; use epiphany_codex_bridge::view::epiphany_view_needs_pressure; use epiphany_codex_bridge::view::epiphany_view_needs_reorientation_inputs; use epiphany_codex_bridge::view::epiphany_view_needs_runtime_store; +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 super::CodexMessageProcessor; @@ -185,26 +186,6 @@ impl CodexMessageProcessor { } else { ThreadEpiphanyRolesSource::Stored }; - let Some(state) = thread.epiphany_state.as_ref() else { - self.outgoing - .send_response( - request_id, - ThreadEpiphanyRoleResultResponse { - thread_id: thread_uuid.to_string(), - role_id, - source, - state_status: ThreadEpiphanyReorientStateStatus::Missing, - state_revision: None, - binding_id, - status: ThreadEpiphanyRoleResultStatus::MissingState, - job: None, - finding: None, - note: "No authoritative Epiphany state exists for this thread.".to_string(), - }, - ) - .await; - return; - }; if let Err(message) = epiphany_role_binding_id(role_id) { self.send_invalid_request_error(request_id, message).await; @@ -216,34 +197,17 @@ impl CodexMessageProcessor { } else { None }; - let job = map_epiphany_jobs(Some(state), None) - .into_iter() - .find(|job| job.id == binding_id); - let (status, finding, note) = load_epiphany_role_result_snapshot( - state, - runtime_store_path.as_deref(), + let response = map_epiphany_role_result_response(EpiphanyRoleResultResponseInput { + thread_id: thread_uuid.to_string(), role_id, - &binding_id, - ) + source, + binding_id, + state: thread.epiphany_state.as_ref(), + runtime_store_path: runtime_store_path.as_deref(), + }) .await; - self.outgoing - .send_response( - request_id, - ThreadEpiphanyRoleResultResponse { - thread_id: thread_uuid.to_string(), - role_id, - source, - state_status: ThreadEpiphanyReorientStateStatus::Ready, - state_revision: Some(state.revision), - binding_id, - status, - job, - finding, - note, - }, - ) - .await; + self.outgoing.send_response(request_id, response).await; } pub(super) async fn thread_epiphany_freshness( @@ -446,59 +410,21 @@ impl CodexMessageProcessor { } else { ThreadEpiphanyReorientSource::Stored }; - let Some(state) = thread.epiphany_state.as_ref() else { - self.outgoing - .send_response( - request_id, - ThreadEpiphanyReorientResultResponse { - thread_id: thread_uuid.to_string(), - source, - state_status: ThreadEpiphanyReorientStateStatus::Missing, - state_revision: None, - binding_id, - status: ThreadEpiphanyReorientResultStatus::MissingState, - job: None, - finding: None, - note: "No authoritative Epiphany state exists for this thread.".to_string(), - }, - ) - .await; - return; - }; - - let state_revision = Some(state.revision); let runtime_store_path = if let Some(loaded_thread) = loaded_thread.as_ref() { Some(loaded_thread.epiphany_runtime_spine_store_path().await) } else { None }; - let job = map_epiphany_jobs(Some(state), None) - .into_iter() - .find(|job| job.id == binding_id); - - let (status, finding, note) = load_epiphany_reorient_result_snapshot( - Some(state), - runtime_store_path.as_deref(), - binding_id.as_str(), - ) + let response = map_epiphany_reorient_result_response(EpiphanyReorientResultResponseInput { + thread_id: thread_uuid.to_string(), + source, + binding_id, + state: thread.epiphany_state.as_ref(), + runtime_store_path: runtime_store_path.as_deref(), + }) .await; - self.outgoing - .send_response( - request_id, - ThreadEpiphanyReorientResultResponse { - thread_id: thread_uuid.to_string(), - source, - state_status: ThreadEpiphanyReorientStateStatus::Ready, - state_revision, - binding_id, - status, - job, - finding, - note, - }, - ) - .await; + self.outgoing.send_response(request_id, response).await; } pub(super) async fn thread_epiphany_retrieve(