Map token pressure at host wall
This commit is contained in:
parent
623cde94c3
commit
d749c50f2d
8 changed files with 35 additions and 20 deletions
|
|
@ -25,6 +25,7 @@ use tracing::warn;
|
|||
|
||||
use super::epiphany_thread_host::EpiphanyCodexThreadHost;
|
||||
use super::epiphany_thread_host::client_visible_live_thread_epiphany_state;
|
||||
use super::epiphany_thread_host::epiphany_token_usage_snapshot;
|
||||
use crate::outgoing_message::ThreadScopedOutgoingMessageSender;
|
||||
use crate::thread_state::ThreadState;
|
||||
|
||||
|
|
@ -51,6 +52,7 @@ pub(crate) async fn maybe_run_epiphany_coordinator_automation_for_turn_boundary(
|
|||
.snapshot(&thread_id_text)
|
||||
.await;
|
||||
let token_usage_info = thread.token_usage_info().await;
|
||||
let token_usage_snapshot = epiphany_token_usage_snapshot(token_usage_info.as_ref());
|
||||
let runtime_store_path = thread.epiphany_runtime_spine_store_path().await;
|
||||
|
||||
let verdict = select_epiphany_coordinator_automation(EpiphanyCoordinatorAutomationInput {
|
||||
|
|
@ -58,7 +60,7 @@ pub(crate) async fn maybe_run_epiphany_coordinator_automation_for_turn_boundary(
|
|||
state: &state,
|
||||
retrieval_override: &retrieval_override,
|
||||
watcher_snapshot: epiphany_freshness_watcher_snapshot(&watcher_snapshot),
|
||||
token_usage_info: token_usage_info.as_ref(),
|
||||
token_usage_info: token_usage_snapshot.as_ref(),
|
||||
runtime_store_path: runtime_store_path.as_path(),
|
||||
force_checkpoint_compaction,
|
||||
})
|
||||
|
|
@ -112,7 +114,8 @@ 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());
|
||||
let token_usage_snapshot = epiphany_token_usage_snapshot(token_usage_info.as_ref());
|
||||
let pressure = map_epiphany_pressure(token_usage_snapshot.as_ref());
|
||||
if !should_run_epiphany_pre_compaction_checkpoint_intervention(&pressure) {
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ use super::CodexMessageProcessor;
|
|||
use super::ConnectionRequestId;
|
||||
use super::ThreadReadViewError;
|
||||
use super::epiphany_thread_host::EpiphanyCodexThreadHost;
|
||||
use super::epiphany_thread_host::epiphany_token_usage_snapshot;
|
||||
|
||||
impl CodexMessageProcessor {
|
||||
async fn load_epiphany_thread(
|
||||
|
|
@ -259,6 +260,7 @@ impl CodexMessageProcessor {
|
|||
.await;
|
||||
let token_usage_info = loaded_thread.token_usage_info().await;
|
||||
let host = EpiphanyCodexThreadHost::new(loaded_thread.as_ref());
|
||||
let token_usage_snapshot = epiphany_token_usage_snapshot(token_usage_info.as_ref());
|
||||
let applied = match launch_thread_epiphany_reorient(
|
||||
&host,
|
||||
&thread_id,
|
||||
|
|
@ -267,7 +269,7 @@ impl CodexMessageProcessor {
|
|||
thread.epiphany_state.as_ref(),
|
||||
Some(&retrieval_override),
|
||||
Some(epiphany_freshness_watcher_snapshot(&watcher_snapshot)),
|
||||
token_usage_info.as_ref(),
|
||||
token_usage_snapshot.as_ref(),
|
||||
)
|
||||
.await
|
||||
{
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ use epiphany_codex_bridge::view::map_epiphany_view_response;
|
|||
use super::CodexMessageProcessor;
|
||||
use super::ConnectionRequestId;
|
||||
use super::ThreadReadViewError;
|
||||
use super::epiphany_thread_host::epiphany_token_usage_snapshot;
|
||||
use super::latest_token_usage_info_from_rollout_path;
|
||||
|
||||
impl CodexMessageProcessor {
|
||||
|
|
@ -124,6 +125,7 @@ impl CodexMessageProcessor {
|
|||
} else {
|
||||
None
|
||||
};
|
||||
let token_usage_snapshot = epiphany_token_usage_snapshot(token_usage_info.as_ref());
|
||||
let response = map_epiphany_view_response(EpiphanyViewResponseInput {
|
||||
thread_id: thread_id.clone(),
|
||||
lenses,
|
||||
|
|
@ -133,7 +135,7 @@ impl CodexMessageProcessor {
|
|||
watcher_snapshot: watcher_snapshot
|
||||
.as_ref()
|
||||
.map(epiphany_freshness_watcher_snapshot),
|
||||
token_usage_info: token_usage_info.as_ref(),
|
||||
token_usage_info: token_usage_snapshot.as_ref(),
|
||||
runtime_store_path: runtime_store_path.as_deref(),
|
||||
})
|
||||
.await;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,9 @@ use codex_core::latest_epiphany_state_from_rollout_items;
|
|||
use codex_protocol::error::CodexErr;
|
||||
use codex_protocol::protocol::EpiphanyThreadState;
|
||||
use codex_protocol::protocol::InitialHistory;
|
||||
use codex_protocol::protocol::TokenUsageInfo;
|
||||
use epiphany_codex_bridge::mutation_service::EpiphanyMutationHost;
|
||||
use epiphany_codex_bridge::pressure::EpiphanyTokenUsageSnapshot;
|
||||
use epiphany_codex_bridge::state::client_visible_epiphany_state_for_paths;
|
||||
use epiphany_codex_bridge::state::thread_state_mirror_id_from_rollout_path;
|
||||
|
||||
|
|
@ -91,3 +93,14 @@ pub(super) async fn client_visible_live_thread_epiphany_state(
|
|||
) -> EpiphanyThreadState {
|
||||
live_thread_epiphany_state(thread).await.unwrap_or(fallback)
|
||||
}
|
||||
|
||||
pub(super) fn epiphany_token_usage_snapshot(
|
||||
info: Option<&TokenUsageInfo>,
|
||||
) -> Option<EpiphanyTokenUsageSnapshot> {
|
||||
info.map(|info| EpiphanyTokenUsageSnapshot {
|
||||
total_tokens: info.total_token_usage.total_tokens,
|
||||
last_turn_tokens: info.last_token_usage.total_tokens,
|
||||
model_context_window: info.model_context_window,
|
||||
model_auto_compact_token_limit: info.model_auto_compact_token_limit,
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue