@devries-cameron20 / t3code-1 / commits / 29aec6b887
Fork 0

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

fix(server): Claude task lists survive a server restart (#18398)

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

Antony committed Oct 20, 2026 at 02:04 UTC 29aec6b887796cd435d7c27e43120b6ba6d7275e
2 files changed +211 -49
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts
+131 -38
@@ -5295,45 +5295,57 @@ describe("ClaudeAdapterV2 background wake turns", () => {
5295 ];
5296 }
5297
5298 - const makeTaskToolHarness = Effect.gen(function* () {
5299 - const harness = yield* makeWakeHarness;
5300 - let sequence = 600;
5301 - let turn = 0;
5302 - const nextUuid = () => `00000000-0000-4000-8000-${String(++sequence).padStart(12, "0")}`;
5303 - const startTurn = Effect.fnUntraced(function* () {
5304 - turn++;
5305 - yield* harness.runtime.startTurn(
5306 - makeClaudeTestTurnInput({
5307 - threadId: harness.threadId,
5308 - providerThread: harness.providerThread,
5309 - now: yield* DateTime.now,
5310 - attemptId: RunAttemptId.make(`attempt-claude-task-tools-${turn}`),
5311 - providerTurnOrdinal: turn,
5312 - text: "Update the task list.",
5313 - attachments: [],
5314 - }),
5315 - );
5316 - });
5317 - const call = Effect.fnUntraced(function* (
5318 - tool: TaskToolCall,
5319 - options?: { parentToolUseId?: string; isError?: boolean; extraToolResult?: boolean },
5320 - ) {
5321 - for (const frame of taskToolFrames(tool, nextUuid, options)) {
5322 - yield* harness.offerAndWait(frame);
5323 - }
5324 - });
5325 - const finishTurn = Effect.fnUntraced(function* () {
5326 - yield* harness.offerAndWait(
5327 - makeResultFrame({ uuid: nextUuid(), result: "Task list updated." }),
5328 - );
5329 - yield* Queue.take(harness.terminalReceipts);
5298 + const makeTaskToolHarnessWithOptions = (environment: NodeJS.ProcessEnv = {}) =>
5299 + Effect.gen(function* () {
5300 + const configDir = yield* (yield* FileSystem.FileSystem).makeTempDirectoryScoped({
5301 + prefix: "t3-claude-tasks-",
5302 + });
5303 + const path = yield* Path.Path;
5304 + const harness = yield* makeWakeHarnessWithOptions({
5305 + environment: {
5306 + CLAUDE_CONFIG_DIR: path.relative(CLAUDE_TEST_RUNTIME_POLICY.cwd ?? ".", configDir),
5307 + ...environment,
5308 + },
5309 + });
5310 + let sequence = 600;
5311 + let turn = 0;
5312 + const nextUuid = () => `00000000-0000-4000-8000-${String(++sequence).padStart(12, "0")}`;
5313 + const startTurn = Effect.fnUntraced(function* () {
5314 + turn++;
5315 + yield* harness.runtime.startTurn(
5316 + makeClaudeTestTurnInput({
5317 + threadId: harness.threadId,
5318 + providerThread: harness.providerThread,
5319 + now: yield* DateTime.now,
5320 + attemptId: RunAttemptId.make(`attempt-claude-task-tools-${turn}`),
5321 + providerTurnOrdinal: turn,
5322 + text: "Update the task list.",
5323 + attachments: [],
5324 + }),
5325 + );
5326 + });
5327 + const call = Effect.fnUntraced(function* (
5328 + tool: TaskToolCall,
5329 + options?: { parentToolUseId?: string; isError?: boolean; extraToolResult?: boolean },
5330 + ) {
5331 + for (const frame of taskToolFrames(tool, nextUuid, options)) {
5332 + yield* harness.offerAndWait(frame);
5333 + }
5334 + });
5335 + const finishTurn = Effect.fnUntraced(function* () {
5336 + yield* harness.offerAndWait(
5337 + makeResultFrame({ uuid: nextUuid(), result: "Task list updated." }),
5338 + );
5339 + return yield* Queue.take(harness.terminalReceipts);
5340 + });
5341 + const plans = () =>
5342 + harness.events.flatMap((event) =>
5343 + event.type === "plan.updated" && event.plan.kind === "todo_list" ? [event.plan] : [],
5344 + );
5345 + return { configDir, startTurn, call, finishTurn, plans };
5346 });
5331 - const plans = () =>
5332 - harness.events.flatMap((event) =>
5333 - event.type === "plan.updated" && event.plan.kind === "todo_list" ? [event.plan] : [],
5334 - );
5335 - return { startTurn, call, finishTurn, plans };
5336 - });
5347 +
5348 + const makeTaskToolHarness = makeTaskToolHarnessWithOptions();
5349
5350 const createTask = (id: string, subject: string): TaskToolCall => ({
5351 name: "TaskCreate",
@@ -5494,6 +5506,87 @@ describe("ClaudeAdapterV2 background wake turns", () => {
5506 ),
5507 );
5508
5509 + it.effect.each([
5510 + {
5511 + tool: updateTask({ taskId: "2", status: "completed" }),
5512 + listId: undefined,
5513 + directory: WAKE_NATIVE_SESSION,
5514 + status: "completed",
5515 + },
5516 + {
5517 + tool: createTask("2", "Implement"),
5518 + listId: " list/ID ",
5519 + directory: "list-ID",
5520 + status: "pending",
5521 + },
5522 + ] as const)(
5523 + "recovers persisted tasks on the first $tool.name after restart",
5524 + ({ tool, listId, directory, status }) =>
5525 + Effect.gen(function* () {
5526 + const fs = yield* FileSystem.FileSystem;
5527 + const harness = yield* makeTaskToolHarnessWithOptions({ CLAUDE_CODE_TASK_LIST_ID: listId });
5528 + const tasksDir = `${harness.configDir}/tasks/${directory}`;
5529 + yield* fs.makeDirectory(tasksDir, { recursive: true });
5530 + // The native tool has already written its result before emitting the SDK frame.
5531 + for (const task of [
5532 + { id: "1", subject: "Inspect", status: "completed" },
5533 + { id: "2", subject: "Implement", status },
5534 + { id: "3", subject: "Internal", status: "pending", metadata: { _internal: true } },
5535 + ]) {
5536 + yield* fs.writeFileString(
5537 + `${tasksDir}/${task.id}.json`,
5538 + JSON.stringify({ description: "", blocks: [], blockedBy: [], ...task }),
5539 + );
5540 + }
5541 + yield* fs.writeFileString(`${tasksDir}/4.json`, "{");
5542 + yield* fs.makeDirectory(`${tasksDir}/5.json`);
5543 +
5544 + yield* harness.startTurn();
5545 + yield* harness.call(tool);
5546 + assert.equal((yield* harness.finishTurn()).status, "completed");
5547 + assert.deepEqual(
5548 + harness.plans().map((plan) => plan.steps),
5549 + [
5550 + [
5551 + { id: "task-1", text: "Inspect", status: "completed" },
5552 + { id: "task-2", text: "Implement", status },
5553 + ],
5554 + ],
5555 + );
5556 + }).pipe(
5557 + Effect.scoped,
5558 + Effect.provide(
5559 + Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),
5560 + ),
5561 + ),
5562 + );
5563 +
5564 + it.effect(
5565 + "publishes an empty task list when the first TaskUpdate after restart deletes the last task",
5566 + () =>
5567 + Effect.gen(function* () {
5568 + const fs = yield* FileSystem.FileSystem;
5569 + const harness = yield* makeTaskToolHarness;
5570 + const tasksDir = `${harness.configDir}/tasks/${WAKE_NATIVE_SESSION}`;
5571 + // Claude has removed the task file before emitting the SDK frame.
5572 + yield* fs.makeDirectory(tasksDir, { recursive: true });
5573 + yield* fs.writeFileString(`${tasksDir}/.highwatermark`, "1");
5574 +
5575 + yield* harness.startTurn();
5576 + yield* harness.call(updateTask({ taskId: "1", status: "deleted" }));
5577 + assert.equal((yield* harness.finishTurn()).status, "completed");
5578 + assert.deepEqual(
5579 + harness.plans().map((plan) => plan.steps),
5580 + [[]],
5581 + );
5582 + }).pipe(
5583 + Effect.scoped,
5584 + Effect.provide(
5585 + Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),
5586 + ),
5587 + ),
5588 + );
5589 +
5590 it.effect.each(["success false", "error result", "unknown id"] as const)(
5591 "does not emit a plan update for TaskUpdate with %s",
5592 (reason) =>
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
+80 -11
@@ -60,6 +60,7 @@ import {
60 import {
61 type ChatAttachment,
62 ClaudeSettings,
63 + TrimmedNonEmptyString,
64 defaultInstanceIdForDriver,
65 type ModelSelection,
66 type OrchestrationV2ConversationMessage,
@@ -128,6 +129,7 @@ import { signalProcessGroup } from "@t3tools/provider-core/server/processGroup";
129 import {
130 claudeSignedOutMessage,
131 makeClaudeEnvironment,
132 + resolveClaudeHomePath,
133 } from "../../provider/Drivers/ClaudeHome.ts";
134 import {
135 BUNDLED_CLAUDE_MODEL_CATALOG,
@@ -3486,6 +3488,52 @@ function applyClaudeTaskTool(
3488 return new Map(tasks).set(id, { text, status });
3489 }
3490
3491 +const CLAUDE_TASK_TOOL_NAMES = new Set(["TaskCreate", "TaskUpdate", "TaskList"]);
3492 +const decodeClaudeTaskFile = Schema.decodeUnknownOption(
3493 + Schema.fromJsonString(
3494 + Schema.Struct({
3495 + id: TrimmedNonEmptyString,
3496 + subject: TrimmedNonEmptyString,
3497 + status: Schema.Literals(["pending", "in_progress", "completed"]),
3498 + metadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
3499 + }),
3500 + ),
3501 +);
3502 +
3503 +const readClaudeTaskList = Effect.fnUntraced(
3504 + function* (input: {
3505 + readonly environment: NodeJS.ProcessEnv;
3506 + readonly cwd: string | null | undefined;
3507 + readonly nativeThreadId: string;
3508 + }) {
3509 + const fileSystem = yield* FileSystem.FileSystem;
3510 + const path = yield* Path.Path;
3511 + const configDirOverride = input.environment.CLAUDE_CONFIG_DIR?.trim();
3512 + const configDir = configDirOverride
3513 + ? path.resolve(input.cwd ?? ".", configDirOverride)
3514 + : yield* resolveClaudeHomePath({ homePath: "" });
3515 + const listId = input.environment.CLAUDE_CODE_TASK_LIST_ID?.trim() || input.nativeThreadId;
3516 + const directory = path.join(configDir, "tasks", listId.replace(/[^a-zA-Z0-9_-]/g, "-"));
3517 + const tasks = new Map<string, Omit<OrchestrationV2PlanStep, "id">>();
3518 + const names = (yield* fileSystem.readDirectory(directory))
3519 + .filter((name) => /^\d+\.json$/.test(name))
3520 + .toSorted((left, right) => Number.parseInt(left, 10) - Number.parseInt(right, 10));
3521 + for (const name of names) {
3522 + const contents = yield* fileSystem
3523 + .readFileString(path.join(directory, name))
3524 + .pipe(Effect.orElseSucceed(() => ""));
3525 + const task = Option.getOrUndefined(decodeClaudeTaskFile(contents));
3526 + if (task === undefined || task.metadata?._internal) continue;
3527 + tasks.set(task.id, {
3528 + text: task.subject,
3529 + status: task.status === "in_progress" ? "running" : task.status,
3530 + });
3531 + }
3532 + return tasks;
3533 + },
3534 + Effect.orElseSucceed((): ClaudeTaskList | undefined => undefined),
3535 +);
3536 +
3537 function claudeTaskSteps(tasks: ClaudeTaskList): ReadonlyArray<OrchestrationV2PlanStep> {
3538 return [...tasks].map(([id, task]) => ({ id: `task-${id}`, ...task }));
3539 }
@@ -3621,7 +3669,9 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
3669 const openedNativeThreads = yield* Ref.make(new Set<string>());
3670 const latestPlanByKind = yield* Ref.make(new Map<string, OrchestrationV2PlanArtifact>());
3671 // Claude 5 task tools edit one list per native session, across turns.
3624 - const taskListsByNativeThread = yield* Ref.make(new Map<string, ClaudeTaskList>());
3672 + const taskListsByNativeThread = yield* Ref.make(
3673 + new Map<string, ClaudeTaskList | undefined>(),
3674 + );
3675 const planIdsByNativeItem = yield* Ref.make(
3676 new Map<string, OrchestrationV2PlanArtifact["id"]>(),
3677 );
@@ -7862,19 +7912,38 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
7912 output,
7913 completedAt: yield* DateTime.now,
7914 });
7865 - if (parentToolUseId === null && !isClaudeToolResultError(toolResult)) {
7915 + if (
7916 + parentToolUseId === null &&
7917 + !isClaudeToolResultError(toolResult) &&
7918 + CLAUDE_TASK_TOOL_NAMES.has(toolCall.toolName)
7919 + ) {
7920 const taskLists = yield* Ref.get(taskListsByNativeThread);
7867 - const taskList = applyClaudeTaskTool(
7868 - taskLists.get(liveQuery.nativeThreadId) ?? new Map(),
7869 - toolCall.toolName,
7870 - claudeNativeToolInputValue(toolCall.input),
7871 - claudeNativeToolOutputValue(output),
7921 + const knownTaskList = taskLists.get(liveQuery.nativeThreadId);
7922 + // TaskList already supplies a snapshot. Mutations need Claude's persisted
7923 + // list once; afterward the cache also records an unavailable store.
7924 + const storedTaskList =
7925 + !taskLists.has(liveQuery.nativeThreadId) && toolCall.toolName !== "TaskList"
7926 + ? yield* readClaudeTaskList({
7927 + environment: adapterOptions.environment,
7928 + cwd: context.input.runtimePolicy.cwd,
7929 + nativeThreadId: liveQuery.nativeThreadId,
7930 + }).pipe(
7931 + Effect.provideService(FileSystem.FileSystem, fileSystem),
7932 + Effect.provideService(Path.Path, path),
7933 + )
7934 + : undefined;
7935 + const taskList =
7936 + applyClaudeTaskTool(
7937 + knownTaskList ?? storedTaskList ?? new Map(),
7938 + toolCall.toolName,
7939 + claudeNativeToolInputValue(toolCall.input),
7940 + claudeNativeToolOutputValue(output),
7941 + ) ?? storedTaskList;
7942 + yield* Ref.set(
7943 + taskListsByNativeThread,
7944 + new Map(taskLists).set(liveQuery.nativeThreadId, taskList ?? knownTaskList),
7945 );
7946 if (taskList !== undefined) {
7874 - yield* Ref.set(
7875 - taskListsByNativeThread,
7876 - new Map(taskLists).set(liveQuery.nativeThreadId, taskList),
7877 - );
7947 yield* emitClaudePlanProjection({
7948 context,
7949 nativeItemId: `claude-tasks:${context.providerTurnId}`,