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 + }, }) }