@@ -320,18 +320,18 @@ async function refreshChatSessionPickerAfterRename(state: AppViewState) {
320320 return ;
321321 }
322322 // Tie the refresh to the picker request-generation counter so that a newer
323- // search arriving while the rename-triggered sessions.list is in flight
324- // is not overwritten by the stale refresh response. When the signature
325- // matches the active request (begin returns null) there is no concurrent
326- // search to race against, so proceed without the cancel guard.
327- const guardId = beginChatSessionPickerSearchRequest (
328- state ,
329- createChatSessionPickerRequestSignature ( {
330- query : normalizeOptionalString ( state . chatSessionPickerAppliedQuery ) ?? "" ,
331- } ) ,
332- ) ;
323+ // search arriving while the rename-triggered sessions.list is in flight is
324+ // not overwritten by the stale refresh response. When the signature matches
325+ // the active request (begin returns null) we still need our own guard: a
326+ // newer search can start during the await below, so invalidate the duplicate
327+ // and take a fresh generation, keeping the post-await assignment guarded.
328+ const signature = createChatSessionPickerRequestSignature ( {
329+ query : normalizeOptionalString ( state . chatSessionPickerAppliedQuery ) ?? "" ,
330+ } ) ;
331+ let guardId = beginChatSessionPickerSearchRequest ( state , signature ) ;
333332 if ( guardId === null ) {
334333 invalidateChatSessionPickerSearchRequests ( state ) ;
334+ guardId = beginChatSessionPickerSearchRequest ( state , signature ) ;
335335 }
336336 const query = normalizeOptionalString ( state . chatSessionPickerAppliedQuery ) ?? "" ;
337337 const limit =
@@ -349,13 +349,13 @@ async function refreshChatSessionPickerAfterRename(state: AppViewState) {
349349 limit,
350350 } ) ,
351351 ) ;
352- if ( guardId !== null && ! isCurrentChatSessionPickerSearchRequest ( state , guardId ) ) {
352+ // guardId is always a live generation here, so a newer search started during
353+ // the await wins and this stale refresh bails instead of clobbering it.
354+ if ( ! isCurrentChatSessionPickerSearchRequest ( state , guardId ) ) {
353355 return ;
354356 }
355357 state . chatSessionPickerResult = projectChatSessionPickerResult ( state , listResult ) ;
356- if ( guardId !== null ) {
357- finishChatSessionPickerSearchRequest ( state , guardId ) ;
358- }
358+ finishChatSessionPickerSearchRequest ( state , guardId ) ;
359359}
360360
361361async function saveChatSessionPickerRename (
0 commit comments