From 4417e5c85917ba9e01714720d9058faa058552f7 Mon Sep 17 00:00:00 2001 From: Andre Sutherland Date: Sun, 16 Aug 2026 12:14:08 +0100 Subject: [PATCH 1/3] fix(lib-rt-core): read what a websocket client actually sent Binary messages are framed as routeLength, route, requireAck, messageIdLength, messageId and then the payload. The runtime never read the acknowledgement byte, so everything after the route came out one place early. A message that asked for no acknowledgement had its message id length byte and its message id handed to the handler as the start of its payload, and one that asked for an acknowledgement was read as having a single character id and a payload beginning part way through the real one. No combination came out right, so no binary message from a client that follows the format was read correctly. The test covering this built its frames the same way the parser read them, which is why it passed. Reading the framing properly also stops two ways a client could take its own connection down, an empty binary frame indexing past the end and a message id that is not valid utf8 being unwrapped. A JSON message's own id is now read from the top level messageId key rather than thrown away and replaced with one the runtime made up. An id the client chose is the one it will hear back in an acknowledgement, and the one a lost message notification has to name for the application to act on it. Both kinds of message can now ask to be acknowledged, and are answered in the encoding they arrived in, so a client with only text because its environment allows nothing else still gets a reply it can read. Opting in without an id is ignored, since an acknowledgement names the message it is for. The reply goes out on receipt rather than on completion, because it says the message arrived, and a handler that runs for a minute should not keep a client waiting that long to hear it. Handlers are told the id in both call modes, over the stream as a new field on the websocket message and over FFI as before, so instrumentation on either side can be tied to what the client sees. The lost message notification was built with a two byte header where the format has four, so clients matching on all four never recognised it and the whole notification went unseen. Its body also left out the caller, which was dropped when a resend rebuilt the send context, so it went missing on the first retry and a lost message is by definition one that has retried. --- libs/runtime/core/src/consts.rs | 7 + .../core/src/generated/celerity.runtime.v1.rs | 9 + libs/runtime/core/src/ipc_frames.rs | 1 + libs/runtime/core/src/ipc_websocket.rs | 4 + libs/runtime/core/src/types.rs | 5 + libs/runtime/core/src/websocket.rs | 163 ++++++++++++++--- .../runtime/core/tests/ipc_end_to_end_test.rs | 171 +++++++++++++++++- .../proto/celerity/runtime/v1/runtime.proto | 8 + libs/runtime/ws/ws-registry/src/acks.rs | 49 +++-- .../ws/ws-registry/src/message_helpers.rs | 22 ++- libs/runtime/ws/ws-registry/src/registry.rs | 40 +++- 11 files changed, 420 insertions(+), 59 deletions(-) diff --git a/libs/runtime/core/src/consts.rs b/libs/runtime/core/src/consts.rs index 17a45ec6..e130bb82 100644 --- a/libs/runtime/core/src/consts.rs +++ b/libs/runtime/core/src/consts.rs @@ -189,6 +189,13 @@ pub const CELERITY_WS_FORBIDDEN_ERROR_CODE: u16 = 4002; // client to fall back to constrained capabilities (text-only). pub const CELERITY_WS_CAPABILITIES_SIGNAL: [u8; 4] = [0x1, 0x5, 0x0, 0x0]; +// The prefix of a binary acknowledgement, route key `0x4`, followed by the JSON +// body naming the message being acknowledged. +// +// A reserved message requires no acknowledgement of its own and carries no +// message id, which is what the two trailing zero bytes say. +pub const CELERITY_WS_ACK_SIGNAL: [u8; 4] = [0x1, 0x4, 0x0, 0x0]; + // The route key for the connect handler for a WebSocket API. // A handler registered with this route key will be called when a client // connects to the WebSocket API server after authentication has been performed diff --git a/libs/runtime/core/src/generated/celerity.runtime.v1.rs b/libs/runtime/core/src/generated/celerity.runtime.v1.rs index e1359b3c..d82cd4fd 100644 --- a/libs/runtime/core/src/generated/celerity.runtime.v1.rs +++ b/libs/runtime/core/src/generated/celerity.runtime.v1.rs @@ -292,6 +292,15 @@ pub struct WebSocketMessage { /// the two frame types as distinct. #[prost(bool, tag = "6")] pub is_binary: bool, + /// The id this message is known by, which is the one the client gave it when + /// it gave one and a runtime generated one otherwise. + /// + /// Distinct from request_id, which identifies the delivery. This identifies + /// the message, so it is what an acknowledgement names and what a lost + /// message notification refers to, and a handler needs it to tie its own + /// instrumentation to what the client sees. + #[prost(string, tag = "7")] + pub message_id: ::prost::alloc::string::String, } #[derive(Clone, PartialEq, ::prost::Message)] pub struct ConsumerBatch { diff --git a/libs/runtime/core/src/ipc_frames.rs b/libs/runtime/core/src/ipc_frames.rs index d23e541a..c7c8aebd 100644 --- a/libs/runtime/core/src/ipc_frames.rs +++ b/libs/runtime/core/src/ipc_frames.rs @@ -115,6 +115,7 @@ fn websocket_message(message: WebSocketEventData) -> proto::WebSocketMessage { request_id: message.request_id.unwrap_or_default(), message: message.message.to_vec(), is_binary: message.is_binary, + message_id: message.message_id.unwrap_or_default(), } } diff --git a/libs/runtime/core/src/ipc_websocket.rs b/libs/runtime/core/src/ipc_websocket.rs index 3b92731c..8b333204 100644 --- a/libs/runtime/core/src/ipc_websocket.rs +++ b/libs/runtime/core/src/ipc_websocket.rs @@ -60,6 +60,7 @@ impl IpcWebSocketHandler { &self, connection_id: String, request_id: Option, + message_id: Option, client_ip: String, message: Bytes, is_binary: bool, @@ -77,6 +78,7 @@ impl IpcWebSocketHandler { connection_id, source_ip: client_ip, request_id, + message_id, message, is_binary, }), @@ -187,6 +189,7 @@ impl WebSocketMessageHandler for IpcWebSocketHandler { .request_ctx .as_ref() .map(|ctx| ctx.request_id.clone()), + Some(message.message_id), message .request_ctx .as_ref() @@ -212,6 +215,7 @@ impl WebSocketMessageHandler for IpcWebSocketHandler { .request_ctx .as_ref() .map(|ctx| ctx.request_id.clone()), + Some(message.message_id), message .request_ctx .as_ref() diff --git a/libs/runtime/core/src/types.rs b/libs/runtime/core/src/types.rs index f7d88e91..a8b1ffe2 100644 --- a/libs/runtime/core/src/types.rs +++ b/libs/runtime/core/src/types.rs @@ -79,6 +79,11 @@ pub struct WebSocketEventData { #[serde(rename = "requestId")] #[serde(skip_serializing_if = "Option::is_none")] pub request_id: Option, + /// The id the client gave this message, as distinct from `request_id`, + /// which the runtime assigns so that every message can be traced. + #[serde(rename = "messageId")] + #[serde(skip_serializing_if = "Option::is_none")] + pub message_id: Option, /// The message exactly as it arrived. pub message: Bytes, /// Whether this arrived as a binary frame rather than a text one. Bytes diff --git a/libs/runtime/core/src/websocket.rs b/libs/runtime/core/src/websocket.rs index 7f594b7a..505cdb83 100644 --- a/libs/runtime/core/src/websocket.rs +++ b/libs/runtime/core/src/websocket.rs @@ -45,7 +45,7 @@ use crate::{ }, auth_jwt::{validate_jwt_on_ws_connect, ValidateJwtError}, consts::{ - CELERITY_WS_CAPABILITIES_SIGNAL, CELERITY_WS_CONNECT_HANDLER_ROUTE, + CELERITY_WS_ACK_SIGNAL, CELERITY_WS_CAPABILITIES_SIGNAL, CELERITY_WS_CONNECT_HANDLER_ROUTE, CELERITY_WS_DEFAULT_MESSAGE_HANDLER_ROUTE, CELERITY_WS_DISCONNECT_HANDLER_ROUTE, CELERITY_WS_FORBIDDEN_ERROR_CODE, CELERITY_WS_UNAUTHORISED_ERROR_CODE, WS_CONNECTION_DRAIN_GRACE_MS, WS_CONNECTION_SATURATED_RETRY_AFTER_MS, @@ -654,9 +654,15 @@ fn spawn_message_worker( ) -> JoinHandle<()> { tokio::spawn(async move { while let Some((message, request_ctx)) = work_rx.recv().await { - if process_message(message, connection_id.clone(), request_ctx, &state) - .await - .is_break() + if process_message( + message, + connection_id.clone(), + request_ctx, + &state, + &socket_ref, + ) + .await + .is_break() { // The connection is finished, and the read loop is waiting on a // socket that may never produce anything again. Closing it is @@ -1026,6 +1032,7 @@ async fn process_message( connection_id: String, request_ctx: WebSocketRequestContext, state: &WebSocketAppState, + socket_ref: &Arc>, ) -> ControlFlow<(), ()> { match msg { Message::Text(text) => { @@ -1034,8 +1041,16 @@ async fn process_message( connection_id.clone(), state.route_key.clone(), )?; - if let Some((route, message_id, data)) = resolved { + if let Some((route, message_id, requires_ack, data)) = resolved { if let Some(handler) = get_message_route_handler(&route, state).await { + acknowledge_if_asked( + socket_ref, + &connection_id, + message_id.as_deref(), + requires_ack, + AckFormat::Json, + ) + .await; handle_json_message( handler.clone(), connection_id.clone(), @@ -1055,8 +1070,16 @@ async fn process_message( } Message::Binary(bytes) => { let resolved = resolve_binary_route(&bytes, connection_id.clone())?; - if let Some((route, message_id, bytes_stripped)) = resolved { + if let Some((route, message_id, requires_ack, bytes_stripped)) = resolved { if let Some(handler) = get_message_route_handler(&route, state).await { + acknowledge_if_asked( + socket_ref, + &connection_id, + message_id.as_deref(), + requires_ack, + AckFormat::Binary, + ) + .await; handle_binary_message( handler.clone(), connection_id.clone(), @@ -1237,7 +1260,62 @@ async fn handle_binary_message( .await; } -type JsonRouteData = (String, Option, Value); +/// Which encoding an acknowledgement goes back in. +/// +/// It mirrors whatever the message being acknowledged arrived as. A client that +/// can send binary can read it, and one that only has text, because its +/// environment gave it no choice, gets text back. +#[derive(Clone, Copy)] +enum AckFormat { + Json, + Binary, +} + +/// Tells the client its message arrived, when the message asked to be told. +/// +/// Opting in without a message id does nothing, since an acknowledgement names +/// the message it is for and there would be nothing to name. +async fn acknowledge_if_asked( + socket_ref: &Arc>, + connection_id: &str, + message_id: Option<&str>, + requires_ack: bool, + format: AckFormat, +) { + if !requires_ack { + return; + } + let Some(message_id) = message_id else { + return; + }; + + let timestamp = get_epoch_seconds().to_string(); + let message = match format { + AckFormat::Json => Message::Text( + serde_json::json!({ + "event": "ack", + "data": { "messageId": message_id, "timestamp": timestamp }, + }) + .to_string() + .into(), + ), + AckFormat::Binary => { + let body = + serde_json::json!({ "messageId": message_id, "timestamp": timestamp }).to_string(); + let mut frame = CELERITY_WS_ACK_SIGNAL.to_vec(); + frame.extend_from_slice(body.as_bytes()); + Message::Binary(frame.into()) + } + }; + + if let Err(err) = socket_ref.lock().await.send(message).await { + error!("failed to acknowledge a message from client {connection_id}: {err}"); + } +} + +/// A JSON message's route, its message id, whether it asked to be acknowledged, +/// and the body as it arrived. +type JsonRouteData = (String, Option, bool, Value); fn resolve_route( msg_text: String, @@ -1264,10 +1342,22 @@ fn resolve_route( return ControlFlow::Continue(None); } }; + // The id the application chose, which is what a lost message notification + // has to name for the application to act on it. The runtime falls back to + // one of its own only when a message carries none. + let message_id = data_obj + .get("messageId") + .and_then(Value::as_str) + .map(str::to_string); + // Opting in without an id is ignored, since an acknowledgement has nothing + // to name. + let requires_ack = + message_id.is_some() && data_obj.get("ack").and_then(Value::as_bool) == Some(true); + let route_opt = data_obj.get(&route_key); if let Some(route_val) = route_opt { if let Value::String(route) = route_val { - ControlFlow::Continue(Some((route.clone(), None, data))) + ControlFlow::Continue(Some((route.clone(), message_id, requires_ack, data))) } else { error!( "invalid JSON message from client {}, expected route value to be a string", @@ -1284,29 +1374,44 @@ fn resolve_route( ); ControlFlow::Continue(Some(( CELERITY_WS_DEFAULT_MESSAGE_HANDLER_ROUTE.to_string(), - None, + message_id, + requires_ack, data, ))) } } -type BinaryRouteData<'a> = (String, Option, &'a [u8]); +/// A binary message's route, its message id, whether it asked to be +/// acknowledged, and the payload left once the framing is stripped. +type BinaryRouteData<'a> = (String, Option, bool, &'a [u8]); +/// Splits a binary message into its framing and its payload. +/// +/// The format is ``. +/// Every length is a single byte, so nothing here can read past a message that +/// carries the bytes it says it does, and a message that does not is refused +/// rather than trusted. fn resolve_binary_route<'a>( msg_bytes: &'a [u8], connection_id: String, ) -> ControlFlow<(), Option>> { - let route_length = msg_bytes[0]; - if route_length as usize > msg_bytes.len() - 1 { + let Some(&route_length) = msg_bytes.first() else { + error!("invalid binary message from client {connection_id}, message is empty"); + return ControlFlow::Continue(None); + }; + let route_end = 1 + route_length as usize; + + // The route is followed by the acknowledgement flag and the message id + // length, so both have to be there for the message to be complete. + if msg_bytes.len() < route_end + 2 { error!( - "invalid binary message from client {}, route length exceeds message length", + "invalid binary message from client {}, message is shorter than its own framing", connection_id ); return ControlFlow::Continue(None); } - let route_result = std::str::from_utf8(&msg_bytes[1..=route_length as usize]); - let route = match route_result { + let route = match std::str::from_utf8(&msg_bytes[1..route_end]) { Ok(route) => route, Err(e) => { error!( @@ -1317,8 +1422,12 @@ fn resolve_binary_route<'a>( } }; - let message_id_length = msg_bytes[route_length as usize + 1]; - if message_id_length as usize > msg_bytes.len() - 1 { + let requires_ack = msg_bytes[route_end] == 0x1; + + let message_id_length = msg_bytes[route_end + 1] as usize; + let message_id_start = route_end + 2; + let message_id_end = message_id_start + message_id_length; + if msg_bytes.len() < message_id_end { error!( "invalid binary message from client {}, message id length exceeds message length", connection_id @@ -1327,21 +1436,25 @@ fn resolve_binary_route<'a>( } let message_id = if message_id_length > 0 { - let start_idx = route_length as usize + 2; - let end_idx = start_idx + message_id_length as usize; - let message_id_bytes = &msg_bytes[start_idx..end_idx]; - let message_id_str = std::str::from_utf8(message_id_bytes).unwrap(); - Some(message_id_str.to_string()) + match std::str::from_utf8(&msg_bytes[message_id_start..message_id_end]) { + Ok(message_id) => Some(message_id.to_string()), + Err(e) => { + error!( + "invalid binary message from client {}, failed to parse message id: {}", + connection_id, e + ); + return ControlFlow::Continue(None); + } + } } else { None }; - let data_start_idx = route_length as usize + 2 + message_id_length as usize; - ControlFlow::Continue(Some(( route.to_string(), message_id, - &msg_bytes[data_start_idx..], + requires_ack, + &msg_bytes[message_id_end..], ))) } diff --git a/libs/runtime/core/tests/ipc_end_to_end_test.rs b/libs/runtime/core/tests/ipc_end_to_end_test.rs index e5fe0a3c..964d32da 100644 --- a/libs/runtime/core/tests/ipc_end_to_end_test.rs +++ b/libs/runtime/core/tests/ipc_end_to_end_test.rs @@ -1392,6 +1392,173 @@ async fn does_not_reorder_messages_when_handling_them_off_the_read_loop() { let _ = tokio::fs::remove_file(&socket).await; } +#[test_log::test(tokio::test)] +async fn acknowledges_a_binary_message_that_asks_to_be_acknowledged() { + let (_app, addr, socket) = start_runtime( + "ipc-ws-ack-binary", + "tests/data/fixtures/ipc-websocket-api.blueprint.yaml", + ) + .await; + let mut handler = HandlerStub::attach(&socket, |_| Some(websocket_ack())).await; + + let (mut socket_conn, _) = tokio_tungstenite::connect_async(format!("ws://{addr}/")) + .await + .expect("the WebSocket server should accept the connection"); + + // [routeLength][route][requireAck][messageIdLength][messageId][message], + // built the way the spec defines. + // The message id is what the acknowledgement has to name. + let route = b"sendMessage"; + let message_id = b"msg-1"; + let body: Vec = vec![0xde, 0xad, 0xbe, 0xef]; + let mut payload = vec![route.len() as u8]; + payload.extend_from_slice(route); + payload.push(0x1); + payload.push(message_id.len() as u8); + payload.extend_from_slice(message_id); + payload.extend_from_slice(&body); + + socket_conn + .send(tokio_tungstenite::tungstenite::Message::Binary(payload)) + .await + .unwrap(); + + let ack = tokio::time::timeout(Duration::from_secs(5), async { + while let Some(Ok(message)) = socket_conn.next().await { + if let tokio_tungstenite::tungstenite::Message::Binary(bytes) = message { + if bytes.starts_with(&[0x1, 0x4, 0x0, 0x0]) { + return Some(bytes[4..].to_vec()); + } + } + } + None + }) + .await + .expect("the acknowledgement should not take five seconds"); + + let ack = ack.expect("a message that asks to be acknowledged should be acknowledged"); + let ack: serde_json::Value = serde_json::from_slice(&ack).unwrap(); + assert_eq!(ack["messageId"], "msg-1"); + assert!( + ack["timestamp"].is_string(), + "the acknowledgement should carry a timestamp, got {ack}" + ); + + let dispatch = handler + .next_dispatch() + .await + .expect("the message should still reach the handler"); + let Some(proto::dispatch::Source::Websocket(message)) = dispatch.source else { + panic!("expected a WebSocket source"); + }; + assert_eq!(&message.message[..], &body[..]); + // The handler is told the id the client used, so instrumentation on its + // side can be tied to what the client saw acknowledged. + assert_eq!(message.message_id, "msg-1"); + + let _ = tokio::fs::remove_file(&socket).await; +} + +#[test_log::test(tokio::test)] +async fn acknowledges_a_json_message_that_asks_to_be_acknowledged() { + let (_app, addr, socket) = start_runtime( + "ipc-ws-ack-json", + "tests/data/fixtures/ipc-websocket-api.blueprint.yaml", + ) + .await; + let _handler = HandlerStub::attach(&socket, |_| Some(websocket_ack())).await; + + let (mut socket_conn, _) = tokio_tungstenite::connect_async(format!("ws://{addr}/")) + .await + .expect("the WebSocket server should accept the connection"); + + socket_conn + .send(tokio_tungstenite::tungstenite::Message::Text( + json!({ + "event": "sendMessage", + "messageId": "msg-json-1", + "ack": true, + "data": { "text": "hello" }, + }) + .to_string(), + )) + .await + .unwrap(); + + // Answered in the encoding it arrived in, so a client that only has text + // because its environment gave it no choice can still read the reply. + let ack = tokio::time::timeout(Duration::from_secs(5), async { + while let Some(Ok(message)) = socket_conn.next().await { + if let tokio_tungstenite::tungstenite::Message::Text(text) = message { + if let Ok(value) = serde_json::from_str::(&text) { + if value["event"] == "ack" { + return Some(value); + } + } + } + } + None + }) + .await + .expect("the acknowledgement should not take five seconds"); + + let ack = ack.expect("a message that asks to be acknowledged should be acknowledged"); + assert_eq!(ack["data"]["messageId"], "msg-json-1"); + assert!(ack["data"]["timestamp"].is_string()); + + let _ = tokio::fs::remove_file(&socket).await; +} + +#[test_log::test(tokio::test)] +async fn does_not_acknowledge_a_message_that_did_not_ask() { + let (_app, addr, socket) = start_runtime( + "ipc-ws-ack-absent", + "tests/data/fixtures/ipc-websocket-api.blueprint.yaml", + ) + .await; + let _handler = HandlerStub::attach(&socket, |_| Some(websocket_ack())).await; + + let (mut socket_conn, _) = tokio_tungstenite::connect_async(format!("ws://{addr}/")) + .await + .expect("the WebSocket server should accept the connection"); + + // Carries an id but does not opt in, and opting in without an id has + // nothing to name. Neither should be answered. + for message in [ + json!({ "event": "sendMessage", "messageId": "msg-2", "data": {} }), + json!({ "event": "sendMessage", "ack": true, "data": {} }), + ] { + socket_conn + .send(tokio_tungstenite::tungstenite::Message::Text( + message.to_string(), + )) + .await + .unwrap(); + } + + let unexpected = tokio::time::timeout(Duration::from_secs(2), async { + while let Some(Ok(message)) = socket_conn.next().await { + if let tokio_tungstenite::tungstenite::Message::Text(text) = message { + if let Ok(value) = serde_json::from_str::(&text) { + if value["event"] == "ack" { + return true; + } + } + } + } + false + }) + .await; + + assert_ne!( + unexpected, + Ok(true), + "acknowledgement is opt in, and an opt in without a message id is ignored" + ); + + let _ = tokio::fs::remove_file(&socket).await; +} + #[test_log::test(tokio::test)] async fn carries_a_binary_websocket_frame_without_corrupting_it() { let (_app, addr, socket) = start_runtime( @@ -1405,12 +1572,14 @@ async fn carries_a_binary_websocket_frame_without_corrupting_it() { .await .expect("the WebSocket server should accept the connection"); - // The binary framing is [route_len][route][msg_id_len][msg_id][body]. + // [routeLength][route][requireAck][messageIdLength][messageId][message], + // here with no acknowledgement asked for and no message id. let route = b"sendMessage"; let body: Vec = vec![0xff, 0xfe, 0x00, 0x80, 0x01, 0x02]; let mut payload = vec![route.len() as u8]; payload.extend_from_slice(route); payload.push(0); + payload.push(0); payload.extend_from_slice(&body); socket_conn diff --git a/libs/runtime/proto/celerity/runtime/v1/runtime.proto b/libs/runtime/proto/celerity/runtime/v1/runtime.proto index 40e03d2a..57f0d79c 100644 --- a/libs/runtime/proto/celerity/runtime/v1/runtime.proto +++ b/libs/runtime/proto/celerity/runtime/v1/runtime.proto @@ -194,6 +194,14 @@ message WebSocketMessage { // alone cannot express the distinction, and the WebSocket protocol treats // the two frame types as distinct. bool is_binary = 6; + // The id this message is known by, which is the one the client gave it when + // it gave one and a runtime generated one otherwise. + // + // Distinct from request_id, which identifies the delivery. This identifies + // the message, so it is what an acknowledgement names and what a lost + // message notification refers to, and a handler needs it to tie its own + // instrumentation to what the client sees. + string message_id = 7; } message ConsumerBatch { diff --git a/libs/runtime/ws/ws-registry/src/acks.rs b/libs/runtime/ws/ws-registry/src/acks.rs index 75b640e2..7ee3c300 100644 --- a/libs/runtime/ws/ws-registry/src/acks.rs +++ b/libs/runtime/ws/ws-registry/src/acks.rs @@ -27,7 +27,14 @@ pub const ACK_WAIT_CHECK_INTERVAL_MS: u64 = 20; pub enum AckStatus { // The message has been sent but no acknowledgement // has been received yet. - Pending(String, MessageType, Vec), + Pending { + message: String, + message_type: MessageType, + inform_clients: Vec, + // The context the message was sent from, carried so that a client told + // the message was lost is told what it was for. + caller: Option, + }, // The message has been received by the node that // has the connection that the message was sent for. Received, @@ -42,6 +49,9 @@ pub struct ResendMessageInfo { pub message_type: MessageType, pub message: String, pub inform_clients_on_loss: Vec, + // Carried through the resend so that it is still there if the message is + // eventually declared lost, rather than being dropped on the first retry. + pub caller: Option, } #[derive(Clone, Debug, PartialEq)] @@ -51,7 +61,11 @@ pub enum MessageAction { Resend(ResendMessageInfo), // The message should be considered lost and the caller should be informed that the message // was lost. - Lost(String, Vec), + Lost { + message_id: String, + inform_clients: Vec, + caller: Option, + }, } pub enum AckWorkerMessage { @@ -187,7 +201,7 @@ impl Worker { let mut acks_guard = self.acks.lock().await; let existing_ack_status = acks_guard.get(&message_id).cloned(); - let new_detailed_ack_status = if matches!(ack_status, AckStatus::Pending(_, _, _)) { + let new_detailed_ack_status = if matches!(ack_status, AckStatus::Pending { .. }) { // Only increment the attempts if the message is still pending. DetailedAckStatus { status: ack_status, @@ -221,12 +235,22 @@ async fn check_for_actions_periodic( let mut acks_guard = acks.lock().await; for (message_id, detailed_ack_status) in acks_guard.iter_mut() { - if let AckStatus::Pending(message, message_type, client_ids) = &detailed_ack_status.status { + if let AckStatus::Pending { + message, + message_type, + inform_clients: client_ids, + caller, + } = &detailed_ack_status.status + { if let Some(last_attempt_time) = detailed_ack_status.last_attempt_time { if now.duration_since(last_attempt_time) > Duration::from_millis(message_timeout_ms) { let action = if detailed_ack_status.attempts >= max_attempts { - MessageAction::Lost(message_id.clone(), client_ids.clone()) + MessageAction::Lost { + message_id: message_id.clone(), + inform_clients: client_ids.clone(), + caller: caller.clone(), + } } else { MessageAction::Resend(ResendMessageInfo { client_id: message_id.clone(), @@ -234,6 +258,7 @@ async fn check_for_actions_periodic( message_type: message_type.clone(), message: message.clone(), inform_clients_on_loss: client_ids.clone(), + caller: caller.clone(), }) }; actions.push(action); @@ -247,16 +272,10 @@ async fn check_for_actions_periodic( for action in actions { let message_id = match &action { - MessageAction::Resend(ResendMessageInfo { - message_id, - client_id: _, - message: _, - message_type: _, - inform_clients_on_loss: _, - }) => message_id.clone(), - MessageAction::Lost(message_id, _) => message_id.clone(), + MessageAction::Resend(ResendMessageInfo { message_id, .. }) => message_id.clone(), + MessageAction::Lost { message_id, .. } => message_id.clone(), }; - let is_lost = matches!(action, MessageAction::Lost(_, _)); + let is_lost = matches!(action, MessageAction::Lost { .. }); if message_action_tx.send(action).await.is_err() { error!( @@ -286,7 +305,7 @@ async fn handle_ack_wait( // Check if we have a status for this message let acks_guard = acks.lock().await; if let Some(detailed_ack_status) = acks_guard.get(&message_id) { - let is_pending = matches!(detailed_ack_status.status, AckStatus::Pending(_, _, _)); + let is_pending = matches!(detailed_ack_status.status, AckStatus::Pending { .. }); if !is_pending { // Message is no longer pending, send the final status if tx.send(detailed_ack_status.status.clone()).is_err() { diff --git a/libs/runtime/ws/ws-registry/src/message_helpers.rs b/libs/runtime/ws/ws-registry/src/message_helpers.rs index bebd929e..8ec94751 100644 --- a/libs/runtime/ws/ws-registry/src/message_helpers.rs +++ b/libs/runtime/ws/ws-registry/src/message_helpers.rs @@ -7,20 +7,24 @@ use crate::types::MessageType; /// Creates a message lost event to be sent to a WebSocket connection. /// This follows the Celerity Binary Message Format documented here: /// https://www.celerityframework.io/docs/applications/resources/celerity-api#celerity-binary-message-format -pub fn create_message_lost_event(message_id: String) -> Vec { - let route_len_byte = 0x1_u8; - let route_byte = 0x3_u8; +pub fn create_message_lost_event(message_id: String, caller: Option) -> Vec { let payload = json!({ "messageId": message_id, + // Names the context the lost message came from, so an application can + // tell the client what to retry rather than only that something went + // missing. Absent when the sender named none. + "caller": caller.unwrap_or_default(), }) .to_string(); let payload_bytes = payload.as_bytes(); - // The message is a binary message with the route length, route and payload. - // In this case, the route length is 1 byte, the route is 1 byte and the payload is length of - // the serialised JSON message. - let mut message = Vec::with_capacity(payload_bytes.len() + 2); - message.push(route_len_byte); - message.push(route_byte); + + // `[routeLength][route][requireAck][messageIdLength]` then the payload. A + // reserved message needs no acknowledgement of its own and carries no + // message id of its own, which is what the two zero bytes say. Clients match + // on all four, so a short header is not a shorter version of this message, + // it is one they cannot recognise at all. + let mut message = Vec::with_capacity(payload_bytes.len() + 4); + message.extend_from_slice(&[0x1, 0x3, 0x0, 0x0]); message.extend_from_slice(payload_bytes); message } diff --git a/libs/runtime/ws/ws-registry/src/registry.rs b/libs/runtime/ws/ws-registry/src/registry.rs index 05cd9af9..25536839 100644 --- a/libs/runtime/ws/ws-registry/src/registry.rs +++ b/libs/runtime/ws/ws-registry/src/registry.rs @@ -143,7 +143,7 @@ impl WebSocketConnRegistry { resend_message_info.message.clone(), Some(SendContext { wait_for_ack: false, - caller: None, + caller: resend_message_info.caller.clone(), inform_clients: resend_message_info.inform_clients_on_loss, }), ) @@ -156,7 +156,11 @@ impl WebSocketConnRegistry { ); } } - MessageAction::Lost(message_id, inform_clients) => { + MessageAction::Lost { + message_id, + inform_clients, + caller, + } => { for client_id in inform_clients { // Only inform clients that are connected to the current node. if let Some(connection) = self.get_connection(client_id.clone()) { @@ -169,7 +173,11 @@ impl WebSocketConnRegistry { debug!(connection_id = %client_id, "sending message lost event to connection: {}", client_id); conn_lock .send(Message::Binary( - create_message_lost_event(message_id.clone()).into(), + create_message_lost_event( + message_id.clone(), + caller.clone(), + ) + .into(), )) .await .unwrap(); @@ -313,12 +321,18 @@ impl WebSocketConnRegistry { message_type: MessageType, message: String, inform_clients: Vec, + caller: Option, ) { if let Some(ack_sender) = self.ack_sender.lock().await.as_ref() { ack_sender .send(AckWorkerMessage::Status( message_id, - AckStatus::Pending(message, message_type, inform_clients), + AckStatus::Pending { + message, + message_type, + inform_clients, + caller, + }, )) .await .expect("ack worker channel unexpectedly closed"); @@ -399,6 +413,7 @@ impl WebSocketRegistrySend for WebSocketConnRegistry { message_type.clone(), message.clone(), send_ctx.inform_clients.clone(), + send_ctx.caller.clone(), ) .await; @@ -422,13 +437,15 @@ impl WebSocketRegistrySend for WebSocketConnRegistry { // (no broadcaster), then the message is lost and the provided clients connected to // the current node should be informed. let send_ctx = ctx.unwrap_or_default(); + // Taken before the loop consumes the rest of the context. + let caller = send_ctx.caller; for client_id in send_ctx.inform_clients { if let Some(connection) = self.get_connection(client_id.clone()) { connection .lock() .await .send(Message::Binary( - create_message_lost_event(message_id.clone()).into(), + create_message_lost_event(message_id.clone(), caller.clone()).into(), )) .await?; } @@ -486,6 +503,7 @@ mod tests { struct MessageLostBody { #[serde(rename = "messageId")] message_id: String, + caller: String, } #[derive(Deserialize, Debug, Serialize)] @@ -545,7 +563,7 @@ mod tests { msg.to_string(), Some(SendContext { wait_for_ack: true, - caller: None, + caller: Some("test-caller".to_string()), inform_clients: vec![connection_id.clone()], }), ) @@ -773,11 +791,15 @@ mod tests { // and client should be informed with a message lost event. let node1_msg_received = lost_event.expect("the registry should send a protocol-level lost message event"); - assert_eq!(node1_msg_received[0], 0x1); // Route length should be 1 - assert_eq!(node1_msg_received[1], 0x3); // Route should be 0x3 (message lost) - let json_msg = String::from_utf8(node1_msg_received[2..].to_vec()).unwrap(); + // `[routeLength][route][requireAck][messageIdLength]`, all four of which + // a client matches on before it will treat this as a lost message. + assert_eq!(node1_msg_received[..4], [0x1, 0x3, 0x0, 0x0]); + let json_msg = String::from_utf8(node1_msg_received[4..].to_vec()).unwrap(); let message_lost_event: MessageLostBody = serde_json::from_str(&json_msg).unwrap(); assert_eq!(message_lost_event.message_id, "test-message-1"); + // Carried through from the send, so the client is told what the lost + // message was for and not only that one went missing. + assert_eq!(message_lost_event.caller, "test-caller"); } #[test_log::test(tokio::test)] From 74b6e849e656ba5decda269887a58dd43fd0f1a5 Mon Sep 17 00:00:00 2001 From: Andre Sutherland Date: Sun, 16 Aug 2026 13:11:18 +0100 Subject: [PATCH 2/3] fix(lib-rt-core): acknowledge a websocket message when it is taken in An acknowledgement says a message arrived. It was being sent from where the message is handled instead, which is a later moment and sometimes a much later one, so a message that arrived promptly could be acknowledged well after the client had given up waiting and sent it again. The runtime had the message the whole time. It is now answered from the connection's read loop, off the frame itself, reading only as far as the message id and the flag. Sent once the message is safely queued rather than before, so nothing is acknowledged that then gets shed for want of room. Whether a text message opts in is checked before it is parsed, so the ones that do not, which is almost all of them, cost a scan rather than a second parse. The check looks for `ack` as a key rather than anywhere in the text, because the protocol also reserves it as a value for acknowledgement messages themselves, and clients will be sending those inbound once they can answer acknowledgements of their own. Covered by a message queued behind a handler that has not finished, which is answered in well under the time that handler runs for, along with unit tests for the prefilter in both directions and for binary frames that ask, that do not, and that claim to be longer than they are. --- libs/runtime/core/src/websocket.rs | 173 +++++++++++++----- .../runtime/core/tests/ipc_end_to_end_test.rs | 60 ++++++ 2 files changed, 190 insertions(+), 43 deletions(-) diff --git a/libs/runtime/core/src/websocket.rs b/libs/runtime/core/src/websocket.rs index 505cdb83..970bf83e 100644 --- a/libs/runtime/core/src/websocket.rs +++ b/libs/runtime/core/src/websocket.rs @@ -429,6 +429,10 @@ async fn handle_socket( // served by waiting for it in silence, since waiting is // what stops the heartbeat being answered. It is shed // instead, with a hint for when to come back. + // Read before the message is handed on, since handing it on + // gives it away. + let ack = ack_request(&msg); + match work_tx .send_timeout( (msg, request_ctx.clone()), @@ -436,7 +440,19 @@ async fn handle_socket( ) .await { - Ok(()) => {} + Ok(()) => { + // Answered as soon as the message is taken in, since + // that is what an acknowledgement says. Anything + // that happens to it afterwards, however long it + // takes, is not what the client is waiting to hear. + // + // Sent once it is safely queued and not before, so + // nothing is acknowledged that then gets shed to + // process incoming messages. + if let Some((message_id, format)) = ack { + acknowledge(&socket_ref, &connection_id, &message_id, format).await; + } + } Err(SendTimeoutError::Timeout(_)) => { warn!( "client {connection_id} is sending faster than its handlers can \ @@ -654,15 +670,9 @@ fn spawn_message_worker( ) -> JoinHandle<()> { tokio::spawn(async move { while let Some((message, request_ctx)) = work_rx.recv().await { - if process_message( - message, - connection_id.clone(), - request_ctx, - &state, - &socket_ref, - ) - .await - .is_break() + if process_message(message, connection_id.clone(), request_ctx, &state) + .await + .is_break() { // The connection is finished, and the read loop is waiting on a // socket that may never produce anything again. Closing it is @@ -1032,7 +1042,6 @@ async fn process_message( connection_id: String, request_ctx: WebSocketRequestContext, state: &WebSocketAppState, - socket_ref: &Arc>, ) -> ControlFlow<(), ()> { match msg { Message::Text(text) => { @@ -1041,16 +1050,8 @@ async fn process_message( connection_id.clone(), state.route_key.clone(), )?; - if let Some((route, message_id, requires_ack, data)) = resolved { + if let Some((route, message_id, _requires_ack, data)) = resolved { if let Some(handler) = get_message_route_handler(&route, state).await { - acknowledge_if_asked( - socket_ref, - &connection_id, - message_id.as_deref(), - requires_ack, - AckFormat::Json, - ) - .await; handle_json_message( handler.clone(), connection_id.clone(), @@ -1070,16 +1071,8 @@ async fn process_message( } Message::Binary(bytes) => { let resolved = resolve_binary_route(&bytes, connection_id.clone())?; - if let Some((route, message_id, requires_ack, bytes_stripped)) = resolved { + if let Some((route, message_id, _requires_ack, bytes_stripped)) = resolved { if let Some(handler) = get_message_route_handler(&route, state).await { - acknowledge_if_asked( - socket_ref, - &connection_id, - message_id.as_deref(), - requires_ack, - AckFormat::Binary, - ) - .await; handle_binary_message( handler.clone(), connection_id.clone(), @@ -1265,30 +1258,71 @@ async fn handle_binary_message( /// It mirrors whatever the message being acknowledged arrived as. A client that /// can send binary can read it, and one that only has text, because its /// environment gave it no choice, gets text back. -#[derive(Clone, Copy)] +#[derive(Clone, Copy, Debug)] enum AckFormat { Json, Binary, } -/// Tells the client its message arrived, when the message asked to be told. +/// Whether a JSON text carries `ack` as an object key. /// -/// Opting in without a message id does nothing, since an acknowledgement names -/// the message it is for and there would be nothing to name. -async fn acknowledge_if_asked( +/// A prefilter, not a parser. It is allowed to say yes to a message that turns +/// out not to opt in, which costs a parse that then finds nothing. It must not +/// say no to one that does, which is why it looks for the key rather than for +/// the word. +fn has_ack_key(text: &str) -> bool { + text.match_indices("\"ack\"") + .any(|(index, matched)| text[index + matched.len()..].trim_start().starts_with(':')) +} + +fn ack_request(msg: &Message) -> Option<(String, AckFormat)> { + match msg { + Message::Text(text) => { + // Parsing every text message twice to find out that almost none of + // them opt in is not worth it, so a message that does not carry the + // key is passed over before it is parsed at all. + // + // Matched as a key rather than anywhere in the text, since a + // message is free to carry "ack" as a value and many will. + if !has_ack_key(text) { + return None; + } + let value: Value = serde_json::from_str(text).ok()?; + let object = value.as_object()?; + if object.get("ack").and_then(Value::as_bool) != Some(true) { + return None; + } + let message_id = object.get("messageId").and_then(Value::as_str)?; + Some((message_id.to_string(), AckFormat::Json)) + } + Message::Binary(bytes) => { + // `[routeLength][route][requireAck][messageIdLength][messageId]`, + // read far enough to answer and no further. + let route_length = *bytes.first()? as usize; + let requires_ack = *bytes.get(1 + route_length)? == 0x1; + if !requires_ack { + return None; + } + let message_id_length = *bytes.get(route_length + 2)? as usize; + let start = route_length + 3; + let message_id = bytes.get(start..start + message_id_length)?; + let message_id = std::str::from_utf8(message_id).ok()?; + if message_id.is_empty() { + return None; + } + Some((message_id.to_string(), AckFormat::Binary)) + } + _ => None, + } +} + +/// Tells the client its message arrived. +async fn acknowledge( socket_ref: &Arc>, connection_id: &str, - message_id: Option<&str>, - requires_ack: bool, + message_id: &str, format: AckFormat, ) { - if !requires_ack { - return; - } - let Some(message_id) = message_id else { - return; - }; - let timestamp = get_epoch_seconds().to_string(); let message = match format { AckFormat::Json => Message::Text( @@ -1560,6 +1594,59 @@ async fn close_with_retry_after(socket_ref: Arc>, ret mod tests { use super::*; + #[test] + fn test_has_ack_key_ignores_ack_as_a_value() { + // Reserved as an event value by the protocol itself, so a message + // carrying it is ordinary rather than an opt in. + assert!(!has_ack_key(r#"{"event":"ack","data":{}}"#)); + assert!(!has_ack_key(r#"{"event":"send","data":{"type":"ack"}}"#)); + } + + #[test] + fn test_has_ack_key_finds_the_key() { + assert!(has_ack_key(r#"{"ack":true,"messageId":"1"}"#)); + // Whitespace is legal JSON either side of the colon. + assert!(has_ack_key(r#"{"ack" : true}"#)); + // Present as a value elsewhere as well as a key. + assert!(has_ack_key(r#"{"event":"ack","ack":true}"#)); + } + + #[test] + fn test_ack_request_reads_a_binary_frame() { + // [routeLength][route][requireAck][messageIdLength][messageId][payload] + let mut frame = vec![2u8]; + frame.extend_from_slice(b"ab"); + frame.push(0x1); + frame.push(3); + frame.extend_from_slice(b"m-1"); + frame.extend_from_slice(&[0xff, 0x00]); + + let request = ack_request(&Message::Binary(frame.into())); + let Some((message_id, AckFormat::Binary)) = request else { + panic!("expected a binary acknowledgement request, got {request:?}"); + }; + assert_eq!(message_id, "m-1"); + } + + #[test] + fn test_ack_request_ignores_a_binary_frame_that_did_not_ask() { + let mut frame = vec![2u8]; + frame.extend_from_slice(b"ab"); + frame.push(0x0); + frame.push(3); + frame.extend_from_slice(b"m-1"); + + assert!(ack_request(&Message::Binary(frame.into())).is_none()); + } + + #[test] + fn test_ack_request_refuses_a_frame_that_is_shorter_than_it_claims() { + // Claims a route longer than the bytes that follow it, so reading the + // acknowledgement flag would run off the end. + let frame = vec![9u8, b'a', b'b']; + assert!(ack_request(&Message::Binary(frame.into())).is_none()); + } + #[test] fn test_detect_json_ping() { let msg = Message::Text(r#"{"ping":true}"#.into()); diff --git a/libs/runtime/core/tests/ipc_end_to_end_test.rs b/libs/runtime/core/tests/ipc_end_to_end_test.rs index 964d32da..f96efacc 100644 --- a/libs/runtime/core/tests/ipc_end_to_end_test.rs +++ b/libs/runtime/core/tests/ipc_end_to_end_test.rs @@ -1509,6 +1509,66 @@ async fn acknowledges_a_json_message_that_asks_to_be_acknowledged() { let _ = tokio::fs::remove_file(&socket).await; } +#[test_log::test(tokio::test)] +async fn acknowledges_a_message_queued_behind_a_handler_that_is_still_running() { + let (_app, addr, socket) = start_runtime( + "ipc-ws-ack-queued", + "tests/data/fixtures/ipc-websocket-api.blueprint.yaml", + ) + .await; + // Answers nothing, so the first message is still being handled, for the + // whole of the ten second timeout this fixture sets, while the second + // arrives. + let _handler = HandlerStub::attach(&socket, |_| None).await; + + let (mut socket_conn, _) = tokio_tungstenite::connect_async(format!("ws://{addr}/")) + .await + .expect("the WebSocket server should accept the connection"); + + socket_conn + .send(tokio_tungstenite::tungstenite::Message::Text( + json!({ "event": "sendMessage", "data": { "first": true } }).to_string(), + )) + .await + .unwrap(); + socket_conn + .send(tokio_tungstenite::tungstenite::Message::Text( + json!({ + "event": "sendMessage", + "messageId": "queued-1", + "ack": true, + "data": { "second": true }, + }) + .to_string(), + )) + .await + .unwrap(); + + // Acknowledgement follows the message being taken in, not what happens to + // it after. Tying it to handling would leave this one waiting on the + // handler ahead of it, and a client that hears nothing sends it again for a + // message the runtime was holding the entire time. + let ack = tokio::time::timeout(Duration::from_secs(3), async { + while let Some(Ok(message)) = socket_conn.next().await { + if let tokio_tungstenite::tungstenite::Message::Text(text) = message { + if let Ok(value) = serde_json::from_str::(&text) { + if value["event"] == "ack" { + return Some(value); + } + } + } + } + None + }) + .await + .expect("the acknowledgement should not wait for the handler ahead of it"); + + let ack = ack.expect("the queued message should be acknowledged"); + assert_eq!(ack["data"]["messageId"], "queued-1"); + + let _ = tokio::fs::remove_file(&socket).await; +} + #[test_log::test(tokio::test)] async fn does_not_acknowledge_a_message_that_did_not_ask() { let (_app, addr, socket) = start_runtime( From b0f355ad5ba771dd95c4a4b0d8e52c9a6426e603 Mon Sep 17 00:00:00 2001 From: Andre Sutherland Date: Sun, 16 Aug 2026 19:44:30 +0100 Subject: [PATCH 3/3] fix(lib-rt-ws-registry): send a resend to the connection it was meant for Pending acknowledgements are keyed by message id, and the connection the message was going to was not kept anywhere, so a resend was addressed to the message id for want of anything better. No connection has that id, on this node or any other, so a resend missed the local lookup, went out over the broadcaster addressed to nothing, and reached nobody. It still counted as an attempt, so a message that needed retrying was retried into the void until it ran out of attempts and was called lost. Delivery between nodes therefore only ever worked first time. Anything that needed a second go was certain to fail while looking like an ordinary failure to deliver. The connection is now held alongside the message and a resend goes to it. This is the first test in a module that decides when to retry, when to give up, and when to tell clients a message went missing. The registry's own tests could not have caught it, since the connection they resend to does not exist either way, so the address being wrong makes no difference to them. --- libs/runtime/ws/ws-registry/src/acks.rs | 45 ++++++++++++++++++++- libs/runtime/ws/ws-registry/src/registry.rs | 3 ++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/libs/runtime/ws/ws-registry/src/acks.rs b/libs/runtime/ws/ws-registry/src/acks.rs index 7ee3c300..f0e693e1 100644 --- a/libs/runtime/ws/ws-registry/src/acks.rs +++ b/libs/runtime/ws/ws-registry/src/acks.rs @@ -28,6 +28,7 @@ pub enum AckStatus { // The message has been sent but no acknowledgement // has been received yet. Pending { + connection_id: String, message: String, message_type: MessageType, inform_clients: Vec, @@ -236,6 +237,7 @@ async fn check_for_actions_periodic( for (message_id, detailed_ack_status) in acks_guard.iter_mut() { if let AckStatus::Pending { + connection_id, message, message_type, inform_clients: client_ids, @@ -253,7 +255,7 @@ async fn check_for_actions_periodic( } } else { MessageAction::Resend(ResendMessageInfo { - client_id: message_id.clone(), + client_id: connection_id.clone(), message_id: message_id.clone(), message_type: message_type.clone(), message: message.clone(), @@ -330,3 +332,44 @@ async fn handle_ack_wait( drop(acks_guard); } } + +#[cfg(test)] +mod tests { + use super::*; + + /// A resend has to go to the connection the message was for. + /// + /// Pending acknowledgements are keyed by message id, which says nothing + /// about where the message was headed, so the connection it was for is held + /// alongside. Sending a resend to the message id instead finds no + /// connection anywhere in the cluster and the message reaches nobody, while + /// still counting as an attempt until it is declared lost. + #[test_log::test(tokio::test)] + async fn test_resend_is_addressed_to_the_connection_not_the_message() { + let acks = Arc::new(Mutex::new(HashMap::from([( + "message-1".to_string(), + DetailedAckStatus { + status: AckStatus::Pending { + connection_id: "connection-1".to_string(), + message: "{}".to_string(), + message_type: MessageType::Json, + inform_clients: vec![], + caller: None, + }, + attempts: 0, + // Long enough ago that it is due to be retried. + last_attempt_time: Some(Instant::now() - Duration::from_secs(60)), + }, + )]))); + + let (action_tx, mut action_rx) = tokio::sync::mpsc::channel(4); + check_for_actions_periodic(&acks, &action_tx, 1_000, 3).await; + + let action = action_rx.recv().await.expect("a resend should be due"); + let MessageAction::Resend(resend) = action else { + panic!("expected a resend, got {action:?}"); + }; + assert_eq!(resend.client_id, "connection-1"); + assert_eq!(resend.message_id, "message-1"); + } +} diff --git a/libs/runtime/ws/ws-registry/src/registry.rs b/libs/runtime/ws/ws-registry/src/registry.rs index 25536839..ae6efe8e 100644 --- a/libs/runtime/ws/ws-registry/src/registry.rs +++ b/libs/runtime/ws/ws-registry/src/registry.rs @@ -317,6 +317,7 @@ impl WebSocketConnRegistry { async fn record_pending_ack( &self, + connection_id: String, message_id: String, message_type: MessageType, message: String, @@ -328,6 +329,7 @@ impl WebSocketConnRegistry { .send(AckWorkerMessage::Status( message_id, AckStatus::Pending { + connection_id, message, message_type, inform_clients, @@ -409,6 +411,7 @@ impl WebSocketRegistrySend for WebSocketConnRegistry { let send_ctx = ctx.unwrap_or_default(); debug!(connection_id = %connection_id, "connection not found locally, preparing to send message to broadcaster"); self.record_pending_ack( + connection_id.to_string(), message_id.clone(), message_type.clone(), message.clone(),