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 authored and copyberry committed 2026-09-14 15:30:22 +00:00
1 parent b6a5d5bb14
commit 4d8eca1ff3
40 files changed
+355 -43

No files matched your search

@@ -12,6 +12,7 @@ use codex_extension_api::ExtensionData;
use codex_otel::SessionTelemetry;
use codex_protocol::approvals::GuardianAssessmentAction;
use codex_protocol::approvals::GuardianReviewReason;
use codex_protocol::items::ModelInvocationContext;
use codex_protocol::openai_models::ModelInfo;
use codex_protocol::protocol::GuardianAssessmentDecisionSource;
use codex_protocol::protocol::GuardianAssessmentEvent;
@@ -36,6 +37,7 @@ pub struct ReviewMetadata {
pub reviewed_action: GuardianReviewedAction,
pub action: GuardianAssessmentAction,
pub review_reason: GuardianReviewReason,
pub model_context: ModelInvocationContext,
}
pub struct ReviewReport {
@@ -58,6 +60,7 @@ impl ReviewReport {
);
let started = GuardianAssessmentEvent {
review_reason: Some(metadata.review_reason),
model_context: Some(metadata.model_context),
id: metadata.review_id,
target_item_id: metadata.target_item_id,
plugin_id: metadata.plugin_id,