Move Epiphany automation assembly into bridge

This commit is contained in:
Meta Vens 2026-05-18 07:26:38 +01:00
commit 0ca51e02ca
6 changed files with 61 additions and 35 deletions

View file

@ -19,6 +19,7 @@ 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::CodexThread;
use codex_protocol::protocol::EpiphanyAcceptanceReceipt;
use codex_protocol::protocol::EpiphanyRetrievalState;
use codex_protocol::protocol::EpiphanyThreadState;
@ -64,13 +65,17 @@ 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::invalidation::EpiphanyInvalidationManager;
use crate::invalidation::epiphany_freshness_watcher_snapshot;
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::retrieve::thread_epiphany_retrieval_state;
use crate::runtime_results::load_epiphany_reorient_result_snapshot;
use crate::runtime_results::load_epiphany_role_result_snapshot;
use crate::state::runtime_spine_store_path;
use std::collections::HashSet;
use std::path::Path;
@ -504,6 +509,35 @@ pub async fn select_epiphany_coordinator_automation(
}
}
pub async fn select_thread_epiphany_coordinator_automation(
thread_id: &str,
thread: &CodexThread,
epiphany_invalidation_manager: &EpiphanyInvalidationManager,
force_checkpoint_compaction: bool,
) -> Option<EpiphanyCoordinatorAutomationVerdict> {
let state = thread.epiphany_state().await?;
let retrieval_override = thread_epiphany_retrieval_state(thread).await;
let config_snapshot = thread.config_snapshot().await;
epiphany_invalidation_manager
.ensure_thread_watch(thread_id, &config_snapshot.cwd)
.await;
let watcher_snapshot = epiphany_invalidation_manager.snapshot(thread_id).await;
let token_usage_info = thread.token_usage_info().await;
let runtime_store_path = runtime_spine_store_path(thread).await;
Some(
select_epiphany_coordinator_automation(EpiphanyCoordinatorAutomationInput {
thread_id,
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,
)
}
pub fn map_epiphany_coordinator(
state_status: ThreadEpiphanyReorientStateStatus,
checkpoint_present: bool,

View file

@ -88,3 +88,11 @@ pub fn render_epiphany_pre_compaction_checkpoint_intervention(
.replace("{pressure_level}", pressure_level_label(pressure.level))
.replace("{usage}", &usage)
}
pub fn render_pre_compaction_checkpoint_intervention_for_token_usage(
info: Option<&CoreTokenUsageInfo>,
) -> Option<String> {
let pressure = map_epiphany_pressure(info);
should_run_epiphany_pre_compaction_checkpoint_intervention(&pressure)
.then(|| render_epiphany_pre_compaction_checkpoint_intervention(&pressure))
}

View file

@ -63,6 +63,7 @@ remembers doctrine; the branch remembers the blade.
- Epiphany job launch/interrupt policy and state-update application now belong to `epiphany-codex-bridge::mutation_service`: heartbeat launch planning, runtime-spine job opening, binding/runtime-link mutation, interrupt binding cleanup, and typed patch apply are out of vendored `CodexThread`. `CodexThread` now exposes only the narrow Codex-session host seam for reading current Epiphany state/reference turn and persisting an already-mutated snapshot into rollout/session storage.
- Epiphany retrieval status, indexing, and retrieval execution now belong to `epiphany-codex-bridge::retrieve`; vendored `CodexThread` only exposes cwd/codex-home host facts for that path.
- Vendored app-server no longer imports `epiphany_core` directly. Retrieval query normalization and raw route job-launch DTO construction are bridge-owned adapters; the remaining direct native render call is in Codex core's model-context prompt fragment host seam.
- Coordinator automation input assembly and pre-compaction intervention text rendering now belong to `epiphany-codex-bridge`; vendored app-server keeps only host actions: submit Codex compaction, launch through bridge, steer active turns, and emit JSON-RPC notifications.
- Heartbeat durable document/schema types now live in `epiphany-core/src/heartbeat_state/heartbeat_documents.rs`, role/default construction lives in `epiphany-core/src/heartbeat_state/heartbeat_roles.rs`, persistence/validation lives in `epiphany-core/src/heartbeat_state/heartbeat_store.rs`, and status/artifact JSON projection lives in `epiphany-core/src/heartbeat_state/heartbeat_projection.rs`. The root `heartbeat_state.rs` keeps scheduling and Void cognition orchestration for the next cuts. Focused heartbeat tests and `epiphany-core` check pass after the splits.
- Heartbeat role/default and store seams now have module-local unit tests: fixed lane catalog, Ghostlight scene role projection, and typed state/cognition CultCache round-trip. Keep future heartbeat cuts aligned to those seam tests instead of growing root integration-only coverage.
- Heartbeat adaptive pacing now lives in `epiphany-core/src/heartbeat_state/heartbeat_pacing.rs`, including running-turn count and effective cooldown multipliers. It has a module-local unit test for pending-turn counting; root scheduling calls the pacing seam instead of owning pressure/concurrency math directly.

Binary file not shown.

View file

@ -37,6 +37,10 @@ objective:
Vendored app-server no longer imports `epiphany_core` directly; retrieval
query normalization and route job-launch DTO construction are bridge-owned
adapters.
Coordinator automation input assembly and pre-compaction intervention text
rendering are now bridge-owned; vendored app-server keeps only Codex host
actions such as submitting compaction, steering active turns, and emitting
JSON-RPC notifications.
constraints:
- No frontier-scale training tithe.

View file

@ -11,16 +11,10 @@ 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::EpiphanyCoordinatorAutomationInput;
use epiphany_codex_bridge::coordinator::select_epiphany_coordinator_automation;
use epiphany_codex_bridge::coordinator::select_thread_epiphany_coordinator_automation;
use epiphany_codex_bridge::invalidation::EpiphanyInvalidationManager;
use epiphany_codex_bridge::invalidation::epiphany_freshness_watcher_snapshot;
use epiphany_codex_bridge::mutation_service::launch_thread_epiphany_job;
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::runtime_spine_store_path;
use epiphany_codex_bridge::pressure::render_pre_compaction_checkpoint_intervention_for_token_usage;
use tokio::sync::Mutex;
use tracing::warn;
@ -35,32 +29,17 @@ pub(crate) async fn maybe_run_epiphany_coordinator_automation_for_turn_boundary(
force_checkpoint_compaction: bool,
) {
let thread_id_text = thread_id.to_string();
let Some(state) = thread.epiphany_state().await else {
let Some(verdict) = select_thread_epiphany_coordinator_automation(
&thread_id_text,
thread.as_ref(),
&epiphany_invalidation_manager,
force_checkpoint_compaction,
)
.await
else {
return;
};
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)
.await;
let watcher_snapshot = epiphany_invalidation_manager
.snapshot(&thread_id_text)
.await;
let token_usage_info = thread.token_usage_info().await;
let runtime_store_path = runtime_spine_store_path(thread.as_ref()).await;
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 => {
@ -112,10 +91,11 @@ pub(crate) async fn maybe_run_epiphany_pre_compaction_checkpoint_intervention_fo
token_usage_info: Option<CoreTokenUsageInfo>,
thread_state: &Arc<Mutex<ThreadState>>,
) {
let pressure = map_epiphany_pressure(token_usage_info.as_ref());
if !should_run_epiphany_pre_compaction_checkpoint_intervention(&pressure) {
let Some(text) =
render_pre_compaction_checkpoint_intervention_for_token_usage(token_usage_info.as_ref())
else {
return;
}
};
if thread.epiphany_state().await.is_none() {
return;
}
@ -129,7 +109,6 @@ pub(crate) async fn maybe_run_epiphany_pre_compaction_checkpoint_intervention_fo
}
}
let text = render_epiphany_pre_compaction_checkpoint_intervention(&pressure);
match thread
.steer_input(
vec![CoreInputItem::Text {