@@ -73,6 +73,7 @@ export const makeEnvironmentShellState = Effect.fn("EnvironmentShellState.make")
7373 } ) ;
7474 const awaitingCompletion = yield * Ref . make ( false ) ;
7575 const lastAuthoritativeSession = yield * Ref . make < RpcSession | null > ( null ) ;
76+ const activeSubscriptionSession = yield * Ref . make < RpcSession | null > ( null ) ;
7677 const persistence = yield * Queue . sliding < OrchestrationShellSnapshot > ( 1 ) ;
7778
7879 const persist = Effect . fn ( "EnvironmentShellState.persist" ) ( function * (
@@ -168,6 +169,12 @@ export const makeEnvironmentShellState = Effect.fn("EnvironmentShellState.make")
168169 status : waiting ? "synchronizing" : "live" ,
169170 error : Option . none ( ) ,
170171 } ) ;
172+ if ( item . kind === "snapshot" ) {
173+ const session = yield * Ref . get ( activeSubscriptionSession ) ;
174+ if ( session !== null ) {
175+ yield * Ref . set ( lastAuthoritativeSession , session ) ;
176+ }
177+ }
171178 yield * Queue . offer ( persistence , nextSnapshot ) ;
172179 } ) ;
173180
@@ -182,6 +189,7 @@ export const makeEnvironmentShellState = Effect.fn("EnvironmentShellState.make")
182189 subscribeDynamic (
183190 ORCHESTRATION_WS_METHODS . subscribeShell ,
184191 Effect . fn ( "EnvironmentShellState.makeSubscribeInput" ) ( function * ( session ) {
192+ yield * Ref . set ( activeSubscriptionSession , session ) ;
185193 const supportsCompletionMarker = yield * session . initialConfig . pipe (
186194 Effect . map ( ( config ) => config . shellResumeCompletionMarker === true ) ,
187195 Effect . orElseSucceed ( ( ) => false ) ,
@@ -213,7 +221,6 @@ export const makeEnvironmentShellState = Effect.fn("EnvironmentShellState.make")
213221 const httpSnapshot = yield * snapshotLoader . load ( prepared ) ;
214222 if ( Option . isSome ( httpSnapshot ) ) {
215223 yield * applyItem ( { kind : "snapshot" , snapshot : httpSnapshot . value } ) ;
216- yield * Ref . set ( lastAuthoritativeSession , session ) ;
217224 canResume = true ;
218225 current = yield * SubscriptionRef . get ( state ) ;
219226 }
0 commit comments