From 54c44b9ed4c7d6d1ec9bf7897bb76f6411d8e033 Mon Sep 17 00:00:00 2001 From: jif Date: Fri, 10 Jul 2026 10:55:31 +0000 Subject: [PATCH] Propagate tracing subscribers to exec start tasks (#32135) ## Why The process-start background task can move to a Tokio worker thread, where the caller's thread-local tracing subscriber is otherwise unavailable. This can break propagation of the caller's trace context to the exec-server request. ## What changed - Attach both the current span and current tracing subscriber to spawned process-start tasks. - Run exec-server Bazel unit tests serially because their tracing setup uses process-global state. ## Testing Run the trace-context regression test on a multi-thread Tokio runtime so it exercises propagation across the background task. GitOrigin-RevId: a586eefd6983916d670fc5a90f0decd0468d273b --- codex-rs/exec-server/BUILD.bazel | 7 ++++--- codex-rs/exec-server/src/client.rs | 9 +++++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/codex-rs/exec-server/BUILD.bazel b/codex-rs/exec-server/BUILD.bazel index e3c5c05b93..edd3380811 100644 --- a/codex-rs/exec-server/BUILD.bazel +++ b/codex-rs/exec-server/BUILD.bazel @@ -14,9 +14,10 @@ codex_rust_crate( integration_compile_data_extra = [ "src/proto/codex.exec_server.relay.v1.rs", ], - # Keep the crate's integration tests single-threaded under Bazel because - # they install process-global test-binary dispatch state, and the remote - # exec-server cases already rely on serialization around the full CLI path. + # Keep the crate's tests single-threaded under Bazel because they install + # process-global test-binary dispatch state, and the remote exec-server + # cases already rely on serialization around the full CLI path. integration_test_args = ["--test-threads=1"], test_tags = ["no-sandbox"], + unit_test_args = ["--test-threads=1"], ) diff --git a/codex-rs/exec-server/src/client.rs b/codex-rs/exec-server/src/client.rs index 6b8e22b7b2..ae601c5dda 100644 --- a/codex-rs/exec-server/src/client.rs +++ b/codex-rs/exec-server/src/client.rs @@ -23,6 +23,7 @@ use tokio_util::task::AbortOnDropHandle; use tokio::time::timeout; use tracing::Instrument; use tracing::debug; +use tracing::instrument::WithSubscriber; use crate::ProcessId; use crate::client::http_client::response_body_stream::MAX_QUEUED_HTTP_BODY_BYTES; @@ -781,7 +782,11 @@ impl ExecServerClient { } } }; - tokio::spawn(process_start_task.in_current_span()); + tokio::spawn( + process_start_task + .in_current_span() + .with_current_subscriber(), + ); return result_rx.await.map_err(|_| { ExecServerError::Protocol("process start task stopped unexpectedly".to_string()) })?; @@ -1479,7 +1484,7 @@ mod tests { .expect("json-rpc line should write"); } - #[tokio::test(flavor = "current_thread")] + #[tokio::test(flavor = "multi_thread", worker_threads = 1)] async fn process_start_propagates_caller_trace_context_across_background_task() { let (client_stdin, server_reader) = duplex(1 << 20); let (mut server_writer, client_stdout) = duplex(1 << 20);