From 8d52bdf99de803a4a7a8d63336dc2204df290af5 Mon Sep 17 00:00:00 2001 From: Viktor Barzin Date: Mon, 9 Feb 2026 21:37:07 +0000 Subject: [PATCH] Fix stale task polling by keeping it always active alongside WebSocket MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Polling was disabled when wsConnected was true, but if the WS connected while workers hadn't been redeployed (no pub/sub messages flowing), the UI received no updates at all. Polling now always runs at 5s as the baseline. WebSocket provides faster real-time updates on top when available — the two coexist, last writer wins. --- frontend/src/components/TaskIndicator.tsx | 9 ++++----- frontend/src/constants/index.ts | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/frontend/src/components/TaskIndicator.tsx b/frontend/src/components/TaskIndicator.tsx index 140e45c..36afba1 100644 --- a/frontend/src/components/TaskIndicator.tsx +++ b/frontend/src/components/TaskIndicator.tsx @@ -134,11 +134,8 @@ export function TaskIndicator({ } }, [wsConnected, wsTasks, taskID]); - // ----- Polling fallback (only when WS is not connected) ----- + // ----- Polling (always active as baseline; WS provides faster updates on top) ----- useEffect(() => { - // If WS is connected, skip polling - if (wsConnected) return; - if (!user || !taskID) { setTaskStatus(null); setTaskResult(null); @@ -153,6 +150,8 @@ export function TaskIndicator({ setTaskResult(null); const pollTaskStatus = async () => { + // Skip this poll cycle if cancelled locally + if (cancelledRef.current) return true; try { const data = await fetchTaskStatus(user, taskID); const status = data.status as TaskStatus; @@ -214,7 +213,7 @@ export function TaskIndicator({ }, POLLING_INTERVALS.TASK_STATUS_MS); return () => clearInterval(interval); - }, [taskID, user, wsConnected]); + }, [taskID, user]); const handleCancel = async () => { if (!user || !taskID || isCancelling) return; diff --git a/frontend/src/constants/index.ts b/frontend/src/constants/index.ts index dc503aa..2cbfbf3 100644 --- a/frontend/src/constants/index.ts +++ b/frontend/src/constants/index.ts @@ -59,7 +59,7 @@ export const DEFAULT_FORM_VALUES = { // Polling intervals export const POLLING_INTERVALS = { - TASK_STATUS_MS: 30000, // 30 seconds (fallback when WebSocket is unavailable) + TASK_STATUS_MS: 5000, // 5 seconds } as const; // WebSocket paths