feat(tools): propagate timeout abort signals to tool execution

This commit is contained in:
William Valentin
2026-02-15 22:05:43 -08:00
parent 0220ec10dd
commit 2cdfb66071
10 changed files with 113 additions and 18 deletions
+8 -4
View File
@@ -225,6 +225,7 @@ export class ToolExecutor {
});
let timeoutHandle: NodeJS.Timeout | undefined;
const abortController = new AbortController();
try {
const result = await Promise.race([
(async () => {
@@ -232,17 +233,20 @@ export class ToolExecutor {
const sandboxSessionId = context?.sessionId ?? `${context?.channel ?? 'unknown'}:${context?.sender ?? 'unknown'}`;
const sandbox = await this.sandboxManager.getOrCreate(sandboxSessionId);
if (toolName === 'shell.exec') {
return createSandboxedShellTool(sandbox).execute(args);
return createSandboxedShellTool(sandbox).execute(args, { signal: abortController.signal });
}
if (toolName === 'process.start') {
return createSandboxedProcessStartTool(sandbox).execute(args);
return createSandboxedProcessStartTool(sandbox).execute(args, { signal: abortController.signal });
}
}
return tool.execute(args);
return tool.execute(args, { signal: abortController.signal });
})(),
new Promise<ToolResult>((_, reject) => {
timeoutHandle = setTimeout(
() => reject(new Error(`Tool '${toolName}' timed out after ${this.defaultTimeoutMs}ms`)),
() => {
abortController.abort();
reject(new Error(`Tool '${toolName}' timed out after ${this.defaultTimeoutMs}ms`));
},
this.defaultTimeoutMs,
);
}),