Skip to content

Commit 82e23b6

Browse files
TonybynMp4claude
andcommitted
fix(server): deleted Claude tasks leave the task list
TaskUpdate with status "deleted" was read as pending, so deleted tasks stayed in the list until Claude called TaskList. Remove them instead, and emit the list when it becomes empty so the composer clears it. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 9b5963d commit 82e23b6

2 files changed

Lines changed: 51 additions & 8 deletions

File tree

‎apps/server/src/provider/Layers/ClaudeAdapter.test.ts‎

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@ import {
5050
import { ProviderAdapterProcessError, ProviderAdapterValidationError } from "../Errors.ts";
5151
import type { ClaudeAdapterShape } from "../Services/ClaudeAdapter.ts";
5252
import type { ClaudeScopedLimitNames } from "./claudeUsageLimits.ts";
53-
import { makeClaudeAdapter, type ClaudeAdapterLiveOptions } from "./ClaudeAdapter.ts";
53+
import {
54+
applyClaudeTaskToolResult,
55+
makeClaudeAdapter,
56+
type ClaudeAdapterLiveOptions,
57+
} from "./ClaudeAdapter.ts";
5458
const decodeClaudeSettings = Schema.decodeSync(ClaudeSettings);
5559
const encodeUnknownJsonString = Schema.encodeSync(Schema.fromJsonString(Schema.Unknown));
5660

@@ -8367,3 +8371,41 @@ describe("ClaudeAdapterLive", () => {
83678371
);
83688372
});
83698373
});
8374+
8375+
describe("applyClaudeTaskToolResult", () => {
8376+
const taskList = () => new Map() as Parameters<typeof applyClaudeTaskToolResult>[0];
8377+
const create = (tasks: ReturnType<typeof taskList>, id: string, subject: string) =>
8378+
applyClaudeTaskToolResult(
8379+
tasks,
8380+
{ toolName: "TaskCreate", input: { subject } },
8381+
{ task: { id, subject } },
8382+
);
8383+
8384+
it("removes tasks that TaskUpdate deletes", () => {
8385+
const tasks = taskList();
8386+
create(tasks, "1", "Inspect");
8387+
create(tasks, "2", "Ship");
8388+
8389+
assert.isTrue(
8390+
applyClaudeTaskToolResult(
8391+
tasks,
8392+
{ toolName: "TaskUpdate", input: { taskId: "2", status: "deleted" } },
8393+
{ success: true, taskId: "2" },
8394+
),
8395+
);
8396+
assert.deepEqual([...tasks.keys()], ["1"]);
8397+
});
8398+
8399+
it("reports a change when TaskList empties the list", () => {
8400+
const tasks = taskList();
8401+
create(tasks, "1", "Inspect");
8402+
8403+
assert.isTrue(
8404+
applyClaudeTaskToolResult(tasks, { toolName: "TaskList", input: {} }, { tasks: [] }),
8405+
);
8406+
assert.equal(tasks.size, 0);
8407+
assert.isFalse(
8408+
applyClaudeTaskToolResult(tasks, { toolName: "TaskList", input: {} }, { tasks: [] }),
8409+
);
8410+
});
8411+
});

‎apps/server/src/provider/Layers/ClaudeAdapter.ts‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,9 +1172,9 @@ function readClaudeTaskFromResult(
11721172
: undefined;
11731173
}
11741174

1175-
function applyClaudeTaskToolResult(
1175+
export function applyClaudeTaskToolResult(
11761176
tasks: Map<string, ClaudeTaskState>,
1177-
tool: ToolInFlight,
1177+
tool: Pick<ToolInFlight, "toolName" | "input">,
11781178
result: Record<string, unknown> | undefined,
11791179
): boolean {
11801180
if (!isClaudeTaskTool(tool.toolName)) {
@@ -1187,6 +1187,7 @@ function applyClaudeTaskToolResult(
11871187
if (!Array.isArray(resultTasks)) {
11881188
return false;
11891189
}
1190+
const hadTasks = tasks.size > 0;
11901191
tasks.clear();
11911192
for (const entry of resultTasks) {
11921193
if (entry === null || typeof entry !== "object" || Array.isArray(entry)) {
@@ -1205,7 +1206,7 @@ function applyClaudeTaskToolResult(
12051206
blockedBy: new Set(readStringArray(task.blockedBy)),
12061207
});
12071208
}
1208-
return tasks.size > 0;
1209+
return hadTasks || tasks.size > 0;
12091210
}
12101211

12111212
if (tool.toolName === "TaskCreate") {
@@ -1228,6 +1229,9 @@ function applyClaudeTaskToolResult(
12281229
if (!taskId) {
12291230
return false;
12301231
}
1232+
if (tool.input.status === "deleted") {
1233+
return tasks.delete(taskId);
1234+
}
12311235
const task = tasks.get(taskId);
12321236
if (!task) {
12331237
return false;
@@ -2632,11 +2636,8 @@ export const makeClaudeAdapter = Effect.fn("makeClaudeAdapter")(function* (
26322636
readonly rawPayload: unknown;
26332637
},
26342638
) {
2639+
// An empty plan is sent on purpose: it clears the list once every task is deleted.
26352640
const plan = planStepsFromClaudeTasks(context.claudeTasks);
2636-
if (plan.length === 0) {
2637-
return;
2638-
}
2639-
26402641
const stamp = yield* makeEventStamp();
26412642
yield* offerRuntimeEvent({
26422643
type: "turn.plan.updated",

0 commit comments

Comments
 (0)