From 468e59f86c311370d264e4a885ef6a50f01cf7fb Mon Sep 17 00:00:00 2001 From: nioasoft Date: Mon, 26 Jan 2026 12:26:06 +0200 Subject: [PATCH 1/2] fix: handle 404 errors for deleted assistant conversations When a stored conversation ID no longer exists (e.g., database was reset or conversation was deleted), the UI would repeatedly try to fetch it, causing endless 404 errors in the console. This fix: - Stops retrying on 404 errors (conversation doesn't exist) - Automatically clears the stored conversation ID from localStorage when a 404 is received, allowing the user to start fresh Co-Authored-By: Claude Opus 4.5 --- ui/src/components/AssistantPanel.tsx | 10 +++++++++- ui/src/hooks/useConversations.ts | 7 +++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/ui/src/components/AssistantPanel.tsx b/ui/src/components/AssistantPanel.tsx index 5efe624..2093564 100644 --- a/ui/src/components/AssistantPanel.tsx +++ b/ui/src/components/AssistantPanel.tsx @@ -49,11 +49,19 @@ export function AssistantPanel({ projectName, isOpen, onClose }: AssistantPanelP ) // Fetch conversation details when we have an ID - const { data: conversationDetail, isLoading: isLoadingConversation } = useConversation( + const { data: conversationDetail, isLoading: isLoadingConversation, error: conversationError } = useConversation( projectName, conversationId ) + // Clear stored conversation ID if it no longer exists (404 error) + useEffect(() => { + if (conversationError && conversationId) { + console.warn(`Conversation ${conversationId} not found, clearing stored ID`) + setConversationId(null) + } + }, [conversationError, conversationId]) + // Convert API messages to ChatMessage format for the chat component const initialMessages: ChatMessage[] | undefined = conversationDetail?.messages.map((msg) => ({ id: `db-${msg.id}`, diff --git a/ui/src/hooks/useConversations.ts b/ui/src/hooks/useConversations.ts index 908b22d..0a59534 100644 --- a/ui/src/hooks/useConversations.ts +++ b/ui/src/hooks/useConversations.ts @@ -26,6 +26,13 @@ export function useConversation(projectName: string | null, conversationId: numb queryFn: () => api.getAssistantConversation(projectName!, conversationId!), enabled: !!projectName && !!conversationId, staleTime: 30_000, // Cache for 30 seconds + retry: (failureCount, error) => { + // Don't retry on 404 errors (conversation doesn't exist) + if (error instanceof Error && error.message.includes('404')) { + return false + } + return failureCount < 3 + }, }) } From 2b07625ce4c6082d25e848f86a49f8b1ccfd79bb Mon Sep 17 00:00:00 2001 From: nioasoft Date: Mon, 26 Jan 2026 12:47:21 +0200 Subject: [PATCH 2/2] fix: improve 404 detection for deleted conversations - Check for 'not found' message (server response) in addition to '404' - Only clear stored conversation ID on actual 404 errors - Prevent unnecessary retries for deleted conversations - Don't clear conversation on transient network errors Co-Authored-By: Claude Opus 4.5 --- ui/src/components/AssistantPanel.tsx | 8 ++++++-- ui/src/hooks/useConversations.ts | 7 +++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/ui/src/components/AssistantPanel.tsx b/ui/src/components/AssistantPanel.tsx index 2093564..c02d380 100644 --- a/ui/src/components/AssistantPanel.tsx +++ b/ui/src/components/AssistantPanel.tsx @@ -57,8 +57,12 @@ export function AssistantPanel({ projectName, isOpen, onClose }: AssistantPanelP // Clear stored conversation ID if it no longer exists (404 error) useEffect(() => { if (conversationError && conversationId) { - console.warn(`Conversation ${conversationId} not found, clearing stored ID`) - setConversationId(null) + const message = conversationError.message.toLowerCase() + // Only clear for 404 errors, not transient network issues + if (message.includes('not found') || message.includes('404')) { + console.warn(`Conversation ${conversationId} not found, clearing stored ID`) + setConversationId(null) + } } }, [conversationError, conversationId]) diff --git a/ui/src/hooks/useConversations.ts b/ui/src/hooks/useConversations.ts index 0a59534..c3b50de 100644 --- a/ui/src/hooks/useConversations.ts +++ b/ui/src/hooks/useConversations.ts @@ -27,8 +27,11 @@ export function useConversation(projectName: string | null, conversationId: numb enabled: !!projectName && !!conversationId, staleTime: 30_000, // Cache for 30 seconds retry: (failureCount, error) => { - // Don't retry on 404 errors (conversation doesn't exist) - if (error instanceof Error && error.message.includes('404')) { + // Don't retry on "not found" errors (404) - conversation doesn't exist + if (error instanceof Error && ( + error.message.toLowerCase().includes('not found') || + error.message === 'HTTP 404' + )) { return false } return failureCount < 3