fix: 工具执行 IPC 卡死问题 — 多层超时保护

问题:确认工具操作后 Agent Loop 卡死在'正在思考中',工具未执行。

修复:
- tool-registry.ts: executeTool() 新增 25 秒 IPC 硬超时
- agent-engine.ts: executeTool 内部 .catch 捕获异常,防止 reject 逃逸
- ipc.ts: tool:execute handler 外层 try-catch 确保始终返回响应
- 全链路添加 console.log 便于排查
This commit is contained in:
Metona Dev
2026-04-06 20:41:56 +08:00
parent 509e402844
commit a9c56582d0
3 changed files with 34 additions and 12 deletions
+10 -1
View File
@@ -159,10 +159,19 @@ export async function executeTool(toolName: string, args: Record<string, unknown
}
try {
const result = await bridge.tool.execute(toolName, args);
console.log('[ToolRegistry] 开始执行:', toolName, args);
// IPC 调用 + 25 秒硬超时(比 agent-engine 的 30 秒先触发)
const result = await Promise.race([
bridge.tool.execute(toolName, args),
new Promise<ToolResult>((_, reject) =>
setTimeout(() => reject(new Error(`工具 ${toolName} IPC 超时(25秒)`)), 25000)
)
]);
console.log('[ToolRegistry] 执行完成:', toolName, result);
return result;
} catch (err) {
logError(`工具异常: ${toolName}`, (err as Error).message);
console.error('[ToolRegistry] 执行异常:', toolName, err);
return { success: false, error: (err as Error).message };
}
}