Remove Epiphany app-server compatibility surface
This commit is contained in:
parent
3c92272d22
commit
5f6f2441c8
174 changed files with 8747 additions and 48296 deletions
|
|
@ -1,13 +1,7 @@
|
|||
mod auth_routes;
|
||||
mod catalog_routes;
|
||||
mod command_routes;
|
||||
mod epiphany_mutation_routes;
|
||||
mod epiphany_read_routes;
|
||||
mod epiphany_thread_host;
|
||||
#[cfg(test)]
|
||||
mod epiphany_compatibility_architecture;
|
||||
mod listener_lifecycle;
|
||||
mod legacy_epiphany_rollout;
|
||||
mod mcp_routes;
|
||||
mod realtime_routes;
|
||||
mod review_routes;
|
||||
|
|
@ -26,13 +20,10 @@ mod thread_turn_routes;
|
|||
mod turn_routes;
|
||||
|
||||
use self::auth_routes::ActiveLogin;
|
||||
use self::epiphany_thread_host::live_thread_epiphany_state;
|
||||
use self::epiphany_thread_host::load_epiphany_state_from_rollout_path;
|
||||
pub(super) use self::listener_lifecycle::{EnsureConversationListenerResult, ListenerTaskContext};
|
||||
pub(crate) use self::running_thread_resume_routes::handle_pending_thread_resume_request;
|
||||
pub(crate) use self::thread_config::{config_load_error, validate_dynamic_tools};
|
||||
pub(crate) use self::thread_projection::*;
|
||||
pub(super) use self::thread_read_routes::ThreadReadViewError;
|
||||
pub(crate) use self::thread_turn_projection::*;
|
||||
use crate::bespoke_event_handling::apply_bespoke_event_handling;
|
||||
use crate::bespoke_event_handling::maybe_emit_hook_prompt_item_completed;
|
||||
|
|
@ -374,7 +365,6 @@ use crate::filters::source_kind_matches;
|
|||
use crate::thread_state::ThreadListenerCommand;
|
||||
use crate::thread_state::ThreadState;
|
||||
use crate::thread_state::ThreadStateManager;
|
||||
use token_usage_replay::latest_token_usage_info_from_rollout_path;
|
||||
use token_usage_replay::latest_token_usage_turn_id_for_thread_path;
|
||||
use token_usage_replay::latest_token_usage_turn_id_from_rollout_items;
|
||||
use token_usage_replay::latest_token_usage_turn_id_from_rollout_path;
|
||||
|
|
@ -637,38 +627,6 @@ impl CodexMessageProcessor {
|
|||
self.thread_read(to_connection_request_id(request_id), params)
|
||||
.await;
|
||||
}
|
||||
ClientRequest::ThreadEpiphanyView { request_id, params } => {
|
||||
self.thread_epiphany_view(to_connection_request_id(request_id), params)
|
||||
.await;
|
||||
}
|
||||
ClientRequest::ThreadEpiphanyRoleResult { request_id, params } => {
|
||||
self.thread_epiphany_role_result(to_connection_request_id(request_id), params)
|
||||
.await;
|
||||
}
|
||||
ClientRequest::ThreadEpiphanyFreshness { request_id, params } => {
|
||||
self.thread_epiphany_freshness(to_connection_request_id(request_id), params)
|
||||
.await;
|
||||
}
|
||||
ClientRequest::ThreadEpiphanyContext { request_id, params } => {
|
||||
self.thread_epiphany_context(to_connection_request_id(request_id), params)
|
||||
.await;
|
||||
}
|
||||
ClientRequest::ThreadEpiphanyGraphQuery { request_id, params } => {
|
||||
self.thread_epiphany_graph_query(to_connection_request_id(request_id), params)
|
||||
.await;
|
||||
}
|
||||
ClientRequest::ThreadEpiphanyReorientResult { request_id, params } => {
|
||||
self.thread_epiphany_reorient_result(to_connection_request_id(request_id), params)
|
||||
.await;
|
||||
}
|
||||
ClientRequest::ThreadEpiphanyJobInterrupt { request_id, params } => {
|
||||
self.thread_epiphany_job_interrupt(to_connection_request_id(request_id), params)
|
||||
.await;
|
||||
}
|
||||
ClientRequest::ThreadEpiphanyUpdate { request_id, params } => {
|
||||
self.thread_epiphany_update(to_connection_request_id(request_id), params)
|
||||
.await;
|
||||
}
|
||||
ClientRequest::ThreadTurnsList { request_id, params } => {
|
||||
self.thread_turns_list(to_connection_request_id(request_id), params)
|
||||
.await;
|
||||
|
|
|
|||
|
|
@ -1,89 +0,0 @@
|
|||
#[test]
|
||||
fn mutation_routes_are_explicit_compatibility_delegates() {
|
||||
let source = include_str!("epiphany_mutation_routes.rs");
|
||||
for delegate in [
|
||||
"apply_thread_epiphany_update(",
|
||||
"interrupt_thread_epiphany_job(",
|
||||
] {
|
||||
assert!(source.contains(delegate), "missing compatibility delegate {delegate}");
|
||||
}
|
||||
for forbidden in [
|
||||
"apply_epiphany_state_update_to_state(",
|
||||
"acceptance_receipts.push(",
|
||||
"job_bindings.push(",
|
||||
"runtime_links.push(",
|
||||
".steer_input(",
|
||||
".submit(Op::Compact)",
|
||||
"select_epiphany_coordinator_automation(",
|
||||
] {
|
||||
assert!(
|
||||
!source.contains(forbidden),
|
||||
"compatibility route regained local authority through {forbidden}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn only_named_client_routes_remain_registered() {
|
||||
let protocol = include_str!("../../../app-server-protocol/src/protocol/common.rs");
|
||||
let registrations = protocol
|
||||
.split("ThreadTurnsList =>")
|
||||
.next()
|
||||
.expect("client request registration section");
|
||||
for retained in [
|
||||
"thread/epiphany/view",
|
||||
"thread/epiphany/roleResult",
|
||||
"thread/epiphany/freshness",
|
||||
"thread/epiphany/context",
|
||||
"thread/epiphany/graphQuery",
|
||||
"thread/epiphany/reorientResult",
|
||||
"thread/epiphany/jobInterrupt",
|
||||
"thread/epiphany/update",
|
||||
] {
|
||||
assert!(registrations.contains(retained), "missing retained client route {retained}");
|
||||
}
|
||||
for removed in [
|
||||
"thread/epiphany/roleLaunch",
|
||||
"thread/epiphany/roleAccept",
|
||||
"thread/epiphany/reorientLaunch",
|
||||
"thread/epiphany/reorientAccept",
|
||||
"thread/epiphany/index",
|
||||
"thread/epiphany/distill",
|
||||
"thread/epiphany/propose",
|
||||
"thread/epiphany/promote",
|
||||
"thread/epiphany/jobLaunch",
|
||||
"thread/epiphany/retrieve",
|
||||
] {
|
||||
assert!(!registrations.contains(removed), "unconsumed route remains registered: {removed}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn read_routes_have_no_mutation_or_scheduler_authority() {
|
||||
let source = include_str!("epiphany_read_routes.rs");
|
||||
for forbidden in [
|
||||
"apply_thread_epiphany_",
|
||||
"launch_thread_epiphany_",
|
||||
"interrupt_thread_epiphany_",
|
||||
"index_epiphany_retrieval_for_paths(",
|
||||
".steer_input(",
|
||||
".submit(Op::Compact)",
|
||||
"select_epiphany_coordinator_automation(",
|
||||
] {
|
||||
assert!(
|
||||
!source.contains(forbidden),
|
||||
"read route regained actuator authority through {forbidden}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn compatibility_surface_has_no_implicit_event_loop_trigger() {
|
||||
let processor = include_str!("../codex_message_processor.rs");
|
||||
let event_loop = include_str!("../bespoke_event_handling.rs");
|
||||
let thread_state = include_str!("../thread_state.rs");
|
||||
|
||||
assert!(!processor.contains("mod epiphany_automation"));
|
||||
assert!(!event_loop.contains("maybe_run_epiphany"));
|
||||
assert!(!thread_state.contains("epiphany_checkpoint_intervention"));
|
||||
}
|
||||
|
|
@ -1,190 +0,0 @@
|
|||
use codex_app_server_protocol::*;
|
||||
use codex_core::CodexThread;
|
||||
use codex_protocol::ThreadId;
|
||||
use epiphany_state_model::EpiphanyThreadState;
|
||||
use epiphany_codex_bridge::cultnet::EpiphanyStateUpdatedField;
|
||||
use epiphany_codex_bridge::error::EpiphanyBridgeError;
|
||||
use epiphany_codex_bridge::mutation_service::apply_thread_epiphany_update;
|
||||
use epiphany_codex_bridge::mutation_service::interrupt_thread_epiphany_job;
|
||||
use epiphany_codex_bridge::protocol_edge::protocol_job_from_surface;
|
||||
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 std::sync::Arc;
|
||||
|
||||
use super::CodexMessageProcessor;
|
||||
use super::ConnectionRequestId;
|
||||
use super::epiphany_thread_host::EpiphanyCodexThreadHost;
|
||||
|
||||
impl CodexMessageProcessor {
|
||||
async fn load_epiphany_thread(
|
||||
&self,
|
||||
request_id: &ConnectionRequestId,
|
||||
thread_id: &str,
|
||||
) -> Option<(ThreadId, Arc<CodexThread>)> {
|
||||
let thread_uuid = match ThreadId::from_string(thread_id) {
|
||||
Ok(id) => id,
|
||||
Err(err) => {
|
||||
self.send_invalid_request_error(
|
||||
request_id.clone(),
|
||||
format!("invalid thread id: {err}"),
|
||||
)
|
||||
.await;
|
||||
return None;
|
||||
}
|
||||
};
|
||||
|
||||
let thread = match self.thread_manager.get_thread(thread_uuid).await {
|
||||
Ok(thread) => thread,
|
||||
Err(_) => {
|
||||
self.send_invalid_request_error(
|
||||
request_id.clone(),
|
||||
format!("thread not loaded: {thread_uuid}"),
|
||||
)
|
||||
.await;
|
||||
return None;
|
||||
}
|
||||
};
|
||||
|
||||
Some((thread_uuid, thread))
|
||||
}
|
||||
|
||||
async fn send_epiphany_state_updated(
|
||||
&self,
|
||||
thread_uuid: ThreadId,
|
||||
source: ThreadEpiphanyStateUpdatedSource,
|
||||
changed_fields: Vec<EpiphanyStateUpdatedField>,
|
||||
epiphany_state: EpiphanyThreadState,
|
||||
) {
|
||||
self.outgoing
|
||||
.send_server_notification(ServerNotification::ThreadEpiphanyStateUpdated(
|
||||
protocol_state_updated_notification(
|
||||
thread_uuid.to_string(),
|
||||
source,
|
||||
epiphany_state.revision,
|
||||
changed_fields,
|
||||
epiphany_state,
|
||||
),
|
||||
))
|
||||
.await;
|
||||
}
|
||||
|
||||
pub(super) async fn thread_epiphany_update(
|
||||
&self,
|
||||
request_id: ConnectionRequestId,
|
||||
params: ThreadEpiphanyUpdateParams,
|
||||
) {
|
||||
let ThreadEpiphanyUpdateParams {
|
||||
thread_id,
|
||||
expected_revision,
|
||||
patch,
|
||||
} = params;
|
||||
|
||||
let (thread_uuid, thread) = match self.load_epiphany_thread(&request_id, &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
|
||||
{
|
||||
Ok(applied) => applied,
|
||||
Err(EpiphanyBridgeError::InvalidRequest(message)) => {
|
||||
self.send_invalid_request_error(request_id, message).await;
|
||||
return;
|
||||
}
|
||||
Err(err) => {
|
||||
self.send_internal_error(
|
||||
request_id,
|
||||
format!("failed to update Epiphany state for {thread_uuid}: {err}"),
|
||||
)
|
||||
.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 = ThreadEpiphanyUpdateResponse {
|
||||
revision: applied.revision,
|
||||
changed_fields: protocol_changed_fields,
|
||||
epiphany_state: epiphany_state.clone(),
|
||||
};
|
||||
|
||||
self.outgoing.send_response(request_id, response).await;
|
||||
self.send_epiphany_state_updated(
|
||||
thread_uuid,
|
||||
ThreadEpiphanyStateUpdatedSource::Update,
|
||||
changed_fields,
|
||||
epiphany_state,
|
||||
)
|
||||
.await;
|
||||
}
|
||||
|
||||
pub(super) async fn thread_epiphany_job_interrupt(
|
||||
&self,
|
||||
request_id: ConnectionRequestId,
|
||||
params: ThreadEpiphanyJobInterruptParams,
|
||||
) {
|
||||
let ThreadEpiphanyJobInterruptParams {
|
||||
thread_id,
|
||||
expected_revision,
|
||||
binding_id,
|
||||
reason,
|
||||
} = params;
|
||||
|
||||
let (thread_uuid, thread) = match self.load_epiphany_thread(&request_id, &thread_id).await {
|
||||
Some(thread) => thread,
|
||||
None => return,
|
||||
};
|
||||
|
||||
let host = EpiphanyCodexThreadHost::new(thread.as_ref());
|
||||
let applied = match interrupt_thread_epiphany_job(
|
||||
&host,
|
||||
expected_revision,
|
||||
&binding_id,
|
||||
reason,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(applied) => applied,
|
||||
Err(EpiphanyBridgeError::InvalidRequest(message)) => {
|
||||
self.send_invalid_request_error(request_id, message).await;
|
||||
return;
|
||||
}
|
||||
Err(err) => {
|
||||
self.send_internal_error(
|
||||
request_id,
|
||||
format!("failed to interrupt Epiphany job for {thread_uuid}: {err}"),
|
||||
)
|
||||
.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;
|
||||
|
||||
self.outgoing
|
||||
.send_response(
|
||||
request_id,
|
||||
ThreadEpiphanyJobInterruptResponse {
|
||||
cancel_requested: applied.cancel_requested,
|
||||
interrupted_thread_ids: applied.interrupted_thread_ids.clone(),
|
||||
revision: applied.revision,
|
||||
changed_fields: protocol_changed_fields,
|
||||
epiphany_state: epiphany_state.clone(),
|
||||
job: protocol_job_from_surface(applied.job, None, None),
|
||||
},
|
||||
)
|
||||
.await;
|
||||
self.send_epiphany_state_updated(
|
||||
thread_uuid,
|
||||
ThreadEpiphanyStateUpdatedSource::JobInterrupt,
|
||||
changed_fields,
|
||||
epiphany_state,
|
||||
)
|
||||
.await;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,418 +0,0 @@
|
|||
use codex_app_server_protocol::*;
|
||||
use codex_core::CodexThread;
|
||||
use codex_protocol::ThreadId;
|
||||
use epiphany_state_model::EpiphanyRetrievalState;
|
||||
use super::epiphany_thread_host::runtime_spine_store_path;
|
||||
use epiphany_codex_bridge::cultnet::EpiphanySurfaceSource;
|
||||
use epiphany_codex_bridge::invalidation::epiphany_freshness_watcher_snapshot;
|
||||
use epiphany_codex_bridge::launch::EPIPHANY_REORIENT_LAUNCH_BINDING_ID;
|
||||
use epiphany_codex_bridge::launch::epiphany_role_binding_id;
|
||||
use epiphany_codex_bridge::protocol_edge::core_epiphany_view_needs_jobs;
|
||||
use epiphany_codex_bridge::protocol_edge::core_epiphany_view_needs_pressure;
|
||||
use epiphany_codex_bridge::protocol_edge::core_epiphany_view_needs_reorientation_inputs;
|
||||
use epiphany_codex_bridge::protocol_edge::core_epiphany_view_needs_runtime_store;
|
||||
use epiphany_codex_bridge::protocol_edge::default_core_epiphany_view_lenses;
|
||||
use epiphany_codex_bridge::protocol_edge::protocol_context_params_to_core;
|
||||
use epiphany_codex_bridge::protocol_edge::protocol_freshness_response_from_surface;
|
||||
use epiphany_codex_bridge::protocol_edge::protocol_graph_query_to_core;
|
||||
use epiphany_codex_bridge::protocol_edge::protocol_role_id_to_core;
|
||||
use epiphany_codex_bridge::protocol_edge::protocol_view_lenses_to_core;
|
||||
use epiphany_codex_bridge::retrieve::epiphany_retrieval_state_for_paths;
|
||||
use epiphany_codex_bridge::view_protocol::EpiphanyFreshnessResponseInput;
|
||||
use epiphany_codex_bridge::view_protocol::EpiphanyReorientResultResponseInput;
|
||||
use epiphany_codex_bridge::view_protocol::EpiphanyRoleResultResponseInput;
|
||||
use epiphany_codex_bridge::view_protocol::EpiphanyViewResponseInput;
|
||||
use epiphany_codex_bridge::view_protocol::derive_epiphany_freshness_surface;
|
||||
use epiphany_codex_bridge::view_protocol::map_epiphany_context_response;
|
||||
use epiphany_codex_bridge::view_protocol::map_epiphany_graph_query_response;
|
||||
use epiphany_codex_bridge::view_protocol::map_epiphany_reorient_result_response;
|
||||
use epiphany_codex_bridge::view_protocol::map_epiphany_role_result_response;
|
||||
use epiphany_codex_bridge::view_protocol::map_epiphany_view_response;
|
||||
|
||||
use super::CodexMessageProcessor;
|
||||
use super::ConnectionRequestId;
|
||||
use super::ThreadReadViewError;
|
||||
use super::epiphany_thread_host::epiphany_token_usage_snapshot;
|
||||
use super::latest_token_usage_info_from_rollout_path;
|
||||
|
||||
impl CodexMessageProcessor {
|
||||
pub(super) async fn thread_epiphany_view(
|
||||
&self,
|
||||
request_id: ConnectionRequestId,
|
||||
params: ThreadEpiphanyViewParams,
|
||||
) {
|
||||
let ThreadEpiphanyViewParams { thread_id, lenses } = params;
|
||||
let lenses = if lenses.is_empty() {
|
||||
default_core_epiphany_view_lenses()
|
||||
} else {
|
||||
protocol_view_lenses_to_core(lenses)
|
||||
};
|
||||
|
||||
let thread_uuid = match ThreadId::from_string(&thread_id) {
|
||||
Ok(id) => id,
|
||||
Err(err) => {
|
||||
self.send_invalid_request_error(request_id, format!("invalid thread id: {err}"))
|
||||
.await;
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
let loaded_thread = self.thread_manager.get_thread(thread_uuid).await.ok();
|
||||
let loaded = loaded_thread.is_some();
|
||||
let thread = match self.read_thread_view(thread_uuid, false).await {
|
||||
Ok(thread) => thread,
|
||||
Err(ThreadReadViewError::InvalidRequest(message)) => {
|
||||
self.send_invalid_request_error(request_id, message).await;
|
||||
return;
|
||||
}
|
||||
Err(ThreadReadViewError::Internal(message)) => {
|
||||
self.send_internal_error(request_id, message).await;
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
let needs_jobs = core_epiphany_view_needs_jobs(&lenses);
|
||||
let needs_reorientation_inputs = core_epiphany_view_needs_reorientation_inputs(&lenses);
|
||||
let needs_pressure = core_epiphany_view_needs_pressure(&lenses);
|
||||
let retrieval_override = if (needs_jobs || needs_reorientation_inputs)
|
||||
&& thread
|
||||
.epiphany_state
|
||||
.as_ref()
|
||||
.and_then(|state| state.retrieval.as_ref())
|
||||
.is_none()
|
||||
{
|
||||
if let Some(loaded_thread) = loaded_thread.as_ref() {
|
||||
Some(thread_epiphany_retrieval_state(loaded_thread.as_ref()).await)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let watcher_snapshot = if needs_reorientation_inputs {
|
||||
if let Some(loaded_thread) = loaded_thread.as_ref() {
|
||||
let config_snapshot = loaded_thread.config_snapshot().await;
|
||||
self.epiphany_invalidation_manager
|
||||
.ensure_thread_watch(&thread_id, &config_snapshot.cwd)
|
||||
.await;
|
||||
Some(
|
||||
self.epiphany_invalidation_manager
|
||||
.snapshot(&thread_id)
|
||||
.await,
|
||||
)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let token_usage_info = if needs_pressure {
|
||||
if let Some(loaded_thread) = loaded_thread.as_ref() {
|
||||
loaded_thread.token_usage_info().await
|
||||
} else {
|
||||
match thread.path.as_deref() {
|
||||
Some(path) => latest_token_usage_info_from_rollout_path(path).await,
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let runtime_store_path = if core_epiphany_view_needs_runtime_store(&lenses) {
|
||||
if let Some(loaded_thread) = loaded_thread.as_ref() {
|
||||
Some(runtime_spine_store_path(loaded_thread).await)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let token_usage_snapshot = epiphany_token_usage_snapshot(token_usage_info.as_ref());
|
||||
let response = map_epiphany_view_response(EpiphanyViewResponseInput {
|
||||
thread_id: thread_id.clone(),
|
||||
lenses,
|
||||
loaded,
|
||||
state: thread.epiphany_state.as_ref(),
|
||||
retrieval_override: retrieval_override.as_ref(),
|
||||
watcher_snapshot: watcher_snapshot
|
||||
.as_ref()
|
||||
.map(epiphany_freshness_watcher_snapshot),
|
||||
token_usage_info: token_usage_snapshot.as_ref(),
|
||||
runtime_store_path: runtime_store_path.as_deref(),
|
||||
})
|
||||
.await;
|
||||
self.outgoing.send_response(request_id, response).await;
|
||||
}
|
||||
|
||||
pub(super) async fn thread_epiphany_role_result(
|
||||
&self,
|
||||
request_id: ConnectionRequestId,
|
||||
params: ThreadEpiphanyRoleResultParams,
|
||||
) {
|
||||
let ThreadEpiphanyRoleResultParams {
|
||||
thread_id,
|
||||
role_id,
|
||||
binding_id,
|
||||
} = params;
|
||||
let core_role_id = protocol_role_id_to_core(role_id);
|
||||
|
||||
let binding_id = match binding_id {
|
||||
Some(binding_id) => binding_id,
|
||||
None => match epiphany_role_binding_id(core_role_id) {
|
||||
Ok(binding_id) => binding_id.to_string(),
|
||||
Err(message) => {
|
||||
self.send_invalid_request_error(request_id, message).await;
|
||||
return;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
let thread_uuid = match ThreadId::from_string(&thread_id) {
|
||||
Ok(id) => id,
|
||||
Err(err) => {
|
||||
self.send_invalid_request_error(request_id, format!("invalid thread id: {err}"))
|
||||
.await;
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
let loaded_thread = self.thread_manager.get_thread(thread_uuid).await.ok();
|
||||
let thread = match self.read_thread_view(thread_uuid, false).await {
|
||||
Ok(thread) => thread,
|
||||
Err(ThreadReadViewError::InvalidRequest(message)) => {
|
||||
self.send_invalid_request_error(request_id, message).await;
|
||||
return;
|
||||
}
|
||||
Err(ThreadReadViewError::Internal(message)) => {
|
||||
self.send_internal_error(request_id, message).await;
|
||||
return;
|
||||
}
|
||||
};
|
||||
let source = if loaded_thread.is_some() {
|
||||
EpiphanySurfaceSource::Live
|
||||
} else {
|
||||
EpiphanySurfaceSource::Stored
|
||||
};
|
||||
|
||||
if let Err(message) = epiphany_role_binding_id(core_role_id) {
|
||||
self.send_invalid_request_error(request_id, message).await;
|
||||
return;
|
||||
}
|
||||
|
||||
let runtime_store_path = if let Some(loaded_thread) = loaded_thread.as_ref() {
|
||||
Some(runtime_spine_store_path(loaded_thread).await)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let response = map_epiphany_role_result_response(EpiphanyRoleResultResponseInput {
|
||||
thread_id: thread_uuid.to_string(),
|
||||
role_id: core_role_id,
|
||||
source,
|
||||
binding_id,
|
||||
state: thread.epiphany_state.as_ref(),
|
||||
runtime_store_path: runtime_store_path.as_deref(),
|
||||
})
|
||||
.await;
|
||||
|
||||
self.outgoing.send_response(request_id, response).await;
|
||||
}
|
||||
|
||||
pub(super) async fn thread_epiphany_freshness(
|
||||
&self,
|
||||
request_id: ConnectionRequestId,
|
||||
params: ThreadEpiphanyFreshnessParams,
|
||||
) {
|
||||
let ThreadEpiphanyFreshnessParams { thread_id } = params;
|
||||
|
||||
let thread_uuid = match ThreadId::from_string(&thread_id) {
|
||||
Ok(id) => id,
|
||||
Err(err) => {
|
||||
self.send_invalid_request_error(request_id, format!("invalid thread id: {err}"))
|
||||
.await;
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
let loaded_thread = self.thread_manager.get_thread(thread_uuid).await.ok();
|
||||
let thread = match self.read_thread_view(thread_uuid, false).await {
|
||||
Ok(thread) => thread,
|
||||
Err(ThreadReadViewError::InvalidRequest(message)) => {
|
||||
self.send_invalid_request_error(request_id, message).await;
|
||||
return;
|
||||
}
|
||||
Err(ThreadReadViewError::Internal(message)) => {
|
||||
self.send_internal_error(request_id, message).await;
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
let retrieval_override = if let Some(loaded_thread) = loaded_thread.as_ref() {
|
||||
Some(thread_epiphany_retrieval_state(loaded_thread.as_ref()).await)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let watcher_snapshot = if let Some(loaded_thread) = loaded_thread.as_ref() {
|
||||
let config_snapshot = loaded_thread.config_snapshot().await;
|
||||
self.epiphany_invalidation_manager
|
||||
.ensure_thread_watch(&thread_id, &config_snapshot.cwd)
|
||||
.await;
|
||||
Some(
|
||||
self.epiphany_invalidation_manager
|
||||
.snapshot(&thread_id)
|
||||
.await,
|
||||
)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let surface = derive_epiphany_freshness_surface(EpiphanyFreshnessResponseInput {
|
||||
thread_id,
|
||||
loaded: loaded_thread.is_some(),
|
||||
state: thread.epiphany_state.as_ref(),
|
||||
retrieval_override: retrieval_override.as_ref(),
|
||||
watcher_snapshot: watcher_snapshot
|
||||
.as_ref()
|
||||
.map(epiphany_freshness_watcher_snapshot),
|
||||
});
|
||||
let response = protocol_freshness_response_from_surface(surface);
|
||||
self.outgoing.send_response(request_id, response).await;
|
||||
}
|
||||
|
||||
pub(super) async fn thread_epiphany_context(
|
||||
&self,
|
||||
request_id: ConnectionRequestId,
|
||||
params: ThreadEpiphanyContextParams,
|
||||
) {
|
||||
let thread_id = params.thread_id.clone();
|
||||
let thread_uuid = match ThreadId::from_string(&thread_id) {
|
||||
Ok(id) => id,
|
||||
Err(err) => {
|
||||
self.send_invalid_request_error(request_id, format!("invalid thread id: {err}"))
|
||||
.await;
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
let loaded = self.thread_manager.get_thread(thread_uuid).await.is_ok();
|
||||
let thread = match self.read_thread_view(thread_uuid, false).await {
|
||||
Ok(thread) => thread,
|
||||
Err(ThreadReadViewError::InvalidRequest(message)) => {
|
||||
self.send_invalid_request_error(request_id, message).await;
|
||||
return;
|
||||
}
|
||||
Err(ThreadReadViewError::Internal(message)) => {
|
||||
self.send_internal_error(request_id, message).await;
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
let core_params = protocol_context_params_to_core(¶ms);
|
||||
let response = map_epiphany_context_response(
|
||||
thread_id,
|
||||
loaded,
|
||||
thread.epiphany_state.as_ref(),
|
||||
&core_params,
|
||||
);
|
||||
self.outgoing.send_response(request_id, response).await;
|
||||
}
|
||||
|
||||
pub(super) async fn thread_epiphany_graph_query(
|
||||
&self,
|
||||
request_id: ConnectionRequestId,
|
||||
params: ThreadEpiphanyGraphQueryParams,
|
||||
) {
|
||||
let thread_id = params.thread_id.clone();
|
||||
let thread_uuid = match ThreadId::from_string(&thread_id) {
|
||||
Ok(id) => id,
|
||||
Err(err) => {
|
||||
self.send_invalid_request_error(request_id, format!("invalid thread id: {err}"))
|
||||
.await;
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
let loaded = self.thread_manager.get_thread(thread_uuid).await.is_ok();
|
||||
let thread = match self.read_thread_view(thread_uuid, false).await {
|
||||
Ok(thread) => thread,
|
||||
Err(ThreadReadViewError::InvalidRequest(message)) => {
|
||||
self.send_invalid_request_error(request_id, message).await;
|
||||
return;
|
||||
}
|
||||
Err(ThreadReadViewError::Internal(message)) => {
|
||||
self.send_internal_error(request_id, message).await;
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
let core_query = protocol_graph_query_to_core(¶ms.query);
|
||||
let response = map_epiphany_graph_query_response(
|
||||
thread_id,
|
||||
loaded,
|
||||
thread.epiphany_state.as_ref(),
|
||||
&core_query,
|
||||
);
|
||||
self.outgoing.send_response(request_id, response).await;
|
||||
}
|
||||
|
||||
pub(super) async fn thread_epiphany_reorient_result(
|
||||
&self,
|
||||
request_id: ConnectionRequestId,
|
||||
params: ThreadEpiphanyReorientResultParams,
|
||||
) {
|
||||
let ThreadEpiphanyReorientResultParams {
|
||||
thread_id,
|
||||
binding_id,
|
||||
} = params;
|
||||
let binding_id = binding_id.unwrap_or_else(|| EPIPHANY_REORIENT_LAUNCH_BINDING_ID.into());
|
||||
|
||||
let thread_uuid = match ThreadId::from_string(&thread_id) {
|
||||
Ok(id) => id,
|
||||
Err(err) => {
|
||||
self.send_invalid_request_error(request_id, format!("invalid thread id: {err}"))
|
||||
.await;
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
let loaded_thread = self.thread_manager.get_thread(thread_uuid).await.ok();
|
||||
let thread = match self.read_thread_view(thread_uuid, false).await {
|
||||
Ok(thread) => thread,
|
||||
Err(ThreadReadViewError::InvalidRequest(message)) => {
|
||||
self.send_invalid_request_error(request_id, message).await;
|
||||
return;
|
||||
}
|
||||
Err(ThreadReadViewError::Internal(message)) => {
|
||||
self.send_internal_error(request_id, message).await;
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
let source = if loaded_thread.is_some() {
|
||||
EpiphanySurfaceSource::Live
|
||||
} else {
|
||||
EpiphanySurfaceSource::Stored
|
||||
};
|
||||
let runtime_store_path = if let Some(loaded_thread) = loaded_thread.as_ref() {
|
||||
Some(runtime_spine_store_path(loaded_thread).await)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let response = map_epiphany_reorient_result_response(EpiphanyReorientResultResponseInput {
|
||||
thread_id: thread_uuid.to_string(),
|
||||
source,
|
||||
binding_id,
|
||||
state: thread.epiphany_state.as_ref(),
|
||||
runtime_store_path: runtime_store_path.as_deref(),
|
||||
})
|
||||
.await;
|
||||
|
||||
self.outgoing.send_response(request_id, response).await;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
async fn thread_epiphany_retrieval_state(thread: &CodexThread) -> EpiphanyRetrievalState {
|
||||
let config = thread.config_snapshot().await;
|
||||
let codex_home = thread.codex_home().await;
|
||||
epiphany_retrieval_state_for_paths(config.cwd.to_path_buf(), codex_home).await
|
||||
}
|
||||
|
|
@ -1,124 +0,0 @@
|
|||
pub(super) use super::legacy_epiphany_rollout::load_epiphany_state_from_rollout_path;
|
||||
use codex_core::CodexThread;
|
||||
use codex_protocol::protocol::TokenUsageInfo;
|
||||
use epiphany_codex_bridge::mutation_service::EpiphanyMutationHost;
|
||||
use epiphany_codex_bridge::mutation_service::load_authoritative_accepted_state;
|
||||
use epiphany_codex_bridge::pressure::EpiphanyTokenUsageSnapshot;
|
||||
use epiphany_codex_bridge::state::client_visible_epiphany_state_for_paths;
|
||||
use epiphany_codex_bridge::state::thread_state_mirror_id_from_rollout_path;
|
||||
use epiphany_state_model::EpiphanyThreadState;
|
||||
|
||||
pub(super) struct EpiphanyCodexThreadHost<'a> {
|
||||
thread: &'a CodexThread,
|
||||
}
|
||||
|
||||
impl<'a> EpiphanyCodexThreadHost<'a> {
|
||||
pub(super) fn new(thread: &'a CodexThread) -> Self {
|
||||
Self { thread }
|
||||
}
|
||||
}
|
||||
|
||||
impl EpiphanyMutationHost for EpiphanyCodexThreadHost<'_> {
|
||||
async fn epiphany_thread_id(&self) -> String {
|
||||
thread_state_mirror_id_from_rollout_path(self.thread.rollout_path().as_deref())
|
||||
}
|
||||
|
||||
async fn epiphany_state(&self) -> Option<EpiphanyThreadState> {
|
||||
let store = runtime_spine_store_path(self.thread).await;
|
||||
match load_authoritative_accepted_state(&store) {
|
||||
Ok(Some(state)) => Some(state),
|
||||
Ok(None) => load_legacy_rollout_state(self.thread).await,
|
||||
Err(error) => {
|
||||
tracing::error!(%error, store = %store.display(), "failed to read authoritative unified Epiphany acceptance state");
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn epiphany_reference_turn_id(&self) -> Option<String> {
|
||||
self.thread.reference_turn_id().await
|
||||
}
|
||||
|
||||
async fn epiphany_runtime_spine_store_path(&self) -> std::path::PathBuf {
|
||||
runtime_spine_store_path(self.thread).await
|
||||
}
|
||||
|
||||
async fn client_visible_epiphany_state(
|
||||
&self,
|
||||
fallback: EpiphanyThreadState,
|
||||
) -> EpiphanyThreadState {
|
||||
client_visible_live_thread_epiphany_state(self.thread, fallback).await
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) async fn live_thread_epiphany_state(
|
||||
thread: &CodexThread,
|
||||
) -> Option<EpiphanyThreadState> {
|
||||
let state = load_authoritative_epiphany_state(thread).await?;
|
||||
let config = thread.config_snapshot().await;
|
||||
let codex_home = thread.codex_home().await;
|
||||
let rollout_path = thread.rollout_path();
|
||||
let mirror_thread_id = thread_state_mirror_id_from_rollout_path(rollout_path.as_deref());
|
||||
Some(
|
||||
client_visible_epiphany_state_for_paths(
|
||||
state,
|
||||
config.cwd.as_path(),
|
||||
codex_home,
|
||||
Some(mirror_thread_id.as_str()),
|
||||
)
|
||||
.await,
|
||||
)
|
||||
}
|
||||
|
||||
pub(super) async fn load_authoritative_epiphany_state(
|
||||
thread: &CodexThread,
|
||||
) -> Option<EpiphanyThreadState> {
|
||||
let store = runtime_spine_store_path(thread).await;
|
||||
match load_authoritative_accepted_state(&store) {
|
||||
Ok(Some(state)) => Some(state),
|
||||
Ok(None) => load_legacy_rollout_state(thread).await,
|
||||
Err(error) => {
|
||||
tracing::error!(%error, store = %store.display(), "failed to read unified Epiphany state");
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) async fn runtime_spine_store_path(thread: &CodexThread) -> std::path::PathBuf {
|
||||
thread
|
||||
.config_snapshot()
|
||||
.await
|
||||
.cwd
|
||||
.join("state")
|
||||
.join("runtime-spine.msgpack")
|
||||
.to_path_buf()
|
||||
}
|
||||
|
||||
async fn load_legacy_rollout_state(thread: &CodexThread) -> Option<EpiphanyThreadState> {
|
||||
let rollout_path = thread.rollout_path()?;
|
||||
match load_epiphany_state_from_rollout_path(&rollout_path).await {
|
||||
Ok(state) => state,
|
||||
Err(error) => {
|
||||
tracing::error!(%error, rollout = %rollout_path.display(), "failed to read legacy Epiphany rollout state");
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) async fn client_visible_live_thread_epiphany_state(
|
||||
thread: &CodexThread,
|
||||
fallback: EpiphanyThreadState,
|
||||
) -> EpiphanyThreadState {
|
||||
live_thread_epiphany_state(thread).await.unwrap_or(fallback)
|
||||
}
|
||||
|
||||
pub(super) fn epiphany_token_usage_snapshot(
|
||||
info: Option<&TokenUsageInfo>,
|
||||
) -> Option<EpiphanyTokenUsageSnapshot> {
|
||||
info.map(|info| EpiphanyTokenUsageSnapshot {
|
||||
total_tokens: info.total_token_usage.total_tokens,
|
||||
last_turn_tokens: info.last_token_usage.total_tokens,
|
||||
model_context_window: info.model_context_window,
|
||||
model_auto_compact_token_limit: info.model_auto_compact_token_limit,
|
||||
})
|
||||
}
|
||||
|
|
@ -1,262 +0,0 @@
|
|||
use std::path::Path;
|
||||
|
||||
use codex_protocol::models::ResponseItem;
|
||||
use codex_protocol::protocol::EventMsg;
|
||||
use codex_protocol::protocol::RolloutItem;
|
||||
use codex_protocol::protocol::RolloutLine;
|
||||
use epiphany_state_model::EpiphanyStateItem;
|
||||
use epiphany_state_model::EpiphanyThreadState;
|
||||
|
||||
enum LegacyReplayItem {
|
||||
Codex(RolloutItem),
|
||||
Epiphany(EpiphanyStateItem),
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct LegacySegment {
|
||||
turn_id: Option<String>,
|
||||
user_turn: bool,
|
||||
state: Option<EpiphanyThreadState>,
|
||||
}
|
||||
|
||||
fn compatible(active: Option<&str>, item: Option<&str>) -> bool {
|
||||
active.is_none_or(|active| item.is_none_or(|item| item == active))
|
||||
}
|
||||
|
||||
fn finish(segment: LegacySegment, state: &mut Option<EpiphanyThreadState>, rollbacks: &mut usize) {
|
||||
if *rollbacks > 0 && segment.user_turn {
|
||||
*rollbacks -= 1;
|
||||
} else if state.is_none()
|
||||
&& (segment.user_turn || (segment.turn_id.is_none() && segment.state.is_some()))
|
||||
{
|
||||
*state = segment.state;
|
||||
}
|
||||
}
|
||||
|
||||
fn is_out_of_band(segment: &LegacySegment) -> bool {
|
||||
segment.turn_id.is_none() && !segment.user_turn && segment.state.is_some()
|
||||
}
|
||||
|
||||
fn latest_legacy_epiphany_state(
|
||||
items: &[LegacyReplayItem],
|
||||
) -> Result<Option<EpiphanyThreadState>, String> {
|
||||
let mut state = None;
|
||||
let mut rollbacks = 0usize;
|
||||
let mut segment: Option<LegacySegment> = None;
|
||||
|
||||
for item in items.iter().rev() {
|
||||
if segment.as_ref().is_some_and(is_out_of_band)
|
||||
&& let Some(segment) = segment.take()
|
||||
{
|
||||
finish(segment, &mut state, &mut rollbacks);
|
||||
}
|
||||
if state.is_some() {
|
||||
break;
|
||||
}
|
||||
|
||||
match item {
|
||||
LegacyReplayItem::Codex(RolloutItem::EventMsg(EventMsg::ThreadRolledBack(event))) => {
|
||||
rollbacks = rollbacks
|
||||
.saturating_add(usize::try_from(event.num_turns).unwrap_or(usize::MAX));
|
||||
}
|
||||
LegacyReplayItem::Codex(RolloutItem::EventMsg(EventMsg::TurnComplete(event))) => {
|
||||
let segment = segment.get_or_insert_with(LegacySegment::default);
|
||||
segment.turn_id.get_or_insert_with(|| event.turn_id.clone());
|
||||
}
|
||||
LegacyReplayItem::Codex(RolloutItem::EventMsg(EventMsg::TurnAborted(event))) => {
|
||||
if let Some(turn_id) = &event.turn_id {
|
||||
segment
|
||||
.get_or_insert_with(LegacySegment::default)
|
||||
.turn_id
|
||||
.get_or_insert_with(|| turn_id.clone());
|
||||
}
|
||||
}
|
||||
LegacyReplayItem::Codex(RolloutItem::EventMsg(EventMsg::UserMessage(_))) => {
|
||||
segment.get_or_insert_with(LegacySegment::default).user_turn = true;
|
||||
}
|
||||
LegacyReplayItem::Codex(RolloutItem::ResponseItem(ResponseItem::Message {
|
||||
role,
|
||||
..
|
||||
})) if role == "user" => {
|
||||
segment.get_or_insert_with(LegacySegment::default).user_turn = true;
|
||||
}
|
||||
LegacyReplayItem::Epiphany(item) => {
|
||||
let segment = segment.get_or_insert_with(LegacySegment::default);
|
||||
if segment.turn_id.is_none() {
|
||||
segment.turn_id = item.turn_id.clone();
|
||||
}
|
||||
if compatible(segment.turn_id.as_deref(), item.turn_id.as_deref())
|
||||
&& segment.state.is_none()
|
||||
{
|
||||
segment.state = Some(item.state.clone());
|
||||
}
|
||||
}
|
||||
LegacyReplayItem::Codex(RolloutItem::EventMsg(EventMsg::TurnStarted(event))) => {
|
||||
if segment.as_ref().is_some_and(|segment| {
|
||||
compatible(segment.turn_id.as_deref(), Some(event.turn_id.as_str()))
|
||||
}) && let Some(segment) = segment.take()
|
||||
{
|
||||
finish(segment, &mut state, &mut rollbacks);
|
||||
}
|
||||
}
|
||||
LegacyReplayItem::Codex(_) => {}
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(segment) = segment {
|
||||
finish(segment, &mut state, &mut rollbacks);
|
||||
}
|
||||
Ok(state)
|
||||
}
|
||||
|
||||
pub(super) async fn load_epiphany_state_from_rollout_path(
|
||||
path: &Path,
|
||||
) -> Result<Option<EpiphanyThreadState>, String> {
|
||||
let text = tokio::fs::read_to_string(path)
|
||||
.await
|
||||
.map_err(|error| format!("failed to read rollout `{}`: {error}", path.display()))?;
|
||||
let mut items = Vec::new();
|
||||
for line in text.lines().filter(|line| !line.trim().is_empty()) {
|
||||
if let Some(item) = parse_replay_line(line)? {
|
||||
items.push(item);
|
||||
}
|
||||
}
|
||||
latest_legacy_epiphany_state(&items)
|
||||
}
|
||||
|
||||
fn parse_replay_line(line: &str) -> Result<Option<LegacyReplayItem>, String> {
|
||||
let Ok(value) = serde_json::from_str::<serde_json::Value>(line) else {
|
||||
return Ok(None);
|
||||
};
|
||||
if value.get("type").and_then(serde_json::Value::as_str) == Some("epiphany_state") {
|
||||
let payload = value
|
||||
.get("payload")
|
||||
.cloned()
|
||||
.ok_or_else(|| "legacy Epiphany rollout item is missing payload".to_string())?;
|
||||
let item = serde_json::from_value(payload)
|
||||
.map_err(|error| format!("invalid legacy Epiphany rollout payload: {error}"))?;
|
||||
Ok(Some(LegacyReplayItem::Epiphany(item)))
|
||||
} else {
|
||||
Ok(serde_json::from_value::<RolloutLine>(value)
|
||||
.ok()
|
||||
.map(|line| LegacyReplayItem::Codex(line.item)))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use codex_protocol::config_types::ModeKind;
|
||||
use codex_protocol::protocol::ThreadRolledBackEvent;
|
||||
use codex_protocol::protocol::TurnCompleteEvent;
|
||||
use codex_protocol::protocol::TurnStartedEvent;
|
||||
use codex_protocol::protocol::UserMessageEvent;
|
||||
|
||||
#[test]
|
||||
fn codex_event_loop_has_no_epiphany_automation_authority() {
|
||||
let event_loop = include_str!("../bespoke_event_handling.rs");
|
||||
let processor = include_str!("../codex_message_processor.rs");
|
||||
let thread_state = include_str!("../thread_state.rs");
|
||||
|
||||
assert!(!event_loop.contains("maybe_run_epiphany"));
|
||||
assert!(!processor.contains("mod epiphany_automation"));
|
||||
assert!(!thread_state.contains("epiphany_checkpoint_intervention"));
|
||||
}
|
||||
use epiphany_state_model::EpiphanyStateItem;
|
||||
|
||||
fn state(id: &str) -> EpiphanyThreadState {
|
||||
EpiphanyThreadState {
|
||||
revision: 1,
|
||||
last_updated_turn_id: Some(id.to_string()),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
fn turn(id: &str, state: EpiphanyThreadState) -> Vec<LegacyReplayItem> {
|
||||
vec![
|
||||
LegacyReplayItem::Codex(RolloutItem::EventMsg(EventMsg::TurnStarted(
|
||||
TurnStartedEvent {
|
||||
turn_id: id.to_string(),
|
||||
started_at: None,
|
||||
model_context_window: None,
|
||||
collaboration_mode_kind: ModeKind::Default,
|
||||
},
|
||||
))),
|
||||
LegacyReplayItem::Codex(RolloutItem::EventMsg(EventMsg::UserMessage(
|
||||
UserMessageEvent {
|
||||
message: id.to_string(),
|
||||
images: None,
|
||||
local_images: Vec::new(),
|
||||
text_elements: Vec::new(),
|
||||
},
|
||||
))),
|
||||
LegacyReplayItem::Epiphany(EpiphanyStateItem {
|
||||
turn_id: Some(id.to_string()),
|
||||
state,
|
||||
}),
|
||||
LegacyReplayItem::Codex(RolloutItem::EventMsg(EventMsg::TurnComplete(
|
||||
TurnCompleteEvent {
|
||||
turn_id: id.to_string(),
|
||||
last_agent_message: None,
|
||||
completed_at: None,
|
||||
duration_ms: None,
|
||||
time_to_first_token_ms: None,
|
||||
},
|
||||
))),
|
||||
]
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn returns_latest_surviving_legacy_state() {
|
||||
let first = state("one");
|
||||
let second = state("two");
|
||||
let mut items = turn("one", first);
|
||||
items.extend(turn("two", second.clone()));
|
||||
assert_eq!(latest_legacy_epiphany_state(&items), Ok(Some(second)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn skips_rolled_back_legacy_state() {
|
||||
let first = state("one");
|
||||
let mut items = turn("one", first.clone());
|
||||
items.extend(turn("two", state("two")));
|
||||
items.push(LegacyReplayItem::Codex(RolloutItem::EventMsg(
|
||||
EventMsg::ThreadRolledBack(ThreadRolledBackEvent { num_turns: 1 }),
|
||||
)));
|
||||
assert_eq!(latest_legacy_epiphany_state(&items), Ok(Some(first)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejects_malformed_legacy_state_payload() {
|
||||
let line = serde_json::json!({
|
||||
"timestamp": "2026-07-12T00:00:00Z",
|
||||
"type": "epiphany_state",
|
||||
"payload": { "turn_id": "not-the-legacy-shape" }
|
||||
});
|
||||
assert!(parse_replay_line(&line.to_string()).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn recognizes_only_the_historical_raw_line_tag() {
|
||||
let expected = state("raw-line");
|
||||
let line = serde_json::json!({
|
||||
"timestamp": "2026-07-12T00:00:00Z",
|
||||
"type": "epiphany_state",
|
||||
"payload": {
|
||||
"turn_id": "raw-line",
|
||||
"state": expected
|
||||
}
|
||||
});
|
||||
let Some(LegacyReplayItem::Epiphany(item)) =
|
||||
parse_replay_line(&line.to_string()).expect("parse historical line")
|
||||
else {
|
||||
panic!("expected quarantined Epiphany migration item");
|
||||
};
|
||||
assert_eq!(item.turn_id.as_deref(), Some("raw-line"));
|
||||
assert_eq!(item.state, state("raw-line"));
|
||||
|
||||
assert!(parse_replay_line(r#"{"type":"future_unknown","payload":{}}"#)
|
||||
.expect("unknown line should remain nonfatal to migration scan")
|
||||
.is_none());
|
||||
}
|
||||
}
|
||||
|
|
@ -141,8 +141,6 @@ impl CodexMessageProcessor {
|
|||
match read_summary_from_rollout(rollout_path.as_path(), fallback_provider).await {
|
||||
Ok(summary) => {
|
||||
let mut thread = summary_to_thread(summary, &self.config.cwd);
|
||||
thread.epiphany_state =
|
||||
live_thread_epiphany_state(review_thread.as_ref()).await;
|
||||
self.thread_watch_manager
|
||||
.upsert_thread_silently(thread.clone())
|
||||
.await;
|
||||
|
|
|
|||
|
|
@ -194,17 +194,6 @@ impl CodexMessageProcessor {
|
|||
/*has_in_progress_turn*/ false,
|
||||
);
|
||||
self.attach_thread_name(thread_id, &mut thread).await;
|
||||
if let Some(rollout_path) = thread.path.as_deref() {
|
||||
match load_epiphany_state_from_rollout_path(rollout_path).await {
|
||||
Ok(epiphany_state) => {
|
||||
thread.epiphany_state = epiphany_state;
|
||||
}
|
||||
Err(message) => {
|
||||
self.send_internal_error(request_id, message).await;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
let thread_id = thread.id.clone();
|
||||
let response = ThreadUnarchiveResponse { thread };
|
||||
self.outgoing.send_response(request_id, response).await;
|
||||
|
|
|
|||
|
|
@ -267,8 +267,6 @@ impl CodexMessageProcessor {
|
|||
return;
|
||||
}
|
||||
|
||||
thread.epiphany_state = live_thread_epiphany_state(forked_thread.as_ref()).await;
|
||||
|
||||
self.thread_watch_manager
|
||||
.upsert_thread_silently(thread.clone())
|
||||
.await;
|
||||
|
|
|
|||
|
|
@ -248,7 +248,6 @@ pub(crate) fn thread_from_stored_thread(
|
|||
source: source.into(),
|
||||
git_info,
|
||||
name: thread.name,
|
||||
epiphany_state: None,
|
||||
turns: Vec::new(),
|
||||
};
|
||||
(thread, history)
|
||||
|
|
@ -709,7 +708,6 @@ pub(crate) fn build_thread_from_snapshot(
|
|||
source: config_snapshot.session_source.clone().into(),
|
||||
git_info: None,
|
||||
name: None,
|
||||
epiphany_state: None,
|
||||
turns: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
|
@ -765,7 +763,6 @@ pub(crate) fn summary_to_thread(
|
|||
source: source.into(),
|
||||
git_info,
|
||||
name: None,
|
||||
epiphany_state: None,
|
||||
turns: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -257,9 +257,6 @@ impl CodexMessageProcessor {
|
|||
)));
|
||||
};
|
||||
|
||||
self.apply_thread_read_epiphany_state(&mut thread, loaded_thread.as_ref())
|
||||
.await?;
|
||||
|
||||
let has_live_in_progress_turn = if let Some(loaded_thread) = loaded_thread.as_ref() {
|
||||
matches!(loaded_thread.agent_status().await, AgentStatus::Running)
|
||||
} else {
|
||||
|
|
@ -351,27 +348,6 @@ impl CodexMessageProcessor {
|
|||
Ok(Some(thread))
|
||||
}
|
||||
|
||||
async fn apply_thread_read_epiphany_state(
|
||||
&self,
|
||||
thread: &mut Thread,
|
||||
loaded_thread: Option<&Arc<CodexThread>>,
|
||||
) -> Result<(), ThreadReadViewError> {
|
||||
if let Some(loaded_thread) = loaded_thread {
|
||||
thread.epiphany_state = live_thread_epiphany_state(loaded_thread).await;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let Some(rollout_path) = thread.path.as_deref() else {
|
||||
thread.epiphany_state = None;
|
||||
return Ok(());
|
||||
};
|
||||
|
||||
thread.epiphany_state = load_epiphany_state_from_rollout_path(rollout_path)
|
||||
.await
|
||||
.map_err(ThreadReadViewError::Internal)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn apply_thread_read_rollout_fields(
|
||||
&self,
|
||||
thread_id: ThreadId,
|
||||
|
|
|
|||
|
|
@ -391,7 +391,6 @@ impl CodexMessageProcessor {
|
|||
)
|
||||
.await?;
|
||||
self.attach_thread_name(thread_id, &mut thread).await;
|
||||
thread.epiphany_state = live_thread_epiphany_state(live_thread).await;
|
||||
Ok(thread)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -281,13 +281,6 @@ impl CodexMessageProcessor {
|
|||
&config_snapshot,
|
||||
session_configured.rollout_path.clone(),
|
||||
);
|
||||
thread.epiphany_state = live_thread_epiphany_state(&codex_thread)
|
||||
.instrument(tracing::info_span!(
|
||||
"app_server.thread_start.epiphany_state",
|
||||
otel.name = "app_server.thread_start.epiphany_state",
|
||||
))
|
||||
.await;
|
||||
|
||||
// Auto-attach a thread listener when starting a thread.
|
||||
Self::log_listener_attach_result(
|
||||
Self::ensure_conversation_listener_task(
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ use codex_core::CodexThread;
|
|||
use codex_protocol::ThreadId;
|
||||
use codex_protocol::protocol::EventMsg;
|
||||
use codex_protocol::protocol::RolloutItem;
|
||||
use codex_protocol::protocol::TokenUsageInfo;
|
||||
|
||||
use crate::codex_message_processor::read_rollout_items_from_rollout;
|
||||
use crate::outgoing_message::ConnectionId;
|
||||
|
|
@ -72,22 +71,6 @@ pub(super) async fn latest_token_usage_turn_id_from_rollout_path(
|
|||
latest_token_usage_turn_id_from_rollout_items(&rollout_items, thread)
|
||||
}
|
||||
|
||||
pub(super) async fn latest_token_usage_info_from_rollout_path(
|
||||
rollout_path: &Path,
|
||||
) -> Option<TokenUsageInfo> {
|
||||
let rollout_items = read_rollout_items_from_rollout(rollout_path).await.ok()?;
|
||||
latest_token_usage_info_from_rollout_items(&rollout_items)
|
||||
}
|
||||
|
||||
fn latest_token_usage_info_from_rollout_items(
|
||||
rollout_items: &[RolloutItem],
|
||||
) -> Option<TokenUsageInfo> {
|
||||
rollout_items.iter().rev().find_map(|item| match item {
|
||||
RolloutItem::EventMsg(EventMsg::TokenCount(event)) => event.info.clone(),
|
||||
_ => None,
|
||||
})
|
||||
}
|
||||
|
||||
/// Identifies the turn that was active when a `TokenCount` record appeared.
|
||||
///
|
||||
/// The id is preferred when it still appears in the rebuilt thread. The position
|
||||
|
|
|
|||
|
|
@ -902,7 +902,6 @@ mod tests {
|
|||
source,
|
||||
git_info: None,
|
||||
name: None,
|
||||
epiphany_state: None,
|
||||
turns: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue