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 <noreply@openai.com>
This commit is contained in:
starr-openai
2026-05-05 16:32:19 -07:00
parent c72f484068
commit 3ff901257a
3 changed files with 17 additions and 33 deletions

View File

@@ -65,15 +65,11 @@ impl Drop for StdioTransport {
}
}
pub(crate) struct JsonRpcConnectionRuntime {
pub(crate) struct JsonRpcConnection {
pub(crate) outgoing_tx: mpsc::Sender<JSONRPCMessage>,
pub(crate) incoming_rx: mpsc::Receiver<JsonRpcConnectionEvent>,
pub(crate) disconnected_rx: watch::Receiver<bool>,
pub(crate) task_handles: Vec<tokio::task::JoinHandle<()>>,
}
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,
}
}

View File

@@ -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<RpcClientEvent>) {
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::<RequestId, PendingRequest>::new()));

View File

@@ -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) =