Track artifact operations from trusted plugin markers (#38057)

## What changed

- Recognize validated create and edit marker commands from the trusted presentations, documents, spreadsheets, and PDF plugins.
- Emit a `codex_artifact_operation` analytics event plus started-count and expected-output-count metrics when a recognized marker starts through unified exec.
- Attribute remote executor commands only when their plugin cache path and script contents match a trusted local plugin, including primary-runtime plugins.

## Testing

- Cover supported marker combinations and reject mismatched plugins, paths, arguments, counts, and output formats.
- Cover local, relocated remote, and Windows-style plugin attribution, including rejection of modified remote scripts.

GitOrigin-RevId: 475cc1689aa7f371a24dec0a8bdb6f7fd5a2e922
This commit is contained in:
edwardysun3 authored and copyberry committed 2026-08-11 19:26:41 +00:00
1 parent 285abc0368
commit 44d992c14e
18 files changed
+971 -60

No files matched your search

@@ -41,12 +41,16 @@ use crate::events::codex_app_metadata;
use crate::events::codex_hook_run_metadata;
use crate::events::codex_plugin_metadata;
use crate::events::codex_plugin_used_metadata;
use crate::events::current_runtime_metadata;
use crate::events::subagent_thread_started_event_request;
use crate::facts::AnalyticsFact;
use crate::facts::AnalyticsJsonRpcError;
use crate::facts::AppInvocation;
use crate::facts::AppMentionedInput;
use crate::facts::AppUsedInput;
use crate::facts::ArtifactOperation;
use crate::facts::ArtifactOperationInput;
use crate::facts::ArtifactOperationLifecycle;
use crate::facts::CodeModeToolCallFact;
use crate::facts::CodeModeToolCallStatus;
use crate::facts::CodexCompactionEvent;
@@ -3745,6 +3749,62 @@ fn plugin_used_dedupe_is_keyed_by_turn_and_plugin() {
assert_eq!(queue.should_enqueue_plugin_used(&turn_2, &plugin), true);
}
#[tokio::test]
async fn reducer_ingests_artifact_operation_fact() {
let mut reducer = AnalyticsReducer::default();
let mut events = Vec::new();
reducer
.ingest(
AnalyticsFact::Custom(CustomAnalyticsFact::ArtifactOperation(
ArtifactOperationInput {
tracking: test_tracking_context("thread-1", "turn-1"),
operation: ArtifactOperation {
item_id: "call-1".to_string(),
lifecycle: ArtifactOperationLifecycle::Started,
occurred_at_ms: 1_786_000_000_000,
plugin_id: "presentations@openai-primary-runtime".to_string(),
script_path: "skills/presentations/container_tools/mark_artifact_operation_started.mjs".to_string(),
skill: "presentations".to_string(),
artifact_type: "presentation".to_string(),
operation_kind: "create".to_string(),
expected_output_count: 2,
output_format: "pptx".to_string(),
execution_backend: "unified_exec".to_string(),
},
},
)),
&mut events,
)
.await;
assert!(events[0].can_send_with_api_key_auth());
assert_eq!(
serde_json::to_value(events).expect("serialize events"),
json!([{
"event_type": "codex_artifact_operation",
"event_params": {
"thread_id": "thread-1",
"turn_id": "turn-1",
"item_id": "call-1",
"lifecycle": "started",
"occurred_at_ms": 1_786_000_000_000_u64,
"product_client_id": TEST_PRODUCT_CLIENT_ID,
"runtime": serde_json::to_value(current_runtime_metadata())
.expect("serialize runtime metadata"),
"model_slug": "gpt-5",
"plugin_id": "presentations@openai-primary-runtime",
"script_path": "skills/presentations/container_tools/mark_artifact_operation_started.mjs",
"skill": "presentations",
"artifact_type": "presentation",
"operation_kind": "create",
"expected_output_count": 2,
"output_format": "pptx",
"execution_backend": "unified_exec"
}
}])
);
}
#[tokio::test]
async fn reducer_ingests_skill_invoked_fact() {
let mut reducer = AnalyticsReducer::default();