Skip to content

infinite retry loop on Azure 429 with Retry-After: 0 #37076

Description

@eriera1

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:

  1. policy() (line 176) — No maximum retry count. It retries indefinitely as long as retryable() returns true.
  2. delay() (line 35) — Converts Retry-After: 0 to a 0ms delay, triggering an immediate retry with no backoff.
  3. 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):

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions