mirror of
https://github.com/openai/codex.git
synced 2026-04-24 06:35:50 +00:00
Add active context token counts to compaction analytics
This commit is contained in:
@@ -270,6 +270,8 @@ fn compaction_event_serializes_expected_shape() {
|
||||
mode: CompactionMode::Remote,
|
||||
status: CompactionStatus::Completed,
|
||||
error: None,
|
||||
active_context_tokens_before: 120_000,
|
||||
active_context_tokens_after: 18_000,
|
||||
started_at: 100,
|
||||
completed_at: 106,
|
||||
duration_ms: Some(6543),
|
||||
@@ -289,6 +291,8 @@ fn compaction_event_serializes_expected_shape() {
|
||||
"mode": "remote",
|
||||
"status": "completed",
|
||||
"error": null,
|
||||
"active_context_tokens_before": 120000,
|
||||
"active_context_tokens_after": 18000,
|
||||
"started_at": 100,
|
||||
"completed_at": 106,
|
||||
"duration_ms": 6543
|
||||
@@ -507,6 +511,8 @@ async fn compaction_event_ingests_custom_fact() {
|
||||
mode: CompactionMode::Local,
|
||||
status: CompactionStatus::Failed,
|
||||
error: Some("context limit exceeded".to_string()),
|
||||
active_context_tokens_before: 131_000,
|
||||
active_context_tokens_after: 131_000,
|
||||
started_at: 100,
|
||||
completed_at: 101,
|
||||
duration_ms: Some(1200),
|
||||
|
||||
@@ -132,6 +132,8 @@ pub(crate) struct CodexCompactionEventParams {
|
||||
pub(crate) mode: crate::facts::CompactionMode,
|
||||
pub(crate) status: crate::facts::CompactionStatus,
|
||||
pub(crate) error: Option<String>,
|
||||
pub(crate) active_context_tokens_before: i64,
|
||||
pub(crate) active_context_tokens_after: i64,
|
||||
pub(crate) started_at: u64,
|
||||
pub(crate) completed_at: u64,
|
||||
pub(crate) duration_ms: Option<u64>,
|
||||
@@ -232,6 +234,8 @@ pub(crate) fn codex_compaction_event_params(
|
||||
mode: input.mode,
|
||||
status: input.status,
|
||||
error: input.error,
|
||||
active_context_tokens_before: input.active_context_tokens_before,
|
||||
active_context_tokens_after: input.active_context_tokens_after,
|
||||
started_at: input.started_at,
|
||||
completed_at: input.completed_at,
|
||||
duration_ms: input.duration_ms,
|
||||
|
||||
@@ -95,6 +95,8 @@ pub struct CodexCompactionEvent {
|
||||
pub mode: CompactionMode,
|
||||
pub status: CompactionStatus,
|
||||
pub error: Option<String>,
|
||||
pub active_context_tokens_before: i64,
|
||||
pub active_context_tokens_after: i64,
|
||||
pub started_at: u64,
|
||||
pub completed_at: u64,
|
||||
pub duration_ms: Option<u64>,
|
||||
|
||||
@@ -287,6 +287,7 @@ pub(crate) struct CompactionAnalyticsAttempt {
|
||||
turn_id: String,
|
||||
trigger: CompactionTrigger,
|
||||
mode: CompactionMode,
|
||||
active_context_tokens_before: i64,
|
||||
started_at: u64,
|
||||
start_instant: Instant,
|
||||
}
|
||||
@@ -298,12 +299,19 @@ impl CompactionAnalyticsAttempt {
|
||||
trigger: CompactionTrigger,
|
||||
mode: CompactionMode,
|
||||
) -> Self {
|
||||
let enabled = sess.enabled(Feature::GeneralAnalytics);
|
||||
let active_context_tokens_before = if enabled {
|
||||
sess.get_total_token_usage().await
|
||||
} else {
|
||||
0
|
||||
};
|
||||
Self {
|
||||
enabled: sess.enabled(Feature::GeneralAnalytics),
|
||||
enabled,
|
||||
thread_id: sess.conversation_id.to_string(),
|
||||
turn_id: turn_context.sub_id.clone(),
|
||||
trigger,
|
||||
mode,
|
||||
active_context_tokens_before,
|
||||
started_at: now_unix_seconds(),
|
||||
start_instant: Instant::now(),
|
||||
}
|
||||
@@ -318,6 +326,7 @@ impl CompactionAnalyticsAttempt {
|
||||
if !self.enabled {
|
||||
return;
|
||||
}
|
||||
let active_context_tokens_after = sess.get_total_token_usage().await;
|
||||
sess.services
|
||||
.analytics_events_client
|
||||
.track_compaction(CodexCompactionEvent {
|
||||
@@ -327,6 +336,8 @@ impl CompactionAnalyticsAttempt {
|
||||
mode: self.mode,
|
||||
status,
|
||||
error,
|
||||
active_context_tokens_before: self.active_context_tokens_before,
|
||||
active_context_tokens_after,
|
||||
started_at: self.started_at,
|
||||
completed_at: now_unix_seconds(),
|
||||
duration_ms: Some(
|
||||
|
||||
Reference in New Issue
Block a user