Move update promote protocol shaping into bridge

This commit is contained in:
Meta Vens 2026-06-09 13:32:00 +01:00
commit 946145a85e
6 changed files with 163 additions and 74 deletions

View file

@ -32,6 +32,8 @@ use codex_app_server_protocol::ThreadEpiphanyPressure;
use codex_app_server_protocol::ThreadEpiphanyPressureBasis;
use codex_app_server_protocol::ThreadEpiphanyPressureLevel;
use codex_app_server_protocol::ThreadEpiphanyPressureStatus;
use codex_app_server_protocol::ThreadEpiphanyPromoteParams;
use codex_app_server_protocol::ThreadEpiphanyPromoteResponse;
use codex_app_server_protocol::ThreadEpiphanyReorientAcceptParams;
use codex_app_server_protocol::ThreadEpiphanyReorientAction;
use codex_app_server_protocol::ThreadEpiphanyReorientCheckpointStatus;
@ -56,7 +58,9 @@ use codex_app_server_protocol::ThreadEpiphanyRolesSource;
use codex_app_server_protocol::ThreadEpiphanyStateUpdatedField;
use codex_app_server_protocol::ThreadEpiphanyStateUpdatedNotification;
use codex_app_server_protocol::ThreadEpiphanyStateUpdatedSource;
use codex_app_server_protocol::ThreadEpiphanyUpdateParams;
use codex_app_server_protocol::ThreadEpiphanyUpdatePatch;
use codex_app_server_protocol::ThreadEpiphanyUpdateResponse;
use codex_app_server_protocol::ThreadEpiphanyViewLens;
use codex_app_server_protocol::ThreadEpiphanyWorkerLaunchDocument;
use epiphany_core::EPIPHANY_REORIENT_LAUNCH_BINDING_ID;
@ -92,6 +96,9 @@ use epiphany_core::epiphany_view_needs_reorientation_inputs;
use epiphany_core::epiphany_view_needs_runtime_store;
use epiphany_state_model::EpiphanyThreadState;
use crate::mutation_service::EpiphanyThreadPromoteApplied;
use crate::mutation_service::EpiphanyThreadUpdateApplied;
pub fn default_core_epiphany_view_lenses() -> Vec<EpiphanyViewLens> {
default_epiphany_view_lenses()
}
@ -459,6 +466,107 @@ pub fn plan_thread_epiphany_job_launch(
}
}
pub struct ThreadEpiphanyUpdatePlan {
pub thread_id: String,
pub expected_revision: Option<u64>,
pub patch: EpiphanyRoleStatePatchDocument,
}
pub fn plan_thread_epiphany_update(params: ThreadEpiphanyUpdateParams) -> ThreadEpiphanyUpdatePlan {
let ThreadEpiphanyUpdateParams {
thread_id,
expected_revision,
patch,
} = params;
ThreadEpiphanyUpdatePlan {
thread_id,
expected_revision,
patch: protocol_update_patch_to_core(&patch),
}
}
pub struct ThreadEpiphanyPromotePlan {
pub thread_id: String,
pub expected_revision: Option<u64>,
pub patch: EpiphanyRoleStatePatchDocument,
pub verifier_evidence: epiphany_state_model::EpiphanyEvidenceRecord,
}
pub fn plan_thread_epiphany_promote(
params: ThreadEpiphanyPromoteParams,
) -> ThreadEpiphanyPromotePlan {
let ThreadEpiphanyPromoteParams {
thread_id,
expected_revision,
patch,
verifier_evidence,
} = params;
ThreadEpiphanyPromotePlan {
thread_id,
expected_revision,
patch: protocol_update_patch_to_core(&patch),
verifier_evidence,
}
}
pub struct ThreadEpiphanyUpdateRouteOutput {
pub response: ThreadEpiphanyUpdateResponse,
pub changed_fields: Vec<EpiphanyStateUpdatedField>,
pub epiphany_state: EpiphanyThreadState,
}
pub fn thread_epiphany_update_output(
applied: EpiphanyThreadUpdateApplied,
) -> ThreadEpiphanyUpdateRouteOutput {
let changed_fields = applied.changed_fields;
let epiphany_state = applied.epiphany_state;
let response = ThreadEpiphanyUpdateResponse {
revision: applied.revision,
changed_fields: protocol_state_updated_fields(changed_fields.clone()),
epiphany_state: epiphany_state.clone(),
};
ThreadEpiphanyUpdateRouteOutput {
response,
changed_fields,
epiphany_state,
}
}
pub struct ThreadEpiphanyPromoteRouteOutput {
pub response: ThreadEpiphanyPromoteResponse,
pub accepted: Option<ThreadEpiphanyUpdateRouteOutput>,
}
pub fn thread_epiphany_promote_output(
applied: EpiphanyThreadPromoteApplied,
) -> ThreadEpiphanyPromoteRouteOutput {
match applied {
EpiphanyThreadPromoteApplied::Rejected { reasons } => ThreadEpiphanyPromoteRouteOutput {
response: ThreadEpiphanyPromoteResponse {
accepted: false,
reasons,
revision: None,
changed_fields: Vec::new(),
epiphany_state: None,
},
accepted: None,
},
EpiphanyThreadPromoteApplied::Accepted(applied) => {
let accepted = thread_epiphany_update_output(applied);
ThreadEpiphanyPromoteRouteOutput {
response: ThreadEpiphanyPromoteResponse {
accepted: true,
reasons: Vec::new(),
revision: Some(accepted.response.revision),
changed_fields: accepted.response.changed_fields.clone(),
epiphany_state: Some(accepted.epiphany_state.clone()),
},
accepted: Some(accepted),
}
}
}
}
pub fn protocol_state_updated_fields(
fields: Vec<EpiphanyStateUpdatedField>,
) -> Vec<ThreadEpiphanyStateUpdatedField> {

View file

@ -19,8 +19,8 @@ The spine exists in more than twenty-five live paths:
- client read hydration: app-server thread views attach live or reconstructed `thread.epiphanyState` in [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4706) and [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4822).
- explicit distillation proposals: app-server routes read-only `thread/epiphany/distill` through a loaded-thread handler into `epiphany-core` so one explicit observation can become a patch candidate without mutating state; tool/command/shell/model sources now get typed evidence kinds and bounded salient-output summaries instead of dumping raw output into durable state in [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4358) and [distillation.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/distillation.rs:28).
- explicit map/churn proposals: app-server routes read-only `thread/epiphany/propose` through a loaded-thread handler into `epiphany-core` so verified observations with code refs and accepting recent evidence can be selected explicitly or auto-selected as a bounded path cluster, prioritize the strongest selected observation, focus or extend architecture graph nodes, rescue unanchored graph nodes through strict semantic overlap, carry linked dataflow nodes and incident graph edges into the frontier, update churn candidates with match-kind-aware map-delta judgment and pressure, and still avoid mutation until promotion in [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4429) and [proposal.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/proposal.rs:115).
- explicit promotion gates: app-server routes `thread/epiphany/promote` through a loaded-thread handler into `epiphany-core` policy evaluation, rejects failed verifier evidence without mutation, applies accepted candidates through the same durable update path, and now treats medium/high/expanded/broadening/semantic churn deltas as needing explicit rationale plus stronger verifier evidence whose kind is token-matched rather than substring-matched; the same gate also validates durable investigation-checkpoint packets, including linked evidence ids, before they can be inked into state in [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4501) and [promotion.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/promotion.rs:33).
- explicit state updates: app-server routes `thread/epiphany/update` through `epiphany-codex-bridge` mutation policy, which rejects malformed appended observation/evidence graph records and structurally invalid replacement fields, including investigation checkpoints that cite missing evidence and planning records with broken ids/source refs/backlog links/draft acceptance criteria, then asks `CodexThread` only to persist the already-mutated typed state snapshot as a `RolloutItem::EpiphanyState` in [mutation_service.rs](E:/Projects/EpiphanyAgent/epiphany-codex-bridge/src/mutation_service.rs:126), [codex_thread.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/core/src/codex_thread.rs:348), and [promotion.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/promotion.rs:44).
- explicit promotion gates: app-server routes `thread/epiphany/promote` through a loaded-thread handler into bridge protocol planning, which converts the protocol patch before `epiphany-core` policy evaluation; rejected verifier evidence returns a bridge-shaped legacy response without mutation, while accepted candidates apply through the same durable update path. Promotion treats medium/high/expanded/broadening/semantic churn deltas as needing explicit rationale plus stronger verifier evidence whose kind is token-matched rather than substring-matched; the same gate also validates durable investigation-checkpoint packets, including linked evidence ids, before they can be inked into state in [protocol_edge.rs](E:/Projects/EpiphanyAgent/epiphany-codex-bridge/src/protocol_edge.rs:438), [mutation_service.rs](E:/Projects/EpiphanyAgent/epiphany-codex-bridge/src/mutation_service.rs:428), and [promotion.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/promotion.rs:33).
- explicit state updates: app-server routes `thread/epiphany/update` through bridge protocol planning, which converts the protocol patch before `epiphany-codex-bridge` mutation policy rejects malformed appended observation/evidence graph records and structurally invalid replacement fields, including investigation checkpoints that cite missing evidence and planning records with broken ids/source refs/backlog links/draft acceptance criteria, then asks `CodexThread` only to persist the already-mutated typed state snapshot as a `RolloutItem::EpiphanyState` in [protocol_edge.rs](E:/Projects/EpiphanyAgent/epiphany-codex-bridge/src/protocol_edge.rs:420), [mutation_service.rs](E:/Projects/EpiphanyAgent/epiphany-codex-bridge/src/mutation_service.rs:126), [codex_thread.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/core/src/codex_thread.rs:348), and [promotion.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/promotion.rs:44).
- live state notifications and write responses: app-server declares experimental `thread/epiphany/stateUpdated` and emits it with the updated typed state, typed `source`, event-level `revision`, and typed `changedFields` after successful direct updates and accepted promotions, but not after rejected promotions; direct `thread/epiphany/update` and accepted `thread/epiphany/promote` responses expose the same revision/change metadata, accepted promotions always report `Evidence` because verifier evidence is appended even when the patch evidence list is empty, and successful write response/notification states now use the same client-visible live projection as `thread/read`, including retrieval-summary backfill when durable state has no persisted retrieval metadata, in [common.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/common.rs:1113), [v2.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs:4354), [v2.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs:4419), [v2.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs:4428), [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4555), [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4608), [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4652), [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4693), [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:11327), and [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:11370).
- scene projection: the `scene` view lens reads the same live/stored Epiphany state view used by `thread/read` and adapts the core scene projection. `epiphany-core` derives the compact client scene with objective, active subgoal, invariant status counts, graph focus/counts, retrieval status, investigation-checkpoint summary counts, observation/evidence summaries, churn, live/stored source, and available control-plane actions without mutating or persisting state in [scene.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/surfaces/scene.rs:1).
- job/progress reflection: the `jobs` view lens reads the same thread view as scene, optionally fills retrieval state for loaded threads with no Epiphany state, and adapts core-derived non-authoritative progress slots for retrieval indexing, graph remap, invariant verification, and bound specialist work. Durable `job_bindings` now act as thin Epiphany-owned authority slots with binding id, kind, scope, owner role, authority scope, linked ids, and optional blocking reason only. Runtime job ids project from `runtime_links` through core job view policy; old `agent_jobs` bindings are sealed instead of live-crawled in [jobs.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/surfaces/jobs.rs:1).

View file

@ -77,7 +77,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.
- Generic update/promote service entry points now accept typed `EpiphanyRoleStatePatchDocument` patches. The bridge protocol edge converts `ThreadEpiphanyUpdatePatch` request cargo and shapes update/promote legacy responses before app-server emits them, so neither vendored app-server nor the mutation service treats the JSON-RPC patch as its native write document.
- Changed-field authority is native now. `EpiphanyStateUpdatedField` lives in `epiphany-core`; bridge mutation results carry that typed enum, while app-server projects it into `ThreadEpiphanyStateUpdatedField` only for JSON-RPC responses and notifications.
- Role launch, role accept, and role-result runtime lookup now use core `EpiphanyRoleResultRoleId` inside the bridge. Role accept and role result now plan protocol role/default binding conversion in the bridge; app-server keeps `ThreadEpiphanyRoleId` only for legacy response shape where needed.
- Reorient launch service results now use typed `EpiphanySurfaceSource`; app-server projects it into `ThreadEpiphanyReorientSource` only for the legacy launch response.
@ -916,6 +916,15 @@ invokes the role launch mutation service, builds the legacy launch response
DTO, and emits the state-updated notification. `epiphany_mutation_routes.rs` is
about 714 lines after this cut.
Update/promote write-route planning and response shaping moved to the bridge
protocol edge. `plan_thread_epiphany_update` and
`plan_thread_epiphany_promote` own protocol patch conversion, while
`thread_epiphany_update_output` and `thread_epiphany_promote_output` own the
legacy response DTOs plus the notification payload handoff for accepted writes.
App-server still loads the thread, calls the mutation service, sends the
response, and emits `stateUpdated`. `epiphany_mutation_routes.rs` is about 686
lines after this cut.
Context and graph-query route-level conversion followed. App-server still
parses thread ids, loads live/stored thread views, and emits JSON-RPC
responses, but `map_thread_epiphany_context_response` and

Binary file not shown.

View file

@ -139,7 +139,7 @@ accepted_design:
- `epiphany-core` and `epiphany-codex-bridge` must not depend directly on vendored `codex-core`. Host-specific Codex concepts belong in vendored app-server host adapters or the thin OpenAI subscription auth/model-transport spine, while native retrieval/state/runtime/mutation policy stays in Epiphany crates.
- The prompt reads typed state through a bounded `<epiphany_state>` developer fragment.
- Clients read typed state through `Thread.epiphanyState`, read-only `thread/epiphany/view` lenses for scene/jobs/roles/planning/pressure/reorient/CRRC/coordinator, freshness through `thread/epiphany/freshness`, targeted state shards through `thread/epiphany/context`, bounded graph traversal through `thread/epiphany/graphQuery`, and reviewable role output through `thread/epiphany/roleResult`. The scene, jobs, roles, planning, pressure, reorient, CRRC, and coordinator read projections now live only as view lenses, not standalone protocol verbs.
- Durable typed state writes route through `thread/epiphany/update`, accepted `thread/epiphany/promote`, `thread/epiphany/reorientAccept`, `thread/epiphany/roleAccept`, or the bounded `thread/epiphany/jobLaunch`, `thread/epiphany/jobInterrupt`, `thread/epiphany/reorientLaunch`, and `thread/epiphany/roleLaunch` authority surfaces when they mutate state or `job_bindings`; jobLaunch request construction plus roleLaunch/roleAccept/reorientAccept protocol/default-binding planning now lives in the bridge protocol edge rather than app-server mutation routes.
- Durable typed state writes route through `thread/epiphany/update`, accepted `thread/epiphany/promote`, `thread/epiphany/reorientAccept`, `thread/epiphany/roleAccept`, or the bounded `thread/epiphany/jobLaunch`, `thread/epiphany/jobInterrupt`, `thread/epiphany/reorientLaunch`, and `thread/epiphany/roleLaunch` authority surfaces when they mutate state or `job_bindings`; update/promote patch conversion and response shaping, jobLaunch request construction, plus roleLaunch/roleAccept/reorientAccept protocol/default-binding planning now live in the bridge protocol edge rather than app-server mutation routes.
- `thread/epiphany/retrieve`, `thread/epiphany/distill`, `thread/epiphany/propose`, `thread/epiphany/freshness`, `thread/epiphany/context`, `thread/epiphany/graphQuery`, and `thread/epiphany/view` stay read-only.
- `thread/epiphany/index` writes the retrieval catalog, not durable Epiphany understanding; catalog is auspex output, not doctrine.
- Qdrant is the preferred persistent semantic backend; BM25 remains the bootstrap/fallback/control path. Qdrant's HTTP API and acknowledgements remain JSON wire edges, but Epiphany-owned retrieval point payloads are typed at the adapter boundary before serialization/deserialization.

View file

@ -6,7 +6,6 @@ use codex_protocol::protocol::EpiphanyThreadState;
use epiphany_codex_bridge::cultnet::EpiphanyStateUpdatedField;
use epiphany_codex_bridge::error::EpiphanyBridgeError;
use epiphany_codex_bridge::invalidation::epiphany_freshness_watcher_snapshot;
use epiphany_codex_bridge::mutation_service::EpiphanyThreadPromoteApplied;
use epiphany_codex_bridge::mutation_service::apply_thread_epiphany_promote;
use epiphany_codex_bridge::mutation_service::apply_thread_epiphany_reorient_accept;
use epiphany_codex_bridge::mutation_service::apply_thread_epiphany_role_accept;
@ -16,9 +15,11 @@ use epiphany_codex_bridge::mutation_service::launch_thread_epiphany_job;
use epiphany_codex_bridge::mutation_service::launch_thread_epiphany_reorient;
use epiphany_codex_bridge::mutation_service::launch_thread_epiphany_role;
use epiphany_codex_bridge::protocol_edge::plan_thread_epiphany_job_launch;
use epiphany_codex_bridge::protocol_edge::plan_thread_epiphany_promote;
use epiphany_codex_bridge::protocol_edge::plan_thread_epiphany_reorient_accept;
use epiphany_codex_bridge::protocol_edge::plan_thread_epiphany_role_accept;
use epiphany_codex_bridge::protocol_edge::plan_thread_epiphany_role_launch;
use epiphany_codex_bridge::protocol_edge::plan_thread_epiphany_update;
use epiphany_codex_bridge::protocol_edge::protocol_job_from_surface;
use epiphany_codex_bridge::protocol_edge::protocol_patch_from_core;
use epiphany_codex_bridge::protocol_edge::protocol_reorient_decision;
@ -28,7 +29,8 @@ use epiphany_codex_bridge::protocol_edge::protocol_reorient_state_status;
use epiphany_codex_bridge::protocol_edge::protocol_role_finding;
use epiphany_codex_bridge::protocol_edge::protocol_state_updated_fields;
use epiphany_codex_bridge::protocol_edge::protocol_state_updated_notification;
use epiphany_codex_bridge::protocol_edge::protocol_update_patch_to_core;
use epiphany_codex_bridge::protocol_edge::thread_epiphany_promote_output;
use epiphany_codex_bridge::protocol_edge::thread_epiphany_update_output;
use epiphany_codex_bridge::retrieve::epiphany_retrieval_state_for_paths;
use epiphany_codex_bridge::retrieve::index_epiphany_retrieval_for_paths;
use epiphany_codex_bridge::retrieve_protocol::protocol_index_response;
@ -445,25 +447,22 @@ impl CodexMessageProcessor {
request_id: ConnectionRequestId,
params: ThreadEpiphanyPromoteParams,
) {
let ThreadEpiphanyPromoteParams {
thread_id,
expected_revision,
patch,
verifier_evidence,
} = params;
let promote_plan = plan_thread_epiphany_promote(params);
let (thread_uuid, thread) = match self.load_epiphany_thread(&request_id, &thread_id).await {
let (thread_uuid, thread) = match self
.load_epiphany_thread(&request_id, &promote_plan.thread_id)
.await
{
Some(thread) => thread,
None => return,
};
let host = EpiphanyCodexThreadHost::new(thread.as_ref());
let core_patch = protocol_update_patch_to_core(&patch);
let applied = match apply_thread_epiphany_promote(
&host,
expected_revision,
core_patch,
verifier_evidence,
promote_plan.expected_revision,
promote_plan.patch,
promote_plan.verifier_evidence,
)
.await
{
@ -482,43 +481,19 @@ impl CodexMessageProcessor {
}
};
let applied = match applied {
EpiphanyThreadPromoteApplied::Accepted(applied) => applied,
EpiphanyThreadPromoteApplied::Rejected { reasons } => {
self.outgoing
.send_response(
request_id,
ThreadEpiphanyPromoteResponse {
accepted: false,
reasons,
revision: None,
changed_fields: Vec::new(),
epiphany_state: None,
},
)
.await;
return;
}
};
let changed_fields = applied.changed_fields;
let protocol_changed_fields = protocol_state_updated_fields(changed_fields.clone());
let epiphany_state = applied.epiphany_state;
let response = ThreadEpiphanyPromoteResponse {
accepted: true,
reasons: Vec::new(),
revision: Some(applied.revision),
changed_fields: protocol_changed_fields,
epiphany_state: Some(epiphany_state.clone()),
};
self.outgoing.send_response(request_id, response).await;
self.send_epiphany_state_updated(
thread_uuid,
ThreadEpiphanyStateUpdatedSource::Promote,
changed_fields,
epiphany_state,
)
.await;
let output = thread_epiphany_promote_output(applied);
self.outgoing
.send_response(request_id, output.response)
.await;
if let Some(accepted) = output.accepted {
self.send_epiphany_state_updated(
thread_uuid,
ThreadEpiphanyStateUpdatedSource::Promote,
accepted.changed_fields,
accepted.epiphany_state,
)
.await;
}
}
pub(super) async fn thread_epiphany_update(
@ -526,20 +501,23 @@ impl CodexMessageProcessor {
request_id: ConnectionRequestId,
params: ThreadEpiphanyUpdateParams,
) {
let ThreadEpiphanyUpdateParams {
thread_id,
expected_revision,
patch,
} = params;
let update_plan = plan_thread_epiphany_update(params);
let (thread_uuid, thread) = match self.load_epiphany_thread(&request_id, &thread_id).await {
let (thread_uuid, thread) = match self
.load_epiphany_thread(&request_id, &update_plan.thread_id)
.await
{
Some(thread) => thread,
None => return,
};
let host = EpiphanyCodexThreadHost::new(thread.as_ref());
let core_patch = protocol_update_patch_to_core(&patch);
let applied = match apply_thread_epiphany_update(&host, expected_revision, core_patch).await
let applied = match apply_thread_epiphany_update(
&host,
update_plan.expected_revision,
update_plan.patch,
)
.await
{
Ok(applied) => applied,
Err(EpiphanyBridgeError::InvalidRequest(message)) => {
@ -555,21 +533,15 @@ impl CodexMessageProcessor {
return;
}
};
let changed_fields = applied.changed_fields;
let protocol_changed_fields = protocol_state_updated_fields(changed_fields.clone());
let epiphany_state = applied.epiphany_state;
let response = ThreadEpiphanyUpdateResponse {
revision: applied.revision,
changed_fields: protocol_changed_fields,
epiphany_state: epiphany_state.clone(),
};
self.outgoing.send_response(request_id, response).await;
let output = thread_epiphany_update_output(applied);
self.outgoing
.send_response(request_id, output.response)
.await;
self.send_epiphany_state_updated(
thread_uuid,
ThreadEpiphanyStateUpdatedSource::Update,
changed_fields,
epiphany_state,
output.changed_fields,
output.epiphany_state,
)
.await;
}