fix: add XHR timeout to prevent UI spinning forever

60s timeout for standard tools, 5 min for AI tools. Shows a user-facing
error message instead of spinning indefinitely if the server hangs.
This commit is contained in:
Siddharth Kumar Sah
2026-04-04 14:06:41 +08:00
parent 5cd2b864bd
commit dae27f4d55
+15 -1
View File
@@ -141,6 +141,9 @@ export function useToolProcessor(toolId: string) {
const xhr = new XMLHttpRequest();
xhrRef.current = xhr;
// Timeout: 60s for fast tools, 5 min for AI tools
xhr.timeout = isAiTool ? 300_000 : 60_000;
// For AI tools: upload = 0-15%, processing = 15-100% (continuous, no reset)
// For fast tools: upload = 0-100%, processing = brief 100% hold
const UPLOAD_WEIGHT = isAiTool ? 15 : 100;
@@ -206,7 +209,18 @@ export function useToolProcessor(toolId: string) {
eventSourceRef.current.close();
eventSourceRef.current = null;
}
setError("Network error check your connection");
setError("Network error - check your connection");
setProcessing(false);
setProgress(IDLE_PROGRESS);
};
xhr.ontimeout = () => {
if (elapsedRef.current) clearInterval(elapsedRef.current);
if (eventSourceRef.current) {
eventSourceRef.current.close();
eventSourceRef.current = null;
}
setError("Request timed out - the server may be overloaded. Try again.");
setProcessing(false);
setProgress(IDLE_PROGRESS);
};