Attribute command and plugin analytics to the invoking model (#45445)

## Why

Command execution and plugin measurement events lack model and reasoning-effort labels. Attribution needs to reflect the step that invoked the command, even when model settings change before a background process finishes.

## What changed

- Add `model_slug` and `reasoning_effort` to command execution and plugin measurement analytics.
- Capture model context from resolved step settings and carry it through execution, approval, Guardian review, and plugin metrics collection.
- Preserve the first command-start model context when subsequent start notifications arrive.
- Keep the carried context out of serialized protocol items and generated schemas.

## Testing

Extend analytics tests to cover model switches before invocation and during background execution, default reasoning effort, Guardian-denied commands, and repeated start notifications retaining the original model context.

GitOrigin-RevId: af90e1c0d39bab625f2e89786085b61a9b96c0ce
This commit is contained in:
jwang-openai
2026-09-14 15:30:22 +00:00
committed by copyberry
parent b6a5d5bb14
commit 4d8eca1ff3
40 changed files with 355 additions and 43 deletions
+4
View File
@@ -4,6 +4,7 @@ use crate::tools::sandboxing::ToolCtx;
use codex_analytics::PluginMeasurementsInput;
use codex_core_plugins::PluginMetricsSidecar;
use codex_exec_server::Environment;
use codex_protocol::items::ModelInvocationContext;
use codex_utils_path_uri::PathUri;
/// Creates a metrics sidecar for one plugin command.
@@ -34,6 +35,7 @@ pub(crate) async fn finish_and_track_measurements(
exit_code: i32,
session: &Session,
turn: &TurnContext,
model_context: &ModelInvocationContext,
item_id: &str,
) {
let Some(metrics_sidecar) = metrics_sidecar else {
@@ -50,6 +52,8 @@ pub(crate) async fn finish_and_track_measurements(
turn_id: turn.sub_id.clone(),
item_id: item_id.to_string(),
originator: turn.originator.clone(),
model_slug: Some(model_context.model_slug.clone()),
reasoning_effort: model_context.reasoning_effort.clone(),
plugin_id: batch.plugin_id,
execution_id: batch.execution_id,
operation: batch.operation,