Delete unconsumed status tableaux
This commit is contained in:
parent
2ce9146131
commit
78836f3b45
11 changed files with 11 additions and 529 deletions
|
|
@ -1318,12 +1318,6 @@ fn run_coordinator(args: &Args) -> Result<Value> {
|
|||
break;
|
||||
}
|
||||
}
|
||||
"compactRehydrateReorient" => {
|
||||
push_event(
|
||||
&mut step,
|
||||
json!({"type": "compactUnsupportedInNativeSmoke"}),
|
||||
);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
append_operator_step_jsonl(&steps_path, &step)?;
|
||||
|
|
|
|||
|
|
@ -1,12 +1,8 @@
|
|||
use anyhow::{Context, Result, anyhow};
|
||||
use epiphany_core::{
|
||||
EpiphanyAgentPassContinuationAction, EpiphanyCoordinatorInput, EpiphanyCrrcAction,
|
||||
EpiphanyCrrcRecommendation,
|
||||
EpiphanyCurrentWorkProjection, EpiphanyReorientAction, EpiphanyRoleBoardInput,
|
||||
EpiphanyRoleResultRoleId,
|
||||
EpiphanyTokenUsageSnapshot, RepoFrontierPlanningLifecycle, RepoFrontierPlanningLifecycleStage,
|
||||
RepoFrontierResearchLifecycle, RepoFrontierResearchLifecycleStage, derive_pressure_view,
|
||||
derive_role_board, runtime_job_snapshot,
|
||||
EpiphanyCoordinatorInput, EpiphanyCrrcAction, EpiphanyCurrentWorkProjection,
|
||||
EpiphanyRoleBoardInput, RepoFrontierPlanningLifecycle, RepoFrontierPlanningLifecycleStage,
|
||||
RepoFrontierResearchLifecycle, RepoFrontierResearchLifecycleStage, derive_role_board,
|
||||
};
|
||||
use serde_json::{Value, json};
|
||||
use std::{
|
||||
|
|
@ -114,25 +110,16 @@ fn run_native_status(args: &Args) -> Result<Value> {
|
|||
} else {
|
||||
empty_current_work()
|
||||
};
|
||||
let pressure = derive_pressure_view(None::<&EpiphanyTokenUsageSnapshot>);
|
||||
let latest_reorientation_decision = mind
|
||||
.as_ref()
|
||||
.and_then(|mind| mind.reorientation_decisions.last());
|
||||
let reorientation_work = current_work.reorientation.as_ref();
|
||||
let reorient_action = latest_reorientation_decision
|
||||
.map(|decision| {
|
||||
if decision.mode == "regather" {
|
||||
EpiphanyReorientAction::Regather
|
||||
} else {
|
||||
EpiphanyReorientAction::Resume
|
||||
}
|
||||
})
|
||||
.unwrap_or(EpiphanyReorientAction::Resume);
|
||||
let recommendation = keyed_reorientation_recommendation(
|
||||
reorientation_work,
|
||||
latest_reorientation_decision,
|
||||
pressure.should_prepare_compaction,
|
||||
);
|
||||
let crrc_action = if latest_reorientation_decision
|
||||
.is_some_and(|decision| decision.mode == "regather")
|
||||
{
|
||||
EpiphanyCrrcAction::RegatherManually
|
||||
} else {
|
||||
EpiphanyCrrcAction::Continue
|
||||
};
|
||||
|
||||
let roles = derive_role_board(EpiphanyRoleBoardInput {
|
||||
mind_present: mind.is_some(),
|
||||
|
|
@ -140,72 +127,9 @@ fn run_native_status(args: &Args) -> Result<Value> {
|
|||
});
|
||||
let coordinator = epiphany_core::recommend_coordinator_action(EpiphanyCoordinatorInput {
|
||||
mind_present: mind.is_some(),
|
||||
should_prepare_compaction: pressure.should_prepare_compaction,
|
||||
crrc_action: recommendation.action,
|
||||
crrc_action,
|
||||
current_work: current_work.clone(),
|
||||
});
|
||||
|
||||
let research_lifecycle = mind.as_ref().map(|_| current_work.research.clone());
|
||||
let planning_lifecycle = mind
|
||||
.as_ref()
|
||||
.map(|_| current_work.frontier_planning.clone());
|
||||
let planning_eligibility = mind
|
||||
.as_ref()
|
||||
.map(|_| epiphany_core::runtime_repo_frontier_planning_eligibility(&store_path))
|
||||
.transpose()?;
|
||||
let frontier_relinquishment = mind
|
||||
.as_ref()
|
||||
.map(|_| epiphany_core::runtime_latest_repo_frontier_relinquishment(&store_path))
|
||||
.transpose()?
|
||||
.flatten();
|
||||
let body_job_id = current_work
|
||||
.body_modeling
|
||||
.as_ref()
|
||||
.and_then(|work| work.attempt.job_id.as_deref());
|
||||
let modeling_job_id = current_work
|
||||
.proposal_modeling
|
||||
.as_ref()
|
||||
.and_then(|work| work.attempt.job_id.as_deref())
|
||||
.or(body_job_id)
|
||||
.or(current_work
|
||||
.frontier_verdict_modeling
|
||||
.as_ref()
|
||||
.and_then(|work| work.attempt.job_id.as_deref()));
|
||||
let imagination_job_id = planning_lifecycle
|
||||
.as_ref()
|
||||
.and_then(|lifecycle| lifecycle.imagination_job_id.as_deref())
|
||||
.or(current_work
|
||||
.imagination_considerations
|
||||
.first()
|
||||
.and_then(|work| work.attempt.job_id.as_deref()))
|
||||
.or(current_work
|
||||
.admitted_model_direction_consideration
|
||||
.as_ref()
|
||||
.and_then(|work| work.attempt.job_id.as_deref()));
|
||||
let role_results = json!({
|
||||
"imagination": native_role_result(&store_path, imagination_job_id, EpiphanyRoleResultRoleId::Imagination),
|
||||
"research": native_role_result(
|
||||
&store_path,
|
||||
research_lifecycle.as_ref().and_then(|lifecycle| lifecycle.worker_job_id.as_deref()),
|
||||
EpiphanyRoleResultRoleId::Research,
|
||||
),
|
||||
"modeling": native_role_result(&store_path, modeling_job_id, EpiphanyRoleResultRoleId::Modeling),
|
||||
"verification": native_role_result(
|
||||
&store_path,
|
||||
current_work.verification.as_ref().and_then(|work| work.attempt.job_id.as_deref()),
|
||||
EpiphanyRoleResultRoleId::Verification,
|
||||
),
|
||||
});
|
||||
let tools = if mind.is_some() {
|
||||
native_tool_invocation_surface(&store_path)?
|
||||
} else {
|
||||
json!({"source": "native", "status": "missingMind"})
|
||||
};
|
||||
let reorient_result = keyed_reorientation_result(
|
||||
&store_path,
|
||||
reorientation_work,
|
||||
latest_reorientation_decision,
|
||||
)?;
|
||||
Ok(sanitize_for_operator(json!({
|
||||
"threadId": thread_id,
|
||||
"read": {
|
||||
|
|
@ -214,31 +138,9 @@ fn run_native_status(args: &Args) -> Result<Value> {
|
|||
"mindPresent": mind.is_some(),
|
||||
"projectionDigest": mind.as_ref().map(|mind| mind.projection_digest.as_str()),
|
||||
},
|
||||
"pressure": {"threadId": thread_id, "source": "native", "pressure": pressure},
|
||||
"reorient": {
|
||||
"threadId": thread_id,
|
||||
"source": "native",
|
||||
"decision": {
|
||||
"action": reorient_action,
|
||||
"nextAction": latest_reorientation_decision
|
||||
.map(|decision| decision.next_safe_move.as_str())
|
||||
.unwrap_or("No unresolved keyed reorientation obligation."),
|
||||
"requestId": reorientation_work.map(|work| work.request.request_id.as_str()),
|
||||
"authority": "keyedMindCurrentWork",
|
||||
},
|
||||
},
|
||||
"roles": {"threadId": thread_id, "source": "native", "roles": roles},
|
||||
"currentWork": current_work,
|
||||
"frontierPlanning": {
|
||||
"lifecycle": planning_lifecycle,
|
||||
"eligibility": planning_eligibility,
|
||||
},
|
||||
"frontierRelinquishment": frontier_relinquishment,
|
||||
"roleResults": role_results,
|
||||
"reorientResult": reorient_result,
|
||||
"crrc": {"threadId": thread_id, "source": "native", "recommendation": recommendation},
|
||||
"coordinator": coordinator,
|
||||
"tools": tools,
|
||||
})))
|
||||
}
|
||||
|
||||
|
|
@ -272,108 +174,6 @@ fn empty_current_work() -> EpiphanyCurrentWorkProjection {
|
|||
}
|
||||
}
|
||||
|
||||
fn native_role_result(
|
||||
runtime_store: &Path,
|
||||
job_id: Option<&str>,
|
||||
role_id: EpiphanyRoleResultRoleId,
|
||||
) -> Value {
|
||||
let Some(job_id) = job_id else {
|
||||
return json!({"source": "native", "status": "noCurrentWork"});
|
||||
};
|
||||
let snapshot = epiphany_core::read_runtime_role_result(Some(runtime_store), job_id, role_id);
|
||||
let mut result = json!({
|
||||
"source": "native",
|
||||
"status": snapshot.status,
|
||||
"runtimeJobId": job_id,
|
||||
"note": snapshot.note,
|
||||
});
|
||||
if let Some(finding) = snapshot.finding {
|
||||
result["finding"] = json!(finding);
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
fn keyed_reorientation_recommendation(
|
||||
work: Option<&epiphany_core::EpiphanyReorientationWorkProjection>,
|
||||
accepted: Option<&epiphany_core::EpiphanyMindReorientationDecisionDocument>,
|
||||
should_prepare_compaction: bool,
|
||||
) -> EpiphanyCrrcRecommendation {
|
||||
let build = |action, reason: &str| EpiphanyCrrcRecommendation {
|
||||
action,
|
||||
reason: reason.into(),
|
||||
};
|
||||
if let Some(work) = work {
|
||||
return match work.attempt.action {
|
||||
EpiphanyAgentPassContinuationAction::Launch => build(
|
||||
EpiphanyCrrcAction::LaunchReorientWorker,
|
||||
"The exact keyed continuity request has no live attempt.",
|
||||
),
|
||||
EpiphanyAgentPassContinuationAction::Wait => build(
|
||||
EpiphanyCrrcAction::WaitForReorientWorker,
|
||||
"The exact keyed continuity attempt is still live.",
|
||||
),
|
||||
EpiphanyAgentPassContinuationAction::Review => build(
|
||||
EpiphanyCrrcAction::ReviewReorientResult,
|
||||
"The exact keyed continuity result awaits admission.",
|
||||
),
|
||||
};
|
||||
}
|
||||
if should_prepare_compaction {
|
||||
return build(
|
||||
EpiphanyCrrcAction::LaunchReorientWorker,
|
||||
"Context pressure requires a new keyed continuity request.",
|
||||
);
|
||||
}
|
||||
if accepted.is_some_and(|decision| decision.mode == "regather") {
|
||||
return build(
|
||||
EpiphanyCrrcAction::RegatherManually,
|
||||
"The accepted keyed continuity decision requires explicit regather.",
|
||||
);
|
||||
}
|
||||
build(
|
||||
EpiphanyCrrcAction::Continue,
|
||||
"No unresolved keyed reorientation obligation exists.",
|
||||
)
|
||||
}
|
||||
|
||||
fn keyed_reorientation_result(
|
||||
runtime_store: &Path,
|
||||
work: Option<&epiphany_core::EpiphanyReorientationWorkProjection>,
|
||||
accepted: Option<&epiphany_core::EpiphanyMindReorientationDecisionDocument>,
|
||||
) -> Result<Value> {
|
||||
let Some(work) = work else {
|
||||
return Ok(accepted
|
||||
.map(|decision| json!({"status": "accepted", "decision": decision}))
|
||||
.unwrap_or(Value::Null));
|
||||
};
|
||||
let Some(job_id) = work.attempt.job_id.as_deref() else {
|
||||
return Ok(json!({"status": "unlaunched", "requestId": work.request.request_id}));
|
||||
};
|
||||
let snapshot = runtime_job_snapshot(runtime_store, job_id)?
|
||||
.ok_or_else(|| anyhow!("keyed reorientation work lost its runtime job"))?;
|
||||
Ok(json!({
|
||||
"status": format!("{:?}", snapshot.job.status).to_ascii_lowercase(),
|
||||
"requestId": work.request.request_id,
|
||||
"jobId": job_id,
|
||||
"result": epiphany_core::runtime_reorient_worker_result(runtime_store, job_id)?,
|
||||
}))
|
||||
}
|
||||
|
||||
fn native_tool_invocation_surface(runtime_store: &Path) -> Result<Value> {
|
||||
let spine_status = epiphany_core::runtime_spine_status(runtime_store)?;
|
||||
Ok(json!({
|
||||
"source": "native",
|
||||
"runtimeStore": runtime_store.display().to_string(),
|
||||
"summary": {
|
||||
"present": spine_status.present,
|
||||
"intentCount": spine_status.tool_invocation_intents,
|
||||
"pendingCount": spine_status.pending_tool_invocations,
|
||||
"receiptCount": spine_status.tool_invocation_receipts,
|
||||
},
|
||||
"invocations": epiphany_core::runtime_tool_invocation_statuses(runtime_store)?,
|
||||
}))
|
||||
}
|
||||
|
||||
pub fn render_status(status: &Value) -> String {
|
||||
let read = &status["read"];
|
||||
let coordinator = &status["coordinator"];
|
||||
|
|
|
|||
|
|
@ -655,12 +655,7 @@ pub use surfaces::EpiphanyCoordinatorInput;
|
|||
pub use surfaces::EpiphanyCoordinatorRoleResultStatus;
|
||||
pub use surfaces::EpiphanyCoordinatorRoleStatus;
|
||||
pub use surfaces::EpiphanyCrrcAction;
|
||||
pub use surfaces::EpiphanyCrrcRecommendation;
|
||||
pub use surfaces::EpiphanyCrrcResultStatus;
|
||||
pub use surfaces::EpiphanyPressure;
|
||||
pub use surfaces::EpiphanyPressureBasis;
|
||||
pub use surfaces::EpiphanyPressureLevel;
|
||||
pub use surfaces::EpiphanyPressureStatus;
|
||||
pub use surfaces::EpiphanyReorientAction;
|
||||
pub use surfaces::EpiphanyReorientFindingInterpretation;
|
||||
pub use surfaces::EpiphanyReorientWorkerLaunchDocument;
|
||||
|
|
@ -670,7 +665,6 @@ pub use surfaces::EpiphanyRoleBoardLane;
|
|||
pub use surfaces::EpiphanyRoleFindingInterpretation;
|
||||
pub use surfaces::EpiphanyRoleResultRoleId;
|
||||
pub use surfaces::EpiphanyRoleWorkerLaunchDocument;
|
||||
pub use surfaces::EpiphanyTokenUsageSnapshot;
|
||||
pub use surfaces::EpiphanyWorkerLaunchDocument;
|
||||
pub use surfaces::ImaginationConsiderationContextProjection;
|
||||
pub use surfaces::REORIENT_WORKER_OUTPUT_CONTRACT_ID;
|
||||
|
|
@ -690,7 +684,6 @@ pub use surfaces::RepoFrontierPlanningContextProjection;
|
|||
pub use surfaces::RepoFrontierProposalModelingContextProjection;
|
||||
pub use surfaces::RepoFrontierResearchContextProjection;
|
||||
pub use surfaces::RepoFrontierVerificationContextProjection;
|
||||
pub use surfaces::derive_pressure_view;
|
||||
pub use surfaces::derive_role_board;
|
||||
pub use surfaces::interpret_runtime_reorient_worker_result;
|
||||
pub use surfaces::interpret_runtime_role_worker_result;
|
||||
|
|
|
|||
|
|
@ -995,7 +995,6 @@ pub(crate) fn resident_self_current_work_action(
|
|||
let projection_digest = current_work.projection_digest()?;
|
||||
let decision = crate::recommend_coordinator_action(crate::EpiphanyCoordinatorInput {
|
||||
mind_present: true,
|
||||
should_prepare_compaction: false,
|
||||
crrc_action: crate::EpiphanyCrrcAction::Continue,
|
||||
current_work,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -30,7 +30,6 @@ pub enum EpiphanyCoordinatorRoleResultStatus {
|
|||
#[serde(rename_all = "camelCase")]
|
||||
pub enum EpiphanyCoordinatorAction {
|
||||
PrepareCheckpoint,
|
||||
CompactRehydrateReorient,
|
||||
LaunchReorientWorker,
|
||||
WaitForReorientWorker,
|
||||
ReviewReorientResult,
|
||||
|
|
@ -61,7 +60,6 @@ pub enum EpiphanyCoordinatorAction {
|
|||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct EpiphanyCoordinatorInput {
|
||||
pub mind_present: bool,
|
||||
pub should_prepare_compaction: bool,
|
||||
pub crrc_action: EpiphanyCrrcAction,
|
||||
pub current_work: EpiphanyCurrentWorkProjection,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,13 +24,6 @@ pub fn recommend_coordinator_action(
|
|||
);
|
||||
}
|
||||
|
||||
if input.should_prepare_compaction {
|
||||
return decision(
|
||||
EpiphanyCoordinatorAction::CompactRehydrateReorient,
|
||||
"Context pressure requires a new continuity obligation over the current keyed Mind.",
|
||||
);
|
||||
}
|
||||
|
||||
if input.crrc_action == EpiphanyCrrcAction::RegatherManually {
|
||||
return decision(
|
||||
EpiphanyCoordinatorAction::RegatherManually,
|
||||
|
|
|
|||
|
|
@ -19,17 +19,9 @@ pub enum EpiphanyCrrcResultStatus {
|
|||
#[serde(rename_all = "camelCase")]
|
||||
pub enum EpiphanyCrrcAction {
|
||||
Continue,
|
||||
PrepareCheckpoint,
|
||||
LaunchReorientWorker,
|
||||
WaitForReorientWorker,
|
||||
ReviewReorientResult,
|
||||
AcceptReorientResult,
|
||||
RegatherManually,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct EpiphanyCrrcRecommendation {
|
||||
pub action: EpiphanyCrrcAction,
|
||||
pub reason: String,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
mod coordinator_contract;
|
||||
mod coordinator_decision;
|
||||
mod crrc;
|
||||
mod pressure;
|
||||
mod reorient;
|
||||
mod research_decision;
|
||||
mod role_board;
|
||||
|
|
@ -11,14 +10,7 @@ mod worker_launch;
|
|||
pub use coordinator_contract::*;
|
||||
pub use coordinator_decision::recommend_coordinator_action;
|
||||
pub use crrc::EpiphanyCrrcAction;
|
||||
pub use crrc::EpiphanyCrrcRecommendation;
|
||||
pub use crrc::EpiphanyCrrcResultStatus;
|
||||
pub use pressure::EpiphanyPressure;
|
||||
pub use pressure::EpiphanyPressureBasis;
|
||||
pub use pressure::EpiphanyPressureLevel;
|
||||
pub use pressure::EpiphanyPressureStatus;
|
||||
pub use pressure::EpiphanyTokenUsageSnapshot;
|
||||
pub use pressure::derive_pressure_view;
|
||||
pub use reorient::EpiphanyReorientAction;
|
||||
pub use research_decision::EpiphanyResearchDecision;
|
||||
pub use role_board::EpiphanyRoleBoardInput;
|
||||
|
|
|
|||
|
|
@ -1,243 +0,0 @@
|
|||
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,
|
||||
pub last_turn_tokens: i64,
|
||||
pub model_context_window: Option<i64>,
|
||||
pub model_auto_compact_token_limit: Option<i64>,
|
||||
}
|
||||
|
||||
#[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, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub enum EpiphanyPressureStatus {
|
||||
Unknown,
|
||||
Ready,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub enum EpiphanyPressureLevel {
|
||||
Unknown,
|
||||
Low,
|
||||
Elevated,
|
||||
High,
|
||||
Critical,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub enum EpiphanyPressureBasis {
|
||||
Unknown,
|
||||
AutoCompactLimit,
|
||||
ModelContextWindow,
|
||||
}
|
||||
|
||||
pub fn derive_pressure_view(info: Option<&EpiphanyTokenUsageSnapshot>) -> EpiphanyPressure {
|
||||
let Some(info) = info else {
|
||||
return EpiphanyPressure {
|
||||
status: EpiphanyPressureStatus::Unknown,
|
||||
level: EpiphanyPressureLevel::Unknown,
|
||||
basis: EpiphanyPressureBasis::Unknown,
|
||||
used_tokens: None,
|
||||
model_context_window: None,
|
||||
model_auto_compact_token_limit: None,
|
||||
remaining_tokens: None,
|
||||
ratio_per_mille: None,
|
||||
should_prepare_compaction: false,
|
||||
note: "No token usage telemetry has been recorded for this thread yet.".to_string(),
|
||||
};
|
||||
};
|
||||
|
||||
let used_tokens = info.last_turn_tokens.max(0);
|
||||
if used_tokens == 0 && info.total_tokens > 0 {
|
||||
return EpiphanyPressure {
|
||||
status: EpiphanyPressureStatus::Unknown,
|
||||
level: EpiphanyPressureLevel::Unknown,
|
||||
basis: EpiphanyPressureBasis::Unknown,
|
||||
used_tokens: None,
|
||||
model_context_window: info.model_context_window,
|
||||
model_auto_compact_token_limit: info.model_auto_compact_token_limit,
|
||||
remaining_tokens: None,
|
||||
ratio_per_mille: None,
|
||||
should_prepare_compaction: false,
|
||||
note: "Only cumulative token spend is available; CRRC will not infer current context pressure from that.".to_string(),
|
||||
};
|
||||
}
|
||||
|
||||
let model_context_window = info.model_context_window.filter(|value| *value > 0);
|
||||
let model_auto_compact_token_limit = info
|
||||
.model_auto_compact_token_limit
|
||||
.filter(|value| *value > 0);
|
||||
let (basis, limit) = if let Some(limit) = model_auto_compact_token_limit {
|
||||
(EpiphanyPressureBasis::AutoCompactLimit, Some(limit))
|
||||
} else if let Some(limit) = model_context_window {
|
||||
(EpiphanyPressureBasis::ModelContextWindow, Some(limit))
|
||||
} else {
|
||||
(EpiphanyPressureBasis::Unknown, None)
|
||||
};
|
||||
|
||||
let Some(limit) = limit else {
|
||||
return EpiphanyPressure {
|
||||
status: EpiphanyPressureStatus::Unknown,
|
||||
level: EpiphanyPressureLevel::Unknown,
|
||||
basis,
|
||||
used_tokens: Some(used_tokens),
|
||||
model_context_window: info.model_context_window,
|
||||
model_auto_compact_token_limit: info.model_auto_compact_token_limit,
|
||||
remaining_tokens: None,
|
||||
ratio_per_mille: None,
|
||||
should_prepare_compaction: false,
|
||||
note: "Current context usage is known, but no context window or auto-compact threshold is available."
|
||||
.to_string(),
|
||||
};
|
||||
};
|
||||
|
||||
let ratio_per_mille = ((used_tokens.saturating_mul(1000)) / limit).max(0) as u32;
|
||||
let remaining_tokens = limit.saturating_sub(used_tokens);
|
||||
let level = match ratio_per_mille {
|
||||
ratio if ratio >= EPIPHANY_PRESSURE_CRITICAL_PER_MILLE => EpiphanyPressureLevel::Critical,
|
||||
ratio if ratio >= EPIPHANY_PRESSURE_PREPARE_COMPACTION_PER_MILLE => {
|
||||
EpiphanyPressureLevel::High
|
||||
}
|
||||
ratio if ratio >= EPIPHANY_PRESSURE_ELEVATED_PER_MILLE => EpiphanyPressureLevel::Elevated,
|
||||
_ => EpiphanyPressureLevel::Low,
|
||||
};
|
||||
let should_prepare_compaction =
|
||||
ratio_per_mille >= EPIPHANY_PRESSURE_PREPARE_COMPACTION_PER_MILLE;
|
||||
let note = match basis {
|
||||
EpiphanyPressureBasis::AutoCompactLimit => {
|
||||
"Pressure is derived from current context usage against the model auto-compact token limit.".to_string()
|
||||
}
|
||||
EpiphanyPressureBasis::ModelContextWindow => {
|
||||
"Pressure is derived from current context usage against the model context window because no auto-compact threshold was recorded.".to_string()
|
||||
}
|
||||
EpiphanyPressureBasis::Unknown => {
|
||||
"Current context usage is known, but no usable pressure limit was recorded.".to_string()
|
||||
}
|
||||
};
|
||||
|
||||
EpiphanyPressure {
|
||||
status: EpiphanyPressureStatus::Ready,
|
||||
level,
|
||||
basis,
|
||||
used_tokens: Some(used_tokens),
|
||||
model_context_window: info.model_context_window,
|
||||
model_auto_compact_token_limit: info.model_auto_compact_token_limit,
|
||||
remaining_tokens: Some(remaining_tokens),
|
||||
ratio_per_mille: Some(ratio_per_mille),
|
||||
should_prepare_compaction,
|
||||
note,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn token_usage_info(
|
||||
total_tokens: i64,
|
||||
last_tokens: i64,
|
||||
model_context_window: Option<i64>,
|
||||
model_auto_compact_token_limit: Option<i64>,
|
||||
) -> EpiphanyTokenUsageSnapshot {
|
||||
EpiphanyTokenUsageSnapshot {
|
||||
total_tokens,
|
||||
last_turn_tokens: last_tokens,
|
||||
model_context_window,
|
||||
model_auto_compact_token_limit,
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reports_unknown_without_telemetry() {
|
||||
let pressure = derive_pressure_view(None);
|
||||
|
||||
assert_eq!(pressure.status, EpiphanyPressureStatus::Unknown);
|
||||
assert_eq!(pressure.level, EpiphanyPressureLevel::Unknown);
|
||||
assert_eq!(pressure.basis, EpiphanyPressureBasis::Unknown);
|
||||
assert!(!pressure.should_prepare_compaction);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn prefers_auto_compact_limit() {
|
||||
let info = token_usage_info(1_000, 82, Some(200), Some(100));
|
||||
let pressure = derive_pressure_view(Some(&info));
|
||||
|
||||
assert_eq!(pressure.status, EpiphanyPressureStatus::Ready);
|
||||
assert_eq!(pressure.level, EpiphanyPressureLevel::High);
|
||||
assert_eq!(pressure.basis, EpiphanyPressureBasis::AutoCompactLimit);
|
||||
assert_eq!(pressure.ratio_per_mille, Some(820));
|
||||
assert_eq!(pressure.remaining_tokens, Some(18));
|
||||
assert!(pressure.should_prepare_compaction);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ignores_cumulative_thread_spend() {
|
||||
let info = token_usage_info(310, 70, Some(200), Some(100));
|
||||
let pressure = derive_pressure_view(Some(&info));
|
||||
|
||||
assert_eq!(pressure.status, EpiphanyPressureStatus::Ready);
|
||||
assert_eq!(pressure.level, EpiphanyPressureLevel::Elevated);
|
||||
assert_eq!(pressure.used_tokens, Some(70));
|
||||
assert_eq!(pressure.ratio_per_mille, Some(700));
|
||||
assert!(!pressure.should_prepare_compaction);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn refuses_cumulative_only_telemetry() {
|
||||
let info = token_usage_info(310, 0, Some(200), Some(100));
|
||||
let pressure = derive_pressure_view(Some(&info));
|
||||
|
||||
assert_eq!(pressure.status, EpiphanyPressureStatus::Unknown);
|
||||
assert_eq!(pressure.level, EpiphanyPressureLevel::Unknown);
|
||||
assert_eq!(pressure.ratio_per_mille, None);
|
||||
assert!(!pressure.should_prepare_compaction);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn falls_back_to_context_window() {
|
||||
let info = token_usage_info(1_000, 150, Some(200), None);
|
||||
let pressure = derive_pressure_view(Some(&info));
|
||||
|
||||
assert_eq!(pressure.status, EpiphanyPressureStatus::Ready);
|
||||
assert_eq!(pressure.level, EpiphanyPressureLevel::Elevated);
|
||||
assert_eq!(pressure.basis, EpiphanyPressureBasis::ModelContextWindow);
|
||||
assert_eq!(pressure.ratio_per_mille, Some(750));
|
||||
assert!(!pressure.should_prepare_compaction);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn compaction_prep_starts_at_eighty_percent() {
|
||||
let elevated = token_usage_info(1_000, 79, None, Some(100));
|
||||
let high = token_usage_info(1_000, 80, None, Some(100));
|
||||
|
||||
assert!(!derive_pressure_view(Some(&elevated)).should_prepare_compaction);
|
||||
assert!(derive_pressure_view(Some(&high)).should_prepare_compaction);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"$id": "https://gamecult.dev/epiphany/cultnet/epiphany.surface.pressure.schema.json",
|
||||
"title": "Epiphany pressure",
|
||||
"description": "Read-only context pressure reflection over typed pressure inputs.",
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"properties": {
|
||||
"threadId": {
|
||||
"type": "string"
|
||||
},
|
||||
"source": {
|
||||
"type": "string"
|
||||
},
|
||||
"pressure": {
|
||||
"type": "object",
|
||||
"additionalProperties": true
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"threadId",
|
||||
"source",
|
||||
"pressure"
|
||||
]
|
||||
}
|
||||
|
|
@ -334,17 +334,6 @@
|
|||
"title": "Epiphany graph-query",
|
||||
"path": "epiphany.surface.graph-query.schema.json"
|
||||
},
|
||||
{
|
||||
"schemaId": "https://gamecult.dev/epiphany/cultnet/epiphany.surface.pressure.schema.json",
|
||||
"kind": "document_payload",
|
||||
"wireContracts": [
|
||||
"cultnet.schema.v0"
|
||||
],
|
||||
"schemaVersion": "epiphany.pressure_surface.v0",
|
||||
"documentType": "epiphany.surface.pressure",
|
||||
"title": "Epiphany pressure",
|
||||
"path": "epiphany.surface.pressure.schema.json"
|
||||
},
|
||||
{
|
||||
"schemaId": "https://gamecult.dev/epiphany/cultnet/epiphany.surface.reorient.schema.json",
|
||||
"kind": "document_payload",
|
||||
|
|
|
|||
Reference in a new issue