@@ -350,7 +350,33 @@ it.layer(layerClaudeTextGenerationTest)("ClaudeTextGeneration", (it) => {
350350
351351 const apiError = "API Error: 400 Model blocked by guardrail: 4 endpoints excluded" ;
352352 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+ } ;
353360 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+ ] ,
354380 [
355381 "the stdout error over a stderr notice" ,
356382 JSON . stringify ( { is_error : true , api_error_status : 400 , result : apiError } ) ,
@@ -392,4 +418,25 @@ it.layer(layerClaudeTextGenerationTest)("ClaudeTextGeneration", (it) => {
392418 } ) ,
393419 ) ,
394420 ) ;
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+ ) ;
395442} ) ;
0 commit comments