From 18bd46fa8be26f5ec050ecc5df3be82f4c5f50ff Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sun, 15 Nov 2026 22:26:56 +0000 Subject: [PATCH 1/4] test(acp): a tool call stays open when its agent process exits mid-prompt Fails on main: the prompt-failure path finalizes the turn without ending its open foreground tool calls, so the dead agent's command keeps showing Running in the failed turn (#37368). Co-Authored-By: Claude Opus 5.5 --- .../Adapters/AcpAdapterV2.test.ts | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts index d71b0f7b5e2b8..1767b669ed518 100644 --- a/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts @@ -5191,6 +5191,38 @@ describe("AcpAdapterV2", () => { }).pipe(Effect.provide(layerTest)), ); + it.effect("ends a running tool call when its agent process exits mid-prompt", () => + Effect.gen(function* () { + const harness = yield* makePromptInactivityHarness({ + environment: (runtimeOrdinal) => + runtimeOrdinal === 1 ? { T3_ACP_EMIT_TRACKED_TOOL_CALL_KIND_THEN_HANG: "execute" } : {}, + }); + yield* harness.startTurn(1); + let exited = false; + const statuses = yield* harness.runtime.events.pipe( + Stream.takeUntil((event) => event.type === "turn.terminal"), + Stream.flatMap((event) => + event.type === "turn_item.updated" && + event.turnItem.nativeItemRef?.nativeId === "tracked-tool-call" + ? Stream.make(event.turnItem.status) + : Stream.empty, + ), + // The agent dies while its tool call is open. + Stream.tap(() => + exited + ? Effect.void + : Effect.sync(() => (exited = true)).pipe( + Effect.andThen(harness.natives[0]!.notify("_test/exit", {})), + ), + ), + Stream.runCollect, + Effect.map((collected) => Array.from(collected)), + ); + // regression: #37368 the dead agent's tool call stayed open in the failed turn. + assert.include(["failed", "interrupted", "cancelled"], statuses.at(-1)); + }).pipe(Effect.provide(layerTest)), + ); + it.live("does not poll the process ledger while a cgroup lease owns teardown", () => Effect.gen(function* () { if ((yield* HostProcess.Platform) !== "linux") return; From 56dca014399467a24840a774c9357ff6ce19b4b6 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sun, 15 Nov 2026 22:33:59 +0000 Subject: [PATCH 2/4] fix(server): an ACP agent's open tool call ends when its process dies mid-turn When session/prompt failed (the agent process exited or its pipe broke), the prompt-failure branch finalized the turn as failed without ending its open foreground tool calls, so the dead agent's command kept showing Running with a timer and a Stop button. End them as failed first, as the branch for an error in the prompt's own response already does. Fixes pingdotgg/t3code#37368 Co-Authored-By: Claude Opus 5.5 --- packages/provider-acp/src/server/adapter.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/provider-acp/src/server/adapter.ts b/packages/provider-acp/src/server/adapter.ts index d642cfe200cbd..11c12f267aaaa 100644 --- a/packages/provider-acp/src/server/adapter.ts +++ b/packages/provider-acp/src/server/adapter.ts @@ -8973,6 +8973,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* ( if (!interrupted && flavor.restartRuntimeAfterPromptError?.(failure) === true) { yield* Ref.set(runtimeRestartRequired, true); } + if (!interrupted) yield* terminalizeOpenForegroundTools(context, "failed"); yield* finalizeTurn( context, interrupted ? "interrupted" : "failed", From 81c0dce3330a11aeb4fa86fcdb16836ea30860c2 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sun, 15 Nov 2026 22:51:38 +0000 Subject: [PATCH 3/4] fix(server): keep a surviving ACP agent's tools open after a prompt error An agent that answers session/prompt with an error is still alive, and a command it started keeps running on the Waiting strip until it ends or the user stops background work. Only end open tools as failed when the prompt failed because the agent process or its pipe is gone. Co-Authored-By: Claude Opus 5.5 --- packages/provider-acp/src/server/adapter.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/provider-acp/src/server/adapter.ts b/packages/provider-acp/src/server/adapter.ts index 11c12f267aaaa..5ba534d49847e 100644 --- a/packages/provider-acp/src/server/adapter.ts +++ b/packages/provider-acp/src/server/adapter.ts @@ -8973,7 +8973,13 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* ( if (!interrupted && flavor.restartRuntimeAfterPromptError?.(failure) === true) { yield* Ref.set(runtimeRestartRequired, true); } - if (!interrupted) yield* terminalizeOpenForegroundTools(context, "failed"); + // An agent that answered with an error is still alive and may finish its + // tools; any other failure means its process or pipe is gone. + const agentAnswered = + Result.isSuccess(error) && error.success._tag === "AcpRequestError"; + if (!interrupted && !agentAnswered) { + yield* terminalizeOpenForegroundTools(context, "failed"); + } yield* finalizeTurn( context, interrupted ? "interrupted" : "failed", From 6a7a2e87f6e3e33cbcfb1d201dc21dcd6349571a Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sun, 15 Nov 2026 23:17:34 +0000 Subject: [PATCH 4/4] fix(server): end open ACP tools when the runtime terminates a work-state turn With followAgentWorkState (ACP protocol v2, e.g. Claude ACP), the runtime termination callback finalizes the failed turn before the prompt-failure branch runs, so that branch returned early and the dead agent's tool call kept showing Running. End the turn's open foreground tools as failed there too, unless the turn was interrupted, and cover both modes in the test. Co-Authored-By: Claude Opus 5.5 --- .../Adapters/AcpAdapterV2.test.ts | 68 +++++++++++-------- packages/provider-acp/src/server/adapter.ts | 6 +- 2 files changed, 43 insertions(+), 31 deletions(-) diff --git a/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts index 1767b669ed518..c52cb3900f253 100644 --- a/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts @@ -611,6 +611,7 @@ const makePromptInactivityHarness = Effect.fnUntraced(function* (input: { prompt: AcpSessionRuntime.AcpSessionRuntime["Service"]["prompt"], ) => AcpSessionRuntime.AcpSessionRuntime["Service"]["prompt"]; readonly cancelled?: Deferred.Deferred; + readonly followAgentWorkState?: boolean; }) { const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner; const natives: Array = []; @@ -621,6 +622,7 @@ const makePromptInactivityHarness = Effect.fnUntraced(function* (input: { driver: ACP_TEST_DRIVER, capabilities: AcpProviderCapabilitiesV2, promptInactivityTimeout: "15 minutes", + ...(input.followAgentWorkState === true ? { followAgentWorkState: true } : {}), makeRuntime: makeMockRuntime({ childProcessSpawner, mockAgentPath: yield* bundledMockAgentPath, @@ -639,6 +641,9 @@ const makePromptInactivityHarness = Effect.fnUntraced(function* (input: { }), }, selfInvocation: yield* resolveSelfInvocation(), + ...(input.followAgentWorkState === true + ? { continuationRequests: { offer: () => Effect.void } } + : {}), }); const threadId = ThreadId.make("thread-acp-prompt-inactivity"); const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ @@ -5191,36 +5196,39 @@ describe("AcpAdapterV2", () => { }).pipe(Effect.provide(layerTest)), ); - it.effect("ends a running tool call when its agent process exits mid-prompt", () => - Effect.gen(function* () { - const harness = yield* makePromptInactivityHarness({ - environment: (runtimeOrdinal) => - runtimeOrdinal === 1 ? { T3_ACP_EMIT_TRACKED_TOOL_CALL_KIND_THEN_HANG: "execute" } : {}, - }); - yield* harness.startTurn(1); - let exited = false; - const statuses = yield* harness.runtime.events.pipe( - Stream.takeUntil((event) => event.type === "turn.terminal"), - Stream.flatMap((event) => - event.type === "turn_item.updated" && - event.turnItem.nativeItemRef?.nativeId === "tracked-tool-call" - ? Stream.make(event.turnItem.status) - : Stream.empty, - ), - // The agent dies while its tool call is open. - Stream.tap(() => - exited - ? Effect.void - : Effect.sync(() => (exited = true)).pipe( - Effect.andThen(harness.natives[0]!.notify("_test/exit", {})), - ), - ), - Stream.runCollect, - Effect.map((collected) => Array.from(collected)), - ); - // regression: #37368 the dead agent's tool call stayed open in the failed turn. - assert.include(["failed", "interrupted", "cancelled"], statuses.at(-1)); - }).pipe(Effect.provide(layerTest)), + it.effect.each([false, true])( + "ends a running tool call when its agent process exits mid-prompt (followAgentWorkState: %s)", + (followAgentWorkState) => + Effect.gen(function* () { + const harness = yield* makePromptInactivityHarness({ + followAgentWorkState, + environment: (runtimeOrdinal) => + runtimeOrdinal === 1 ? { T3_ACP_EMIT_TRACKED_TOOL_CALL_KIND_THEN_HANG: "execute" } : {}, + }); + yield* harness.startTurn(1); + let exited = false; + const statuses = yield* harness.runtime.events.pipe( + Stream.takeUntil((event) => event.type === "turn.terminal"), + Stream.flatMap((event) => + event.type === "turn_item.updated" && + event.turnItem.nativeItemRef?.nativeId === "tracked-tool-call" + ? Stream.make(event.turnItem.status) + : Stream.empty, + ), + // The agent dies while its tool call is open. + Stream.tap(() => + exited + ? Effect.void + : Effect.sync(() => (exited = true)).pipe( + Effect.andThen(harness.natives[0]!.notify("_test/exit", {})), + ), + ), + Stream.runCollect, + Effect.map((collected) => Array.from(collected)), + ); + // regression: #37368 the dead agent's tool call stayed open in the failed turn. + assert.include(["failed", "interrupted", "cancelled"], statuses.at(-1)); + }).pipe(Effect.provide(layerTest)), ); it.live("does not poll the process ledger while a cgroup lease owns teardown", () => diff --git a/packages/provider-acp/src/server/adapter.ts b/packages/provider-acp/src/server/adapter.ts index 5ba534d49847e..01bfafd68b11d 100644 --- a/packages/provider-acp/src/server/adapter.ts +++ b/packages/provider-acp/src/server/adapter.ts @@ -2550,12 +2550,16 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* ( yield* Ref.set(continuationRequested, false); yield* cancelPendingRuntimeRequests(); const context = yield* Ref.get(activeTurn); - if (context !== null) + if (context !== null) { + if (!context.finalized && !context.interrupted) { + yield* terminalizeOpenForegroundTools(context, "failed"); + } yield* finalizeTurn( context, "failed", makeProviderFailure({ class: "transport_error" }), ); + } }), ).pipe(Effect.asVoid); const makeRuntimeInput = (