The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 18:15 UTC
fix(acp): idle agent errors fail their turns (#24615)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 24, 2026 at 17:05 UTC
5a969c17e76301e45e53e1fd9aad2f5b4599d865
7 files changed
+427
-22
apps/server/scripts/acp-mock-agent.ts
+118
@@ -962,6 +962,124 @@ const program = Effect.gen(function* () {
962
const requestedSessionId = String(request.sessionId ?? sessionId);
963
beginAcpMockPrompt(cancelledSessions, requestedSessionId);
964
promptCount += 1;
965
+ const idleError = process.env.T3_ACP_IDLE_ERROR;
966
+ if (idleError === "grok-background" && promptCount === 1) {
967
+ // The structured completion lands before the prompt settles, so it is buffered.
968
+ const taskId = "call-idle-error-background";
969
+ writeJsonRpcNotification("session/update", {
970
+ sessionId: requestedSessionId,
971
+ update: {
972
+ sessionUpdate: "tool_call",
973
+ toolCallId: taskId,
974
+ title: "run_terminal_command",
975
+ kind: "execute",
976
+ status: "in_progress",
977
+ rawInput: { command: "sleep 1; echo done" },
978
+ },
979
+ });
980
+ writeJsonRpcNotification("session/update", {
981
+ sessionId: requestedSessionId,
982
+ update: {
983
+ sessionUpdate: "tool_call_update",
984
+ toolCallId: taskId,
985
+ status: "completed",
986
+ rawOutput: {
987
+ type: "BackgroundTaskStarted",
988
+ task_id: taskId,
989
+ task_type: "bash",
990
+ status: "running",
991
+ command: "sleep 1; echo done",
992
+ },
993
+ },
994
+ });
995
+ writeJsonRpcNotification("_x.ai/task_completed", {
996
+ sessionId: requestedSessionId,
997
+ update: {
998
+ sessionUpdate: "task_completed",
999
+ task_snapshot: { task_id: taskId, kind: "bash", exit_code: 0, output: "done\n" },
1000
+ },
1001
+ });
1002
+ writeJsonRpcNotification("session/update", {
1003
+ sessionId: requestedSessionId,
1004
+ update: { sessionUpdate: "state_update", state: "idle", stopReason: "error" },
1005
+ });
1006
+ return {};
1007
+ }
1008
+ if (idleError !== undefined && promptCount === 1) {
1009
+ const toolCallId = "tool-call-idle-error-1";
1010
+ writeJsonRpcNotification("session/update", {
1011
+ sessionId: requestedSessionId,
1012
+ update: {
1013
+ sessionUpdate: "tool_call_update",
1014
+ toolCallId,
1015
+ title: "Terminal",
1016
+ kind: "execute",
1017
+ status: "in_progress",
1018
+ rawInput: { command: ["long-running-tool"] },
1019
+ },
1020
+ });
1021
+ writeJsonRpcNotification("session/update", {
1022
+ sessionId: requestedSessionId,
1023
+ update: {
1024
+ sessionUpdate: "tool_call_update",
1025
+ toolCallId: "tool-call-idle-error-monitor",
1026
+ title: "Monitor",
1027
+ kind: "execute",
1028
+ status: "in_progress",
1029
+ rawInput: { command: ["background-monitor"] },
1030
+ },
1031
+ });
1032
+ writeJsonRpcNotification("session/update", {
1033
+ sessionId: requestedSessionId,
1034
+ update: {
1035
+ sessionUpdate: "tool_call_update",
1036
+ toolCallId: "tool-call-idle-error-subagent",
1037
+ title: "Subagent",
1038
+ kind: "other",
1039
+ status: "in_progress",
1040
+ rawInput: {},
1041
+ },
1042
+ });
1043
+ writeJsonRpcNotification("session/update", {
1044
+ sessionId: "mock-child-session-idle-error",
1045
+ update: {
1046
+ sessionUpdate: "tool_call_update",
1047
+ toolCallId: "tool-call-idle-error-child",
1048
+ title: "Child tool",
1049
+ kind: "execute",
1050
+ status: "in_progress",
1051
+ rawInput: { command: ["child-tool"] },
1052
+ },
1053
+ });
1054
+ writeJsonRpcNotification("session/update", {
1055
+ sessionId: requestedSessionId,
1056
+ update: {
1057
+ sessionUpdate: "state_update",
1058
+ state: "idle",
1059
+ stopReason: "error",
1060
+ ...(idleError === "details"
1061
+ ? { error: { code: -32000, message: "Missing Authentication header" } }
1062
+ : {}),
1063
+ },
1064
+ });
1065
+ // The agent outlives the failed prompt, so its subagent finishes afterwards.
1066
+ yield* Effect.sleep("50 millis").pipe(
1067
+ Effect.andThen(
1068
+ Effect.sync(() =>
1069
+ writeJsonRpcNotification("session/update", {
1070
+ sessionId: requestedSessionId,
1071
+ update: {
1072
+ sessionUpdate: "tool_call_update",
1073
+ toolCallId: "tool-call-idle-error-subagent",
1074
+ status: "completed",
1075
+ },
1076
+ }),
1077
+ ),
1078
+ ),
1079
+ Effect.forkDetach,
1080
+ );
1081
+ return {};
1082
+ }
1083
if (
1084
process.env.T3_ACP_CRASH_PROMPT === "1" &&
1085
request.prompt.some((part) => part.type === "text" && part.text === "crash now")
apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts
+211
@@ -399,6 +399,151 @@ function assertReinjectedInstructions(
399
}
400
401
describe("AcpAdapterV2", () => {
402
+ it.live.each(["details", "none"] as const)(
403
+ "fails the turn on an ACP v2 idle error with %s, settles its open tool, and accepts the next prompt",
404
+ (details) =>
405
+ Effect.gen(function* () {
406
+ const path = yield* Path.Path;
407
+ const instanceId = ProviderInstanceId.make(`idle-error-${details}`);
408
+ const threadId = ThreadId.make(`thread-idle-error-${details}`);
409
+ const childSessionId = "mock-child-session-idle-error";
410
+ const adapter = yield* makeAcpAdapterV2({
411
+ instanceId,
412
+ selfInvocation: yield* resolveSelfInvocation(),
413
+ flavor: {
414
+ driver: ACP_TEST_DRIVER,
415
+ capabilities: AcpProviderCapabilitiesV2,
416
+ extractBackgroundTaskId: (toolCall) =>
417
+ toolCall.toolCallId === "tool-call-idle-error-monitor"
418
+ ? "idle-error-monitor"
419
+ : undefined,
420
+ extractSubagentUpdate: (toolCall) =>
421
+ toolCall.toolCallId === "tool-call-idle-error-subagent"
422
+ ? {
423
+ nativeTaskId: "task-idle-error",
424
+ prompt: "child work",
425
+ title: "child work",
426
+ model: null,
427
+ status: toolCall.status === "completed" ? "completed" : "running",
428
+ childSessionId,
429
+ result: null,
430
+ suppressNormalTool: true,
431
+ }
432
+ : undefined,
433
+ makeRuntime: makeMockRuntime({
434
+ childProcessSpawner: yield* ChildProcessSpawner.ChildProcessSpawner,
435
+ mockAgentPath: yield* path.fromFileUrl(
436
+ new URL("../../../scripts/acp-mock-agent.ts", import.meta.url),
437
+ ),
438
+ environment: { T3_ACP_IDLE_ERROR: details },
439
+ }),
440
+ },
441
+ });
442
+ const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({
443
+ runtimeMode: "full-access",
444
+ interactionMode: "default",
445
+ cwd: process.cwd(),
446
+ });
447
+ const modelSelection = { instanceId, model: "default" } as const;
448
+ const runtime = yield* adapter.openSession({
449
+ threadId,
450
+ providerSessionId: ProviderSessionId.make(`session-idle-error-${details}`),
451
+ modelSelection,
452
+ runtimePolicy,
453
+ });
454
+ const providerThread = yield* runtime.ensureThread({
455
+ threadId,
456
+ modelSelection,
457
+ runtimePolicy,
458
+ });
459
+ const runTurn = (ordinal: number) =>
460
+ Effect.gen(function* () {
461
+ yield* runtime.startTurn(
462
+ makeTurnInput({
463
+ threadId,
464
+ providerThread,
465
+ instanceId,
466
+ runtimePolicy,
467
+ now: yield* DateTime.now,
468
+ ordinal,
469
+ }),
470
+ );
471
+ return yield* runtime.events.pipe(
472
+ Stream.takeUntil((event) => event.type === "turn.terminal"),
473
+ Stream.runCollect,
474
+ );
475
+ });
476
+
477
+ const failedEvents = yield* runTurn(1);
478
+ const failed = failedEvents.at(-1);
479
+ assert.equal(failed?.type, "turn.terminal");
480
+ if (failed?.type !== "turn.terminal" || failed.status !== "failed") {
481
+ return assert.fail("expected a failed terminal");
482
+ }
483
+ assert.isTrue(
484
+ failed.childTurnsContinue,
485
+ "the run keeps ingesting work that outlives the failed prompt",
486
+ );
487
+ const lateSubagent = yield* runtime.events.pipe(
488
+ Stream.filter(
489
+ (event) => event.type === "subagent.updated" && event.subagent.status === "completed",
490
+ ),
491
+ Stream.runHead,
492
+ Effect.timeoutOption("2 seconds"),
493
+ );
494
+ assert.isTrue(
495
+ Option.isSome(lateSubagent) && Option.isSome(lateSubagent.value),
496
+ "a subagent finishing after the failed prompt still reports to the run",
497
+ );
498
+ assert.deepEqual(
499
+ failed.failure,
500
+ details === "details"
501
+ ? {
502
+ class: "provider_error",
503
+ message: "Missing Authentication header",
504
+ code: "-32000",
505
+ retryable: null,
506
+ }
507
+ : {
508
+ class: "provider_error",
509
+ message: "Provider turn failed.",
510
+ code: null,
511
+ retryable: null,
512
+ },
513
+ );
514
+ const toolItems = (nativeId: string) =>
515
+ failedEvents.flatMap((event) =>
516
+ event.type === "turn_item.updated" &&
517
+ event.turnItem.nativeItemRef?.nativeId === nativeId
518
+ ? [event.turnItem]
519
+ : [],
520
+ );
521
+ const toolStatuses = toolItems("tool-call-idle-error-1").map((item) => item.status);
522
+ assert.include(toolStatuses, "running");
523
+ assert.equal(toolStatuses.at(-1), "failed");
524
+ assert.deepEqual(
525
+ toolItems("tool-call-idle-error-monitor").map((item) => item.status),
526
+ ["running"],
527
+ "a background monitor outlives the failed turn and keeps its running row",
528
+ );
529
+ const childItems = toolItems("task-idle-error:tool:tool-call-idle-error-child");
530
+ assert.deepEqual(
531
+ childItems.map((item) => item.status),
532
+ ["running"],
533
+ "a child-session tool keeps running in its own thread",
534
+ );
535
+ assert.isTrue(childItems.every((item) => item.threadId !== threadId));
536
+ assert.isEmpty(
537
+ toolItems("tool-call-idle-error-child"),
538
+ "the failed turn must not reproject the child tool as a root tool",
539
+ );
540
+
541
+ const nextEvents = yield* runTurn(2);
542
+ const next = nextEvents.at(-1);
543
+ assert.equal(next?.type === "turn.terminal" ? next.status : undefined, "completed");
544
+ }).pipe(Effect.provide(layerTest), Effect.scoped),
545
+ );
546
+
547
// Factory Droid 0.243.0 sends an optional text companion for every AskUser choice.
548
const droidChoice = {
549
type: "string",
@@ -3082,6 +3227,72 @@ describe("AcpAdapterV2", () => {
3227
}).pipe(Effect.provide(layerTest), Effect.scoped),
3228
);
3229
3230
+ it.live("settles a Grok background command that completed before an ACP v2 idle error", () =>
3231
+ Effect.gen(function* () {
3232
+ const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
3233
+ const path = yield* Path.Path;
3234
+ const mockAgentPath = yield* path.fromFileUrl(
3235
+ new URL("../../../scripts/acp-mock-agent.ts", import.meta.url),
3236
+ );
3237
+ const instanceId = ProviderInstanceId.make("grok-idle-error-background");
3238
+ const adapter = yield* makeGrokAdapterV2({
3239
+ instanceId,
3240
+ settings: DEFAULT_GROK_SETTINGS,
3241
+ environment: {},
3242
+ hostPlatform: yield* HostProcess.Platform,
3243
+ selfInvocation: yield* resolveSelfInvocation(),
3244
+ makeRuntime: (input) =>
3245
+ makeMockRuntime({
3246
+ childProcessSpawner,
3247
+ mockAgentPath,
3248
+ environment: { T3_ACP_IDLE_ERROR: "grok-background" },
3249
+ })(input).pipe(Effect.flatMap(makeXAiPromptCompletionRuntime)),
3250
+ });
3251
+ const threadId = ThreadId.make("grok-idle-error-background");
3252
+ const modelSelection = { instanceId, model: "default" } as const;
3253
+ const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({
3254
+ runtimeMode: "full-access",
3255
+ interactionMode: "default",
3256
+ cwd: process.cwd(),
3257
+ });
3258
+ const runtime = yield* adapter.openSession({
3259
+ threadId,
3260
+ providerSessionId: ProviderSessionId.make("grok-idle-error-background"),
3261
+ modelSelection,
3262
+ runtimePolicy,
3263
+ });
3264
+ const providerThread = yield* runtime.ensureThread({
3265
+ threadId,
3266
+ modelSelection,
3267
+ runtimePolicy,
3268
+ });
3269
+ yield* runtime.startTurn(
3270
+ makeTurnInput({
3271
+ threadId,
3272
+ providerThread,
3273
+ instanceId,
3274
+ runtimePolicy,
3275
+ now: yield* DateTime.now,
3276
+ }),
3277
+ );
3278
+ const events = yield* runtime.events.pipe(
3279
+ Stream.takeUntil((event) => event.type === "turn.terminal"),
3280
+ Stream.runCollect,
3281
+ );
3282
+ const terminal = events.at(-1);
3283
+ assert.equal(terminal?.type === "turn.terminal" ? terminal.status : undefined, "failed");
3284
+ const command = events.findLast(
3285
+ (event) =>
3286
+ event.type === "turn_item.updated" &&
3287
+ event.turnItem.nativeItemRef?.nativeId === "call-idle-error-background",
3288
+ );
3289
+ assert.equal(
3290
+ command?.type === "turn_item.updated" ? command.turnItem.status : undefined,
3291
+ "completed",
3292
+ );
3293
+ }).pipe(Effect.provide(layerTest), Effect.scoped),
3294
+ );
3295
+
3296
// Oracle: Grok incident frames. Command completion must release the turn even
3297
// when the CLI keeps the prompt RPC and process alive. Command polls stay visible.
3298
it.live(
apps/server/src/orchestration-v2/RunExecutionService.test.ts
+11
@@ -1850,6 +1850,17 @@ it.effect.each([null, "run:nested-sdk"] as const)(
1850
}),
1851
);
1852
1853
+it.effect("keeps ingesting a failed root's background item when its work continues", () =>
1854
+ Effect.gen(function* () {
1855
+ const observed = yield* runBackgroundItemScenario("bg-failed-continues", (ids) => [
1856
+ backgroundTurnItemEvent(ids, "command_execution", "running", 1),
1857
+ { ...rootTerminalEvent(ids, "failed"), childTurnsContinue: true },
1858
+ backgroundTurnItemEvent(ids, "command_execution", "completed", 2),
1859
+ ]);
1860
+ assert.deepEqual(observed, ["turn_item:running", "root-finalized", "turn_item:completed"]);
1861
+ }),
1862
+);
1863
+
1864
it.effect("does not pin ingestion on background items when the root turn is interrupted", () =>
1865
Effect.gen(function* () {
1866
const observed = yield* runBackgroundItemScenario("bg-interrupted", (ids) => [
packages/effect-acp/src/client.test.ts
+31
@@ -1307,6 +1307,37 @@ it.layer(NodeServices.layer)("effect-acp client", (it) => {
1307
}),
1308
);
1309
1310
+ it.effect("returns the ACP v2 idle error as the prompt result", () =>
1311
+ Effect.gen(function* () {
1312
+ const { stdio, input, output } = yield* makeInMemoryStdio();
1313
+ const acp = yield* AcpClient.make(stdio);
1314
+ const error = { code: -32000, message: "Missing Authentication header" };
1315
+ const prompt = yield* acp.agent
1316
+ .prompt({ sessionId: "idle-error", prompt: [{ type: "text", text: "Hello" }] })
1317
+ .pipe(Effect.forkScoped);
1318
+ const request = yield* decodePromptRequestLine(yield* Queue.take(output));
1319
+ yield* Queue.offer(
1320
+ input,
1321
+ concatBytes([
1322
+ yield* encodeJsonl(jsonRpcResponse(Schema.Unknown), {
1323
+ jsonrpc: "2.0",
1324
+ id: request.id,
1325
+ result: { messageId: `user-${request.id}` },
1326
+ }),
1327
+ yield* encodeJsonl(SessionUpdateNotification, {
1328
+ jsonrpc: "2.0",
1329
+ method: "session/update",
1330
+ params: {
1331
+ sessionId: "idle-error",
1332
+ update: { sessionUpdate: "state_update", state: "idle", stopReason: "error", error },
1333
+ },
1334
+ }),
1335
+ ]),
1336
+ );
1337
+ assert.deepEqual(yield* Fiber.join(prompt), { stopReason: "error", error });
1338
+ }).pipe(Effect.scoped),
1339
+ );
1340
+
1341
it.effect("routes MCP-over-ACP connect, message, notification, and disconnect callbacks", () =>
1342
Effect.gen(function* () {
1343
const handle = yield* makeHandle({ ACP_MOCK_MCP_OVER_ACP: "1" });
packages/effect-acp/src/client.ts
+1
@@ -797,6 +797,7 @@ export const make = Effect.fn("effect-acp/AcpClient.make")(function* (
797
return Deferred.succeed(completion, {
798
stopReason: idle.stopReason ?? "end_turn",
799
...(idle.usage === undefined ? {} : { usage: idle.usage }),
800
+ ...(idle.error === undefined ? {} : { error: idle.error }),
801
...(idle._meta === undefined ? {} : { _meta: idle._meta }),
802
}).pipe(Effect.asVoid);
803
})
packages/effect-acp/src/compat.ts
+1
@@ -242,6 +242,7 @@ export type PromptRequest = Omit<V2.PromptRequest, "prompt"> & {
242
export interface PromptResponse {
243
readonly stopReason: StopReason;
244
readonly usage?: V2.Usage | null;
245
+ readonly error?: V2.Error | null;
246
readonly _meta?: Meta;
247
}
248
packages/provider-acp/src/server/adapter.ts
+54
-22
@@ -1314,7 +1314,8 @@ function acpSubagentHasPendingBackgroundWork(subagent: ActiveAcpSubagent): boole
1314
1315
type AcpCarryoverSubagents = {
1316
readonly sessionId: string;
1317
- readonly rootTerminalStatus: "completed" | "interrupted" | "failed" | "cancelled";
1317
+ /** The root's subscriber keeps ingesting, so late child terminals can still project. */
1318
+ readonly projectsLateTerminals: boolean;
1319
readonly subagents: ReadonlyArray<ActiveAcpSubagent>;
1320
};
1321
@@ -3373,6 +3374,16 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
3374
return false;
3375
};
3376
3377
+ const hasSurvivingBackgroundWork = (context: ActiveAcpTurn): boolean =>
3378
+ [...context.toolCallIdsByBackgroundTaskId.values()].some((toolCallId) => {
3379
+ const tool = context.tools.get(toolCallId);
3380
+ const status = tool === undefined ? undefined : toolStatus(tool.status);
3381
+ return status === "pending" || status === "running";
3382
+ }) ||
3383
+ [...context.subagents.values()].some((subagent) =>
3384
+ acpSubagentStatusBlocksTurnSettlement(subagent.task.status),
3385
+ );
3386
+
3387
const rearmDeferredFinalize =
3388
/* Provider events include streaming deltas; avoid a span for each update. */
3389
Effect.fnUntraced(function* (context: ActiveAcpTurn) {
@@ -4443,6 +4454,20 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
4454
return true;
4455
});
4456
4457
+ const idleErrorFailure = (error: EffectAcpSchema.PromptResponse["error"]) =>
4458
+ flavor.promptFailure?.(
4459
+ new EffectAcpErrors.AcpRequestError({
4460
+ code: error?.code ?? -32603,
4461
+ errorMessage: error?.message ?? "Provider turn failed.",
4462
+ ...(error?.data === undefined ? {} : { data: error.data }),
4463
+ }),
4464
+ ) ??
4465
+ makeProviderFailure({
4466
+ message: error?.message,
4467
+ code: error == null ? null : String(error.code),
4468
+ class: "provider_error",
4469
+ });
4470
+
4471
const settleIdleWork = Effect.fnUntraced(function* (
4472
context: ActiveAcpTurn,
4473
): Effect.fn.Return<void> {
@@ -4459,16 +4484,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
4484
if (work.stopReason === "cancelled" && pendingStopCloseTurn === context) {
4485
context.interrupted = true;
4486
}
4462
- const failure =
4463
- work.stopReason === "error"
4464
- ? (flavor.promptFailure?.(
4465
- new EffectAcpErrors.AcpRequestError({
4466
- code: work.error?.code ?? -32603,
4467
- errorMessage: work.error?.message ?? "Provider turn failed.",
4468
- ...(work.error?.data === undefined ? {} : { data: work.error.data }),
4469
- }),
4470
- ) ?? makeProviderFailure({ message: work.error?.message, class: "provider_error" }))
4471
- : undefined;
4487
+ const failure = work.stopReason === "error" ? idleErrorFailure(work.error) : undefined;
4488
yield* finalizeTurn(
4489
context,
4490
failure !== undefined
@@ -4684,7 +4700,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
4700
const rootTerminalCanStillProject =
4701
carryover !== null &&
4702
carryover.sessionId === (yield* Ref.get(activeSessionId)) &&
4687
- carryover.rootTerminalStatus === "completed";
4703
+ carryover.projectsLateTerminals;
4704
const projectCarryover = rootTerminalCanStillProject;
4705
let carryoverTerminalized = false;
4706
if (
@@ -5677,7 +5693,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
5693
project:
5694
carryover !== null &&
5695
carryover.sessionId === (yield* Ref.get(activeSessionId)) &&
5680
- carryover.rootTerminalStatus === "completed",
5696
+ carryover.projectsLateTerminals,
5697
},
5698
);
5699
});
@@ -6932,11 +6948,12 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
6948
6949
const terminalizeOpenForegroundTools = Effect.fnUntraced(function* (
6950
context: ActiveAcpTurn,
6951
+ status: "completed" | "failed" = "completed",
6952
) {
6953
for (const tool of context.tools.values()) {
6954
if (!acpCompletedTurnShouldTerminalizeTool(tool, { ...flavor, extractSubagentUpdate }))
6955
continue;
6939
- yield* emitTool(context, tool, "completed");
6956
+ yield* emitTool(context, tool, status);
6957
}
6958
});
6959
@@ -6960,6 +6977,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
6977
context: ActiveAcpTurn,
6978
status: "completed" | "interrupted" | "failed" | "cancelled",
6979
failure?: OrchestrationV2ProviderFailure,
6980
+ options?: { readonly childTurnsContinue?: boolean },
6981
): Effect.fn.Return<void> {
6982
if (context.finalized) return;
6983
const settledStatus = context.interrupted ? "interrupted" : status;
@@ -7059,6 +7077,12 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
7077
providerThread: updatedProviderThread,
7078
});
7079
const rootSessionId = yield* Ref.get(activeSessionId);
7080
+ const childTurnsContinue =
7081
+ settledStatus === "failed" &&
7082
+ (options?.childTurnsContinue === true ||
7083
+ (followsAgentWorkState &&
7084
+ rootSessionId !== null &&
7085
+ hasWorkingDescendant(rootSessionId)));
7086
yield* emitProviderEvent(
7087
settledStatus === "failed"
7088
? {
@@ -7072,11 +7096,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
7096
`terminal-failure:${context.providerTurnId}`,
7097
),
7098
status: settledStatus,
7075
- ...(followsAgentWorkState &&
7076
- rootSessionId !== null &&
7077
- hasWorkingDescendant(rootSessionId)
7078
- ? { childTurnsContinue: true }
7079
- : {}),
7099
+ ...(childTurnsContinue ? { childTurnsContinue: true } : {}),
7100
failure: failure ?? makeProviderFailure({ class: "provider_error" }),
7101
...(context.providerRetry === undefined
7102
? {}
@@ -7105,7 +7125,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
7125
if (sessionId !== null) {
7126
yield* Ref.set(carryoverSubagents, {
7127
sessionId,
7108
- rootTerminalStatus: settledStatus,
7128
+ projectsLateTerminals: settledStatus === "completed" || childTurnsContinue,
7129
subagents: subagentsRequiringCarryover,
7130
});
7131
}
@@ -7590,8 +7610,11 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
7610
promptGeneration,
7611
Effect.gen(function* () {
7612
if (context.finalized || followsAgentWorkState) return;
7593
- const status =
7594
- result.stopReason === "cancelled"
7613
+ // ACP v2 reports a failed prompt as an idle `error`, not an RPC error.
7614
+ const idleError = result.stopReason === "error" && !context.interrupted;
7615
+ const status = idleError
7616
+ ? "failed"
7617
+ : result.stopReason === "cancelled"
7618
? context.interrupted
7619
? "interrupted"
7620
: "cancelled"
@@ -7604,6 +7627,15 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
7627
yield* finishRegisteredBackgroundTool({ taskId, ...completion });
7628
}
7629
}
7630
+ if (idleError) {
7631
+ yield* terminalizeOpenForegroundTools(context, "failed");
7632
+ // Unlike an RPC failure, the agent survives an idle error, so its
7633
+ // background tools and subagents keep reporting to this run.
7634
+ yield* finalizeTurn(context, "failed", idleErrorFailure(result.error), {
7635
+ childTurnsContinue: hasSurvivingBackgroundWork(context),
7636
+ });
7637
+ return;
7638
+ }
7639
if (
7640
flavor.deferFinalizeForBackgroundWork === true &&
7641
!context.interrupted &&