@devries-cameron20 / t3code-1 / commits / 623047ccfd
Fork 0

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

fix(server): an ACP agent's open tool call ends when its process dies mid-turn (#37377)

Julius Marminge committed Nov 15, 2026 at 15:49 UTC 623047ccfd6bbc1281a9ba77065a67468235cb5d
2 files changed +52 -1
apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts
+40
@@ -611,6 +611,7 @@ const makePromptInactivityHarness = Effect.fnUntraced(function* (input: {
611 prompt: AcpSessionRuntime.AcpSessionRuntime["Service"]["prompt"],
612 ) => AcpSessionRuntime.AcpSessionRuntime["Service"]["prompt"];
613 readonly cancelled?: Deferred.Deferred<void>;
614 + readonly followAgentWorkState?: boolean;
615 }) {
616 const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
617 const natives: Array<AcpSessionRuntime.AcpSessionRuntime["Service"]> = [];
@@ -621,6 +622,7 @@ const makePromptInactivityHarness = Effect.fnUntraced(function* (input: {
622 driver: ACP_TEST_DRIVER,
623 capabilities: AcpProviderCapabilitiesV2,
624 promptInactivityTimeout: "15 minutes",
625 + ...(input.followAgentWorkState === true ? { followAgentWorkState: true } : {}),
626 makeRuntime: makeMockRuntime({
627 childProcessSpawner,
628 mockAgentPath: yield* bundledMockAgentPath,
@@ -639,6 +641,9 @@ const makePromptInactivityHarness = Effect.fnUntraced(function* (input: {
641 }),
642 },
643 selfInvocation: yield* resolveSelfInvocation(),
644 + ...(input.followAgentWorkState === true
645 + ? { continuationRequests: { offer: () => Effect.void } }
646 + : {}),
647 });
648 const threadId = ThreadId.make("thread-acp-prompt-inactivity");
649 const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({
@@ -5191,6 +5196,41 @@ describe("AcpAdapterV2", () => {
5196 }).pipe(Effect.provide(layerTest)),
5197 );
5198
5199 + it.effect.each([false, true])(
5200 + "ends a running tool call when its agent process exits mid-prompt (followAgentWorkState: %s)",
5201 + (followAgentWorkState) =>
5202 + Effect.gen(function* () {
5203 + const harness = yield* makePromptInactivityHarness({
5204 + followAgentWorkState,
5205 + environment: (runtimeOrdinal) =>
5206 + runtimeOrdinal === 1 ? { T3_ACP_EMIT_TRACKED_TOOL_CALL_KIND_THEN_HANG: "execute" } : {},
5207 + });
5208 + yield* harness.startTurn(1);
5209 + let exited = false;
5210 + const statuses = yield* harness.runtime.events.pipe(
5211 + Stream.takeUntil((event) => event.type === "turn.terminal"),
5212 + Stream.flatMap((event) =>
5213 + event.type === "turn_item.updated" &&
5214 + event.turnItem.nativeItemRef?.nativeId === "tracked-tool-call"
5215 + ? Stream.make(event.turnItem.status)
5216 + : Stream.empty,
5217 + ),
5218 + // The agent dies while its tool call is open.
5219 + Stream.tap(() =>
5220 + exited
5221 + ? Effect.void
5222 + : Effect.sync(() => (exited = true)).pipe(
5223 + Effect.andThen(harness.natives[0]!.notify("_test/exit", {})),
5224 + ),
5225 + ),
5226 + Stream.runCollect,
5227 + Effect.map((collected) => Array.from(collected)),
5228 + );
5229 + // regression: #37368 the dead agent's tool call stayed open in the failed turn.
5230 + assert.include(["failed", "interrupted", "cancelled"], statuses.at(-1));
5231 + }).pipe(Effect.provide(layerTest)),
5232 + );
5233 +
5234 it.live("does not poll the process ledger while a cgroup lease owns teardown", () =>
5235 Effect.gen(function* () {
5236 if ((yield* HostProcess.Platform) !== "linux") return;
packages/provider-acp/src/server/adapter.ts
+12 -1
@@ -2550,12 +2550,16 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
2550 yield* Ref.set(continuationRequested, false);
2551 yield* cancelPendingRuntimeRequests();
2552 const context = yield* Ref.get(activeTurn);
2553 - if (context !== null)
2553 + if (context !== null) {
2554 + if (!context.finalized && !context.interrupted) {
2555 + yield* terminalizeOpenForegroundTools(context, "failed");
2556 + }
2557 yield* finalizeTurn(
2558 context,
2559 "failed",
2560 makeProviderFailure({ class: "transport_error" }),
2561 );
2562 + }
2563 }),
2564 ).pipe(Effect.asVoid);
2565 const makeRuntimeInput = (
@@ -8973,6 +8977,13 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
8977 if (!interrupted && flavor.restartRuntimeAfterPromptError?.(failure) === true) {
8978 yield* Ref.set(runtimeRestartRequired, true);
8979 }
8980 + // An agent that answered with an error is still alive and may finish its
8981 + // tools; any other failure means its process or pipe is gone.
8982 + const agentAnswered =
8983 + Result.isSuccess(error) && error.success._tag === "AcpRequestError";
8984 + if (!interrupted && !agentAnswered) {
8985 + yield* terminalizeOpenForegroundTools(context, "failed");
8986 + }
8987 yield* finalizeTurn(
8988 context,
8989 interrupted ? "interrupted" : "failed",