Move Epiphany thread policy to bridge
This commit is contained in:
parent
d510f39b4c
commit
8f9b7ab3b5
13 changed files with 332 additions and 343 deletions
|
|
@ -1,5 +1,7 @@
|
|||
use chrono::SecondsFormat;
|
||||
use chrono::Utc;
|
||||
use std::path::Path;
|
||||
|
||||
use codex_app_server_protocol::ThreadEpiphanyJob;
|
||||
use codex_app_server_protocol::ThreadEpiphanyJobKind;
|
||||
use codex_app_server_protocol::ThreadEpiphanyReorientDecision;
|
||||
|
|
@ -18,9 +20,20 @@ use codex_protocol::protocol::EpiphanyRetrievalState;
|
|||
use codex_protocol::protocol::EpiphanyThreadState;
|
||||
use codex_protocol::protocol::TokenUsageInfo as CoreTokenUsageInfo;
|
||||
use epiphany_core::EpiphanyJobInterruptRequest;
|
||||
use epiphany_core::EpiphanyJobInterruptResult;
|
||||
use epiphany_core::EpiphanyJobLaunchRequest;
|
||||
use epiphany_core::EpiphanyJobLaunchResult;
|
||||
use epiphany_core::EpiphanyPromotionInput;
|
||||
use epiphany_core::EpiphanyStateUpdate;
|
||||
use epiphany_core::RuntimeSpineHeartbeatJobOptions;
|
||||
use epiphany_core::RuntimeSpineHeartbeatLaunchPlanOptions;
|
||||
use epiphany_core::apply_epiphany_state_update;
|
||||
use epiphany_core::clear_epiphany_job_binding_backend;
|
||||
use epiphany_core::epiphany_state_update_validation_errors;
|
||||
use epiphany_core::evaluate_promotion;
|
||||
use epiphany_core::open_runtime_spine_heartbeat_job;
|
||||
use epiphany_core::plan_runtime_spine_heartbeat_launch;
|
||||
use epiphany_core::replace_or_append_epiphany_job_binding;
|
||||
|
||||
use crate::jobs::epiphany_blocked_state_job;
|
||||
use crate::jobs::map_epiphany_jobs;
|
||||
|
|
@ -112,6 +125,161 @@ pub struct EpiphanyReorientLaunchApplied {
|
|||
pub job: ThreadEpiphanyJob,
|
||||
}
|
||||
|
||||
pub async fn apply_epiphany_state_update_to_thread(
|
||||
thread: &CodexThread,
|
||||
update: EpiphanyStateUpdate,
|
||||
) -> Result<EpiphanyThreadState, CodexErr> {
|
||||
if update.is_empty() {
|
||||
return Err(CodexErr::InvalidRequest(
|
||||
"epiphany update patch must contain at least one mutation".to_string(),
|
||||
));
|
||||
}
|
||||
|
||||
let mut next_state = thread.epiphany_state().await.unwrap_or_default();
|
||||
if let Some(expected_revision) = update.expected_revision
|
||||
&& next_state.revision != expected_revision
|
||||
{
|
||||
return Err(CodexErr::InvalidRequest(format!(
|
||||
"epiphany state revision mismatch: expected {expected_revision}, found {}",
|
||||
next_state.revision
|
||||
)));
|
||||
}
|
||||
|
||||
let validation_errors = epiphany_state_update_validation_errors(&next_state, &update);
|
||||
if !validation_errors.is_empty() {
|
||||
return Err(CodexErr::InvalidRequest(format!(
|
||||
"invalid epiphany update patch: {}",
|
||||
validation_errors.join("; ")
|
||||
)));
|
||||
}
|
||||
|
||||
let reference_turn_id = thread.epiphany_reference_turn_id().await;
|
||||
apply_epiphany_state_update(&mut next_state, update, reference_turn_id);
|
||||
thread.epiphany_persist_state(next_state).await
|
||||
}
|
||||
|
||||
pub async fn launch_epiphany_job_on_thread(
|
||||
thread: &CodexThread,
|
||||
request: EpiphanyJobLaunchRequest,
|
||||
) -> Result<EpiphanyJobLaunchResult, CodexErr> {
|
||||
let current_state = thread.epiphany_state().await.unwrap_or_default();
|
||||
validate_expected_revision(request.expected_revision, current_state.revision)?;
|
||||
|
||||
let launcher_job_id = format!("epiphany-heartbeat-launch-{}", Uuid::new_v4());
|
||||
let backend_job_id = Uuid::new_v4().to_string();
|
||||
let launch_plan = plan_runtime_spine_heartbeat_launch(
|
||||
¤t_state,
|
||||
RuntimeSpineHeartbeatLaunchPlanOptions {
|
||||
binding_id: request.binding_id.clone(),
|
||||
kind: request.kind,
|
||||
scope: request.scope.clone(),
|
||||
owner_role: request.owner_role.clone(),
|
||||
authority_scope: request.authority_scope.clone(),
|
||||
linked_subgoal_ids: request.linked_subgoal_ids.clone(),
|
||||
linked_graph_node_ids: request.linked_graph_node_ids.clone(),
|
||||
instruction: request.instruction.clone(),
|
||||
launch_document: request.launch_document.clone(),
|
||||
output_contract_id: request.output_contract_id.clone(),
|
||||
max_runtime_seconds: request.max_runtime_seconds,
|
||||
runtime_job_id: backend_job_id.clone(),
|
||||
},
|
||||
)
|
||||
.map_err(|err| CodexErr::InvalidRequest(err.to_string()))?;
|
||||
let runtime_store = thread.epiphany_runtime_spine_store_path().await;
|
||||
open_epiphany_runtime_spine_job(
|
||||
runtime_store.as_path(),
|
||||
¤t_state,
|
||||
&request,
|
||||
backend_job_id.as_str(),
|
||||
)?;
|
||||
let next_job_bindings = replace_or_append_epiphany_job_binding(
|
||||
current_state.job_bindings.clone(),
|
||||
launch_plan.binding,
|
||||
);
|
||||
|
||||
let validation_errors = epiphany_state_update_validation_errors(
|
||||
¤t_state,
|
||||
&EpiphanyStateUpdate {
|
||||
job_bindings: Some(next_job_bindings.clone()),
|
||||
runtime_links: vec![launch_plan.runtime_link.clone()],
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
if !validation_errors.is_empty() {
|
||||
return Err(CodexErr::InvalidRequest(format!(
|
||||
"invalid Epiphany job launch patch: {}",
|
||||
validation_errors.join("; ")
|
||||
)));
|
||||
}
|
||||
|
||||
let epiphany_state = apply_epiphany_state_update_to_thread(
|
||||
thread,
|
||||
EpiphanyStateUpdate {
|
||||
expected_revision: request.expected_revision,
|
||||
job_bindings: Some(next_job_bindings),
|
||||
runtime_links: vec![launch_plan.runtime_link],
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(EpiphanyJobLaunchResult {
|
||||
epiphany_state,
|
||||
binding_id: request.binding_id,
|
||||
launcher_job_id,
|
||||
backend_job_id,
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn interrupt_epiphany_job_on_thread(
|
||||
thread: &CodexThread,
|
||||
request: EpiphanyJobInterruptRequest,
|
||||
) -> Result<EpiphanyJobInterruptResult, CodexErr> {
|
||||
if request.binding_id.trim().is_empty() {
|
||||
return Err(CodexErr::InvalidRequest(
|
||||
"epiphany job interrupt binding_id must be non-empty".to_string(),
|
||||
));
|
||||
}
|
||||
|
||||
let current_state = thread.epiphany_state().await.unwrap_or_default();
|
||||
validate_expected_revision(request.expected_revision, current_state.revision)?;
|
||||
|
||||
let Some(binding_index) = current_state
|
||||
.job_bindings
|
||||
.iter()
|
||||
.position(|binding| binding.id == request.binding_id)
|
||||
else {
|
||||
return Err(CodexErr::InvalidRequest(format!(
|
||||
"epiphany job binding {:?} was not found",
|
||||
request.binding_id
|
||||
)));
|
||||
};
|
||||
let interrupted_thread_ids = Vec::new();
|
||||
let cancel_requested = false;
|
||||
|
||||
let next_job_bindings = clear_epiphany_job_binding_backend(
|
||||
current_state.job_bindings.clone(),
|
||||
binding_index,
|
||||
"No active heartbeat turn is currently bound; launch explicitly to resume specialist work.",
|
||||
);
|
||||
let epiphany_state = apply_epiphany_state_update_to_thread(
|
||||
thread,
|
||||
EpiphanyStateUpdate {
|
||||
expected_revision: request.expected_revision,
|
||||
job_bindings: Some(next_job_bindings),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(EpiphanyJobInterruptResult {
|
||||
epiphany_state,
|
||||
binding_id: request.binding_id,
|
||||
cancel_requested,
|
||||
interrupted_thread_ids,
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn apply_thread_epiphany_update(
|
||||
thread: &CodexThread,
|
||||
expected_revision: Option<u64>,
|
||||
|
|
@ -119,7 +287,7 @@ pub async fn apply_thread_epiphany_update(
|
|||
) -> Result<EpiphanyThreadUpdateApplied, CodexErr> {
|
||||
let changed_fields = epiphany_update_patch_changed_fields(&patch);
|
||||
let update = state_update_from_thread_patch(expected_revision, patch);
|
||||
let epiphany_state = thread.epiphany_update_state(update).await?;
|
||||
let epiphany_state = apply_epiphany_state_update_to_thread(thread, update).await?;
|
||||
let epiphany_state = client_visible_live_thread_epiphany_state(thread, epiphany_state).await;
|
||||
Ok(EpiphanyThreadUpdateApplied {
|
||||
revision: epiphany_state.revision,
|
||||
|
|
@ -158,7 +326,7 @@ pub async fn apply_thread_epiphany_promote(
|
|||
let mut patch = patch;
|
||||
patch.evidence.push(verifier_evidence);
|
||||
let update = state_update_from_thread_patch(expected_revision, patch);
|
||||
let epiphany_state = thread.epiphany_update_state(update).await?;
|
||||
let epiphany_state = apply_epiphany_state_update_to_thread(thread, update).await?;
|
||||
let epiphany_state = client_visible_live_thread_epiphany_state(thread, epiphany_state).await;
|
||||
Ok(EpiphanyThreadPromoteApplied::Accepted(
|
||||
EpiphanyThreadUpdateApplied {
|
||||
|
|
@ -200,12 +368,14 @@ pub async fn apply_thread_epiphany_role_accept(
|
|||
let accepted_evidence_id = acceptance_update.accepted_evidence_id.clone();
|
||||
let changed_fields = acceptance_update.changed_fields.clone();
|
||||
let applied_patch = acceptance_update.patch.clone();
|
||||
let epiphany_state = thread
|
||||
.epiphany_update_state(state_update_from_thread_patch(
|
||||
let epiphany_state = apply_epiphany_state_update_to_thread(
|
||||
thread,
|
||||
state_update_from_thread_patch(
|
||||
expected_revision,
|
||||
acceptance_update.patch,
|
||||
))
|
||||
.await?;
|
||||
),
|
||||
)
|
||||
.await?;
|
||||
let epiphany_state = client_visible_live_thread_epiphany_state(thread, epiphany_state).await;
|
||||
|
||||
Ok(EpiphanyRoleAcceptApplied {
|
||||
|
|
@ -259,9 +429,8 @@ pub async fn apply_thread_epiphany_reorient_accept(
|
|||
let accepted_observation_id = acceptance_update.accepted_observation_id.clone();
|
||||
let accepted_evidence_id = acceptance_update.accepted_evidence_id.clone();
|
||||
let changed_fields = acceptance_update.changed_fields.clone();
|
||||
let epiphany_state = thread
|
||||
.epiphany_update_state(acceptance_update.state_update)
|
||||
.await?;
|
||||
let epiphany_state =
|
||||
apply_epiphany_state_update_to_thread(thread, acceptance_update.state_update).await?;
|
||||
let epiphany_state = client_visible_live_thread_epiphany_state(thread, epiphany_state).await;
|
||||
|
||||
Ok(EpiphanyReorientAcceptApplied {
|
||||
|
|
@ -312,7 +481,7 @@ pub async fn launch_thread_epiphany_job(
|
|||
missing_projection_reason: &str,
|
||||
) -> Result<EpiphanyJobLaunchApplied, CodexErr> {
|
||||
let changed_fields = epiphany_job_launch_changed_fields();
|
||||
let launched = thread.epiphany_launch_job(launch_request).await?;
|
||||
let launched = launch_epiphany_job_on_thread(thread, launch_request).await?;
|
||||
let epiphany_state =
|
||||
client_visible_live_thread_epiphany_state(thread, launched.epiphany_state).await;
|
||||
let job = map_launched_epiphany_job(
|
||||
|
|
@ -338,13 +507,15 @@ pub async fn interrupt_thread_epiphany_job(
|
|||
reason: Option<String>,
|
||||
) -> Result<EpiphanyJobInterruptApplied, CodexErr> {
|
||||
let changed_fields = vec![ThreadEpiphanyStateUpdatedField::JobBindings];
|
||||
let interrupted = thread
|
||||
.epiphany_interrupt_job(EpiphanyJobInterruptRequest {
|
||||
let interrupted = interrupt_epiphany_job_on_thread(
|
||||
thread,
|
||||
EpiphanyJobInterruptRequest {
|
||||
expected_revision,
|
||||
binding_id: binding_id.to_string(),
|
||||
reason,
|
||||
})
|
||||
.await?;
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
let epiphany_state =
|
||||
client_visible_live_thread_epiphany_state(thread, interrupted.epiphany_state).await;
|
||||
let job = map_interrupted_epiphany_job(&epiphany_state, binding_id);
|
||||
|
|
@ -397,7 +568,7 @@ pub async fn launch_thread_epiphany_reorient(
|
|||
&decision,
|
||||
);
|
||||
let changed_fields = epiphany_job_launch_changed_fields();
|
||||
let launched = thread.epiphany_launch_job(launch_request).await?;
|
||||
let launched = launch_epiphany_job_on_thread(thread, launch_request).await?;
|
||||
let epiphany_state =
|
||||
client_visible_live_thread_epiphany_state(thread, launched.epiphany_state).await;
|
||||
let job = map_epiphany_jobs(Some(&epiphany_state), None)
|
||||
|
|
@ -424,6 +595,45 @@ pub async fn launch_thread_epiphany_reorient(
|
|||
})
|
||||
}
|
||||
|
||||
fn open_epiphany_runtime_spine_job(
|
||||
store_path: &Path,
|
||||
state: &EpiphanyThreadState,
|
||||
request: &EpiphanyJobLaunchRequest,
|
||||
backend_job_id: &str,
|
||||
) -> Result<(), CodexErr> {
|
||||
let now = Utc::now().to_rfc3339_opts(SecondsFormat::Secs, true);
|
||||
open_runtime_spine_heartbeat_job(
|
||||
store_path,
|
||||
RuntimeSpineHeartbeatJobOptions {
|
||||
runtime_id: "epiphany-local".to_string(),
|
||||
display_name: "Epiphany Local".to_string(),
|
||||
session_id: "epiphany-main".to_string(),
|
||||
objective: state
|
||||
.objective
|
||||
.clone()
|
||||
.filter(|objective| !objective.trim().is_empty())
|
||||
.unwrap_or_else(|| "Epiphany heartbeat activation".to_string()),
|
||||
coordinator_note: "App-server launch opened this typed runtime session.".to_string(),
|
||||
job_id: backend_job_id.to_string(),
|
||||
role: request.owner_role.clone(),
|
||||
binding_id: request.binding_id.clone(),
|
||||
authority_scope: request.authority_scope.clone(),
|
||||
instruction: request.instruction.clone(),
|
||||
launch_document: request.launch_document.clone(),
|
||||
output_contract_id: request.output_contract_id.clone(),
|
||||
created_at: now,
|
||||
},
|
||||
)
|
||||
.map_err(|err| {
|
||||
CodexErr::Fatal(format!(
|
||||
"failed to open Epiphany runtime spine job {:?} in {}: {err}",
|
||||
backend_job_id,
|
||||
store_path.display()
|
||||
))
|
||||
})?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn validate_expected_revision(
|
||||
expected_revision: Option<u64>,
|
||||
actual_revision: u64,
|
||||
|
|
|
|||
|
|
@ -7,9 +7,13 @@ use codex_app_server_protocol::ThreadEpiphanyRetrieveShardSummary;
|
|||
use codex_core::CodexThread;
|
||||
use codex_protocol::protocol::EpiphanyRetrievalState;
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
use epiphany_core::EpiphanyRetrieveQuery;
|
||||
use epiphany_core::EpiphanyRetrieveResponse as CoreEpiphanyRetrieveResponse;
|
||||
use epiphany_core::EpiphanyRetrieveResult as CoreEpiphanyRetrieveResult;
|
||||
use epiphany_core::EpiphanyRetrieveResultKind as CoreEpiphanyRetrieveResultKind;
|
||||
use epiphany_core::index_workspace;
|
||||
use epiphany_core::retrieval_state_for_workspace;
|
||||
use epiphany_core::retrieve_workspace;
|
||||
|
||||
pub fn map_epiphany_retrieve_response(
|
||||
response: CoreEpiphanyRetrieveResponse,
|
||||
|
|
@ -29,13 +33,55 @@ pub async fn index_thread_epiphany_retrieval(
|
|||
thread: &CodexThread,
|
||||
force_full_rebuild: bool,
|
||||
) -> anyhow::Result<ThreadEpiphanyIndexResponse> {
|
||||
let index_summary = thread
|
||||
.epiphany_index(force_full_rebuild)
|
||||
let index_summary = index_thread_epiphany_retrieval_state(thread, force_full_rebuild)
|
||||
.await
|
||||
.and_then(map_epiphany_retrieve_index_summary)?;
|
||||
Ok(ThreadEpiphanyIndexResponse { index_summary })
|
||||
}
|
||||
|
||||
pub async fn thread_epiphany_retrieval_state(thread: &CodexThread) -> EpiphanyRetrievalState {
|
||||
let config = thread.config_snapshot().await;
|
||||
let workspace_root = config.cwd.to_path_buf();
|
||||
let codex_home = thread.codex_home().await;
|
||||
let fallback_workspace_root = workspace_root.clone();
|
||||
let fallback_codex_home = codex_home.clone();
|
||||
tokio::task::spawn_blocking(move || {
|
||||
retrieval_state_for_workspace(&workspace_root, codex_home.as_path())
|
||||
})
|
||||
.await
|
||||
.unwrap_or_else(|_| {
|
||||
retrieval_state_for_workspace(&fallback_workspace_root, fallback_codex_home.as_path())
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn index_thread_epiphany_retrieval_state(
|
||||
thread: &CodexThread,
|
||||
force_full_rebuild: bool,
|
||||
) -> anyhow::Result<EpiphanyRetrievalState> {
|
||||
let config = thread.config_snapshot().await;
|
||||
let workspace_root = config.cwd.to_path_buf();
|
||||
let codex_home = thread.codex_home().await;
|
||||
tokio::task::spawn_blocking(move || {
|
||||
index_workspace(&workspace_root, codex_home.as_path(), force_full_rebuild)
|
||||
})
|
||||
.await
|
||||
.map_err(|err| anyhow::anyhow!("epiphany index worker failed: {err}"))?
|
||||
}
|
||||
|
||||
pub async fn retrieve_thread_epiphany(
|
||||
thread: &CodexThread,
|
||||
query: EpiphanyRetrieveQuery,
|
||||
) -> anyhow::Result<CoreEpiphanyRetrieveResponse> {
|
||||
let config = thread.config_snapshot().await;
|
||||
let workspace_root = config.cwd.to_path_buf();
|
||||
let codex_home = thread.codex_home().await;
|
||||
tokio::task::spawn_blocking(move || {
|
||||
retrieve_workspace(&workspace_root, codex_home.as_path(), query)
|
||||
})
|
||||
.await
|
||||
.map_err(|err| anyhow::anyhow!("epiphany retrieval worker failed: {err}"))?
|
||||
}
|
||||
|
||||
pub fn map_epiphany_retrieve_index_summary(
|
||||
summary: EpiphanyRetrievalState,
|
||||
) -> anyhow::Result<ThreadEpiphanyRetrieveIndexSummary> {
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@ use codex_protocol::protocol::InitialHistory;
|
|||
use epiphany_core::write_thread_state;
|
||||
use tracing::warn;
|
||||
|
||||
use crate::retrieve::thread_epiphany_retrieval_state;
|
||||
|
||||
pub async fn load_epiphany_state_from_rollout_path(
|
||||
rollout_path: &Path,
|
||||
) -> std::result::Result<Option<EpiphanyThreadState>, String> {
|
||||
|
|
@ -33,7 +35,7 @@ pub async fn live_thread_epiphany_state(thread: &CodexThread) -> Option<Epiphany
|
|||
if let Some(state) = epiphany_state.as_mut()
|
||||
&& state.retrieval.is_none()
|
||||
{
|
||||
state.retrieval = Some(thread.epiphany_retrieval_state().await);
|
||||
state.retrieval = Some(thread_epiphany_retrieval_state(thread).await);
|
||||
}
|
||||
if let Some(state) = epiphany_state.as_ref() {
|
||||
let config = thread.config_snapshot().await;
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ The spine exists in more than twenty-five live paths:
|
|||
- explicit distillation proposals: app-server routes read-only `thread/epiphany/distill` through a loaded-thread handler into `epiphany-core` so one explicit observation can become a patch candidate without mutating state; tool/command/shell/model sources now get typed evidence kinds and bounded salient-output summaries instead of dumping raw output into durable state in [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4358) and [distillation.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/distillation.rs:28).
|
||||
- explicit map/churn proposals: app-server routes read-only `thread/epiphany/propose` through a loaded-thread handler into `epiphany-core` so verified observations with code refs and accepting recent evidence can be selected explicitly or auto-selected as a bounded path cluster, prioritize the strongest selected observation, focus or extend architecture graph nodes, rescue unanchored graph nodes through strict semantic overlap, carry linked dataflow nodes and incident graph edges into the frontier, update churn candidates with match-kind-aware map-delta judgment and pressure, and still avoid mutation until promotion in [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4429) and [proposal.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/proposal.rs:115).
|
||||
- explicit promotion gates: app-server routes `thread/epiphany/promote` through a loaded-thread handler into `epiphany-core` policy evaluation, rejects failed verifier evidence without mutation, applies accepted candidates through the same durable update path, and now treats medium/high/expanded/broadening/semantic churn deltas as needing explicit rationale plus stronger verifier evidence whose kind is token-matched rather than substring-matched; the same gate also validates durable investigation-checkpoint packets, including linked evidence ids, before they can be inked into state in [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4501) and [promotion.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/promotion.rs:33).
|
||||
- explicit state updates: app-server routes `thread/epiphany/update` through a loaded `CodexThread` update method that rejects malformed appended observation/evidence graph records and structurally invalid replacement fields, including investigation checkpoints that cite missing evidence and planning records with broken ids/source refs/backlog links/draft acceptance criteria, mutates live `SessionState` only after validation, bumps the revision, and persists an immediate `RolloutItem::EpiphanyState` snapshot in [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4620), [codex_thread.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/core/src/codex_thread.rs:376), [codex_thread.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/core/src/codex_thread.rs:552), [codex_thread.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/core/src/codex_thread.rs:1294), and [promotion.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/promotion.rs:44).
|
||||
- explicit state updates: app-server routes `thread/epiphany/update` through `epiphany-codex-bridge` mutation policy, which rejects malformed appended observation/evidence graph records and structurally invalid replacement fields, including investigation checkpoints that cite missing evidence and planning records with broken ids/source refs/backlog links/draft acceptance criteria, then asks `CodexThread` only to persist the already-mutated typed state snapshot as a `RolloutItem::EpiphanyState` in [mutation_service.rs](E:/Projects/EpiphanyAgent/epiphany-codex-bridge/src/mutation_service.rs:126), [codex_thread.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/core/src/codex_thread.rs:348), and [promotion.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/promotion.rs:44).
|
||||
- live state notifications and write responses: app-server declares experimental `thread/epiphany/stateUpdated` and emits it with the updated typed state, typed `source`, event-level `revision`, and typed `changedFields` after successful direct updates and accepted promotions, but not after rejected promotions; direct `thread/epiphany/update` and accepted `thread/epiphany/promote` responses expose the same revision/change metadata, accepted promotions always report `Evidence` because verifier evidence is appended even when the patch evidence list is empty, and successful write response/notification states now use the same client-visible live projection as `thread/read`, including retrieval-summary backfill when durable state has no persisted retrieval metadata, in [common.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/common.rs:1113), [v2.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs:4354), [v2.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs:4419), [v2.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs:4428), [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4555), [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4608), [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4652), [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4693), [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:11327), and [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:11370).
|
||||
- scene projection: the `scene` view lens reads the same live/stored Epiphany state view used by `thread/read` and adapts the core scene projection. `epiphany-core` derives the compact client scene with objective, active subgoal, invariant status counts, graph focus/counts, retrieval status, investigation-checkpoint summary counts, observation/evidence summaries, churn, live/stored source, and available control-plane actions without mutating or persisting state in [scene.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/surfaces/scene.rs:1).
|
||||
- job/progress reflection: the `jobs` view lens reads the same thread view as scene, optionally fills retrieval state for loaded threads with no Epiphany state, and adapts core-derived non-authoritative progress slots for retrieval indexing, graph remap, invariant verification, and bound specialist work. Durable `job_bindings` now act as thin Epiphany-owned authority slots with binding id, kind, scope, owner role, authority scope, linked ids, and optional blocking reason only. Runtime job ids project from `runtime_links` through core job view policy; old `agent_jobs` bindings are sealed instead of live-crawled in [jobs.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/surfaces/jobs.rs:1).
|
||||
|
|
@ -45,7 +45,7 @@ The spine exists in more than twenty-five live paths:
|
|||
- reorientation launch: app-server now declares experimental `thread/epiphany/reorientLaunch`, requires a loaded thread plus durable investigation checkpoint, consumes the live reorientation verdict, and launches one fixed `reorient-worker` binding through the existing job-control seam with explicit resume-versus-regather scope, checkpoint-derived payload, and structured-output expectations instead of pretending CRRC suddenly grew a scheduler in [common.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/common.rs:370), [v2.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs:4575), and [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4519).
|
||||
- reorientation result read-back: app-server now declares experimental read-only `thread/epiphany/reorientResult`, defaults to the fixed `reorient-worker` binding, resolves heartbeat bindings through typed runtime-spine job results, seals legacy `agent_jobs` bindings, and projects a reviewable finding with mode, summary, next safe move, checkpoint-validity flag, inspected files, frontier ids, evidence ids, raw result, and any errors without mutating state, promoting evidence, or scheduling follow-up work.
|
||||
- reorientation finding acceptance: app-server now declares experimental `thread/epiphany/reorientAccept`, requires a loaded thread and a completed `reorient-worker` result, accepts heartbeat-backed results from typed runtime-spine receipts before falling back to old bindings, uses core acceptance bundle policy to build accepted observation/evidence/receipt payloads plus optional scratch and durable investigation-checkpoint updates, persists through the normal typed update path, and emits `thread/epiphany/stateUpdated` with source `reorientAccept` without accepting pending work, auto-promoting arbitrary worker output, launching follow-up work, or silently continuing implementation in [common.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/common.rs:378), [v2.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs:4635), [role_result.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/surfaces/role_result.rs:150), and [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4885).
|
||||
- retrieval/indexing: app-server routes `thread/epiphany/retrieve` and `thread/epiphany/index` through loaded `CodexThread` host methods into `epiphany-core` in [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4356), [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4432), [codex_thread.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/core/src/codex_thread.rs:467), and [codex_thread.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/core/src/codex_thread.rs:449).
|
||||
- retrieval/indexing: app-server routes `thread/epiphany/retrieve` and `thread/epiphany/index` through `epiphany-codex-bridge::retrieve`, which reads only host cwd/Codex-home facts from `CodexThread` and calls native `epiphany-core` retrieval/indexing in [retrieve.rs](E:/Projects/EpiphanyAgent/epiphany-codex-bridge/src/retrieve.rs:42), [retrieve.rs](E:/Projects/EpiphanyAgent/epiphany-codex-bridge/src/retrieve.rs:57), and [retrieve.rs](E:/Projects/EpiphanyAgent/epiphany-codex-bridge/src/retrieve.rs:69).
|
||||
|
||||
The thick Epiphany-owned implementation is mostly outside vendored Codex now:
|
||||
|
||||
|
|
@ -64,7 +64,7 @@ flowchart TD
|
|||
A["Loaded Codex Session"] --> B["SessionState.epiphany_state"]
|
||||
B --> C["build_initial_context"]
|
||||
C --> D["EpiphanyStateInstructions wrapper"]
|
||||
D --> E["epiphany-core render_epiphany_state"]
|
||||
D --> E["epiphany-state-model render_epiphany_state"]
|
||||
E --> EA["Operating Discipline anti-Jenga section"]
|
||||
EA --> F["<epiphany_state> developer fragment"]
|
||||
F --> G["Model/tool turn runs in normal Codex loop"]
|
||||
|
|
@ -130,15 +130,15 @@ flowchart TD
|
|||
AE --> AF{"Accepted?"}
|
||||
AF -->|"No"| AG["Return reasons, no state mutation"]
|
||||
AF -->|"Yes"| Z
|
||||
R --> T["CodexThread.epiphany_retrieve"]
|
||||
S --> U["CodexThread.epiphany_index"]
|
||||
Z --> ZA["CodexThread.epiphany_update_state"]
|
||||
AJL --> AJLA["CodexThread.epiphany_launch_job"]
|
||||
R --> T["epiphany-codex-bridge retrieve_thread_epiphany"]
|
||||
S --> U["epiphany-codex-bridge index_thread_epiphany_retrieval_state"]
|
||||
Z --> ZA["epiphany-codex-bridge apply_epiphany_state_update_to_thread"]
|
||||
AJL --> AJLA["epiphany-codex-bridge launch_epiphany_job_on_thread"]
|
||||
QRLQ --> QRLA["Map checkpoint + reorient verdict into fixed reorient-worker launch"]
|
||||
QRLA --> AJLA
|
||||
AJLA --> AJLB["Persist authority-slot jobBinding + runtimeLink"]
|
||||
AJLB --> ZD
|
||||
AJI --> AJIA["CodexThread.epiphany_interrupt_job"]
|
||||
AJI --> AJIA["epiphany-codex-bridge interrupt_epiphany_job_on_thread"]
|
||||
AJIA --> AJIB["Interrupt backend worker(s) + clear bound backend from jobBinding"]
|
||||
AJIB --> ZD
|
||||
ZA --> ZB["Apply typed patch and increment revision"]
|
||||
|
|
@ -415,7 +415,7 @@ For `thread/read`, `read_thread_view` loads the persisted thread view and option
|
|||
- if the thread is loaded, use `live_thread_epiphany_state`.
|
||||
- otherwise, read rollout items from disk and reconstruct the latest surviving Epiphany state with `latest_epiphany_state_from_rollout_items`.
|
||||
|
||||
`live_thread_epiphany_state` reads `CodexThread.epiphany_state()`. If state exists but has no retrieval summary, it calls `thread.epiphany_retrieval_state().await` and backfills the summary into the returned API object. That backfill is for the view; it is not a durable rollout write.
|
||||
`live_thread_epiphany_state` reads `CodexThread.epiphany_state()`. If state exists but has no retrieval summary, it calls `epiphany-codex-bridge::thread_epiphany_retrieval_state` and backfills the summary into the returned API object. That backfill is for the view; it is not a durable rollout write.
|
||||
|
||||
Code refs:
|
||||
|
||||
|
|
@ -468,10 +468,10 @@ The app-server handler:
|
|||
3. rejects zero limits.
|
||||
4. requires the thread to be loaded.
|
||||
5. clamps limit to Epiphany bounds.
|
||||
6. calls `CodexThread.epiphany_retrieve`.
|
||||
6. calls `epiphany-codex-bridge::retrieve_thread_epiphany`.
|
||||
7. maps core results into app-server protocol DTOs.
|
||||
|
||||
`CodexThread.epiphany_retrieve` snapshots the thread config, extracts `cwd` as workspace root, gets `codex_home`, and runs `epiphany_retrieval::retrieve_workspace` in `spawn_blocking`.
|
||||
`retrieve_thread_epiphany` snapshots the host config, extracts `cwd` as workspace root, gets Codex home from the host seam, and runs `epiphany_core::retrieve_workspace` in `spawn_blocking`.
|
||||
|
||||
`epiphany-core::retrieve_workspace`:
|
||||
|
||||
|
|
@ -541,10 +541,10 @@ The app-server handler:
|
|||
|
||||
1. parses the thread id.
|
||||
2. requires the thread to be loaded.
|
||||
3. calls `CodexThread.epiphany_index(force_full_rebuild)`.
|
||||
3. calls `epiphany-codex-bridge::index_thread_epiphany_retrieval`.
|
||||
4. maps the returned core retrieval state into an app-server index summary response.
|
||||
|
||||
`CodexThread.epiphany_index` snapshots `cwd`, reads `codex_home`, and runs `epiphany_retrieval::index_workspace` in `spawn_blocking`.
|
||||
`index_thread_epiphany_retrieval_state` snapshots `cwd`, reads Codex home from the host seam, and runs `epiphany_core::index_workspace` in `spawn_blocking`.
|
||||
|
||||
`epiphany-core::index_workspace`:
|
||||
|
||||
|
|
@ -595,7 +595,7 @@ It must stay light. It should measure the catalog, not rewrite the catalog. If t
|
|||
|
||||
### Mechanism
|
||||
|
||||
`live_thread_epiphany_state` calls `thread.epiphany_retrieval_state().await`. That method runs `retrieval_state_for_workspace`, which:
|
||||
`live_thread_epiphany_state` calls `epiphany-codex-bridge::thread_epiphany_retrieval_state`. That bridge helper runs `retrieval_state_for_workspace`, which:
|
||||
|
||||
1. checks the workspace exists.
|
||||
2. loads backend config.
|
||||
|
|
@ -653,14 +653,14 @@ The app-server handler:
|
|||
1. parses the thread id.
|
||||
2. requires the thread to be loaded.
|
||||
3. maps the app-server patch DTO into `EpiphanyStateUpdate`.
|
||||
4. calls `CodexThread.epiphany_update_state`.
|
||||
4. calls `epiphany-codex-bridge::apply_epiphany_state_update_to_thread`.
|
||||
5. computes `changedFields` from the accepted patch surface.
|
||||
6. projects the just-written state through `client_visible_live_thread_epiphany_state`, which reuses the `thread/read` live-state helper and backfills retrieval summary metadata when needed.
|
||||
7. returns the client-visible `EpiphanyThreadState` plus response-level `revision` and `changedFields`.
|
||||
8. emits `thread/epiphany/stateUpdated` with `source: "update"`, event-level `revision`, typed `changedFields`, and the same client-visible updated state.
|
||||
9. reports empty patches and revision mismatches as invalid requests before notification.
|
||||
|
||||
`CodexThread.epiphany_update_state`:
|
||||
`apply_epiphany_state_update_to_thread`:
|
||||
|
||||
1. rejects an empty patch.
|
||||
2. reads the current reference turn id when one exists.
|
||||
|
|
@ -920,7 +920,7 @@ The app-server handler:
|
|||
4. returns `accepted: false`, reasons, and `epiphanyState: null` when policy rejects.
|
||||
5. appends verifier evidence to the patch evidence when policy accepts.
|
||||
6. maps the patch into `EpiphanyStateUpdate`.
|
||||
7. calls `CodexThread.epiphany_update_state`.
|
||||
7. calls `epiphany-codex-bridge::apply_epiphany_state_update_to_thread`.
|
||||
8. projects the just-written state through `client_visible_live_thread_epiphany_state`, matching the `thread/read` live-state view and retrieval-summary backfill.
|
||||
9. returns the client-visible `EpiphanyThreadState` plus response-level `revision` and `changedFields`.
|
||||
10. emits `thread/epiphany/stateUpdated` with `source: "promote"`, event-level `revision`, and typed `changedFields` only for the accepted path; `Evidence` is included even if the accepted patch had no patch evidence because verifier evidence was appended to the durable state.
|
||||
|
|
@ -958,7 +958,7 @@ Rejected promotions return reasons and no state. Accepted promotions return the
|
|||
|
||||
### Invariant
|
||||
|
||||
Promotion is a gate, not independent persistence. It does not write rollout items directly, it does not mutate state on rejection, and rejected promotions emit no state update notification. Accepted promotions still go through `CodexThread.epiphany_update_state`, so the red pen remains one tool, not three tools in a coat.
|
||||
Promotion is a gate, not independent persistence. It does not write rollout items directly, it does not mutate state on rejection, and rejected promotions emit no state update notification. Accepted promotions still go through `epiphany-codex-bridge::apply_epiphany_state_update_to_thread`, so the red pen remains one tool, not three tools in a coat.
|
||||
|
||||
## Flow 13: Scene View Lens Control Flow
|
||||
|
||||
|
|
@ -1509,7 +1509,7 @@ Current tests cover the landed flows at useful seams:
|
|||
- deterministic map/churn proposal in `epiphany-core`.
|
||||
- verifier-backed promotion policy in `epiphany-core`.
|
||||
- map/churn promotion validation for evidence-backed state replacements in `epiphany-core`.
|
||||
- typed state-update patch application in `codex-core`.
|
||||
- typed state-update patch application in `epiphany-codex-bridge` plus host persistence in `codex-core`.
|
||||
- retrieval ranking, fallback, stale manifest detection, and mocked Qdrant/Ollama indexing in `epiphany-core`.
|
||||
- app-server protocol serde for `thread/epiphany/retrieve`, `thread/epiphany/index`, `thread/epiphany/distill`, `thread/epiphany/propose`, `thread/epiphany/promote`, `thread/epiphany/update`, `thread/epiphany/stateUpdated`, and `thread/epiphany/jobsUpdated`.
|
||||
- focused app-server coverage for sealed `thread/epiphany/jobsUpdated` behavior and heartbeat-backed job projection.
|
||||
|
|
|
|||
|
|
@ -656,21 +656,19 @@ there is one runtime job for the worker, owned by runtime-spine, and the worker
|
|||
runner completes that job.
|
||||
|
||||
The Codex-core re-export husks for `epiphany_distillation`, `epiphany_promotion`,
|
||||
`epiphany_proposal`, and `epiphany_retrieval` have also been deleted.
|
||||
`codex-core` now re-exports those native types/functions directly from
|
||||
`epiphany-core`, and `CodexThread` calls `epiphany_core::retrieve_workspace` /
|
||||
`index_workspace` / `retrieval_state_for_workspace` directly.
|
||||
The `epiphany_rollout` husk is gone too; `codex-core::lib` keeps only the
|
||||
one host-boundary function that passes Codex's turn-boundary predicate into
|
||||
`epiphany-core`.
|
||||
`epiphany_proposal`, and `epiphany_retrieval` have also been deleted. The
|
||||
`epiphany_rollout` husk is gone too; `codex-core::lib` keeps only the one
|
||||
host-boundary function that passes Codex's turn-boundary predicate into
|
||||
`epiphany-core`. `codex-core` no longer depends on `epiphany-core` at all:
|
||||
`CodexThread` exposes host persistence/path facts, while `epiphany-codex-bridge`
|
||||
calls native retrieval/indexing and state-update policy.
|
||||
|
||||
The runtime-spine job-opening mechanism for heartbeat/specialist launches has
|
||||
also been pulled into `epiphany-core` as `open_runtime_spine_heartbeat_job`.
|
||||
Vendored `codex_core::CodexThread::epiphany_launch_job` still validates,
|
||||
persists, and updates Codex thread state, but it no longer owns the
|
||||
initialize-session-open-job sequence. That is a small cut, but a real ownership
|
||||
move: native runtime lifecycle belongs to the runtime spine, not the Codex
|
||||
thread wrapper.
|
||||
Launch/interrupt policy now lives in `epiphany-codex-bridge`; vendored
|
||||
`CodexThread` only persists the typed state snapshot and exposes the runtime
|
||||
store path. Native runtime lifecycle belongs to the runtime spine, not the
|
||||
Codex thread wrapper.
|
||||
|
||||
That job-opening path now preserves the work order instead of shaving it into a
|
||||
generic job id. `epiphany-core::EpiphanyRuntimeWorkerLaunchRequest` is a
|
||||
|
|
|
|||
Binary file not shown.
File diff suppressed because one or more lines are too long
1
vendor/codex/codex-rs/Cargo.lock
generated
vendored
1
vendor/codex/codex-rs/Cargo.lock
generated
vendored
|
|
@ -2393,7 +2393,6 @@ dependencies = [
|
|||
"dirs",
|
||||
"dunce",
|
||||
"env-flags",
|
||||
"epiphany-core",
|
||||
"eventsource-stream",
|
||||
"futures",
|
||||
"http 1.4.0",
|
||||
|
|
|
|||
|
|
@ -15,9 +15,11 @@ use epiphany_codex_bridge::coordinator::select_epiphany_coordinator_automation;
|
|||
use epiphany_codex_bridge::invalidation::EpiphanyInvalidationManager;
|
||||
use epiphany_codex_bridge::invalidation::epiphany_freshness_watcher_snapshot;
|
||||
use epiphany_codex_bridge::mutation::epiphany_job_launch_changed_fields;
|
||||
use epiphany_codex_bridge::mutation_service::launch_epiphany_job_on_thread;
|
||||
use epiphany_codex_bridge::pressure::map_epiphany_pressure;
|
||||
use epiphany_codex_bridge::pressure::render_epiphany_pre_compaction_checkpoint_intervention;
|
||||
use epiphany_codex_bridge::pressure::should_run_epiphany_pre_compaction_checkpoint_intervention;
|
||||
use epiphany_codex_bridge::retrieve::thread_epiphany_retrieval_state;
|
||||
use epiphany_codex_bridge::state::client_visible_live_thread_epiphany_state;
|
||||
use tokio::sync::Mutex;
|
||||
use tracing::warn;
|
||||
|
|
@ -37,7 +39,7 @@ pub(crate) async fn maybe_run_epiphany_coordinator_automation_for_turn_boundary(
|
|||
return;
|
||||
};
|
||||
|
||||
let retrieval_override = thread.epiphany_retrieval_state().await;
|
||||
let retrieval_override = thread_epiphany_retrieval_state(thread.as_ref()).await;
|
||||
let config_snapshot = thread.config_snapshot().await;
|
||||
epiphany_invalidation_manager
|
||||
.ensure_thread_watch(&thread_id_text, &config_snapshot.cwd)
|
||||
|
|
@ -72,7 +74,9 @@ pub(crate) async fn maybe_run_epiphany_coordinator_automation_for_turn_boundary(
|
|||
let Some(launch_request) = verdict.launch_request else {
|
||||
return;
|
||||
};
|
||||
let launched = match thread.epiphany_launch_job(launch_request).await {
|
||||
let launched = match launch_epiphany_job_on_thread(thread.as_ref(), launch_request)
|
||||
.await
|
||||
{
|
||||
Ok(launched) => launched,
|
||||
Err(err) => {
|
||||
warn!(
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ 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::index_thread_epiphany_retrieval;
|
||||
use epiphany_codex_bridge::retrieve::thread_epiphany_retrieval_state;
|
||||
use epiphany_core::EpiphanyJobLaunchRequest;
|
||||
use std::sync::Arc;
|
||||
|
||||
|
|
@ -248,7 +249,7 @@ impl CodexMessageProcessor {
|
|||
}
|
||||
};
|
||||
|
||||
let retrieval_override = loaded_thread.epiphany_retrieval_state().await;
|
||||
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)
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ 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::retrieve::map_epiphany_retrieve_response;
|
||||
use epiphany_codex_bridge::retrieve::retrieve_thread_epiphany;
|
||||
use epiphany_codex_bridge::retrieve::thread_epiphany_retrieval_state;
|
||||
use epiphany_codex_bridge::view::EpiphanyFreshnessResponseInput;
|
||||
use epiphany_codex_bridge::view::EpiphanyReorientResultResponseInput;
|
||||
use epiphany_codex_bridge::view::EpiphanyRoleResultResponseInput;
|
||||
|
|
@ -75,7 +77,7 @@ impl CodexMessageProcessor {
|
|||
.is_none()
|
||||
{
|
||||
if let Some(loaded_thread) = loaded_thread.as_ref() {
|
||||
Some(loaded_thread.epiphany_retrieval_state().await)
|
||||
Some(thread_epiphany_retrieval_state(loaded_thread.as_ref()).await)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
|
@ -238,7 +240,7 @@ impl CodexMessageProcessor {
|
|||
};
|
||||
|
||||
let retrieval_override = if let Some(loaded_thread) = loaded_thread.as_ref() {
|
||||
Some(loaded_thread.epiphany_retrieval_state().await)
|
||||
Some(thread_epiphany_retrieval_state(loaded_thread.as_ref()).await)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
|
@ -438,8 +440,7 @@ impl CodexMessageProcessor {
|
|||
}
|
||||
};
|
||||
|
||||
let response = match thread
|
||||
.epiphany_retrieve(query)
|
||||
let response = match retrieve_thread_epiphany(thread.as_ref(), query)
|
||||
.await
|
||||
.and_then(map_epiphany_retrieve_response)
|
||||
{
|
||||
|
|
|
|||
1
vendor/codex/codex-rs/core/Cargo.toml
vendored
1
vendor/codex/codex-rs/core/Cargo.toml
vendored
|
|
@ -70,7 +70,6 @@ codex-utils-string = { workspace = true }
|
|||
codex-utils-stream-parser = { workspace = true }
|
||||
codex-utils-template = { workspace = true }
|
||||
codex-windows-sandbox = { package = "codex-windows-sandbox", path = "../windows-sandbox-rs" }
|
||||
epiphany-core = { path = "../../../../epiphany-core" }
|
||||
csv = { workspace = true }
|
||||
dirs = { workspace = true }
|
||||
dunce = { workspace = true }
|
||||
|
|
|
|||
293
vendor/codex/codex-rs/core/src/codex_thread.rs
vendored
293
vendor/codex/codex-rs/core/src/codex_thread.rs
vendored
|
|
@ -20,7 +20,6 @@ use codex_protocol::models::ResponseInputItem;
|
|||
use codex_protocol::models::ResponseItem;
|
||||
use codex_protocol::openai_models::ReasoningEffort;
|
||||
use codex_protocol::protocol::AskForApproval;
|
||||
use codex_protocol::protocol::EpiphanyRetrievalState;
|
||||
use codex_protocol::protocol::EpiphanyStateItem;
|
||||
use codex_protocol::protocol::EpiphanyThreadState;
|
||||
use codex_protocol::protocol::Event;
|
||||
|
|
@ -35,21 +34,6 @@ use codex_protocol::protocol::TokenUsageInfo;
|
|||
use codex_protocol::protocol::W3cTraceContext;
|
||||
use codex_protocol::user_input::UserInput;
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
use epiphany_core::EpiphanyJobInterruptRequest;
|
||||
use epiphany_core::EpiphanyJobInterruptResult;
|
||||
use epiphany_core::EpiphanyJobLaunchRequest;
|
||||
use epiphany_core::EpiphanyJobLaunchResult;
|
||||
use epiphany_core::EpiphanyRetrieveQuery;
|
||||
use epiphany_core::EpiphanyRetrieveResponse;
|
||||
use epiphany_core::EpiphanyStateUpdate;
|
||||
use epiphany_core::RuntimeSpineHeartbeatJobOptions;
|
||||
use epiphany_core::RuntimeSpineHeartbeatLaunchPlanOptions;
|
||||
use epiphany_core::apply_epiphany_state_update;
|
||||
use epiphany_core::clear_epiphany_job_binding_backend;
|
||||
use epiphany_core::epiphany_state_update_validation_errors;
|
||||
use epiphany_core::open_runtime_spine_heartbeat_job;
|
||||
use epiphany_core::plan_runtime_spine_heartbeat_launch;
|
||||
use epiphany_core::replace_or_append_epiphany_job_binding;
|
||||
use rmcp::model::ReadResourceRequestParams;
|
||||
use std::collections::HashMap;
|
||||
use std::path::PathBuf;
|
||||
|
|
@ -57,7 +41,6 @@ use tokio::sync::Mutex;
|
|||
use tokio::sync::watch;
|
||||
|
||||
use codex_rollout::state_db::StateDbHandle;
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct ThreadConfigSnapshot {
|
||||
|
|
@ -339,46 +322,19 @@ impl CodexThread {
|
|||
self.codex.session.epiphany_state().await
|
||||
}
|
||||
|
||||
pub async fn epiphany_update_state(
|
||||
&self,
|
||||
update: EpiphanyStateUpdate,
|
||||
) -> CodexResult<EpiphanyThreadState> {
|
||||
if update.is_empty() {
|
||||
return Err(CodexErr::InvalidRequest(
|
||||
"epiphany update patch must contain at least one mutation".to_string(),
|
||||
));
|
||||
}
|
||||
|
||||
let reference_turn_id = self
|
||||
.codex
|
||||
pub async fn epiphany_reference_turn_id(&self) -> Option<String> {
|
||||
self.codex
|
||||
.session
|
||||
.reference_context_item()
|
||||
.await
|
||||
.and_then(|item| item.turn_id);
|
||||
let mut next_state = self
|
||||
.codex
|
||||
.session
|
||||
.epiphany_state()
|
||||
.await
|
||||
.unwrap_or_default();
|
||||
if let Some(expected_revision) = update.expected_revision
|
||||
&& next_state.revision != expected_revision
|
||||
{
|
||||
return Err(CodexErr::InvalidRequest(format!(
|
||||
"epiphany state revision mismatch: expected {expected_revision}, found {}",
|
||||
next_state.revision
|
||||
)));
|
||||
}
|
||||
.and_then(|item| item.turn_id)
|
||||
}
|
||||
|
||||
let validation_errors = epiphany_state_update_validation_errors(&next_state, &update);
|
||||
if !validation_errors.is_empty() {
|
||||
return Err(CodexErr::InvalidRequest(format!(
|
||||
"invalid epiphany update patch: {}",
|
||||
validation_errors.join("; ")
|
||||
)));
|
||||
}
|
||||
|
||||
apply_epiphany_state_update(&mut next_state, update, reference_turn_id.clone());
|
||||
pub async fn epiphany_persist_state(
|
||||
&self,
|
||||
next_state: EpiphanyThreadState,
|
||||
) -> CodexResult<EpiphanyThreadState> {
|
||||
let reference_turn_id = self.epiphany_reference_turn_id().await;
|
||||
self.codex
|
||||
.session
|
||||
.set_epiphany_state(Some(next_state.clone()))
|
||||
|
|
@ -394,166 +350,6 @@ impl CodexThread {
|
|||
Ok(next_state)
|
||||
}
|
||||
|
||||
pub async fn epiphany_launch_job(
|
||||
&self,
|
||||
request: EpiphanyJobLaunchRequest,
|
||||
) -> CodexResult<EpiphanyJobLaunchResult> {
|
||||
let current_state = self
|
||||
.codex
|
||||
.session
|
||||
.epiphany_state()
|
||||
.await
|
||||
.unwrap_or_default();
|
||||
if let Some(expected_revision) = request.expected_revision
|
||||
&& current_state.revision != expected_revision
|
||||
{
|
||||
return Err(CodexErr::InvalidRequest(format!(
|
||||
"epiphany state revision mismatch: expected {expected_revision}, found {}",
|
||||
current_state.revision
|
||||
)));
|
||||
}
|
||||
|
||||
let launcher_job_id = format!("epiphany-heartbeat-launch-{}", Uuid::new_v4());
|
||||
let backend_job_id = Uuid::new_v4().to_string();
|
||||
let launch_plan = plan_runtime_spine_heartbeat_launch(
|
||||
¤t_state,
|
||||
RuntimeSpineHeartbeatLaunchPlanOptions {
|
||||
binding_id: request.binding_id.clone(),
|
||||
kind: request.kind,
|
||||
scope: request.scope.clone(),
|
||||
owner_role: request.owner_role.clone(),
|
||||
authority_scope: request.authority_scope.clone(),
|
||||
linked_subgoal_ids: request.linked_subgoal_ids.clone(),
|
||||
linked_graph_node_ids: request.linked_graph_node_ids.clone(),
|
||||
instruction: request.instruction.clone(),
|
||||
launch_document: request.launch_document.clone(),
|
||||
output_contract_id: request.output_contract_id.clone(),
|
||||
max_runtime_seconds: request.max_runtime_seconds,
|
||||
runtime_job_id: backend_job_id.clone(),
|
||||
},
|
||||
)
|
||||
.map_err(|err| CodexErr::InvalidRequest(err.to_string()))?;
|
||||
let runtime_store = self.epiphany_runtime_spine_store_path().await;
|
||||
open_epiphany_runtime_spine_job(
|
||||
runtime_store.as_path(),
|
||||
¤t_state,
|
||||
&request,
|
||||
backend_job_id.as_str(),
|
||||
)?;
|
||||
let next_job_bindings = replace_or_append_epiphany_job_binding(
|
||||
current_state.job_bindings.clone(),
|
||||
launch_plan.binding,
|
||||
);
|
||||
|
||||
let validation_errors = epiphany_state_update_validation_errors(
|
||||
¤t_state,
|
||||
&EpiphanyStateUpdate {
|
||||
job_bindings: Some(next_job_bindings.clone()),
|
||||
runtime_links: vec![launch_plan.runtime_link.clone()],
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
if !validation_errors.is_empty() {
|
||||
return Err(CodexErr::InvalidRequest(format!(
|
||||
"invalid Epiphany job launch patch: {}",
|
||||
validation_errors.join("; ")
|
||||
)));
|
||||
}
|
||||
|
||||
let epiphany_state = self
|
||||
.epiphany_update_state(EpiphanyStateUpdate {
|
||||
expected_revision: request.expected_revision,
|
||||
job_bindings: Some(next_job_bindings),
|
||||
runtime_links: vec![launch_plan.runtime_link],
|
||||
..Default::default()
|
||||
})
|
||||
.await?;
|
||||
|
||||
Ok(EpiphanyJobLaunchResult {
|
||||
epiphany_state,
|
||||
binding_id: request.binding_id,
|
||||
launcher_job_id,
|
||||
backend_job_id,
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn epiphany_interrupt_job(
|
||||
&self,
|
||||
request: EpiphanyJobInterruptRequest,
|
||||
) -> CodexResult<EpiphanyJobInterruptResult> {
|
||||
if request.binding_id.trim().is_empty() {
|
||||
return Err(CodexErr::InvalidRequest(
|
||||
"epiphany job interrupt binding_id must be non-empty".to_string(),
|
||||
));
|
||||
}
|
||||
|
||||
let current_state = self
|
||||
.codex
|
||||
.session
|
||||
.epiphany_state()
|
||||
.await
|
||||
.unwrap_or_default();
|
||||
if let Some(expected_revision) = request.expected_revision
|
||||
&& current_state.revision != expected_revision
|
||||
{
|
||||
return Err(CodexErr::InvalidRequest(format!(
|
||||
"epiphany state revision mismatch: expected {expected_revision}, found {}",
|
||||
current_state.revision
|
||||
)));
|
||||
}
|
||||
|
||||
let Some(binding_index) = current_state
|
||||
.job_bindings
|
||||
.iter()
|
||||
.position(|binding| binding.id == request.binding_id)
|
||||
else {
|
||||
return Err(CodexErr::InvalidRequest(format!(
|
||||
"epiphany job binding {:?} was not found",
|
||||
request.binding_id
|
||||
)));
|
||||
};
|
||||
let interrupted_thread_ids = Vec::new();
|
||||
let cancel_requested = false;
|
||||
|
||||
let next_job_bindings = clear_epiphany_job_binding_backend(
|
||||
current_state.job_bindings.clone(),
|
||||
binding_index,
|
||||
"No active heartbeat turn is currently bound; launch explicitly to resume specialist work.",
|
||||
);
|
||||
let epiphany_state = self
|
||||
.epiphany_update_state(EpiphanyStateUpdate {
|
||||
expected_revision: request.expected_revision,
|
||||
job_bindings: Some(next_job_bindings),
|
||||
..Default::default()
|
||||
})
|
||||
.await?;
|
||||
|
||||
Ok(EpiphanyJobInterruptResult {
|
||||
epiphany_state,
|
||||
binding_id: request.binding_id,
|
||||
cancel_requested,
|
||||
interrupted_thread_ids,
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn epiphany_retrieval_state(&self) -> EpiphanyRetrievalState {
|
||||
let config = self.codex.thread_config_snapshot().await;
|
||||
let workspace_root = config.cwd.to_path_buf();
|
||||
let codex_home = self.codex.session.codex_home().await;
|
||||
let fallback_workspace_root = workspace_root.clone();
|
||||
let fallback_codex_home = codex_home.clone();
|
||||
tokio::task::spawn_blocking(move || {
|
||||
epiphany_core::retrieval_state_for_workspace(&workspace_root, codex_home.as_path())
|
||||
})
|
||||
.await
|
||||
.unwrap_or_else(|_| {
|
||||
epiphany_core::retrieval_state_for_workspace(
|
||||
&fallback_workspace_root,
|
||||
fallback_codex_home.as_path(),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn epiphany_runtime_spine_store_path(&self) -> PathBuf {
|
||||
self.config_snapshot()
|
||||
.await
|
||||
|
|
@ -563,36 +359,8 @@ impl CodexThread {
|
|||
.to_path_buf()
|
||||
}
|
||||
|
||||
pub async fn epiphany_index(
|
||||
&self,
|
||||
force_full_rebuild: bool,
|
||||
) -> anyhow::Result<EpiphanyRetrievalState> {
|
||||
let config = self.codex.thread_config_snapshot().await;
|
||||
let workspace_root = config.cwd.to_path_buf();
|
||||
let codex_home = self.codex.session.codex_home().await;
|
||||
tokio::task::spawn_blocking(move || {
|
||||
epiphany_core::index_workspace(
|
||||
&workspace_root,
|
||||
codex_home.as_path(),
|
||||
force_full_rebuild,
|
||||
)
|
||||
})
|
||||
.await
|
||||
.map_err(|err| anyhow::anyhow!("epiphany index worker failed: {err}"))?
|
||||
}
|
||||
|
||||
pub async fn epiphany_retrieve(
|
||||
&self,
|
||||
query: EpiphanyRetrieveQuery,
|
||||
) -> anyhow::Result<EpiphanyRetrieveResponse> {
|
||||
let config = self.codex.thread_config_snapshot().await;
|
||||
let workspace_root = config.cwd.to_path_buf();
|
||||
let codex_home = self.codex.session.codex_home().await;
|
||||
tokio::task::spawn_blocking(move || {
|
||||
epiphany_core::retrieve_workspace(&workspace_root, codex_home.as_path(), query)
|
||||
})
|
||||
.await
|
||||
.map_err(|err| anyhow::anyhow!("epiphany retrieval worker failed: {err}"))?
|
||||
pub async fn codex_home(&self) -> PathBuf {
|
||||
self.codex.session.codex_home().await.to_path_buf()
|
||||
}
|
||||
|
||||
pub async fn read_mcp_resource(
|
||||
|
|
@ -668,45 +436,6 @@ impl CodexThread {
|
|||
}
|
||||
}
|
||||
|
||||
fn open_epiphany_runtime_spine_job(
|
||||
store_path: &std::path::Path,
|
||||
state: &EpiphanyThreadState,
|
||||
request: &EpiphanyJobLaunchRequest,
|
||||
backend_job_id: &str,
|
||||
) -> CodexResult<()> {
|
||||
let now = chrono::Utc::now().to_rfc3339_opts(chrono::SecondsFormat::Secs, true);
|
||||
open_runtime_spine_heartbeat_job(
|
||||
store_path,
|
||||
RuntimeSpineHeartbeatJobOptions {
|
||||
runtime_id: "epiphany-local".to_string(),
|
||||
display_name: "Epiphany Local".to_string(),
|
||||
session_id: "epiphany-main".to_string(),
|
||||
objective: state
|
||||
.objective
|
||||
.clone()
|
||||
.filter(|objective| !objective.trim().is_empty())
|
||||
.unwrap_or_else(|| "Epiphany heartbeat activation".to_string()),
|
||||
coordinator_note: "App-server launch opened this typed runtime session.".to_string(),
|
||||
job_id: backend_job_id.to_string(),
|
||||
role: request.owner_role.clone(),
|
||||
binding_id: request.binding_id.clone(),
|
||||
authority_scope: request.authority_scope.clone(),
|
||||
instruction: request.instruction.clone(),
|
||||
launch_document: request.launch_document.clone(),
|
||||
output_contract_id: request.output_contract_id.clone(),
|
||||
created_at: now,
|
||||
},
|
||||
)
|
||||
.map_err(|err| {
|
||||
CodexErr::Fatal(format!(
|
||||
"failed to open Epiphany runtime spine job {:?} in {}: {err}",
|
||||
backend_job_id,
|
||||
store_path.display()
|
||||
))
|
||||
})?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn pending_message_input_item(message: &ResponseItem) -> CodexResult<ResponseInputItem> {
|
||||
match message {
|
||||
ResponseItem::Message { role, content, .. } => Ok(ResponseInputItem::Message {
|
||||
|
|
|
|||
Reference in a new issue