-
Notifications
You must be signed in to change notification settings - Fork 3
feat: add timeout guard for tool execution #37
Copy link
Copy link
Closed
Labels
coreAffects @chatcops/core packageAffects @chatcops/core packageenhancementNew feature or requestNew feature or request
Description
Context
PR #34 wired up tool calling execution across all providers. Currently, if tool.execute() hangs (e.g., a slow webhook target or external API), the entire SSE stream blocks indefinitely with no timeout.
What to do
Add a configurable timeout wrapper around tool execution in packages/core/src/providers/tool-execution.ts:
const TOOL_TIMEOUT_MS = 30_000; // 30 seconds default
export async function executeToolCall(
params: ProviderChatParams,
call: ProviderToolCall
): Promise<ToolResult> {
if (!params.toolExecutor) {
return { success: false, message: `No tool executor for "${call.name}".` };
}
try {
const result = await Promise.race([
params.toolExecutor(call),
new Promise<never>((_, reject) =>
setTimeout(() => reject(new Error('Tool execution timed out')), TOOL_TIMEOUT_MS)
),
]);
return result;
} catch (error) {
return toToolFailure(error);
}
}On timeout, the tool returns a failure result and the AI can respond gracefully (e.g., "Sorry, I couldn't complete that action").
Optionally, make the timeout configurable via ProviderChatParams or ChatCopsServerConfig.
Files to modify
| File | Change |
|---|---|
packages/core/src/providers/tool-execution.ts |
Add Promise.race timeout wrapper |
packages/core/src/types.ts |
Optionally add toolTimeout to ProviderChatParams |
Tests to add
- Tool execution that exceeds timeout returns failure result
- Tool execution within timeout returns normal result
- Timeout value is configurable
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
coreAffects @chatcops/core packageAffects @chatcops/core packageenhancementNew feature or requestNew feature or request