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
This commit is contained in:
1 parent
29d7ee1a18
commit
f33a205fd9
1 file changed
+4
-1
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user