@devries-cameron20 / t3code-1 / commits / 47f90ee2e9
Fork 0

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

fix(server): end pending ACP tools when their prompt fails (#37537)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

Wout Stiens committed Nov 16, 2026 at 08:25 UTC 47f90ee2e94086c86b1121eb004adc44b60f5aa9
3 files changed +44 -25
apps/server/scripts/acp-mock-agent.ts
+5 -5
@@ -1414,10 +1414,6 @@ const program = Effect.gen(function* () {
1414 }
1415 }
1416
1417 - if (failPrompt || promptCount === failPromptOrdinal) {
1418 - return yield* AcpError.AcpRequestError.internalError("Mock prompt failure");
1419 - }
1420 -
1417 if (emitTrackedToolCallKindThenHang !== undefined) {
1418 yield* agent.client.sessionUpdate({
1419 sessionId: requestedSessionId,
@@ -1430,7 +1426,11 @@ const program = Effect.gen(function* () {
1426 rawInput: { command: "git status" },
1427 },
1428 });
1433 - return yield* Effect.never;
1429 + if (!failPrompt && promptCount !== failPromptOrdinal) return yield* Effect.never;
1430 + }
1431 +
1432 + if (failPrompt || promptCount === failPromptOrdinal) {
1433 + return yield* AcpError.AcpRequestError.internalError("Mock prompt failure");
1434 }
1435
1436 if (hangPromptForever || (emitEmptySuccessfulBashThenHang && promptCount === 2)) {
apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts
+31 -16
@@ -5207,28 +5207,35 @@ describe("AcpAdapterV2", () => {
5207 }).pipe(Effect.provide(layerTest)),
5208 );
5209
5210 - it.effect.each([false, true])(
5211 - "ends a running tool call when its agent process exits mid-prompt (followAgentWorkState: %s)",
5212 - (followAgentWorkState) =>
5210 + it.effect.each(
5211 + [false, true].flatMap((followAgentWorkState) => [
5212 + { ending: "agent process exits mid-prompt", followAgentWorkState },
5213 + { ending: "prompt returns an RPC error", followAgentWorkState },
5214 + ]),
5215 + )(
5216 + "ends an open tool call when its $ending (followAgentWorkState: $followAgentWorkState)",
5217 + ({ ending, followAgentWorkState }) =>
5218 Effect.gen(function* () {
5219 + const agentExits = ending === "agent process exits mid-prompt";
5220 const harness = yield* makePromptInactivityHarness({
5221 followAgentWorkState,
5222 environment: (runtimeOrdinal) =>
5217 - runtimeOrdinal === 1 ? { T3_ACP_EMIT_TRACKED_TOOL_CALL_KIND_THEN_HANG: "execute" } : {},
5223 + runtimeOrdinal === 1
5224 + ? {
5225 + T3_ACP_EMIT_TRACKED_TOOL_CALL_KIND_THEN_HANG: "execute",
5226 + ...(agentExits ? {} : { T3_ACP_FAIL_PROMPT: "1" }),
5227 + }
5228 + : {},
5229 });
5230 yield* harness.startTurn(1);
5220 - let exited = false;
5221 - const statuses = yield* harness.runtime.events.pipe(
5231 + let exited = !agentExits;
5232 + const events = yield* harness.runtime.events.pipe(
5233 Stream.takeUntil((event) => event.type === "turn.terminal"),
5223 - Stream.flatMap((event) =>
5224 - event.type === "turn_item.updated" &&
5225 - event.turnItem.nativeItemRef?.nativeId === "tracked-tool-call"
5226 - ? Stream.make(event.turnItem.status)
5227 - : Stream.empty,
5228 - ),
5234 // The agent dies while its tool call is open.
5230 - Stream.tap(() =>
5231 - exited
5235 + Stream.tap((event) =>
5236 + exited ||
5237 + event.type !== "turn_item.updated" ||
5238 + event.turnItem.nativeItemRef?.nativeId !== "tracked-tool-call"
5239 ? Effect.void
5240 : Effect.sync(() => (exited = true)).pipe(
5241 Effect.andThen(harness.natives[0]!.notify("_test/exit", {})),
@@ -5237,8 +5244,16 @@ describe("AcpAdapterV2", () => {
5244 Stream.runCollect,
5245 Effect.map((collected) => Array.from(collected)),
5246 );
5240 - // regression: #37368 the dead agent's tool call stayed open in the failed turn.
5241 - assert.include(["failed", "interrupted", "cancelled"], statuses.at(-1));
5247 + const toolStatuses = events.flatMap((event) =>
5248 + event.type === "turn_item.updated" &&
5249 + event.turnItem.nativeItemRef?.nativeId === "tracked-tool-call"
5250 + ? [event.turnItem.status]
5251 + : [],
5252 + );
5253 + // regression: #37368 the tool call stayed open in the failed turn.
5254 + assert.equal(toolStatuses.at(-1), "failed");
5255 + const terminal = events.at(-1);
5256 + assert.equal(terminal?.type === "turn.terminal" ? terminal.status : undefined, "failed");
5257 }).pipe(Effect.provide(layerTest)),
5258 );
5259
packages/provider-acp/src/server/adapter.ts
+8 -4
@@ -7957,10 +7957,12 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
7957 const terminalizeOpenForegroundTools = Effect.fnUntraced(function* (
7958 context: ActiveAcpTurn,
7959 status: "completed" | "failed" = "completed",
7960 + options?: { readonly unstartedOnly?: boolean },
7961 ) {
7962 for (const tool of context.tools.values()) {
7963 if (!acpCompletedTurnShouldTerminalizeTool(tool, { ...flavor, extractSubagentUpdate }))
7964 continue;
7965 + if (options?.unstartedOnly === true && tool.status !== "pending") continue;
7966 yield* emitTool(context, tool, status);
7967 }
7968 });
@@ -8973,12 +8975,14 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
8975 if (!interrupted && flavor.restartRuntimeAfterPromptError?.(failure) === true) {
8976 yield* Ref.set(runtimeRestartRequired, true);
8977 }
8976 - // An agent that answered with an error is still alive and may finish its
8977 - // tools; any other failure means its process or pipe is gone.
8978 + // An agent that answered with an error may still finish tools it started,
8979 + // never pending ones; any other failure means its process or pipe is gone.
8980 const agentAnswered =
8981 Result.isSuccess(error) && error.success._tag === "AcpRequestError";
8980 - if (!interrupted && !agentAnswered) {
8981 - yield* terminalizeOpenForegroundTools(context, "failed");
8982 + if (!interrupted) {
8983 + yield* terminalizeOpenForegroundTools(context, "failed", {
8984 + unstartedOnly: agentAnswered,
8985 + });
8986 }
8987 yield* finalizeTurn(
8988 context,