Fix: Stop the client dropping chat messages that begin with e

CChatManager::OnReceive opened with the same heartbeat guard the other
managers use, `if (szBuffer[0] == TOKEN_HEARTBEAT) return;`, before it
looked at the length. TOKEN_HEARTBEAT is 101, which is also the letter e,
and this channel carries free text rather than command bytes, so every
message starting with e -- "echo", "error", anything -- was silently
discarded. The sender never learned: the server's chat dialog had already
written the text into its own log, so the two sides disagreed about what
was said.

The guard is dead code here. Heartbeats travel on the main connection
only, as a multi-byte [101][Heartbeat] packet consumed by the main
dispatcher; the server never sends one on a chat sub-connection. Delete
it and keep the length check that follows.

The server keeps prepending a space when the GBK payload starts with
101, because already-deployed clients still carry the guard and losing
the message outright is worse than an invisible leading space. Note the
same guard, harmless today, still sits in the machine, file, proxy and
screen-hide managers.

Verified with the Debug instance and a local Debug client: with the
server's space temporarily disabled, chat_send "echo test" and
"second line" both showed up verbatim in the client dialog (read back
with WM_GETTEXT); with the space restored the first arrives as
" echo test". Details in docs/Mcp_Chat_Design.md section 5.

Co-Authored-By: deepseek-flash
This commit is contained in:
yuanyuanxianganddeepseek-flash committed 2026-10-25 14:57:47 +01:00
1 parent cc3e11d30d
commit 1c5fab1645
3 files changed
+24 -10

No files matched your search

+6 -5
View File
@@ -7,9 +7,9 @@
// → 双向文本 [CP936 字节][NUL],无 token 前缀
// → 服务端 [COMMAND_CHAT_CLOSE=1] 关闭窗口
//
// 客户端怪癖(见 docs/Mcp_Chat_Design.md §4):
// 1. ChatManager.cpp 在任何长度判断前丢弃首字节为 TOKEN_HEARTBEAT(101, 'e') 的包,
// 故 GBK 首字节为 101 时前置一个空格。
// 客户端怪癖(见 docs/Mcp_Chat_Design.md §5):
// 1. 老客户端 ChatManager.cpp 在任何长度判断前丢弃首字节为 TOKEN_HEARTBEAT(101, 'e')
// 的包,故 GBK 首字节为 101 时前置一个空格(新客户端已删掉那行守卫,空格只为兼容)。
// 2. 窗口由子线程 CreateDialogParamA 创建,收到 [0] 后仍有约 150ms 建窗延迟;
// 绑定后 1000ms 内不返回 chat_open,也不接受 chat_send。
//
@@ -419,8 +419,9 @@ static std::string BuildChatSend(const Json::Value& id, const Json::Value& args,
" GBK bytes (limit " + std::to_string(kMaxSendBytes) + ")");
}
// 客户端在长度判断之前丢弃首字节为 TOKEN_HEARTBEAT(101, 'e') 的包。
// 前置一个空格规避,显示上无感(2026-10 客户端 ChatManager.cpp:281)。
// 兼容老客户端:它们在任何长度判断之前丢弃首字节为 TOKEN_HEARTBEAT(101, 'e') 的包
// (ChatManager::OnReceive 里照搬来的心跳守卫)。新客户端已删掉那行,这里保留前置空格
// 是为了不区分客户端版本——多一个看不见的空格,好过老客户端静默丢消息。
if ((BYTE)gbk[0] == (BYTE)TOKEN_HEARTBEAT) gbk.insert(gbk.begin(), ' ');
std::vector<char> packet(gbk.begin(), gbk.end());