@@ -3885,31 +3885,23 @@ it.effect(
38853885 unloaded : unloadedNativeThreadIds ,
38863886 } ) ) ,
38873887 ) ;
3888+ // An unreadable setting at load marks the catalog unknown so it refreshes later.
38883889 yield * Ref . set ( settingsUnavailable , true ) ;
38893890 yield * resume ( threadA ) ;
3890- yield * resume ( threadA ) ;
3891- assert . deepEqual ( yield * observed , { resumeCount : 1 , unloaded : [ ] } ) ;
38923891 yield * Ref . set ( settingsUnavailable , false ) ;
38933892 yield * resume ( threadB ) ;
38943893 assert . deepEqual ( yield * observed , { resumeCount : 2 , unloaded : [ ] } ) ;
38953894
38963895 yield * settings . updateSettings ( { linkedEnvironmentsEnabled : true } ) ;
38973896 // Background work, or a probe that cannot tell, keeps the stale thread loaded.
3897+ // A native resume meanwhile must not overwrite the recorded catalog.
38983898 yield * Ref . set ( pendingWork , Effect . succeed ( true ) ) ;
38993899 yield * resume ( threadA , { ...modelSelection , model : "gpt-5.4-mini" } ) ;
3900- yield * resume ( threadA ) ;
39013900 yield * Ref . set ( pendingWork , Effect . die ( "probe failed" ) ) ;
39023901 yield * resume ( threadA ) ;
39033902 assert . deepEqual ( yield * observed , { resumeCount : 4 , unloaded : [ ] } ) ;
39043903
39053904 yield * Ref . set ( pendingWork , Effect . succeed ( false ) ) ;
3906- const reloaded = yield * resume ( threadA ) ;
3907- assert . deepEqual ( reloaded . nativeThreadRef , providerThreads [ threadA ] ! . nativeThreadRef ) ;
3908- assert . deepEqual ( yield * observed , { resumeCount : 5 , unloaded : [ "native-links-a" ] } ) ;
3909- yield * Ref . set ( settingsUnavailable , true ) ;
3910- yield * resume ( threadA ) ;
3911- assert . deepEqual ( yield * observed , { resumeCount : 5 , unloaded : [ "native-links-a" ] } ) ;
3912- yield * Ref . set ( settingsUnavailable , false ) ;
39133905 yield * resume ( threadA ) ;
39143906 assert . deepEqual ( yield * observed , { resumeCount : 5 , unloaded : [ "native-links-a" ] } ) ;
39153907
@@ -4012,13 +4004,11 @@ it.effect.each([true, false])(
40124004 Effect . gen ( function * ( ) {
40134005 const state = yield * Ref . make ( emptyState ) ;
40144006 const pendingWork = yield * Ref . make < Effect . Effect < boolean > > ( Effect . succeed ( false ) ) ;
4015- const settingsUnavailable = yield * Ref . make ( false ) ;
4016- const settings = yield * makeTestSettings ( settingsUnavailable ) ;
4007+ const settings = yield * makeTestSettings ( yield * Ref . make ( false ) ) ;
40174008 yield * Effect . gen ( function * ( ) {
40184009 const eventSink = yield * EventSink . EventSinkV2 ;
40194010 const idAllocator = yield * IdAllocator . IdAllocatorV2 ;
40204011 const manager = yield * ProviderSessionManager . ProviderSessionManagerV2 ;
4021- const projectionStore = yield * ProjectionStore . ProjectionStoreV2 ;
40224012 const now = yield * DateTime . now ;
40234013 const threadId = ThreadId . make ( "thread-provider-session-manager-links-exclusive" ) ;
40244014 const providerSessionId = yield * idAllocator . allocate . providerSession ( {
@@ -4028,25 +4018,18 @@ it.effect.each([true, false])(
40284018 yield * eventSink . write ( {
40294019 events : [ yield * makeThreadCreatedEvent ( { idAllocator, threadId, now } ) ] ,
40304020 } ) ;
4031- const providerThread = makeProviderThread ( {
4032- idAllocator,
4033- threadId,
4034- providerSessionId,
4035- now,
4036- nativeThreadId : "native-links-exclusive" ,
4037- } ) ;
40384021 const open = manager . open ( { threadId, providerSessionId, modelSelection, runtimePolicy } ) ;
40394022 const counts = Ref . get ( state ) . pipe (
40404023 Effect . map ( ( { openCount, closeCount } ) => ( { openCount, closeCount } ) ) ,
40414024 ) ;
40424025
4043- yield * Ref . set ( settingsUnavailable , true ) ;
40444026 const first = yield * open ;
4045- yield * first . resumeThread ( { providerThread, threadId, modelSelection, runtimePolicy } ) ;
4046- assert . strictEqual ( yield * open , first ) ;
4047- yield * Ref . set ( settingsUnavailable , false ) ;
4048-
40494027 yield * settings . updateSettings ( { linkedEnvironmentsEnabled : true } ) ;
4028+ if ( ! canResumeAfterRestart ) {
4029+ assert . strictEqual ( yield * open , first ) ;
4030+ assert . deepEqual ( yield * counts , { openCount : 1 , closeCount : 0 } ) ;
4031+ return ;
4032+ }
40504033 yield * Ref . set ( pendingWork , Effect . succeed ( true ) ) ;
40514034 assert . strictEqual ( yield * open , first ) ;
40524035 yield * Ref . set ( pendingWork , Effect . die ( "probe failed" ) ) ;
@@ -4055,7 +4038,13 @@ it.effect.each([true, false])(
40554038 idAllocator,
40564039 threadId,
40574040 providerSessionId,
4058- providerThread,
4041+ providerThread : makeProviderThread ( {
4042+ idAllocator,
4043+ threadId,
4044+ providerSessionId,
4045+ now,
4046+ nativeThreadId : "native-links-exclusive" ,
4047+ } ) ,
40594048 now,
40604049 } ) ;
40614050 yield * eventSink . write ( { events : pending . events } ) ;
@@ -4075,65 +4064,8 @@ it.effect.each([true, false])(
40754064 } ,
40764065 ] ,
40774066 } ) ;
4078-
4079- const second = yield * open ;
4080- if ( ! canResumeAfterRestart ) {
4081- assert . strictEqual ( second , first ) ;
4082- assert . deepEqual ( yield * counts , { openCount : 1 , closeCount : 0 } ) ;
4083- return ;
4084- }
4085- assert . notStrictEqual ( second , first ) ;
4067+ yield * open ;
40864068 assert . deepEqual ( yield * counts , { openCount : 2 , closeCount : 1 } ) ;
4087- const resumed = yield * second . resumeThread ( {
4088- providerThread,
4089- threadId,
4090- modelSelection,
4091- runtimePolicy,
4092- } ) ;
4093- assert . deepEqual ( resumed . nativeThreadRef , providerThread . nativeThreadRef ) ;
4094- assert . equal ( ( yield * Ref . get ( state ) ) . resumeCount , 2 ) ;
4095-
4096- yield * settings . updateSettings ( { linkedEnvironmentsEnabled : false } ) ;
4097- const third = yield * open ;
4098- assert . notStrictEqual ( third , second ) ;
4099- assert . deepEqual ( yield * counts , { openCount : 3 , closeCount : 2 } ) ;
4100-
4101- // A turn that starts while the refresh probes for background work keeps the runtime.
4102- yield * settings . updateSettings ( { linkedEnvironmentsEnabled : true } ) ;
4103- const probing = yield * Deferred . make < void > ( ) ;
4104- const finishProbe = yield * Deferred . make < void > ( ) ;
4105- yield * Ref . set (
4106- pendingWork ,
4107- Deferred . succeed ( probing , undefined ) . pipe (
4108- Effect . andThen ( Deferred . await ( finishProbe ) ) ,
4109- Effect . as ( false ) ,
4110- ) ,
4111- ) ;
4112- const reopening = yield * open . pipe ( Effect . forkChild ) ;
4113- yield * Deferred . await ( probing ) ;
4114- const runId = idAllocator . derive . run ( { threadId, ordinal : 1 } ) ;
4115- yield * third . startTurn ( {
4116- appThread : ( yield * projectionStore . getThreadProjection ( threadId ) ) . thread ,
4117- threadId,
4118- runId,
4119- runOrdinal : 1 ,
4120- providerTurnOrdinal : 1 ,
4121- attemptId : idAllocator . derive . runAttempt ( { runId, attemptOrdinal : 1 } ) ,
4122- rootNodeId : idAllocator . derive . rootNode ( { runId } ) ,
4123- providerThread,
4124- message : {
4125- createdBy : "user" ,
4126- creationSource : "web" ,
4127- messageId : yield * idAllocator . allocate . message ( { threadId, ordinal : 1 } ) ,
4128- text : "turn" ,
4129- attachments : [ ] ,
4130- } ,
4131- modelSelection,
4132- runtimePolicy,
4133- } ) ;
4134- yield * Deferred . succeed ( finishProbe , undefined ) ;
4135- assert . strictEqual ( yield * Fiber . join ( reopening ) , third ) ;
4136- assert . deepEqual ( yield * counts , { openCount : 3 , closeCount : 2 } ) ;
41374069 } ) . pipe (
41384070 Effect . provide (
41394071 layerTest ( {
@@ -4426,9 +4358,6 @@ it.effect(
44264358 yield * settings . updateSettings ( { linkedEnvironmentsEnabled : false } ) ;
44274359 yield * Ref . set ( pendingWork , false ) ;
44284360 assert . equal ( yield * countRawResumes ( failed ) , 1 ) ;
4429- assert . equal ( yield * countRawResumes ( failed ) , 0 ) ;
4430- assert . equal ( yield * countRawResumes ( sibling ) , 0 ) ;
4431- assert . equal ( yield * countRawResumes ( healthy ) , 0 ) ;
44324361 assert . deepEqual ( ( yield * Ref . get ( state ) ) . unloadedNativeThreadIds , [
44334362 "idle-failed-runtime" ,
44344363 "idle-failed-runtime" ,
0 commit comments