[P1/高] ToolRegistry timeoutMs 为 undefined 时导致 0ms 立即触发超时 #12

Open
opened 2026-07-21 21:55:42 +08:00 by thzxx · 0 comments
Owner

问题类型

缺陷 / 高 / 工具系统

文件位置

electron/harness/tools/registry.ts

问题描述

工具定义中 timeoutMs 是可选字段。当工具未设置 timeoutMs 时,setTimeout(fn, undefined) 实际上等同于 setTimeout(fn, 0),导致:

  1. 工具刚启动就立即触发超时
  2. 工具根本无法正常执行
  3. LLM 收到错误的超时错误,可能误判为工具不可用

影响

  • 新增工具忘记配置 timeoutMs 时立即失败
  • 难以调试(看似超时但实际未执行)

建议修复

// 修改前
const timer = setTimeout(() => reject(...), tool.timeoutMs);

// 修改后
const timeout = tool.timeoutMs ?? this.defaultTimeoutMs ?? 120_000;
if (typeof timeout !== 'number' || timeout <= 0) {
  throw new Error(`Invalid timeoutMs: ${tool.timeoutMs}`);
}
const timer = setTimeout(() => reject(...), timeout);

并在 ToolDef 类型定义时强制类型检查。

## 问题类型 缺陷 / 高 / 工具系统 ## 文件位置 `electron/harness/tools/registry.ts` ## 问题描述 工具定义中 `timeoutMs` 是可选字段。当工具未设置 `timeoutMs` 时,`setTimeout(fn, undefined)` 实际上等同于 `setTimeout(fn, 0)`,导致: 1. 工具刚启动就立即触发超时 2. 工具根本无法正常执行 3. LLM 收到错误的超时错误,可能误判为工具不可用 ## 影响 - 新增工具忘记配置 timeoutMs 时立即失败 - 难以调试(看似超时但实际未执行) ## 建议修复 ```ts // 修改前 const timer = setTimeout(() => reject(...), tool.timeoutMs); // 修改后 const timeout = tool.timeoutMs ?? this.defaultTimeoutMs ?? 120_000; if (typeof timeout !== 'number' || timeout <= 0) { throw new Error(`Invalid timeoutMs: ${tool.timeoutMs}`); } const timer = setTimeout(() => reject(...), timeout); ``` 并在 ToolDef 类型定义时强制类型检查。
thzxx added the ??????? labels 2026-07-21 21:55:42 +08:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: MetonaTeam/metona-ai-desktop#12