Skip to content

Commit 914bce6

Browse files
committed
All RPC requests now have a JSON-RPC id field
1 parent ba411d2 commit 914bce6

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

crates/amalthea/src/socket/shell.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -302,16 +302,11 @@ impl Shell {
302302
/// request from the frontend to deliver a message to a backend, often as
303303
/// the request side of a request/response pair.
304304
fn handle_comm_msg(&self, header: JupyterHeader, msg: &CommWireMsg) -> crate::Result<()> {
305-
// If there is a `jsonrpc` field, we treat the presence of `id` as a
306-
// request rather than a notification. If there is no such field, we
307-
// have a regular message from one of the regular Positron client comms.
308-
// In the future we should only support proper JSON-RPC messages, see
305+
// The presence of an `id` field means this is a request, not a notification
309306
// https://github.com/posit-dev/positron/issues/7448
310-
let request = msg.data.get("jsonrpc").is_none() || msg.data.get("id").is_some();
311-
312-
let comm_msg = if request {
313-
// We don't consider the JSON-RPC `id` field which must exactly
314-
// match the one in the Jupyter header
307+
let comm_msg = if msg.data.get("id").is_some() {
308+
// Note that the JSON-RPC `id` field must exactly match the one in
309+
// the Jupyter header
315310
let request_id = header.msg_id.clone();
316311

317312
// Store this message as a pending RPC request so that when the comm

crates/amalthea/tests/client.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ fn test_amalthea_comms() {
155155

156156
let comm_req_id = frontend.send_shell(CommWireMsg {
157157
comm_id: comm_id.to_string(),
158-
data: serde_json::Value::Null,
158+
// Include `id` field to signal this is a request
159+
data: serde_json::json!({ "id": "foo" }),
159160
});
160161

161162
frontend.recv_iopub_busy();

0 commit comments

Comments
 (0)