mirror of
https://github.com/openai/codex.git
synced 2026-08-27 13:49:27 +00:00
## Why Sequential dispatch lets a long-running request block unrelated health checks and cleanup on the same connection. ## What changed - Add `--concurrent-requests <COUNT>` for local and remote exec-server connections, while retaining sequential dispatch when the option is omitted or set to `1`. - Preserve handshake ordering before enabling concurrent dispatch. - Reserve separate capacity for status, signal, terminate, and close requests so they remain responsive when ordinary request capacity is saturated. - Drain queued client responses during disconnect and cancel outstanding request tasks during connection shutdown. ## Testing - Cover CLI parsing and concurrency-limit validation. - Verify default sequential behavior, pipelined handshake ordering, concurrent request progress, control-request responsiveness, and disconnect handling. GitOrigin-RevId: 48e4b092e318204ed635543f01f9ee0e7df095fc
108 lines
3.3 KiB
Rust
108 lines
3.3 KiB
Rust
mod file_system_handler;
|
|
mod handler;
|
|
mod process_handler;
|
|
mod processor;
|
|
mod registry;
|
|
mod request_dispatcher;
|
|
mod session_registry;
|
|
mod transport;
|
|
|
|
pub(crate) use handler::ExecServerHandler;
|
|
pub(crate) use processor::ConnectionProcessor;
|
|
pub use request_dispatcher::ConcurrentRequestLimit;
|
|
pub use request_dispatcher::RequestDispatchMode;
|
|
pub use transport::DEFAULT_LISTEN_URL;
|
|
pub use transport::ExecServerListenUrlParseError;
|
|
|
|
use crate::ExecServerRuntimePaths;
|
|
use crate::ExecServerTelemetry;
|
|
use codex_http_client::HttpClientFactory;
|
|
|
|
pub async fn run_main(
|
|
listen_url: &str,
|
|
runtime_paths: ExecServerRuntimePaths,
|
|
http_client_factory: HttpClientFactory,
|
|
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
|
run_main_with_telemetry(
|
|
listen_url,
|
|
runtime_paths,
|
|
ExecServerTelemetry::default(),
|
|
http_client_factory,
|
|
RequestDispatchMode::Inline,
|
|
)
|
|
.await
|
|
}
|
|
|
|
#[tracing::instrument(
|
|
name = "codex.exec_server",
|
|
skip_all,
|
|
fields(otel.kind = "internal")
|
|
)]
|
|
pub async fn run_main_with_telemetry(
|
|
listen_url: &str,
|
|
runtime_paths: ExecServerRuntimePaths,
|
|
telemetry: ExecServerTelemetry,
|
|
http_client_factory: HttpClientFactory,
|
|
request_dispatch_mode: RequestDispatchMode,
|
|
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
|
transport::run_transport(
|
|
listen_url,
|
|
runtime_paths,
|
|
telemetry,
|
|
http_client_factory,
|
|
request_dispatch_mode,
|
|
)
|
|
.await
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use codex_http_client::HttpClientFactory;
|
|
use codex_http_client::OutboundProxyPolicy;
|
|
use opentelemetry::trace::TracerProvider as _;
|
|
use opentelemetry_sdk::trace::InMemorySpanExporter;
|
|
use opentelemetry_sdk::trace::SdkTracerProvider;
|
|
use tracing::instrument::WithSubscriber;
|
|
use tracing_subscriber::prelude::*;
|
|
|
|
use super::run_main_with_telemetry;
|
|
use crate::ExecServerRuntimePaths;
|
|
use crate::ExecServerTelemetry;
|
|
|
|
#[tokio::test]
|
|
async fn telemetry_entrypoint_emits_root_span() {
|
|
let exporter = InMemorySpanExporter::default();
|
|
let provider = SdkTracerProvider::builder()
|
|
.with_simple_exporter(exporter.clone())
|
|
.build();
|
|
let subscriber = tracing_subscriber::registry()
|
|
.with(tracing_opentelemetry::layer().with_tracer(provider.tracer("exec-server-test")));
|
|
|
|
async {
|
|
tracing::callsite::rebuild_interest_cache();
|
|
run_main_with_telemetry(
|
|
"invalid",
|
|
ExecServerRuntimePaths::new(
|
|
std::env::current_exe().expect("current executable"),
|
|
/*codex_linux_sandbox_exe*/ None,
|
|
)
|
|
.expect("runtime paths"),
|
|
ExecServerTelemetry::default(),
|
|
HttpClientFactory::new(OutboundProxyPolicy::ReqwestDefault),
|
|
super::RequestDispatchMode::Inline,
|
|
)
|
|
.await
|
|
.expect_err("invalid listen URL should fail");
|
|
}
|
|
.with_subscriber(subscriber)
|
|
.await;
|
|
|
|
provider.force_flush().expect("flush traces");
|
|
let spans = exporter.get_finished_spans().expect("span export");
|
|
assert!(
|
|
spans.iter().any(|span| span.name == "codex.exec_server"),
|
|
"root exec-server span missing: {spans:?}"
|
|
);
|
|
}
|
|
}
|