Move Epiphany update routes into bridge service
This commit is contained in:
parent
410c5c8661
commit
f3ae9f4cb5
6 changed files with 138 additions and 53 deletions
|
|
@ -3,6 +3,7 @@ pub mod coordinator;
|
|||
pub mod jobs;
|
||||
pub mod launch;
|
||||
pub mod mutation;
|
||||
pub mod mutation_service;
|
||||
pub mod pressure;
|
||||
pub mod reorient;
|
||||
pub mod results;
|
||||
|
|
|
|||
84
epiphany-codex-bridge/src/mutation_service.rs
Normal file
84
epiphany-codex-bridge/src/mutation_service.rs
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
use codex_app_server_protocol::ThreadEpiphanyStateUpdatedField;
|
||||
use codex_app_server_protocol::ThreadEpiphanyUpdatePatch;
|
||||
use codex_core::CodexThread;
|
||||
use codex_core::EpiphanyPromotionInput;
|
||||
use codex_core::evaluate_promotion;
|
||||
use codex_protocol::error::CodexErr;
|
||||
use codex_protocol::protocol::EpiphanyEvidenceRecord;
|
||||
use codex_protocol::protocol::EpiphanyThreadState;
|
||||
|
||||
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::state::client_visible_live_thread_epiphany_state;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct EpiphanyThreadUpdateApplied {
|
||||
pub revision: u64,
|
||||
pub changed_fields: Vec<ThreadEpiphanyStateUpdatedField>,
|
||||
pub epiphany_state: EpiphanyThreadState,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum EpiphanyThreadPromoteApplied {
|
||||
Rejected { reasons: Vec<String> },
|
||||
Accepted(EpiphanyThreadUpdateApplied),
|
||||
}
|
||||
|
||||
pub async fn apply_thread_epiphany_update(
|
||||
thread: &CodexThread,
|
||||
expected_revision: Option<u64>,
|
||||
patch: ThreadEpiphanyUpdatePatch,
|
||||
) -> Result<EpiphanyThreadUpdateApplied, CodexErr> {
|
||||
let changed_fields = epiphany_update_patch_changed_fields(&patch);
|
||||
let update = state_update_from_thread_patch(expected_revision, patch);
|
||||
let epiphany_state = thread.epiphany_update_state(update).await?;
|
||||
let epiphany_state = client_visible_live_thread_epiphany_state(thread, epiphany_state).await;
|
||||
Ok(EpiphanyThreadUpdateApplied {
|
||||
revision: epiphany_state.revision,
|
||||
changed_fields,
|
||||
epiphany_state,
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn apply_thread_epiphany_promote(
|
||||
thread: &CodexThread,
|
||||
expected_revision: Option<u64>,
|
||||
patch: ThreadEpiphanyUpdatePatch,
|
||||
verifier_evidence: EpiphanyEvidenceRecord,
|
||||
) -> Result<EpiphanyThreadPromoteApplied, CodexErr> {
|
||||
let decision = evaluate_promotion(EpiphanyPromotionInput {
|
||||
has_state_replacements: thread_epiphany_patch_has_state_replacements(&patch),
|
||||
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(),
|
||||
investigation_checkpoint: patch.investigation_checkpoint.clone(),
|
||||
churn: patch.churn.clone(),
|
||||
observations: patch.observations.clone(),
|
||||
evidence: patch.evidence.clone(),
|
||||
verifier_evidence: verifier_evidence.clone(),
|
||||
});
|
||||
if !decision.accepted {
|
||||
return Ok(EpiphanyThreadPromoteApplied::Rejected {
|
||||
reasons: decision.reasons,
|
||||
});
|
||||
}
|
||||
|
||||
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 epiphany_state = thread.epiphany_update_state(update).await?;
|
||||
let epiphany_state = client_visible_live_thread_epiphany_state(thread, epiphany_state).await;
|
||||
Ok(EpiphanyThreadPromoteApplied::Accepted(
|
||||
EpiphanyThreadUpdateApplied {
|
||||
revision: epiphany_state.revision,
|
||||
changed_fields,
|
||||
epiphany_state,
|
||||
},
|
||||
))
|
||||
}
|
||||
Reference in a new issue