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
This commit is contained in:
jif
2026-07-10 11:00:12 +00:00
committed by copyberry
parent 707bd3cc18
commit 54c44b9ed4
2 changed files with 11 additions and 5 deletions
+4 -3
View File
@@ -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"],
)
+7 -2
View File
@@ -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);