Skip to content

[model-gateway] add retry and circuit breaker support to gRPC routers#15585

Merged
slin1237 merged 1 commit intomainfrom
refactor-n/4
Dec 22, 2025
Merged

[model-gateway] add retry and circuit breaker support to gRPC routers#15585
slin1237 merged 1 commit intomainfrom
refactor-n/4

Conversation

@slin1237
Copy link
Copy Markdown
Collaborator

  • Add circuit breaker outcome recording to WorkerSelection in context.rs
  • Record outcomes in request_execution.rs after gRPC calls complete
  • Add RetryExecutor with exponential backoff to GrpcRouter and GrpcPDRouter
  • Use is_retryable_status for 408, 429, 500, 502, 503, 504 status codes
  • Record retry metrics with proper worker labels (WORKER_REGULAR, WORKER_PREFILL, WORKER_DECODE)
  • Consistent with HTTP router retry patterns

Checklist

- Add circuit breaker outcome recording to WorkerSelection in context.rs
- Record outcomes in request_execution.rs after gRPC calls complete
- Add RetryExecutor with exponential backoff to GrpcRouter and GrpcPDRouter
- Use is_retryable_status for 408, 429, 500, 502, 503, 504 status codes
- Record retry metrics with proper worker labels (WORKER_REGULAR, WORKER_PREFILL, WORKER_DECODE)
- Consistent with HTTP router retry patterns
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @slin1237, 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 improves the robustness and reliability of the model-gateway's gRPC communication by integrating comprehensive retry and circuit breaker support. It introduces an exponential backoff retry strategy for gRPC requests across both standard and prefill/decode routers, coupled with outcome recording for worker selections to inform circuit breaking. These changes ensure that transient network issues or service unavailability are handled gracefully, reducing user-facing errors and providing clearer insights into system health through new metrics.

Highlights

  • Circuit Breaker Outcome Recording: Implemented mechanisms to record circuit breaker outcomes within the WorkerSelection logic in context.rs and request_execution.rs after gRPC calls complete, enabling better fault tolerance.
  • Retry Mechanism for gRPC Routers: Added RetryExecutor with exponential backoff to both GrpcRouter and GrpcPDRouter to automatically retry failed gRPC requests, enhancing system resilience.
  • Defined Retryable Status Codes: Configured the retry logic to consider specific HTTP status codes (408, 429, 500, 502, 503, 504) as retryable, aligning with common transient error patterns.
  • Enhanced Retry Metrics: Integrated detailed retry metrics recording with appropriate worker labels (WORKER_REGULAR, WORKER_PREFILL, WORKER_DECODE) to provide better observability into retry behavior and performance.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

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
Copy Markdown
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 effectively introduces retry and circuit breaker mechanisms to the gRPC routers, enhancing the resilience of the model gateway. The changes are well-structured, with clear separation of concerns: circuit breaker outcomes are recorded in the execution stage, and retry logic is encapsulated within RetryExecutor in the router implementations. The metric recording for retries and backoffs is also a great addition for observability.

My main feedback is regarding code duplication in both GrpcPDRouter and GrpcRouter where the retry logic is applied. I've left specific suggestions on how to refactor this into helper methods to improve maintainability. Overall, this is a solid contribution to making the gateway more robust.

@slin1237 slin1237 merged commit 122c250 into main Dec 22, 2025
71 checks passed
@slin1237 slin1237 deleted the refactor-n/4 branch December 22, 2025 01:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant