From dd4c4c8c0fdc108a23342b3c24ed70545b5b157a Mon Sep 17 00:00:00 2001 From: Hitonabi Date: Sun, 28 Jun 2026 02:02:50 +0200 Subject: [PATCH] Fix: EL-Retry bei 429 (Free-Tier-Concurrency) + index.html no-cache (immer frisches Bundle) 5 parallele EL-Calls -> 1x 502 (Concurrency-Limit). elevenlabs_tts retryt jetzt 429/5xx mit Backoff. index.html wird nicht mehr gecacht -> nach Deploy kein altes Bundle mehr. Co-Authored-By: Claude Opus 4.8 --- backend/app.py | 3 ++- voice_service/app.py | 28 ++++++++++++++++++++-------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/backend/app.py b/backend/app.py index 723aaa5..d112fed 100644 --- a/backend/app.py +++ b/backend/app.py @@ -86,6 +86,7 @@ if FRONTEND_DIST.exists(): index = FRONTEND_DIST / "index.html" if index.exists(): - return FileResponse(index) + # index.html nie cachen → Browser zieht nach jedem Deploy das aktuelle (gehashte) Bundle. + return FileResponse(index, headers={"Cache-Control": "no-cache, must-revalidate"}) return {"detail": "frontend not built"} diff --git a/voice_service/app.py b/voice_service/app.py index a0ee86f..1dfbadf 100644 --- a/voice_service/app.py +++ b/voice_service/app.py @@ -233,14 +233,26 @@ def elevenlabs_tts(text: str, voice: str) -> bytes: data=body, headers={"xi-api-key": key, "Content-Type": "application/json", "Accept": "audio/mpeg"}, ) - try: - with urllib.request.urlopen(req, timeout=60) as r: - return r.read() - except urllib.error.HTTPError as e: - detail = e.read()[:200].decode("utf-8", "replace") - raise HTTPException(502, f"ElevenLabs-Fehler {e.code}: {detail}") - except urllib.error.URLError as e: - raise HTTPException(502, f"ElevenLabs nicht erreichbar: {e}") + import time + # Free-Tier hat ein Concurrency-Limit → parallele Sätze geben 429. Retry mit Backoff fängt das ab. + last = "" + for attempt in range(4): + try: + with urllib.request.urlopen(req, timeout=60) as r: + return r.read() + except urllib.error.HTTPError as e: + last = f"{e.code}: {e.read()[:200].decode('utf-8', 'replace')}" + if e.code in (429, 500, 502, 503, 529) and attempt < 3: + time.sleep(0.5 * (attempt + 1)) + continue + raise HTTPException(502, f"ElevenLabs-Fehler {last}") + except urllib.error.URLError as e: + last = str(e) + if attempt < 3: + time.sleep(0.5 * (attempt + 1)) + continue + raise HTTPException(502, f"ElevenLabs nicht erreichbar: {last}") + raise HTTPException(502, f"ElevenLabs-Fehler (nach Retries): {last}") def elevenlabs_list() -> list[dict]: