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

Closed
opened 2026-07-21 21:55:42 +08:00 by thzxx · 1 comment
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
Author
Owner

修复说明

文件: electron/harness/tools/registry.ts

修复: 对 tool.definition.timeoutMs 添加类型与有效性校验(typeof === 'number' && > 0),无效时回退到默认值 120_000ms,防止 setTimeout(fn, undefined) 被解释为 setTimeout(fn, 0) 立即触发超时。

验证: tsc --noEmit 类型检查通过。

## 修复说明 **文件**: `electron/harness/tools/registry.ts` **修复**: 对 `tool.definition.timeoutMs` 添加类型与有效性校验(`typeof === 'number' && > 0`),无效时回退到默认值 `120_000ms`,防止 `setTimeout(fn, undefined)` 被解释为 `setTimeout(fn, 0)` 立即触发超时。 **验证**: `tsc --noEmit` 类型检查通过。
thzxx closed this issue 2026-07-22 09:42: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