@devries-cameron20 / t3code-1 / commits / 300a35670a
Fork 0

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

fix(server): provider failures say why a turn could not start (#16303)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Co-authored-by: SAPHID <saphid@users.noreply.github.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>

Alex Southwell committed Oct 20, 2026 at 05:27 UTC 300a35670abc0f73662e17c9ce909bcc106be70f
12 files changed +168 -51
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts
+14 -14
@@ -8509,12 +8509,10 @@ describe("ClaudeAdapterV2 background wake turns", () => {
8509 );
8510
8511 yield* userTurn("attempt-failed-start-1", 1);
8512 - yield* Queue.offer(harness.sdkMessages, wakeTaskStarted);
8513 - yield* Queue.offer(harness.sdkMessages, turnOneResult);
8514 - yield* awaitUntil(() => harness.terminalEvents().length === 1, "first turn terminal");
8515 - yield* Queue.offer(harness.sdkMessages, wakeNotification);
8516 - let notificationYields = 0;
8517 - yield* awaitUntil(() => notificationYields++ >= 50, "notification to be recorded");
8512 + yield* harness.offerAndWait(wakeTaskStarted);
8513 + yield* harness.offerAndWait(turnOneResult);
8514 + yield* Queue.take(harness.terminalReceipts);
8515 + yield* harness.offerAndWait(wakeNotification);
8516 assert.isFalse(yield* harness.hasPendingBackgroundWork);
8517
8518 const missing = ChatImageAttachment.make({
@@ -8524,20 +8522,22 @@ describe("ClaudeAdapterV2 background wake turns", () => {
8522 mimeType: "image/png",
8523 sizeBytes: 4,
8524 });
8527 - const failed = yield* Effect.exit(userTurn("attempt-failed-start-2", 2, [missing]));
8528 - assert.isTrue(Exit.isFailure(failed));
8525 + const failed = yield* userTurn("attempt-failed-start-2", 2, [missing]).pipe(Effect.flip);
8526 + assert.equal(
8527 + makeProviderFailure({ cause: failed }).message,
8528 + "The provider could not start this turn: an attachment could not be read. Retry the turn; if it keeps failing, check the provider setup and server logs.",
8529 + );
8530
8531 yield* userTurn("attempt-failed-start-3", 2);
8531 - yield* Queue.offer(
8532 - harness.sdkMessages,
8532 + yield* harness.offerAndWait(
8533 makeResultFrame({ uuid: "00000000-0000-4000-8000-000000000911", result: "Answered." }),
8534 );
8535 - yield* awaitUntil(() => harness.terminalEvents().length === 2, "second turn terminal");
8535 + yield* Queue.take(harness.terminalReceipts);
8536
8537 - yield* Queue.offer(harness.sdkMessages, wakeAssistant);
8538 - yield* awaitUntil(() => harness.continuationRequests.length === 1, "command wake");
8537 + yield* harness.offerAndWait(wakeAssistant);
8538 + const continuation = yield* Queue.take(harness.continuationReceipts);
8539 assert.equal(
8540 - harness.continuationRequests[0]?.notification?.summary,
8540 + continuation.notification?.summary,
8541 `Command "${WAKE_TASK_DESCRIPTION}" finished`,
8542 );
8543 }).pipe(
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
+2
@@ -1685,6 +1685,7 @@ const makeClaudeUserMessageWithAttachments = Effect.fnUntraced(function* (input:
1685 new ProviderAdapter.ProviderAdapterProtocolError({
1686 driver: CLAUDE_PROVIDER,
1687 detail: `Failed to read attachment '${attachment.id}'`,
1688 + reason: "attachment_unreadable",
1689 payload: cause,
1690 }),
1691 ),
@@ -8760,6 +8761,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
8761 return yield* new ProviderAdapter.ProviderAdapterProtocolError({
8762 driver: CLAUDE_PROVIDER,
8763 detail: `Claude provider turn ${currentTurn.providerTurnId} is still active.`,
8764 + reason: "previous_turn_active",
8765 });
8766 }
8767 yield* Ref.update(lastTurnRouteByNativeThread, (current) => {
apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts
+11 -7
@@ -3126,13 +3126,17 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
3126 if (attachmentPath === null) {
3127 return yield* toProtocolError(`Invalid attachment id '${attachment.id}'`);
3128 }
3129 - const bytes = yield* fileSystem
3130 - .readFile(attachmentPath)
3131 - .pipe(
3132 - Effect.mapError((cause) =>
3133 - toProtocolError(`Failed to read attachment '${attachment.id}'.`, cause),
3134 - ),
3135 - );
3129 + const bytes = yield* fileSystem.readFile(attachmentPath).pipe(
3130 + Effect.mapError(
3131 + (cause) =>
3132 + new ProviderAdapter.ProviderAdapterProtocolError({
3133 + driver: CODEX_PROVIDER,
3134 + detail: `Failed to read attachment '${attachment.id}'.`,
3135 + reason: "attachment_unreadable",
3136 + payload: cause,
3137 + }),
3138 + ),
3139 + );
3140 return {
3141 type: "image" as const,
3142 url: `data:${attachment.mimeType};base64,${Buffer.from(bytes).toString("base64")}`,
packages/provider-acp/src/server/adapter.ts
+2
@@ -6354,6 +6354,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
6354 new ProviderAdapter.ProviderAdapterProtocolError({
6355 driver,
6356 detail: `Failed to read attachment '${attachment.id}'`,
6357 + reason: "attachment_unreadable",
6358 payload: cause,
6359 }),
6360 ),
@@ -6411,6 +6412,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
6412 return yield* new ProviderAdapter.ProviderAdapterProtocolError({
6413 driver,
6414 detail: `ACP provider turn ${existing.providerTurnId} is still active`,
6415 + reason: "previous_turn_active",
6416 });
6417 }
6418 useProviderThreadIdentity(turnInput.providerThread);
packages/provider-core/src/server/ProviderAdapter.ts
+8
@@ -360,11 +360,19 @@ export class ProviderAdapterEventStreamError extends Schema.TaggedError<Provider
360 }
361 }
362
363 +// Only fixed reasons reach failure messages; detail can contain private configuration.
364 +const ProviderAdapterFailureReason = Schema.Literals([
365 + "previous_turn_active",
366 + "attachment_unreadable",
367 +]);
368 +export type ProviderAdapterFailureReason = typeof ProviderAdapterFailureReason.Type;
369 +
370 export class ProviderAdapterProtocolError extends Schema.TaggedError<ProviderAdapterProtocolError>()(
371 "ProviderAdapterProtocolError",
372 {
373 driver: ProviderDriverKind,
374 detail: Schema.String,
375 + reason: Schema.optional(ProviderAdapterFailureReason),
376 cause: Schema.optional(Schema.Defect()),
377 payload: Schema.optional(Schema.Unknown),
378 },
packages/provider-core/src/server/failure.test.ts
+59
@@ -101,6 +101,65 @@ it("preserves actionable handoff errors wrapped by turn startup", () => {
101 );
102 });
103
104 +it.each([
105 + ["previous_turn_active", "the previous turn is still running"],
106 + ["attachment_unreadable", "an attachment could not be read"],
107 +] as const)("names %s without exposing provider detail or losing guidance", (reason, wording) => {
108 + const failure = makeProviderFailure({
109 + cause: Cause.fail({
110 + _tag: "ProviderAdapterTurnStartError",
111 + cause: Cause.fail(
112 + new ProviderAdapter.ProviderAdapterProtocolError({
113 + driver: ProviderDriverKind.make("claudeAgent"),
114 + detail: `Private configuration: ${"x".repeat(5000)}`,
115 + reason,
116 + }),
117 + ),
118 + }),
119 + });
120 + assert.equal(
121 + failure.message,
122 + `The provider could not start this turn: ${wording}. Retry the turn; if it keeps failing, check the provider setup and server logs.`,
123 + );
124 +});
125 +
126 +it("keeps unrecognized reasons and provider text out of category messages", () => {
127 + for (const cause of [
128 + "Private launch command",
129 + { _tag: "ProviderAdapterProtocolError", detail: "Pi model 'private-config' is invalid" },
130 + { _tag: "ProviderAdapterProtocolError", reason: "private-config" },
131 + { _tag: "ProviderAdapterProtocolError", reason: "constructor" },
132 + { _tag: "constructor", cause: "private-config" },
133 + ]) {
134 + assert.equal(
135 + makeProviderFailure({ cause: { _tag: "ProviderAdapterTurnStartError", cause } }).message,
136 + "The provider could not start this turn. Retry the turn; if it keeps failing, check the provider setup and server logs.",
137 + );
138 + }
139 + assert.equal(
140 + makeProviderFailure({
141 + cause: { _tag: "ProviderAdapterProtocolError", reason: "previous_turn_active" },
142 + }).message,
143 + "Provider turn failed.",
144 + );
145 +});
146 +
147 +it("uses the innermost category without carrying an outer reason into it", () => {
148 + assert.equal(
149 + makeProviderFailure({
150 + cause: {
151 + _tag: "ProviderAdapterTurnStartError",
152 + cause: {
153 + _tag: "ProviderAdapterProtocolError",
154 + reason: "previous_turn_active",
155 + cause: Cause.fail({ _tag: "ProviderAdapterOpenSessionError" }),
156 + },
157 + },
158 + }).message,
159 + "The provider session could not be opened. Check that the provider is installed and signed in, then retry the turn.",
160 + );
161 +});
162 +
163 it("does not expose defect text nested inside a known error category", () => {
164 const failure = makeProviderFailure({
165 cause: {
packages/provider-core/src/server/failure.ts
+49 -18
@@ -14,6 +14,7 @@ import * as DateTime from "effect/DateTime";
14 import * as Cause from "effect/Cause";
15
16 import * as IdAllocator from "./IdAllocator.ts";
17 +import type { ProviderAdapterFailureReason } from "./ProviderAdapter.ts";
18 import * as Schema from "effect/Schema";
19
20 export class ContextHandoffBudgetError extends Schema.TaggedError<ContextHandoffBudgetError>()(
@@ -30,9 +31,36 @@ export const MAX_PROVIDER_FAILURE_CODE_LENGTH = 128;
31
32 const DEFAULT_PROVIDER_FAILURE_MESSAGE = "Provider turn failed.";
33
34 +const PROVIDER_FAILURE_CATEGORIES: Partial<
35 + Record<string, { readonly summary: string; readonly guidance: string }>
36 +> = {
37 + ProviderAdapterTurnStartError: {
38 + summary: "The provider could not start this turn",
39 + guidance: "Retry the turn; if it keeps failing, check the provider setup and server logs.",
40 + },
41 + ProviderAdapterEventStreamError: {
42 + summary: "The provider event stream closed unexpectedly",
43 + guidance: "Retry the turn; if it keeps failing, check the provider and server logs.",
44 + },
45 + ProviderAdapterOpenSessionError: {
46 + summary: "The provider session could not be opened",
47 + guidance: "Check that the provider is installed and signed in, then retry the turn.",
48 + },
49 + ProviderAdapterResumeThreadError: {
50 + summary: "The provider conversation could not be resumed",
51 + guidance: "Retry the turn; if it keeps failing, check the provider and server logs.",
52 + },
53 +};
54 +
55 +const PROVIDER_FAILURE_REASONS: Record<ProviderAdapterFailureReason, string> = {
56 + previous_turn_active: "the previous turn is still running",
57 + attachment_unreadable: "an attachment could not be read",
58 +};
59 +
60 function causeMessage(cause: unknown): string | undefined {
61 const seen = new Set<unknown>();
35 - let message: string | undefined;
62 + let category: (typeof PROVIDER_FAILURE_CATEGORIES)[string];
63 + let reason: string | undefined;
64 for (let depth = 0; depth < 16 && cause != null && !seen.has(cause); depth++) {
65 seen.add(cause);
66 try {
@@ -41,7 +69,8 @@ function causeMessage(cause: unknown): string | undefined {
69 continue;
70 }
71 if (typeof cause !== "object") break;
44 - switch ((cause as Record<string, unknown>)._tag) {
72 + const tag = (cause as Record<string, unknown>)._tag;
73 + switch (tag) {
74 case "ContextHandoffBudgetError":
75 return new ContextHandoffBudgetError().message;
76 case "ClaudeBackgroundWorkBlocksQueryReplacementError":
@@ -49,29 +78,31 @@ function causeMessage(cause: unknown): string | undefined {
78 return stringField(cause, "message");
79 case "ContextHandoffDeliveryUncertainError":
80 return "T3 could not confirm whether conversation history reached the provider. Retry the turn to recover the session.";
52 - case "ProviderAdapterTurnStartError":
53 - message =
54 - "The provider could not start this turn. Retry the turn; if it keeps failing, check the provider setup and server logs.";
55 - break;
56 - case "ProviderAdapterEventStreamError":
57 - message =
58 - "The provider event stream closed unexpectedly. Retry the turn; if it keeps failing, check the provider and server logs.";
59 - break;
60 - case "ProviderAdapterOpenSessionError":
61 - message =
62 - "The provider session could not be opened. Check that the provider is installed and signed in, then retry the turn.";
63 - break;
64 - case "ProviderAdapterResumeThreadError":
65 - message =
66 - "The provider conversation could not be resumed. Retry the turn; if it keeps failing, check the provider and server logs.";
81 + case "ProviderAdapterProtocolError": {
82 + const typedReason = (cause as Record<string, unknown>).reason;
83 + if (
84 + category !== undefined &&
85 + typeof typedReason === "string" &&
86 + Object.hasOwn(PROVIDER_FAILURE_REASONS, typedReason)
87 + ) {
88 + reason ??= PROVIDER_FAILURE_REASONS[typedReason as ProviderAdapterFailureReason];
89 + }
90 break;
91 + }
92 + }
93 + if (typeof tag === "string" && Object.hasOwn(PROVIDER_FAILURE_CATEGORIES, tag)) {
94 + category = PROVIDER_FAILURE_CATEGORIES[tag];
95 + reason = undefined;
96 }
97 cause = (cause as Record<string, unknown>).cause;
98 } catch {
99 break;
100 }
101 }
74 - return message;
102 + if (category === undefined) return undefined;
103 + return reason
104 + ? `${category.summary}: ${reason}. ${category.guidance}`
105 + : `${category.summary}. ${category.guidance}`;
106 }
107
108 function stringField(value: unknown, key: "message" | "code"): string | undefined {
packages/provider-cursor/src/server/adapter.ts
+2
@@ -2199,6 +2199,7 @@ export const makeCursorAdapterV2 = Effect.fn("makeCursorAdapterV2")(function* (
2199 new ProviderAdapter.ProviderAdapterProtocolError({
2200 driver: CursorAgentSdk.CURSOR_PROVIDER,
2201 detail: `Failed to read attachment '${attachment.id}'.`,
2202 + reason: "attachment_unreadable",
2203 payload: cause,
2204 }),
2205 ),
@@ -2232,6 +2233,7 @@ export const makeCursorAdapterV2 = Effect.fn("makeCursorAdapterV2")(function* (
2233 return yield* new ProviderAdapter.ProviderAdapterProtocolError({
2234 driver: CursorAgentSdk.CURSOR_PROVIDER,
2235 detail: `Cursor provider turn ${current.providerTurnId} is still active.`,
2236 + reason: "previous_turn_active",
2237 });
2238 }
2239 const agentId = nativeThreadId(turnInput.providerThread);
packages/provider-muse/src/server/adapter.ts
+5 -3
@@ -1904,9 +1904,11 @@ export const makeMuseAdapterV2 = Effect.fn("makeMuseAdapterV2")(function* (
1904 if (!validateThread(turnInput.providerThread) || broken || closed)
1905 return yield* protocolError("Muse thread is not attached to this host");
1906 if (active)
1907 - return yield* protocolError(
1908 - "Muse already has an active turn; queue through the orchestrator",
1909 - );
1907 + return yield* new ProviderAdapter.ProviderAdapterProtocolError({
1908 + driver: MUSE_PROVIDER,
1909 + detail: "Muse already has an active turn; queue through the orchestrator",
1910 + reason: "previous_turn_active",
1911 + });
1912 if (turnInput.runtimePolicy.interactionMode === "plan")
1913 return yield* protocolError("Muse does not support dedicated Plan mode");
1914 if (turnInput.runtimePolicy.runtimeMode !== input.runtimePolicy.runtimeMode)
packages/provider-opencode/src/server/adapter.ts
+10 -6
@@ -3094,9 +3094,11 @@ export const makeOpenCodeAdapterV2 = Effect.fn("makeOpenCodeAdapterV2")(function
3094 return yield* protocolError(`OpenCode session ${sessionId} is not registered`);
3095 }
3096 if (state.activeTurn !== null) {
3097 - return yield* protocolError(
3098 - `OpenCode provider thread ${turnInput.providerThread.id} already has an active turn`,
3099 - );
3097 + return yield* new ProviderAdapter.ProviderAdapterProtocolError({
3098 + driver: OPENCODE_PROVIDER,
3099 + detail: `OpenCode provider thread ${turnInput.providerThread.id} already has an active turn`,
3100 + reason: "previous_turn_active",
3101 + });
3102 }
3103 const parsedModel = OpenCodeRuntime.parseOpenCodeModelSlug(
3104 turnInput.modelSelection.model,
@@ -3138,9 +3140,11 @@ export const makeOpenCodeAdapterV2 = Effect.fn("makeOpenCodeAdapterV2")(function
3140 );
3141 }
3142 if (state.activeTurn !== null) {
3141 - return yield* protocolError(
3142 - `OpenCode provider thread ${turnInput.providerThread.id} already has an active turn`,
3143 - );
3143 + return yield* new ProviderAdapter.ProviderAdapterProtocolError({
3144 + driver: OPENCODE_PROVIDER,
3145 + detail: `OpenCode provider thread ${turnInput.providerThread.id} already has an active turn`,
3146 + reason: "previous_turn_active",
3147 + });
3148 }
3149 const turn: ActiveOpenCodeTurn = {
3150 isRoot: true,
packages/provider-opencode/src/server/v2/adapter.ts
+1
@@ -3441,6 +3441,7 @@ export const make = Effect.fn("OpenCode2Adapter.make")(function* (instanceId: Pr
3441 return yield* new ProviderAdapter.ProviderAdapterProtocolError({
3442 driver: OPENCODE_PROVIDER,
3443 detail: `OpenCode session ${sessionId} already has an active turn`,
3444 + reason: "previous_turn_active",
3445 });
3446 }
3447 if (isContinuation(turnInput)) return yield* runWake(state, turnInput);
packages/provider-pi/src/server/adapter.ts
+5 -3
@@ -2418,9 +2418,11 @@ export const makePiAdapterV2 = Effect.fn("makePiAdapterV2")(function* (
2418 return yield* protocolError("Pi session has no registered thread");
2419 }
2420 if (state.activeTurn !== null) {
2421 - return yield* protocolError(
2422 - `Pi provider thread ${turnInput.providerThread.id} already has an active turn`,
2423 - );
2421 + return yield* new ProviderAdapter.ProviderAdapterProtocolError({
2422 + driver: PI_PROVIDER,
2423 + detail: `Pi provider thread ${turnInput.providerThread.id} already has an active turn`,
2424 + reason: "previous_turn_active",
2425 + });
2426 }
2427 if (
2428 state.providerThread.nativeThreadRef?.nativeId !==