Principle:416rehman DeepZero Adaptive Retry Backoff
| Knowledge Sources | |
|---|---|
| Domains | Retry_Logic, Distributed_Systems |
| Last Updated | 2026-10-27 00:00 GMT |
Overview
A retry strategy that classifies errors into roles (rate-limit, context-window, non-retryable, retryable) and applies role-specific backoff policies, decaying backoff on success and escalating on rate limits.
Description
Adaptive retry backoff addresses the problem of retrying unreliable external services without wasting resources on unrecoverable errors. The key insight is that not all errors are equal:
- Rate-limit errors are transient by definition—the service is throttling you. Retry with exponential backoff (doubling the wait each time) gives the service time to recover.
- Context-window errors are permanent for this request—the prompt is too long. Retrying wastes a call; the provider raises immediately.
- Non-retryable errors (auth failures, invalid input) will not improve with retries. Surface immediately.
- Retryable errors (network, server 5xx) are transient but not rate-related. Retry with standard exponential backoff (2^attempt).
The adaptive aspect is the backoff decay on success. After a successful call, the backoff timer decays toward the initial value (multiplied by a decay factor). This means:
- A burst of rate-limit errors escalates backoff quickly (doubling each time).
- A subsequent success reduces backoff, so the next rate-limit starts from a lower wait.
- In steady-state with occasional rate limits, backoff oscillates near the initial value rather than staying maxed out.
The error roles are declared by the backend, not hardcoded in the retry loop. This is the open/closed principle: adding a new backend means declaring its error classes, not modifying the retry logic.
Usage
Use this pattern when:
- Calling external services with rate limits (LLM APIs, web APIs)
- Different error types require different retry strategies
- Backoff should adapt to success/failure patterns, not stay fixed
- The retry logic should be backend-agnostic
Theoretical Basis
# Abstract retry loop (NOT real implementation)
def complete_with_retry(backend, messages, max_retries, initial_backoff, max_backoff, decay):
backoff = initial_backoff
for attempt in range(max_retries + 1):
try:
result = backend.raw_complete(messages)
backoff = max(initial_backoff, backoff * decay) # decay on success
return result
except backend.rate_limit_error:
backoff = min(max_backoff, backoff * 2.0) # escalate
sleep(backoff)
except backend.context_window_error:
raise # will not improve
except backend.non_retryable_errors:
raise # will not improve
except backend.retryable_errors:
sleep(min(max_backoff, 2 ** attempt)) # standard exponential