Fix Gemini quota circuit-breaker: detect 'quota' in 429 body
Browse filesGemini sends retry-after:5 even for daily quota exhaustion, so the
old 'wait > 30' check never fired. Now detect 'quota' in the body
and circuit-break for 8 hours, stopping the retry loop immediately.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
724 unmodified lines72572672772872973073173273373473555 unmodified lines791792793794795796797798799800801724 unmodified lineswait = float(retry_after)except (ValueError, TypeError):wait = 5.0if wait > 30:self._rate_limited_until = time.monotonic() + waitlogger.warning(f"Gemini quota exhausted for {wait:.0f}s")return ""body = e.response.text[:200].replace("{", "(").replace("}", ")")logger.warning(f"Gemini 429: {body} β waiting {wait}s")await asyncio.sleep(wait)else:55 unmodified lineswait = float(retry_after)except (ValueError, TypeError):wait = 5.0if wait > 30:self._rate_limited_until = time.monotonic() + waitlogger.warning(f"Gemini quota exhausted for {wait:.0f}s")return {}body = e.response.text[:200].replace("{", "(").replace("}", ")")logger.warning(f"Gemini 429 (json): {body} β waiting {wait}s")await asyncio.sleep(wait)else:724 unmodified lines72572672772872973073173273373473573673773873974055 unmodified lines796797798799800801802803804805806807808809724 unmodified lineswait = float(retry_after)except (ValueError, TypeError):wait = 5.0body_raw = e.response.text or ""# Daily quota exhausted β Gemini sends retry-after:5 even for daily limits,# so detect via message body and circuit-break for 8 hours.if "quota" in body_raw.lower() or wait > 30:circuit_wait = max(wait, 28800) # 8 hoursself._rate_limited_until = time.monotonic() + circuit_waitbody = body_raw[:200].replace("{", "(").replace("}", ")")logger.warning(f"Gemini daily quota exhausted β circuit-breaking for {circuit_wait/3600:.1f}h: {body}")return ""body = body_raw[:200].replace("{", "(").replace("}", ")")logger.warning(f"Gemini 429: {body} β waiting {wait}s")await asyncio.sleep(wait)else:55 unmodified lineswait = float(retry_after)except (ValueError, TypeError):wait = 5.0body_raw = e.response.text or ""if "quota" in body_raw.lower() or wait > 30:circuit_wait = max(wait, 28800) # 8 hoursself._rate_limited_until = time.monotonic() + circuit_waitbody = body_raw[:200].replace("{", "(").replace("}", ")")logger.warning(f"Gemini daily quota exhausted β circuit-breaking for {circuit_wait/3600:.1f}h: {body}")return {}body = body_raw[:200].replace("{", "(").replace("}", ")")logger.warning(f"Gemini 429 (json): {body} β waiting {wait}s")await asyncio.sleep(wait)else:
src/soci/engine/llm.py+16-8