@devries-cameron20 / t3code-1 / commits / 56d893e764
Fork 0

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

fix(server): failed Claude text generation shows Claude's error instead of raw JSON (#30331)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

MarcoDotIO committed Nov 5, 2026 at 23:28 UTC 56d893e764895998a2ceb7ff4bc34ecbfc6f6095
2 files changed +62 -2
apps/server/src/textGeneration/ClaudeTextGeneration.test.ts
+47
@@ -350,7 +350,33 @@ it.layer(layerClaudeTextGenerationTest)("ClaudeTextGeneration", (it) => {
350
351 const apiError = "API Error: 400 Model blocked by guardrail: 4 endpoints excluded";
352 const wrapperNotice = "Using the OpenRouter credential from the global credential file.";
353 + const structuredOutputError = "Failed to provide valid structured output after 5 attempts";
354 + const structuredOutputFailure = {
355 + type: "result",
356 + subtype: "error_max_structured_output_retries",
357 + is_error: true,
358 + errors: [structuredOutputError],
359 + };
360 it.effect.each([
361 + [
362 + "the errors list of a result with no result text",
363 + JSON.stringify(structuredOutputFailure),
364 + structuredOutputError,
365 + ],
366 + [
367 + "the errors list from verbose output",
368 + JSON.stringify([{ type: "system", subtype: "init" }, structuredOutputFailure]),
369 + structuredOutputError,
370 + ],
371 + [
372 + "the errors list without CLI telemetry",
373 + JSON.stringify({
374 + ...structuredOutputFailure,
375 + subtype: "error_during_execution",
376 + errors: ["[ede_diagnostic] result_type=user last_content_type=n/a", apiError],
377 + }),
378 + apiError,
379 + ],
380 [
381 "the stdout error over a stderr notice",
382 JSON.stringify({ is_error: true, api_error_status: 400, result: apiError }),
@@ -392,4 +418,25 @@ it.layer(layerClaudeTextGenerationTest)("ClaudeTextGeneration", (it) => {
418 }),
419 ),
420 );
421 +
422 + it.effect("does not report the raw result JSON when a failed run writes nothing to stderr", () =>
423 + withFakeClaudeEnv(
424 + { output: JSON.stringify(structuredOutputFailure), exitCode: 1 },
425 + (textGeneration) =>
426 + Effect.gen(function* () {
427 + const error = yield* Effect.flip(
428 + textGeneration.generateThreadTitle({
429 + cwd: process.cwd(),
430 + message: "Name this thread",
431 + modelSelection: {
432 + instanceId: ProviderInstanceId.make("claudeAgent"),
433 + model: SYNTHETIC_CLAUDE_STANDARD_MODEL,
434 + },
435 + }),
436 + );
437 +
438 + expect(error.detail).toBe(`Claude CLI command failed: ${structuredOutputError}`);
439 + }),
440 + ),
441 + );
442 });
apps/server/src/textGeneration/ClaudeTextGeneration.ts
+15 -2
@@ -66,7 +66,13 @@ const decodeClaudeOutput = Schema.decodeEffect(
66 Schema.fromJsonString(Schema.Union([ClaudeOutputEnvelope, Schema.Array(ClaudeOutputMessage)])),
67 );
68
69 -const ClaudeErrorResult = Schema.Struct({ is_error: Schema.Literal(true), result: Schema.String });
69 +// Only `success` results carry `result`; error subtypes such as
70 +// error_max_structured_output_retries report through `errors` instead.
71 +const ClaudeErrorResult = Schema.Struct({
72 + is_error: Schema.Literal(true),
73 + result: Schema.optionalKey(Schema.String),
74 + errors: Schema.optionalKey(Schema.Array(Schema.String)),
75 +});
76 const isClaudeErrorResult = Schema.is(ClaudeErrorResult);
77 const decodeJsonOption = Schema.decodeUnknownOption(Schema.fromJsonString(Schema.Unknown));
78
@@ -76,7 +82,14 @@ function claudeErrorResult(stdout: string): string | undefined {
82 const messages: ReadonlyArray<unknown> = Array.isArray(output) ? output : [output];
83 return messages
84 .filter(isClaudeErrorResult)
79 - .map((message) => message.result.trim())
85 + .map((message) =>
86 + (
87 + message.result ??
88 + // error_during_execution mixes CLI telemetry into the list.
89 + message.errors?.filter((error) => !error.startsWith("[ede_diagnostic]")).join("\n") ??
90 + ""
91 + ).trim(),
92 + )
93 .findLast((result) => result.length > 0);
94 }
95