Classify MCP auth and approval outcomes in analytics (#45716)

## What changed

- Record `auth_or_link` for Codex app calls with trusted connector authentication failure metadata, capturing it before result callbacks or model-facing rewrites. Propagate the classification to MCP tool-call and app-usage analytics.
- Record `approval` when a dispatched approval request is denied, times out, or aborts, covering both MCP elicitation and legacy user-input approvals.

## Testing

Add unit and turn-level coverage for authentication failures, metadata removal by callbacks, successful and rejected approvals, and closed approval response channels. Verify event counts, classification, and exclusion of sensitive test values and authentication URLs from analytics payloads.

GitOrigin-RevId: 493df2a2923f346a0f644f1f26ab8b6b9b8888e0
This commit is contained in:
priyanshusingh-de authored and copyberry committed 2026-09-15 15:03:29 +00:00
1 parent 2fdcdeaf0e
commit 7784318b5f
6 files changed
+618 -120

No files matched your search

+12 -1
View File
@@ -13,6 +13,7 @@ use std::time::Duration;
use anyhow::Context;
use anyhow::Result;
use anyhow::anyhow;
use codex_analytics::AnalyticsEventsClient;
use codex_attachment_store::AttachmentStore;
use codex_config::CloudConfigBundleLoader;
use codex_core::CodexThread;
@@ -329,6 +330,7 @@ pub fn turn_permission_fields(
pub struct TestCodexBuilder {
config_mutators: Vec<Box<ConfigMutator>>,
auth: CodexAuth,
analytics_events_client: Option<AnalyticsEventsClient>,
pre_build_hooks: Vec<Box<PreBuildHook>>,
workspace_setups: Vec<Box<WorkspaceSetup>>,
home: Option<Arc<TempDir>>,
@@ -365,6 +367,14 @@ impl TestCodexBuilder {
self
}
pub fn with_analytics_events_client(
mut self,
analytics_events_client: AnalyticsEventsClient,
) -> Self {
self.analytics_events_client = Some(analytics_events_client);
self
}
pub fn with_models_manager(mut self, models_manager: SharedModelsManager) -> Self {
self.models_manager = Some(models_manager);
self
@@ -742,7 +752,7 @@ impl TestCodexBuilder {
Arc::clone(&environment_manager),
Arc::new(extensions.build()),
user_instructions_provider,
/*analytics_events_client*/ None,
self.analytics_events_client.clone(),
Arc::clone(&self.image_store),
Arc::clone(&thread_store),
codex_core::local_agent_graph_store_from_state_db(state_db.as_ref()),
@@ -1393,6 +1403,7 @@ pub fn test_codex() -> TestCodexBuilder {
.expect("test config should allow ShellSnapshot override");
})],
auth: CodexAuth::from_api_key("dummy"),
analytics_events_client: None,
pre_build_hooks: vec![],
workspace_setups: vec![],
home: None,