TypeScript
fix(web): Claude task lists stay in the composer between turns (#18392)
Antony1ba3c781d04a
diff --git a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.tsindex 20bf645bdf9..138528263fb 100644--- a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts+++ b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts@@ -6380,6 +6380,20 @@ describe("ClaudeAdapterV2 background wake turns", () => {harness.sdkMessages,toolResults("00000000-0000-4000-8000-000000000505", ["tool-todo-2", "tool-exit-plan-1"]),);+ yield* Queue.offer(+ harness.sdkMessages,+ assistantTools("00000000-0000-4000-8000-000000000509", [+ {+ id: "tool-todo-3",+ name: "TodoWrite",+ input: { todos: [{ content: "Implement", status: "pending" }] },+ },+ ]),+ );+ yield* Queue.offer(+ harness.sdkMessages,+ toolResults("00000000-0000-4000-8000-000000000510", ["tool-todo-3"]),+ );yield* Queue.offer(harness.sdkMessages,makeResultFrame({@@ -6401,7 +6415,15 @@ describe("ClaudeAdapterV2 background wake turns", () => {);const todoItems = [...items.values()].filter((item) => item.type === "todo_list");const proposedItems = [...items.values()].filter((item) => item.type === "proposed_plan");- assert.lengthOf(todoItems, 2);+ assert.lengthOf(todoItems, 3);+ assert.equal(todoItems[1]?.status, "completed");+ assert.deepEqual(todoItems[1]?.steps, [+ { id: "todo-0", text: "Inspect", status: "completed" },+ ]);+ assert.deepEqual(todoItems[2]?.steps, [+ { id: "todo-0", text: "Implement", status: "pending" },+ ]);+ assert.equal(todoItems[1]?.runId, todoItems[2]?.runId);assert.lengthOf(proposedItems, 1);assert.equal(proposedItems[0]?.type === "proposed_plan" && proposedItems[0].markdown,@@ -6419,15 +6441,15 @@ describe("ClaudeAdapterV2 background wake turns", () => {item.type === "dynamic_tool" && item.nativeItemRef?.nativeId === "tool-exit-plan-1",),);+ const proposedPlan = [...plans.values()].find((plan) => plan.kind === "proposed_plan");+ assert.equal(proposedPlan?.status, "active");+ assert.deepEqual(harness.permissionModeChanges, ["bypassPermissions"]);assert.deepEqual([...plans.values()].filter((plan) => plan.kind === "todo_list").map((plan) => plan.status),- ["superseded", "completed"],+ ["superseded", "superseded", "active"],);- const proposedPlan = [...plans.values()].find((plan) => plan.kind === "proposed_plan");- assert.equal(proposedPlan?.status, "active");- assert.deepEqual(harness.permissionModeChanges, ["bypassPermissions"]);}).pipe(Effect.provide(Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),diff --git a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.tsindex 43ebbce9690..53c71b9eed7 100644--- a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts+++ b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts@@ -5953,7 +5953,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* ([...(previousPlan === undefined ||previousPlan.id === plan.id ||- previousPlan.status === "completed"+ (previousPlan.kind !== "todo_list" && previousPlan.status === "completed")? []: [emitProviderEvent({diff --git a/apps/server/src/orchestration-v2/ProjectionStore.test.ts b/apps/server/src/orchestration-v2/ProjectionStore.test.tsindex 64435283024..e14281979e4 100644--- a/apps/server/src/orchestration-v2/ProjectionStore.test.ts+++ b/apps/server/src/orchestration-v2/ProjectionStore.test.ts@@ -1609,6 +1609,8 @@ it.layer(layerTest)("ProjectionStoreV2", (it) => {const now = yield* DateTime.now;const nowIso = DateTime.formatIso(now);const threadId = ThreadId.make("thread:notification-turn-pages");+ const providerInstanceId = ProviderInstanceId.make("claudeAgent");+ const modelSelection = { instanceId: providerInstanceId, model: "claude-sonnet-4-6" };yield* projectionStore.apply({id: EventId.make("event:notification-turn-pages:thread"),type: "thread.created",@@ -1639,6 +1641,53 @@ it.layer(layerTest)("ProjectionStoreV2", (it) => {},});+ const providerThreadId = ProviderThreadId.make("provider-thread:notification-turn-pages");+ yield* projectionStore.apply({+ id: EventId.make("event:notification-turn-pages:provider-thread"),+ type: "provider-thread.updated",+ threadId,+ occurredAt: now,+ payload: {+ id: providerThreadId,+ driver: ProviderDriverKind.make("claudeAgent"),+ providerInstanceId,+ providerSessionId: null,+ appThreadId: threadId,+ ownerNodeId: null,+ nativeThreadRef: null,+ nativeConversationHeadRef: null,+ status: "idle",+ firstRunOrdinal: 1,+ lastRunOrdinal: 412,+ handoffIds: [],+ forkedFrom: null,+ createdAt: now,+ updatedAt: now,+ },+ });+ const planId = PlanId.make("plan:notification-turn-pages");+ const olderPlanId = PlanId.make("plan:notification-turn-pages:older");+ for (const [id, run] of [+ [olderPlanId, 1],+ [planId, 2],+ ] as const) {+ yield* projectionStore.apply({+ id: EventId.make(`event:notification-turn-pages:plan:${run}`),+ type: "plan.updated",+ threadId,+ occurredAt: now,+ payload: {+ id,+ threadId,+ runId: RunId.make(`run:notification-turn-pages:${run}`),+ nodeId: NodeId.make(`node:notification-turn-pages:${run}`),+ kind: "todo_list",+ status: "active",+ steps: [{ id: "unfinished", text: "Finish the task", status: "pending" }],+ },+ });+ }+const startedRuns = 412;const allIds: string[] = [];const startIds: string[] = [];@@ -1693,14 +1742,14 @@ it.layer(layerTest)("ProjectionStoreV2", (it) => {run_id, thread_id, ordinal, provider, provider_thread_id, status,requested_at, completed_at, payload_json) VALUES (- ${runId}, ${threadId}, ${run}, 'codex', NULL, ${status}, ${nowIso}, ${nowIso},+ ${runId}, ${threadId}, ${run}, 'claudeAgent', ${providerThreadId}, ${status}, ${nowIso}, ${nowIso},${encodeUnknownJsonString({id: runId,threadId,ordinal: run,providerInstanceId,modelSelection,- providerThreadId: null,+ providerThreadId,userMessageId: `message:notification-turn-pages:${run}`,rootNodeId: `node:notification-turn-pages:${run}`,activeAttemptId: null,@@ -1763,6 +1812,22 @@ it.layer(layerTest)("ProjectionStoreV2", (it) => {snapshotSequence: 0,});assert.strictEqual(bounded.projection.visibleTurnItems[0]?.sourceItemId, startIds[262]);+ assert.deepEqual(+ bounded.projection.plans.map((plan) => plan.id),+ [planId, olderPlanId],+ );+ assert.deepEqual(+ {+ oldRunIds: bounded.projection.runs+ .filter((run) => run.ordinal < 261)+ .map((run) => run.id),+ providerThreadIds: bounded.projection.providerThreads.map((thread) => thread.id),+ },+ {+ oldRunIds: [RunId.make("run:notification-turn-pages:2")],+ providerThreadIds: [providerThreadId],+ },+ );const loaded = bounded.projection.visibleTurnItems.map((row) => String(row.sourceItemId));let cursor = bounded.historyCursor;for (let pages = 0; cursor !== null; pages += 1) {@@ -1784,6 +1849,119 @@ it.layer(layerTest)("ProjectionStoreV2", (it) => {cursor = page.nextCursor;}assert.deepEqual(loaded, allIds);++ const completedPlan = {+ id: planId,+ threadId,+ runId: RunId.make("run:notification-turn-pages:2"),+ nodeId: NodeId.make("node:notification-turn-pages:2"),+ kind: "todo_list" as const,+ status: "completed" as const,+ explanation: "All tasks complete",+ steps: [{ id: "unfinished", text: "Finish the task", status: "completed" as const }],+ };+ yield* projectionStore.apply({+ id: EventId.make("event:notification-turn-pages:plan:completed"),+ type: "plan.updated",+ threadId,+ occurredAt: now,+ payload: completedPlan,+ });+ const afterCompletion = yield* projectionStore.getThreadSnapshotWindow(threadId, {+ rowLimit: 77,+ userTurnLimit: 10,+ });+ const completedBounded = buildBoundedThreadProjection({+ projection: afterCompletion.projection,+ snapshotSequence: 0,+ });+ assert.deepEqual(+ {+ plans: completedBounded.projection.plans,+ oldRunIds: completedBounded.projection.runs+ .filter((run) => run.ordinal < 261)+ .map((run) => run.id),+ providerThreadIds: completedBounded.projection.providerThreads.map((thread) => thread.id),+ },+ {+ plans: [completedPlan, bounded.projection.plans.find((plan) => plan.id === olderPlanId)],+ oldRunIds: [completedPlan.runId],+ providerThreadIds: [providerThreadId],+ },+ );++ // Older versions left completed predecessors unsuperseded; IDs do not order replacements.+ const newerPlan = {+ ...completedPlan,+ id: PlanId.make("plan:legacy-newer"),+ status: "active" as const,+ explanation: "More work remains",+ steps: [{ id: "new", text: "Finish the new task", status: "pending" as const }],+ };+ yield* projectionStore.apply({+ id: EventId.make("event:notification-turn-pages:plan:legacy-newer"),+ type: "plan.updated",+ threadId,+ occurredAt: now,+ payload: newerPlan,+ });+ for (const [plan, itemOrdinal] of [+ [completedPlan, 7],+ [newerPlan, 8],+ ] as const) {+ yield* projectionStore.apply({+ id: EventId.make(`event:notification-turn-pages:legacy-item:${itemOrdinal}`),+ type: "turn-item.updated",+ threadId,+ runId: plan.runId,+ nodeId: plan.nodeId,+ occurredAt: now,+ payload: {+ id: TurnItemId.make(`turn-item:notification-turn-pages:${itemOrdinal}`),+ threadId,+ runId: plan.runId,+ nodeId: plan.nodeId,+ providerThreadId,+ providerTurnId: null,+ nativeItemRef: null,+ parentItemId: null,+ ordinal: itemOrdinal,+ status: "completed",+ title: null,+ startedAt: now,+ completedAt: now,+ updatedAt: now,+ type: "todo_list",+ planId: plan.id,+ steps: plan.steps,+ explanation: plan.explanation,+ },+ });+ }+ const legacySnapshot = yield* projectionStore.getThreadSnapshotWindow(threadId, {+ rowLimit: 77,+ userTurnLimit: 10,+ });+ assert.isTrue(legacySnapshot.projection.turnItems.every((item) => item.ordinal > 8));+ assert.deepEqual(+ legacySnapshot.projection.plans.findLast((plan) => plan.runId === newerPlan.runId),+ newerPlan,+ );+ const legacyBounded = buildBoundedThreadProjection({+ projection: legacySnapshot.projection,+ snapshotSequence: 0,+ });+ assert.deepEqual(+ {+ ownerPlans: legacyBounded.projection.plans.filter(+ (plan) => plan.runId === newerPlan.runId,+ ),+ oldRunIds: legacyBounded.projection.runs+ .filter((run) => run.ordinal < 261)+ .map((run) => run.id),+ },+ { ownerPlans: [newerPlan], oldRunIds: [newerPlan.runId] },+ );}),);diff --git a/apps/server/src/orchestration-v2/ProjectionStore.ts b/apps/server/src/orchestration-v2/ProjectionStore.tsindex 1abad6204c8..747c7c6f395 100644--- a/apps/server/src/orchestration-v2/ProjectionStore.ts+++ b/apps/server/src/orchestration-v2/ProjectionStore.ts@@ -3091,6 +3091,54 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =const cohortPlanIds = cohortJson("planId");const cohortCheckpointIds = cohortJson("checkpointId");const cohortHandoffIds = cohortJson("contextHandoffId");+ // A newer completion must keep an older active list from resurfacing after paging.+ const [latestTodoList] =+ window === undefined ||+ (fields !== undefined &&+ !fields.some(+ (field) => field === "plans" || field === "runs" || field === "providerThreads",+ ))+ ? []+ : yield* sql<{+ readonly plan_id: string;+ readonly run_id: string;+ readonly provider_thread_id: string | null;+ readonly last_plan_id: string;+ }>`+ WITH latest_owner AS MATERIALIZED (+ SELECT plan.plan_id, owner.run_id, owner.provider_thread_id+ FROM orchestration_v2_projection_plans AS plan+ INNER JOIN orchestration_v2_projection_runs AS owner+ ON owner.thread_id = plan.thread_id AND owner.run_id = plan.run_id+ WHERE plan.thread_id = ${threadId}+ AND plan.kind = 'todo_list' AND plan.status <> 'superseded'+ ORDER BY owner.ordinal DESC, plan.plan_id DESC+ LIMIT 1+ )+ SELECT COALESCE(CASE WHEN EXISTS (+ SELECT 1 FROM orchestration_v2_projection_plans+ WHERE thread_id = ${threadId} AND run_id = owner.run_id+ AND kind = 'todo_list' AND status <> 'superseded'+ AND plan_id <> owner.plan_id+ ) THEN (+ -- Plan UUIDs cannot order replacements within a run.+ SELECT plan.plan_id+ FROM orchestration_v2_projection_turn_items AS item+ CROSS JOIN orchestration_v2_projection_plans AS plan+ ON plan.plan_id = json_extract(item.payload_json, '$.planId')+ WHERE item.run_id = owner.run_id AND item.thread_id = ${threadId}+ AND item.type = 'todo_list'+ AND plan.run_id = owner.run_id AND plan.thread_id = ${threadId}+ AND plan.kind = 'todo_list' AND plan.status <> 'superseded'+ ORDER BY item.ordinal DESC+ LIMIT 1+ ) END, owner.plan_id) AS plan_id, owner.run_id, owner.provider_thread_id,+ (+ SELECT MAX(plan_id) FROM orchestration_v2_projection_plans+ WHERE thread_id = ${threadId} AND run_id = owner.run_id+ ) AS last_plan_id+ FROM latest_owner AS owner+ `;const [thread,@@ -3126,7 +3174,18 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =WHERE thread_id = ${threadId}AND (status IN ('queued','preparing','starting','running','waiting')OR run_id IN (SELECT value FROM json_each(${cohortRunIds}))- OR run_id = ${window.requiredRunId ?? null})+ OR run_id = ${window.requiredRunId ?? null}+ -- Queued or cancelled turns must not hide the latest actual session.+ OR run_id = ${latestTodoList?.run_id ?? null}+ OR run_id = (+ SELECT run_id FROM orchestration_v2_projection_runs+ WHERE thread_id = ${threadId}+ AND provider_thread_id IS NOT NULL+ AND json_extract(payload_json, '$.startedAt') IS NOT NULL+ AND ${latestTodoList?.plan_id ?? null} IS NOT NULL+ ORDER BY ordinal DESC+ LIMIT 1+ ))ORDER BY ordinal ASC`,fields !== undefined && !fields.includes("attempts")@@ -3246,6 +3305,8 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =WHERE (thread_id = ${threadId} AND status = 'active')OR provider_thread_id IN (SELECT value FROM json_each(${cohortProviderThreadIds}))OR owner_node_id IN (SELECT value FROM json_each(${cohortNodeIds}))+ OR (thread_id = ${threadId}+ AND provider_thread_id = ${latestTodoList?.provider_thread_id ?? null})ORDER BY COALESCE(first_run_ordinal, 0), provider_thread_id ASC`,fields !== undefined && !fields.includes("providerTurns")@@ -3322,11 +3383,15 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =WHERE plan.thread_id = ${threadId}AND (plan.status = 'active'+ OR plan.plan_id = ${latestTodoList?.plan_id ?? null}OR plan.plan_id IN (SELECT value FROM json_each(${cohortPlanIds})))- ORDER BY plan_id ASC+ -- Keep the selected artifact last within its run for equal-run consumers.+ ORDER BY CASE WHEN plan_id = ${latestTodoList?.plan_id ?? null}+ THEN ${latestTodoList?.last_plan_id ?? null} ELSE plan_id END ASC,+ plan_id = ${latestTodoList?.plan_id ?? null} ASC`,fields !== undefined && !fields.includes("checkpointScopes")? Effect.succeed([])diff --git a/apps/server/src/orchestration-v2/threadHistoryPaging.ts b/apps/server/src/orchestration-v2/threadHistoryPaging.tsindex 5f466bdbb15..6e863857085 100644--- a/apps/server/src/orchestration-v2/threadHistoryPaging.ts+++ b/apps/server/src/orchestration-v2/threadHistoryPaging.ts@@ -482,9 +482,26 @@ export function buildBoundedThreadProjection(input: {}): BoundedProjectionResult {const policy = input.policy ?? THREAD_HISTORY_PAGE_POLICY;const threadId = input.projection.thread.id;+ const runOrdinals = new Map(input.projection.runs.map((run) => [run.id, run.ordinal]));+ let latestTodoList: (typeof input.projection.plans)[number] | undefined;+ let latestTodoListOrdinal = -1;+ for (const plan of input.projection.plans) {+ const ordinal = plan.runId === null ? undefined : runOrdinals.get(plan.runId);+ if (+ plan.kind === "todo_list" &&+ plan.status !== "superseded" &&+ ordinal !== undefined &&+ ordinal >= latestTodoListOrdinal+ ) {+ latestTodoList = plan;+ latestTodoListOrdinal = ordinal;+ }+ }const controlProjection = {...input.projection,- plans: input.projection.plans.filter((plan) => plan.status === "active"),+ plans: input.projection.plans.filter(+ (plan) => plan.status === "active" || plan.id === latestTodoList?.id,+ ),contextHandoffs: input.projection.contextHandoffs.filter((handoff) => handoff.status === "pending" || handoff.status === "ready",),@@ -506,7 +523,7 @@ export function buildBoundedThreadProjection(input: {turnItems: [],visibleTurnItems: [],});- // Control state (checkpoint file lists, an active plan) cannot be paged, so it may claim at most+ // Control state (checkpoint file lists, the latest task list) cannot be paged, so it may claim at most// half the budget; past that the window would shrink to the one row every page admits.const windowBudget = Math.max(policy.maxEncodedBytes / 2,@@ -548,9 +565,14 @@ export function buildBoundedThreadProjection(input: {turnItems.flatMap((item) => (item.type === "handoff" ? [String(item.contextHandoffId)] : [])),);const plans = input.projection.plans- .filter((plan) => plan.status === "active" || visiblePlanIds.has(String(plan.id)))+ .filter(+ (plan) =>+ plan.status === "active" ||+ plan.id === latestTodoList?.id ||+ visiblePlanIds.has(String(plan.id)),+ ).map((plan) =>- plan.status === "active"+ plan.status === "active" || plan.id === latestTodoList?.id? plan: plan.kind === "proposed_plan"? { ...plan, markdown: "", detailInTurnItem: true as const }diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsxindex 7b14f8b1c54..d581ff5278c 100644--- a/apps/web/src/components/ChatView.tsx+++ b/apps/web/src/components/ChatView.tsx@@ -187,6 +187,7 @@ import {derivePhase,selectHandoffImageResources,deriveActivePlanState,+ selectComposerTasksPlan,deriveActiveWorkStartedAt,deriveCanInterruptRunningThread,findLatestProposedPlan,@@ -1827,27 +1828,29 @@ export default function ChatView(props: ChatViewProps) {}const latestRunSettled = isLatestRunSettled(activeLatestRun, activeRuntime);const activePlan = deriveActivePlanState(serverProjection, activeActivityRun?.runId);- // Tasks progress for the running turn's own plan only — deriveActivePlanState- // falls back to older runs' plans, which must not label fresh work.+ const activeActivityRunSettled = isLatestRunSettled(activeActivityRun, activeRuntime);+ const composerTasksPlan = selectComposerTasksPlan(+ serverProjection,+ activePlan,+ activeActivityRun?.runId ?? null,+ activeActivityRunSettled,+ );const activeComposerTasksProgress = (() => {- if (- isLatestRunSettled(activeActivityRun, activeRuntime) ||- !activePlan ||- activePlan.runId !== (activeActivityRun?.runId ?? null)- ) {- return null;- }- const totalSteps = activePlan.steps.length;+ if (!composerTasksPlan) return null;+ const live = !activeActivityRunSettled && composerTasksPlan.runId === activeActivityRun?.runId;+ const totalSteps = composerTasksPlan.steps.length;if (totalSteps === 0) return null;- const completedSteps = activePlan.steps.filter((step) => step.status === "completed").length;+ const completedSteps = composerTasksPlan.steps.filter(+ (step) => step.status === "completed",+ ).length;const step =- activePlan.steps.find((candidate) => candidate.status === "inProgress")?.step ??- activePlan.steps.find((candidate) => candidate.status === "pending")?.step ??- activePlan.steps.at(-1)!.step;- return { step, completedSteps, totalSteps };+ composerTasksPlan.steps.find((candidate) => candidate.status === "inProgress")?.step ??+ composerTasksPlan.steps.find((candidate) => candidate.status === "pending")?.step ??+ composerTasksPlan.steps.at(-1)!.step;+ return { step, completedSteps, totalSteps, live };})();const activeComposerTaskSteps =- activeComposerTasksProgress && activePlan ? activePlan.steps : null;+ activeComposerTasksProgress && composerTasksPlan ? composerTasksPlan.steps : null;const activeThreadEnvironmentId = activeThread?.environmentId;const activeThreadProjectId = activeThread?.projectId;const activeProjectRef =diff --git a/apps/web/src/components/chat/ComposerTasksBadge.tsx b/apps/web/src/components/chat/ComposerTasksBadge.tsxindex 3031924e44e..704bfc38e4a 100644--- a/apps/web/src/components/chat/ComposerTasksBadge.tsx+++ b/apps/web/src/components/chat/ComposerTasksBadge.tsx@@ -9,6 +9,7 @@ export interface ComposerTasksProgress {readonly step: string;readonly completedSteps: number;readonly totalSteps: number;+ readonly live: boolean;}export interface ComposerTaskStep {@@ -205,7 +206,7 @@ export const ComposerTasksContent = memo(function ComposerTasksContent({>{step.durationMs !== undefined? formatDuration(step.durationMs)- : step.status === "inProgress"+ : step.status === "inProgress" && progress.live? "now": null}</span>diff --git a/apps/web/src/session-logic.test.ts b/apps/web/src/session-logic.test.tsindex 9895998b137..bf82e4564f4 100644--- a/apps/web/src/session-logic.test.ts+++ b/apps/web/src/session-logic.test.ts@@ -5,6 +5,7 @@ import {CheckpointScopeId,NodeId,PlanId,+ ProviderDriverKind,ProviderInstanceId,ProviderThreadId,RunAttemptId,@@ -31,6 +32,7 @@ import {derivePhase,findLatestProposedPlan,isLatestRunSettled,+ selectComposerTasksPlan,selectHandoffImageResources,selectMessageImageResources,createMessageAttachmentPreviewProjector,@@ -1130,6 +1132,190 @@ describe("V2 session presentation", () => {});});+describe("composer tasks drawer", () => {+ const projection = makeThreadProjectionFixture();+ const now = projection.updatedAt;++ function providerThread(id: string, driver: string) {+ return {+ id: ProviderThreadId.make(id),+ driver: ProviderDriverKind.make(driver),+ providerInstanceId: ProviderInstanceId.make(driver),+ providerSessionId: null,+ appThreadId: projection.thread.id,+ ownerNodeId: null,+ nativeThreadRef: null,+ nativeConversationHeadRef: null,+ status: "idle" as const,+ firstRunOrdinal: null,+ lastRunOrdinal: null,+ handoffIds: [],+ forkedFrom: null,+ createdAt: now,+ updatedAt: now,+ };+ }++ function run(id: string, ordinal: number, providerThreadId: string | null) {+ return {+ id: RunId.make(id),+ threadId: projection.thread.id,+ ordinal,+ providerInstanceId: projection.thread.providerInstanceId,+ modelSelection: projection.thread.modelSelection,+ providerThreadId: providerThreadId === null ? null : ProviderThreadId.make(providerThreadId),+ userMessageId: MessageId.make(`message-${id}`),+ rootNodeId: null,+ activeAttemptId: null,+ status: "completed" as const,+ requestedAt: now,+ startedAt: now,+ completedAt: now,+ checkpointId: null,+ contextHandoffId: null,+ };+ }++ const openList = {+ createdAt: "2026-06-20T00:00:00.000Z",+ runId: RunId.make("run-1"),+ steps: [+ { step: "Inspect", status: "completed" as const },+ { step: "Implement", status: "inProgress" as const },+ { step: "Verify", status: "pending" as const },+ ],+ };+ const completedList = {+ ...openList,+ steps: openList.steps.map((step) => ({ ...step, status: "completed" as const })),+ };++ it.each(["claudeAgent", "codex"])(+ "shows %s tasks through the run lifecycle, retaining unfinished tasks only for Claude",+ (driver) => {+ const firstRun = run("run-1", 1, driver);+ const settled = {+ ...projection,+ providerThreads: [providerThread(driver, driver)],+ runs: [firstRun],+ };+ const running = {+ ...settled,+ runs: [{ ...firstRun, status: "running" as const, completedAt: null }],+ };+ expect(selectComposerTasksPlan(running, openList, firstRun.id, false)).toBe(openList);+ expect(selectComposerTasksPlan(running, completedList, firstRun.id, false)).toBe(+ completedList,+ );++ const retainedList = driver === "claudeAgent" ? openList : null;+ expect(selectComposerTasksPlan(settled, openList, firstRun.id, true)).toBe(retainedList);+ expect(selectComposerTasksPlan(settled, completedList, firstRun.id, true)).toBeNull();++ const nextRun = {+ ...run("run-2", 2, driver),+ status: "running" as const,+ completedAt: null,+ };+ const later = { ...settled, runs: [...settled.runs, nextRun] };+ expect(selectComposerTasksPlan(later, openList, nextRun.id, false)).toBe(retainedList);+ },+ );++ it("retains the newest unfinished Claude list after loading plans in snapshot order", () => {+ const olderRun = run("run:ordinal:8", 8, "claudeAgent");+ const planRun = run("run:ordinal:12", 12, "claudeAgent");+ const laterRun = {+ ...run("run:ordinal:13", 13, "claudeAgent"),+ status: "running" as const,+ completedAt: null,+ };+ const newestPlan = {+ id: PlanId.make("plan:run:ordinal:12"),+ threadId: projection.thread.id,+ runId: planRun.id,+ nodeId: NodeId.make("node:ordinal:12"),+ kind: "todo_list" as const,+ status: "active" as const,+ steps: [{ id: "new", text: "Finish the current task", status: "pending" as const }],+ };+ for (const status of ["superseded", "active"] as const) {+ const snapshot = {+ ...projection,+ providerThreads: [providerThread("claudeAgent", "claudeAgent")],+ runs: [olderRun, planRun, laterRun],+ plans: [+ newestPlan,+ {+ ...newestPlan,+ id: PlanId.make("plan:run:ordinal:8"),+ runId: olderRun.id,+ nodeId: NodeId.make("node:ordinal:8"),+ status,+ steps: [{ id: "old", text: "Stale task", status: "pending" as const }],+ },+ ],+ };+ const plan = deriveActivePlanState(snapshot, laterRun.id);+ expect+ .soft(selectComposerTasksPlan(snapshot, plan, laterRun.id, false), status)+ .toMatchObject({+ runId: planRun.id,+ steps: [{ step: "Finish the current task", status: "pending" }],+ });+ }+ });++ it.each(["codex", "claudeAgent"])(+ "drops retained Claude tasks only after a new %s session actually starts",+ (driver) => {+ const settled = {+ ...projection,+ providerThreads: [+ providerThread("claude-original", "claudeAgent"),+ providerThread("next-session", driver),+ ],+ runs: [run("run-1", 1, "claude-original")],+ };+ const nextRun = run("run-2", 2, "next-session");+ for (const status of ["queued", "cancelled"] as const) {+ const unstarted = {+ ...settled,+ runs: [+ ...settled.runs,+ {+ ...nextRun,+ status,+ startedAt: null,+ completedAt: status === "cancelled" ? now : null,+ },+ ],+ };+ expect+ .soft(+ selectComposerTasksPlan(unstarted, openList, nextRun.id, status === "cancelled"),+ `A ${status} run with an assigned provider thread has not switched sessions`,+ )+ .toBe(openList);+ }++ const started = {+ ...settled,+ runs: [...settled.runs, { ...nextRun, status: "running" as const, completedAt: null }],+ };+ expect(selectComposerTasksPlan(started, openList, nextRun.id, false)).toBeNull();+ expect(+ selectComposerTasksPlan(+ { ...settled, runs: [...settled.runs, nextRun] },+ openList,+ nextRun.id,+ true,+ ),+ ).toBeNull();+ },+ );+});+describe("native provider presentation in the v2 timeline", () => {const timestamp = DateTime.makeUnsafe("2026-09-04T12:00:00.000Z");const base = {diff --git a/apps/web/src/session-logic.ts b/apps/web/src/session-logic.tsindex 29bdad1be0b..0d6956fa378 100644--- a/apps/web/src/session-logic.ts+++ b/apps/web/src/session-logic.ts@@ -255,11 +255,22 @@ export function deriveActivePlanState(latestRunId: RunId | undefined,): ActivePlanState | null {if (projection === null) return null;- const plans = projection.plans.filter((plan) => plan.kind === "todo_list");+ const plans = projection.plans+ .filter((plan) => plan.kind === "todo_list")+ .filter((plan) => plan.status !== "superseded");+ const runOrdinals = new Map<RunId | null, number>(+ projection.runs.map((run) => [run.id, run.ordinal]),+ );const plan =- [...plans].toReversed().find((candidate) => candidate.runId === latestRunId) ??- plans.at(-1) ??- null;+ plans.findLast((candidate) => candidate.runId === latestRunId) ??+ plans.reduce<(typeof plans)[number] | null>(+ (latest, candidate) =>+ latest === null ||+ (runOrdinals.get(candidate.runId) ?? -1) >= (runOrdinals.get(latest.runId) ?? -1)+ ? candidate+ : latest,+ null,+ );if (plan === null || plan.steps.length === 0) return null;return {createdAt: planItemTime(projection, plan.id),@@ -273,6 +284,37 @@ export function deriveActivePlanState(};}+// Claude's unfinished tasks belong to the provider session, not just the turn.+export function selectComposerTasksPlan(+ projection: OrchestrationV2ThreadProjection | null,+ plan: ActivePlanState | null,+ activeRunId: RunId | null,+ activeRunSettled: boolean,+): ActivePlanState | null {+ if (projection === null || plan === null) return null;+ if (activeRunId !== null && !activeRunSettled && plan.runId === activeRunId) return plan;+ if (plan.steps.every((step) => step.status === "completed")) return null;+ const planProviderThreadId = projection.runs.find(+ (run) => run.id === plan.runId,+ )?.providerThreadId;+ if (planProviderThreadId === undefined || planProviderThreadId === null) return null;+ const planDriver = projection.providerThreads.find(+ (providerThread) => providerThread.id === planProviderThreadId,+ )?.driver;+ if (planDriver !== "claudeAgent") return null;+ let latestStartedRun: OrchestrationV2ThreadProjection["runs"][number] | null = null;+ for (const run of projection.runs) {+ if (+ run.startedAt !== null &&+ run.providerThreadId !== null &&+ (latestStartedRun === null || run.ordinal > latestStartedRun.ordinal)+ ) {+ latestStartedRun = run;+ }+ }+ return latestStartedRun?.providerThreadId === planProviderThreadId ? plan : null;+}+function planItemTime(projection: OrchestrationV2ThreadProjection, planId: PlanId): string {const item = projection.turnItems.findLast((candidate) =>diff --git a/docs/user/providers-claude.md b/docs/user/providers-claude.mdindex a569c5b8f39..344cffb4780 100644--- a/docs/user/providers-claude.md+++ b/docs/user/providers-claude.md@@ -77,6 +77,13 @@ can still be started by you. Invoke those one per message: Claude directly runsonly the last named skill and may try to start earlier ones through its Skilltool, which refuses skills reserved for manual invocation.+## Task lists++To show Claude task lists in the web and desktop apps, add+`CLAUDE_CODE_ENABLE_TODO_TOOLS=1` under **Variables** in the Claude instance's+**Environment** section in **Settings > Providers**. Unfinished tasks stay visible+between turns in the same Claude session.+## OpenRouterCreate a Claude instance with its own config directory, such as