Fix(mcp): bound host_inspect, precheck remote_open, name the busy holder
Three smaller contract fixes that remove ways for an agent call to hang or fail without an explanation: - host_inspect with several aspects opens one sub-connection per aspect (5s ready + 12s list each), so all ten could run ~170s and outlive the caller's HTTP timeout. After 60s no new aspect is started; the running one finishes on its own timeout and the skipped ones land in errors.<aspect> with code -32001 and a "skipped:" message, so the model can retry with fewer aspects. - remote_open checked nothing before opening the hidden screen session. A Linux host that declares capability bits but not CLIENT_CAP_SCREEN_PREVIEW has no X11 display, so capture and injection cannot work: return -32005 immediately instead of waiting out timeout_ms and then reporting a sub-connection timeout. Android is deliberately excluded -- its SCREEN_PREVIEW bit tracks accessibility (API 30+ takeScreenshot for get_screenshot), while remote control uses MediaProjection capture and dispatchGesture, which can work without it. Old hosts with empty caps are still let through. - The -32003 busy errors in remote_open now append the DescribeBusy suffix (tool, elapsed), matching the other busy paths. tools.json descriptions are kept byte-identical to the C++ literals. Debug build green; check_platform_table, gen_go_tools --check and go test ./... pass. Co-Authored-By: deepseek-flash
This commit is contained in:
1 parent
d49ebe521d
commit
61b9031269
3 files changed
+46
-7
No files matched your search
@@ -52,6 +52,11 @@ const int kActionTimeoutMs = 12000; // 动作 → 客户端自动回的刷新
|
||||
// 每步最多 12s,故留 60s 余量;单步等待再按剩余时间收敛。
|
||||
const int kSessionDeadlineMs = 60000;
|
||||
|
||||
// host_inspect 多 aspect 的总预算(软截止):每个 aspect 最坏 5s 就绪 + 12s 列表,10 个
|
||||
// 全选要 170s,HTTP 调用方会先超时。60 秒后不再下发新的 aspect,正在跑的那个按自身
|
||||
// 超时跑完;跳过的逐个记入 errors,让调用方看到「没来得及取」而不是一直等。
|
||||
const int kInspectTotalBudgetMs = 60000;
|
||||
|
||||
// 单个包的上限:正常列表远小于此;超过即视为异常,置 clientError 并断开子连接。
|
||||
const size_t kMaxPacketBytes = 8u * 1024u * 1024u;
|
||||
|
||||
@@ -2194,9 +2199,24 @@ std::string BuildHostInspect(const Json::Value& id, const Json::Value& args,
|
||||
Json::Value errors(Json::objectValue);
|
||||
std::string summary;
|
||||
int okCount = 0, failCount = 0;
|
||||
const auto deadline = std::chrono::steady_clock::now() +
|
||||
std::chrono::milliseconds(kInspectTotalBudgetMs);
|
||||
for (const InspectAspect* a : aspects) {
|
||||
InspectRun run;
|
||||
if (!summary.empty()) summary += u8";";
|
||||
// 总预算用尽:剩余的 aspect 不再下发。逐个记入 errors(而不是让整个调用失败),
|
||||
// 调用方据此知道是「没来得及取」,可以少选几项重试。
|
||||
if (std::chrono::steady_clock::now() >= deadline) {
|
||||
Json::Value e(Json::objectValue);
|
||||
e["code"] = -32001;
|
||||
e["message"] = std::string("skipped: host_inspect used up its ") +
|
||||
std::to_string(kInspectTotalBudgetMs / 1000) +
|
||||
"s budget; retry with fewer aspects or a faster host";
|
||||
errors[a->name] = e;
|
||||
failCount++;
|
||||
summary += std::string(a->what) + u8":跳过(总预算用尽)";
|
||||
continue;
|
||||
}
|
||||
InspectRun run;
|
||||
if (RunInspectAspect(*a, id, args, parent, run)) {
|
||||
results[a->name] = run.sc;
|
||||
okCount++;
|
||||
@@ -3188,7 +3208,9 @@ void AppendTools(Json::Value& tools) {
|
||||
u8"total 为命中数、totalAll 为该项全部条目数。"
|
||||
u8"单个 aspect 时顶层就是该项的列表结果(与合并前的旧工具一致);多个 aspect 时汇总在 "
|
||||
u8"results.<aspect>,某个 aspect 失败只记入 errors.<aspect>、不影响其它 aspect,全部失败才 isError=true。"
|
||||
u8"每多选一个 aspect 就多一次子连接,耗时线性增长,不需要的不要选。只读。",
|
||||
u8"每多选一个 aspect 就多一次子连接,耗时线性增长,不需要的不要选;多个 aspect 共用 "
|
||||
u8"60 秒预算,用尽后不再下发新的 aspect(正在跑的会跑完),跳过的逐个记入 errors"
|
||||
u8"(code=-32001,message 以 skipped 开头),少选几项重试即可。只读。",
|
||||
BuildHostInspectInputSchema(), BuildHostInspectOutputSchema());
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user