From 3ff901257ad75b30ebe248fcd5614882b52312ff Mon Sep 17 00:00:00 2001 From: starr-openai Date: Tue, 5 May 2026 16:32:19 -0700 Subject: [PATCH] Flatten JSON-RPC connection state Drop the separate JsonRpcConnectionRuntime wrapper so JsonRpcConnection directly owns the channels, disconnect watch, transport tasks, and transport guard. This keeps the lifetime model explicit without helper extraction methods. Co-authored-by: Codex --- codex-rs/exec-server/src/connection.rs | 26 +++++++------------- codex-rs/exec-server/src/rpc.rs | 12 +++------ codex-rs/exec-server/src/server/processor.rs | 12 +++------ 3 files changed, 17 insertions(+), 33 deletions(-) diff --git a/codex-rs/exec-server/src/connection.rs b/codex-rs/exec-server/src/connection.rs index bb92791138..2c0d7ee6d2 100644 --- a/codex-rs/exec-server/src/connection.rs +++ b/codex-rs/exec-server/src/connection.rs @@ -65,15 +65,11 @@ impl Drop for StdioTransport { } } -pub(crate) struct JsonRpcConnectionRuntime { +pub(crate) struct JsonRpcConnection { pub(crate) outgoing_tx: mpsc::Sender, pub(crate) incoming_rx: mpsc::Receiver, pub(crate) disconnected_rx: watch::Receiver, pub(crate) task_handles: Vec>, -} - -pub(crate) struct JsonRpcConnection { - pub(crate) runtime: JsonRpcConnectionRuntime, pub(crate) transport: JsonRpcTransport, } @@ -161,12 +157,10 @@ impl JsonRpcConnection { }); Self { - runtime: JsonRpcConnectionRuntime { - outgoing_tx, - incoming_rx, - disconnected_rx, - task_handles: vec![reader_task, writer_task], - }, + outgoing_tx, + incoming_rx, + disconnected_rx, + task_handles: vec![reader_task, writer_task], transport: JsonRpcTransport::Plain, } } @@ -298,12 +292,10 @@ impl JsonRpcConnection { }); Self { - runtime: JsonRpcConnectionRuntime { - outgoing_tx, - incoming_rx, - disconnected_rx, - task_handles: vec![reader_task, writer_task], - }, + outgoing_tx, + incoming_rx, + disconnected_rx, + task_handles: vec![reader_task, writer_task], transport: JsonRpcTransport::Plain, } } diff --git a/codex-rs/exec-server/src/rpc.rs b/codex-rs/exec-server/src/rpc.rs index c90fef2ab9..3e99976be8 100644 --- a/codex-rs/exec-server/src/rpc.rs +++ b/codex-rs/exec-server/src/rpc.rs @@ -23,7 +23,6 @@ use tokio::task::JoinHandle; use crate::connection::JsonRpcConnection; use crate::connection::JsonRpcConnectionEvent; -use crate::connection::JsonRpcConnectionRuntime; use crate::connection::JsonRpcTransport; #[derive(Debug)] @@ -234,13 +233,10 @@ pub(crate) struct RpcClient { impl RpcClient { pub(crate) fn new(connection: JsonRpcConnection) -> (Self, mpsc::Receiver) { let JsonRpcConnection { - runtime: - JsonRpcConnectionRuntime { - outgoing_tx: write_tx, - incoming_rx: mut incoming_rx, - disconnected_rx: _, - task_handles: transport_tasks, - }, + outgoing_tx: write_tx, + incoming_rx: mut incoming_rx, + disconnected_rx: _, + task_handles: transport_tasks, transport, } = connection; let pending = Arc::new(Mutex::new(HashMap::::new())); diff --git a/codex-rs/exec-server/src/server/processor.rs b/codex-rs/exec-server/src/server/processor.rs index a880e35fe9..5382512be3 100644 --- a/codex-rs/exec-server/src/server/processor.rs +++ b/codex-rs/exec-server/src/server/processor.rs @@ -8,7 +8,6 @@ use crate::ExecServerRuntimePaths; use crate::connection::CHANNEL_CAPACITY; use crate::connection::JsonRpcConnection; use crate::connection::JsonRpcConnectionEvent; -use crate::connection::JsonRpcConnectionRuntime; use crate::rpc::RpcNotificationSender; use crate::rpc::RpcServerOutboundMessage; use crate::rpc::encode_server_message; @@ -49,13 +48,10 @@ async fn run_connection( ) { let router = Arc::new(build_router()); let JsonRpcConnection { - runtime: - JsonRpcConnectionRuntime { - outgoing_tx: json_outgoing_tx, - incoming_rx: mut incoming_rx, - disconnected_rx: mut disconnected_rx, - task_handles: connection_tasks, - }, + outgoing_tx: json_outgoing_tx, + incoming_rx: mut incoming_rx, + disconnected_rx: mut disconnected_rx, + task_handles: connection_tasks, transport: _transport, } = connection; let (outgoing_tx, mut outgoing_rx) =