Skip to content

feat: implement credential-based round-robin for gemini-cli#1663

Merged
luispater merged 1 commit intorouter-for-me:devfrom
rensumo:main
Feb 23, 2026
Merged

feat: implement credential-based round-robin for gemini-cli#1663
luispater merged 1 commit intorouter-for-me:devfrom
rensumo:main

Conversation

@rensumo
Copy link

@rensumo rensumo commented Feb 21, 2026

The previous code applied flat round-robin across all virtual auths (including projects from different credentials) in a fixed order, causing the same credential to be used consecutively in bulk, resulting in uneven load distribution.

…uths

Changes the RoundRobinSelector to use two-level round-robin when
gemini-cli virtual auths are detected (via gemini_virtual_parent attr):
- Level 1: cycle across credential groups (parent accounts)
- Level 2: cycle within each group's project auths

Credentials start from a random offset (rand.IntN) for fair distribution.
Non-virtual auths and single-credential scenarios fall back to flat RR.

Adds 3 test cases covering multi-credential grouping, single-parent
fallback, and mixed virtual/non-virtual fallback.
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @rensumo, 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 RoundRobinSelector mechanism for gemini-cli virtual authentications. It transitions from a flat round-robin approach to a more sophisticated two-level strategy, which groups authentications by their parent credentials. This change ensures a more balanced and efficient distribution of requests across different credentials and their associated projects, thereby resolving previous issues of uneven load and consecutive usage of the same credential.

Highlights

  • Two-Level Round-Robin for Gemini CLI: Implemented a new selection strategy for gemini-cli virtual authentications that first cycles through credential groups (parent accounts) and then cycles through project authentications within the selected group.
  • Improved Load Distribution: Addressed the issue of uneven load distribution by ensuring that different credentials are used consecutively, preventing a single credential from being overused and promoting fairer resource allocation.
  • Randomized Initial Credential Selection: Added randomization to the initial selection of credential groups to further balance the load and avoid predictable starting points.
  • New Helper Functions: Introduced ensureCursorKey to manage cursor map capacity and groupByVirtualParent to categorize authentications by their virtual parent attribute, facilitating the new two-level logic.
  • Enhanced Test Coverage: Included new test cases to verify the correct behavior of the credential-based grouping, including scenarios for single-parent fallback and mixed virtual/non-virtual authentications.

🧠 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.

Changelog
  • sdk/cliproxy/auth/selector.go
    • Imported math/rand/v2 for random number generation.
    • Modified the Pick method to implement a two-level round-robin logic for gemini-cli virtual auths, prioritizing credential groups before projects.
    • Added ensureCursorKey function to manage cursor map entries.
    • Added groupByVirtualParent function to categorize auths by their virtual parent attribute.
  • sdk/cliproxy/auth/selector_test.go
    • Added TestRoundRobinSelectorPick_GeminiCLICredentialGrouping to verify the two-level round-robin behavior.
    • Added TestRoundRobinSelectorPick_SingleParentFallsBackToFlat to test the fallback to flat round-robin when only one credential group exists.
    • Added TestRoundRobinSelectorPick_MixedVirtualAndNonVirtualFallsBackToFlat to ensure flat round-robin is used when both virtual and non-virtual auths are present.
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

The pull request successfully implements a two-level round-robin selection strategy for gemini-cli virtual auths. This change ensures that load is distributed evenly across different credentials (parent accounts) before cycling through projects within each credential. The implementation is robust, handles mixed auth types gracefully by falling back to flat round-robin, and includes comprehensive unit tests. I have identified a minor performance optimization regarding the grouping logic being executed under a mutex for all providers.


// Check if any available auth has gemini_virtual_parent attribute,
// indicating gemini-cli virtual auths that should use credential-level polling.
groups, parentOrder := groupByVirtualParent(available)
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The groupByVirtualParent function iterates through all available auths and performs string operations and map allocations. Since this is called while holding the s.mu mutex, it could potentially become a bottleneck if the number of available auths is large or if there is high concurrency. Consider checking the provider string first to only perform this grouping for relevant providers (like gemini-cli), or optimizing the check to bail out early if no virtual auths are expected.

@luispater luispater changed the base branch from main to dev February 23, 2026 22:02
@luispater luispater merged commit 7cb398d into router-for-me:dev Feb 23, 2026
2 checks passed
AoaoMH pushed a commit to AoaoMH/CLIProxyAPI-Aoao that referenced this pull request Mar 3, 2026
feat: implement credential-based round-robin for gemini-cli
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.

2 participants