Keep changed fields core-shaped

This commit is contained in:
Meta Vens 2026-05-20 02:37:10 +01:00
commit 6d055ab518
10 changed files with 139 additions and 56 deletions

View file

@ -1,7 +1,6 @@
use epiphany_core::EpiphanyGraphFreshness;
use epiphany_core::EpiphanyInvalidationInput;
use epiphany_core::EpiphanyRetrievalFreshness;
pub use epiphany_core::EpiphanyGraphFreshnessStatus;
use epiphany_core::EpiphanyInvalidationInput;
pub use epiphany_core::EpiphanyInvalidationStatus;
pub use epiphany_core::EpiphanyJobStatus;
pub use epiphany_core::EpiphanyJobView;
@ -16,7 +15,9 @@ pub use epiphany_core::EpiphanyReorientFreshnessStatus;
pub use epiphany_core::EpiphanyReorientPressureLevel;
pub use epiphany_core::EpiphanyReorientReason;
pub use epiphany_core::EpiphanyReorientStateStatus;
use epiphany_core::EpiphanyRetrievalFreshness;
pub use epiphany_core::EpiphanyRetrievalFreshnessStatus;
pub use epiphany_core::EpiphanyStateUpdatedField;
pub use epiphany_state_model::EpiphanyJobKind;
use serde::Deserialize;
use serde::Serialize;

View file

@ -9,6 +9,7 @@ use epiphany_core::EpiphanyRoleAcceptanceFinding;
use epiphany_core::EpiphanyRoleFindingInterpretation as CoreEpiphanyRoleFinding;
use epiphany_core::EpiphanyRoleStatePatchDocument;
use epiphany_core::EpiphanyStateUpdate;
use epiphany_core::EpiphanyStateUpdatedField;
use epiphany_core::build_reorient_acceptance_bundle;
use epiphany_core::build_role_acceptance_bundle;
use epiphany_core::imagination_role_state_patch_policy_errors;
@ -20,7 +21,7 @@ use crate::results::map_core_role_result_role_id;
pub struct RoleAcceptanceUpdate {
pub state_update: EpiphanyStateUpdate,
pub applied_patch: EpiphanyRoleStatePatchDocument,
pub changed_fields: Vec<ThreadEpiphanyStateUpdatedField>,
pub changed_fields: Vec<EpiphanyStateUpdatedField>,
pub accepted_receipt_id: String,
pub accepted_observation_id: String,
pub accepted_evidence_id: String,
@ -28,7 +29,7 @@ pub struct RoleAcceptanceUpdate {
pub struct ReorientAcceptanceUpdate {
pub state_update: EpiphanyStateUpdate,
pub changed_fields: Vec<ThreadEpiphanyStateUpdatedField>,
pub changed_fields: Vec<EpiphanyStateUpdatedField>,
pub accepted_receipt_id: String,
pub accepted_observation_id: String,
pub accepted_evidence_id: String,
@ -128,18 +129,59 @@ pub fn epiphany_state_updated_notification(
thread_id: String,
source: ThreadEpiphanyStateUpdatedSource,
revision: u64,
changed_fields: Vec<ThreadEpiphanyStateUpdatedField>,
changed_fields: Vec<EpiphanyStateUpdatedField>,
epiphany_state: epiphany_state_model::EpiphanyThreadState,
) -> ThreadEpiphanyStateUpdatedNotification {
ThreadEpiphanyStateUpdatedNotification {
thread_id,
source,
revision,
changed_fields,
changed_fields: map_protocol_state_updated_fields(changed_fields),
epiphany_state,
}
}
pub fn map_protocol_state_updated_fields(
fields: Vec<EpiphanyStateUpdatedField>,
) -> Vec<ThreadEpiphanyStateUpdatedField> {
fields
.into_iter()
.map(map_protocol_state_updated_field)
.collect()
}
pub fn map_protocol_state_updated_field(
field: EpiphanyStateUpdatedField,
) -> ThreadEpiphanyStateUpdatedField {
match field {
EpiphanyStateUpdatedField::Objective => ThreadEpiphanyStateUpdatedField::Objective,
EpiphanyStateUpdatedField::ActiveSubgoalId => {
ThreadEpiphanyStateUpdatedField::ActiveSubgoalId
}
EpiphanyStateUpdatedField::Subgoals => ThreadEpiphanyStateUpdatedField::Subgoals,
EpiphanyStateUpdatedField::Invariants => ThreadEpiphanyStateUpdatedField::Invariants,
EpiphanyStateUpdatedField::Graphs => ThreadEpiphanyStateUpdatedField::Graphs,
EpiphanyStateUpdatedField::GraphFrontier => ThreadEpiphanyStateUpdatedField::GraphFrontier,
EpiphanyStateUpdatedField::GraphCheckpoint => {
ThreadEpiphanyStateUpdatedField::GraphCheckpoint
}
EpiphanyStateUpdatedField::Scratch => ThreadEpiphanyStateUpdatedField::Scratch,
EpiphanyStateUpdatedField::InvestigationCheckpoint => {
ThreadEpiphanyStateUpdatedField::InvestigationCheckpoint
}
EpiphanyStateUpdatedField::JobBindings => ThreadEpiphanyStateUpdatedField::JobBindings,
EpiphanyStateUpdatedField::AcceptanceReceipts => {
ThreadEpiphanyStateUpdatedField::AcceptanceReceipts
}
EpiphanyStateUpdatedField::RuntimeLinks => ThreadEpiphanyStateUpdatedField::RuntimeLinks,
EpiphanyStateUpdatedField::Observations => ThreadEpiphanyStateUpdatedField::Observations,
EpiphanyStateUpdatedField::Evidence => ThreadEpiphanyStateUpdatedField::Evidence,
EpiphanyStateUpdatedField::Churn => ThreadEpiphanyStateUpdatedField::Churn,
EpiphanyStateUpdatedField::Mode => ThreadEpiphanyStateUpdatedField::Mode,
EpiphanyStateUpdatedField::Planning => ThreadEpiphanyStateUpdatedField::Planning,
}
}
pub fn imagination_role_accept_patch_errors(patch: &ThreadEpiphanyUpdatePatch) -> Vec<String> {
imagination_role_state_patch_policy_errors(&core_state_patch_from_protocol(patch))
}
@ -270,15 +312,15 @@ pub fn build_reorient_acceptance_update(
let investigation_checkpoint = acceptance_bundle.investigation_checkpoint;
let mut changed_fields = vec![
ThreadEpiphanyStateUpdatedField::AcceptanceReceipts,
ThreadEpiphanyStateUpdatedField::Observations,
ThreadEpiphanyStateUpdatedField::Evidence,
EpiphanyStateUpdatedField::AcceptanceReceipts,
EpiphanyStateUpdatedField::Observations,
EpiphanyStateUpdatedField::Evidence,
];
if scratch.is_some() {
changed_fields.push(ThreadEpiphanyStateUpdatedField::Scratch);
changed_fields.push(EpiphanyStateUpdatedField::Scratch);
}
if investigation_checkpoint.is_some() {
changed_fields.push(ThreadEpiphanyStateUpdatedField::InvestigationCheckpoint);
changed_fields.push(EpiphanyStateUpdatedField::InvestigationCheckpoint);
}
Ok(ReorientAcceptanceUpdate {
@ -298,10 +340,10 @@ pub fn build_reorient_acceptance_update(
})
}
pub fn epiphany_job_launch_changed_fields() -> Vec<ThreadEpiphanyStateUpdatedField> {
pub fn epiphany_job_launch_changed_fields() -> Vec<EpiphanyStateUpdatedField> {
vec![
ThreadEpiphanyStateUpdatedField::JobBindings,
ThreadEpiphanyStateUpdatedField::RuntimeLinks,
EpiphanyStateUpdatedField::JobBindings,
EpiphanyStateUpdatedField::RuntimeLinks,
]
}
@ -327,68 +369,68 @@ pub fn thread_epiphany_patch_has_state_replacements(
pub fn epiphany_update_patch_changed_fields(
patch: &ThreadEpiphanyUpdatePatch,
) -> Vec<ThreadEpiphanyStateUpdatedField> {
) -> Vec<EpiphanyStateUpdatedField> {
let mut fields = Vec::new();
if patch.objective.is_some() {
fields.push(ThreadEpiphanyStateUpdatedField::Objective);
fields.push(EpiphanyStateUpdatedField::Objective);
}
if patch.active_subgoal_id.is_some() {
fields.push(ThreadEpiphanyStateUpdatedField::ActiveSubgoalId);
fields.push(EpiphanyStateUpdatedField::ActiveSubgoalId);
}
if patch.subgoals.is_some() {
fields.push(ThreadEpiphanyStateUpdatedField::Subgoals);
fields.push(EpiphanyStateUpdatedField::Subgoals);
}
if patch.invariants.is_some() {
fields.push(ThreadEpiphanyStateUpdatedField::Invariants);
fields.push(EpiphanyStateUpdatedField::Invariants);
}
if patch.graphs.is_some() {
fields.push(ThreadEpiphanyStateUpdatedField::Graphs);
fields.push(EpiphanyStateUpdatedField::Graphs);
}
if patch.graph_frontier.is_some() {
fields.push(ThreadEpiphanyStateUpdatedField::GraphFrontier);
fields.push(EpiphanyStateUpdatedField::GraphFrontier);
}
if patch.graph_checkpoint.is_some() {
fields.push(ThreadEpiphanyStateUpdatedField::GraphCheckpoint);
fields.push(EpiphanyStateUpdatedField::GraphCheckpoint);
}
if patch.scratch.is_some() {
fields.push(ThreadEpiphanyStateUpdatedField::Scratch);
fields.push(EpiphanyStateUpdatedField::Scratch);
}
if patch.investigation_checkpoint.is_some() {
fields.push(ThreadEpiphanyStateUpdatedField::InvestigationCheckpoint);
fields.push(EpiphanyStateUpdatedField::InvestigationCheckpoint);
}
if patch.job_bindings.is_some() {
fields.push(ThreadEpiphanyStateUpdatedField::JobBindings);
fields.push(EpiphanyStateUpdatedField::JobBindings);
}
if !patch.acceptance_receipts.is_empty() {
fields.push(ThreadEpiphanyStateUpdatedField::AcceptanceReceipts);
fields.push(EpiphanyStateUpdatedField::AcceptanceReceipts);
}
if !patch.runtime_links.is_empty() {
fields.push(ThreadEpiphanyStateUpdatedField::RuntimeLinks);
fields.push(EpiphanyStateUpdatedField::RuntimeLinks);
}
if !patch.observations.is_empty() {
fields.push(ThreadEpiphanyStateUpdatedField::Observations);
fields.push(EpiphanyStateUpdatedField::Observations);
}
if !patch.evidence.is_empty() {
fields.push(ThreadEpiphanyStateUpdatedField::Evidence);
fields.push(EpiphanyStateUpdatedField::Evidence);
}
if patch.churn.is_some() {
fields.push(ThreadEpiphanyStateUpdatedField::Churn);
fields.push(EpiphanyStateUpdatedField::Churn);
}
if patch.mode.is_some() {
fields.push(ThreadEpiphanyStateUpdatedField::Mode);
fields.push(EpiphanyStateUpdatedField::Mode);
}
if patch.planning.is_some() {
fields.push(ThreadEpiphanyStateUpdatedField::Planning);
fields.push(EpiphanyStateUpdatedField::Planning);
}
fields
}
pub fn epiphany_promote_changed_fields(
patch: &EpiphanyRoleStatePatchDocument,
) -> Vec<ThreadEpiphanyStateUpdatedField> {
) -> Vec<EpiphanyStateUpdatedField> {
let mut fields = epiphany_update_patch_changed_fields(&protocol_patch_from_core(patch.clone()));
if !fields.contains(&ThreadEpiphanyStateUpdatedField::Evidence) {
fields.push(ThreadEpiphanyStateUpdatedField::Evidence);
if !fields.contains(&EpiphanyStateUpdatedField::Evidence) {
fields.push(EpiphanyStateUpdatedField::Evidence);
}
fields
}

View file

@ -5,7 +5,6 @@ use std::path::PathBuf;
use codex_app_server_protocol::ThreadEpiphanyReorientSource;
use codex_app_server_protocol::ThreadEpiphanyRoleId;
use codex_app_server_protocol::ThreadEpiphanyStateUpdatedField;
use epiphany_core::EpiphanyJobInterruptRequest;
use epiphany_core::EpiphanyJobInterruptResult;
use epiphany_core::EpiphanyJobLaunchRequest;
@ -18,6 +17,7 @@ use epiphany_core::EpiphanyReorientStateStatus;
use epiphany_core::EpiphanyRoleFindingInterpretation;
use epiphany_core::EpiphanyRoleStatePatchDocument;
use epiphany_core::EpiphanyStateUpdate;
use epiphany_core::EpiphanyStateUpdatedField;
use epiphany_core::EpiphanyTokenUsageSnapshot;
use epiphany_core::RuntimeSpineHeartbeatJobOptions;
use epiphany_core::RuntimeSpineHeartbeatLaunchPlanOptions;
@ -75,7 +75,7 @@ pub trait EpiphanyMutationHost {
#[derive(Debug, Clone)]
pub struct EpiphanyThreadUpdateApplied {
pub revision: u64,
pub changed_fields: Vec<ThreadEpiphanyStateUpdatedField>,
pub changed_fields: Vec<EpiphanyStateUpdatedField>,
pub epiphany_state: EpiphanyThreadState,
}
@ -88,7 +88,7 @@ pub enum EpiphanyThreadPromoteApplied {
#[derive(Debug, Clone)]
pub struct EpiphanyRoleAcceptApplied {
pub revision: u64,
pub changed_fields: Vec<ThreadEpiphanyStateUpdatedField>,
pub changed_fields: Vec<EpiphanyStateUpdatedField>,
pub epiphany_state: EpiphanyThreadState,
pub accepted_receipt_id: String,
pub accepted_observation_id: String,
@ -100,7 +100,7 @@ pub struct EpiphanyRoleAcceptApplied {
#[derive(Debug, Clone)]
pub struct EpiphanyReorientAcceptApplied {
pub revision: u64,
pub changed_fields: Vec<ThreadEpiphanyStateUpdatedField>,
pub changed_fields: Vec<EpiphanyStateUpdatedField>,
pub epiphany_state: EpiphanyThreadState,
pub accepted_receipt_id: String,
pub accepted_observation_id: String,
@ -113,7 +113,7 @@ pub struct EpiphanyJobLaunchApplied {
pub launcher_job_id: String,
pub backend_job_id: String,
pub revision: u64,
pub changed_fields: Vec<ThreadEpiphanyStateUpdatedField>,
pub changed_fields: Vec<EpiphanyStateUpdatedField>,
pub epiphany_state: EpiphanyThreadState,
pub job: EpiphanyJobView,
}
@ -123,7 +123,7 @@ pub struct EpiphanyJobInterruptApplied {
pub cancel_requested: bool,
pub interrupted_thread_ids: Vec<String>,
pub revision: u64,
pub changed_fields: Vec<ThreadEpiphanyStateUpdatedField>,
pub changed_fields: Vec<EpiphanyStateUpdatedField>,
pub epiphany_state: EpiphanyThreadState,
pub job: EpiphanyJobView,
}
@ -137,7 +137,7 @@ pub struct EpiphanyReorientLaunchApplied {
pub state_revision: Option<u64>,
pub decision: EpiphanyReorientDecision,
pub revision: u64,
pub changed_fields: Vec<ThreadEpiphanyStateUpdatedField>,
pub changed_fields: Vec<EpiphanyStateUpdatedField>,
pub epiphany_state: EpiphanyThreadState,
pub job: EpiphanyJobView,
}
@ -544,7 +544,7 @@ pub async fn interrupt_thread_epiphany_job(
binding_id: &str,
reason: Option<String>,
) -> BridgeResult<EpiphanyJobInterruptApplied> {
let changed_fields = vec![ThreadEpiphanyStateUpdatedField::JobBindings];
let changed_fields = vec![EpiphanyStateUpdatedField::JobBindings];
let interrupted = interrupt_epiphany_job_on_thread(
thread,
EpiphanyJobInterruptRequest {