Summary
The LLM provider integration lacks retry logic for transient API errors (rate limits, temporary failures), treating all errors as permanent failures.
Location
packages/opencode/src/provider/provider.ts (overall architecture)
packages/opencode/src/provider/sdk/copilot/openai-compatible-error.ts
Issue
The provider SDK:
- Has no exponential backoff for 429 (rate limit) responses
- Doesn't parse or respect `Retry-After` headers
- Treats all API errors as permanent failures
- Has no retry budget or max attempts configuration
- Error structures don't implement `isRetryable` checks
// Current error handling doesn't distinguish retryable from permanent errors
const errorStructure = config.errorStructure ?? defaultOpenAICompatibleErrorStructure
Impact
- Severity: Medium
- Type: Reliability
- Effect:
- Rate limit errors immediately fail instead of backing off
- Temporary network issues cause permanent failures
- Higher error rates during API instability
Suggested Fix
- Add retry configuration to provider options:
interface ProviderRetryConfig {
maxAttempts?: number
initialDelayMs?: number
maxDelayMs?: number
retryableStatusCodes?: number[]
}
- Implement exponential backoff with jitter:
async function fetchWithRetry(url, options, retryConfig) {
let attempt = 0
while (attempt < retryConfig.maxAttempts) {
try {
const response = await fetch(url, options)
if (response.status === 429 || response.status >= 500) {
const retryAfter = response.headers.get('Retry-After')
const delay = retryAfter
? parseInt(retryAfter) * 1000
: calculateBackoff(attempt, retryConfig)
await sleep(delay)
attempt++
continue
}
return response
} catch (e) {
if (!isRetryableError(e) || attempt >= retryConfig.maxAttempts - 1) throw e
await sleep(calculateBackoff(attempt, retryConfig))
attempt++
}
}
}
- Add `isRetryable` to error structures to distinguish between:
- Rate limit (429) - retry with backoff
- Server error (5xx) - retry with backoff
- Client error (4xx except 429) - don't retry
- Network error - retry with backoff
Summary
The LLM provider integration lacks retry logic for transient API errors (rate limits, temporary failures), treating all errors as permanent failures.
Location
packages/opencode/src/provider/provider.ts(overall architecture)packages/opencode/src/provider/sdk/copilot/openai-compatible-error.tsIssue
The provider SDK:
Impact
Suggested Fix