From 6efa46f44043fc9b4cf93304aa7f65545e958b39 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Fri, 6 Nov 2026 05:19:20 +0000 Subject: [PATCH 1/7] test(server): reproduce #31817 failed Claude turn dropping live background tasks These tests reproduce pingdotgg/t3code#31817. When a Claude turn fails (for example on an API error) while the CLI process stays alive, the adapter wipes the native thread's background-task roster and wake eligibility. The still-running tasks then cannot be awaited, and their completion no longer wakes the idle thread. AI-assisted; verified with the tests and tools listed above. Co-Authored-By: Claude Opus 5.5 --- .../Adapters/ClaudeAdapterV2.test.ts | 94 +++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts index d7d03c779b4b..c454fa3baebf 100644 --- a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts @@ -10098,6 +10098,100 @@ describe("ClaudeAdapterV2 background wake turns", () => { ), ); + // An API error fails the turn, but the CLI process and its background tasks keep running. + const liveProcessFailedResult = makeResultFrame({ + uuid: "00000000-0000-4000-8000-000000000311", + result: "API Error: 502 Bad Gateway", + isError: true, + apiErrorStatus: 502, + terminalReason: "api_error", + }); + + it.effect("keeps background tasks waitable after a turn fails on a live process", () => + Effect.scoped( + Effect.gen(function* () { + const harness = yield* makeWakeHarness; + const awaitBackgroundTasks = harness.runtime.awaitBackgroundTasks; + if (awaitBackgroundTasks === undefined) { + throw new Error("Claude adapter runtime must expose awaitBackgroundTasks."); + } + yield* harness.runtime.startTurn( + makeClaudeTestTurnInput({ + threadId: harness.threadId, + providerThread: harness.providerThread, + now: yield* DateTime.now, + attemptId: RunAttemptId.make("attempt-claude-failed-live-roster"), + text: "Run the build in the background.", + attachments: [], + }), + ); + yield* Queue.offer(harness.sdkMessages, wakeTaskStarted); + yield* Queue.offer(harness.sdkMessages, liveProcessFailedResult); + assert.equal((yield* Queue.take(harness.terminalReceipts)).status, "failed"); + + assert.deepStrictEqual( + providerThreadRosterEvents(harness.events) + .at(-1) + ?.providerThread.pendingBackgroundTasks?.map((task) => task.taskId), + [WAKE_TASK_ID], + ); + assert.isTrue(yield* harness.hasPendingBackgroundWork); + const marked = yield* awaitBackgroundTasks({ + providerThread: harness.providerThread, + taskIds: [WAKE_TASK_ID], + awaited: true, + }); + assert.deepStrictEqual(marked.matched, [WAKE_TASK_ID]); + }).pipe( + Effect.provide( + Layer.mergeAll( + IdAllocator.layer, + McpProviderSessions.layer, + NodeServices.layer, + NodeCrypto.layer, + ), + ), + ), + ), + ); + + it.effect("wakes the idle thread when a task outlives a turn that failed on a live process", () => + Effect.scoped( + Effect.gen(function* () { + const harness = yield* makeWakeHarness; + yield* harness.runtime.startTurn( + makeClaudeTestTurnInput({ + threadId: harness.threadId, + providerThread: harness.providerThread, + now: yield* DateTime.now, + attemptId: RunAttemptId.make("attempt-claude-failed-live-wake"), + text: "Run the build in the background.", + attachments: [], + }), + ); + yield* Queue.offer(harness.sdkMessages, wakeTaskStarted); + yield* Queue.offer(harness.sdkMessages, liveProcessFailedResult); + assert.equal((yield* Queue.take(harness.terminalReceipts)).status, "failed"); + + yield* harness.offerAndWait(wakeNotification); + yield* harness.offerAndWait(wakeAssistant); + assert.deepStrictEqual( + harness.continuationRequests.map((request) => request.detail), + [WAKE_SUMMARY], + ); + }).pipe( + Effect.provide( + Layer.mergeAll( + IdAllocator.layer, + McpProviderSessions.layer, + NodeServices.layer, + NodeCrypto.layer, + ), + ), + ), + ), + ); + it.effect("keeps a running Claude monitor typed after many newer monitors end", () => Effect.scoped( Effect.gen(function* () { From 357f72f5a1c5c6377d7897fe66912c0e2a0cb945 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Fri, 6 Nov 2026 05:23:45 +0000 Subject: [PATCH 2/7] fix(server): keep background tasks waitable after a Claude turn fails on a live process A failed Claude turn cleared the native thread's background-task roster, wake eligibility and opaque replay tombstones even when the CLI process that ran it stayed open and kept the tasks running. The SDK only resends background_tasks_changed on change, so the roster never came back: waits reported the tasks unmatched and their completion never woke the thread. Keep that state when the turn failed and the live, non-stopping query is the one that ran it. Interrupts and failures on a closed or closing process still clear it before root settlement. Co-Authored-By: Claude Opus 5.5 --- .../orchestration-v2/Adapters/ClaudeAdapterV2.test.ts | 8 +++++--- .../src/orchestration-v2/Adapters/ClaudeAdapterV2.ts | 10 ++++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts index c454fa3baebf..cd0c89f68188 100644 --- a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts @@ -11097,10 +11097,12 @@ describe("ClaudeAdapterV2 background wake turns", () => { const rosterBAfterFail = providerThreadRosterEvents(events).findLast( (event) => event.providerThread.id === providerThreadB.id, )?.providerThread.pendingBackgroundTasks; - assert.deepEqual(rosterBAfterFail ?? [], []); + assert.deepEqual(rosterBAfterFail ?? [], [ + { taskId: taskB, description: "work on B", kind: "command" }, + ]); assert.isFalse(yield* hasPendingBackgroundWorkForThread(providerThreadA)); - assert.isFalse(yield* hasPendingBackgroundWorkForThread(providerThreadB)); - assert.isFalse(yield* hasPendingBackgroundWork); + assert.isTrue(yield* hasPendingBackgroundWorkForThread(providerThreadB)); + assert.isTrue(yield* hasPendingBackgroundWork); }).pipe( Effect.provide( Layer.mergeAll( diff --git a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts index 10edb77c5011..f8af9cbcb0b0 100644 --- a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts +++ b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts @@ -8155,8 +8155,15 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* ( Effect.gen(function* () { const nativeThreadId = input.context.input.providerThread.nativeThreadRef?.nativeId ?? null; + const liveQuery = yield* Ref.get(queryContext); + // Background tasks outlive a failed turn while the process that ran it stays open. + const processKeepsTasks = + input.status === "failed" && + liveQuery !== null && + !liveQuery.stopping && + liveQuery.lastTurn === input.context; if (nativeThreadId !== null) { - if (input.status !== "completed") { + if (input.status !== "completed" && !processKeepsTasks) { yield* clearPendingBackgroundTasksForNativeThread(nativeThreadId); yield* clearNativeThreadTaskIdSet( wakeEligibleBackgroundTasksByNativeThread, @@ -8190,7 +8197,6 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* ( nativeThreadId === null ? undefined : goalsByNativeThread.get(nativeThreadId); const goalChecked = goalCheckedTurns.delete(input.context.providerTurnId); const terminalReason = input.result?.terminal_reason; - const liveQuery = yield* Ref.get(queryContext); if ( nativeThreadId !== null && goal?.status === "active" && From 40c273131f32df5ced197e4c270f1c158ab19ba5 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Fri, 6 Nov 2026 05:34:27 +0000 Subject: [PATCH 3/7] test(server): a Claude process exiting mid-turn still clears its background tasks Pins the live-process half of the failed-turn guard: without it, a crashed CLI would leave a phantom roster that keeps the session pinned. Co-Authored-By: Claude Opus 5.5 --- .../Adapters/ClaudeAdapterV2.test.ts | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts index cd0c89f68188..2db41a83afe7 100644 --- a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts @@ -10155,6 +10155,44 @@ describe("ClaudeAdapterV2 background wake turns", () => { ), ); + it.effect("clears background tasks when the Claude process exits mid-turn", () => + Effect.scoped( + Effect.gen(function* () { + const harness = yield* makeWakeHarness; + yield* harness.runtime.startTurn( + makeClaudeTestTurnInput({ + threadId: harness.threadId, + providerThread: harness.providerThread, + now: yield* DateTime.now, + attemptId: RunAttemptId.make("attempt-claude-probe-exit"), + text: "Run the build in the background.", + attachments: [], + }), + ); + yield* harness.offerAndWait(wakeTaskStarted); + assert.isTrue(yield* harness.hasPendingBackgroundWork); + yield* Queue.shutdown(harness.sdkMessages); + assert.equal((yield* Queue.take(harness.terminalReceipts)).status, "failed"); + assert.deepStrictEqual( + providerThreadRosterEvents(harness.events) + .at(-1) + ?.providerThread.pendingBackgroundTasks?.map((task) => task.taskId) ?? [], + [], + ); + assert.isFalse(yield* harness.hasPendingBackgroundWork); + }).pipe( + Effect.provide( + Layer.mergeAll( + IdAllocator.layer, + McpProviderSessions.layer, + NodeServices.layer, + NodeCrypto.layer, + ), + ), + ), + ), + ); + it.effect("wakes the idle thread when a task outlives a turn that failed on a live process", () => Effect.scoped( Effect.gen(function* () { From df538f62c7692d622c0bbd44147d704d5dd27132 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Fri, 6 Nov 2026 05:39:02 +0000 Subject: [PATCH 4/7] fix(server): a failed run keeps ingesting roster updates while background work runs A failed turn on a live Claude process now keeps its background tasks, so the run must keep reading provider events until they end, as a completed run does. Co-Authored-By: Claude Opus 5.5 --- .../RunExecutionService.test.ts | 52 +++++++++++++++++++ .../orchestration-v2/RunExecutionService.ts | 3 +- 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/apps/server/src/orchestration-v2/RunExecutionService.test.ts b/apps/server/src/orchestration-v2/RunExecutionService.test.ts index 5bfb4fe34dc6..38e817b0afb8 100644 --- a/apps/server/src/orchestration-v2/RunExecutionService.test.ts +++ b/apps/server/src/orchestration-v2/RunExecutionService.test.ts @@ -3134,6 +3134,58 @@ it.effect("keeps completed runs completed when pull request refresh fails", () = }), ); +it.effect.each(["completed", "failed"] as const)( + "persists a background-task roster clear that arrives after a %s turn", + (status) => + Effect.gen(function* () { + const pending = yield* Ref.make(true); + const ingested = yield* Ref.make>([]); + yield* captureRootRunTermination({ + key: `roster-clear-${status}`, + shouldFinalizeRun: () => Effect.succeed(true), + hasPendingBackgroundWorkForThread: () => Ref.get(pending), + events: (ids) => { + const roster = (hasTask: boolean) => + ({ + type: "provider_thread.updated", + driver, + providerThread: { + id: ids.providerThreadId, + driver, + appThreadId: ids.threadId, + providerSessionId: ProviderSessionId.make(`session:roster-clear-${status}`), + pendingBackgroundTasks: hasTask + ? [{ taskId: "running-build", kind: "command", awaited: true }] + : [], + }, + }) as ProviderAdapter.ProviderAdapterV2Event; + return Stream.fromIterable([ + roster(true), + rootTerminalEvent(ids, status), + roster(false), + ]).pipe( + Stream.mapEffect((event) => + event.type === "provider_thread.updated" + ? Ref.set( + pending, + (event.providerThread.pendingBackgroundTasks?.length ?? 0) > 0, + ).pipe(Effect.as(event)) + : Effect.succeed(event), + ), + ); + }, + ingestNormalized: (input) => + Ref.update(ingested, (all) => [...all, input.event]).pipe(Effect.as([])), + }); + const rosters = (yield* Ref.get(ingested)).flatMap((event) => + event.type === "provider_thread.updated" + ? [event.providerThread.pendingBackgroundTasks] + : [], + ); + assert.deepEqual(rosters.at(-1), [], "an ended task must leave the persisted roster"); + }), +); + function captureRootRunTermination(input: { readonly key: string; readonly shouldFinalizeRun: () => Effect.Effect; diff --git a/apps/server/src/orchestration-v2/RunExecutionService.ts b/apps/server/src/orchestration-v2/RunExecutionService.ts index 304eeaba4342..7b954bfc52dc 100644 --- a/apps/server/src/orchestration-v2/RunExecutionService.ts +++ b/apps/server/src/orchestration-v2/RunExecutionService.ts @@ -1282,10 +1282,11 @@ export const layer: Layer.Layer< return false; } const terminal = yield* Ref.get(terminalEvent); + // A failed turn can leave background work running in a live provider process. if ( terminal !== null && terminal.status !== "completed" && - !childTurnsContinue(terminal) + terminal.status !== "failed" ) { return true; } From fc235fc8fd855b95228414b81a05d324503dc01d Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Fri, 6 Nov 2026 05:50:33 +0000 Subject: [PATCH 5/7] fix(server): a failed run waits only on the thread's background work Running turn items a failed adapter never settled must not pin the run's subscription; only the provider's own background-work probe keeps it open. Co-Authored-By: Claude Opus 5.5 --- .../RunExecutionService.test.ts | 20 ++++++----- .../orchestration-v2/RunExecutionService.ts | 35 ++++++++++--------- 2 files changed, 30 insertions(+), 25 deletions(-) diff --git a/apps/server/src/orchestration-v2/RunExecutionService.test.ts b/apps/server/src/orchestration-v2/RunExecutionService.test.ts index 38e817b0afb8..562685246a81 100644 --- a/apps/server/src/orchestration-v2/RunExecutionService.test.ts +++ b/apps/server/src/orchestration-v2/RunExecutionService.test.ts @@ -2015,15 +2015,17 @@ it.effect("keeps ingesting a failed root's background item when its work continu }), ); -it.effect("does not pin ingestion on background items when the root turn is interrupted", () => - Effect.gen(function* () { - const observed = yield* runBackgroundItemScenario("bg-interrupted", (ids) => [ - backgroundTurnItemEvent(ids, "command_execution", "running", 1), - rootTerminalEvent(ids, "interrupted"), - backgroundTurnItemEvent(ids, "command_execution", "completed", 2), - ]); - assert.deepEqual(observed, ["turn_item:running", "root-finalized"]); - }), +it.effect.each(["interrupted", "failed"] as const)( + "does not pin ingestion on background items when the root turn is %s", + (status) => + Effect.gen(function* () { + const observed = yield* runBackgroundItemScenario(`bg-${status}`, (ids) => [ + backgroundTurnItemEvent(ids, "command_execution", "running", 1), + rootTerminalEvent(ids, status), + backgroundTurnItemEvent(ids, "command_execution", "completed", 2), + ]); + assert.deepEqual(observed, ["turn_item:running", "root-finalized"]); + }), ); it.effect("seeds inherited background items before their next update", () => diff --git a/apps/server/src/orchestration-v2/RunExecutionService.ts b/apps/server/src/orchestration-v2/RunExecutionService.ts index 7b954bfc52dc..e2e7fe55c54b 100644 --- a/apps/server/src/orchestration-v2/RunExecutionService.ts +++ b/apps/server/src/orchestration-v2/RunExecutionService.ts @@ -1277,18 +1277,33 @@ export const layer: Layer.Layer< const childSubagents = yield* Ref.get(activeChildSubagents); return childSubagents.size === 0; }); + // Claude background Bash has no turn-item projection. Use only the + // thread-scoped probe: session-wide pending work (siblings, wake + // buffers, session subagents) must not pin this root subscription. + const threadHasPendingBackgroundWork = Effect.gen(function* () { + if (input.session.hasPendingBackgroundWorkForThread === undefined) { + return false; + } + return yield* input.session + .hasPendingBackgroundWorkForThread(yield* Ref.get(latestProviderThread)) + .pipe(Effect.catchCause(() => Effect.succeed(false))); + }); const shouldStopProviderEventIngestion = Effect.gen(function* () { if (!(yield* agentTurnsSettled)) { return false; } const terminal = yield* Ref.get(terminalEvent); - // A failed turn can leave background work running in a live provider process. if ( terminal !== null && terminal.status !== "completed" && - terminal.status !== "failed" + !childTurnsContinue(terminal) ) { - return true; + // A failed turn can leave background work running in a live provider process. + return ( + terminal.status !== "failed" || + (yield* Ref.get(providerThreadOwnerLost)) || + !(yield* threadHasPendingBackgroundWork) + ); } // Newly owned items depend on adapters emitting a non-terminal event before the root // terminal. Owner loss (a newer run claimed lastRunOrdinal) must not close this stream @@ -1301,19 +1316,7 @@ export const layer: Layer.Layer< if (yield* Ref.get(providerThreadOwnerLost)) { return true; } - // Claude background Bash has no turn-item projection. Use only the - // thread-scoped probe: session-wide pending work (siblings, wake - // buffers, session subagents) must not pin this root subscription. - const latestProviderThreadSnapshot = yield* Ref.get(latestProviderThread); - if (input.session.hasPendingBackgroundWorkForThread !== undefined) { - const hasPendingWork = yield* input.session - .hasPendingBackgroundWorkForThread(latestProviderThreadSnapshot) - .pipe(Effect.catchCause(() => Effect.succeed(false))); - if (hasPendingWork) { - return false; - } - } - return true; + return !(yield* threadHasPendingBackgroundWork); }); const filterAssistantEvent = makeAssistantStreamingFilter(responseStreamingMode); // Held text writes nothing, so its item would take a position only From 6b429d18a195c62a9abdf79b950e259bda4cbc7f Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Fri, 6 Nov 2026 06:07:10 +0000 Subject: [PATCH 6/7] test(server): type the failed-run roster fixture Co-Authored-By: Claude Opus 5.5 --- .../RunExecutionService.test.ts | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/apps/server/src/orchestration-v2/RunExecutionService.test.ts b/apps/server/src/orchestration-v2/RunExecutionService.test.ts index 562685246a81..c1316cd08538 100644 --- a/apps/server/src/orchestration-v2/RunExecutionService.test.ts +++ b/apps/server/src/orchestration-v2/RunExecutionService.test.ts @@ -10,6 +10,7 @@ import { type OrchestrationV2CheckpointScope, type OrchestrationV2DomainEvent, type OrchestrationV2ExecutionNode, + type OrchestrationV2PendingBackgroundTask, type OrchestrationV2ProviderThread, type OrchestrationV2ProviderTurn, type OrchestrationV2Run, @@ -3147,32 +3148,33 @@ it.effect.each(["completed", "failed"] as const)( shouldFinalizeRun: () => Effect.succeed(true), hasPendingBackgroundWorkForThread: () => Ref.get(pending), events: (ids) => { - const roster = (hasTask: boolean) => - ({ + const runningBuild: OrchestrationV2PendingBackgroundTask = { + taskId: "running-build", + kind: "command", + }; + const roster = (hasTask: boolean): ProviderAdapter.ProviderAdapterV2Event => { + const pendingBackgroundTasks: ReadonlyArray = + hasTask ? [runningBuild] : []; + return { type: "provider_thread.updated", driver, providerThread: { id: ids.providerThreadId, driver, appThreadId: ids.threadId, - providerSessionId: ProviderSessionId.make(`session:roster-clear-${status}`), - pendingBackgroundTasks: hasTask - ? [{ taskId: "running-build", kind: "command", awaited: true }] - : [], - }, - }) as ProviderAdapter.ProviderAdapterV2Event; + pendingBackgroundTasks, + } as OrchestrationV2ProviderThread, + }; + }; return Stream.fromIterable([ roster(true), rootTerminalEvent(ids, status), roster(false), ]).pipe( - Stream.mapEffect((event) => + Stream.tap((event) => event.type === "provider_thread.updated" - ? Ref.set( - pending, - (event.providerThread.pendingBackgroundTasks?.length ?? 0) > 0, - ).pipe(Effect.as(event)) - : Effect.succeed(event), + ? Ref.set(pending, (event.providerThread.pendingBackgroundTasks?.length ?? 0) > 0) + : Effect.void, ), ); }, From 3ce46f351afd516ddd6af0a3b36f80ee8c2233df Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Tue, 10 Nov 2026 21:46:57 +0000 Subject: [PATCH 7/7] fix(server): keep ingesting until a stored Claude roster clears Claude roster updates never set pendingBackgroundWork, so the live probe could turn false before ingestion consumed the queued roster clear, closing the subscription with the task still persisted. A non-empty stored roster now counts as pending work, for failed and completed turns alike. AI-assisted; verified with the tests and tools listed above. --- .../RunExecutionService.test.ts | 22 +++++++++---------- .../orchestration-v2/RunExecutionService.ts | 6 +++-- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/apps/server/src/orchestration-v2/RunExecutionService.test.ts b/apps/server/src/orchestration-v2/RunExecutionService.test.ts index 7b49aedbbb59..00f202c86955 100644 --- a/apps/server/src/orchestration-v2/RunExecutionService.test.ts +++ b/apps/server/src/orchestration-v2/RunExecutionService.test.ts @@ -3207,20 +3207,18 @@ it.effect.each(["completed", "failed"] as const)( } as OrchestrationV2ProviderThread, }; }; - return Stream.fromIterable([ - roster(true), - rootTerminalEvent(ids, status), - roster(false), - ]).pipe( - Stream.tap((event) => - event.type === "provider_thread.updated" - ? Ref.set(pending, (event.providerThread.pendingBackgroundTasks?.length ?? 0) > 0) - : Effect.void, - ), - ); + return Stream.fromIterable([roster(true), rootTerminalEvent(ids, status), roster(false)]); }, + // The adapter clears its live roster before ingestion reaches the queued clear. + beforeTerminalWrite: () => Ref.set(pending, false).pipe(Effect.as(true)), ingestNormalized: (input) => - Ref.update(ingested, (all) => [...all, input.event]).pipe(Effect.as([])), + Ref.update(ingested, (all) => [...all, input.event]).pipe( + Effect.as( + input.event.type === "provider_thread.updated" + ? [{} as OrchestrationV2StoredEvent] + : [], + ), + ), }); const rosters = (yield* Ref.get(ingested)).flatMap((event) => event.type === "provider_thread.updated" diff --git a/apps/server/src/orchestration-v2/RunExecutionService.ts b/apps/server/src/orchestration-v2/RunExecutionService.ts index 9d589b96f46d..be21e6e13fd8 100644 --- a/apps/server/src/orchestration-v2/RunExecutionService.ts +++ b/apps/server/src/orchestration-v2/RunExecutionService.ts @@ -1083,7 +1083,7 @@ export const layer: Layer.Layer< ReadonlySet >(new Set(inheritedBackgroundTurnItemsById.keys())); const openRunOwnedSubagents = yield* Ref.make(emptyOpenRunOwnedSubagentProjection()); - // The last stored root snapshot's pendingBackgroundWork; adapters that omit it leave it false. + // The last stored root snapshot still reports background work, by flag or task roster. let rootSnapshotPendingWork = false; const assistantStreaming = makeAssistantStreamingFilter(responseStreamingMode); // Set when ingestion ends or finalization settles the run's open items, which a later @@ -1575,7 +1575,9 @@ export const layer: Layer.Layer< if (event.type === "provider_thread.updated") { if (event.providerThread.id === input.providerThread.id && storedEventCount > 0) { yield* Ref.set(latestProviderThread, event.providerThread); - rootSnapshotPendingWork = event.pendingBackgroundWork === true; + rootSnapshotPendingWork = + event.pendingBackgroundWork === true || + (event.providerThread.pendingBackgroundTasks?.length ?? 0) > 0; } } if (