Skip to content

Commit 421e319

Browse files
authored
fix(llm-task): forward tool cancellation (#124673)
1 parent e0e9e27 commit 421e319

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

‎extensions/llm-task/src/llm-task-tool.test.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,20 @@ describe("llm-task tool (json-only)", () => {
382382
expect(call.messages).toEqual([{ role: "user", content: expect.stringContaining("TASK:\nx") }]);
383383
});
384384

385+
it("forwards caller cancellation to the isolated completion", async () => {
386+
const controller = new AbortController();
387+
const cancellation = new Error("caller cancelled");
388+
complete.mockImplementationOnce(async (params) => {
389+
controller.abort(cancellation);
390+
params.signal?.throwIfAborted();
391+
return completionResult(params, '{"ok":true}');
392+
});
393+
394+
const tool = createLlmTaskTool(fakeApi());
395+
await expect(tool.execute("id", { prompt: "x" }, controller.signal)).rejects.toBe(cancellation);
396+
expect(firstIsolatedCompletionCall().signal).toBe(controller.signal);
397+
});
398+
385399
it("rejects malformed numeric run options before dispatch", async () => {
386400
const tool = createLlmTaskTool(fakeApi());
387401

‎extensions/llm-task/src/llm-task-tool.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export function createLlmTaskTool(api: OpenClawPluginApi) {
132132
return {
133133
...llmTaskToolDefinition,
134134

135-
async execute(_id: string, params: LlmTaskParams) {
135+
async execute(_id: string, params: LlmTaskParams, signal?: AbortSignal) {
136136
const prompt = typeof params.prompt === "string" ? params.prompt : "";
137137
if (!prompt.trim()) {
138138
throw new Error("prompt required");
@@ -235,6 +235,7 @@ export function createLlmTaskTool(api: OpenClawPluginApi) {
235235
reasoning: thinkLevel,
236236
maxTokens: streamParams.maxTokens,
237237
temperature: streamParams.temperature,
238+
signal,
238239
purpose: "llm-task",
239240
execution: {
240241
mode: "isolated-agent-runtime",

0 commit comments

Comments
 (0)