Skip to content

Commit 73ed7eb

Browse files
fix: add fallback polling for missed WebSocket events
The initial fix only handled the case where processing was already complete on initial page load. This adds a 5-second polling fallback that re-fetches batch summary to detect completion when WebSocket events are missed (e.g., all harmful content files processed before WebSocket connected). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 3f1b99c commit 73ed7eb

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

src/frontend/src/pages/modernizationPage.tsx

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,6 +1013,43 @@ useEffect(() => {
10131013
return () => clearInterval(checkInactivity);
10141014
}, [lastActivityTime, files, allFilesCompleted, updateSummaryStatus, navigate, batchId]);
10151015

1016+
// Fallback polling: periodically re-fetch batch summary to catch cases where
1017+
// WebSocket events were missed (e.g., all files were harmful and processed
1018+
// before WebSocket connected). Polls every 5 seconds until all files are done.
1019+
useEffect(() => {
1020+
if (allFilesCompleted || !batchId || hasNavigatedRef.current) return;
1021+
1022+
const pollInterval = setInterval(async () => {
1023+
if (hasNavigatedRef.current || allFilesCompleted) {
1024+
clearInterval(pollInterval);
1025+
return;
1026+
}
1027+
try {
1028+
const data = await fetchBatchSummary(batchId);
1029+
if (!data) return;
1030+
1031+
const batchTerminal = ["completed", "failed"].includes(data.status?.toLowerCase() || "");
1032+
const allTerminal = data.files.every((file: any) =>
1033+
["completed", "failed", "error"].includes(file.status?.toLowerCase() || "")
1034+
);
1035+
1036+
if (batchTerminal || allTerminal) {
1037+
console.log("Fallback poll detected batch completion, navigating to batch view");
1038+
clearInterval(pollInterval);
1039+
setAllFilesCompleted(true);
1040+
if (!hasNavigatedRef.current) {
1041+
hasNavigatedRef.current = true;
1042+
navigate(`/batch-view/${batchId}`);
1043+
}
1044+
}
1045+
} catch (err) {
1046+
console.error("Fallback poll error:", err);
1047+
}
1048+
}, 5000);
1049+
1050+
return () => clearInterval(pollInterval);
1051+
}, [batchId, allFilesCompleted, navigate]);
1052+
10161053

10171054
useEffect(() => {
10181055
console.log('Current files state:', files);

0 commit comments

Comments
 (0)