Repository navigation
fix(http_proxy): fix RoundRobinStrategy always selecting first instance - #5879
axsapronov wants to merge 3 commits into
Conversation
The strategy compared ModelInstance objects to detect list changes, but each request passes new objects so the comparison always returned True. This caused the itertools.cycle iterator to be recreated on every call, always returning the first instance.
Summary of ChangesHello, 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 addresses a bug in the RoundRobinStrategy where the load balancer would incorrectly reset its state on every request. By switching from object-based comparison to ID-based comparison, the strategy now correctly maintains the round-robin sequence even when new object instances are provided for the same set of underlying resources. Highlights
New Features🧠 You can now enable Memory (public preview) 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 AssistThe 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
Customization To customize the 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 Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. 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. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request updates the RoundRobinStrategy to track instance IDs (_instance_ids) instead of full ModelInstance objects (_instance_lists), preventing the round-robin iterator from resetting when identical instances are passed as new Python objects. It also introduces a comprehensive test suite for the strategy. The review feedback highlights a critical issue: caching the original ModelInstance objects in itertools.cycle can lead to returning stale objects if their attributes (such as port or IP) change. The reviewer suggests cycling the instance IDs instead and retrieving the fresh object from the input list, as well as updating the tests to verify that updated attributes are correctly returned.
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.
…rategy The iterator now cycles over instance IDs instead of cached ModelInstance objects. This prevents returning stale objects when instance attributes (e.g. worker_ip, port) change between calls. Also adds a test verifying that updated attributes are reflected in the returned instance.
* fix(http_proxy): keep round-robin position across requests RoundRobinStrategy compared the ModelInstance objects it received on the previous call with the ones passed now. Every request builds fresh objects from the database, and any field that moved in between (heartbeat data, restart counters, state) makes that comparison fail, so the cycle iterator was recreated and started from the first instance again. Under bursty load this sends most requests to the first replica; on a two-replica reranker we measured splits of 27/10 and 21/16. Track the sorted instance ids instead, rebuild the cycle only when the membership changes, and return the instance object from the current list so callers never get a stale object. Same approach as #5879, which was closed without being merged. Signed-off-by: Baki Burak Ogun <[email protected]> * fix(http_proxy): look up the selected instance without a generator Wrap the long test line for black and replace the next() call on a generator expression with a dict lookup so no StopIteration can escape the coroutine. Signed-off-by: Baki Burak Ogun <[email protected]> --------- Signed-off-by: Baki Burak Ogun <[email protected]>
The strategy compared ModelInstance objects to detect list changes, but each request passes new objects so the comparison always returned True. This caused the itertools.cycle iterator to be recreated on every call, always returning the first instance.
How it works now:
Replica №1 -
Running: 0 reqsReplica №2 -
Running: 2 reqs