Skip to content

fix: Claude token refresh, Antigravity quota, and 429 rate-limit handling - #862

Closed
oyi77 wants to merge 1 commit into
diegosouzapw:mainfrom
oyi77:fix/token-quota-bugs-836-857-858
Closed

oyi77 wants to merge 1 commit into
diegosouzapw:mainfrom
oyi77:fix/token-quota-bugs-836-857-858

Conversation

@oyi77

@oyi77 oyi77 commented Mar 31, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes 3 bugs in OmniRoute:

  1. Claude Token Refresh ([BUG] Claude Token Refresh Failed #836): Changed to form-urlencoded + anthropic-beta header
  2. Antigravity Quota ([BUG] Antigravity wrong Quota #857): Switched to retrieveUserQuota API (same as Gemini CLI)
  3. 429 Rate-Limit ([Bug] 429 quota reset time from error body not used for account cooldown #858,[BUG] Unexpected Qwen quota (429) errors when using OmniRoute as proxy despite low request rate #832): Parse reset time for all providers, cap at 24h

Verification

  • npm run build: Pass
  • npm test: 1175 tests pass
  • Only 4 files changed

…ling

- Fix Claude OAuth token refresh to use form-urlencoded format (standard OAuth2)
- Add anthropic-beta header required by Claude OAuth API
- Switch Antigravity quota to use retrieveUserQuota API (same as Gemini CLI)
- Parse quota reset time for all providers (not just Antigravity)
- Add quota reset keywords to error classifier
- Cap maximum retry time at 24 hours to prevent infinite wait

Closes diegosouzapw#836, diegosouzapw#857, diegosouzapw#858, diegosouzapw#832

@kilo-code-bot kilo-code-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Overview

Severity Count
CRITICAL 0
WARNING 0
SUGGESTION 0

Verification Performed

All 4 changed files were reviewed:

  1. open-sse/services/accountFallback.ts (lines 244-245)

    • Added "quota will reset" and "your quota will reset" to quota exhaustion detection
    • Pattern follows existing code style using includes()
  2. open-sse/services/tokenRefresh.ts (lines 210-224)

    • Changed to form-urlencoded format as required by Anthropic OAuth spec
    • Added required anthropic-beta: oauth-2025-04-20 header
    • PROVIDERS.claude.clientId correctly sourced from REGISTRY.oauth.clientIdDefault
  3. open-sse/services/usage.ts (lines 668-728)

    • Switched to retrieveUserQuota API for accurate quota across Free/Pro tiers
    • Added projectId validation with early return
    • Added AbortSignal timeout (10s) for reliability
    • Proper null handling for bucket.remainingFraction
    • Correct Math.max(0, total - remaining) to prevent negative values
  4. open-sse/utils/error.ts (lines 125-134)

    • Extended retry time parsing to all providers (not just Antigravity)
    • Added 24-hour cap to prevent infinite wait scenarios
Files Reviewed (4 files)
  • open-sse/services/accountFallback.ts
  • open-sse/services/tokenRefresh.ts
  • open-sse/services/usage.ts
  • open-sse/utils/error.ts

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

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 updates error classification for quota resets, switches Claude OAuth token refresh to form-urlencoded with a beta header, and migrates Antigravity usage tracking to the retrieveUserQuota API. It also introduces a 24-hour cap on retry times. Feedback includes recommendations to avoid hardcoding API endpoints in favor of existing configuration patterns, safer error handling in catch blocks, and merging redundant logic for parsing retry times.

Comment on lines +676 to +677
const response = await fetch(
"https://cloudcode-pa.googleapis.com/v1internal:retrieveUserQuota",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The API endpoint for Antigravity quota retrieval is hardcoded here, which is inconsistent with the existing configuration pattern in this file. It is recommended to update ANTIGRAVITY_CONFIG.quotaApiUrl (line 16) to the new retrieveUserQuota endpoint and reference it here instead.

    const response = await fetch(ANTIGRAVITY_CONFIG.quotaApiUrl, {

};
} catch (error) {
return { message: `Antigravity error: ${error.message}` };
return { message: `Antigravity error: ${(error as Error).message}` };

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Casting error directly to Error in a catch block can be unsafe if the thrown value is not an instance of Error (e.g., a string or a plain object). A safer approach is to check if it's an instance of Error or use a utility to extract the message.

Suggested change
return { message: `Antigravity error: ${(error as Error).message}` };
return { message: `Antigravity error: ${error instanceof Error ? error.message : String(error)}` };

Comment thread open-sse/utils/error.ts
Comment on lines +126 to +128
if (response.status === 429 && !retryAfterMs) {
retryAfterMs = parseAntigravityRetryTime(messageStr);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

This block is redundant for the antigravity provider because the previous block (lines 121-123) already calls parseAntigravityRetryTime for 429 status codes. Since the parsing logic is now intended to be applied globally for all providers on 429 errors, these blocks should be merged for better maintainability.

Suggested change
if (response.status === 429 && !retryAfterMs) {
retryAfterMs = parseAntigravityRetryTime(messageStr);
}
// Parse retry time for providers with "quota will reset after XhYmZs" format
if (response.status === 429 && !retryAfterMs) {
retryAfterMs = parseAntigravityRetryTime(messageStr);
}

diegosouzapw added a commit that referenced this pull request Mar 31, 2026
@diegosouzapw

Copy link
Copy Markdown
Owner

Integrated into release/v3.4.0. Released as part of v3.4.0. Thank you!

@diegosouzapw diegosouzapw mentioned this pull request Apr 22, 2026
This was referenced Apr 30, 2026
Poid-ZA pushed a commit to Poid-ZA/OmniRoute that referenced this pull request Aug 5, 2026
muhamadgalihsaputra pushed a commit to niyatna/NiyatnaRoute that referenced this pull request Sep 27, 2026
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