Record active plugin inventory in turn analytics (#46323)

## What changed

Add `active_plugin_ids_at_turn_start` to turn analytics, combining active host plugins with selected plugin packages. Prefer remote plugin IDs when present and otherwise use validated package IDs. Sort and deduplicate the inventory.

Report `null` for unknown inventories, invalid IDs, IDs longer than 128 bytes, or inventories exceeding 512 distinct IDs; preserve `[]` for an observed empty inventory. Keep the first received inventory even when later resolved configuration updates arrive.

## Testing

Add coverage for ID selection and validation, deduplication, size limits, serialization, and preservation of the first inventory. Extend app-server tests to check inventories after plugin reconciliation and with selected plugins, including turns without explicit plugin mentions.

GitOrigin-RevId: 8a0de912e2570a902cd05bfc918dc8e6ff8b8527
This commit is contained in:
marksteinbrick-oai authored and copyberry committed 2026-09-17 23:47:06 +00:00
1 parent 1f631def3f
commit a1efb59c4a
12 files changed
+368 -15

No files matched your search

@@ -52,6 +52,8 @@ use tokio::process::Child;
use tokio::process::Command;
use tokio::time::timeout;
use super::analytics::mount_analytics_capture;
use super::analytics::wait_for_matching_analytics_event;
use super::app_list::connector_tool;
use super::app_list::start_apps_server_with_delays;
@@ -90,10 +92,8 @@ async fn selected_plugin_mcp_startup_respects_explicit_mentions(
) -> Result<()> {
let explicitly_mentioned = !matches!(mention, PluginMention::Unmentioned);
let responses_server = responses::start_mock_server().await;
let (apps_url, apps_server_handle) =
start_apps_server_with_delays(Vec::new(), Vec::new(), Duration::ZERO, Duration::ZERO)
.await?;
let fixture = selected_capability_fixture(&responses_server.uri(), &apps_url)?;
let fixture = selected_capability_fixture(&responses_server.uri(), &responses_server.uri())?;
mount_analytics_capture(&responses_server, fixture.codex_home.path()).await?;
let config_path = fixture.codex_home.path().join("config.toml");
let config = std::fs::read_to_string(&config_path)?.replace(
"executor_capability_discovery = true",
@@ -139,7 +139,7 @@ async fn selected_plugin_mcp_startup_respects_explicit_mentions(
};
let request_id = app_server
.send_turn_start_request(TurnStartParams {
thread_id,
thread_id: thread_id.clone(),
input: vec![input],
environments: Some(vec![TurnEnvironmentParams {
environment_id: LOCAL_ENVIRONMENT_ID.to_string(),
@@ -149,11 +149,12 @@ async fn selected_plugin_mcp_startup_respects_explicit_mentions(
..Default::default()
})
.await?;
timeout(
let response = timeout(
READ_TIMEOUT,
app_server.read_stream_until_response_message(RequestId::Integer(request_id)),
)
.await??;
let TurnStartResponse { turn } = to_response(response)?;
wait_for_pid_file(&fixture.pid_file).await?;
if explicitly_mentioned {
// An explicit mention must outwait the optional one-second grace.
@@ -180,9 +181,18 @@ async fn selected_plugin_mcp_startup_respects_explicit_mentions(
explicitly_mentioned,
);
let event = wait_for_matching_analytics_event(&responses_server, READ_TIMEOUT, |event| {
event["event_type"] == "codex_turn_event"
&& event["event_params"]["thread_id"] == thread_id
&& event["event_params"]["turn_id"] == turn.id
})
.await?;
assert_eq!(
event["event_params"]["active_plugin_ids_at_turn_start"],
json!([PLUGIN_ID])
);
exec_server.kill().await?;
apps_server_handle.abort();
let _ = apps_server_handle.await;
Ok(())
}