Skip to content

fix: issue #400 header-style selection for gemini-cli#404

Open
ndycode wants to merge 2 commits intoNoeFabris:mainfrom
ndycode:fix/issue-400-gemini-cli-selection
Open

fix: issue #400 header-style selection for gemini-cli#404
ndycode wants to merge 2 commits intoNoeFabris:mainfrom
ndycode:fix/issue-400-gemini-cli-selection

Conversation

@ndycode
Copy link

@ndycode ndycode commented Feb 8, 2026

Fixed issue #400.

The bug was in account selection: requests were being treated like antigravity too early, so gemini-cli could get blocked when Antigravity quota was exhausted.

What changed:

  • account selection now uses the actual requested header style
  • hybrid filtering now checks rate limits for that same style
  • added regression tests for this path in src/plugin/accounts.test.ts

Verified with:

  • npm test -- src/plugin/accounts.test.ts
  • npm run typecheck
  • npm run build
  • npm test

Closes #400

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 8, 2026

Walkthrough

The request handler now computes a single requestedHeaderStyle per request and uses it for account selection and quota checks. Account selection (hybrid and sticky flows) uses isRateLimitedForHeaderStyle(account, headerStyle) for rate-limit decisions and skips the soft-quota threshold check when headerStyle === "gemini-cli". headerStyle is set from the precomputed requestedHeaderStyle throughout the flow. Tests were added to validate hybrid selection behavior and the soft-quota bypass for gemini-cli.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: fixing issue #400 by correcting header-style selection for gemini-cli to prevent incorrect quota blocking.
Description check ✅ Passed The description is directly related to the changeset, explaining the bug fix, specific changes made to account selection and hybrid filtering, and verification steps performed.
Linked Issues check ✅ Passed The code changes fully address issue #400: account selection now uses actual requested header style, hybrid filtering checks per-header-style rate limits, soft quota is bypassed for gemini-cli, and regression tests are added.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing issue #400: modifications to header-style computation and quota checks, plus corresponding test coverage for the fix.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


No actionable comments were generated in the recent review. 🎉

📜 Recent review details

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 16515be and 6328d5c.

📒 Files selected for processing (1)
  • src/plugin.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/plugin.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Greptile Review

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 8, 2026

Greptile Overview

Greptile Summary

This PR improves header-style-aware account selection for Gemini models by computing requestedHeaderStyle once and reusing it during account selection and rate limit checks. The src/plugin/accounts.ts changes correctly implement header-style-specific filtering and skip soft quota thresholds for gemini-cli requests.

However, there's a critical bug at src/plugin.ts:2750 where getHeaderStyleFromUrl has backwards ternary logic that converts "gemini-cli" to "antigravity". This means the function always returns "antigravity" for Gemini models, even when the user has cli_first: true configured or explicitly requests gemini-cli quota. As a result, the account selection improvements don't fully address issue #400 because requestedHeaderStyle will still be "antigravity" in most cases.

The account management and testing changes are solid and well-implemented - the issue is solely in the getHeaderStyleFromUrl helper function.

Confidence Score: 2/5

  • This PR has a critical logic bug that prevents it from fully fixing issue fix: bypass soft quota check for gemini-cli requests #400
  • The account selection logic improvements are correct, but the root cause (getHeaderStyleFromUrl:2750 converting gemini-cli to antigravity) remains unfixed, meaning requests will still be treated as antigravity when they should use gemini-cli quota
  • Pay close attention to src/plugin.ts:2750 - the ternary logic must be fixed for this PR to work correctly

Important Files Changed

Filename Overview
src/plugin.ts Partially addresses issue #400 by using requestedHeaderStyle for account selection, but getHeaderStyleFromUrl:2750 still converts gemini-cli to antigravity
src/plugin/accounts.ts Correctly implements header-style-specific rate limiting and skips soft quota checks for gemini-cli
src/plugin/accounts.test.ts Comprehensive test coverage for header-style-aware account selection and soft quota handling

Sequence Diagram

sequenceDiagram
    participant User
    participant Plugin
    participant getHeaderStyleFromUrl
    participant AccountManager
    participant Account

    User->>Plugin: Request with Gemini model
    loop Account Selection Loop
        Plugin->>getHeaderStyleFromUrl: Get header style from URL
        Note right of getHeaderStyleFromUrl: Line 2750 BUG:<br/>Converts gemini-cli to antigravity
        getHeaderStyleFromUrl-->>Plugin: Returns "antigravity"
        
        Plugin->>AccountManager: getCurrentOrNextForFamily(family, model, strategy, "antigravity")
        AccountManager->>Account: Check rate limits for "antigravity"
        
        alt Antigravity available
            Account-->>AccountManager: Account available
            AccountManager-->>Plugin: Return account
            Plugin->>User: Make request with account
        else Antigravity exhausted
            Account-->>AccountManager: Rate limited for "antigravity"
            AccountManager-->>Plugin: Switch account or apply fallback
            
            alt Quota fallback enabled
                Plugin->>Plugin: Change headerStyle to "gemini-cli"
                Note right of Plugin: Fallback logic works within<br/>inner loop, but reselection<br/>still uses "antigravity"
            else No fallback
                Plugin->>Plugin: Switch to next account
                Note right of Plugin: Loop continues with<br/>"antigravity" for next account
            end
        end
    end
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

3 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 8, 2026

Additional Comments (1)

src/plugin.ts
Stale headerStyle computation

After introducing requestedHeaderStyle, this code still recomputes headerStyle via getHeaderStyleFromUrl(urlString, family) instead of using the already-derived value. If these diverge (e.g., if urlString changes due to endpoint fallback/transformations, or getHeaderStyleFromUrl depends on mutable state), the selection and request header style can get out of sync. Using the cached requestedHeaderStyle keeps behavior consistent with the chosen account/quota.

            let headerStyle = requestedHeaderStyle;
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/plugin.ts
Line: 1140:1146

Comment:
**Stale headerStyle computation**

After introducing `requestedHeaderStyle`, this code still recomputes `headerStyle` via `getHeaderStyleFromUrl(urlString, family)` instead of using the already-derived value. If these diverge (e.g., if `urlString` changes due to endpoint fallback/transformations, or `getHeaderStyleFromUrl` depends on mutable state), the selection and request header style can get out of sync. Using the cached `requestedHeaderStyle` keeps behavior consistent with the chosen account/quota.

```suggestion
            let headerStyle = requestedHeaderStyle;
```

How can I resolve this? If you propose a fix, please make it concise.

@ndycode ndycode changed the title fix: respect requested header style for gemini-cli account selection fix: issue #400 header-style selection for gemini-cli Feb 8, 2026
@ndycode ndycode force-pushed the fix/issue-400-gemini-cli-selection branch from 50ed5cb to 16515be Compare February 8, 2026 09:52
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

3 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

3 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 8, 2026

Additional Comments (1)

src/plugin.ts
This ternary logic is backwards - when quotaPreference is "gemini-cli", it returns "antigravity" instead. This defeats the purpose of the fix since getHeaderStyleFromUrl will always return "antigravity" for Gemini models, even when cli_first: true would make resolveModelWithTier prefer gemini-cli.

  return quotaPreference ?? "antigravity";
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/plugin.ts
Line: 2750:2750

Comment:
This ternary logic is backwards - when `quotaPreference` is `"gemini-cli"`, it returns `"antigravity"` instead. This defeats the purpose of the fix since `getHeaderStyleFromUrl` will always return `"antigravity"` for Gemini models, even when `cli_first: true` would make `resolveModelWithTier` prefer gemini-cli.

```suggestion
  return quotaPreference ?? "antigravity";
```

How can I resolve this? If you propose a fix, please make it concise.

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.

fix: bypass soft quota check for gemini-cli requests

1 participant