Move coordinator automation decision to bridge

This commit is contained in:
Meta Vens 2026-05-14 08:49:03 +01:00
commit 07becb1ca7
5 changed files with 156 additions and 88 deletions

View file

@ -19,8 +19,11 @@ use codex_app_server_protocol::ThreadEpiphanyRoleStatus;
use codex_app_server_protocol::ThreadEpiphanyRolesSource;
use codex_app_server_protocol::ThreadEpiphanySceneAction;
use codex_app_server_protocol::ThreadEpiphanyViewCoordinator;
use codex_core::EpiphanyJobLaunchRequest;
use codex_protocol::protocol::EpiphanyAcceptanceReceipt;
use codex_protocol::protocol::EpiphanyRetrievalState;
use codex_protocol::protocol::EpiphanyThreadState;
use codex_protocol::protocol::TokenUsageInfo;
use epiphany_core::EpiphanyCoordinatorAction as CoreEpiphanyCoordinatorAction;
use epiphany_core::EpiphanyCoordinatorAutomationAction as CoreEpiphanyCoordinatorAutomationAction;
use epiphany_core::EpiphanyCoordinatorCrrcRecommendation;
@ -55,11 +58,18 @@ use epiphany_core::select_coordinator_automation_action;
use crate::launch::EPIPHANY_IMAGINATION_OWNER_ROLE;
use crate::launch::EPIPHANY_IMAGINATION_ROLE_BINDING_ID;
use crate::launch::EPIPHANY_MODELING_ROLE_BINDING_ID;
use crate::launch::EPIPHANY_REORIENT_LAUNCH_BINDING_ID;
use crate::launch::EPIPHANY_REORIENT_OWNER_ROLE;
use crate::launch::EPIPHANY_VERIFICATION_ROLE_BINDING_ID;
use crate::launch::build_epiphany_reorient_launch_request;
use crate::launch::epiphany_role_label;
use crate::launch::render_epiphany_coordinator_note;
use crate::mutation::epiphany_modeling_finding_has_reviewable_state_patch;
use crate::pressure::map_epiphany_pressure;
use crate::reorient::EpiphanyFreshnessWatcherSnapshot;
use crate::reorient::map_epiphany_freshness;
use crate::reorient::map_epiphany_reorient;
use crate::runtime_results::load_epiphany_reorient_result_snapshot;
use crate::runtime_results::load_epiphany_role_result_snapshot;
use std::collections::HashSet;
@ -375,6 +385,124 @@ pub fn select_epiphany_coordinator_automation_action(
))
}
pub struct EpiphanyCoordinatorAutomationInput<'a> {
pub thread_id: &'a str,
pub state: &'a EpiphanyThreadState,
pub retrieval_override: &'a EpiphanyRetrievalState,
pub watcher_snapshot: EpiphanyFreshnessWatcherSnapshot<'a>,
pub token_usage_info: Option<&'a TokenUsageInfo>,
pub runtime_store_path: &'a Path,
pub force_checkpoint_compaction: bool,
}
pub struct EpiphanyCoordinatorAutomationVerdict {
pub action: EpiphanyCoordinatorAutomationAction,
pub launch_request: Option<EpiphanyJobLaunchRequest>,
}
pub async fn select_epiphany_coordinator_automation(
input: EpiphanyCoordinatorAutomationInput<'_>,
) -> EpiphanyCoordinatorAutomationVerdict {
let (_state_revision, retrieval, graph, watcher) = map_epiphany_freshness(
Some(input.state),
Some(input.retrieval_override),
Some(input.watcher_snapshot),
);
let pressure = map_epiphany_pressure(input.token_usage_info);
let (state_status, reorient_decision) =
map_epiphany_reorient(Some(input.state), &pressure, &retrieval, &graph, &watcher);
if state_status != ThreadEpiphanyReorientStateStatus::Ready {
return EpiphanyCoordinatorAutomationVerdict {
action: EpiphanyCoordinatorAutomationAction::None,
launch_request: None,
};
}
let jobs = crate::jobs::map_epiphany_jobs(Some(input.state), Some(input.retrieval_override));
let reorient_job = jobs
.iter()
.find(|job| job.id == EPIPHANY_REORIENT_LAUNCH_BINDING_ID)
.cloned();
let (reorient_result_status, reorient_finding, _) = load_epiphany_reorient_result_snapshot(
Some(input.state),
Some(input.runtime_store_path),
EPIPHANY_REORIENT_LAUNCH_BINDING_ID,
)
.await;
let reorient_finding_accepted = reorient_finding
.as_ref()
.is_some_and(|finding| epiphany_reorient_finding_already_accepted(input.state, finding));
let crrc_recommendation = map_epiphany_crrc_recommendation(
true,
state_status,
&pressure,
&reorient_decision,
reorient_result_status,
input.state.investigation_checkpoint.as_ref().is_some(),
reorient_finding.is_some(),
reorient_finding_accepted,
);
let roles = map_epiphany_roles(
Some(input.state),
&jobs,
&reorient_decision,
&pressure,
&crrc_recommendation,
reorient_result_status,
reorient_job.as_ref(),
);
let coordinator = derive_epiphany_coordinator_status(
Some(input.state),
Some(input.runtime_store_path),
state_status,
&pressure,
&crrc_recommendation,
roles,
Some(&reorient_decision),
reorient_result_status,
reorient_finding.as_ref(),
input.state.investigation_checkpoint.as_ref().is_some(),
)
.await;
let action = select_epiphany_coordinator_automation_action(
&coordinator.decision,
input.force_checkpoint_compaction,
);
let launch_request = match action {
EpiphanyCoordinatorAutomationAction::LaunchReorientWorker => input
.state
.investigation_checkpoint
.as_ref()
.map(|checkpoint| {
build_epiphany_reorient_launch_request(
input.thread_id,
Some(input.state.revision),
None,
input.state,
checkpoint,
&reorient_decision,
)
}),
EpiphanyCoordinatorAutomationAction::None
| EpiphanyCoordinatorAutomationAction::CompactRehydrateReorient => None,
};
let action = if matches!(
action,
EpiphanyCoordinatorAutomationAction::LaunchReorientWorker
) && launch_request.is_none()
{
EpiphanyCoordinatorAutomationAction::None
} else {
action
};
EpiphanyCoordinatorAutomationVerdict {
action,
launch_request,
}
}
pub fn map_epiphany_coordinator(
state_status: ThreadEpiphanyReorientStateStatus,
checkpoint_present: bool,

View file

@ -787,6 +787,14 @@ persisted token-usage snapshot and maps it back to the rebuilt turn owner.
`token_usage_replay.rs` is now just the host shell: read rollout items, choose
whether to replay, and send a connection-scoped JSON-RPC notification.
Safe-boundary coordinator automation decision composition has followed.
`epiphany-codex-bridge::coordinator::select_epiphany_coordinator_automation`
now owns the freshness/pressure/reorient/jobs/CRRC/roles/coordinator
composition and returns either no action, compact, or a typed reorient launch
request. `epiphany_automation.rs` still gathers live host facts and executes
the host side effects: submit `Op::Compact`, call `epiphany_launch_job`, and
emit JSON-RPC state-update notifications.
The MCP config path is now product-quarantined. `Config::to_mcp_config` keeps
user-declared MCP servers but no longer accepts a `PluginsManager`, folds
plugin-provided MCP servers into the runtime, enables Codex apps, enables skill

Binary file not shown.

File diff suppressed because one or more lines are too long

View file

@ -1,7 +1,6 @@
use std::sync::Arc;
use codex_app_server_protocol::ServerNotification;
use codex_app_server_protocol::ThreadEpiphanyReorientStateStatus;
use codex_app_server_protocol::ThreadEpiphanyStateUpdatedNotification;
use codex_app_server_protocol::ThreadEpiphanyStateUpdatedSource;
use codex_core::CodexThread;
@ -11,23 +10,14 @@ use codex_protocol::protocol::Op;
use codex_protocol::protocol::TokenUsageInfo as CoreTokenUsageInfo;
use codex_protocol::user_input::UserInput as CoreInputItem;
use epiphany_codex_bridge::coordinator::EpiphanyCoordinatorAutomationAction;
use epiphany_codex_bridge::coordinator::derive_epiphany_coordinator_status;
use epiphany_codex_bridge::coordinator::epiphany_reorient_finding_already_accepted;
use epiphany_codex_bridge::coordinator::map_epiphany_crrc_recommendation;
use epiphany_codex_bridge::coordinator::map_epiphany_roles;
use epiphany_codex_bridge::coordinator::select_epiphany_coordinator_automation_action;
use epiphany_codex_bridge::coordinator::EpiphanyCoordinatorAutomationInput;
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::jobs::map_epiphany_jobs;
use epiphany_codex_bridge::launch::EPIPHANY_REORIENT_LAUNCH_BINDING_ID;
use epiphany_codex_bridge::launch::build_epiphany_reorient_launch_request;
use epiphany_codex_bridge::mutation::epiphany_job_launch_changed_fields;
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::reorient::map_epiphany_freshness;
use epiphany_codex_bridge::reorient::map_epiphany_reorient;
use epiphany_codex_bridge::runtime_results::load_epiphany_reorient_result_snapshot;
use epiphany_codex_bridge::state::client_visible_live_thread_epiphany_state;
use tokio::sync::Mutex;
use tracing::warn;
@ -58,69 +48,18 @@ pub(crate) async fn maybe_run_epiphany_coordinator_automation_for_turn_boundary(
let token_usage_info = thread.token_usage_info().await;
let runtime_store_path = thread.epiphany_runtime_spine_store_path().await;
let (_state_revision, retrieval, graph, watcher) = map_epiphany_freshness(
Some(&state),
Some(&retrieval_override),
Some(epiphany_freshness_watcher_snapshot(&watcher_snapshot)),
);
let pressure = map_epiphany_pressure(token_usage_info.as_ref());
let (state_status, reorient_decision) =
map_epiphany_reorient(Some(&state), &pressure, &retrieval, &graph, &watcher);
if state_status != ThreadEpiphanyReorientStateStatus::Ready {
return;
}
let jobs = map_epiphany_jobs(Some(&state), Some(&retrieval_override));
let reorient_job = jobs
.iter()
.find(|job| job.id == EPIPHANY_REORIENT_LAUNCH_BINDING_ID)
.cloned();
let (reorient_result_status, reorient_finding, _) = load_epiphany_reorient_result_snapshot(
Some(&state),
Some(runtime_store_path.as_path()),
EPIPHANY_REORIENT_LAUNCH_BINDING_ID,
)
.await;
let reorient_finding_accepted = reorient_finding
.as_ref()
.is_some_and(|finding| epiphany_reorient_finding_already_accepted(&state, finding));
let crrc_recommendation = map_epiphany_crrc_recommendation(
true,
state_status,
&pressure,
&reorient_decision,
reorient_result_status,
state.investigation_checkpoint.as_ref().is_some(),
reorient_finding.is_some(),
reorient_finding_accepted,
);
let roles = map_epiphany_roles(
Some(&state),
&jobs,
&reorient_decision,
&pressure,
&crrc_recommendation,
reorient_result_status,
reorient_job.as_ref(),
);
let coordinator = derive_epiphany_coordinator_status(
Some(&state),
Some(runtime_store_path.as_path()),
state_status,
&pressure,
&crrc_recommendation,
roles,
Some(&reorient_decision),
reorient_result_status,
reorient_finding.as_ref(),
state.investigation_checkpoint.as_ref().is_some(),
)
.await;
match select_epiphany_coordinator_automation_action(
&coordinator.decision,
let verdict = select_epiphany_coordinator_automation(EpiphanyCoordinatorAutomationInput {
thread_id: &thread_id_text,
state: &state,
retrieval_override: &retrieval_override,
watcher_snapshot: epiphany_freshness_watcher_snapshot(&watcher_snapshot),
token_usage_info: token_usage_info.as_ref(),
runtime_store_path: runtime_store_path.as_path(),
force_checkpoint_compaction,
) {
})
.await;
match verdict.action {
EpiphanyCoordinatorAutomationAction::None => {}
EpiphanyCoordinatorAutomationAction::CompactRehydrateReorient => {
if let Err(err) = thread.submit(Op::Compact).await {
@ -130,17 +69,9 @@ pub(crate) async fn maybe_run_epiphany_coordinator_automation_for_turn_boundary(
}
}
EpiphanyCoordinatorAutomationAction::LaunchReorientWorker => {
let Some(checkpoint) = state.investigation_checkpoint.as_ref() else {
let Some(launch_request) = verdict.launch_request else {
return;
};
let launch_request = build_epiphany_reorient_launch_request(
&thread_id_text,
Some(state.revision),
None,
&state,
checkpoint,
&reorient_decision,
);
let launched = match thread.epiphany_launch_job(launch_request).await {
Ok(launched) => launched,
Err(err) => {