From 8c52e150f6763ec420705583f4fb4d11c87bd96b Mon Sep 17 00:00:00 2001 From: Kyle Carberry Date: Fri, 6 Mar 2026 14:42:49 -0800 Subject: [PATCH] fix(site): prevent stale title clobber in sidebar from watchChats race (#22734) --- offlinedocs/next-env.d.ts | 3 +- site/src/pages/AgentsPage/AgentsPage.tsx | 37 ++++++++++++++---------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/offlinedocs/next-env.d.ts b/offlinedocs/next-env.d.ts index 4f11a03dc6..254b73c165 100644 --- a/offlinedocs/next-env.d.ts +++ b/offlinedocs/next-env.d.ts @@ -1,5 +1,6 @@ /// /// +/// // NOTE: This file should not be edited -// see https://nextjs.org/docs/basic-features/typescript for more information. +// see https://nextjs.org/docs/pages/api-reference/config/typescript for more information. diff --git a/site/src/pages/AgentsPage/AgentsPage.tsx b/site/src/pages/AgentsPage/AgentsPage.tsx index bf6e5dd9cf..98e7b4c172 100644 --- a/site/src/pages/AgentsPage/AgentsPage.tsx +++ b/site/src/pages/AgentsPage/AgentsPage.tsx @@ -492,25 +492,32 @@ const AgentsPage: FC = () => { return; } + // Scope field updates by event kind so that + // status_change events (which may carry a stale title + // snapshot from before async title generation + // finished) don't clobber a title_change that already + // landed. + const isTitleEvent = chatEvent.kind === "title_change"; + const isStatusEvent = chatEvent.kind === "status_change"; + queryClient.setQueryData( chatsKey, (prev: TypesGen.Chat[] | undefined) => { if (!prev) return prev; const exists = prev.some((c) => c.id === updatedChat.id); if (exists) { - return prev.map((c) => - c.id === updatedChat.id - ? { - ...c, - status: updatedChat.status, - title: updatedChat.title, - updated_at: - c.updated_at > updatedChat.updated_at - ? c.updated_at - : updatedChat.updated_at, - } - : c, - ); + return prev.map((c) => { + if (c.id !== updatedChat.id) return c; + return { + ...c, + ...(isStatusEvent && { status: updatedChat.status }), + ...(isTitleEvent && { title: updatedChat.title }), + updated_at: + c.updated_at > updatedChat.updated_at + ? c.updated_at + : updatedChat.updated_at, + }; + }); } if (chatEvent.kind === "created") { return [updatedChat, ...prev]; @@ -528,8 +535,8 @@ const AgentsPage: FC = () => { ...previousChat, chat: { ...previousChat.chat, - status: updatedChat.status, - title: updatedChat.title, + ...(isStatusEvent && { status: updatedChat.status }), + ...(isTitleEvent && { title: updatedChat.title }), updated_at: previousChat.chat.updated_at > updatedChat.updated_at ? previousChat.chat.updated_at