Heuristic:ARCANGEL0 EVA Transient Provider Retry
| Knowledge Sources | |
|---|---|
| Domains | LLMs, Optimization, Debugging |
| Last Updated | 2026-10-29 12:00 GMT |
Overview
Retry transient LLM provider errors (429 rate limits, 5xx server errors, connection failures) up to 10 times with a 10-second delay between attempts.
Description
When an LLM provider returns a transient error, Mitsu automatically retries the request rather than failing immediately. Transient errors include HTTP 429 (rate limited), HTTP 500-599 (server errors), and connection-level failures ("could not reach the provider", "provider stream ended unexpectedly", "provider returned an unreadable streamed response"). The retry loop runs up to 11 iterations (10 retries) with a fixed 10-second delay between each attempt. The operator is notified via `api_retry` and `api_retrying` events during the backoff.
Usage
Apply this heuristic when LLM provider requests fail with rate-limit or server errors. The retry logic is built into `run_agent_turn` and activates automatically — no configuration is needed. Non-transient errors (e.g., 400 Bad Request, 401 Unauthorized) fail immediately without retry.
The Insight (Rule of Thumb)
- Action: Let `run_agent_turn` retry transient provider errors automatically.
- Value: Maximum 10 retries, 10-second delay between attempts (fixed, not exponential).
- Trade-off: Adds up to 100 seconds of latency for persistent transient failures, but avoids failing on temporary provider hiccups.
- Compatibility: Works with all providers (OpenAI, Anthropic, OpenRouter, Ollama, etc.).
Reasoning
Cloud LLM providers commonly return 429 rate-limit responses during peak usage and 5xx errors during outages. A fixed 10-second delay is simple and effective for most rate-limit windows. The 10-retry cap prevents infinite loops while giving the provider enough time to recover. Non-transient errors (4xx excluding 429) are not retried because they indicate configuration or authentication problems that won't resolve with retry.
Code Evidence
Retry loop from `agents/runtime.py:289-333`:
for retry_number in range(11):
try:
# ... request logic ...
break
except ProviderRequestError as error:
if retry_number >= 10 or not _is_transient_provider_error(error):
raise
retry_attempt = retry_number + 1
yield AgentEvent("api_retry", {
"attempt": retry_attempt, "max_attempts": 10, "delay": 10, "error": str(error),
})
await asyncio.sleep(10)
yield AgentEvent("api_retrying", {"attempt": retry_attempt})
Transient error detection from `agents/runtime.py:456-470`:
def _is_transient_provider_error(error: ProviderRequestError) -> bool:
message = str(error).casefold()
if "provider request failed (429)" in message:
return True
for status in range(500, 600):
if f"provider request failed ({status})" in message:
return True
return any(
marker in message
for marker in (
"could not reach the provider",
"provider stream ended unexpectedly",
"provider returned an unreadable streamed response",
)
)