From e61d3a06b2840940b16dd6816cb5f4619f0f3651 Mon Sep 17 00:00:00 2001 From: Danny Avila Date: Fri, 12 Dec 2025 01:15:25 -0500 Subject: [PATCH] fix: Prevent memory leaks in useResumableSSE by clearing handler maps on stream completion and cleanup --- client/src/hooks/SSE/useResumableSSE.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/client/src/hooks/SSE/useResumableSSE.ts b/client/src/hooks/SSE/useResumableSSE.ts index ccfe406b1c..fd5a6f31d4 100644 --- a/client/src/hooks/SSE/useResumableSSE.ts +++ b/client/src/hooks/SSE/useResumableSSE.ts @@ -151,6 +151,8 @@ export default function useResumableSSE( setIsSubmitting(false); setShowStopButton(false); } + // Clear handler maps on stream completion to prevent memory leaks + clearStepMaps(); (startupConfig?.balance?.enabled ?? false) && balanceQuery.refetch(); sse.close(); setStreamId(null); @@ -369,6 +371,7 @@ export default function useResumableSSE( contentHandler, resetContentHandler, syncStepMessage, + clearStepMaps, messageHandler, errorHandler, setIsSubmitting, @@ -476,6 +479,8 @@ export default function useResumableSSE( sseRef.current.close(); sseRef.current = null; } + // Clear handler maps to prevent memory leaks and stale state + clearStepMaps(); // Reset UI state on cleanup - useResumeOnLoad will restore if needed setIsSubmitting(false); setShowStopButton(false);