@devries-cameron20 / t3code Mirror · read-only / commits / bda042aada
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 22:00 UTC

fix(server): subagent task updates reach Claude task lists (#20985)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>

Antony committed Oct 20, 2026 at 07:33 UTC bda042aadae96ff7e5f00907ed276908cffcd468
2 files changed +134 -20
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts
+99 -12
@@ -6279,7 +6279,12 @@ describe("ClaudeAdapterV2 background wake turns", () => {
6279 function taskToolFrames(
6280 tool: TaskToolCall,
6281 nextUuid: () => string,
6282 - options?: { parentToolUseId?: string; isError?: boolean; extraToolResult?: boolean },
6282 + options?: {
6283 + parentToolUseId?: string;
6284 + isError?: boolean;
6285 + extraToolResult?: boolean;
6286 + nonExecutionKind?: string;
6287 + },
6288 ): ReadonlyArray<SDKMessage> {
6289 const uuid = nextUuid();
6290 const toolUseId = `tool-${uuid}`;
@@ -6314,15 +6319,28 @@ describe("ClaudeAdapterV2 background wake turns", () => {
6319 {
6320 type: "tool_result",
6321 tool_use_id: toolUseId,
6317 - content: "Task tool finished.",
6318 - is_error: options?.isError ?? false,
6322 + content:
6323 + parentToolUseId !== null && tool.name === "TaskCreate"
6324 + ? `Task #${tool.output.task.id} created successfully: ${tool.output.task.subject}`
6325 + : parentToolUseId !== null && tool.name === "TaskUpdate"
6326 + ? tool.output.success
6327 + ? `Updated task #${tool.output.taskId} ${tool.output.updatedFields.join(", ")}`
6328 + : tool.output.error
6329 + : "Task tool finished.",
6330 + ...(options?.isError === undefined ? {} : { is_error: options.isError }),
6331 },
6332 ...(options?.extraToolResult
6333 ? [{ type: "tool_result", tool_use_id: "unrelated-tool", content: "ok" }]
6334 : []),
6335 ],
6336 },
6325 - tool_use_result: tool.output,
6337 + // Like real Claude, subagent results carry only the text, no `tool_use_result`.
6338 + ...(parentToolUseId === null ? { tool_use_result: tool.output } : {}),
6339 + ...(options?.nonExecutionKind === undefined
6340 + ? {}
6341 + : {
6342 + tool_result_meta: [{ id: toolUseId, non_execution_kind: options.nonExecutionKind }],
6343 + }),
6344 parent_tool_use_id: parentToolUseId,
6345 uuid: nextUuid(),
6346 session_id: WAKE_NATIVE_SESSION,
@@ -6361,7 +6379,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
6379 });
6380 const call = Effect.fnUntraced(function* (
6381 tool: TaskToolCall,
6364 - options?: { parentToolUseId?: string; isError?: boolean; extraToolResult?: boolean },
6382 + options?: Parameters<typeof taskToolFrames>[2],
6383 ) {
6384 for (const frame of taskToolFrames(tool, nextUuid, options)) {
6385 yield* harness.offerAndWait(frame);
@@ -6377,7 +6395,22 @@ describe("ClaudeAdapterV2 background wake turns", () => {
6395 harness.events.flatMap((event) =>
6396 event.type === "plan.updated" && event.plan.kind === "todo_list" ? [event.plan] : [],
6397 );
6380 - return { configDir, startTurn, call, finishTurn, plans };
6398 + // Registers a running subagent so frames carrying its tool_use_id as
6399 + // parent_tool_use_id are processed instead of held for an unknown owner.
6400 + const launchSubagent = (toolUseId: string) =>
6401 + harness.offerAndWait(
6402 + claudeSdkFrame({
6403 + type: "system",
6404 + subtype: "task_started",
6405 + task_id: `task-${toolUseId}`,
6406 + tool_use_id: toolUseId,
6407 + description: "Work on tasks",
6408 + task_type: "local_agent",
6409 + uuid: nextUuid(),
6410 + session_id: WAKE_NATIVE_SESSION,
6411 + }),
6412 + );
6413 + return { configDir, startTurn, call, launchSubagent, finishTurn, plans };
6414 });
6415
6416 const makeTaskToolHarness = makeTaskToolHarnessWithOptions();
@@ -6691,20 +6724,74 @@ describe("ClaudeAdapterV2 background wake turns", () => {
6724 ),
6725 );
6726
6694 - it.effect("keeps subagent TaskCreate, TaskUpdate and TaskList out of the main plan", () =>
6727 + it.effect("applies subagent task tools to the parent turn's shared task list", () =>
6728 Effect.gen(function* () {
6729 const harness = yield* makeTaskToolHarness;
6730 yield* harness.startTurn();
6731 yield* harness.call(createTask("1", "Main task"));
6732 + yield* harness.launchSubagent("tool-parent-agent");
6733 const child = { parentToolUseId: "tool-parent-agent" };
6700 - yield* harness.call(createTask("2", "Child task"), child);
6734 yield* harness.call(updateTask({ taskId: "1", status: "completed" }), child);
6702 - yield* harness.call({ name: "TaskList", input: {}, output: { tasks: [] } }, child);
6703 - yield* harness.call(updateTask({ taskId: "1", status: "in_progress" }));
6735 + yield* harness.call(createTask("2", "Child task"), child);
6736 + yield* harness.call(
6737 + {
6738 + name: "TaskUpdate",
6739 + input: { taskId: "2", status: "completed" },
6740 + output: {
6741 + success: false,
6742 + taskId: "2",
6743 + updatedFields: [],
6744 + error: "Tests must pass before completing.",
6745 + },
6746 + },
6747 + child,
6748 + );
6749 + yield* harness.call(updateTask({ taskId: "2", status: "in_progress" }), {
6750 + ...child,
6751 + isError: true,
6752 + });
6753 + // A cancelled call never ran, even without `is_error`.
6754 + yield* harness.call(updateTask({ taskId: "2", status: "completed" }), {
6755 + ...child,
6756 + nonExecutionKind: "cancelled",
6757 + });
6758 + yield* harness.finishTurn();
6759 + const plans = harness.plans();
6760 + assert.lengthOf(plans, 3);
6761 + assert.equal(new Set(plans.map((plan) => plan.id)).size, 1);
6762 + assert.deepEqual(plans.at(-1)?.steps, [
6763 + { id: "task-1", text: "Main task", status: "completed" },
6764 + { id: "task-2", text: "Child task", status: "pending" },
6765 + ]);
6766 + }).pipe(
6767 + Effect.scoped,
6768 + Effect.provide(
6769 + Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),
6770 + ),
6771 + ),
6772 + );
6773 +
6774 + it.effect("recovers persisted tasks when a subagent's TaskList comes first", () =>
6775 + Effect.gen(function* () {
6776 + const fs = yield* FileSystem.FileSystem;
6777 + const harness = yield* makeTaskToolHarness;
6778 + const tasksDir = `${harness.configDir}/tasks/${WAKE_NATIVE_SESSION}`;
6779 + yield* fs.makeDirectory(tasksDir, { recursive: true });
6780 + yield* fs.writeFileString(
6781 + `${tasksDir}/1.json`,
6782 + JSON.stringify({ id: "1", subject: "Inspect", status: "pending", blockedBy: [] }),
6783 + );
6784 +
6785 + yield* harness.startTurn();
6786 + yield* harness.launchSubagent("tool-parent-agent");
6787 + yield* harness.call(
6788 + { name: "TaskList", input: {}, output: { tasks: [] } },
6789 + { parentToolUseId: "tool-parent-agent" },
6790 + );
6791 + yield* harness.call(updateTask({ taskId: "1", status: "completed" }));
6792 yield* harness.finishTurn();
6705 - assert.lengthOf(harness.plans(), 2);
6793 assert.deepEqual(harness.plans().at(-1)?.steps, [
6707 - { id: "task-1", text: "Main task", status: "running" },
6794 + { id: "task-1", text: "Inspect", status: "completed" },
6795 ]);
6796 }).pipe(
6797 Effect.scoped,
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
+35 -8
@@ -3606,12 +3606,20 @@ function applyClaudeTaskTool(
3606 }
3607 if (toolName === "TaskCreate") {
3608 const created = claudeTaskField(result, "task");
3609 - const id = claudeTaskString(created, "id");
3610 - const text = claudeTaskString(created, "subject") ?? claudeTaskString(input, "subject");
3609 + const fromText = claudeCreatedTaskFromText(result);
3610 + const id = claudeTaskString(created, "id") ?? fromText?.id;
3611 + const text =
3612 + claudeTaskString(created, "subject") ??
3613 + fromText?.subject ??
3614 + claudeTaskString(input, "subject");
3615 if (id === undefined || text === undefined) return undefined;
3616 return new Map(tasks).set(id, { text, status: "pending" });
3617 }
3614 - if (toolName !== "TaskUpdate" || claudeTaskField(result, "success") === false) {
3618 + if (
3619 + toolName !== "TaskUpdate" ||
3620 + claudeTaskField(result, "success") === false ||
3621 + (typeof result === "string" && !result.startsWith("Updated task #"))
3622 + ) {
3623 return undefined;
3624 }
3625 const id = claudeTaskString(input, "taskId") ?? claudeTaskString(result, "taskId");
@@ -3629,6 +3637,16 @@ function applyClaudeTaskTool(
3637 return new Map(tasks).set(id, { text, status });
3638 }
3639
3640 +// Subagent results carry no structured `tool_use_result`, only the text
3641 +// "Task #3 created successfully: <subject>".
3642 +function claudeCreatedTaskFromText(
3643 + result: unknown,
3644 +): { readonly id: string; readonly subject: string } | undefined {
3645 + const match =
3646 + typeof result === "string" ? /^Task #(\S+) created successfully: (.+)$/s.exec(result) : null;
3647 + return match === null ? undefined : { id: match[1]!, subject: match[2]!.trim() };
3648 +}
3649 +
3650 const CLAUDE_TASK_TOOL_NAMES = new Set(["TaskCreate", "TaskUpdate", "TaskList"]);
3651 const decodeClaudeTaskFile = Schema.decodeUnknownOption(
3652 Schema.fromJsonString(
@@ -8141,17 +8159,26 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
8159 output,
8160 completedAt: yield* DateTime.now,
8161 });
8162 + // Subagents write to the session's shared task store, so their
8163 + // task tools update the parent turn's list. Failed or never-run
8164 + // calls changed nothing.
8165 if (
8145 - parentToolUseId === null &&
8166 + claudeToolNonExecutionKind(message, toolResult.tool_use_id) === undefined &&
8167 !isClaudeToolResultError(toolResult) &&
8168 CLAUDE_TASK_TOOL_NAMES.has(toolCall.toolName)
8169 ) {
8170 const taskLists = yield* Ref.get(taskListsByNativeThread);
8171 const knownTaskList = taskLists.get(liveQuery.nativeThreadId);
8151 - // TaskList already supplies a snapshot. Mutations need Claude's persisted
8152 - // list once; afterward the cache also records an unavailable store.
8172 + const outputValue = claudeNativeToolOutputValue(output);
8173 + // A structured TaskList already supplies a snapshot. Anything else, including
8174 + // a subagent's text-only TaskList, needs Claude's persisted list once;
8175 + // afterward the cache also records an unavailable store.
8176 const storedTaskList =
8154 - !taskLists.has(liveQuery.nativeThreadId) && toolCall.toolName !== "TaskList"
8177 + !taskLists.has(liveQuery.nativeThreadId) &&
8178 + !(
8179 + toolCall.toolName === "TaskList" &&
8180 + Array.isArray(claudeTaskField(outputValue, "tasks"))
8181 + )
8182 ? yield* readClaudeTaskList({
8183 environment: adapterOptions.environment,
8184 cwd: context.input.runtimePolicy.cwd,
@@ -8166,7 +8193,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
8193 knownTaskList ?? storedTaskList ?? new Map(),
8194 toolCall.toolName,
8195 claudeNativeToolInputValue(toolCall.input),
8169 - claudeNativeToolOutputValue(output),
8196 + outputValue,
8197 ) ?? storedTaskList;
8198 yield* Ref.set(
8199 taskListsByNativeThread,