feat(tools): propagate timeout abort signals to tool execution
This commit is contained in:
@@ -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,
|
||||
);
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user