Delete unconsumed Epiphany app-server routes
This commit is contained in:
parent
09761d41be
commit
5fd927481c
11 changed files with 116 additions and 1893 deletions
|
|
@ -641,18 +641,10 @@ impl CodexMessageProcessor {
|
|||
self.thread_epiphany_view(to_connection_request_id(request_id), params)
|
||||
.await;
|
||||
}
|
||||
ClientRequest::ThreadEpiphanyRoleLaunch { request_id, params } => {
|
||||
self.thread_epiphany_role_launch(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::ThreadEpiphanyRoleAccept { request_id, params } => {
|
||||
self.thread_epiphany_role_accept(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;
|
||||
|
|
@ -665,38 +657,10 @@ impl CodexMessageProcessor {
|
|||
self.thread_epiphany_graph_query(to_connection_request_id(request_id), params)
|
||||
.await;
|
||||
}
|
||||
ClientRequest::ThreadEpiphanyReorientLaunch { request_id, params } => {
|
||||
self.thread_epiphany_reorient_launch(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::ThreadEpiphanyReorientAccept { request_id, params } => {
|
||||
self.thread_epiphany_reorient_accept(to_connection_request_id(request_id), params)
|
||||
.await;
|
||||
}
|
||||
ClientRequest::ThreadEpiphanyIndex { request_id, params } => {
|
||||
self.thread_epiphany_index(to_connection_request_id(request_id), params)
|
||||
.await;
|
||||
}
|
||||
ClientRequest::ThreadEpiphanyDistill { request_id, params } => {
|
||||
self.thread_epiphany_distill(to_connection_request_id(request_id), params)
|
||||
.await;
|
||||
}
|
||||
ClientRequest::ThreadEpiphanyPropose { request_id, params } => {
|
||||
self.thread_epiphany_propose(to_connection_request_id(request_id), params)
|
||||
.await;
|
||||
}
|
||||
ClientRequest::ThreadEpiphanyPromote { request_id, params } => {
|
||||
self.thread_epiphany_promote(to_connection_request_id(request_id), params)
|
||||
.await;
|
||||
}
|
||||
ClientRequest::ThreadEpiphanyJobLaunch { request_id, params } => {
|
||||
self.thread_epiphany_job_launch(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;
|
||||
|
|
@ -705,10 +669,6 @@ impl CodexMessageProcessor {
|
|||
self.thread_epiphany_update(to_connection_request_id(request_id), params)
|
||||
.await;
|
||||
}
|
||||
ClientRequest::ThreadEpiphanyRetrieve { request_id, params } => {
|
||||
self.thread_epiphany_retrieve(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;
|
||||
|
|
|
|||
|
|
@ -2,14 +2,7 @@
|
|||
fn mutation_routes_are_explicit_compatibility_delegates() {
|
||||
let source = include_str!("epiphany_mutation_routes.rs");
|
||||
for delegate in [
|
||||
"launch_thread_epiphany_role(",
|
||||
"apply_thread_epiphany_role_accept(",
|
||||
"launch_thread_epiphany_reorient(",
|
||||
"apply_thread_epiphany_reorient_accept(",
|
||||
"index_epiphany_retrieval_for_paths(",
|
||||
"apply_thread_epiphany_promote(",
|
||||
"apply_thread_epiphany_update(",
|
||||
"launch_thread_epiphany_job(",
|
||||
"interrupt_thread_epiphany_job(",
|
||||
] {
|
||||
assert!(source.contains(delegate), "missing compatibility delegate {delegate}");
|
||||
|
|
@ -30,6 +23,41 @@ fn mutation_routes_are_explicit_compatibility_delegates() {
|
|||
}
|
||||
}
|
||||
|
||||
#[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");
|
||||
|
|
|
|||
|
|
@ -1,45 +1,20 @@
|
|||
use codex_app_server_protocol::*;
|
||||
use codex_core::CodexThread;
|
||||
use codex_protocol::ThreadId;
|
||||
use epiphany_state_model::EpiphanyRetrievalState;
|
||||
use epiphany_state_model::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::launch::EPIPHANY_REORIENT_LAUNCH_BINDING_ID;
|
||||
use epiphany_codex_bridge::launch::build_epiphany_job_launch_request;
|
||||
use epiphany_codex_bridge::launch::epiphany_role_binding_id;
|
||||
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;
|
||||
use epiphany_codex_bridge::mutation_service::apply_thread_epiphany_update;
|
||||
use epiphany_codex_bridge::mutation_service::interrupt_thread_epiphany_job;
|
||||
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::protocol_job_from_surface;
|
||||
use epiphany_codex_bridge::protocol_edge::protocol_patch_from_core;
|
||||
use epiphany_codex_bridge::protocol_edge::protocol_reorient_decision;
|
||||
use epiphany_codex_bridge::protocol_edge::protocol_reorient_finding;
|
||||
use epiphany_codex_bridge::protocol_edge::protocol_reorient_source;
|
||||
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_role_id_to_core;
|
||||
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::protocol_worker_launch_document_to_core;
|
||||
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;
|
||||
use std::sync::Arc;
|
||||
|
||||
use super::CodexMessageProcessor;
|
||||
use super::ConnectionRequestId;
|
||||
use super::ThreadReadViewError;
|
||||
use super::epiphany_thread_host::EpiphanyCodexThreadHost;
|
||||
use super::epiphany_thread_host::epiphany_token_usage_snapshot;
|
||||
|
||||
impl CodexMessageProcessor {
|
||||
async fn load_epiphany_thread(
|
||||
|
|
@ -94,450 +69,6 @@ impl CodexMessageProcessor {
|
|||
.await;
|
||||
}
|
||||
|
||||
pub(super) async fn thread_epiphany_role_launch(
|
||||
&self,
|
||||
request_id: ConnectionRequestId,
|
||||
params: ThreadEpiphanyRoleLaunchParams,
|
||||
) {
|
||||
let ThreadEpiphanyRoleLaunchParams {
|
||||
thread_id,
|
||||
role_id,
|
||||
expected_revision,
|
||||
max_runtime_seconds,
|
||||
} = params;
|
||||
let core_role_id = protocol_role_id_to_core(role_id);
|
||||
|
||||
let (thread_uuid, loaded_thread) =
|
||||
match self.load_epiphany_thread(&request_id, &thread_id).await {
|
||||
Some(thread) => thread,
|
||||
None => return,
|
||||
};
|
||||
let host = EpiphanyCodexThreadHost::new(loaded_thread.as_ref());
|
||||
let applied = match launch_thread_epiphany_role(
|
||||
&host,
|
||||
&thread_id,
|
||||
core_role_id,
|
||||
expected_revision,
|
||||
max_runtime_seconds,
|
||||
)
|
||||
.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 launch Epiphany role specialist 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,
|
||||
ThreadEpiphanyRoleLaunchResponse {
|
||||
thread_id: thread_uuid.to_string(),
|
||||
role_id,
|
||||
revision: applied.revision,
|
||||
changed_fields: protocol_changed_fields,
|
||||
epiphany_state: epiphany_state.clone(),
|
||||
job: protocol_job_from_surface(
|
||||
applied.job,
|
||||
Some(applied.launcher_job_id),
|
||||
Some(applied.backend_job_id),
|
||||
),
|
||||
},
|
||||
)
|
||||
.await;
|
||||
self.send_epiphany_state_updated(
|
||||
thread_uuid,
|
||||
ThreadEpiphanyStateUpdatedSource::JobLaunch,
|
||||
changed_fields,
|
||||
epiphany_state,
|
||||
)
|
||||
.await;
|
||||
}
|
||||
|
||||
pub(super) async fn thread_epiphany_role_accept(
|
||||
&self,
|
||||
request_id: ConnectionRequestId,
|
||||
params: ThreadEpiphanyRoleAcceptParams,
|
||||
) {
|
||||
let ThreadEpiphanyRoleAcceptParams {
|
||||
thread_id,
|
||||
role_id,
|
||||
expected_revision,
|
||||
binding_id,
|
||||
} = params;
|
||||
let core_role_id = protocol_role_id_to_core(role_id);
|
||||
|
||||
let default_binding_id = match epiphany_role_binding_id(core_role_id) {
|
||||
Ok(binding_id) => binding_id,
|
||||
Err(message) => {
|
||||
self.send_invalid_request_error(request_id, message).await;
|
||||
return;
|
||||
}
|
||||
};
|
||||
let binding_id = binding_id.unwrap_or_else(|| default_binding_id.into());
|
||||
|
||||
let (thread_uuid, loaded_thread) =
|
||||
match self.load_epiphany_thread(&request_id, &thread_id).await {
|
||||
Some(thread) => thread,
|
||||
None => return,
|
||||
};
|
||||
let host = EpiphanyCodexThreadHost::new(loaded_thread.as_ref());
|
||||
let applied = match apply_thread_epiphany_role_accept(
|
||||
&host,
|
||||
core_role_id,
|
||||
expected_revision,
|
||||
&binding_id,
|
||||
)
|
||||
.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 apply Epiphany role finding: {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,
|
||||
ThreadEpiphanyRoleAcceptResponse {
|
||||
revision: applied.revision,
|
||||
changed_fields: protocol_changed_fields,
|
||||
epiphany_state: epiphany_state.clone(),
|
||||
role_id,
|
||||
binding_id: binding_id.clone(),
|
||||
accepted_receipt_id: applied.accepted_receipt_id,
|
||||
accepted_observation_id: applied.accepted_observation_id,
|
||||
accepted_evidence_id: applied.accepted_evidence_id,
|
||||
applied_patch: protocol_patch_from_core(applied.applied_patch),
|
||||
finding: protocol_role_finding(role_id, applied.finding),
|
||||
},
|
||||
)
|
||||
.await;
|
||||
self.send_epiphany_state_updated(
|
||||
thread_uuid,
|
||||
ThreadEpiphanyStateUpdatedSource::RoleAccept,
|
||||
changed_fields,
|
||||
epiphany_state,
|
||||
)
|
||||
.await;
|
||||
}
|
||||
|
||||
pub(super) async fn thread_epiphany_reorient_launch(
|
||||
&self,
|
||||
request_id: ConnectionRequestId,
|
||||
params: ThreadEpiphanyReorientLaunchParams,
|
||||
) {
|
||||
let ThreadEpiphanyReorientLaunchParams {
|
||||
thread_id,
|
||||
expected_revision,
|
||||
max_runtime_seconds,
|
||||
} = params;
|
||||
|
||||
let (thread_uuid, loaded_thread) =
|
||||
match self.load_epiphany_thread(&request_id, &thread_id).await {
|
||||
Some(thread) => thread,
|
||||
None => return,
|
||||
};
|
||||
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 = thread_epiphany_retrieval_state(loaded_thread.as_ref()).await;
|
||||
let config_snapshot = loaded_thread.config_snapshot().await;
|
||||
self.epiphany_invalidation_manager
|
||||
.ensure_thread_watch(&thread_id, &config_snapshot.cwd)
|
||||
.await;
|
||||
let watcher_snapshot = self
|
||||
.epiphany_invalidation_manager
|
||||
.snapshot(&thread_id)
|
||||
.await;
|
||||
let token_usage_info = loaded_thread.token_usage_info().await;
|
||||
let host = EpiphanyCodexThreadHost::new(loaded_thread.as_ref());
|
||||
let token_usage_snapshot = epiphany_token_usage_snapshot(token_usage_info.as_ref());
|
||||
let applied = match launch_thread_epiphany_reorient(
|
||||
&host,
|
||||
&thread_id,
|
||||
expected_revision,
|
||||
max_runtime_seconds,
|
||||
thread.epiphany_state.as_ref(),
|
||||
Some(&retrieval_override),
|
||||
Some(epiphany_freshness_watcher_snapshot(&watcher_snapshot)),
|
||||
token_usage_snapshot.as_ref(),
|
||||
)
|
||||
.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 launch Epiphany reorientation worker 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,
|
||||
ThreadEpiphanyReorientLaunchResponse {
|
||||
thread_id: thread_uuid.to_string(),
|
||||
source: protocol_reorient_source(applied.source),
|
||||
state_status: protocol_reorient_state_status(applied.state_status),
|
||||
state_revision: applied.state_revision,
|
||||
decision: protocol_reorient_decision(applied.decision),
|
||||
revision: applied.revision,
|
||||
changed_fields: protocol_changed_fields,
|
||||
epiphany_state: epiphany_state.clone(),
|
||||
job: protocol_job_from_surface(
|
||||
applied.job,
|
||||
Some(applied.launcher_job_id),
|
||||
Some(applied.backend_job_id),
|
||||
),
|
||||
},
|
||||
)
|
||||
.await;
|
||||
self.send_epiphany_state_updated(
|
||||
thread_uuid,
|
||||
ThreadEpiphanyStateUpdatedSource::JobLaunch,
|
||||
changed_fields,
|
||||
epiphany_state,
|
||||
)
|
||||
.await;
|
||||
}
|
||||
|
||||
pub(super) async fn thread_epiphany_reorient_accept(
|
||||
&self,
|
||||
request_id: ConnectionRequestId,
|
||||
params: ThreadEpiphanyReorientAcceptParams,
|
||||
) {
|
||||
let ThreadEpiphanyReorientAcceptParams {
|
||||
thread_id,
|
||||
expected_revision,
|
||||
binding_id,
|
||||
update_scratch,
|
||||
update_investigation_checkpoint,
|
||||
} = params;
|
||||
let binding_id = binding_id.unwrap_or_else(|| EPIPHANY_REORIENT_LAUNCH_BINDING_ID.into());
|
||||
|
||||
let (thread_uuid, loaded_thread) =
|
||||
match self.load_epiphany_thread(&request_id, &thread_id).await {
|
||||
Some(thread) => thread,
|
||||
None => return,
|
||||
};
|
||||
let host = EpiphanyCodexThreadHost::new(loaded_thread.as_ref());
|
||||
let applied = match apply_thread_epiphany_reorient_accept(
|
||||
&host,
|
||||
expected_revision,
|
||||
binding_id.as_str(),
|
||||
update_scratch,
|
||||
update_investigation_checkpoint,
|
||||
)
|
||||
.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 accept Epiphany reorientation finding: {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,
|
||||
ThreadEpiphanyReorientAcceptResponse {
|
||||
revision: applied.revision,
|
||||
changed_fields: protocol_changed_fields,
|
||||
epiphany_state: epiphany_state.clone(),
|
||||
binding_id: binding_id.clone(),
|
||||
accepted_receipt_id: applied.accepted_receipt_id,
|
||||
accepted_observation_id: applied.accepted_observation_id,
|
||||
accepted_evidence_id: applied.accepted_evidence_id,
|
||||
finding: protocol_reorient_finding(applied.finding),
|
||||
},
|
||||
)
|
||||
.await;
|
||||
self.send_epiphany_state_updated(
|
||||
thread_uuid,
|
||||
ThreadEpiphanyStateUpdatedSource::ReorientAccept,
|
||||
changed_fields,
|
||||
epiphany_state,
|
||||
)
|
||||
.await;
|
||||
}
|
||||
|
||||
pub(super) async fn thread_epiphany_index(
|
||||
&self,
|
||||
request_id: ConnectionRequestId,
|
||||
params: ThreadEpiphanyIndexParams,
|
||||
) {
|
||||
let ThreadEpiphanyIndexParams {
|
||||
thread_id,
|
||||
force_full_rebuild,
|
||||
} = params;
|
||||
|
||||
let (thread_uuid, thread) = match self.load_epiphany_thread(&request_id, &thread_id).await {
|
||||
Some(thread) => thread,
|
||||
None => return,
|
||||
};
|
||||
|
||||
let config = thread.config_snapshot().await;
|
||||
let codex_home = thread.codex_home().await;
|
||||
let response = match index_epiphany_retrieval_for_paths(
|
||||
config.cwd.to_path_buf(),
|
||||
codex_home,
|
||||
force_full_rebuild,
|
||||
)
|
||||
.await
|
||||
.and_then(protocol_index_response)
|
||||
{
|
||||
Ok(response) => response,
|
||||
Err(err) => {
|
||||
self.send_internal_error(
|
||||
request_id,
|
||||
format!("failed to index Epiphany retrieval state for {thread_uuid}: {err}"),
|
||||
)
|
||||
.await;
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
self.outgoing.send_response(request_id, response).await;
|
||||
}
|
||||
|
||||
pub(super) async fn thread_epiphany_promote(
|
||||
&self,
|
||||
request_id: ConnectionRequestId,
|
||||
params: ThreadEpiphanyPromoteParams,
|
||||
) {
|
||||
let ThreadEpiphanyPromoteParams {
|
||||
thread_id,
|
||||
expected_revision,
|
||||
patch,
|
||||
verifier_evidence,
|
||||
} = 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_promote(
|
||||
&host,
|
||||
expected_revision,
|
||||
core_patch,
|
||||
verifier_evidence,
|
||||
)
|
||||
.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 promote Epiphany state update: {err}"),
|
||||
)
|
||||
.await;
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
pub(super) async fn thread_epiphany_update(
|
||||
&self,
|
||||
request_id: ConnectionRequestId,
|
||||
|
|
@ -591,97 +122,6 @@ impl CodexMessageProcessor {
|
|||
.await;
|
||||
}
|
||||
|
||||
pub(super) async fn thread_epiphany_job_launch(
|
||||
&self,
|
||||
request_id: ConnectionRequestId,
|
||||
params: ThreadEpiphanyJobLaunchParams,
|
||||
) {
|
||||
let ThreadEpiphanyJobLaunchParams {
|
||||
thread_id,
|
||||
expected_revision,
|
||||
binding_id,
|
||||
kind,
|
||||
scope,
|
||||
owner_role,
|
||||
authority_scope,
|
||||
linked_subgoal_ids,
|
||||
linked_graph_node_ids,
|
||||
instruction,
|
||||
launch_document,
|
||||
output_contract_id,
|
||||
max_runtime_seconds,
|
||||
} = 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_launch_document = protocol_worker_launch_document_to_core(launch_document);
|
||||
let applied = match launch_thread_epiphany_job(
|
||||
&host,
|
||||
build_epiphany_job_launch_request(
|
||||
expected_revision,
|
||||
binding_id.clone(),
|
||||
kind,
|
||||
scope,
|
||||
owner_role,
|
||||
authority_scope,
|
||||
linked_subgoal_ids,
|
||||
linked_graph_node_ids,
|
||||
instruction,
|
||||
core_launch_document,
|
||||
output_contract_id,
|
||||
max_runtime_seconds,
|
||||
),
|
||||
kind,
|
||||
"missing launched job projection",
|
||||
)
|
||||
.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 launch 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,
|
||||
ThreadEpiphanyJobLaunchResponse {
|
||||
revision: applied.revision,
|
||||
changed_fields: protocol_changed_fields,
|
||||
epiphany_state: epiphany_state.clone(),
|
||||
job: protocol_job_from_surface(
|
||||
applied.job,
|
||||
Some(applied.launcher_job_id),
|
||||
Some(applied.backend_job_id),
|
||||
),
|
||||
},
|
||||
)
|
||||
.await;
|
||||
self.send_epiphany_state_updated(
|
||||
thread_uuid,
|
||||
ThreadEpiphanyStateUpdatedSource::JobLaunch,
|
||||
changed_fields,
|
||||
epiphany_state,
|
||||
)
|
||||
.await;
|
||||
}
|
||||
|
||||
pub(super) async fn thread_epiphany_job_interrupt(
|
||||
&self,
|
||||
request_id: ConnectionRequestId,
|
||||
|
|
@ -748,9 +188,3 @@ impl CodexMessageProcessor {
|
|||
.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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ use codex_app_server_protocol::*;
|
|||
use codex_core::CodexThread;
|
||||
use codex_protocol::ThreadId;
|
||||
use epiphany_state_model::EpiphanyRetrievalState;
|
||||
use super::epiphany_thread_host::load_authoritative_epiphany_state;
|
||||
use super::epiphany_thread_host::runtime_spine_store_path;
|
||||
use epiphany_codex_bridge::cultnet::EpiphanySurfaceSource;
|
||||
use epiphany_codex_bridge::invalidation::epiphany_freshness_watcher_snapshot;
|
||||
|
|
@ -14,24 +13,18 @@ use epiphany_codex_bridge::protocol_edge::core_epiphany_view_needs_reorientation
|
|||
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_distill_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::retrieve::normalize_thread_epiphany_retrieve_query;
|
||||
use epiphany_codex_bridge::retrieve::retrieve_epiphany_for_paths;
|
||||
use epiphany_codex_bridge::retrieve_protocol::protocol_retrieve_response;
|
||||
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_distill_response;
|
||||
use epiphany_codex_bridge::view_protocol::map_epiphany_graph_query_response;
|
||||
use epiphany_codex_bridge::view_protocol::map_epiphany_propose_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;
|
||||
|
|
@ -415,171 +408,7 @@ impl CodexMessageProcessor {
|
|||
self.outgoing.send_response(request_id, response).await;
|
||||
}
|
||||
|
||||
pub(super) async fn thread_epiphany_retrieve(
|
||||
&self,
|
||||
request_id: ConnectionRequestId,
|
||||
params: ThreadEpiphanyRetrieveParams,
|
||||
) {
|
||||
let ThreadEpiphanyRetrieveParams {
|
||||
thread_id,
|
||||
query,
|
||||
limit,
|
||||
path_prefixes,
|
||||
} = 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 query = match normalize_thread_epiphany_retrieve_query(query, limit, path_prefixes) {
|
||||
Ok(query) => query,
|
||||
Err(message) => {
|
||||
self.send_invalid_request_error(request_id, message.to_string())
|
||||
.await;
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
let thread = match self.thread_manager.get_thread(thread_uuid).await {
|
||||
Ok(thread) => thread,
|
||||
Err(_) => {
|
||||
self.send_invalid_request_error(
|
||||
request_id,
|
||||
format!("thread not loaded: {thread_uuid}"),
|
||||
)
|
||||
.await;
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
let config = thread.config_snapshot().await;
|
||||
let codex_home = thread.codex_home().await;
|
||||
let response =
|
||||
match retrieve_epiphany_for_paths(config.cwd.to_path_buf(), codex_home, query)
|
||||
.await
|
||||
.and_then(protocol_retrieve_response)
|
||||
{
|
||||
Ok(response) => response,
|
||||
Err(err) => {
|
||||
self.send_internal_error(
|
||||
request_id,
|
||||
format!("failed to retrieve Epiphany results for {thread_uuid}: {err}"),
|
||||
)
|
||||
.await;
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
self.outgoing.send_response(request_id, response).await;
|
||||
}
|
||||
|
||||
pub(super) async fn thread_epiphany_distill(
|
||||
&self,
|
||||
request_id: ConnectionRequestId,
|
||||
params: ThreadEpiphanyDistillParams,
|
||||
) {
|
||||
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 thread = match self.thread_manager.get_thread(thread_uuid).await {
|
||||
Ok(thread) => thread,
|
||||
Err(_) => {
|
||||
self.send_invalid_request_error(
|
||||
request_id,
|
||||
format!("thread not loaded: {thread_uuid}"),
|
||||
)
|
||||
.await;
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
let expected_revision = load_authoritative_epiphany_state(&thread)
|
||||
.await
|
||||
.map(|state| state.revision)
|
||||
.unwrap_or(0);
|
||||
let input = protocol_distill_params_to_core(params);
|
||||
let response = match map_epiphany_distill_response(expected_revision, input) {
|
||||
Ok(response) => response,
|
||||
Err(err) => {
|
||||
self.send_invalid_request_error(
|
||||
request_id,
|
||||
format!("failed to distill Epiphany observation: {err}"),
|
||||
)
|
||||
.await;
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
self.outgoing.send_response(request_id, response).await;
|
||||
}
|
||||
|
||||
pub(super) async fn thread_epiphany_propose(
|
||||
&self,
|
||||
request_id: ConnectionRequestId,
|
||||
params: ThreadEpiphanyProposeParams,
|
||||
) {
|
||||
let ThreadEpiphanyProposeParams { thread_id, .. } = ¶ms;
|
||||
let thread_id = 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 thread = match self.thread_manager.get_thread(thread_uuid).await {
|
||||
Ok(thread) => thread,
|
||||
Err(_) => {
|
||||
self.send_invalid_request_error(
|
||||
request_id,
|
||||
format!("thread not loaded: {thread_uuid}"),
|
||||
)
|
||||
.await;
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
let state = match load_authoritative_epiphany_state(&thread).await {
|
||||
Some(state) => state,
|
||||
None => {
|
||||
self.send_invalid_request_error(
|
||||
request_id,
|
||||
format!("thread has no Epiphany state: {thread_uuid}"),
|
||||
)
|
||||
.await;
|
||||
return;
|
||||
}
|
||||
};
|
||||
let response = match map_epiphany_propose_response(state, params.observation_ids) {
|
||||
Ok(response) => response,
|
||||
Err(err) => {
|
||||
self.send_invalid_request_error(
|
||||
request_id,
|
||||
format!("failed to propose Epiphany map update: {err}"),
|
||||
)
|
||||
.await;
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
self.outgoing.send_response(request_id, response).await;
|
||||
}
|
||||
}
|
||||
|
||||
async fn thread_epiphany_retrieval_state(thread: &CodexThread) -> EpiphanyRetrievalState {
|
||||
|
|
|
|||
Reference in a new issue