File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -105,6 +105,7 @@ function layerExecutorFor(input: {
105105 shutdown : Effect . void ,
106106 open : ( ) => Effect . die ( "unused open" ) ,
107107 get : ( ) => Effect . succeed ( Option . none ( ) ) ,
108+ isLive : ( ) => Effect . succeed ( false ) ,
108109 close : ( ) => Effect . void ,
109110 closeInstance : ( ) => Effect . void ,
110111 release : ( ) => record ( "release" ) ,
Original file line number Diff line number Diff line change @@ -2899,6 +2899,25 @@ it.effect(
28992899 } ) ,
29002900) ;
29012901
2902+ it . effect ( "ProviderSessionManagerV2 checks liveness without delaying idle release" , ( ) =>
2903+ Effect . gen ( function * ( ) {
2904+ const state = yield * Ref . make ( emptyState ) ;
2905+ const effect = Effect . gen ( function * ( ) {
2906+ const manager = yield * ProviderSessionManager . ProviderSessionManagerV2 ;
2907+ const { providerSessionId } = yield * openSessionWithBackgroundCommand (
2908+ "provider-session-manager-is-live" ,
2909+ ) ;
2910+ yield * TestClock . adjust ( "600 millis" ) ;
2911+ assert . isTrue ( yield * manager . isLive ( providerSessionId ) ) ;
2912+ yield * TestClock . adjust ( "600 millis" ) ;
2913+ yield * Effect . yieldNow ;
2914+ assert . isFalse ( yield * manager . isLive ( providerSessionId ) ) ;
2915+ } ) ;
2916+
2917+ yield * effect . pipe ( Effect . provide ( layerTest ( { state, idleTimeoutMs : 1000 } ) ) ) ;
2918+ } ) ,
2919+ ) ;
2920+
29022921it . effect ( "ProviderSessionManagerV2 clears the background roster of an idle-released session" , ( ) =>
29032922 Effect . gen ( function * ( ) {
29042923 const state = yield * Ref . make ( emptyState ) ;
Original file line number Diff line number Diff line change @@ -169,6 +169,8 @@ export interface ProviderSessionManagerV2Shape {
169169 Option . Option < ProviderAdapter . ProviderAdapterV2SessionRuntime > ,
170170 ProviderSessionManagerV2Error
171171 > ;
172+ /** Whether the session's runtime is running. Unlike `get`, not activity. */
173+ readonly isLive : ( providerSessionId : ProviderSessionId ) => Effect . Effect < boolean > ;
172174 readonly close : (
173175 providerSessionId : ProviderSessionId ,
174176 ) => Effect . Effect < void , ProviderSessionManagerV2Error > ;
@@ -2346,6 +2348,10 @@ export const layerWithOptions = (
23462348 return exposedRuntime ;
23472349 } ) ,
23482350 ) ,
2351+ isLive : ( providerSessionId ) =>
2352+ Ref . get ( sessions ) . pipe (
2353+ Effect . map ( ( current ) => current . has ( sessionKey ( providerSessionId ) ) ) ,
2354+ ) ,
23492355 get : ( providerSessionId ) =>
23502356 Effect . gen ( function * ( ) {
23512357 const entry = ( yield * Ref . get ( sessions ) ) . get ( sessionKey ( providerSessionId ) ) ;
Original file line number Diff line number Diff line change @@ -273,6 +273,7 @@ it.effect(
273273 Effect . succeed (
274274 providerSessionId === oldSessionId ? Option . some ( runtime ) : Option . none ( ) ,
275275 ) ,
276+ isLive : ( providerSessionId ) => Effect . succeed ( providerSessionId === oldSessionId ) ,
276277 close : ( ) => Effect . void ,
277278 closeInstance : ( ) => Effect . void ,
278279 release : ( ) => Effect . void ,
Original file line number Diff line number Diff line change @@ -5,7 +5,6 @@ import * as Deferred from "effect/Deferred";
55import * as Fiber from "effect/Fiber" ;
66import * as FileSystem from "effect/FileSystem" ;
77import * as Layer from "effect/Layer" ;
8- import * as Option from "effect/Option" ;
98import type * as Path from "effect/Path" ;
109import type * as Scope from "effect/Scope" ;
1110import * as Stream from "effect/Stream" ;
@@ -313,7 +312,7 @@ const cleanupFixture = (
313312 Effect . sync ( ( ) => threads . find ( ( thread ) => thread . id === threadId ) ?? null ) ,
314313 } as unknown as ProjectionStore . ProjectionStoreV2 [ "Service" ] ) ,
315314 Effect . provideService ( ProviderSessionManager . ProviderSessionManagerV2 , {
316- get : ( ) => Effect . sync ( ( ) => ( sessionLive ? Option . some ( { } ) : Option . none ( ) ) ) ,
315+ isLive : ( ) => Effect . sync ( ( ) => sessionLive ) ,
317316 } as unknown as ProviderSessionManager . ProviderSessionManagerV2 [ "Service" ] ) ,
318317 Effect . provideService ( Orchestrator . OrchestratorV2 , {
319318 streamDomainEvents : Stream . suspend ( ( ) => events ) ,
Original file line number Diff line number Diff line change @@ -626,7 +626,7 @@ const make = Effect.gen(function* () {
626626 const cwd = path . resolve ( session . cwd ) ;
627627 if (
628628 ( cwd === worktreePath || inside ( worktreePath , cwd ) ) &&
629- Option . isSome ( yield * providerSessions . get ( session . id ) )
629+ ( yield * providerSessions . isLive ( session . id ) )
630630 )
631631 return "provider session is still open" ;
632632 }
You can’t perform that action at this time.
0 commit comments