From 136f75e7b7fca7d327fe0f23368ed5482804ea5f Mon Sep 17 00:00:00 2001 From: "Adam Perry @ OpenAI" Date: Mon, 3 Aug 2026 18:18:47 +0000 Subject: [PATCH] Stabilize network policy event capture in concurrent tests (#36779) ## Why Concurrent tests without a tracing subscriber can cache the network policy callsite as disabled, causing event-capture tests to miss events. ## What changed - Attach the test event collector directly to the captured future. - Rebuild the tracing interest cache before running that future while keeping tracing out of its single-subscriber fast path. GitOrigin-RevId: 20d6160d26f56ad9fd86afd5107cb4313a5fce73 --- codex-rs/network-proxy/src/network_policy.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/codex-rs/network-proxy/src/network_policy.rs b/codex-rs/network-proxy/src/network_policy.rs index 05d9f06944..1a5f180e90 100644 --- a/codex-rs/network-proxy/src/network_policy.rs +++ b/codex-rs/network-proxy/src/network_policy.rs @@ -407,6 +407,7 @@ pub(crate) mod test_support { use tracing::Subscriber; use tracing::field::Field; use tracing::field::Visit; + use tracing::instrument::WithSubscriber; use tracing::span::Attributes; use tracing::span::Record; use tracing::subscriber::Interest; @@ -531,8 +532,15 @@ pub(crate) mod test_support { Fut: Future, { let collector = EventCollector::default(); - let _guard = tracing::subscriber::set_default(collector.clone()); - let output = f().await; + // Keep tracing out of its single-subscriber fast path: concurrent tests + // without a subscriber can otherwise cache this callsite as disabled. + let _interest_dispatch = tracing::Dispatch::new(collector.clone()); + let output = async { + tracing::callsite::rebuild_interest_cache(); + f().await + } + .with_subscriber(collector.clone()) + .await; let events = collector.events(); (output, events) }