@@ -480,17 +480,25 @@ describe.skipIf(!enabled)('Assistant search latency on a realistic indexed corpu
480480 expect ( run ) . not . toHaveBeenCalled ( )
481481 } )
482482
483- it . each ( [ 'keyword' , 'both' ] as const ) (
484- 'handles %s SQL branches exceeding the deadline explicitly ' ,
483+ it . each ( [ 'vector' , ' keyword', 'both' ] as const ) (
484+ 'keeps the Assistant budget when %s SQL branches are delayed ' ,
485485 async ( delayedLegs ) => {
486+ diagnosticLog ?. mockClear ( )
487+ let vectorDelayed = false
486488 const query = SearchBudget . prototype . query
487489 const delayed = vi . spyOn ( SearchBudget . prototype , 'query' ) . mockImplementation ( function < T > (
488490 this : SearchBudget ,
489491 stage : SearchStage ,
490492 run : ( executor : SearchExecutor ) => PromiseLike < T >
491493 ) : Promise < T > {
492494 return query . call ( this , stage , async ( tx ) => {
493- if ( delayedLegs === 'both' || this . leg === 'keyword' )
495+ if ( delayedLegs === 'vector' && this . leg === 'vector' && ! vectorDelayed ) {
496+ vectorDelayed = true
497+ await tx . execute ( sql `SELECT pg_sleep(4)` )
498+ } else if (
499+ delayedLegs === 'both' ||
500+ ( delayedLegs === 'keyword' && this . leg === 'keyword' )
501+ )
494502 await tx . execute ( sql `SELECT pg_sleep(9)` )
495503 return run ( tx )
496504 } ) as Promise < T >
@@ -509,6 +517,10 @@ describe.skipIf(!enabled)('Assistant search latency on a realistic indexed corpu
509517 } ) ,
510518 }
511519 )
520+ const completed = diagnosticLog ?. mock . calls . find (
521+ ( [ message ] ) => message === 'Knowledge search completed'
522+ )
523+ expect ( diagnosticSchema . parse ( completed ?. [ 1 ] ) . vectorBudgetMs ) . toBe ( 8000 )
512524 if ( delayedLegs === 'both' ) {
513525 expect ( result ) . toMatchObject ( {
514526 success : true ,
@@ -521,14 +533,19 @@ describe.skipIf(!enabled)('Assistant search latency on a realistic indexed corpu
521533 }
522534 expect ( result ) . toMatchObject ( {
523535 success : true ,
524- data : { retrieval : { status : 'partial' , timedOutLegs : [ 'keyword' ] } } ,
536+ data : {
537+ retrieval :
538+ delayedLegs === 'vector'
539+ ? { status : 'complete' , timedOutLegs : [ ] }
540+ : { status : 'partial' , timedOutLegs : [ 'keyword' ] } ,
541+ } ,
525542 } )
526543 const parsed = resultSchema . parse ( result )
527544 expect ( parsed . data . results . length ) . toBeGreaterThan ( 0 )
528545 expect (
529546 parsed . data . results . every ( ( row ) => row . knowledgeBaseId === ids . knowledgeBaseId )
530547 ) . toBe ( true )
531- report [ ' deadline.partial' ] = { resultCount : parsed . data . results . length }
548+ report [ `assistant. deadline.${ delayedLegs } ` ] = { resultCount : parsed . data . results . length }
532549 } finally {
533550 delayed . mockRestore ( )
534551 }
@@ -539,6 +556,7 @@ describe.skipIf(!enabled)('Assistant search latency on a realistic indexed corpu
539556 it . each ( [ 'vector' , 'both' ] as const ) (
540557 'returns incomplete dashboard coverage when %s SQL branches exceed their deadline' ,
541558 async ( delayedLegs ) => {
559+ diagnosticLog ?. mockClear ( )
542560 const authenticate = vi . spyOn ( internalSessionAuth , 'authenticate' ) . mockResolvedValue ( {
543561 kind : 'session' ,
544562 userId : ids . aliceId ,
@@ -552,7 +570,7 @@ describe.skipIf(!enabled)('Assistant search latency on a realistic indexed corpu
552570 ) : Promise < T > {
553571 return query . call ( this , stage , async ( tx ) => {
554572 if ( delayedLegs === 'both' || this . leg === 'vector' )
555- await tx . execute ( sql `SELECT pg_sleep(9 )` )
573+ await tx . execute ( sql `SELECT pg_sleep(${ delayedLegs === 'both' ? 9 : 4 } )` )
556574 return run ( tx )
557575 } ) as Promise < T >
558576 } )
@@ -569,6 +587,13 @@ describe.skipIf(!enabled)('Assistant search latency on a realistic indexed corpu
569587 } )
570588 )
571589 expect ( response . status ) . toBe ( 200 )
590+ const completed = diagnosticLog ?. mock . calls . find (
591+ ( [ message ] ) => message === 'Knowledge search completed'
592+ )
593+ const diagnostics = diagnosticSchema . parse ( completed ?. [ 1 ] )
594+ expect ( diagnostics . vectorBudgetMs ) . toBe ( 3000 )
595+ expect ( diagnostics . stages . vector . totalMs ) . toBeGreaterThan ( 2500 )
596+ expect ( diagnostics . stages . vector . totalMs ) . toBeLessThan ( 4000 )
572597 const data = workspaceKnowledgeSearchDataSchema . parse ( ( await response . json ( ) ) . data )
573598 expect ( data . retrieval ) . toEqual ( {
574599 status : 'partial' ,
0 commit comments