From 1d9607c82ed1f70265ec13bbc0217437847d7963 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Wed, 13 May 2026 01:57:55 +0100 Subject: [PATCH] Extract Epiphany state helpers --- notes/fresh-workspace-handoff.md | 4 + notes/json-contamination-ledger.md | 2 +- state/ledgers.msgpack | Bin 75502 -> 75826 bytes state/map.yaml | 4 +- .../app-server/src/codex_message_processor.rs | 83 ++---------------- .../epiphany_state_helpers.rs | 79 +++++++++++++++++ 6 files changed, 93 insertions(+), 79 deletions(-) create mode 100644 vendor/codex/codex-rs/app-server/src/codex_message_processor/epiphany_state_helpers.rs diff --git a/notes/fresh-workspace-handoff.md b/notes/fresh-workspace-handoff.md index da75f7b2..55ce82a6 100644 --- a/notes/fresh-workspace-handoff.md +++ b/notes/fresh-workspace-handoff.md @@ -458,6 +458,10 @@ The sixteenth cut moved the old in-file processor test tail into `vendor/codex/codex-rs/app-server/src/codex_message_processor/processor_tests.rs`, taking the processor to about 10,502 lines. Treat this as test-ownership relief, not runtime purification by itself. +The seventeenth cut moved live-state hydration, state-patch conversion, +reviewability checks, and rollout-state loading into +`vendor/codex/codex-rs/app-server/src/codex_message_processor/epiphany_state_helpers.rs`, +taking the processor to about 10,433 lines. Also: MCP itself is allowed to be JSON. The target is not "replace MCP JSON"; the target is an Epiphany-owned boundary that speaks typed Epiphany diff --git a/notes/json-contamination-ledger.md b/notes/json-contamination-ledger.md index 8d64b9f1..790ec98e 100644 --- a/notes/json-contamination-ledger.md +++ b/notes/json-contamination-ledger.md @@ -62,6 +62,6 @@ Rule: JSON is allowed at external schema/wire boundaries. Inside Epiphany, live 3. Done: replace role `statePatch` JSON with typed map/planning/graph patch documents. `EpiphanyRoleFindingInterpretation` now carries `EpiphanyRoleStatePatchDocument`; app-server maps it to the legacy protocol patch without JSON round-tripping. 4. Done: replace runtime job result JSON projections. Runtime-spine results now project through typed role/reorient interpreters instead of `runtime_job_result_to_role_json` and `runtime_job_result_to_reorient_json`. 5. Done: replace app-server launch protocol `input_json` / `output_schema_json` with typed launch documents and `output_contract_id`. -6. Continue the whale-carcass cut: the first cuts moved Epiphany launch doctrine and protocol-to-core launch document mapping into `epiphany_launch.rs`, role/reorient result projection into `epiphany_results.rs`, scene projection into `epiphany_scene.rs`, freshness/reorientation mapping into `epiphany_reorient.rs`, context/planning/graph-query projection into `epiphany_context.rs`, jobs projection into `epiphany_jobs.rs`, retrieve projection into `epiphany_retrieve.rs`, pressure/pre-compaction checkpoint projection into `epiphany_pressure.rs`, CRRC/coordinator/role-board projection plus acceptance/evidence signal helpers into `epiphany_coordinator.rs`, Epiphany JSON-RPC route handling under `codex_message_processor/` split into read/proposal routes and mutation/launch/accept/index routes, mutation support helpers into `epiphany_mutation_routes.rs`, runtime-spine result snapshot/adaptation helpers into `epiphany_runtime_results.rs`, automation/pre-compaction orchestration into `epiphany_automation.rs`, and the old processor test tail into `processor_tests.rs`, reducing `codex_message_processor.rs` from about 21,263 to 10,502 lines. Next replace child-module parent visibility with explicit typed service boundaries and move remaining Epiphany prompt/state/runtime helpers out of the processor; success means the processor keeps shrinking and ownership gets clearer, not merely better typed. +6. Continue the whale-carcass cut: the first cuts moved Epiphany launch doctrine and protocol-to-core launch document mapping into `epiphany_launch.rs`, role/reorient result projection into `epiphany_results.rs`, scene projection into `epiphany_scene.rs`, freshness/reorientation mapping into `epiphany_reorient.rs`, context/planning/graph-query projection into `epiphany_context.rs`, jobs projection into `epiphany_jobs.rs`, retrieve projection into `epiphany_retrieve.rs`, pressure/pre-compaction checkpoint projection into `epiphany_pressure.rs`, CRRC/coordinator/role-board projection plus acceptance/evidence signal helpers into `epiphany_coordinator.rs`, Epiphany JSON-RPC route handling under `codex_message_processor/` split into read/proposal routes and mutation/launch/accept/index routes, mutation support helpers into `epiphany_mutation_routes.rs`, runtime-spine result snapshot/adaptation helpers into `epiphany_runtime_results.rs`, automation/pre-compaction orchestration into `epiphany_automation.rs`, state hydration/patch helpers into `epiphany_state_helpers.rs`, and the old processor test tail into `processor_tests.rs`, reducing `codex_message_processor.rs` from about 21,263 to 10,433 lines. Next replace child-module parent visibility with explicit typed service boundaries and move remaining Epiphany imports/dispatch out of the processor where they do not belong; success means the processor keeps shrinking and ownership gets clearer, not merely better typed. 7. Seal MCP payloads behind an Epiphany boundary that speaks typed Epiphany documents internally and MCP JSON externally. 8. Audit heartbeat cognition values and either type them or explicitly expire them. diff --git a/state/ledgers.msgpack b/state/ledgers.msgpack index bbb3741ec50a07ebec846f9b7183223c3ad21b27..7e7ced5b314ad331c348542f9c644aecfad80a9a 100644 GIT binary patch delta 222 zcmaENmSxigmI=yC>OVHBPGe*|(!7Up`yNI{8P(|%Wf_H8OwFxKCO@2^#c_*~Avm=x zHE()@GNW>RPG(uEZgELsNvc9dWlB+ENoIbYjsjRfw;-`3IYS{iKd&scs2D6>lvED$ZeU%J!OpJ{cax(K$i}f0|7#SFu=^B{o8XAWf7+8Va HZ5agslsZns delta 49 zcmdmVf#uy Option { - let mut epiphany_state = thread.epiphany_state().await; - if let Some(state) = epiphany_state.as_mut() - && state.retrieval.is_none() - { - state.retrieval = Some(thread.epiphany_retrieval_state().await); - } - epiphany_state -} - -async fn client_visible_live_thread_epiphany_state( - thread: &CodexThread, - fallback: EpiphanyThreadState, -) -> EpiphanyThreadState { - live_thread_epiphany_state(thread).await.unwrap_or(fallback) -} - -fn core_state_patch_from_protocol( - patch: &ThreadEpiphanyUpdatePatch, -) -> EpiphanyRoleStatePatchDocument { - EpiphanyRoleStatePatchDocument { - objective: patch.objective.clone(), - active_subgoal_id: patch.active_subgoal_id.clone(), - subgoals: patch.subgoals.clone(), - invariants: patch.invariants.clone(), - graphs: patch.graphs.clone(), - graph_frontier: patch.graph_frontier.clone(), - graph_checkpoint: patch.graph_checkpoint.clone(), - scratch: patch.scratch.clone(), - investigation_checkpoint: patch.investigation_checkpoint.clone(), - job_bindings: patch.job_bindings.clone(), - acceptance_receipts: patch.acceptance_receipts.clone(), - runtime_links: patch.runtime_links.clone(), - observations: patch.observations.clone(), - evidence: patch.evidence.clone(), - churn: patch.churn.clone(), - mode: patch.mode.clone(), - planning: patch.planning.clone(), - } -} - -fn epiphany_modeling_finding_has_reviewable_state_patch( - finding: &ThreadEpiphanyRoleFinding, -) -> bool { - finding.role_id == ThreadEpiphanyRoleId::Modeling - && finding - .state_patch - .as_ref() - .is_some_and(|patch| modeling_role_accept_patch_errors(patch).is_empty()) -} - -#[cfg(test)] -fn epiphany_imagination_finding_has_reviewable_state_patch( - finding: &ThreadEpiphanyRoleFinding, -) -> bool { - finding.role_id == ThreadEpiphanyRoleId::Imagination - && finding - .state_patch - .as_ref() - .is_some_and(|patch| imagination_role_accept_patch_errors(patch).is_empty()) -} - pub(crate) fn summary_to_thread( summary: ConversationSummary, fallback_cwd: &AbsolutePathBuf, @@ -10319,20 +10264,6 @@ pub(crate) fn summary_to_thread( } } -async fn load_epiphany_state_from_rollout_path( - rollout_path: &Path, -) -> std::result::Result, String> { - let items = read_rollout_items_from_rollout(rollout_path) - .await - .map_err(|err| { - format!( - "failed to load rollout `{}` for Epiphany state: {err}", - rollout_path.display() - ) - })?; - Ok(latest_epiphany_state_from_rollout_items(&items)) -} - fn thread_backwards_cursor_for_sort_key( summary: &ConversationSummary, sort_key: StoreThreadSortKey, diff --git a/vendor/codex/codex-rs/app-server/src/codex_message_processor/epiphany_state_helpers.rs b/vendor/codex/codex-rs/app-server/src/codex_message_processor/epiphany_state_helpers.rs new file mode 100644 index 00000000..f255fac6 --- /dev/null +++ b/vendor/codex/codex-rs/app-server/src/codex_message_processor/epiphany_state_helpers.rs @@ -0,0 +1,79 @@ +use super::*; + +pub(super) async fn live_thread_epiphany_state( + thread: &CodexThread, +) -> Option { + let mut epiphany_state = thread.epiphany_state().await; + if let Some(state) = epiphany_state.as_mut() + && state.retrieval.is_none() + { + state.retrieval = Some(thread.epiphany_retrieval_state().await); + } + epiphany_state +} + +pub(super) async fn client_visible_live_thread_epiphany_state( + thread: &CodexThread, + fallback: EpiphanyThreadState, +) -> EpiphanyThreadState { + live_thread_epiphany_state(thread).await.unwrap_or(fallback) +} + +pub(super) fn core_state_patch_from_protocol( + patch: &ThreadEpiphanyUpdatePatch, +) -> EpiphanyRoleStatePatchDocument { + EpiphanyRoleStatePatchDocument { + objective: patch.objective.clone(), + active_subgoal_id: patch.active_subgoal_id.clone(), + subgoals: patch.subgoals.clone(), + invariants: patch.invariants.clone(), + graphs: patch.graphs.clone(), + graph_frontier: patch.graph_frontier.clone(), + graph_checkpoint: patch.graph_checkpoint.clone(), + scratch: patch.scratch.clone(), + investigation_checkpoint: patch.investigation_checkpoint.clone(), + job_bindings: patch.job_bindings.clone(), + acceptance_receipts: patch.acceptance_receipts.clone(), + runtime_links: patch.runtime_links.clone(), + observations: patch.observations.clone(), + evidence: patch.evidence.clone(), + churn: patch.churn.clone(), + mode: patch.mode.clone(), + planning: patch.planning.clone(), + } +} + +pub(super) fn epiphany_modeling_finding_has_reviewable_state_patch( + finding: &ThreadEpiphanyRoleFinding, +) -> bool { + finding.role_id == ThreadEpiphanyRoleId::Modeling + && finding + .state_patch + .as_ref() + .is_some_and(|patch| modeling_role_accept_patch_errors(patch).is_empty()) +} + +#[cfg(test)] +pub(super) fn epiphany_imagination_finding_has_reviewable_state_patch( + finding: &ThreadEpiphanyRoleFinding, +) -> bool { + finding.role_id == ThreadEpiphanyRoleId::Imagination + && finding + .state_patch + .as_ref() + .is_some_and(|patch| imagination_role_accept_patch_errors(patch).is_empty()) +} + +pub(super) async fn load_epiphany_state_from_rollout_path( + rollout_path: &Path, +) -> std::result::Result, String> { + let items = read_rollout_items_from_rollout(rollout_path) + .await + .map_err(|err| { + format!( + "failed to load rollout `{}` for Epiphany state: {err}", + rollout_path.display() + ) + })?; + Ok(latest_epiphany_state_from_rollout_items(&items)) +}