@@ -384,17 +384,6 @@ export const make = Effect.fn("WorkspaceSearchIndex.make")(function* (
384384 operation : "directorySearch" | "fileSearch" | "grep" | "mixedSearch" ,
385385 execute : ( ) => Result < A > ,
386386 ) : Effect . fn . Return < A , WorkspaceSearchIndexSearchFailed > {
387- // Watchers can lose events; repair hot indexes occasionally, rather than after every turn.
388- yield * Effect . gen ( function * ( ) {
389- const now = yield * Clock . currentTimeMillis ;
390- if ( now - refreshedAt < WORKSPACE_INDEX_RECOVERY_INTERVAL_MS ) return ;
391- refreshedAt = now ;
392- yield * refresh ( ) . pipe (
393- Effect . catch ( ( cause ) =>
394- Effect . logWarning ( "Periodic workspace index recovery failed" , { cwd, cause } ) ,
395- ) ,
396- ) ;
397- } ) . pipe ( refreshPermit . withPermits ( 1 ) ) ;
398387 const result = yield * Effect . try ( {
399388 try : execute ,
400389 catch : ( cause ) =>
@@ -448,8 +437,21 @@ export const make = Effect.fn("WorkspaceSearchIndex.make")(function* (
448437 refreshedAt = yield * Clock . currentTimeMillis ;
449438 } ) ;
450439
440+ // Watchers can lose events; repair hot indexes occasionally, rather than after every turn.
441+ const recover = Effect . fn ( "WorkspaceSearchIndex.recover" ) ( function * ( ) {
442+ const now = yield * Clock . currentTimeMillis ;
443+ if ( now - refreshedAt < WORKSPACE_INDEX_RECOVERY_INTERVAL_MS ) return ;
444+ refreshedAt = now ;
445+ yield * refresh ( ) . pipe (
446+ Effect . catch ( ( cause ) =>
447+ Effect . logWarning ( "Periodic workspace index recovery failed" , { cwd, cause } ) ,
448+ ) ,
449+ ) ;
450+ } , refreshPermit . withPermits ( 1 ) ) ;
451+
451452 const list : WorkspaceSearchIndex [ "Service" ] [ "list" ] = Effect . fn ( "WorkspaceSearchIndex.list" ) (
452453 function * ( ) {
454+ yield * recover ( ) ;
453455 const incompleteBeforeQuery = hasIncompleteInitialScan ( ) ;
454456 const result = yield * runSearch ( "" , WORKSPACE_INDEX_PAGE_SIZE , "mixedSearch" , ( ) =>
455457 finder . mixedSearch ( "" , { pageSize : WORKSPACE_INDEX_PAGE_SIZE } ) ,
@@ -470,6 +472,7 @@ export const make = Effect.fn("WorkspaceSearchIndex.make")(function* (
470472 const search : WorkspaceSearchIndex [ "Service" ] [ "search" ] = Effect . fn (
471473 "WorkspaceSearchIndex.search" ,
472474 ) ( function * ( query , limit , kind , imageOnly ) {
475+ yield * recover ( ) ;
473476 const pageSize = imageOnly ? WORKSPACE_INDEX_PAGE_SIZE : Math . max ( 1 , limit + 1 ) ;
474477 const incompleteBeforeQuery = hasIncompleteInitialScan ( ) ;
475478 if ( kind === "file" || imageOnly ) {
@@ -496,6 +499,7 @@ export const make = Effect.fn("WorkspaceSearchIndex.make")(function* (
496499 const searchContents : WorkspaceSearchIndex [ "Service" ] [ "searchContents" ] = Effect . fn (
497500 "WorkspaceSearchIndex.searchContents" ,
498501 ) ( function * ( input ) {
502+ yield * recover ( ) ;
499503 const { searchQuery, regexMode } = buildContentSearchQuery ( input ) ;
500504 const deadline = performance . now ( ) + CONTENT_SEARCH_TIME_BUDGET_MS ;
501505 // Grep cursors advance per file; whole-word filtering needs enough raw candidates before advancing.
0 commit comments