From 011773dc997e15f56fbb9b137ad31ebd3d92e4e0 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sun, 15 Nov 2026 10:40:13 +0000 Subject: [PATCH 1/3] test(provider-acp): reportless Grok task completion must not replace the root answer Failing tests for #22865: an unpolled background command that completes before the root prompt settles starts an empty continuation, whose result replaces the child's final answer. Co-Authored-By: Claude Opus 5.5 --- .../Adapters/AcpAdapterV2.test.ts | 39 ++++++++++++++++--- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts index 7643610fd850..fe772580d35c 100644 --- a/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts @@ -9462,7 +9462,7 @@ describe("AcpAdapterV2", () => { ); it.effect( - "staggered pre-settle completion keeps midTurn marks until last background task ends post-finalize", + "staggered pre-settle completion waits for native wake output after the last background task ends", () => Effect.gen(function* () { const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner; @@ -9655,12 +9655,19 @@ describe("AcpAdapterV2", () => { "mutation-only end-notice must not count as post-settle wake evidence", ); yield* sessionUpdateHandler!(bEndNotice); - yield* Effect.yieldNow; - yield* Effect.yieldNow; + assert.lengthOf(continuationRequests, 0, "a task end notice alone cannot start a wake"); + assert.isTrue(yield* runtime.hasPendingBackgroundWork!); + yield* sessionUpdateHandler!({ + sessionId: "mock-session-1", + update: { + sessionUpdate: "agent_message_chunk", + content: { type: "text", text: "Both background tasks finished." }, + }, + }); assert.lengthOf( continuationRequests, 1, - "exactly one continuation when the last running task ends post-finalize with kept midTurn marks", + "the native report must start exactly one continuation", ); }).pipe(Effect.provide(layerTest)), ); @@ -10311,6 +10318,11 @@ describe("AcpAdapterV2", () => { yield* complete("early"); assert.lengthOf(continuationRequests, 0); + yield* update({ + sessionUpdate: "agent_message_chunk", + content: { type: "text", text: "EARLY_SUCCESS_DONE" }, + }); + let backgroundItem: ProviderAdapter.ProviderAdapterV2Event | undefined; let checkpoint = 0; const assertCommand = Effect.fnUntraced(function* (expectedStatus: string, output: string) { @@ -10387,9 +10399,26 @@ describe("AcpAdapterV2", () => { } break; } - yield* Deferred.await(continuationOffered); yield* complete("early"); yield* complete("blocker"); + assert.lengthOf( + continuationRequests, + 0, + "a task completion without native wake output must not replace the root answer", + ); + assert.isTrue(yield* runtime.hasPendingBackgroundWork!); + + yield* update({ + sessionUpdate: "agent_thought_chunk", + content: { type: "text", text: "Preparing the background report" }, + }); + yield* complete("early"); + assert.lengthOf(continuationRequests, 0, "reasoning alone is not a result-bearing wake"); + yield* update({ + sessionUpdate: "agent_message_chunk", + content: { type: "text", text: "LATE_NATIVE_ANSWER" }, + }); + yield* Deferred.await(continuationOffered); assert.lengthOf( continuationRequests, 1, From 1dd737b4ea8aa03e3e8edef12049133816e8e726 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sun, 15 Nov 2026 10:56:25 +0000 Subject: [PATCH 2/3] fix(provider-acp): Grok early task completion no longer replaces the child's answer An unpolled Grok background task that finished before the root prompt settled queued a continuation with no native wake output. That empty run became the latest terminal run, so the delegated result reported "Child task completed without an assistant result." instead of the answer. Offer the post-settle continuation only when the wake buffer holds result-bearing evidence (assistant text or a completed/failed tool update), and keep the unreported completion pending until the native wake arrives. Fixes #22865 Co-Authored-By: Claude Opus 5.5 --- packages/provider-acp/src/server/adapter.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/provider-acp/src/server/adapter.ts b/packages/provider-acp/src/server/adapter.ts index dc12bd7aa1e1..ba678c8f625d 100644 --- a/packages/provider-acp/src/server/adapter.ts +++ b/packages/provider-acp/src/server/adapter.ts @@ -4945,8 +4945,9 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* ( postSettleContinuationEnabled && (yield* Ref.get(activeSessionId)) === sessionId && (yield* Ref.get(runningBackgroundTaskIds)).size === 0 && - ((yield* Ref.get(wakeBuffer)).length > 0 || - (yield* Ref.get(midTurnUnreportedCompletedTaskIds)).size > 0) + (yield* Ref.get(wakeBuffer)).some((notification) => + acpPostSettleContinuationOfferEvidence(notification, flavor), + ) ) { yield* offerContinuationRun(sessionId); } @@ -8180,18 +8181,16 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* ( settledStatus === "completed" && !directStopQuarantine && (yield* Ref.get(runningBackgroundTaskIds)).size === 0 && - ((yield* Ref.get(wakeBuffer)).length > 0 || - (yield* Ref.get(midTurnUnreportedCompletedTaskIds)).size > 0) + (yield* Ref.get(wakeBuffer)).some((notification) => + acpPostSettleContinuationOfferEvidence(notification, flavor), + ) ) { const sessionId = yield* Ref.get(activeSessionId); if (sessionId !== null) { yield* offerContinuationRun(sessionId); } } - if ( - settledStatus !== "completed" || - (yield* Ref.get(runningBackgroundTaskIds)).size === 0 - ) { + if (settledStatus !== "completed") { yield* Ref.set(midTurnUnreportedCompletedTaskIds, new Set()); } yield* Deferred.succeed(context.completed, undefined).pipe(Effect.ignore); @@ -9081,6 +9080,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* ( ) return true; if ((yield* Ref.get(wakeBuffer)).length > 0) return true; + if ((yield* Ref.get(midTurnUnreportedCompletedTaskIds)).size > 0) return true; if (yield* Ref.get(continuationRequested)) return true; if ((yield* Ref.get(runningBackgroundTaskIds)).size > 0) return true; const active = yield* Ref.get(activeTurn); From adc8cb120ac23f290d520a8721a77f2a458a995c Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sun, 15 Nov 2026 11:16:41 +0000 Subject: [PATCH 3/3] fix(provider-acp): keep native reports for unpolled tasks after another task was polled Agent chunks were treated as monitor chatter whenever any background task was handled in the turn. With an unpolled early completion now kept pending until its native wake, that report was dropped, so the task stayed unreported. Skip the chatter suppression while an unreported completion is outstanding. Co-Authored-By: Claude Opus 5.5 --- .../Adapters/AcpAdapterV2.test.ts | 60 +++++++++++-------- packages/provider-acp/src/server/adapter.ts | 3 + 2 files changed, 39 insertions(+), 24 deletions(-) diff --git a/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts index fe772580d35c..d71b0f7b5e2b 100644 --- a/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts @@ -9461,9 +9461,9 @@ describe("AcpAdapterV2", () => { }).pipe(Effect.provide(layerTest)), ); - it.effect( - "staggered pre-settle completion waits for native wake output after the last background task ends", - () => + it.effect.each(["unpolled", "polled"] as const)( + "staggered pre-settle completion waits for native wake output when task B is %s", + (taskB) => Effect.gen(function* () { const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner; const idAllocator = yield* IdAllocator.IdAllocatorV2; @@ -9615,6 +9615,16 @@ describe("AcpAdapterV2", () => { 0, "pre-settle unhandled completion must not offer while the turn is active", ); + if (taskB === "polled") { + yield* sessionUpdateHandler!({ + sessionId: "mock-session-1", + update: { + sessionUpdate: "tool_call_update", + toolCallId: "tool-call-monitor-b", + status: "completed", + }, + }); + } yield* Deferred.succeed(promptGate, { stopReason: "end_turn" }); const providerTurnId = idAllocator.derive.providerTurn({ @@ -9632,30 +9642,32 @@ describe("AcpAdapterV2", () => { assert.lengthOf( continuationRequests, 0, - "finalize must not offer while B is still running", + "finalize must not offer without native wake output", ); - const bEndNotice = { - sessionId: "mock-session-1", - update: { - sessionUpdate: "user_message_chunk" as const, - content: { - type: "text" as const, - text: 'Monitor "task-monitor-b" ended: [monitor ended: exit 0]', + if (taskB === "unpolled") { + const bEndNotice = { + sessionId: "mock-session-1", + update: { + sessionUpdate: "user_message_chunk" as const, + content: { + type: "text" as const, + text: 'Monitor "task-monitor-b" ended: [monitor ended: exit 0]', + }, }, - }, - }; - assert.isFalse( - acpPostSettleWakeEvidence(bEndNotice, { - extractBackgroundToolMutation: (text) => - text.includes('Monitor "task-monitor-b" ended') - ? [{ taskId: "task-monitor-b", status: "completed", appendOutput: "" }] - : [], - }), - "mutation-only end-notice must not count as post-settle wake evidence", - ); - yield* sessionUpdateHandler!(bEndNotice); - assert.lengthOf(continuationRequests, 0, "a task end notice alone cannot start a wake"); + }; + assert.isFalse( + acpPostSettleWakeEvidence(bEndNotice, { + extractBackgroundToolMutation: (text) => + text.includes('Monitor "task-monitor-b" ended') + ? [{ taskId: "task-monitor-b", status: "completed", appendOutput: "" }] + : [], + }), + "mutation-only end-notice must not count as post-settle wake evidence", + ); + yield* sessionUpdateHandler!(bEndNotice); + assert.lengthOf(continuationRequests, 0, "a task end notice alone cannot start a wake"); + } assert.isTrue(yield* runtime.hasPendingBackgroundWork!); yield* sessionUpdateHandler!({ sessionId: "mock-session-1", diff --git a/packages/provider-acp/src/server/adapter.ts b/packages/provider-acp/src/server/adapter.ts index ba678c8f625d..9e75e70b44da 100644 --- a/packages/provider-acp/src/server/adapter.ts +++ b/packages/provider-acp/src/server/adapter.ts @@ -5067,8 +5067,10 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* ( } const backgroundWorkRunning = (yield* Ref.get(runningBackgroundTaskIds)).size > 0; const handledInTurnCount = (yield* Ref.get(handledBackgroundTaskIdsInActiveTurn)).size; + // Chunks carry no task id: while an unpolled completion awaits its report, keep them. const isInTurnHandledAgentChatter = handledInTurnCount > 0 && + (yield* Ref.get(midTurnUnreportedCompletedTaskIds)).size === 0 && (update.sessionUpdate === "agent_message_chunk" || update.sessionUpdate === "agent_thought_chunk"); // Grok re-prompts for each post-settle monitor event; retaining them would replay the whole burst. @@ -5399,6 +5401,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* ( context !== null && context.finalized && (yield* Ref.get(handledBackgroundTaskIdsInActiveTurn)).size > 0 && + (yield* Ref.get(midTurnUnreportedCompletedTaskIds)).size === 0 && (update.sessionUpdate === "agent_message_chunk" || update.sessionUpdate === "agent_thought_chunk") ) {