diff --git a/epiphany-codex-bridge/src/retrieve.rs b/epiphany-codex-bridge/src/retrieve.rs index 6cdf3fec..aa23b491 100644 --- a/epiphany-codex-bridge/src/retrieve.rs +++ b/epiphany-codex-bridge/src/retrieve.rs @@ -1,8 +1,10 @@ +use codex_app_server_protocol::ThreadEpiphanyIndexResponse; use codex_app_server_protocol::ThreadEpiphanyRetrieveIndexSummary; use codex_app_server_protocol::ThreadEpiphanyRetrieveResponse; use codex_app_server_protocol::ThreadEpiphanyRetrieveResult; use codex_app_server_protocol::ThreadEpiphanyRetrieveResultKind; use codex_app_server_protocol::ThreadEpiphanyRetrieveShardSummary; +use codex_core::CodexThread; use codex_core::EpiphanyRetrieveResponse as CoreEpiphanyRetrieveResponse; use codex_core::EpiphanyRetrieveResult as CoreEpiphanyRetrieveResult; use codex_core::EpiphanyRetrieveResultKind as CoreEpiphanyRetrieveResultKind; @@ -23,6 +25,17 @@ pub fn map_epiphany_retrieve_response( }) } +pub async fn index_thread_epiphany_retrieval( + thread: &CodexThread, + force_full_rebuild: bool, +) -> anyhow::Result { + let index_summary = thread + .epiphany_index(force_full_rebuild) + .await + .and_then(map_epiphany_retrieve_index_summary)?; + Ok(ThreadEpiphanyIndexResponse { index_summary }) +} + pub fn map_epiphany_retrieve_index_summary( summary: EpiphanyRetrievalState, ) -> anyhow::Result { diff --git a/notes/fresh-workspace-handoff.md b/notes/fresh-workspace-handoff.md index f3036df7..709cc4db 100644 --- a/notes/fresh-workspace-handoff.md +++ b/notes/fresh-workspace-handoff.md @@ -644,6 +644,15 @@ The vendored route still performs app-server-native work: thread-id parsing, thread/read-view loading, watcher registration/snapshotting, JSON-RPC response shaping, and notification emission. +The next small route cut landed without pretending it was the final purge. +`epiphany-codex-bridge::retrieve::index_thread_epiphany_retrieval` now owns the +index operation/protocol projection, and `epiphany_mutation_routes.rs` collapsed +its repeated parse/load-thread and state-updated notification boilerplate into +transport-only helpers. The mutation route module is about 691 lines. This is +adapter consolidation, not a new architectural throne: app-server still owns +JSON-RPC response shape and watcher/thread-view details while the bridge owns +route-independent Epiphany work. + Also: MCP itself is allowed to be JSON. The target is not "replace MCP JSON"; the target is an Epiphany-owned boundary that speaks typed Epiphany intent/result/receipt documents internally and normal MCP JSON-RPC externally. diff --git a/state/ledgers.msgpack b/state/ledgers.msgpack index 4c1201a0..5fbf1375 100644 Binary files a/state/ledgers.msgpack and b/state/ledgers.msgpack differ diff --git a/state/map.yaml b/state/map.yaml index e3f136c9..90a17d4a 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -279,5 +279,5 @@ rejected_paths: reason: making Epiphany cleaner inside Codex still preserves the wrong organ; Codex must be starved down to OpenAI subscription auth/model transport, while Epiphany data and subsystem communication move to typed CultCache/CultNet. current_status: - summary: The Codex starvation pass has five typing receipts, seventeen processor cuts, a real physical extraction in `epiphany-codex-bridge`, a source-grounded Codex auth spine inventory, the native `epiphany-openai-adapter` document boundary, a buildable Codex auth/model wrapper in `epiphany-openai-codex-spine`, the first native runtime caller in `epiphany-openai-runtime`, native heartbeat launch planning/job opening in `epiphany-core`, native state-update contract/validation/application in `epiphany-core`, and the route-facing mutation service in `epiphany-codex-bridge`. The bridge owns Codex-facing Epiphany adapters for scene, jobs, context/planning/graph query, retrieval, result projection, runtime-spine result adaptation, launch/prompt doctrine, mutation document mechanics, mutation service update/promote/role-accept/reorient-accept/role-launch/reorient-launch/job-launch/job-interrupt application, live-state projection, pressure/pre-compaction rendering, freshness/reorientation projection, CRRC/coordinator/role-board projection, and acceptance/evidence signal helpers. Vendored app-server now retains only `epiphany_invalidation.rs` as a root Epiphany module because watcher lifecycle is still app-server machinery; `codex_message_processor.rs` still contains route dispatch, JSON-RPC response shaping, watcher registration/snapshotting, and notification emission. The processor is about 10,339 lines, `epiphany_mutation_routes.rs` is about 815 lines after the reorient-launch service cut, `epiphany_state_helpers.rs` is down to a 19-line rollout-state loader, and `codex_thread.rs` is about 1,425 lines after state-update law moved native. `epiphany-openai-adapter` defines CultCache `DatabaseEntry` request/event/receipt/auth-status documents with no Codex app-server or generic JSON dependency. `epiphany-openai-codex-spine` projects `AuthManager` / `CodexAuth` into typed `EpiphanyOpenAiAdapterStatus`, maps typed `EpiphanyOpenAiModelRequest` into Codex API `ResponsesApiRequest`, resolves auth/provider through keeper Codex crates, opens HTTP Responses streams through `codex-api`, and maps deltas/completion into typed stream events and receipts. `epiphany-openai-runtime` writes OpenAI status/request/stream-event/receipt records plus runtime sessions/jobs/results/events into `epiphany-core::runtime_spine_cache`, and its smoke proves the route without network. `epiphany-core::plan_runtime_spine_heartbeat_launch` validates launch contracts/conflicts and projects durable job bindings/runtime links; `epiphany-core::open_runtime_spine_heartbeat_job` owns the initialize-runtime/ensure-session/create-job sequence; `epiphany-core::EpiphanyStateUpdate`, `epiphany_state_update_validation_errors`, and `apply_epiphany_state_update` own state-update document shape and mutation law while `codex-core` calls them for compatibility. Vendored `CodexThread::epiphany_launch_job` is now mostly revision check, persistence validation, and rollout/session writeback for the compatibility route. `epiphany-runtime-spine` advertises OpenAI adapter status/model-request/stream-event/receipt CultNet schemas and mutation contracts, so the native caller now has a real storage route instead of only JSON-RPC. MCP itself is correctly JSON at its protocol edge; the target is typed Epiphany intent/result/receipt wrappers around MCP, not replacing MCP JSON. The current OpenAI spine still pulls `codex-api` and a large transport dependency stack, so its next cut is dependency starvation after live callers move. - next_action: Continue Codex starvation by collapsing the remaining vendored `epiphany_mutation_routes.rs` JSON-RPC boilerplate where it still duplicates thread parsing/load/respond/notify patterns, then move live model-turn callers onto `epiphany-openai-runtime` or the same native CultNet contract and shrink the surviving Codex dependency surface to credential refresh, provider/model routing, and the smallest OpenAI Responses call required for Codex subscription compatibility. + summary: The Codex starvation pass has five typing receipts, eighteen processor cuts, a real physical extraction in `epiphany-codex-bridge`, a source-grounded Codex auth spine inventory, the native `epiphany-openai-adapter` document boundary, a buildable Codex auth/model wrapper in `epiphany-openai-codex-spine`, the first native runtime caller in `epiphany-openai-runtime`, native heartbeat launch planning/job opening in `epiphany-core`, native state-update contract/validation/application in `epiphany-core`, and the route-facing mutation service in `epiphany-codex-bridge`. The bridge owns Codex-facing Epiphany adapters for scene, jobs, context/planning/graph query, retrieval/indexing projection, result projection, runtime-spine result adaptation, launch/prompt doctrine, mutation document mechanics, mutation service update/promote/role-accept/reorient-accept/role-launch/reorient-launch/job-launch/job-interrupt application, live-state projection, pressure/pre-compaction rendering, freshness/reorientation projection, CRRC/coordinator/role-board projection, and acceptance/evidence signal helpers. Vendored app-server now retains only `epiphany_invalidation.rs` as a root Epiphany module because watcher lifecycle is still app-server machinery; `codex_message_processor.rs` still contains route dispatch, JSON-RPC response shaping, watcher registration/snapshotting, and notification emission. The processor is about 10,339 lines, `epiphany_mutation_routes.rs` is about 691 lines after the route-load/notification helper cut and index projection move, `epiphany_state_helpers.rs` is down to a 19-line rollout-state loader, and `codex_thread.rs` is about 1,425 lines after state-update law moved native. `epiphany-openai-adapter` defines CultCache `DatabaseEntry` request/event/receipt/auth-status documents with no Codex app-server or generic JSON dependency. `epiphany-openai-codex-spine` projects `AuthManager` / `CodexAuth` into typed `EpiphanyOpenAiAdapterStatus`, maps typed `EpiphanyOpenAiModelRequest` into Codex API `ResponsesApiRequest`, resolves auth/provider through keeper Codex crates, opens HTTP Responses streams through `codex-api`, and maps deltas / completion into typed stream events and receipts. `epiphany-openai-runtime` writes OpenAI status/request/stream-event/receipt records plus runtime sessions/jobs/results/events into `epiphany-core::runtime_spine_cache`, and its smoke proves the route without network. `epiphany-core::plan_runtime_spine_heartbeat_launch` validates launch contracts/conflicts and projects durable job bindings/runtime links; `epiphany-core::open_runtime_spine_heartbeat_job` owns the initialize-runtime/ensure-session/create-job sequence; `epiphany-core::EpiphanyStateUpdate`, `epiphany_state_update_validation_errors`, and `apply_epiphany_state_update` own state-update document shape and mutation law while `codex-core` calls them for compatibility. Vendored `CodexThread::epiphany_launch_job` is now mostly revision check, persistence validation, and rollout/session writeback for the compatibility route. `epiphany-runtime-spine` advertises OpenAI adapter status/model-request/stream-event/receipt CultNet schemas and mutation contracts, so the native caller now has a real storage route instead of only JSON-RPC. MCP itself is correctly JSON at its protocol edge; the target is typed Epiphany intent/result/receipt wrappers around MCP, not replacing MCP JSON. The current OpenAI spine still pulls `codex-api` and a large transport dependency stack, so its next cut is dependency starvation after live callers move. + next_action: Move live model-turn callers onto `epiphany-openai-runtime` or the same native CultNet contract, then shrink the surviving Codex dependency surface to credential refresh, provider/model routing, and the smallest OpenAI Responses call required for Codex subscription compatibility. diff --git a/vendor/codex/codex-rs/app-server/src/codex_message_processor/epiphany_mutation_routes.rs b/vendor/codex/codex-rs/app-server/src/codex_message_processor/epiphany_mutation_routes.rs index 7d8c4bd8..4934867f 100644 --- a/vendor/codex/codex-rs/app-server/src/codex_message_processor/epiphany_mutation_routes.rs +++ b/vendor/codex/codex-rs/app-server/src/codex_message_processor/epiphany_mutation_routes.rs @@ -1,21 +1,24 @@ use codex_app_server_protocol::*; +use codex_core::CodexThread; use codex_core::EpiphanyJobLaunchRequest; use codex_protocol::ThreadId; use codex_protocol::error::CodexErr; +use codex_protocol::protocol::EpiphanyThreadState; use epiphany_codex_bridge::launch::EPIPHANY_REORIENT_LAUNCH_BINDING_ID; use epiphany_codex_bridge::launch::epiphany_role_binding_id; use epiphany_codex_bridge::launch::map_core_worker_launch_document; use epiphany_codex_bridge::mutation::epiphany_state_updated_notification; 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_promote; 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::retrieve::map_epiphany_retrieve_index_summary; +use epiphany_codex_bridge::retrieve::index_thread_epiphany_retrieval; +use std::sync::Arc; use super::CodexMessageProcessor; use super::ConnectionRequestId; @@ -23,6 +26,58 @@ use super::ThreadReadViewError; use super::epiphany_freshness_watcher_snapshot; impl CodexMessageProcessor { + async fn load_epiphany_thread( + &self, + request_id: &ConnectionRequestId, + thread_id: &str, + ) -> Option<(ThreadId, Arc)> { + 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, + epiphany_state: EpiphanyThreadState, + ) { + self.outgoing + .send_server_notification(ServerNotification::ThreadEpiphanyStateUpdated( + epiphany_state_updated_notification( + thread_uuid.to_string(), + source, + epiphany_state.revision, + changed_fields, + epiphany_state, + ), + )) + .await; + } + pub(super) async fn thread_epiphany_role_launch( &self, request_id: ConnectionRequestId, @@ -35,26 +90,11 @@ impl CodexMessageProcessor { max_runtime_seconds, } = 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 = 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 (thread_uuid, loaded_thread) = + match self.load_epiphany_thread(&request_id, &thread_id).await { + Some(thread) => thread, + None => return, + }; let applied = match launch_thread_epiphany_role( loaded_thread.as_ref(), &thread_id, @@ -94,17 +134,13 @@ impl CodexMessageProcessor { }, ) .await; - self.outgoing - .send_server_notification(ServerNotification::ThreadEpiphanyStateUpdated( - epiphany_state_updated_notification( - thread_uuid.to_string(), - ThreadEpiphanyStateUpdatedSource::JobLaunch, - epiphany_state.revision, - changed_fields, - epiphany_state, - ), - )) - .await; + self.send_epiphany_state_updated( + thread_uuid, + ThreadEpiphanyStateUpdatedSource::JobLaunch, + changed_fields, + epiphany_state, + ) + .await; } pub(super) async fn thread_epiphany_role_accept( @@ -128,26 +164,11 @@ impl CodexMessageProcessor { }; let binding_id = binding_id.unwrap_or_else(|| default_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 = 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 (thread_uuid, loaded_thread) = + match self.load_epiphany_thread(&request_id, &thread_id).await { + Some(thread) => thread, + None => return, + }; let applied = match apply_thread_epiphany_role_accept( loaded_thread.as_ref(), role_id, @@ -190,17 +211,13 @@ impl CodexMessageProcessor { }, ) .await; - self.outgoing - .send_server_notification(ServerNotification::ThreadEpiphanyStateUpdated( - epiphany_state_updated_notification( - thread_uuid.to_string(), - ThreadEpiphanyStateUpdatedSource::RoleAccept, - epiphany_state.revision, - changed_fields, - epiphany_state, - ), - )) - .await; + self.send_epiphany_state_updated( + thread_uuid, + ThreadEpiphanyStateUpdatedSource::RoleAccept, + changed_fields, + epiphany_state, + ) + .await; } pub(super) async fn thread_epiphany_reorient_launch( @@ -214,26 +231,11 @@ impl CodexMessageProcessor { max_runtime_seconds, } = 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 = 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 (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)) => { @@ -303,17 +305,13 @@ impl CodexMessageProcessor { }, ) .await; - self.outgoing - .send_server_notification(ServerNotification::ThreadEpiphanyStateUpdated( - epiphany_state_updated_notification( - thread_uuid.to_string(), - ThreadEpiphanyStateUpdatedSource::JobLaunch, - epiphany_state.revision, - changed_fields, - epiphany_state, - ), - )) - .await; + self.send_epiphany_state_updated( + thread_uuid, + ThreadEpiphanyStateUpdatedSource::JobLaunch, + changed_fields, + epiphany_state, + ) + .await; } pub(super) async fn thread_epiphany_reorient_accept( @@ -330,26 +328,11 @@ impl CodexMessageProcessor { } = 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 = 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 (thread_uuid, loaded_thread) = + match self.load_epiphany_thread(&request_id, &thread_id).await { + Some(thread) => thread, + None => return, + }; let applied = match apply_thread_epiphany_reorient_accept( loaded_thread.as_ref(), expected_revision, @@ -391,17 +374,13 @@ impl CodexMessageProcessor { }, ) .await; - self.outgoing - .send_server_notification(ServerNotification::ThreadEpiphanyStateUpdated( - epiphany_state_updated_notification( - thread_uuid.to_string(), - ThreadEpiphanyStateUpdatedSource::ReorientAccept, - epiphany_state.revision, - changed_fields, - epiphany_state, - ), - )) - .await; + self.send_epiphany_state_updated( + thread_uuid, + ThreadEpiphanyStateUpdatedSource::ReorientAccept, + changed_fields, + epiphany_state, + ) + .await; } pub(super) async fn thread_epiphany_index( @@ -414,32 +393,13 @@ impl CodexMessageProcessor { force_full_rebuild, } = 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 (thread_uuid, thread) = match self.load_epiphany_thread(&request_id, &thread_id).await { + Some(thread) => thread, + None => 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 response = match thread - .epiphany_index(force_full_rebuild) + let response = match index_thread_epiphany_retrieval(thread.as_ref(), force_full_rebuild) .await - .and_then(map_epiphany_retrieve_index_summary) - .map(|index_summary| ThreadEpiphanyIndexResponse { index_summary }) { Ok(response) => response, Err(err) => { @@ -467,25 +427,9 @@ impl CodexMessageProcessor { verifier_evidence, } = 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 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 (thread_uuid, thread) = match self.load_epiphany_thread(&request_id, &thread_id).await { + Some(thread) => thread, + None => return, }; let applied = match apply_thread_epiphany_promote( @@ -540,17 +484,13 @@ impl CodexMessageProcessor { }; self.outgoing.send_response(request_id, response).await; - self.outgoing - .send_server_notification(ServerNotification::ThreadEpiphanyStateUpdated( - epiphany_state_updated_notification( - thread_uuid.to_string(), - ThreadEpiphanyStateUpdatedSource::Promote, - epiphany_state.revision, - changed_fields, - epiphany_state, - ), - )) - .await; + self.send_epiphany_state_updated( + thread_uuid, + ThreadEpiphanyStateUpdatedSource::Promote, + changed_fields, + epiphany_state, + ) + .await; } pub(super) async fn thread_epiphany_update( @@ -564,44 +504,27 @@ impl CodexMessageProcessor { patch, } = 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}")) + let (thread_uuid, thread) = match self.load_epiphany_thread(&request_id, &thread_id).await { + Some(thread) => thread, + None => return, + }; + + let applied = + match apply_thread_epiphany_update(thread.as_ref(), expected_revision, patch).await { + Ok(applied) => applied, + Err(CodexErr::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 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 applied = match apply_thread_epiphany_update(thread.as_ref(), expected_revision, patch) - .await - { - Ok(applied) => applied, - Err(CodexErr::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; - } - }; + return; + } + }; let changed_fields = applied.changed_fields; let epiphany_state = applied.epiphany_state; let response = ThreadEpiphanyUpdateResponse { @@ -611,17 +534,13 @@ impl CodexMessageProcessor { }; self.outgoing.send_response(request_id, response).await; - self.outgoing - .send_server_notification(ServerNotification::ThreadEpiphanyStateUpdated( - epiphany_state_updated_notification( - thread_uuid.to_string(), - ThreadEpiphanyStateUpdatedSource::Update, - epiphany_state.revision, - changed_fields, - epiphany_state, - ), - )) - .await; + self.send_epiphany_state_updated( + thread_uuid, + ThreadEpiphanyStateUpdatedSource::Update, + changed_fields, + epiphany_state, + ) + .await; } pub(super) async fn thread_epiphany_job_launch( @@ -645,25 +564,9 @@ impl CodexMessageProcessor { max_runtime_seconds, } = 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 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 (thread_uuid, thread) = match self.load_epiphany_thread(&request_id, &thread_id).await { + Some(thread) => thread, + None => return, }; let launch_document = map_core_worker_launch_document(launch_document); @@ -716,17 +619,13 @@ impl CodexMessageProcessor { }, ) .await; - self.outgoing - .send_server_notification(ServerNotification::ThreadEpiphanyStateUpdated( - epiphany_state_updated_notification( - thread_uuid.to_string(), - ThreadEpiphanyStateUpdatedSource::JobLaunch, - epiphany_state.revision, - changed_fields, - epiphany_state, - ), - )) - .await; + self.send_epiphany_state_updated( + thread_uuid, + ThreadEpiphanyStateUpdatedSource::JobLaunch, + changed_fields, + epiphany_state, + ) + .await; } pub(super) async fn thread_epiphany_job_interrupt( @@ -741,25 +640,9 @@ impl CodexMessageProcessor { reason, } = 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 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 (thread_uuid, thread) = match self.load_epiphany_thread(&request_id, &thread_id).await { + Some(thread) => thread, + None => return, }; let applied = match interrupt_thread_epiphany_job( @@ -800,16 +683,12 @@ impl CodexMessageProcessor { }, ) .await; - self.outgoing - .send_server_notification(ServerNotification::ThreadEpiphanyStateUpdated( - epiphany_state_updated_notification( - thread_uuid.to_string(), - ThreadEpiphanyStateUpdatedSource::JobInterrupt, - epiphany_state.revision, - changed_fields, - epiphany_state, - ), - )) - .await; + self.send_epiphany_state_updated( + thread_uuid, + ThreadEpiphanyStateUpdatedSource::JobInterrupt, + changed_fields, + epiphany_state, + ) + .await; } }