From f33a205fd96fd040cc0ea632d410d2ba62232412 Mon Sep 17 00:00:00 2001 From: yuanyuanxiang <962914132@qq.com> Date: Wed, 11 Nov 2026 15:14:23 +0100 Subject: [PATCH] Fix: Report chat_wait timeouts only when no message arrived WaitChatMessages decided overtime after the drain loop had already emptied the session inbox. Whenever a reply arrived during the wait the loop moved every queued message into the result and then evaluated timed_out on the now-empty queue, so a successful wait was still reported as a timeout. Callers that key off timed_out would either retry needlessly or treat the answer as noise. The arrival state is now captured before draining and the deadline flag is computed from that snapshot. A wait that returns messages is never marked timed out, while an empty wait still reports timed_out so the caller can distinguish silence from a closed session. Verified end to end against the Android emulator over the MCP debug endpoint: after a device reply chat_wait returned one message with timed_out=false, and a follow-up wait on the empty inbox returned timed_out=true, preventing a regression in the other direction. Co-Authored-By: deepseek-flash --- server/2015Remote/McpChat.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/server/2015Remote/McpChat.cpp b/server/2015Remote/McpChat.cpp index bc0107c..57e5324 100644 --- a/server/2015Remote/McpChat.cpp +++ b/server/2015Remote/McpChat.cpp @@ -938,13 +938,16 @@ CMcpServer::ChatWaitResult CMcpServer::WaitChatMessages( m_ChatCv.wait_until(lk, until); } + // 进 drain 前先记住「等待结束时是否已有消息」:drain 会把 inbox 清空, + // 之后再用 inbox.empty() 判断超时会把「收到消息」也标成 timed_out=true。 + const bool arrived = !s->inbox.empty(); while (!s->inbox.empty() && out.size() < maxMessages) { out.push_back(s->inbox.front()); s->inboxBytes -= s->inbox.front().text.size(); s->inbox.pop_front(); } - timedOut = s->inbox.empty() && !s->closed; + timedOut = !arrived && !s->closed; closed = s->closed; dropped = s->dropped; s->dropped = 0;