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
@@ -164,6 +164,7 @@ async fn replayed_commands_preserve_individual_output_and_failure_status() {
let cwd = chat.config.cwd.clone();
let replayed_command =
|id: &str, output: &str, source: ExecCommandSource| AppServerThreadItem::CommandExecution {
model_context: None,
id: id.to_string(),
command: format!("printf {output}"),
cwd: cwd.clone().into(),
@@ -612,6 +613,7 @@ async fn exec_end_without_begin_uses_event_command() {
handle_exec_end(
&mut chat,
AppServerThreadItem::CommandExecution {
model_context: None,
id: "call-orphan".to_string(),
command: codex_shell_command::parse_command::shlex_join(&command),
cwd: cwd.into(),