From f524880c94cc671a4e85ebdccb6febbcc4feb2a7 Mon Sep 17 00:00:00 2001 From: Isaac Sanchez-Hawkins <266845420+isanchez404@users.noreply.github.com> Date: Fri, 8 May 2026 16:34:03 -0400 Subject: [PATCH] fix(terminal): track SSE opens per attempt (#1171) Co-authored-by: Isaac Sanchez --- packages/ui/src/lib/terminalApi.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/ui/src/lib/terminalApi.ts b/packages/ui/src/lib/terminalApi.ts index 2a2df802..99c38835 100644 --- a/packages/ui/src/lib/terminalApi.ts +++ b/packages/ui/src/lib/terminalApi.ts @@ -786,7 +786,6 @@ const connectTerminalStreamViaSse = ( let retryTimeout: ReturnType | null = null; let connectionTimeoutId: ReturnType | null = null; let isClosed = false; - let hasDispatchedOpen = false; let terminalExited = false; const clearTimeouts = () => { @@ -850,20 +849,21 @@ const connectTerminalStreamViaSse = ( } eventSource = new EventSource(`/api/terminal/${sessionId}/stream`); + let opened = false; connectionTimeoutId = setTimeout(() => { - if (!hasDispatchedOpen && eventSource?.readyState !== EventSource.OPEN) { + if (!opened && eventSource?.readyState !== EventSource.OPEN) { eventSource?.close(); handleError(new Error('Connection timeout'), false); } }, connectionTimeout); eventSource.onopen = () => { - if (hasDispatchedOpen) { + if (opened) { return; } - hasDispatchedOpen = true; + opened = true; retryCount = 0; clearTimeouts(); onEvent({ type: 'connected' });