Move Epiphany state update application into bridge
This commit is contained in:
parent
10a6e7a491
commit
85b6dac130
5 changed files with 62 additions and 61 deletions
|
|
@ -25,6 +25,7 @@ use epiphany_core::EpiphanyStateUpdate;
|
|||
use epiphany_core::RuntimeSpineHeartbeatJobOptions;
|
||||
use epiphany_core::RuntimeSpineHeartbeatLaunchPlanOptions;
|
||||
use epiphany_core::apply_memory_patch_candidate;
|
||||
use epiphany_core::apply_epiphany_state_update;
|
||||
use epiphany_core::clear_epiphany_job_binding_backend;
|
||||
use epiphany_core::epiphany_state_update_validation_errors;
|
||||
use epiphany_core::evaluate_promotion;
|
||||
|
|
@ -131,6 +132,34 @@ pub struct EpiphanyReorientLaunchApplied {
|
|||
pub job: ThreadEpiphanyJob,
|
||||
}
|
||||
|
||||
async fn apply_thread_epiphany_state_update(
|
||||
thread: &CodexThread,
|
||||
update: EpiphanyStateUpdate,
|
||||
) -> Result<EpiphanyThreadState, CodexErr> {
|
||||
if update.is_empty() {
|
||||
return Err(CodexErr::InvalidRequest(
|
||||
"epiphany update patch must contain at least one mutation".to_string(),
|
||||
));
|
||||
}
|
||||
|
||||
let reference_turn_id = thread.epiphany_reference_turn_id().await;
|
||||
let mut next_state = thread.epiphany_state().await.unwrap_or_default();
|
||||
validate_expected_revision(update.expected_revision, next_state.revision)?;
|
||||
|
||||
let validation_errors = epiphany_state_update_validation_errors(&next_state, &update);
|
||||
if !validation_errors.is_empty() {
|
||||
return Err(CodexErr::InvalidRequest(format!(
|
||||
"invalid epiphany update patch: {}",
|
||||
validation_errors.join("; ")
|
||||
)));
|
||||
}
|
||||
|
||||
apply_epiphany_state_update(&mut next_state, update, reference_turn_id.clone());
|
||||
thread
|
||||
.persist_epiphany_state(reference_turn_id, next_state)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn apply_thread_epiphany_update(
|
||||
thread: &CodexThread,
|
||||
expected_revision: Option<u64>,
|
||||
|
|
@ -138,7 +167,7 @@ pub async fn apply_thread_epiphany_update(
|
|||
) -> 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 = apply_thread_epiphany_state_update(thread, update).await?;
|
||||
let epiphany_state = client_visible_live_thread_epiphany_state(thread, epiphany_state).await;
|
||||
Ok(EpiphanyThreadUpdateApplied {
|
||||
revision: epiphany_state.revision,
|
||||
|
|
@ -176,7 +205,7 @@ pub async fn apply_thread_epiphany_promote(
|
|||
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 = apply_thread_epiphany_state_update(thread, update).await?;
|
||||
let epiphany_state = client_visible_live_thread_epiphany_state(thread, epiphany_state).await;
|
||||
Ok(EpiphanyThreadPromoteApplied::Accepted(
|
||||
EpiphanyThreadUpdateApplied {
|
||||
|
|
@ -227,12 +256,11 @@ pub async fn apply_thread_epiphany_role_accept(
|
|||
let accepted_evidence_id = acceptance_update.accepted_evidence_id.clone();
|
||||
let changed_fields = acceptance_update.changed_fields.clone();
|
||||
let applied_patch = acceptance_update.patch.clone();
|
||||
let epiphany_state = thread
|
||||
.epiphany_update_state(state_update_from_thread_patch(
|
||||
expected_revision,
|
||||
acceptance_update.patch,
|
||||
))
|
||||
.await?;
|
||||
let epiphany_state = apply_thread_epiphany_state_update(
|
||||
thread,
|
||||
state_update_from_thread_patch(expected_revision, acceptance_update.patch),
|
||||
)
|
||||
.await?;
|
||||
let epiphany_state = client_visible_live_thread_epiphany_state(thread, epiphany_state).await;
|
||||
|
||||
Ok(EpiphanyRoleAcceptApplied {
|
||||
|
|
@ -363,9 +391,8 @@ pub async fn apply_thread_epiphany_reorient_accept(
|
|||
let accepted_observation_id = acceptance_update.accepted_observation_id.clone();
|
||||
let accepted_evidence_id = acceptance_update.accepted_evidence_id.clone();
|
||||
let changed_fields = acceptance_update.changed_fields.clone();
|
||||
let epiphany_state = thread
|
||||
.epiphany_update_state(acceptance_update.state_update)
|
||||
.await?;
|
||||
let epiphany_state =
|
||||
apply_thread_epiphany_state_update(thread, acceptance_update.state_update).await?;
|
||||
let epiphany_state = client_visible_live_thread_epiphany_state(thread, epiphany_state).await;
|
||||
|
||||
Ok(EpiphanyReorientAcceptApplied {
|
||||
|
|
@ -465,7 +492,7 @@ pub async fn launch_thread_epiphany_job(
|
|||
validation_errors.join("; ")
|
||||
)));
|
||||
}
|
||||
let epiphany_state = thread.epiphany_update_state(update).await?;
|
||||
let epiphany_state = apply_thread_epiphany_state_update(thread, update).await?;
|
||||
let epiphany_state = client_visible_live_thread_epiphany_state(thread, epiphany_state).await;
|
||||
let job = map_launched_epiphany_job(
|
||||
&epiphany_state,
|
||||
|
|
@ -551,13 +578,15 @@ pub async fn interrupt_thread_epiphany_job(
|
|||
binding_index,
|
||||
"No active heartbeat turn is currently bound; launch explicitly to resume specialist work.",
|
||||
);
|
||||
let epiphany_state = thread
|
||||
.epiphany_update_state(EpiphanyStateUpdate {
|
||||
let epiphany_state = apply_thread_epiphany_state_update(
|
||||
thread,
|
||||
EpiphanyStateUpdate {
|
||||
expected_revision,
|
||||
job_bindings: Some(next_job_bindings),
|
||||
..Default::default()
|
||||
})
|
||||
.await?;
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
let epiphany_state = client_visible_live_thread_epiphany_state(thread, epiphany_state).await;
|
||||
let job = map_interrupted_epiphany_job(&epiphany_state, binding_id);
|
||||
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ remembers doctrine; the branch remembers the blade.
|
|||
- Thread config helpers now live in `codex_message_processor/thread_config.rs`: instruction-source loading, thread config override construction, config-load error shaping, and dynamic-tool validation. The pure dynamic-tool validation contract has module-local unit tests.
|
||||
- Turn control routes now live in `codex_message_processor/turn_routes.rs`: turn start, thread item injection, app-server client info setting, turn steer, turn interrupt, mode normalization, and input-limit validation with module-local unit tests.
|
||||
- Epiphany memory graph loading and runtime-spine path derivation now belong to `epiphany-codex-bridge::state`. Vendored app-server read routes may decide whether a loaded thread exists, but they no longer own memory graph or runtime-spine store path/load mechanics.
|
||||
- Epiphany job launch/interrupt policy now belongs to `epiphany-codex-bridge::mutation_service`: heartbeat launch planning, runtime-spine job opening, binding/runtime-link mutation, and interrupt binding cleanup are out of vendored `CodexThread`. `CodexThread` still owns the narrow Codex-session read/update seam for Epiphany state until that persistence seam can be replaced cleanly.
|
||||
- Epiphany job launch/interrupt policy and state-update application now belong to `epiphany-codex-bridge::mutation_service`: heartbeat launch planning, runtime-spine job opening, binding/runtime-link mutation, interrupt binding cleanup, and typed patch apply are out of vendored `CodexThread`. `CodexThread` now exposes only the narrow Codex-session host seam for reading current Epiphany state/reference turn and persisting an already-mutated snapshot into rollout/session storage.
|
||||
- Epiphany retrieval status, indexing, and retrieval execution now belong to `epiphany-codex-bridge::retrieve`; vendored `CodexThread` only exposes cwd/codex-home host facts for that path.
|
||||
- Heartbeat durable document/schema types now live in `epiphany-core/src/heartbeat_state/heartbeat_documents.rs`, role/default construction lives in `epiphany-core/src/heartbeat_state/heartbeat_roles.rs`, persistence/validation lives in `epiphany-core/src/heartbeat_state/heartbeat_store.rs`, and status/artifact JSON projection lives in `epiphany-core/src/heartbeat_state/heartbeat_projection.rs`. The root `heartbeat_state.rs` keeps scheduling and Void cognition orchestration for the next cuts. Focused heartbeat tests and `epiphany-core` check pass after the splits.
|
||||
- Heartbeat role/default and store seams now have module-local unit tests: fixed lane catalog, Ghostlight scene role projection, and typed state/cognition CultCache round-trip. Keep future heartbeat cuts aligned to those seam tests instead of growing root integration-only coverage.
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -26,9 +26,11 @@ objective:
|
|||
compatibility. Memory graph loading and runtime-spine path derivation now
|
||||
live in `epiphany-codex-bridge::state`; vendored app-server route code
|
||||
calls that bridge instead of owning store path/load mechanics itself. Job
|
||||
launch/interrupt policy now lives in
|
||||
launch/interrupt policy and state-update application now live in
|
||||
`epiphany-codex-bridge::mutation_service`; vendored `CodexThread` remains
|
||||
the narrow Codex-session persistence seam for Epiphany state read/update.
|
||||
the narrow Codex-session persistence seam for reading the live Epiphany
|
||||
state and writing an already-mutated snapshot into Codex rollout/session
|
||||
storage.
|
||||
Retrieval status, indexing, and retrieval execution now live in
|
||||
`epiphany-codex-bridge::retrieve`; vendored Codex supplies cwd/codex-home
|
||||
host facts rather than owning Epiphany retrieval behavior.
|
||||
|
|
|
|||
54
vendor/codex/codex-rs/core/src/codex_thread.rs
vendored
54
vendor/codex/codex-rs/core/src/codex_thread.rs
vendored
|
|
@ -34,9 +34,6 @@ use codex_protocol::protocol::TokenUsageInfo;
|
|||
use codex_protocol::protocol::W3cTraceContext;
|
||||
use codex_protocol::user_input::UserInput;
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
use epiphany_core::EpiphanyStateUpdate;
|
||||
use epiphany_core::apply_epiphany_state_update;
|
||||
use epiphany_core::epiphany_state_update_validation_errors;
|
||||
use rmcp::model::ReadResourceRequestParams;
|
||||
use std::collections::HashMap;
|
||||
use std::path::PathBuf;
|
||||
|
|
@ -329,59 +326,32 @@ impl CodexThread {
|
|||
self.codex.session.epiphany_state().await
|
||||
}
|
||||
|
||||
pub async fn epiphany_update_state(
|
||||
&self,
|
||||
update: EpiphanyStateUpdate,
|
||||
) -> CodexResult<EpiphanyThreadState> {
|
||||
if update.is_empty() {
|
||||
return Err(CodexErr::InvalidRequest(
|
||||
"epiphany update patch must contain at least one mutation".to_string(),
|
||||
));
|
||||
}
|
||||
|
||||
let reference_turn_id = self
|
||||
.codex
|
||||
pub async fn epiphany_reference_turn_id(&self) -> Option<String> {
|
||||
self.codex
|
||||
.session
|
||||
.reference_context_item()
|
||||
.await
|
||||
.and_then(|item| item.turn_id);
|
||||
let mut next_state = self
|
||||
.codex
|
||||
.session
|
||||
.epiphany_state()
|
||||
.await
|
||||
.unwrap_or_default();
|
||||
if let Some(expected_revision) = update.expected_revision
|
||||
&& next_state.revision != expected_revision
|
||||
{
|
||||
return Err(CodexErr::InvalidRequest(format!(
|
||||
"epiphany state revision mismatch: expected {expected_revision}, found {}",
|
||||
next_state.revision
|
||||
)));
|
||||
}
|
||||
.and_then(|item| item.turn_id)
|
||||
}
|
||||
|
||||
let validation_errors = epiphany_state_update_validation_errors(&next_state, &update);
|
||||
if !validation_errors.is_empty() {
|
||||
return Err(CodexErr::InvalidRequest(format!(
|
||||
"invalid epiphany update patch: {}",
|
||||
validation_errors.join("; ")
|
||||
)));
|
||||
}
|
||||
|
||||
apply_epiphany_state_update(&mut next_state, update, reference_turn_id.clone());
|
||||
pub async fn persist_epiphany_state(
|
||||
&self,
|
||||
reference_turn_id: Option<String>,
|
||||
state: EpiphanyThreadState,
|
||||
) -> CodexResult<EpiphanyThreadState> {
|
||||
self.codex
|
||||
.session
|
||||
.set_epiphany_state(Some(next_state.clone()))
|
||||
.set_epiphany_state(Some(state.clone()))
|
||||
.await;
|
||||
self.codex
|
||||
.session
|
||||
.persist_rollout_items(&[RolloutItem::EpiphanyState(EpiphanyStateItem {
|
||||
turn_id: reference_turn_id,
|
||||
state: next_state.clone(),
|
||||
state: state.clone(),
|
||||
})])
|
||||
.await;
|
||||
self.codex.session.flush_rollout().await?;
|
||||
Ok(next_state)
|
||||
Ok(state)
|
||||
}
|
||||
|
||||
pub async fn read_mcp_resource(
|
||||
|
|
|
|||
Reference in a new issue