mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
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:
1 parent
1f631def3f
commit
a1efb59c4a
12 files changed
+368
-15
No files matched your search
@@ -608,7 +608,10 @@ pub(crate) async fn wait_for_matching_analytics_event(
|
||||
};
|
||||
for request in &requests {
|
||||
if request.method != "POST"
|
||||
|| request.url.path() != "/codex/analytics-events/events"
|
||||
|| !request
|
||||
.url
|
||||
.path()
|
||||
.ends_with("/codex/analytics-events/events")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -31,7 +31,10 @@ use wiremock::matchers::method;
|
||||
use wiremock::matchers::path;
|
||||
use wiremock::matchers::query_param;
|
||||
|
||||
use super::analytics::wait_for_matching_analytics_event;
|
||||
|
||||
const DEFAULT_TIMEOUT: Duration = Duration::from_secs(30);
|
||||
const REMOTE_PLUGIN_ID: &str = "plugins~Plugin_00000000000000000000000000000000";
|
||||
|
||||
#[test_case("WORKSPACE", "workspace-directory"; "workspace")]
|
||||
#[test_case("GLOBAL", "openai-curated-remote"; "global")]
|
||||
@@ -139,6 +142,11 @@ async fn plugin_reconcile_syncs_bundles_and_reports_changes(
|
||||
failed_remote_plugin_ids: failures.clone(),
|
||||
failed_materialization_remote_plugin_ids: failures,
|
||||
};
|
||||
let active_plugin_ids = if enabled {
|
||||
vec![REMOTE_PLUGIN_ID.to_string()]
|
||||
} else {
|
||||
Vec::new()
|
||||
};
|
||||
mount_installed_snapshot(&server, plugins).await;
|
||||
Mock::given(method("GET"))
|
||||
.and(path("/bundle"))
|
||||
@@ -150,7 +158,13 @@ async fn plugin_reconcile_syncs_bundles_and_reports_changes(
|
||||
// A turn exercises the loaded registry, not fresh hooks/list discovery. Hooks run
|
||||
// on the app-server host even when the thread uses a remote executor.
|
||||
assert_eq!(
|
||||
turn_hook_runs(&mut app_server, &server, thread.id.clone()).await?,
|
||||
turn_hook_runs(
|
||||
&mut app_server,
|
||||
&server,
|
||||
thread.id.clone(),
|
||||
active_plugin_ids
|
||||
)
|
||||
.await?,
|
||||
usize::from(scope == "WORKSPACE" && enabled && capabilities.has_hooks),
|
||||
);
|
||||
server.verify().await;
|
||||
@@ -167,7 +181,7 @@ async fn plugin_reconcile_syncs_bundles_and_reports_changes(
|
||||
}
|
||||
);
|
||||
assert_eq!(
|
||||
turn_hook_runs(&mut app_server, &server, thread.id.clone()).await?,
|
||||
turn_hook_runs(&mut app_server, &server, thread.id.clone(), Vec::new()).await?,
|
||||
0
|
||||
);
|
||||
server.verify().await;
|
||||
@@ -196,7 +210,13 @@ async fn turn_hook_runs(
|
||||
app_server: &mut TestAppServer,
|
||||
server: &MockServer,
|
||||
thread_id: String,
|
||||
active_plugin_ids: Vec<String>,
|
||||
) -> Result<usize> {
|
||||
Mock::given(method("POST"))
|
||||
.and(path("/backend-api/codex/analytics-events/events"))
|
||||
.respond_with(ResponseTemplate::new(200))
|
||||
.mount(server)
|
||||
.await;
|
||||
let _response = responses::mount_sse_once(
|
||||
server,
|
||||
responses::sse(vec![
|
||||
@@ -209,7 +229,7 @@ async fn turn_hook_runs(
|
||||
let completed = timeout(
|
||||
DEFAULT_TIMEOUT,
|
||||
app_server.start_turn_and_wait_for_completion(TurnStartParams {
|
||||
thread_id,
|
||||
thread_id: thread_id.clone(),
|
||||
input: vec![UserInput::Text {
|
||||
text: "run hooks".to_string(),
|
||||
text_elements: Vec::new(),
|
||||
@@ -219,6 +239,16 @@ async fn turn_hook_runs(
|
||||
)
|
||||
.await??;
|
||||
assert_eq!(completed.turn.status, TurnStatus::Completed);
|
||||
let event = wait_for_matching_analytics_event(server, DEFAULT_TIMEOUT, |event| {
|
||||
event["event_type"] == "codex_turn_event"
|
||||
&& event["event_params"]["turn_id"] == completed.turn.id
|
||||
})
|
||||
.await?;
|
||||
assert_eq!(event["event_params"]["thread_id"], thread_id);
|
||||
assert_eq!(
|
||||
event["event_params"]["active_plugin_ids_at_turn_start"],
|
||||
json!(active_plugin_ids)
|
||||
);
|
||||
Ok(app_server
|
||||
.pending_notification_methods()
|
||||
.iter()
|
||||
@@ -284,7 +314,7 @@ async fn mount_installed_snapshot(server: &MockServer, plugins: Vec<Value>) {
|
||||
|
||||
fn installed_plugin(version: &str, bundle_url: &str, scope: &str) -> Value {
|
||||
json!({
|
||||
"id": "plugins~Plugin_00000000000000000000000000000000",
|
||||
"id": REMOTE_PLUGIN_ID,
|
||||
"name": "linear",
|
||||
"scope": scope,
|
||||
"discoverability": (scope == "WORKSPACE").then_some("LISTED"),
|
||||
|
||||
@@ -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(())
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user