@@ -1524,6 +1524,73 @@ it.effect("ProviderSessionManagerV2 gives up on a provider that never confirms a
15241524 } ) ,
15251525) ;
15261526
1527+ it . effect ( "ProviderSessionManagerV2 still idles out a session releaseUnlessBusy kept" , ( ) =>
1528+ Effect . gen ( function * ( ) {
1529+ const state = yield * Ref . make ( emptyState ) ;
1530+ yield * Effect . gen ( function * ( ) {
1531+ const eventSink = yield * EventSink . EventSinkV2 ;
1532+ const idAllocator = yield * IdAllocator . IdAllocatorV2 ;
1533+ const manager = yield * ProviderSessionManager . ProviderSessionManagerV2 ;
1534+ const projectionStore = yield * ProjectionStore . ProjectionStoreV2 ;
1535+ const now = yield * DateTime . now ;
1536+ const threadId = ThreadId . make ( "thread-provider-session-manager-kept-idles" ) ;
1537+ const providerSessionId = idAllocator . derive . providerSession ( {
1538+ providerInstanceId : modelSelection . instanceId ,
1539+ } ) ;
1540+ yield * eventSink . write ( {
1541+ events : [ yield * makeThreadCreatedEvent ( { idAllocator, threadId, now } ) ] ,
1542+ } ) ;
1543+ const runtime = yield * manager . open ( {
1544+ threadId,
1545+ providerSessionId,
1546+ modelSelection,
1547+ runtimePolicy,
1548+ } ) ;
1549+ const providerThread = makeProviderThread ( {
1550+ idAllocator,
1551+ threadId,
1552+ providerSessionId,
1553+ now,
1554+ nativeThreadId : `native-${ threadId } ` ,
1555+ } ) ;
1556+ const runId = idAllocator . derive . run ( { threadId, ordinal : 1 } ) ;
1557+ yield * runtime . startTurn ( {
1558+ appThread : ( yield * projectionStore . getThreadProjection ( threadId ) ) . thread ,
1559+ threadId,
1560+ runId,
1561+ runOrdinal : 1 ,
1562+ providerTurnOrdinal : 1 ,
1563+ attemptId : idAllocator . derive . runAttempt ( { runId, attemptOrdinal : 1 } ) ,
1564+ rootNodeId : idAllocator . derive . rootNode ( { runId } ) ,
1565+ providerThread,
1566+ message : {
1567+ createdBy : "user" ,
1568+ creationSource : "web" ,
1569+ messageId : yield * idAllocator . allocate . message ( { threadId, ordinal : 1 } ) ,
1570+ text : "turn" ,
1571+ attachments : [ ] ,
1572+ } ,
1573+ modelSelection,
1574+ runtimePolicy,
1575+ } ) ;
1576+
1577+ assert . isFalse (
1578+ yield * manager . releaseUnlessBusy ( {
1579+ providerSessionId,
1580+ ownProviderThreadIds : [ providerThread . id ] ,
1581+ throughRunOrdinal : 1 ,
1582+ keepIf : Effect . succeed ( true ) ,
1583+ reason : "manual_shutdown" ,
1584+ } ) ,
1585+ ) ;
1586+ assert . isTrue ( yield * manager . isLive ( providerSessionId ) ) ;
1587+ // The stopped run 1 never reports its end.
1588+ yield * TestClock . adjust ( "2 seconds" ) ;
1589+ assert . isFalse ( yield * manager . isLive ( providerSessionId ) ) ;
1590+ } ) . pipe ( Effect . provide ( layerTest ( { state, idleTimeoutMs : 1_000 } ) ) ) ;
1591+ } ) ,
1592+ ) ;
1593+
15271594it . effect (
15281595 "ProviderSessionManagerV2 keeps a shared session a sibling is busy on when releasing" ,
15291596 ( ) =>
0 commit comments