Skip to content

Conversation

SYED-M-HUSSAIN
Copy link
Contributor

PR Description
This PR fixes the retry logic in the LangChain Google integration to respect the retry_delay field returned by the Gemini API in ResourceExhausted (429) errors. Previously, the retry mechanism ignored the server-suggested delay, causing premature retries and quota issues. The fix introduces a custom wait strategy that uses the server-provided delay when available and falls back to exponential backoff otherwise. This aligns client retry behavior with Gemini’s rate limiting guidance, improving reliability and reducing quota exhaustion errors.


Relevant issues


Type
🐛 Bug Fix


Changes (optional)

  • Added wait_with_server_retry_delay custom wait strategy class
  • Updated _create_retry_decorator to use this custom wait handler
  • Retains fallback to exponential backoff if no retry_delay present
  • Added logging to show when server delay is respected

@SYED-M-HUSSAIN
Copy link
Contributor Author

Hey @lkuligin , can you please merge this, thanks.

@lkuligin
Copy link
Collaborator

@SYED-M-HUSSAIN linter is failing

Copy link
Collaborator

@mdrxy mdrxy left a comment

Choose a reason for hiding this comment

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

Looks fine but please answer questions and run linting so that CI passes

"""


def _create_retry_decorator(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we remove the params?

@mdrxy mdrxy changed the title genai : fixed respect retry_delay from Gemini 429 ResourceExhausted error in retry logic fix(genai) : respect retry_delay from Gemini 429 ResourceExhausted Sep 17, 2025
@mdrxy mdrxy added the genai label Sep 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

genai: retry_delay is not used to guide retry interval
3 participants