-
-
Notifications
You must be signed in to change notification settings - Fork 554
fix: simplify Gemini routing and ignore legacy quota_fallback #413
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -1135,10 +1135,13 @@ export const createAntigravityPlugin = (providerId: string) => async ( | |||||
| checkAborted(); | ||||||
|
|
||||||
| const accountCount = accountManager.getAccountCount(); | ||||||
| const cliFirst = getCliFirst(config); | ||||||
| const preferredHeaderStyle = getHeaderStyleFromUrl(urlString, family, cliFirst); | ||||||
| const explicitQuota = isExplicitQuotaFromUrl(urlString); | ||||||
| const allowQuotaFallback = config.quota_fallback && !explicitQuota && family === "gemini"; | ||||||
| const routingDecision = resolveHeaderRoutingDecision(urlString, family, config); | ||||||
| const { | ||||||
| cliFirst, | ||||||
| preferredHeaderStyle, | ||||||
| explicitQuota, | ||||||
| allowQuotaFallback, | ||||||
| } = routingDecision; | ||||||
|
|
||||||
| if (accountCount === 0) { | ||||||
| throw new Error("No Antigravity accounts available. Run `opencode auth login`."); | ||||||
|
|
@@ -1209,7 +1212,7 @@ export const createAntigravityPlugin = (providerId: string) => async ( | |||||
| continue; | ||||||
| } | ||||||
|
|
||||||
| const strictWait = explicitQuota || !allowQuotaFallback; | ||||||
| const strictWait = !allowQuotaFallback; | ||||||
| // All accounts are rate-limited - wait and retry | ||||||
| const waitMs = accountManager.getMinWaitTimeForFamily( | ||||||
| family, | ||||||
|
|
@@ -1472,7 +1475,7 @@ export const createAntigravityPlugin = (providerId: string) => async ( | |||||
| // Check if this header style is rate-limited for this account | ||||||
| if (accountManager.isRateLimitedForHeaderStyle(account, family, headerStyle, model)) { | ||||||
| // Antigravity-first fallback: exhaust antigravity across ALL accounts before gemini-cli | ||||||
| if (config.quota_fallback && !explicitQuota && family === "gemini" && headerStyle === "antigravity" && !cliFirst) { | ||||||
| if (allowQuotaFallback && family === "gemini" && headerStyle === "antigravity") { | ||||||
| // Check if ANY other account has antigravity available | ||||||
| if (accountManager.hasOtherAccountWithAntigravityAvailable(account.index, family, model)) { | ||||||
| // Switch to another account with antigravity (preserve antigravity priority) | ||||||
|
|
@@ -1482,9 +1485,6 @@ export const createAntigravityPlugin = (providerId: string) => async ( | |||||
| // All accounts exhausted antigravity - fall back to gemini-cli on this account | ||||||
| const alternateStyle = accountManager.getAvailableHeaderStyle(account, family, model); | ||||||
| const fallbackStyle = resolveQuotaFallbackHeaderStyle({ | ||||||
| quotaFallback: config.quota_fallback, | ||||||
| cliFirst, | ||||||
| explicitQuota, | ||||||
| family, | ||||||
| headerStyle, | ||||||
| alternateStyle, | ||||||
|
|
@@ -1500,13 +1500,10 @@ export const createAntigravityPlugin = (providerId: string) => async ( | |||||
| shouldSwitchAccount = true; | ||||||
| } | ||||||
| } | ||||||
| } else if (config.quota_fallback && !explicitQuota && family === "gemini") { | ||||||
| } else if (allowQuotaFallback && family === "gemini") { | ||||||
| // gemini-cli rate-limited - try alternate style (antigravity) on same account | ||||||
| const alternateStyle = accountManager.getAvailableHeaderStyle(account, family, model); | ||||||
| const fallbackStyle = resolveQuotaFallbackHeaderStyle({ | ||||||
| quotaFallback: config.quota_fallback, | ||||||
| cliFirst, | ||||||
| explicitQuota, | ||||||
| family, | ||||||
| headerStyle, | ||||||
| alternateStyle, | ||||||
|
|
@@ -1742,7 +1739,7 @@ export const createAntigravityPlugin = (providerId: string) => async ( | |||||
|
|
||||||
| // For Gemini, preserve preferred quota across accounts before fallback | ||||||
| if (family === "gemini") { | ||||||
| if (headerStyle === "antigravity" && !cliFirst) { | ||||||
| if (headerStyle === "antigravity") { | ||||||
| // Check if any other account has Antigravity quota for this model | ||||||
| if (hasOtherAccountWithAntigravity(account)) { | ||||||
| pushDebug(`antigravity exhausted on account ${account.index}, but available on others. Switching account.`); | ||||||
|
|
@@ -1754,12 +1751,9 @@ export const createAntigravityPlugin = (providerId: string) => async ( | |||||
|
|
||||||
| // All accounts exhausted for Antigravity on THIS model. | ||||||
| // Before falling back to gemini-cli, check if it's the last option (automatic fallback) | ||||||
| if (config.quota_fallback && !explicitQuota) { | ||||||
| if (allowQuotaFallback) { | ||||||
| const alternateStyle = accountManager.getAvailableHeaderStyle(account, family, model); | ||||||
| const fallbackStyle = resolveQuotaFallbackHeaderStyle({ | ||||||
| quotaFallback: config.quota_fallback, | ||||||
| cliFirst, | ||||||
| explicitQuota, | ||||||
| family, | ||||||
| headerStyle, | ||||||
| alternateStyle, | ||||||
|
|
@@ -1775,13 +1769,10 @@ export const createAntigravityPlugin = (providerId: string) => async ( | |||||
| continue; | ||||||
| } | ||||||
| } | ||||||
| } else if (headerStyle === "gemini-cli" && cliFirst) { | ||||||
| if (config.quota_fallback && !explicitQuota) { | ||||||
| } else if (headerStyle === "gemini-cli") { | ||||||
| if (allowQuotaFallback) { | ||||||
| const alternateStyle = accountManager.getAvailableHeaderStyle(account, family, model); | ||||||
| const fallbackStyle = resolveQuotaFallbackHeaderStyle({ | ||||||
| quotaFallback: config.quota_fallback, | ||||||
| cliFirst, | ||||||
| explicitQuota, | ||||||
| family, | ||||||
| headerStyle, | ||||||
| alternateStyle, | ||||||
|
|
@@ -2808,25 +2799,42 @@ function getModelFamilyFromUrl(urlString: string): ModelFamily { | |||||
| } | ||||||
|
|
||||||
| function resolveQuotaFallbackHeaderStyle(input: { | ||||||
| quotaFallback: boolean; | ||||||
| cliFirst: boolean; | ||||||
| explicitQuota: boolean; | ||||||
| family: ModelFamily; | ||||||
| headerStyle: HeaderStyle; | ||||||
| alternateStyle: HeaderStyle | null; | ||||||
| }): HeaderStyle | null { | ||||||
| if (!input.quotaFallback || input.explicitQuota || input.family !== "gemini") { | ||||||
| if (input.family !== "gemini") { | ||||||
| return null; | ||||||
| } | ||||||
| if (!input.alternateStyle || input.alternateStyle === input.headerStyle) { | ||||||
| return null; | ||||||
| } | ||||||
| if (input.cliFirst && input.headerStyle !== "gemini-cli") { | ||||||
| return null; | ||||||
| } | ||||||
| return input.alternateStyle; | ||||||
| } | ||||||
|
|
||||||
| type HeaderRoutingDecision = { | ||||||
| cliFirst: boolean; | ||||||
| preferredHeaderStyle: HeaderStyle; | ||||||
| explicitQuota: boolean; | ||||||
| allowQuotaFallback: boolean; | ||||||
| }; | ||||||
|
|
||||||
| function resolveHeaderRoutingDecision( | ||||||
| urlString: string, | ||||||
| family: ModelFamily, | ||||||
| config: AntigravityConfig, | ||||||
| ): HeaderRoutingDecision { | ||||||
| const cliFirst = getCliFirst(config); | ||||||
| const preferredHeaderStyle = getHeaderStyleFromUrl(urlString, family, cliFirst); | ||||||
| const explicitQuota = isExplicitQuotaFromUrl(urlString); | ||||||
| return { | ||||||
| cliFirst, | ||||||
| preferredHeaderStyle, | ||||||
| explicitQuota, | ||||||
| allowQuotaFallback: family === "gemini", | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Prompt To Fix With AIThis is a comment left during a code review.
Path: src/plugin.ts
Line: 2834:2834
Comment:
`allowQuotaFallback` ignores `explicitQuota`, breaking documented behavior. Previously, explicit quota suffixes (`:antigravity` or `:gemini-cli`) would "always use that specific quota and switch accounts if exhausted" without falling back. Now they fallback to the alternate quota.
```suggestion
allowQuotaFallback: !explicitQuota && family === "gemini",
```
How can I resolve this? If you propose a fix, please make it concise. |
||||||
| }; | ||||||
| } | ||||||
|
|
||||||
| function getCliFirst(config: AntigravityConfig): boolean { | ||||||
| return (config as AntigravityConfig & { cli_first?: boolean }).cli_first ?? false; | ||||||
| } | ||||||
|
|
@@ -2858,5 +2866,6 @@ function isExplicitQuotaFromUrl(urlString: string): boolean { | |||||
|
|
||||||
| export const __testExports = { | ||||||
| getHeaderStyleFromUrl, | ||||||
| resolveHeaderRoutingDecision, | ||||||
| resolveQuotaFallbackHeaderStyle, | ||||||
| }; | ||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
description implies unidirectional fallback (only Antigravity → CLI) but fallback is now bidirectional. Consider clarifying: "Automatic fallback between Antigravity and Gemini CLI in both directions"
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Prompt To Fix With AI