From 2c8a55daebe9d777dfc7282d537d2c71d7087c40 Mon Sep 17 00:00:00 2001 From: Gage Krumbach Date: Fri, 16 Jan 2026 15:38:18 -0600 Subject: [PATCH] fix: disconnect EventSource when navigating away from session detail When navigating from session detail page to sessions list, the EventSource connection wasn't being cleaned up. This caused the connection to remain open and block the browser's connection pool (6 concurrent connections per domain), leading to hung network requests on subsequent page loads. The fix adds a cleanup function in the useEffect that calls aguiStream.disconnect() when the component unmounts, properly closing the EventSource connection. Fixes frontend hanging on navigation between session detail and session list. --- .../app/projects/[name]/sessions/[sessionName]/page.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/components/frontend/src/app/projects/[name]/sessions/[sessionName]/page.tsx b/components/frontend/src/app/projects/[name]/sessions/[sessionName]/page.tsx index 355b08ae..e75b2a74 100644 --- a/components/frontend/src/app/projects/[name]/sessions/[sessionName]/page.tsx +++ b/components/frontend/src/app/projects/[name]/sessions/[sessionName]/page.tsx @@ -230,7 +230,14 @@ export default function ProjectSessionDetailPage({ hasConnectedRef.current = true; aguiConnectRef.current(); } - }, [projectName, sessionName]); + + // CRITICAL: Disconnect when navigating away to prevent hung connections + return () => { + console.log('[Session Detail] Unmounting, disconnecting AG-UI stream'); + aguiStream.disconnect(); + hasConnectedRef.current = false; + }; + }, [projectName, sessionName, aguiStream]); // Auto-send initial prompt (handles session start, workflow activation, restarts) // AG-UI pattern: Client (or backend) initiates runs via POST /agui/run