Move Epiphany state host seam to app-server

This commit is contained in:
Meta Vens 2026-05-19 14:12:34 +01:00
commit 1f03e8a449
5 changed files with 96 additions and 58 deletions

View file

@ -4,6 +4,7 @@ mod command_routes;
mod epiphany_automation;
mod epiphany_mutation_routes;
mod epiphany_read_routes;
mod epiphany_thread_host;
mod listener_lifecycle;
mod mcp_routes;
mod realtime_routes;
@ -25,6 +26,8 @@ mod turn_routes;
use self::auth_routes::ActiveLogin;
pub(crate) use self::epiphany_automation::maybe_run_epiphany_coordinator_automation_for_turn_boundary;
pub(crate) use self::epiphany_automation::maybe_run_epiphany_pre_compaction_checkpoint_intervention_for_token_count;
use self::epiphany_thread_host::live_thread_epiphany_state;
use self::epiphany_thread_host::load_epiphany_state_from_rollout_path;
pub(super) use self::listener_lifecycle::{EnsureConversationListenerResult, ListenerTaskContext};
pub(crate) use self::running_thread_resume_routes::handle_pending_thread_resume_request;
pub(crate) use self::thread_config::{config_load_error, validate_dynamic_tools};
@ -340,8 +343,6 @@ use codex_thread_store::UpdateThreadMetadataParams as StoreUpdateThreadMetadataP
use codex_utils_absolute_path::AbsolutePathBuf;
use codex_utils_pty::DEFAULT_OUTPUT_BYTES_CAP;
use epiphany_codex_bridge::invalidation::EpiphanyInvalidationManager;
use epiphany_codex_bridge::state::live_thread_epiphany_state;
use epiphany_codex_bridge::state::load_epiphany_state_from_rollout_path;
use std::collections::HashMap;
use std::collections::HashSet;
use std::io::Error as IoError;

View file

@ -20,10 +20,10 @@ 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::epiphany_retrieval_state_for_paths;
use epiphany_codex_bridge::state::client_visible_live_thread_epiphany_state;
use tokio::sync::Mutex;
use tracing::warn;
use super::epiphany_thread_host::client_visible_live_thread_epiphany_state;
use crate::outgoing_message::ThreadScopedOutgoingMessageSender;
use crate::thread_state::ThreadState;

View file

@ -0,0 +1,53 @@
use std::path::Path;
use codex_core::CodexThread;
use codex_core::RolloutRecorder;
use codex_core::latest_epiphany_state_from_rollout_items;
use codex_protocol::protocol::EpiphanyThreadState;
use codex_protocol::protocol::InitialHistory;
use epiphany_codex_bridge::state::client_visible_epiphany_state_for_paths;
use epiphany_codex_bridge::state::thread_state_mirror_id_from_rollout_path;
pub(super) async fn load_epiphany_state_from_rollout_path(
rollout_path: &Path,
) -> std::result::Result<Option<EpiphanyThreadState>, String> {
let items = match RolloutRecorder::get_rollout_history(rollout_path)
.await
.map_err(|err| {
format!(
"failed to load rollout `{}` for Epiphany state: {err}",
rollout_path.display()
)
})? {
InitialHistory::New | InitialHistory::Cleared => Vec::new(),
InitialHistory::Forked(items) => items,
InitialHistory::Resumed(resumed) => resumed.history,
};
Ok(latest_epiphany_state_from_rollout_items(&items))
}
pub(super) async fn live_thread_epiphany_state(
thread: &CodexThread,
) -> Option<EpiphanyThreadState> {
let state = thread.epiphany_state().await?;
let config = thread.config_snapshot().await;
let codex_home = thread.codex_home().await;
let rollout_path = thread.rollout_path();
let mirror_thread_id = thread_state_mirror_id_from_rollout_path(rollout_path.as_deref());
Some(
client_visible_epiphany_state_for_paths(
state,
config.cwd.as_path(),
codex_home,
Some(mirror_thread_id.as_str()),
)
.await,
)
}
pub(super) async fn client_visible_live_thread_epiphany_state(
thread: &CodexThread,
fallback: EpiphanyThreadState,
) -> EpiphanyThreadState {
live_thread_epiphany_state(thread).await.unwrap_or(fallback)
}