@@ -13,6 +13,7 @@ import type { SearchOperation } from "./workspaceSearchProtocol.ts";
1313const make = Effect . gen ( function * ( ) {
1414 const semaphore = yield * Semaphore . make ( 1 ) ;
1515 let current : { process : SearchProcess ; indexes : Set < number > } | undefined ;
16+ let activeIndex : number | undefined ;
1617 let nextId = 0 ;
1718 let closed = false ;
1819 const stop = Effect . fn ( "WorkspaceSearchHost.stop" ) ( function * ( ) {
@@ -41,6 +42,7 @@ const make = Effect.gen(function* () {
4142 return yield * new WorkspaceSearchProcessFailed ( {
4243 cause : new Error ( "Workspace search index is closed." ) ,
4344 } ) ;
45+ activeIndex = id ;
4446 return yield * Effect . gen ( function * ( ) {
4547 const active = yield * Effect . gen ( function * ( ) {
4648 if ( current ) return current ;
@@ -55,7 +57,14 @@ const make = Effect.gen(function* () {
5557 return operation . method === "initialize"
5658 ? null
5759 : yield * active . process . request ( { id, operation } ) ;
58- } ) . pipe ( Effect . onError ( stop ) ) ;
60+ } ) . pipe (
61+ Effect . onError ( stop ) ,
62+ Effect . ensuring (
63+ Effect . sync ( ( ) => {
64+ activeIndex = undefined ;
65+ } ) ,
66+ ) ,
67+ ) ;
5968 } ,
6069 semaphore . withPermits ( 1 ) ,
6170 Effect . timeout ( "20 seconds" ) ,
@@ -64,19 +73,20 @@ const make = Effect.gen(function* () {
6473 yield * Effect . addFinalizer ( ( ) =>
6574 Effect . gen ( function * ( ) {
6675 released = true ;
67- // Disposal must not wait behind a stuck search or native destructor.
68- // Other handles rebuild lazily if this retires the shared process.
69- yield * Effect . acquireUseRelease (
70- semaphore . take ( 1 ) . pipe ( Effect . timeout ( "1 second" ) , Effect . onError ( stop ) ) ,
71- ( ) =>
72- Effect . gen ( function * ( ) {
73- if ( ! current ?. indexes . has ( id ) ) return ;
74- current . indexes . delete ( id ) ;
75- if ( current . indexes . size === 0 ) return yield * stop ( ) ;
76- yield * current . process . request ( { id, operation : { method : "dispose" } } ) ;
77- } ) . pipe ( Effect . timeout ( "1 second" ) , Effect . onError ( stop ) ) ,
78- ( ) => semaphore . release ( 1 ) ,
79- ) . pipe ( Effect . catchCause ( ( ) => Effect . void ) ) ;
76+ if ( activeIndex === id ) yield * stop ( ) ;
77+ // Give unrelated requests their own deadline. The shorter disposal
78+ // deadline bounds the native destructor, not another workspace's scan.
79+ yield * Effect . gen ( function * ( ) {
80+ if ( ! current ?. indexes . has ( id ) ) return ;
81+ current . indexes . delete ( id ) ;
82+ if ( current . indexes . size === 0 ) return yield * stop ( ) ;
83+ yield * current . process . request ( { id, operation : { method : "dispose" } } ) ;
84+ } ) . pipe (
85+ Effect . timeout ( "1 second" ) ,
86+ Effect . onError ( stop ) ,
87+ semaphore . withPermits ( 1 ) ,
88+ Effect . catchCause ( ( ) => Effect . void ) ,
89+ ) ;
8090 } ) ,
8191 ) ;
8292 yield * run ( initialize ) ;
0 commit comments