Skip to content

Comments

feat: add timeouts, retry logic, and improved error handling#80

Closed
whereisfarukk wants to merge 2 commits intomainfrom
faruk/max-retry
Closed

feat: add timeouts, retry logic, and improved error handling#80
whereisfarukk wants to merge 2 commits intomainfrom
faruk/max-retry

Conversation

@whereisfarukk
Copy link
Collaborator

  • Model-specific timeouts for chat completions (fixes fast/auto model timeouts)
  • Retry logic with exponential backoff for network errors
  • Centralized error handling
  • Remove console logs for production

…ompletions

- Add centralized error handling with handleRequestError() method
- Implement model-specific timeouts for chat completions (5min for fast/auto, 3min for pro)
- Add retry logic with exponential backoff for transient network errors
- Remove console logging statements for production readiness
- Simplify error handling while maintaining functionality

Fixes timeout issues with vlmrun-orion-1:fast and vlmrun-orion-1:auto models
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @whereisfarukk, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the stability and resilience of API interactions by introducing intelligent timeout management, implementing a retry strategy for network fluctuations, and centralizing error reporting. These changes aim to reduce failures due to temporary network issues or long-running model responses, ultimately providing a more robust user experience.

Highlights

  • Model-Specific Timeouts: Implemented dynamic timeouts for chat completion requests, providing longer durations (up to 5 minutes) for 'fast' and 'auto' models to prevent premature timeouts.
  • Retry Logic with Exponential Backoff: Added robust retry mechanisms with exponential backoff for transient network errors (e.g., ETIMEDOUT, ECONNRESET) to improve the reliability of API calls.
  • Centralized Error Handling: Introduced a dedicated private method, handleRequestError, to standardize the processing and reporting of API errors, ensuring consistent and informative error messages.
  • Code Cleanup: Removed console.log statements from production code, contributing to a cleaner and more efficient codebase.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

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

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 several important reliability improvements: model-specific timeouts, retry logic for network errors, and centralized error handling. The changes are well-structured and significantly improve the client's resilience.

My review includes a couple of suggestions for improvement:

  • In VlmRunClient.ts, the timeout logic can be made more robust by using endsWith instead of includes for model name checks, and by using constants for timeout values to improve maintainability.
  • The retry logic's backoff is currently linear, not exponential as commented. I've suggested a fix to align the implementation with the comment, which is important for handling transient errors effectively.

Comment on lines +181 to +185
if (data.model.includes(':fast') || data.model.includes(':auto')) {
timeout = 300000; // 5 minutes for fast/auto
} else {
timeout = 180000; // 3 minutes for pro
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Using includes() to check for model types can be brittle as it can lead to partial matches (e.g., a model named not-so-fast would incorrectly match). Using endsWith() is more robust for checking model suffixes.

Additionally, the timeout values (60000, 300000, 180000) are magic numbers. Consider defining them as named constants at the top of the file for improved readability and maintainability, for example:

const DEFAULT_TIMEOUT_MS = 60 * 1000;
const CHAT_COMPLETION_FAST_AUTO_TIMEOUT_MS = 5 * 60 * 1000;
const CHAT_COMPLETION_PRO_TIMEOUT_MS = 3 * 60 * 1000;
Suggested change
if (data.model.includes(':fast') || data.model.includes(':auto')) {
timeout = 300000; // 5 minutes for fast/auto
} else {
timeout = 180000; // 3 minutes for pro
}
if (data.model.endsWith(':fast') || data.model.endsWith(':auto')) {
timeout = 300000; // 5 minutes for fast/auto
} else {
timeout = 180000; // 3 minutes for pro
}

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.

1 participant