From 01d6a55b14f172045d8f0015613a1c7d43079e42 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Wed, 20 May 2026 02:28:52 +0100 Subject: [PATCH] Keep update patches typed in mutation service --- epiphany-codex-bridge/src/mutation.rs | 8 +-- epiphany-codex-bridge/src/mutation_service.rs | 14 +++--- notes/fresh-workspace-handoff.md | 1 + state/ledgers.msgpack | Bin 137387 -> 137636 bytes state/map.yaml | 8 +-- .../epiphany_mutation_routes.rs | 46 ++++++++++-------- 6 files changed, 45 insertions(+), 32 deletions(-) diff --git a/epiphany-codex-bridge/src/mutation.rs b/epiphany-codex-bridge/src/mutation.rs index 769df1e9..08c2359d 100644 --- a/epiphany-codex-bridge/src/mutation.rs +++ b/epiphany-codex-bridge/src/mutation.rs @@ -305,7 +305,9 @@ pub fn epiphany_job_launch_changed_fields() -> Vec bool { +pub fn thread_epiphany_patch_has_state_replacements( + patch: &EpiphanyRoleStatePatchDocument, +) -> bool { patch.objective.is_some() || patch.active_subgoal_id.is_some() || patch.subgoals.is_some() @@ -382,9 +384,9 @@ pub fn epiphany_update_patch_changed_fields( } pub fn epiphany_promote_changed_fields( - patch: &ThreadEpiphanyUpdatePatch, + patch: &EpiphanyRoleStatePatchDocument, ) -> Vec { - let mut fields = epiphany_update_patch_changed_fields(patch); + let mut fields = epiphany_update_patch_changed_fields(&protocol_patch_from_core(patch.clone())); if !fields.contains(&ThreadEpiphanyStateUpdatedField::Evidence) { fields.push(ThreadEpiphanyStateUpdatedField::Evidence); } diff --git a/epiphany-codex-bridge/src/mutation_service.rs b/epiphany-codex-bridge/src/mutation_service.rs index 0d43a66e..1b004b9d 100644 --- a/epiphany-codex-bridge/src/mutation_service.rs +++ b/epiphany-codex-bridge/src/mutation_service.rs @@ -6,7 +6,6 @@ use std::path::PathBuf; use codex_app_server_protocol::ThreadEpiphanyReorientSource; use codex_app_server_protocol::ThreadEpiphanyRoleId; use codex_app_server_protocol::ThreadEpiphanyStateUpdatedField; -use codex_app_server_protocol::ThreadEpiphanyUpdatePatch; use epiphany_core::EpiphanyJobInterruptRequest; use epiphany_core::EpiphanyJobInterruptResult; use epiphany_core::EpiphanyJobLaunchRequest; @@ -49,7 +48,6 @@ use crate::mutation::build_role_acceptance_update; use crate::mutation::epiphany_job_launch_changed_fields; use crate::mutation::epiphany_promote_changed_fields; use crate::mutation::epiphany_update_patch_changed_fields; -use crate::mutation::state_update_from_thread_patch; use crate::mutation::thread_epiphany_patch_has_state_replacements; use crate::pressure::derive_epiphany_pressure; use crate::reorient::EpiphanyFreshnessWatcherSnapshot; @@ -313,10 +311,12 @@ pub async fn interrupt_epiphany_job_on_thread( pub async fn apply_thread_epiphany_update( thread: &impl EpiphanyMutationHost, expected_revision: Option, - patch: ThreadEpiphanyUpdatePatch, + patch: EpiphanyRoleStatePatchDocument, ) -> BridgeResult { - let changed_fields = epiphany_update_patch_changed_fields(&patch); - let update = state_update_from_thread_patch(expected_revision, patch); + let changed_fields = epiphany_update_patch_changed_fields( + &crate::mutation::protocol_patch_from_core(patch.clone()), + ); + let update = crate::mutation::state_update_from_core_patch(expected_revision, patch); let epiphany_state = apply_epiphany_state_update_to_thread(thread, update).await?; let epiphany_state = thread.client_visible_epiphany_state(epiphany_state).await; Ok(EpiphanyThreadUpdateApplied { @@ -329,7 +329,7 @@ pub async fn apply_thread_epiphany_update( pub async fn apply_thread_epiphany_promote( thread: &impl EpiphanyMutationHost, expected_revision: Option, - patch: ThreadEpiphanyUpdatePatch, + patch: EpiphanyRoleStatePatchDocument, verifier_evidence: EpiphanyEvidenceRecord, ) -> BridgeResult { let decision = evaluate_promotion(EpiphanyPromotionInput { @@ -355,7 +355,7 @@ pub async fn apply_thread_epiphany_promote( let changed_fields = epiphany_promote_changed_fields(&patch); let mut patch = patch; patch.evidence.push(verifier_evidence); - let update = state_update_from_thread_patch(expected_revision, patch); + let update = crate::mutation::state_update_from_core_patch(expected_revision, patch); let epiphany_state = apply_epiphany_state_update_to_thread(thread, update).await?; let epiphany_state = thread.client_visible_epiphany_state(epiphany_state).await; Ok(EpiphanyThreadPromoteApplied::Accepted( diff --git a/notes/fresh-workspace-handoff.md b/notes/fresh-workspace-handoff.md index ff2e2213..d5b64d6a 100644 --- a/notes/fresh-workspace-handoff.md +++ b/notes/fresh-workspace-handoff.md @@ -60,6 +60,7 @@ remembers doctrine; the branch remembers the blade. - Job reflection is now core-shaped inside the bridge. `map_epiphany_jobs` returns typed `EpiphanyJobView`, role-board/view/result assembly consumes that typed job surface, and `ThreadEpiphanyJob` is projected only when building legacy JSON-RPC response structs. - Context and graph-query derivation now receive core `EpiphanyContextParams` / `EpiphanyGraphQuery` documents. The bridge converts `ThreadEpiphanyContextParams` / `ThreadEpiphanyGraphQuery` before invoking core policy, so Codex JSON-RPC request DTOs no longer define the internal graph question. - Role/reorient acceptance service results now carry core typed findings, and role acceptance carries a typed `EpiphanyRoleStatePatchDocument` for the applied patch. App-server mutation routes project those into `ThreadEpiphany*Finding` / `ThreadEpiphanyUpdatePatch` only for legacy accept responses. +- Generic update/promote service entry points now accept typed `EpiphanyRoleStatePatchDocument` patches. Vendored app-server converts `ThreadEpiphanyUpdatePatch` request cargo before invoking the bridge, so the mutation service no longer treats the JSON-RPC patch as its native write document. - 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. - Codex account auth route handling remains in vendored Codex but now lives in `codex_message_processor/auth_routes.rs`: API-key login, ChatGPT browser/device-code/external-token login, logout, auth status, account, rate limits, and add-credits nudge handling. This preserves Codex ownership of subscription auth while cutting the root processor to about 8,094 lines. - One-off command execution and command stream write/resize/terminate route handling now live in `codex_message_processor/command_routes.rs`; `CommandExecManager` remains the lifecycle owner, while the root processor is about 7,800 lines. diff --git a/state/ledgers.msgpack b/state/ledgers.msgpack index 226a222dcf52a4244207986d38f2556fb0650884..059418d62d014aa21d81ca10b71848994af3dbb1 100644 GIT binary patch delta 215 zcmZ3zkz>hbjtR<4l35#73mF-Enx`|iPiJJ@KAn;2zu0shAtpW+Ln|YT$se{#+ub}B zT9A@hlB!=&l%JbllB!UUSdyHfkX%|~rI1vVnUbEWkXu@kSdy8ar%;?)RF;{Xs*smo zu8^3VoLW#a^$?@FK3GR;u|isYkwPhoVb%(X1qHewZK*{H$@zIes-$@OTSZ1`qr?)0 xl8jUZuV8;a-Jk$xg`(8L($wM-g;b!8dRvSPjLdWmOm&S6LJUAowK6u30sz5DOGN+x delta 52 zcmZ3onPc@vjtR<45``O83mF-^o2N6jPiJJ@KAn;2znJJ2BLgEdT?12HBZCkFLn|Xw ID-+8o0LtJGf&c&j diff --git a/state/map.yaml b/state/map.yaml index 81aa6cb0..1c3387f9 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -336,7 +336,9 @@ current_status: Codex `ThreadEpiphany*` request DTOs are converted before the core graph policy is invoked. Role/reorient acceptance service results now return core finding interpretations and typed role-state patches; app-server projects - them into legacy accept-response DTOs. The bridge still depends on vendored - Codex for app-server protocol DTOs and absolute path validation, so the - purification is not done. + them into legacy accept-response DTOs. Generic update/promote service entry + points now take typed `EpiphanyRoleStatePatchDocument` documents; app-server + converts `ThreadEpiphanyUpdatePatch` request cargo at the JSON-RPC edge. The + bridge still depends on vendored Codex for app-server protocol DTOs and + absolute path validation, so the purification is not done. next_action: Continue Codex starvation and CultNet liberation by cutting bridge-internal `ThreadEpiphany*` authority. Prioritize role-result/reorient-result DTO coupling next: derive typed CultNet surfaces first, push JSON-RPC projection into app-server, and keep MCP/OpenAI JSON only at their true protocol/text edges. Do not add compatibility adapters unless they protect a named ownership invariant. diff --git a/vendor/codex/codex-rs/app-server/src/codex_message_processor/epiphany_mutation_routes.rs b/vendor/codex/codex-rs/app-server/src/codex_message_processor/epiphany_mutation_routes.rs index 004ced4d..f8764f76 100644 --- a/vendor/codex/codex-rs/app-server/src/codex_message_processor/epiphany_mutation_routes.rs +++ b/vendor/codex/codex-rs/app-server/src/codex_message_processor/epiphany_mutation_routes.rs @@ -18,6 +18,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::build_epiphany_job_launch_request; use epiphany_codex_bridge::launch::epiphany_role_binding_id; +use epiphany_codex_bridge::mutation::core_state_patch_from_protocol; use epiphany_codex_bridge::mutation::epiphany_state_updated_notification; use epiphany_codex_bridge::mutation::protocol_patch_from_core; use epiphany_codex_bridge::mutation_service::EpiphanyThreadPromoteApplied; @@ -464,24 +465,29 @@ impl CodexMessageProcessor { }; let host = EpiphanyCodexThreadHost::new(thread.as_ref()); - let applied = - match apply_thread_epiphany_promote(&host, expected_revision, patch, verifier_evidence) - .await - { - Ok(applied) => applied, - Err(EpiphanyBridgeError::InvalidRequest(message)) => { - self.send_invalid_request_error(request_id, message).await; - return; - } - Err(err) => { - self.send_internal_error( - request_id, - format!("failed to promote Epiphany state update: {err}"), - ) - .await; - return; - } - }; + let core_patch = core_state_patch_from_protocol(&patch); + let applied = match apply_thread_epiphany_promote( + &host, + expected_revision, + core_patch, + verifier_evidence, + ) + .await + { + Ok(applied) => applied, + Err(EpiphanyBridgeError::InvalidRequest(message)) => { + self.send_invalid_request_error(request_id, message).await; + return; + } + Err(err) => { + self.send_internal_error( + request_id, + format!("failed to promote Epiphany state update: {err}"), + ) + .await; + return; + } + }; let applied = match applied { EpiphanyThreadPromoteApplied::Accepted(applied) => applied, @@ -538,7 +544,9 @@ impl CodexMessageProcessor { }; let host = EpiphanyCodexThreadHost::new(thread.as_ref()); - let applied = match apply_thread_epiphany_update(&host, expected_revision, patch).await { + let core_patch = core_state_patch_from_protocol(&patch); + let applied = match apply_thread_epiphany_update(&host, expected_revision, core_patch).await + { Ok(applied) => applied, Err(EpiphanyBridgeError::InvalidRequest(message)) => { self.send_invalid_request_error(request_id, message).await;