Use typed pressure for reorient decisions
This commit is contained in:
parent
e4052d557f
commit
4955740c8e
8 changed files with 62 additions and 26 deletions
|
|
@ -65,6 +65,7 @@ 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::derive_epiphany_pressure;
|
||||
use crate::pressure::map_epiphany_pressure;
|
||||
use crate::reorient::EpiphanyFreshnessWatcherSnapshot;
|
||||
use crate::reorient::map_epiphany_freshness;
|
||||
|
|
@ -408,9 +409,10 @@ pub async fn select_epiphany_coordinator_automation(
|
|||
Some(input.retrieval_override),
|
||||
Some(input.watcher_snapshot),
|
||||
);
|
||||
let core_pressure = derive_epiphany_pressure(input.token_usage_info);
|
||||
let pressure = map_epiphany_pressure(input.token_usage_info);
|
||||
let (state_status, reorient_decision) =
|
||||
map_epiphany_reorient(Some(input.state), &pressure, &retrieval, &graph, &watcher);
|
||||
map_epiphany_reorient(Some(input.state), &core_pressure, &retrieval, &graph, &watcher);
|
||||
if state_status != ThreadEpiphanyReorientStateStatus::Ready {
|
||||
return EpiphanyCoordinatorAutomationVerdict {
|
||||
action: EpiphanyCoordinatorAutomationAction::None,
|
||||
|
|
|
|||
|
|
@ -5,6 +5,10 @@ pub use epiphany_core::EpiphanyGraphFreshnessStatus;
|
|||
pub use epiphany_core::EpiphanyInvalidationStatus;
|
||||
pub use epiphany_core::EpiphanyJobStatus;
|
||||
pub use epiphany_core::EpiphanyJobView;
|
||||
pub use epiphany_core::EpiphanyPressure;
|
||||
pub use epiphany_core::EpiphanyPressureBasis;
|
||||
pub use epiphany_core::EpiphanyPressureLevel;
|
||||
pub use epiphany_core::EpiphanyPressureStatus;
|
||||
pub use epiphany_core::EpiphanyRetrievalFreshnessStatus;
|
||||
pub use epiphany_state_model::EpiphanyJobKind;
|
||||
use serde::Deserialize;
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ use crate::mutation::epiphany_promote_changed_fields;
|
|||
use crate::mutation::epiphany_update_patch_changed_fields;
|
||||
use crate::mutation::state_update_from_thread_patch;
|
||||
use crate::mutation::thread_epiphany_patch_has_state_replacements;
|
||||
use crate::pressure::map_epiphany_pressure;
|
||||
use crate::pressure::derive_epiphany_pressure;
|
||||
use crate::reorient::EpiphanyFreshnessWatcherSnapshot;
|
||||
use crate::reorient::map_epiphany_freshness;
|
||||
use crate::reorient::map_epiphany_reorient;
|
||||
|
|
@ -582,7 +582,7 @@ pub async fn launch_thread_epiphany_reorient(
|
|||
) -> BridgeResult<EpiphanyReorientLaunchApplied> {
|
||||
let (state_revision, retrieval, graph, watcher) =
|
||||
map_epiphany_freshness(state, retrieval_override, watcher_snapshot);
|
||||
let pressure = map_epiphany_pressure(token_usage_info);
|
||||
let pressure = derive_epiphany_pressure(token_usage_info);
|
||||
let (state_status, decision) =
|
||||
map_epiphany_reorient(state, &pressure, &retrieval, &graph, &watcher);
|
||||
|
||||
|
|
|
|||
|
|
@ -11,12 +11,17 @@ use epiphany_core::derive_pressure_view;
|
|||
|
||||
use crate::launch::epiphany_agent_prompt_with_memory;
|
||||
use crate::launch::epiphany_specialist_prompt_config;
|
||||
use crate::launch::pressure_level_label;
|
||||
|
||||
pub fn derive_epiphany_pressure(
|
||||
snapshot: Option<&EpiphanyTokenUsageSnapshot>,
|
||||
) -> EpiphanyPressure {
|
||||
derive_pressure_view(snapshot)
|
||||
}
|
||||
|
||||
pub fn map_epiphany_pressure(
|
||||
snapshot: Option<&EpiphanyTokenUsageSnapshot>,
|
||||
) -> ThreadEpiphanyPressure {
|
||||
map_core_epiphany_pressure(derive_pressure_view(snapshot))
|
||||
map_core_epiphany_pressure(derive_epiphany_pressure(snapshot))
|
||||
}
|
||||
|
||||
fn map_core_epiphany_pressure(pressure: EpiphanyPressure) -> ThreadEpiphanyPressure {
|
||||
|
|
@ -52,13 +57,13 @@ fn map_core_epiphany_pressure(pressure: EpiphanyPressure) -> ThreadEpiphanyPress
|
|||
}
|
||||
|
||||
pub fn should_run_epiphany_pre_compaction_checkpoint_intervention(
|
||||
pressure: &ThreadEpiphanyPressure,
|
||||
pressure: &EpiphanyPressure,
|
||||
) -> bool {
|
||||
pressure.status == ThreadEpiphanyPressureStatus::Ready && pressure.should_prepare_compaction
|
||||
pressure.status == CoreEpiphanyPressureStatus::Ready && pressure.should_prepare_compaction
|
||||
}
|
||||
|
||||
pub fn render_epiphany_pre_compaction_checkpoint_intervention(
|
||||
pressure: &ThreadEpiphanyPressure,
|
||||
pressure: &EpiphanyPressure,
|
||||
) -> String {
|
||||
let usage = match (
|
||||
pressure.used_tokens,
|
||||
|
|
@ -80,6 +85,16 @@ pub fn render_epiphany_pre_compaction_checkpoint_intervention(
|
|||
);
|
||||
template
|
||||
.trim()
|
||||
.replace("{pressure_level}", pressure_level_label(pressure.level))
|
||||
.replace("{pressure_level}", core_pressure_level_label(pressure.level))
|
||||
.replace("{usage}", &usage)
|
||||
}
|
||||
|
||||
fn core_pressure_level_label(level: CoreEpiphanyPressureLevel) -> &'static str {
|
||||
match level {
|
||||
CoreEpiphanyPressureLevel::Unknown => "unknown",
|
||||
CoreEpiphanyPressureLevel::Low => "low",
|
||||
CoreEpiphanyPressureLevel::Elevated => "elevated",
|
||||
CoreEpiphanyPressureLevel::High => "high",
|
||||
CoreEpiphanyPressureLevel::Critical => "critical",
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ use codex_app_server_protocol::ThreadEpiphanyGraphFreshness;
|
|||
use codex_app_server_protocol::ThreadEpiphanyGraphFreshnessStatus;
|
||||
use codex_app_server_protocol::ThreadEpiphanyInvalidationInput;
|
||||
use codex_app_server_protocol::ThreadEpiphanyInvalidationStatus;
|
||||
use codex_app_server_protocol::ThreadEpiphanyPressure;
|
||||
use codex_app_server_protocol::ThreadEpiphanyPressureLevel;
|
||||
use codex_app_server_protocol::ThreadEpiphanyReorientAction;
|
||||
use codex_app_server_protocol::ThreadEpiphanyReorientCheckpointStatus;
|
||||
|
|
@ -18,6 +17,8 @@ use epiphany_core::EpiphanyGraphFreshness as CoreEpiphanyGraphFreshness;
|
|||
use epiphany_core::EpiphanyGraphFreshnessStatus as CoreEpiphanyGraphFreshnessStatus;
|
||||
use epiphany_core::EpiphanyInvalidationInput as CoreEpiphanyInvalidationInput;
|
||||
use epiphany_core::EpiphanyInvalidationStatus as CoreEpiphanyInvalidationStatus;
|
||||
use epiphany_core::EpiphanyPressure;
|
||||
use epiphany_core::EpiphanyPressureLevel;
|
||||
use epiphany_core::EpiphanyReorientAction as CoreEpiphanyReorientAction;
|
||||
use epiphany_core::EpiphanyReorientCheckpointStatus as CoreEpiphanyReorientCheckpointStatus;
|
||||
use epiphany_core::EpiphanyReorientFreshnessStatus as CoreEpiphanyReorientFreshnessStatus;
|
||||
|
|
@ -163,7 +164,7 @@ fn map_core_epiphany_invalidation_input(
|
|||
|
||||
pub fn map_epiphany_reorient(
|
||||
state: Option<&EpiphanyThreadState>,
|
||||
pressure: &ThreadEpiphanyPressure,
|
||||
pressure: &EpiphanyPressure,
|
||||
retrieval: &ThreadEpiphanyRetrievalFreshness,
|
||||
graph: &ThreadEpiphanyGraphFreshness,
|
||||
watcher: &ThreadEpiphanyInvalidationInput,
|
||||
|
|
@ -192,14 +193,14 @@ pub fn map_epiphany_reorient(
|
|||
}
|
||||
|
||||
fn map_core_reorient_pressure_level(
|
||||
level: ThreadEpiphanyPressureLevel,
|
||||
level: EpiphanyPressureLevel,
|
||||
) -> CoreEpiphanyReorientPressureLevel {
|
||||
match level {
|
||||
ThreadEpiphanyPressureLevel::Unknown => CoreEpiphanyReorientPressureLevel::Unknown,
|
||||
ThreadEpiphanyPressureLevel::Low => CoreEpiphanyReorientPressureLevel::Low,
|
||||
ThreadEpiphanyPressureLevel::Elevated => CoreEpiphanyReorientPressureLevel::Medium,
|
||||
ThreadEpiphanyPressureLevel::High => CoreEpiphanyReorientPressureLevel::High,
|
||||
ThreadEpiphanyPressureLevel::Critical => CoreEpiphanyReorientPressureLevel::Critical,
|
||||
EpiphanyPressureLevel::Unknown => CoreEpiphanyReorientPressureLevel::Unknown,
|
||||
EpiphanyPressureLevel::Low => CoreEpiphanyReorientPressureLevel::Low,
|
||||
EpiphanyPressureLevel::Elevated => CoreEpiphanyReorientPressureLevel::Medium,
|
||||
EpiphanyPressureLevel::High => CoreEpiphanyReorientPressureLevel::High,
|
||||
EpiphanyPressureLevel::Critical => CoreEpiphanyReorientPressureLevel::Critical,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ use crate::cultnet::EpiphanyFreshnessSurface;
|
|||
use crate::cultnet::EpiphanySurfaceSource;
|
||||
use crate::jobs::map_epiphany_jobs;
|
||||
use crate::launch::EPIPHANY_REORIENT_LAUNCH_BINDING_ID;
|
||||
use crate::pressure::derive_epiphany_pressure;
|
||||
use crate::pressure::map_epiphany_pressure;
|
||||
use crate::reorient::EpiphanyFreshnessWatcherSnapshot;
|
||||
use crate::reorient::derive_epiphany_freshness_view;
|
||||
|
|
@ -176,15 +177,16 @@ pub async fn map_epiphany_view_response(
|
|||
let needs_jobs = epiphany_view_needs_jobs(&lenses);
|
||||
let needs_reorientation_inputs = epiphany_view_needs_reorientation_inputs(&lenses);
|
||||
let needs_pressure = epiphany_view_needs_pressure(&lenses);
|
||||
let core_pressure = needs_pressure.then(|| derive_epiphany_pressure(token_usage_info));
|
||||
let pressure = needs_pressure.then(|| map_epiphany_pressure(token_usage_info));
|
||||
let freshness = needs_reorientation_inputs
|
||||
.then(|| map_epiphany_freshness(state, retrieval_override, watcher_snapshot));
|
||||
let (state_revision, reorient_state_status, reorient_decision) =
|
||||
if let (Some((state_revision, retrieval, graph, watcher)), Some(pressure)) =
|
||||
(freshness.as_ref(), pressure.as_ref())
|
||||
if let (Some((state_revision, retrieval, graph, watcher)), Some(core_pressure)) =
|
||||
(freshness.as_ref(), core_pressure.as_ref())
|
||||
{
|
||||
let (state_status, decision) =
|
||||
map_epiphany_reorient(state, pressure, retrieval, graph, watcher);
|
||||
map_epiphany_reorient(state, core_pressure, retrieval, graph, watcher);
|
||||
(*state_revision, state_status, Some(decision))
|
||||
} else {
|
||||
(None, ThreadEpiphanyReorientStateStatus::Missing, None)
|
||||
|
|
|
|||
|
|
@ -2,6 +2,9 @@ const EPIPHANY_PRESSURE_ELEVATED_PER_MILLE: u32 = 650;
|
|||
const EPIPHANY_PRESSURE_PREPARE_COMPACTION_PER_MILLE: u32 = 800;
|
||||
const EPIPHANY_PRESSURE_CRITICAL_PER_MILLE: u32 = 950;
|
||||
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct EpiphanyTokenUsageSnapshot {
|
||||
pub total_tokens: i64,
|
||||
|
|
@ -10,27 +13,35 @@ pub struct EpiphanyTokenUsageSnapshot {
|
|||
pub model_auto_compact_token_limit: Option<i64>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct EpiphanyPressure {
|
||||
pub status: EpiphanyPressureStatus,
|
||||
pub level: EpiphanyPressureLevel,
|
||||
pub basis: EpiphanyPressureBasis,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub used_tokens: Option<i64>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub model_context_window: Option<i64>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub model_auto_compact_token_limit: Option<i64>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub remaining_tokens: Option<i64>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub ratio_per_mille: Option<u32>,
|
||||
pub should_prepare_compaction: bool,
|
||||
pub note: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub enum EpiphanyPressureStatus {
|
||||
Unknown,
|
||||
Ready,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub enum EpiphanyPressureLevel {
|
||||
Unknown,
|
||||
Low,
|
||||
|
|
@ -39,7 +50,8 @@ pub enum EpiphanyPressureLevel {
|
|||
Critical,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub enum EpiphanyPressureBasis {
|
||||
Unknown,
|
||||
AutoCompactLimit,
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ 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::derive_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;
|
||||
|
|
@ -115,7 +115,7 @@ pub(crate) async fn maybe_run_epiphany_pre_compaction_checkpoint_intervention_fo
|
|||
thread_state: &Arc<Mutex<ThreadState>>,
|
||||
) {
|
||||
let token_usage_snapshot = epiphany_token_usage_snapshot(token_usage_info.as_ref());
|
||||
let pressure = map_epiphany_pressure(token_usage_snapshot.as_ref());
|
||||
let pressure = derive_epiphany_pressure(token_usage_snapshot.as_ref());
|
||||
if !should_run_epiphany_pre_compaction_checkpoint_intervention(&pressure) {
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue