feat: add manual and remote_v2 tags to compaction metric (#24608)

## Why
`codex.task.compact` only distinguished `local` vs `remote`, which made
it hard to answer simple counter questions in Statsig. Manual `/compact`
and automatic compaction were collapsed together, and the legacy remote
path was also collapsed with `remote_compaction_v2`.

## What Changed
- route `codex.task.compact` through a shared helper in
`core/src/tasks/mod.rs`
- add a `manual=true|false` tag so manual and automatic compaction can
be counted separately
- split the remote tag into `remote` and `remote_v2`
- emit the metric from the inline auto-compaction path in
`core/src/session/turn.rs` as well as the manual `CompactTask` path in
`core/src/tasks/compact.rs`
- add focused unit coverage for the new tag shapes in
`core/src/tasks/mod_tests.rs`

## Verification
- added unit coverage in `core/src/tasks/mod_tests.rs` covering manual
`remote_v2` tags and automatic `local` tags
This commit is contained in:
jif-oai
2026-05-26 18:47:42 +02:00
committed by GitHub
Unverified
parent f6fd753039
commit 9271e84b79
4 changed files with 88 additions and 9 deletions
+16
View File
@@ -50,6 +50,7 @@ use crate::stream_events_utils::last_assistant_message_from_item;
use crate::stream_events_utils::mark_thread_memory_mode_polluted_if_external_context;
use crate::stream_events_utils::raw_assistant_output_text_from_item;
use crate::stream_events_utils::record_completed_response_item_with_finalized_facts;
use crate::tasks::emit_compact_metric;
use crate::tools::ToolRouter;
use crate::tools::context::SharedTurnDiffTracker;
use crate::tools::parallel::ToolCallRuntime;
@@ -778,6 +779,11 @@ async fn run_auto_compact(
) -> CodexResult<()> {
if should_use_remote_compact_task(turn_context.provider.info()) {
if turn_context.features.enabled(Feature::RemoteCompactionV2) {
emit_compact_metric(
&sess.services.session_telemetry,
"remote_v2",
/*manual*/ false,
);
run_inline_remote_auto_compact_task_v2(
Arc::clone(sess),
Arc::clone(turn_context),
@@ -789,6 +795,11 @@ async fn run_auto_compact(
.await?;
return Ok(());
}
emit_compact_metric(
&sess.services.session_telemetry,
"remote",
/*manual*/ false,
);
run_inline_remote_auto_compact_task(
Arc::clone(sess),
Arc::clone(turn_context),
@@ -798,6 +809,11 @@ async fn run_auto_compact(
)
.await?;
} else {
emit_compact_metric(
&sess.services.session_telemetry,
"local",
/*manual*/ false,
);
run_inline_auto_compact_task(
Arc::clone(sess),
Arc::clone(turn_context),