From 6060b968a7c764833c34f8bcdf56dd8e7d7fad18 Mon Sep 17 00:00:00 2001 From: YokiiroBW Date: Mon, 27 Jul 2026 01:54:17 +0800 Subject: [PATCH] feat(astrbot): record the message id value in the frame trace The first capture answered the question the trace was built for and eliminated it: all 77 plain frames of one reply carried a message_id, so a reply splitting into two bubbles is not the event_id fallback in F-34. What remains depends on the value rather than its presence. If the id changes partway through a reply then the client is correctly showing two messages the server sent; if it stays the same then the split is ours, in the historySessionId fallback that loads another session's history. The id is an opaque row identifier, not content. Also record the length of a string data payload. It separates "the server streamed many small chunks" from "the server sent the reply in one piece" without recording any text. Co-Authored-By: Claude Opus 5 --- src-tauri/src/networking/astrbot_client.rs | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src-tauri/src/networking/astrbot_client.rs b/src-tauri/src/networking/astrbot_client.rs index b3db220..e962475 100644 --- a/src-tauri/src/networking/astrbot_client.rs +++ b/src-tauri/src/networking/astrbot_client.rs @@ -765,6 +765,23 @@ fn trace_frame_shape(line: &str) { let has_message_id = value .get("message_id") .is_some_and(|field| !field.is_null()); + // The *value* decides whether a reply that renders as two bubbles is one + // message the client split, or two messages the server sent. It is an + // opaque row identifier, not content. + let message_id = value + .get("message_id") + .and_then(|field| match field { + Value::String(text) => Some(text.clone()), + Value::Number(number) => Some(number.to_string()), + _ => None, + }) + .unwrap_or_else(|| "".to_owned()); + // Length only. Distinguishes "the server streamed many small chunks" from + // "the server sent the whole reply at once" without recording any text. + let data_len = match value.get("data") { + Some(Value::String(text)) => text.chars().count(), + _ => 0, + }; let has_session_id = value .get("session_id") .is_some_and(|field| !field.is_null()); @@ -773,9 +790,11 @@ fn trace_frame_shape(line: &str) { target: FRAME_TRACE_TARGET, frame_type, has_message_id, + message_id = message_id.as_str(), has_session_id, ?streaming, data_keys = data_keys.as_str(), + data_len, "astrbot sse frame" ); } @@ -898,6 +917,10 @@ mod tests { ); assert!(output.contains("frame_type=\"plain\"")); assert!(output.contains("has_message_id=true")); + // The value, and the chunk length, are what separate "one message the + // client split" from "two messages the server sent". + assert!(output.contains("message_id=\"42\"")); + assert!(output.contains("data_len=2")); assert!(output.contains("frame_type=\"image\"")); // The key names are what identify the plugin attachment shape. assert!(output.contains("data_keys=\"url\""));