From ebd7509d7eca4bc704478e061a673ebfb569d185 Mon Sep 17 00:00:00 2001 From: Usama Date: Thu, 28 Aug 2025 09:51:29 +0000 Subject: [PATCH 1/5] - added specific error codes to make the conversation ended true - added retry logic to check conversation endpoint --- .../src/components/participant/hooks/index.ts | 20 +++++++-- .../participant/ParticipantConversation.tsx | 43 ++++++++++++++++--- 2 files changed, 52 insertions(+), 11 deletions(-) diff --git a/echo/frontend/src/components/participant/hooks/index.ts b/echo/frontend/src/components/participant/hooks/index.ts index 1dd9e355..e07da89d 100644 --- a/echo/frontend/src/components/participant/hooks/index.ts +++ b/echo/frontend/src/components/participant/hooks/index.ts @@ -13,6 +13,7 @@ import { createItem, readItems } from "@directus/sdk"; import { useMutation, useQueryClient } from "@tanstack/react-query"; import { toast } from "@/components/common/Toaster"; import { useQuery } from "@tanstack/react-query"; +import { AxiosError } from "axios"; export const useCreateProjectReportMetricOncePerDayMutation = () => { return useMutation({ @@ -278,7 +279,6 @@ export const useSubmitNotificationParticipant = () => { }); }; - export const useParticipantProjectById = (projectId: string) => { return useQuery({ queryKey: ["participantProject", projectId], @@ -308,7 +308,9 @@ export const combineUserChunks = ( }; }; -export const useConversationRepliesQuery = (conversationId: string | undefined) => { +export const useConversationRepliesQuery = ( + conversationId: string | undefined, +) => { return useQuery({ queryKey: ["participant", "conversation_replies", conversationId], queryFn: () => @@ -330,9 +332,19 @@ export const useConversationQuery = ( ) => { return useQuery({ queryKey: ["participant", "conversation", projectId, conversationId], - queryFn: () => getParticipantConversationById(projectId ?? "", conversationId ?? ""), + queryFn: () => + getParticipantConversationById(projectId ?? "", conversationId ?? ""), enabled: !!conversationId && !!projectId, refetchInterval: 60000, + retry: (failureCount, error: AxiosError) => { + const status = error?.response?.status; + // Don't retry if conversation is deleted + if (status && [404, 403, 410].includes(status as number)) { + return false; + } + + return failureCount < 3; + }, }); }; @@ -346,4 +358,4 @@ export const useConversationChunksQuery = ( getParticipantConversationChunks(projectId ?? "", conversationId ?? ""), refetchInterval: 60000, }); -}; \ No newline at end of file +}; diff --git a/echo/frontend/src/routes/participant/ParticipantConversation.tsx b/echo/frontend/src/routes/participant/ParticipantConversation.tsx index 6d317abc..c402f4ce 100644 --- a/echo/frontend/src/routes/participant/ParticipantConversation.tsx +++ b/echo/frontend/src/routes/participant/ParticipantConversation.tsx @@ -57,8 +57,10 @@ import { ScrollToBottomButton } from "@/components/common/ScrollToBottom"; import { API_BASE_URL } from "@/config"; import useChunkedAudioRecorder from "@/components/participant/hooks/useChunkedAudioRecorder"; import { EchoErrorAlert } from "@/components/participant/EchoErrorAlert"; +import { AxiosError } from "axios"; const DEFAULT_REPLY_COOLDOWN = 120; // 2 minutes in seconds +const CONVERSATION_DELETION_STATUS_CODES = [404, 403, 410]; export const ParticipantConversationAudioRoute = () => { const { projectId, conversationId } = useParams(); @@ -164,17 +166,44 @@ export const ParticipantConversationAudioRoute = () => { // Monitor conversation status during recording - handle deletion mid-recording useEffect(() => { - if (isRecording && (conversationQuery.isError || !conversationQuery.data)) { - console.warn( - "Conversation deleted or became unavailable during recording", - ); - stopRecording(); - setConversationDeletedDuringRecording(true); + if (!isRecording) return; + + if ( + conversationQuery.isError && + !conversationQuery.isFetching && + !conversationQuery.isLoading + ) { + const error = conversationQuery.error as AxiosError; + const httpStatus = error?.response?.status; + + if ( + httpStatus && + CONVERSATION_DELETION_STATUS_CODES.includes(httpStatus) + ) { + console.warn( + "Conversation was deleted or is no longer accessible during recording", + { + status: httpStatus, + error: error?.response?.data || error?.message, + }, + ); + stopRecording(); + setConversationDeletedDuringRecording(true); + } else { + console.warn( + "Temporary error fetching conversation during recording - continuing", + { + status: httpStatus, + error: error?.message, + }, + ); + } } }, [ isRecording, conversationQuery.isError, - conversationQuery.data, + conversationQuery.isLoading, + conversationQuery.isFetching, stopRecording, ]); From 14f7f0cd6ffb6b85223810b3b6aa310e605e3659 Mon Sep 17 00:00:00 2001 From: Usama Date: Thu, 28 Aug 2025 10:10:12 +0000 Subject: [PATCH 2/5] - fixes --- .../routes/participant/ParticipantConversation.tsx | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/echo/frontend/src/routes/participant/ParticipantConversation.tsx b/echo/frontend/src/routes/participant/ParticipantConversation.tsx index c402f4ce..2dc0f2ab 100644 --- a/echo/frontend/src/routes/participant/ParticipantConversation.tsx +++ b/echo/frontend/src/routes/participant/ParticipantConversation.tsx @@ -182,20 +182,14 @@ export const ParticipantConversationAudioRoute = () => { ) { console.warn( "Conversation was deleted or is no longer accessible during recording", - { - status: httpStatus, - error: error?.response?.data || error?.message, - }, + { status: httpStatus, message: error?.message }, ); stopRecording(); setConversationDeletedDuringRecording(true); } else { console.warn( - "Temporary error fetching conversation during recording - continuing", - { - status: httpStatus, - error: error?.message, - }, + "Error fetching conversation during recording - continuing", + { status: httpStatus, message: error?.message }, ); } } @@ -204,6 +198,7 @@ export const ParticipantConversationAudioRoute = () => { conversationQuery.isError, conversationQuery.isLoading, conversationQuery.isFetching, + conversationQuery.error, stopRecording, ]); From ecb449d7e17641e62a618ce447b6437922684caa Mon Sep 17 00:00:00 2001 From: Usama Date: Thu, 28 Aug 2025 10:27:57 +0000 Subject: [PATCH 3/5] - fixes --- .../src/routes/participant/ParticipantConversation.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/echo/frontend/src/routes/participant/ParticipantConversation.tsx b/echo/frontend/src/routes/participant/ParticipantConversation.tsx index 2dc0f2ab..13113d78 100644 --- a/echo/frontend/src/routes/participant/ParticipantConversation.tsx +++ b/echo/frontend/src/routes/participant/ParticipantConversation.tsx @@ -57,7 +57,6 @@ import { ScrollToBottomButton } from "@/components/common/ScrollToBottom"; import { API_BASE_URL } from "@/config"; import useChunkedAudioRecorder from "@/components/participant/hooks/useChunkedAudioRecorder"; import { EchoErrorAlert } from "@/components/participant/EchoErrorAlert"; -import { AxiosError } from "axios"; const DEFAULT_REPLY_COOLDOWN = 120; // 2 minutes in seconds const CONVERSATION_DELETION_STATUS_CODES = [404, 403, 410]; @@ -173,7 +172,7 @@ export const ParticipantConversationAudioRoute = () => { !conversationQuery.isFetching && !conversationQuery.isLoading ) { - const error = conversationQuery.error as AxiosError; + const error = conversationQuery.error; const httpStatus = error?.response?.status; if ( From aaab4c8feaefcadc0bcdb5ff583c97c1a26d6d0e Mon Sep 17 00:00:00 2001 From: Usama Date: Thu, 28 Aug 2025 11:46:55 +0000 Subject: [PATCH 4/5] - increase retry count to 6 times --- echo/frontend/src/components/participant/hooks/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/echo/frontend/src/components/participant/hooks/index.ts b/echo/frontend/src/components/participant/hooks/index.ts index e07da89d..6dc6008c 100644 --- a/echo/frontend/src/components/participant/hooks/index.ts +++ b/echo/frontend/src/components/participant/hooks/index.ts @@ -343,7 +343,7 @@ export const useConversationQuery = ( return false; } - return failureCount < 3; + return failureCount < 6; }, }); }; From b811722247a97bff09b5a1aa26b452ef218a9e11 Mon Sep 17 00:00:00 2001 From: Usama Date: Thu, 28 Aug 2025 11:53:22 +0000 Subject: [PATCH 5/5] - upload chunks retry increased to 20 times --- echo/frontend/src/components/participant/hooks/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/echo/frontend/src/components/participant/hooks/index.ts b/echo/frontend/src/components/participant/hooks/index.ts index 6dc6008c..be1f74b9 100644 --- a/echo/frontend/src/components/participant/hooks/index.ts +++ b/echo/frontend/src/components/participant/hooks/index.ts @@ -56,7 +56,7 @@ export const useUploadConversationChunk = () => { return useMutation({ mutationFn: uploadConversationChunk, - retry: 10, + retry: 20, // When mutate is called: onMutate: async (variables) => { // Cancel any outgoing refetches