Fix AI caller hanging on 'thinking...' indefinitely

- Add 30s timeout to all frontend fetch calls (safeFetch)
- Add 20s asyncio.timeout around lock+LLM in chat, ai-respond, auto-respond
- Reduce OpenRouter timeout from 60s to 25s
- Reduce Inworld TTS timeout from 60s to 25s
- Return graceful fallback responses on timeout instead of hanging

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-06 21:16:15 -07:00
parent cac80a4b52
commit b3fb3b1127
4 changed files with 83 additions and 59 deletions

View File

@@ -17,17 +17,26 @@ let sounds = [];
// --- Safe JSON parsing ---
async function safeFetch(url, options = {}) {
const res = await fetch(url, options);
if (!res.ok) {
async function safeFetch(url, options = {}, timeoutMs = 30000) {
const controller = new AbortController();
const timer = setTimeout(() => controller.abort(), timeoutMs);
try {
const res = await fetch(url, { ...options, signal: controller.signal });
clearTimeout(timer);
if (!res.ok) {
const text = await res.text();
let detail = text;
try { detail = JSON.parse(text).detail || text; } catch {}
throw new Error(detail);
}
const text = await res.text();
let detail = text;
try { detail = JSON.parse(text).detail || text; } catch {}
throw new Error(detail);
if (!text) return {};
return JSON.parse(text);
} catch (err) {
clearTimeout(timer);
if (err.name === 'AbortError') throw new Error('Request timed out');
throw err;
}
const text = await res.text();
if (!text) return {};
return JSON.parse(text);
}