From 24158f14d659afa201f74c1537a6074b03165b13 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Tue, 19 May 2026 14:18:42 +0100 Subject: [PATCH] Separate typed mutation application from host persistence --- epiphany-codex-bridge/src/mutation_service.rs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/epiphany-codex-bridge/src/mutation_service.rs b/epiphany-codex-bridge/src/mutation_service.rs index bd3cdc34..fc61c871 100644 --- a/epiphany-codex-bridge/src/mutation_service.rs +++ b/epiphany-codex-bridge/src/mutation_service.rs @@ -129,6 +129,18 @@ pub struct EpiphanyReorientLaunchApplied { pub async fn apply_epiphany_state_update_to_thread( thread: &CodexThread, update: EpiphanyStateUpdate, +) -> Result { + let current_state = thread.epiphany_state().await.unwrap_or_default(); + let reference_turn_id = thread.epiphany_reference_turn_id().await; + let next_state = + apply_epiphany_state_update_to_state(¤t_state, update, reference_turn_id)?; + thread.epiphany_persist_state(next_state).await +} + +pub fn apply_epiphany_state_update_to_state( + current_state: &EpiphanyThreadState, + update: EpiphanyStateUpdate, + reference_turn_id: Option, ) -> Result { if update.is_empty() { return Err(CodexErr::InvalidRequest( @@ -136,7 +148,7 @@ pub async fn apply_epiphany_state_update_to_thread( )); } - let mut next_state = thread.epiphany_state().await.unwrap_or_default(); + let mut next_state = current_state.clone(); if let Some(expected_revision) = update.expected_revision && next_state.revision != expected_revision { @@ -154,9 +166,8 @@ pub async fn apply_epiphany_state_update_to_thread( ))); } - let reference_turn_id = thread.epiphany_reference_turn_id().await; apply_epiphany_state_update(&mut next_state, update, reference_turn_id); - thread.epiphany_persist_state(next_state).await + Ok(next_state) } pub async fn launch_epiphany_job_on_thread(