From 0ec0f8faaf16cef7aa8e1f415d16987b589313c4 Mon Sep 17 00:00:00 2001 From: Danielle Maywood Date: Fri, 27 Mar 2026 13:08:58 +0000 Subject: [PATCH] fix: guard per-chat cancelQueries to prevent 'Chat not found' race (#23714) --- site/src/pages/AgentsPage/AgentsPage.tsx | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/site/src/pages/AgentsPage/AgentsPage.tsx b/site/src/pages/AgentsPage/AgentsPage.tsx index cb36584680..df704964ba 100644 --- a/site/src/pages/AgentsPage/AgentsPage.tsx +++ b/site/src/pages/AgentsPage/AgentsPage.tsx @@ -471,10 +471,17 @@ const AgentsPage: FC = () => { // title generation finished, so its response carries // the fallback title. void cancelChatListQueries(queryClient); - void queryClient.cancelQueries({ - queryKey: chatKey(updatedChat.id), - exact: true, - }); + // Only cancel a per-chat refetch when the cache + // already has data. Cancelling a first-time fetch + // reverts the query to pending/idle with no data + // and no retry, which AgentDetail shows as + // "Chat not found". + if (queryClient.getQueryData(chatKey(updatedChat.id))) { + void queryClient.cancelQueries({ + queryKey: chatKey(updatedChat.id), + exact: true, + }); + } // For "created" events, use a cross-page existence // check and prepend only to the first page.