Skip to content

fix(opencode): use exponential backoff when retry-after-ms is zero#38697

Open
eriera1 wants to merge 2 commits into
anomalyco:devfrom
eriera1:fix-retry-loop
Open

fix(opencode): use exponential backoff when retry-after-ms is zero#38697
eriera1 wants to merge 2 commits into
anomalyco:devfrom
eriera1:fix-retry-loop

Conversation

@eriera1

@eriera1 eriera1 commented Jul 24, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #37076

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

When Azure OpenAI returns a 429 with retry-after-ms: 0 (which it always does for sliding-window TPM exhaustion), the session-level retry loop produce a non-capped retry storm.

This fix:

  • When retry-after-ms is 0, falls back to exponential backoff (2s, 4s, 8s, 16s, 32s) instead of using the header value directly
  • Caps retries at RETRY_MAX_ATTEMPTS = 5 to prevent infinite retry storms
  • Non-zero retry-after-ms values are still trusted (all other providers)

How did you verify your code works?

  • All 33 existing retry tests pass unchanged
  • Tested against a personal Azure DeepSeek-V4-Flash deployment in Azure: confirmed retry-after-ms: 0 in every 429 response via structured logging, and that the exponential backoff produces growing delays instead of constant 1s waits.
  • Typecheck passes in packages/opencode

Screenshots / recordings

If this is a UI change, please include a screenshot or recording.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

I found a related PR that may be worth reviewing for overlap:

Related PR:

The current PR #38697 appears to be the primary implementation for this specific issue (handling retry-after-ms: 0).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant