@@ -57,6 +57,7 @@ function makeFakeClaudeBinary(dir: string, lifecyclePort?: number) {
5757function withFakeClaudeEnv < A , E , R > (
5858 input : {
5959 output : string ;
60+ rejectsNoSessionPersistence ?: boolean ;
6061 lifecyclePort ?: number ;
6162 exitCode ?: number ;
6263 stderr ?: string ;
@@ -75,6 +76,8 @@ function withFakeClaudeEnv<A, E, R>(
7576 const binDir = yield * makeFakeClaudeBinary ( tempDir , input . lifecyclePort ) ;
7677 const pathDelimiter = ( yield * HostProcess . isWindows ) ? ";" : ":" ;
7778 const previousPath = process . env . PATH ;
79+ const previousRejectsNoSessionPersistence =
80+ process . env . T3_FAKE_CLAUDE_REJECTS_NO_SESSION_PERSISTENCE ;
7881 const previousOutput = process . env . T3_FAKE_CLAUDE_OUTPUT ;
7982 const previousExitCode = process . env . T3_FAKE_CLAUDE_EXIT_CODE ;
8083 const previousStderr = process . env . T3_FAKE_CLAUDE_STDERR ;
@@ -89,6 +92,12 @@ function withFakeClaudeEnv<A, E, R>(
8992 process . env . PATH = `${ binDir } ${ pathDelimiter } ${ previousPath ?? "" } ` ;
9093 process . env . T3_FAKE_CLAUDE_OUTPUT = input . output ;
9194
95+ if ( input . rejectsNoSessionPersistence ) {
96+ process . env . T3_FAKE_CLAUDE_REJECTS_NO_SESSION_PERSISTENCE = "1" ;
97+ } else {
98+ delete process . env . T3_FAKE_CLAUDE_REJECTS_NO_SESSION_PERSISTENCE ;
99+ }
100+
92101 if ( input . exitCode !== undefined ) {
93102 process . env . T3_FAKE_CLAUDE_EXIT_CODE = String ( input . exitCode ) ;
94103 } else {
@@ -135,6 +144,13 @@ function withFakeClaudeEnv<A, E, R>(
135144 Effect . sync ( ( ) => {
136145 process . env . PATH = previousPath ;
137146
147+ if ( previousRejectsNoSessionPersistence === undefined ) {
148+ delete process . env . T3_FAKE_CLAUDE_REJECTS_NO_SESSION_PERSISTENCE ;
149+ } else {
150+ process . env . T3_FAKE_CLAUDE_REJECTS_NO_SESSION_PERSISTENCE =
151+ previousRejectsNoSessionPersistence ;
152+ }
153+
138154 if ( previousOutput === undefined ) {
139155 delete process . env . T3_FAKE_CLAUDE_OUTPUT ;
140156 } else {
@@ -320,6 +336,28 @@ it.layer(layerClaudeTextGenerationTest)("ClaudeTextGeneration", (it) => {
320336 } ) ,
321337 ) ;
322338
339+ it . effect ( "retries without --no-session-persistence when the Claude CLI rejects it" , ( ) =>
340+ withFakeClaudeEnv (
341+ {
342+ output : JSON . stringify ( { structured_output : { title : "Reconnect failures" } } ) ,
343+ rejectsNoSessionPersistence : true ,
344+ } ,
345+ ( textGeneration ) =>
346+ Effect . gen ( function * ( ) {
347+ const generated = yield * textGeneration . generateThreadTitle ( {
348+ cwd : process . cwd ( ) ,
349+ message : "Investigate reconnect failures" ,
350+ modelSelection : {
351+ instanceId : ProviderInstanceId . make ( "claudeAgent" ) ,
352+ model : SYNTHETIC_CLAUDE_STANDARD_MODEL ,
353+ } ,
354+ } ) ;
355+
356+ expect ( generated . title ) . toBe ( "Reconnect failures" ) ;
357+ } ) ,
358+ ) ,
359+ ) ;
360+
323361 it . effect . each ( [
324362 { verbose : false , label : "normal" } ,
325363 { verbose : true , label : "verbose" } ,
@@ -430,6 +468,14 @@ it.layer(layerClaudeTextGenerationTest)("ClaudeTextGeneration", (it) => {
430468 apiError ,
431469 ] ,
432470 [ "stderr when stdout has no error" , "not json" , wrapperNotice ] ,
471+ [
472+ "a stdout error naming --no-session-persistence without retrying" ,
473+ JSON . stringify ( {
474+ is_error : true ,
475+ result : "error: unknown option '--no-session-persistence'" ,
476+ } ) ,
477+ "error: unknown option '--no-session-persistence'" ,
478+ ] ,
433479 ] as const ) ( "reports %s when the Claude CLI fails" , ( [ , output , expected ] ) =>
434480 withFakeClaudeEnv ( { output, stderr : wrapperNotice , exitCode : 1 } , ( textGeneration ) =>
435481 Effect . gen ( function * ( ) {
0 commit comments