Repository navigation
Description
Description
Bug:
When using an Azure OpenAI deployment, a 429 (rate limit / quota exceeded) error with Retry-After: 0 (or retry-after-ms: 0) causes an infinite retry loop, making ~700 API calls in ~5 seconds before manual interruption.
Root Cause:
The session-level retry policy in packages/opencode/src/session/retry.ts has three contributing issues:
- policy() (line 176) — No maximum retry count. It retries indefinitely as long as retryable() returns true.
- delay() (line 35) — Converts Retry-After: 0 to a 0ms delay, triggering an immediate retry with no backoff.
- cap() (line 31) — Only enforces an upper bound on delay, not a minimum. cap(0) returns 0.
The HTTP-level retry in packages/llm/src/route/executor.ts:36-38 handles this correctly (MAX_RETRIES=2 with proper backoff), but the session-level retry wraps around it and overrides its behavior.
Prior Art:
At least 8 PRs attempted to fix this but were all auto-closed by the automated-pr-cleanup bot (30 days inactivity, <2 reactions):
- fix(session): cap retry schedule at RETRY_MAX_ATTEMPTS = 3 #26369 — feat/retry-max-attempts-cap
- fix(opencode): cap retry attempts at 5 to prevent infinite loops #29047 — retry attempts + timeout tweaks
- feat: add configurable max retry limit for SessionRetry #26676 — retry limit fix (closed by compliance bot in 2h)
- fix(session): retry network errors, cap at 3, add retry_exhausted status #28792 — retry cap
- fix: add retry circuit breaker and backoff cap to prevent infinite retry loops #17790, fix: add retry circuit breaker and backoff cap to prevent infinite retry loops #17668 — two attempts by same author
- fix(opencode): cap session retry attempts #30245 — retry limit
- feat(compaction): harden compaction system with breaker, retry, caps, and budget #20516 — retry cap
All share the same core fix: add a maximum retry attempt limit (3–5) to SessionRetry.policy().
Proposed Fix:
In packages/opencode/src/session/retry.ts:
- Add a maxAttempts parameter to policy() (defaulting to 3–5) that stops retrying after N attempts.
- Optionally, add a minimum floor to the delay (e.g., 100ms) to prevent immediate retries on zero-value Retry-After.
The change is ~5 lines, well-understood, and uncontroversial — it has consensus across 8 independent contributors.
Plugins
No response
OpenCode version
No response
Steps to reproduce
No response
Screenshot and/or share link
No response
Operating System
No response
Terminal
No response
Activity
github-actions commentedon Jul 15, 2026
This issue might be a duplicate of existing issues. Please check:
If none of these cover the Azure-specific
Retry-After: 0/ zero-delay edge case, please note that in the issue to help differentiate it.