mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
[codex-analytics] report compaction analytics details (#26680)
## Why Compaction analytics adds retained image count and compaction summary output tokens for v1.5 specifically. ## What changed - Add nullable `retained_image_count` and `compaction_summary_tokens` fields to `codex_compaction_event`. - Populate them only for `responses_compaction_v2`: retained images come from the retained v2 compacted history, and summary tokens come from `response.completed.token_usage.output_tokens`. - Leave local and legacy remote compaction events as `null` for these detail fields. ## Verification - `just fmt` - `just fix -p codex-core` - `just test -p codex-core build_v2_compacted_history_counts_retained_input_images` - `git diff --check`
This commit is contained in:
committed by
GitHub
Unverified
parent
a815311466
commit
f1c18df9ae
@@ -150,7 +150,7 @@ async fn run_compact_task_inner(
|
||||
sess.as_ref(),
|
||||
CompactionStatus::Interrupted,
|
||||
Some(error),
|
||||
/*active_context_tokens_before*/ None,
|
||||
CompactionAnalyticsDetails::default(),
|
||||
)
|
||||
.await;
|
||||
return Err(CodexErr::TurnAborted);
|
||||
@@ -174,7 +174,7 @@ async fn run_compact_task_inner(
|
||||
sess.as_ref(),
|
||||
status,
|
||||
error,
|
||||
/*active_context_tokens_before*/ None,
|
||||
CompactionAnalyticsDetails::default(),
|
||||
)
|
||||
.await;
|
||||
return Err(CodexErr::TurnAborted);
|
||||
@@ -185,7 +185,7 @@ async fn run_compact_task_inner(
|
||||
sess.as_ref(),
|
||||
status,
|
||||
error,
|
||||
/*active_context_tokens_before*/ None,
|
||||
CompactionAnalyticsDetails::default(),
|
||||
)
|
||||
.await;
|
||||
result.map(|_| ())
|
||||
@@ -335,6 +335,13 @@ pub(crate) struct CompactionAnalyticsAttempt {
|
||||
start_instant: Instant,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Default)]
|
||||
pub(crate) struct CompactionAnalyticsDetails {
|
||||
pub(crate) active_context_tokens_before: Option<i64>,
|
||||
pub(crate) retained_image_count: Option<usize>,
|
||||
pub(crate) compaction_summary_tokens: Option<i64>,
|
||||
}
|
||||
|
||||
impl CompactionAnalyticsAttempt {
|
||||
pub(crate) async fn begin(
|
||||
sess: &Session,
|
||||
@@ -363,8 +370,13 @@ impl CompactionAnalyticsAttempt {
|
||||
sess: &Session,
|
||||
status: CompactionStatus,
|
||||
error: Option<String>,
|
||||
active_context_tokens_before: Option<i64>,
|
||||
details: CompactionAnalyticsDetails,
|
||||
) {
|
||||
let CompactionAnalyticsDetails {
|
||||
active_context_tokens_before,
|
||||
retained_image_count,
|
||||
compaction_summary_tokens,
|
||||
} = details;
|
||||
let active_context_tokens_before =
|
||||
active_context_tokens_before.unwrap_or(self.active_context_tokens_before);
|
||||
let active_context_tokens_after = sess.get_total_token_usage().await;
|
||||
@@ -382,6 +394,8 @@ impl CompactionAnalyticsAttempt {
|
||||
error,
|
||||
active_context_tokens_before,
|
||||
active_context_tokens_after,
|
||||
retained_image_count,
|
||||
compaction_summary_tokens,
|
||||
started_at: self.started_at,
|
||||
completed_at: now_unix_seconds(),
|
||||
duration_ms: Some(
|
||||
|
||||
Reference in New Issue
Block a user