Separate typed mutation application from host persistence

This commit is contained in:
Meta Vens 2026-05-19 14:18:42 +01:00
commit 24158f14d6

View file

@ -129,6 +129,18 @@ pub struct EpiphanyReorientLaunchApplied {
pub async fn apply_epiphany_state_update_to_thread(
thread: &CodexThread,
update: EpiphanyStateUpdate,
) -> Result<EpiphanyThreadState, CodexErr> {
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(&current_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<String>,
) -> Result<EpiphanyThreadState, CodexErr> {
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(