mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Honor thread analytics opt-outs when using shared clients (#44646)
## Why An enabled shared analytics client could override a thread's explicit opt-out. Delegated threads also emitted initialization events through the parent's client, bypassing the child's analytics setting. ## What changed - Use a disabled analytics client when `config.analytics_enabled` is `Some(false)`, without disabling analytics for sibling threads or overriding a disabled host client. - Emit delegated thread initialization events through the child's analytics client. - Expose the effective analytics state through `CodexThread::analytics_enabled()`. ## Testing Add regression tests for explicit and unset thread settings with enabled, disabled, and absent shared clients, plus delegated child opt-outs with an enabled parent. Update compaction and rollout-budget rollback tests to wait for thread idle after turn completion and fail immediately on rollback errors. GitOrigin-RevId: 547852909af1a6822b95c0bcd2336b0d6bc7aad1
This commit is contained in:
1 parent
e25bedc166
commit
60825b4988
8 files changed
+295
-19
No files matched your search
@@ -217,6 +217,86 @@ async fn run_codex_thread_interactive_respects_pre_cancelled_spawn() {
|
||||
));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn delegate_start_analytics_honors_child_opt_out_with_enabled_parent() {
|
||||
use codex_analytics::AnalyticsEventsClient;
|
||||
use codex_login::CodexAuth;
|
||||
use wiremock::Mock;
|
||||
use wiremock::MockServer;
|
||||
use wiremock::ResponseTemplate;
|
||||
use wiremock::matchers::path;
|
||||
|
||||
let server = MockServer::start().await;
|
||||
Mock::given(path("/codex/analytics-events/events"))
|
||||
.respond_with(ResponseTemplate::new(200))
|
||||
.mount(&server)
|
||||
.await;
|
||||
let client = AnalyticsEventsClient::new(
|
||||
AuthManager::from_auth_for_testing(CodexAuth::create_dummy_chatgpt_auth_for_testing()),
|
||||
server.uri(),
|
||||
/*analytics_enabled*/ Some(true),
|
||||
);
|
||||
let (mut parent_session, parent_ctx, _rx_events) =
|
||||
crate::session::tests::make_session_and_context_with_rx().await;
|
||||
Arc::get_mut(&mut parent_session)
|
||||
.expect("parent session should be uniquely owned")
|
||||
.services
|
||||
.analytics_events_client = client.clone();
|
||||
parent_session
|
||||
.set_app_server_client_info(
|
||||
Some("codex-test".to_string()),
|
||||
Some("1.0.0".to_string()),
|
||||
/*mcp_elicitations_auto_deny*/ false,
|
||||
)
|
||||
.await
|
||||
.expect("set parent client metadata");
|
||||
|
||||
let mut expected_events = Vec::new();
|
||||
for analytics_enabled in [false, true] {
|
||||
let mut config = parent_ctx.config.as_ref().clone();
|
||||
config.permissions.approval_policy = Constrained::allow_only(AskForApproval::Never);
|
||||
config.analytics_enabled = Some(analytics_enabled);
|
||||
let (session, io) = run_codex_thread_interactive(
|
||||
config,
|
||||
Arc::clone(&parent_session.services.auth_manager),
|
||||
Arc::clone(&parent_session.services.models_manager),
|
||||
Arc::clone(&parent_session),
|
||||
Arc::clone(&parent_ctx),
|
||||
parent_ctx.environments.clone(),
|
||||
CancellationToken::new(),
|
||||
SubAgentSource::Review,
|
||||
codex_extension_api::SessionIsolation::Inherit,
|
||||
/*initial_history*/ None,
|
||||
crate::session::GitEnrichmentPolicy::Fresh,
|
||||
codex_sandboxing::WindowsSandboxProxySettingsMode::Reconcile,
|
||||
)
|
||||
.await
|
||||
.expect("delegate session should start");
|
||||
if analytics_enabled {
|
||||
expected_events.push(serde_json::json!([
|
||||
"codex_thread_initialized",
|
||||
session.thread_id().to_string(),
|
||||
]));
|
||||
}
|
||||
io.shutdown_and_wait()
|
||||
.await
|
||||
.expect("delegate session should shut down");
|
||||
}
|
||||
client.flush().await;
|
||||
let events = server
|
||||
.received_requests()
|
||||
.await
|
||||
.expect("analytics requests")
|
||||
.into_iter()
|
||||
.flat_map(|request| {
|
||||
let payload: Value = serde_json::from_slice(&request.body).expect("analytics payload");
|
||||
payload["events"].as_array().expect("events array").clone()
|
||||
})
|
||||
.map(|event| serde_json::json!([event["event_type"], event["event_params"]["thread_id"]]))
|
||||
.collect::<Vec<_>>();
|
||||
assert_eq!(events, expected_events);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn delegate_isolation_does_not_depend_on_attribution() {
|
||||
let (mut parent_session, parent_ctx, _rx_events) =
|
||||
|
||||
Reference in new issue
Block a user