Fix: Stop MCP tool timeouts from popping MFC dialogs
A sub-connection's first packet doubles as the readiness packet: the file, service, registry, process, log and terminal tools all get answered that way. Once a tool has given up (timeout or failure) its pending entry is gone, so if the client only gets around to sending that first packet afterwards, MessageHandle cannot tell it apart from a human click and opens the matching modeless dialog - a File Manager window appeared while timeouts were being exercised on this machine. The wait paths now record, per device, which first-packet token the abandoned tool would have sent (MarkLateFirstPacketForTool from WaitPending, WaitPendingRegistry, WaitPendingWrite, WaitFileTransferDone and WaitTerminalReady), and every dialog-opening case consumes that marker before falling back to the MFC path. The marker is one-shot, expires after five minutes and is never set on the success path, so normal use is unaffected; the worst case is that a single manual open on a host that just had an MCP timeout is swallowed. ClientMsg packets are dropped with a log line while a tool is pending for that host: new clients still send the legacy popup message alongside the structured failure token, which would otherwise put a modal box on the server UI during an MCP call. Co-Authored-By: deepseek-flash
This commit is contained in:
1 parent
1456882f16
commit
b4cb34fea9
4 files changed
+131
-2
No files matched your search
@@ -673,6 +673,8 @@ token 只从 `-Token` / env 读取,不落仓库、不打印;无在线主机
|
||||
|
||||
- **命令超时会销毁持久会话**(`terminal_exec`):等服务端收集到哨兵超时返回 `-32001`,会话随即被销毁并留 600 秒「墓碑」;对同一 `session_id` 再发命令返回 `-32002`,文案明确写 `Terminal session was destroyed after this command timed out (waited N ms); call terminal_open again`,与「id 写错」(`Terminal session not found: <id>`)区分开。
|
||||
- **新客户端把失败改成结构化回报**(`TOKEN_SERVICE_ERROR=170` / `TOKEN_FILE_LIST_ERROR=171` / `TOKEN_REG_ERROR=172` / `TOKEN_DOWNLOAD_ERROR=173`,布局 `[token:1][win32 码:4 LE]`):`list_services`(未提权)、`list_files`/`list_registry`(路径/键不存在或拒绝访问)、`download_file`(远端路径全部不存在)都在客户端侧就失败并立即回报,服务端转译成 `-32009`/`-32010`,**亚秒级返回**,不再靠超时猜。老客户端不发这些包,成功路径报文一律不变,因此老客户端/老服务端的行为与改造前完全一致(老服务端把未知 token 走 `default` 丢弃)。
|
||||
- **工具放弃后的「迟到首包」一律吸收,不会弹 MFC 窗口**:文件/服务/注册表/进程/日志/终端这几族的子连接都是「建成即发首包」。工具超时清理挂起后,客户端可能才把首包发上来,此时没有挂起会话,`MessageHandle` 只能把它当成人手点击,于是弹出文件管理器/服务管理器/注册表/进程管理器/日志/终端窗口(构造超时场景时实测出现过文件管理器窗口)。现在各等待函数在**放弃分支**登记「设备 → 该工具的首包 token」(`CMcpServer::MarkLateFirstPacketForTool`),包到达时 `TakeToolFirstPacket` 一次性吸收并关子连接:`list_files`/`download_file`/`upload_file`/`search_file` → `TOKEN_DRIVE_LIST`;`list_services`/`control_service` → `TOKEN_SERVERLIST`;`list_registry` → `TOKEN_REGEDIT`;`list_processes`/`kill_process` → `TOKEN_PSLIST`;`list_windows`/`operate_window` → `TOKEN_WSLIST`;`get_client_log` → `TOKEN_REPORT_LOG`;`get_activity_history` → `TOKEN_REPORT_ACTIVITY`(主连接,只丢包不关连接);`exec_command`/`terminal_open` → `TOKEN_SHELL_START` + `TOKEN_TERMINAL_START`。成功路径不登记,命中即消费,标记 5 分钟后过期。**已知代价**:同一主机在工具超时后 5 分钟内手动点开对应窗口,可能被这枚标记吞掉一次(再点即可)——比误弹窗口更可接受。
|
||||
- **MCP 工具在飞时不弹客户端的老式提示框**:新客户端在失败分支同时发结构化 token 和老的 `ClientMsg`(只为兼容老服务端),后者会 `PostMessageA(WM_SHOWERRORMSG)` 在服务端 UI 上弹框。`TOKEN_CLIENT_MSG` 分支现在发现该设备有挂起请求/文件传输时就只记日志不弹框。实测 `list_services`(未提权)时客户端子连接已被服务端关掉,`ClientMsg` 根本发不出来,这条属兜底。
|
||||
- **`download_file` 有停滞看门狗兜底**:60 秒没收到任何数据即失败,返回 `-32001` 且文案带 `File transfer stalled: no data received for 60s ...`。新客户端的 `TOKEN_DOWNLOAD_ERROR` 让这条路基本不再触发,看门狗只用来兜住「客户端卡住/老客户端」。
|
||||
|
||||
- `-32006` 会额外在审计日志里记一条 `CALL_DENIED`(§10.8),其余错误只体现在 `CALL_FAIL` 行。
|
||||
|
||||
@@ -5946,11 +5946,16 @@ VOID CMy2015RemoteDlg::MessageHandle(CONTEXT_OBJECT* ContextObject)
|
||||
// 只取首条全量,取走即 CancelIO 关子链接,停止后续增量推送(与 MFC 日志对话框
|
||||
// 持续接收增量的路径区分开)。
|
||||
uint64_t devId = ContextObject->GetClientID();
|
||||
const bool mcpLate = McpServer().TakeToolFirstPacket(devId, (BYTE)cmd);
|
||||
if (McpServer().IsPending(devId)) {
|
||||
McpServer().TakeMainResponse(devId, szBuffer, len);
|
||||
ContextObject->CancelIO();
|
||||
break;
|
||||
}
|
||||
if (mcpLate) {
|
||||
ContextObject->CancelIO(); // get_client_log 已放弃后的迟到日志子链接:不弹日志窗口
|
||||
break;
|
||||
}
|
||||
std::string logText((char*)(szBuffer + 1), len > 1 ? len - 1 : 0);
|
||||
if (!ContextObject->hDlg) {
|
||||
// 对话框尚未打开:用 SendMessage 同步打开并显示初始全量日志
|
||||
@@ -5968,10 +5973,12 @@ VOID CMy2015RemoteDlg::MessageHandle(CONTEXT_OBJECT* ContextObject)
|
||||
// P2b:MCP 挂起时接管。历史活动为「主连接 RPC」(无子链接),响应回主 context,
|
||||
// 不能 CancelIO(会断开主连接),仅同步拷贝后 break。
|
||||
uint64_t devId = ContextObject->GetClientID();
|
||||
const bool mcpLate = McpServer().TakeToolFirstPacket(devId, (BYTE)cmd);
|
||||
if (McpServer().IsPending(devId)) {
|
||||
McpServer().TakeMainResponse(devId, ContextObject->GetBuffer(0), ContextObject->GetBufferLength());
|
||||
break;
|
||||
}
|
||||
if (mcpLate) break; // get_activity_history 已放弃后的迟到包:主连接,不能 CancelIO,直接丢弃
|
||||
// 一次性快照:直接打开“历史活动”对话框展示,不占用 hDlg(避免与运行日志对话框冲突)
|
||||
std::string text((char*)(szBuffer + 1), len > 1 ? len - 1 : 0);
|
||||
CActivityDialog* dlg = new CActivityDialog(this, ContextObject->GetServer(), ContextObject);
|
||||
@@ -5982,6 +5989,17 @@ VOID CMy2015RemoteDlg::MessageHandle(CONTEXT_OBJECT* ContextObject)
|
||||
break;
|
||||
}
|
||||
case TOKEN_CLIENT_MSG: {
|
||||
// MCP 工具在飞时不弹客户端的老式提示框:新客户端在失败分支同时发结构化 token(已能
|
||||
// 让工具立即返回错误)和老 ClientMsg(只为兼容老服务端),后者会让 MCP 调用在服务端
|
||||
// UI 上弹一个模态框。有挂起请求说明这次失败已经由工具结果解释,直接丢弃并记日志。
|
||||
uint64_t devId = ContextObject->GetClientID();
|
||||
if (McpServer().IsRunning() &&
|
||||
(McpServer().IsPending(devId) || McpServer().IsFileTransferPending(devId))) {
|
||||
ClientMsg *msg =(ClientMsg*)ContextObject->InDeCompressedBuffer.GetBuffer(0);
|
||||
Mprintf("[MCP] suppress client popup dev=%llu title=%.31s text=%.512s\n",
|
||||
(unsigned long long)devId, msg->title, msg->text);
|
||||
break;
|
||||
}
|
||||
ClientMsg *msg =(ClientMsg*)ContextObject->InDeCompressedBuffer.GetBuffer(0);
|
||||
PostMessageA(WM_SHOWERRORMSG, (WPARAM)new CString(_L(msg->text)), (LPARAM)new CString(_L(msg->title)));
|
||||
break;
|
||||
@@ -6848,6 +6866,9 @@ VOID CMy2015RemoteDlg::MessageHandle(CONTEXT_OBJECT* ContextObject)
|
||||
// P2c:MCP 挂起时接管。列盘 = 取走数据后用完即关;列目录 = 转向下发
|
||||
// COMMAND_LIST_FILES、等 TOKEN_FILE_LIST(此时不关子链接,交给 TOKEN_FILE_LIST 分支收尾)。
|
||||
uint64_t devId = ContextObject->GetClientID();
|
||||
// 先取「迟到首包」标记(成功路径同样消费,不留残留):工具超时后客户端才连上来的
|
||||
// 文件管理器子链接与本包,绝不能当成人手点击去弹文件管理器窗口。
|
||||
const bool mcpLate = McpServer().TakeToolFirstPacket(devId, (BYTE)cmd);
|
||||
if (McpServer().IsPending(devId)) {
|
||||
if (McpServer().OnDriveList(devId, ContextObject, szBuffer, len))
|
||||
ContextObject->CancelIO(); // 只列盘 → 用完即关一次性子链接
|
||||
@@ -6860,6 +6881,10 @@ VOID CMy2015RemoteDlg::MessageHandle(CONTEXT_OBJECT* ContextObject)
|
||||
ContextObject->CancelIO();
|
||||
break;
|
||||
}
|
||||
if (mcpLate) {
|
||||
ContextObject->CancelIO(); // 工具已放弃后的迟到包:关子链接,不弹窗
|
||||
break;
|
||||
}
|
||||
ContextObject->EnableZstdContext(6);
|
||||
g_2015RemoteDlg->SendMessage(WM_OPENFILEMANAGERDIALOG, 0, (LPARAM)ContextObject);
|
||||
break;
|
||||
@@ -6927,10 +6952,15 @@ VOID CMy2015RemoteDlg::MessageHandle(CONTEXT_OBJECT* ContextObject)
|
||||
break;
|
||||
}
|
||||
// MCP exec_command 触发的 shell 子上下文:交给 McpServer 接管(老 cmd 管道,GBK)。
|
||||
const bool mcpLate = McpServer().TakeToolFirstPacket(devId, (BYTE)cmd);
|
||||
if (McpServer().IsTermPending(devId)) {
|
||||
McpServer().RegisterTerminalContext(devId, ContextObject, /*isPty*/false);
|
||||
break;
|
||||
}
|
||||
if (mcpLate) {
|
||||
ContextObject->CancelIO(); // 终端工具已放弃后的迟到 shell 子链接:不弹终端窗口
|
||||
break;
|
||||
}
|
||||
g_2015RemoteDlg->SendMessage(WM_OPENSHELLDIALOG, 0, (LPARAM)ContextObject);
|
||||
break;
|
||||
}
|
||||
@@ -6942,10 +6972,15 @@ VOID CMy2015RemoteDlg::MessageHandle(CONTEXT_OBJECT* ContextObject)
|
||||
break;
|
||||
}
|
||||
// MCP exec_command 触发的 PTY 子上下文:交给 McpServer 接管(ConPTY,UTF-8)。
|
||||
const bool mcpLate = McpServer().TakeToolFirstPacket(devId, (BYTE)cmd);
|
||||
if (McpServer().IsTermPending(devId)) {
|
||||
McpServer().RegisterTerminalContext(devId, ContextObject, /*isPty*/true);
|
||||
break;
|
||||
}
|
||||
if (mcpLate) {
|
||||
ContextObject->CancelIO(); // 终端工具已放弃后的迟到 PTY 子链接:不弹终端窗口
|
||||
break;
|
||||
}
|
||||
|
||||
// 三个前置条件,缺任何一个都回退到经典终端,并把原因贴到信息列表。
|
||||
// SYSTEM 场景:WebView2 不支持 LocalSystem token,会出现"窗口能弹但页面空白",
|
||||
@@ -6976,6 +7011,7 @@ VOID CMy2015RemoteDlg::MessageHandle(CONTEXT_OBJECT* ContextObject)
|
||||
// OnSystemReady 命中就绪包时接管子连接并下发写命令(返回 true、不 CancelIO),
|
||||
// 命中确认包或只读工具时返回 false,走 TakeMainResponse + CancelIO 收尾。
|
||||
uint64_t devId = ContextObject->GetClientID();
|
||||
const bool mcpLate = McpServer().TakeToolFirstPacket(devId, (BYTE)cmd);
|
||||
if (McpServer().IsPending(devId)) {
|
||||
if (McpServer().OnSystemReady(devId, ContextObject))
|
||||
break;
|
||||
@@ -6983,6 +7019,10 @@ VOID CMy2015RemoteDlg::MessageHandle(CONTEXT_OBJECT* ContextObject)
|
||||
ContextObject->CancelIO(); // 用完即关,避免子链接泄漏(仿 WebService 终端关闭)
|
||||
break;
|
||||
}
|
||||
if (mcpLate) {
|
||||
ContextObject->CancelIO(); // 进程/窗口工具已放弃后的迟到包:不弹进程管理器
|
||||
break;
|
||||
}
|
||||
g_2015RemoteDlg->SendMessage(WM_OPENSYSTEMDIALOG, 0, (LPARAM)ContextObject);
|
||||
break;
|
||||
}
|
||||
@@ -6994,8 +7034,13 @@ VOID CMy2015RemoteDlg::MessageHandle(CONTEXT_OBJECT* ContextObject)
|
||||
// P3:MCP 挂起时接管。TOKEN_REGEDIT 是客户端子链接构造即发(CRegisterManager 构造),
|
||||
// 命中则下发 COMMAND_REG_FIND 并保持子链接(等 TOKEN_REG_PATH/KEY),不打开 MFC 对话框。
|
||||
uint64_t devId = ContextObject->GetClientID();
|
||||
const bool mcpLate = McpServer().TakeToolFirstPacket(devId, (BYTE)cmd);
|
||||
if (McpServer().IsPending(devId) && McpServer().OnRegeditReady(devId, ContextObject))
|
||||
break;
|
||||
if (mcpLate) {
|
||||
ContextObject->CancelIO(); // list_registry 已放弃后的迟到子链接:不弹注册表窗口
|
||||
break;
|
||||
}
|
||||
g_2015RemoteDlg->SendMessage(WM_OPENREGISTERDIALOG, 0, (LPARAM)ContextObject);
|
||||
break;
|
||||
}
|
||||
@@ -7033,6 +7078,7 @@ VOID CMy2015RemoteDlg::MessageHandle(CONTEXT_OBJECT* ContextObject)
|
||||
// P7:control_service 的就绪/确认是同一 token,OnServiceReady 命中就绪包时接管并下发
|
||||
// COMMAND_SERVICECONFIG(返回 true、不 CancelIO),确认包走 TakeMainResponse 收尾。
|
||||
uint64_t devId = ContextObject->GetClientID();
|
||||
const bool mcpLate = McpServer().TakeToolFirstPacket(devId, (BYTE)cmd);
|
||||
if (McpServer().IsPending(devId)) {
|
||||
if (McpServer().OnServiceReady(devId, ContextObject))
|
||||
break;
|
||||
@@ -7040,6 +7086,10 @@ VOID CMy2015RemoteDlg::MessageHandle(CONTEXT_OBJECT* ContextObject)
|
||||
ContextObject->CancelIO();
|
||||
break;
|
||||
}
|
||||
if (mcpLate) {
|
||||
ContextObject->CancelIO(); // 服务工具已放弃后的迟到包:不弹服务管理器
|
||||
break;
|
||||
}
|
||||
g_2015RemoteDlg->SendMessage(WM_OPENSERVICESDIALOG, 0, (LPARAM)ContextObject);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -6491,6 +6491,8 @@ bool CMcpServer::WaitTerminalReady(uint64_t device_id, context*& subCtx, bool& i
|
||||
bool signaled = m_TermCv.wait_for(lk, std::chrono::milliseconds(timeoutMs),
|
||||
[&] { return it->second.started; });
|
||||
if (!signaled) {
|
||||
// 放弃:迟到的 shell 子连接就绪包(TOKEN_SHELL_START/TOKEN_TERMINAL_START)不能弹终端窗口。
|
||||
MarkLateFirstPacket(device_id, { (BYTE)TOKEN_SHELL_START, (BYTE)TOKEN_TERMINAL_START });
|
||||
m_TermSessions.erase(it); // 超时 → 清理
|
||||
return false;
|
||||
}
|
||||
@@ -7220,6 +7222,8 @@ bool CMcpServer::WaitPending(uint64_t device_id, std::vector<BYTE>& out, int tim
|
||||
bool signaled = m_PendingCv.wait_for(lk, std::chrono::milliseconds(timeoutMs),
|
||||
[&] { return it->second.done; });
|
||||
if (!signaled || it->second.data.empty()) {
|
||||
// 放弃:客户端可能在我们返回后才把应答首包发上来,登记吸收,别让它弹 MFC 窗口。
|
||||
MarkLateFirstPacketForTool(device_id, it->second.tool);
|
||||
m_Pending.erase(it); // 超时/空数据 → 清理
|
||||
return false;
|
||||
}
|
||||
@@ -7233,6 +7237,54 @@ void CMcpServer::ClearPending(uint64_t device_id) {
|
||||
m_Pending.erase(device_id);
|
||||
}
|
||||
|
||||
// ===== 迟到首包吸收 =====
|
||||
// 工具放弃后 5 分钟内到达的「应答首包」只吸收一次;过期即失效(不长期压制人工操作)。
|
||||
static const int kFirstPacketMarkMs = 5 * 60 * 1000;
|
||||
|
||||
void CMcpServer::MarkLateFirstPacket(uint64_t device_id, std::initializer_list<BYTE> tokens) {
|
||||
if (tokens.size() == 0) return;
|
||||
const auto now = std::chrono::steady_clock::now();
|
||||
std::lock_guard<std::mutex> lk(m_FirstPacketMutex);
|
||||
for (auto it = m_FirstPacketMarks.begin(); it != m_FirstPacketMarks.end();) {
|
||||
if (it->second.expiry <= now) it = m_FirstPacketMarks.erase(it);
|
||||
else ++it;
|
||||
}
|
||||
FirstPacketMark mk;
|
||||
mk.tokens.insert(tokens.begin(), tokens.end());
|
||||
mk.expiry = now + std::chrono::milliseconds(kFirstPacketMarkMs);
|
||||
m_FirstPacketMarks[device_id] = std::move(mk);
|
||||
}
|
||||
|
||||
// 工具 → 应答首包 token。只有「子连接第一个包会弹 MFC 窗口」的工具需要登记。
|
||||
void CMcpServer::MarkLateFirstPacketForTool(uint64_t device_id, const std::string& tool) {
|
||||
if (tool == "list_files" || tool == "download_file" || tool == "upload_file" || tool == "search_file")
|
||||
MarkLateFirstPacket(device_id, { (BYTE)TOKEN_DRIVE_LIST });
|
||||
else if (tool == "list_registry")
|
||||
MarkLateFirstPacket(device_id, { (BYTE)TOKEN_REGEDIT });
|
||||
else if (tool == "list_services" || tool == "control_service")
|
||||
MarkLateFirstPacket(device_id, { (BYTE)TOKEN_SERVERLIST });
|
||||
else if (tool == "list_processes" || tool == "kill_process")
|
||||
MarkLateFirstPacket(device_id, { (BYTE)TOKEN_PSLIST });
|
||||
else if (tool == "list_windows" || tool == "operate_window")
|
||||
MarkLateFirstPacket(device_id, { (BYTE)TOKEN_WSLIST });
|
||||
else if (tool == "get_client_log")
|
||||
MarkLateFirstPacket(device_id, { (BYTE)TOKEN_REPORT_LOG });
|
||||
else if (tool == "get_activity_history")
|
||||
MarkLateFirstPacket(device_id, { (BYTE)TOKEN_REPORT_ACTIVITY });
|
||||
}
|
||||
|
||||
bool CMcpServer::TakeToolFirstPacket(uint64_t device_id, BYTE token) {
|
||||
std::lock_guard<std::mutex> lk(m_FirstPacketMutex);
|
||||
auto it = m_FirstPacketMarks.find(device_id);
|
||||
if (it == m_FirstPacketMarks.end()) return false;
|
||||
if (it->second.expiry <= std::chrono::steady_clock::now()) { m_FirstPacketMarks.erase(it); return false; }
|
||||
if (it->second.tokens.find(token) == it->second.tokens.end()) return false; // 不是该工具的应答首包
|
||||
m_FirstPacketMarks.erase(it); // 一次性消费
|
||||
Mprintf("[MCP] absorb late first token=%d dev=%llu (tool gave up earlier)\n",
|
||||
(int)token, (unsigned long long)device_id);
|
||||
return true;
|
||||
}
|
||||
|
||||
// ===== P2c:list_files / get_screenshot 扩展 =====
|
||||
|
||||
bool CMcpServer::BeginPending(uint64_t device_id, const std::string& tool, const std::string& path) {
|
||||
@@ -7479,6 +7531,7 @@ bool CMcpServer::WaitPendingRegistry(uint64_t device_id, std::vector<BYTE>& subk
|
||||
bool signaled = m_PendingCv.wait_for(lk, std::chrono::milliseconds(timeoutMs),
|
||||
[&] { return it->second.done; });
|
||||
if (!signaled) {
|
||||
MarkLateFirstPacketForTool(device_id, it->second.tool); // 放弃后的 TOKEN_REGEDIT 不弹注册表窗口
|
||||
m_Pending.erase(it); // 超时 → 清理
|
||||
return false;
|
||||
}
|
||||
@@ -7566,6 +7619,7 @@ bool CMcpServer::WaitPendingWrite(uint64_t device_id, std::vector<BYTE>& out, in
|
||||
subCtx = it->second.subCtx;
|
||||
Mprintf("[MCP-P7] WaitPendingWrite dev=%llu TIMEOUT: signaled=%d dataEmpty=%d subCtx=%p\n",
|
||||
device_id, signaled ? 1 : 0, it->second.data.empty() ? 1 : 0, (void*)subCtx);
|
||||
MarkLateFirstPacketForTool(device_id, it->second.tool); // 就绪包迟到 → 吸收,不弹进程/服务窗口
|
||||
m_Pending.erase(it); // 超时/空数据 → 清理
|
||||
lk.unlock();
|
||||
if (subCtx) subCtx->CancelIO(); // 锁外关子连接,防孤儿子连接
|
||||
@@ -7873,7 +7927,10 @@ bool CMcpServer::WaitFileTransferDone(uint64_t device_id, int timeoutMs,
|
||||
for (auto& kv : s.fileEntries) files.push_back(kv.second);
|
||||
skipped = (int)s.skipped.size();
|
||||
|
||||
return s.done && s.error == 0;
|
||||
const bool ok = s.done && s.error == 0;
|
||||
// 放弃的文件工具:迟到的 TOKEN_DRIVE_LIST(文件管理器子链接首包)不能弹文件管理器窗口。
|
||||
if (!ok) MarkLateFirstPacketForTool(device_id, s.tool);
|
||||
return ok;
|
||||
}
|
||||
|
||||
void CMcpServer::ClearFileTransfer(uint64_t device_id) {
|
||||
|
||||
@@ -322,6 +322,15 @@ public:
|
||||
// 工具线程:等待写确认包(第二个同 token 包);超时/空数据清挂起并 CancelIO 子连接。
|
||||
bool WaitPendingWrite(uint64_t device_id, std::vector<BYTE>& out, int timeoutMs);
|
||||
|
||||
// ===== 迟到首包吸收(工具放弃后不再弹出 MFC 对话框)=====
|
||||
// 工具超时/失败清掉挂起后,客户端仍可能才把应答首包发上来(列盘、服务列表、注册表、
|
||||
// 进程列表、终端都是「子连接建成即发」)。那时已无挂起会话,MessageHandle 会把它当成
|
||||
// 人手点击而打开文件管理器/服务管理器/注册表/进程窗口/日志/终端窗口。
|
||||
// 工具放弃时按设备登记该工具的应答首包 token;包到达时一次性吸收(调用方关子连接、
|
||||
// 不弹窗)。命中即消费,过期即失效,绝不长期压制人工操作。
|
||||
// MessageHandle 各对话框分支开头调用(早于挂起判断:成功路径同样消费,不留残留)。
|
||||
bool TakeToolFirstPacket(uint64_t device_id, BYTE token);
|
||||
|
||||
// OfflineProc 调用:接管的子连接断开时清挂起(置 done 并清 subCtx,唤醒等待线程)。
|
||||
// 不擦表(由 WaitPendingWrite 持有迭代器时自行擦除,防迭代器失效);清 subCtx 使
|
||||
// 超时路径不会对已回收(连接池复用)的 context 误 CancelIO。
|
||||
@@ -359,7 +368,7 @@ public:
|
||||
bool IsKeylogEnabled() const { return m_keylogEnabled; }
|
||||
|
||||
// ===== 工具默认等待超时([settings] McpToolTimeoutMs,ini-only 键)=====
|
||||
// 慢主机上 20s 固定的工具超时太紧;调到 60s 更实用。范围 clamp 到 [1000, 120000]。
|
||||
// 慢主机上 20s 固定的工具超时太紧;调到 60s 更实用。范围 clamp 到 [1000, 600000]。
|
||||
// 改动需重启服务端生效(与其它 Mcp* 开关一致)。
|
||||
void SetToolTimeoutMs(int ms);
|
||||
int ToolTimeoutMs() const { return m_toolTimeoutMs; }
|
||||
@@ -554,6 +563,17 @@ private:
|
||||
// 清理过期墓碑(持 m_PendingMutex 调用)。
|
||||
void PruneOrphanMarksLocked(std::chrono::steady_clock::time_point now);
|
||||
|
||||
// ===== 迟到首包吸收(受 m_FirstPacketMutex 保护,独立锁避免与挂起/传输表形成锁序)=====
|
||||
// 等待函数在「超时/失败」分支调用:登记该工具放弃后可能迟到的应答首包 token。
|
||||
struct FirstPacketMark {
|
||||
std::set<BYTE> tokens;
|
||||
std::chrono::steady_clock::time_point expiry;
|
||||
};
|
||||
std::mutex m_FirstPacketMutex;
|
||||
std::map<uint64_t, FirstPacketMark> m_FirstPacketMarks;
|
||||
void MarkLateFirstPacket(uint64_t device_id, std::initializer_list<BYTE> tokens);
|
||||
void MarkLateFirstPacketForTool(uint64_t device_id, const std::string& tool);
|
||||
|
||||
// 路由表大小(已绑定 + 已吸收的子连接数)。MessageHandle 每个包都会调用
|
||||
// OnManagedSubPacket,若无会话在飞则用它无锁快速返回,避免音频/屏幕等高频
|
||||
// 子连接逐包争用 m_PendingMutex。只在持锁时更新(store)。
|
||||
|
||||
Reference in new issue
Block a user