@@ -173,9 +173,11 @@ public async Task Should_Apply_All_ReasoningEffort_Values_On_Session_Create(stri
173173 [ Trait ( E2ETestTraits . Backend , E2ETestTraits . SelfConfiguredBackend ) ]
174174 public async Task Should_Apply_ReasoningEffort_On_Session_Resume ( )
175175 {
176- var originalSession = await CreateSessionAsync ( ) ;
176+ await using var originalSession = await CreateSessionAsync ( ) ;
177+ var sessionId = originalSession . SessionId ;
178+ await SuspendAndUntrackSessionForResumeAsync ( originalSession ) ;
177179 const string reasoningModelId = "custom-reasoning-model" ;
178- var resumedSession = await ResumeSessionAsync ( originalSession . SessionId , new ResumeSessionConfig
180+ var resumedSession = await ResumeSessionAsync ( sessionId , new ResumeSessionConfig
179181 {
180182 Model = reasoningModelId ,
181183 Provider = CreateProxyProvider ( "resume-reasoning" ) ,
@@ -187,7 +189,6 @@ public async Task Should_Apply_ReasoningEffort_On_Session_Resume()
187189 Assert . Equal ( "high" , resumeEvent . Data . ReasoningEffort ) ;
188190
189191 await resumedSession . DisposeAsync ( ) ;
190- await originalSession . DisposeAsync ( ) ;
191192 }
192193
193194 [ Fact ]
@@ -233,8 +234,9 @@ public async Task Should_Forward_Custom_Provider_Headers_On_Create()
233234 [ Trait ( E2ETestTraits . Backend , E2ETestTraits . SelfConfiguredBackend ) ]
234235 public async Task Should_Forward_Custom_Provider_Headers_On_Resume ( )
235236 {
236- var session1 = await CreateSessionAsync ( ) ;
237+ await using var session1 = await CreateSessionAsync ( ) ;
237238 var sessionId = session1 . SessionId ;
239+ await SuspendAndUntrackSessionForResumeAsync ( session1 ) ;
238240
239241 var session2 = await ResumeSessionAsync ( sessionId , new ResumeSessionConfig
240242 {
@@ -339,8 +341,9 @@ public async Task Should_Apply_WorkingDirectory_On_Session_Resume()
339341 Directory . CreateDirectory ( subDir ) ;
340342 await File . WriteAllTextAsync ( Path . Join ( subDir , "resume-marker.txt" ) , "I am in the resume working directory" ) ;
341343
342- var session1 = await CreateSessionAsync ( ) ;
344+ await using var session1 = await CreateSessionAsync ( ) ;
343345 var sessionId = session1 . SessionId ;
346+ await SuspendAndUntrackSessionForResumeAsync ( session1 ) ;
344347
345348 var session2 = await ResumeSessionAsync ( sessionId , new ResumeSessionConfig
346349 {
@@ -360,8 +363,9 @@ public async Task Should_Apply_WorkingDirectory_On_Session_Resume()
360363 [ Fact ]
361364 public async Task Should_Apply_SystemMessage_On_Session_Resume ( )
362365 {
363- var session1 = await CreateSessionAsync ( ) ;
366+ await using var session1 = await CreateSessionAsync ( ) ;
364367 var sessionId = session1 . SessionId ;
368+ await SuspendAndUntrackSessionForResumeAsync ( session1 ) ;
365369
366370 var resumeInstruction = "End the response with RESUME_SYSTEM_MESSAGE_SENTINEL." ;
367371 var session2 = await ResumeSessionAsync ( sessionId , new ResumeSessionConfig
@@ -422,11 +426,13 @@ await File.WriteAllTextAsync(
422426 Path . Join ( instructionFilesDir , "extra.instructions.md" ) ,
423427 $ "Always include { sentinel } .") ;
424428
425- var session1 = await CreateSessionAsync ( new SessionConfig
429+ await using var session1 = await CreateSessionAsync ( new SessionConfig
426430 {
427431 WorkingDirectory = projectDir ,
428432 } ) ;
429- var session2 = await ResumeSessionAsync ( session1 . SessionId , new ResumeSessionConfig
433+ var sessionId = session1 . SessionId ;
434+ await SuspendAndUntrackSessionForResumeAsync ( session1 ) ;
435+ var session2 = await ResumeSessionAsync ( sessionId , new ResumeSessionConfig
430436 {
431437 WorkingDirectory = projectDir ,
432438 InstructionDirectories = [ instructionDir ] ,
@@ -438,14 +444,14 @@ await File.WriteAllTextAsync(
438444 Assert . Contains ( sentinel , GetSystemMessage ( exchange ) ) ;
439445
440446 await session2 . DisposeAsync ( ) ;
441- await session1 . DisposeAsync ( ) ;
442447 }
443448
444449 [ Fact ]
445450 public async Task Should_Apply_AvailableTools_On_Session_Resume ( )
446451 {
447- var session1 = await CreateSessionAsync ( ) ;
452+ await using var session1 = await CreateSessionAsync ( ) ;
448453 var sessionId = session1 . SessionId ;
454+ await SuspendAndUntrackSessionForResumeAsync ( session1 ) ;
449455
450456 var session2 = await ResumeSessionAsync ( sessionId , new ResumeSessionConfig
451457 {
@@ -493,8 +499,10 @@ public async Task Should_Apply_Session_Limits_On_Create()
493499 [ Fact ]
494500 public async Task Should_Apply_Session_Limits_On_Resume ( )
495501 {
496- var session1 = await CreateSessionAsync ( ) ;
497- var session2 = await ResumeSessionAsync ( session1 . SessionId , new ResumeSessionConfig
502+ await using var session1 = await CreateSessionAsync ( ) ;
503+ var sessionId = session1 . SessionId ;
504+ await SuspendAndUntrackSessionForResumeAsync ( session1 ) ;
505+ var session2 = await ResumeSessionAsync ( sessionId , new ResumeSessionConfig
498506 {
499507 SessionLimits = new SessionLimitsConfig
500508 {
@@ -513,7 +521,6 @@ public async Task Should_Apply_Session_Limits_On_Resume()
513521 finally
514522 {
515523 await session2 . DisposeAsync ( ) ;
516- await session1 . DisposeAsync ( ) ;
517524 }
518525 }
519526
@@ -558,8 +565,10 @@ public async Task Should_Apply_Excluded_Built_In_Agents_On_Resume()
558565 {
559566 const string excludedAgent = "explore" ;
560567
561- var session1 = await CreateSessionAsync ( ) ;
562- var session2 = await ResumeSessionAsync ( session1 . SessionId , new ResumeSessionConfig
568+ await using var session1 = await CreateSessionAsync ( ) ;
569+ var sessionId = session1 . SessionId ;
570+ await SuspendAndUntrackSessionForResumeAsync ( session1 ) ;
571+ var session2 = await ResumeSessionAsync ( sessionId , new ResumeSessionConfig
563572 {
564573 ExcludedBuiltInAgents = [ excludedAgent ] ,
565574 } ) ;
@@ -575,7 +584,6 @@ public async Task Should_Apply_Excluded_Built_In_Agents_On_Resume()
575584 finally
576585 {
577586 await session2 . DisposeAsync ( ) ;
578- await session1 . DisposeAsync ( ) ;
579587 }
580588 }
581589
0 commit comments