Skip to content

feat: implement request retry mechanism for provider requests#8699

Open
Soulter wants to merge 1 commit into
masterfrom
feat--llm-provider-retry
Open

feat: implement request retry mechanism for provider requests#8699
Soulter wants to merge 1 commit into
masterfrom
feat--llm-provider-retry

Conversation

@Soulter

@Soulter Soulter commented Jun 9, 2026

Copy link
Copy Markdown
Member

Modifications / 改动点

  • This is NOT a breaking change. / 这不是一个破坏性变更。

Screenshots or Test Results / 运行截图或测试结果


Checklist / 检查清单

  • 😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
    / 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。

  • 👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
    / 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”

  • 🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in requirements.txt and pyproject.toml.
    / 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到 requirements.txtpyproject.toml 文件相应位置。

  • 😮 My changes do not introduce malicious code.
    / 我的更改没有引入恶意代码。

Summary by Sourcery

Introduce a shared retry mechanism for transient provider request failures and apply it across major LLM providers.

New Features:

  • Add a generic asynchronous retry utility for provider requests with exponential backoff and configurable rate-limit handling.

Enhancements:

  • Wrap OpenAI, Gemini, and Anthropic model listing and generation/streaming calls with the shared retry utility to improve resilience to transient network and server errors.

Tests:

  • Add unit tests verifying that OpenAI, Gemini, and Anthropic providers retry model listing after transient connection failures.

@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. area:provider The bug / feature is about AI Provider, Models, LLM Agent, LLM Agent Runner. labels Jun 9, 2026

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • The retry_provider_request_context helper only retries failures in __aenter__ and not errors that occur while iterating/using the stream; if the intent is to make streaming calls more robust, consider whether you also want a retry strategy around mid-stream failures or add a brief comment clarifying that only connection/setup errors are retried.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `retry_provider_request_context` helper only retries failures in `__aenter__` and not errors that occur while iterating/using the stream; if the intent is to make streaming calls more robust, consider whether you also want a retry strategy around mid-stream failures or add a brief comment clarifying that only connection/setup errors are retried.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a centralized request retry mechanism using the tenacity library to handle transient errors and rate limits for LLM provider requests. It adds a new request_retry.py module and integrates it into the Anthropic, Gemini, and OpenAI provider sources to retry queries, streams, and model listing requests. Additionally, corresponding unit tests have been added to verify the retry behavior under transient connection failures. I have no feedback to provide as there are no review comments to address.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

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

Labels

area:provider The bug / feature is about AI Provider, Models, LLM Agent, LLM Agent Runner. size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant