Skip to content

feat(oauth): rank Antigravity failover by Gemini vs Claude quota family - #4676

Draft
agentHits wants to merge 2 commits into
lidge-jun:devfrom
agentHits:agentHits/antigravity-quota-family
Draft

agentHits wants to merge 2 commits into
lidge-jun:devfrom
agentHits:agentHits/antigravity-quota-family

Conversation

@agentHits

@agentHits agentHits commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

Summary

Make generic OAuth ranking and 429 cooldown model-family aware for google-antigravity.

Gemini requests use Gem / Gem (Weekly) windows only. Claude requests use Cla / Cla (Weekly). A spent Claude window no longer ranks the account as exhausted for Gemini, and a Claude 429 cools only the Claude family so the same account can still serve Gemini.

Unknown labels and Gemma ids fall back to the current unranked ring. Codex and Anthropic paths are unchanged.

Refs #3375. Complements the GUI pool-settings panel; does not add a dedicated Antigravity router.

Verification

  • bun test tests/oauth/oauth-account-quota-rank.test.ts tests/oauth/generic-oauth-failover.test.ts tests/providers/kiro/kiro-pool-rank.test.ts tests/test-layout.test.ts tests/test-layout-tooling.test.ts tests/lab/core-lab-boundary.test.ts — 109 passed
  • bun run typecheck — passed

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed.
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults.

Review readiness checklist

This PR stays in draft until every box below is ticked. Tick all four boxes once the requirements are met:

  • All CI tests are green on my local testing.

  • I pushed my PR to the latest dev commit.

  • I resolved all correct Codex and CodeRabbit findings.

  • My PR is ready for review.

Summary by CodeRabbit

  • Bug Fixes

    • Improved OAuth account quota tracking for Antigravity models by separating Gemini and Claude quota windows.
    • Prevented quota exhaustion and cooldown status for one model family from incorrectly affecting another.
    • Updated account selection and failover decisions to use the requested model and current cooldown information.
  • Tests

    • Added coverage for model-family classification, quota ranking, and cross-family failover behavior.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@github-actions github-actions Bot added the intake: hygiene-blocked Deterministic PR hygiene checks failed label Sep 15, 2026
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Deterministic hygiene checks failed.

  • unsponsored_surface — This changes an authentication, workflow, release-automation, or dependency surface. MAINTAINERS.md requires security review for these; ask a maintainer to apply maintainer-sponsored once they have reviewed it. Paths: src/oauth/account-quota-rank.ts, src/oauth/generic-account-failover.ts.

@github-actions github-actions Bot added the enhancement New feature or request label Sep 15, 2026
@coderabbitai

coderabbitai Bot commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Advanced

Run ID: eca27580-e88c-4dfe-bfa7-e2cc57736075

📥 Commits

Reviewing files that changed from the base of the PR and between 3ea88f3 and 60a349b.

📒 Files selected for processing (6)
  • scripts/test-layout/layout.json
  • src/oauth/account-quota-rank.ts
  • src/oauth/generic-account-failover.ts
  • src/server/responses/core.ts
  • tests/fixtures/test-layout-expected.json
  • tests/oauth/oauth-account-quota-rank.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The change adds Gemini and Claude family awareness to Antigravity quota ranking and generic OAuth failover. It scopes quota windows and cooldowns by requested model, forwards model data through server response paths, and adds focused tests and layout mappings.

Changes

OAuth quota and failover

Layer / File(s) Summary
Quota family classification and ranking
src/oauth/account-quota-rank.ts
Lines 16–44 add QuotaModelFamily and model classification. Lines 80–200 scope headroom, exhaustion, ranking, and evidence checks to matching Antigravity quota windows.
Family-scoped failover state
src/oauth/generic-account-failover.ts
Lines 86–476 scope cooldown keys, account eligibility, rotation, preferred-account selection, ranking, and retry-after scanning by model family.
Request wiring and validation
src/server/responses/core.ts, tests/oauth/oauth-account-quota-rank.test.ts, scripts/test-layout/layout.json, tests/fixtures/test-layout-expected.json
Lines 4948–9124 pass the current time and route.modelId through selection and rotation paths. The new tests cover family classification, independent quota windows, family-scoped cooldowns, and test-layout mappings.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant ResponsesCore
  participant GenericOAuthFailover
  participant QuotaRanking
  participant HealthMap
  ResponsesCore->>GenericOAuthFailover: pass Date.now() and route.modelId
  GenericOAuthFailover->>QuotaRanking: classify family and rank eligible accounts
  GenericOAuthFailover->>HealthMap: store or read family-scoped cooldown
  GenericOAuthFailover-->>ResponsesCore: return account selection or rotation result
Loading

Merge Risk: ⚪ Minimal · up to 60a34

No confirmed merge-blocking issue remains; the family-scoped quota and cooldown behavior is ready to merge.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 72.22% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 18 functions across 4 files. (2 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: model-family-aware ranking of Antigravity OAuth failover accounts by Gemini versus Claude quota.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 72.22% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 18 functions across 4 files. (2 skipped: 2 unsupported.)

✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@github-actions

github-actions Bot commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

⏳ DRAFT

  • hygiene: unsponsored_surface.

What to do

  • Fix unsponsored_surface — This changes an authentication, workflow, release-automation, or dependency surface. MAINTAINERS.md requires security review for these; ask a maintainer to apply maintainer-sponsored once they have reviewed it. Paths: src/oauth/account-quota-rank.ts, src/oauth/generic-account-failover.ts.
  • Tick all four boxes in the PR description once you're done (currently 0/4).

Review readiness checklist

  • ⬜ All CI tests are green on my local testing.
  • ⬜ I pushed my PR to the latest dev commit.
  • ⬜ I resolved all correct Codex and CodeRabbit findings.
  • ⬜ My PR is ready for review.

0/4 boxes ticked.

This pull request was already a draft. Its draft status will be preserved after every issue above is resolved.
@agentHits Tick the boxes once your local CI is green, your branch is on the latest dev commit, and every correct Codex and CodeRabbit finding is resolved.

@lidge-jun

Copy link
Copy Markdown
Owner

리뷰 · 우선순위 62 / 80

설명

이 PR은 google-antigravity 한 계정 안에 Gemini 쿼터 창(Gem / Gem (Weekly))과 Claude 쿼터 창(Cla / Cla (Weekly))이 같이 들어 있는 현실을, generic OAuth failover 순위에 반영한다. 지금 dev HEAD(3ea88f3db, #4674 lab sync-activation 테스트까지)의 src/oauth/account-quota-rank.tsheadroomOfcustomWindows의 percent를 전부 모아서 최소 여유를 본다. 그래서 Claude 창이 100%면 Gemini 요청에도 그 계정이 고갈로 보인다. src/providers/quota/antigravity.ts가 이미 라벨을 Gem/Cla로 나눠 넣고 있는데, 랭킹·429 쿨다운은 아직 가족 구분이 없다.

변경의 핵심은 세 겹이다. (1) classifyModelFamilyForQuota / windowMatchesFamily로 모델 id를 gem | cla로 분류하고, 가족별 창만으로 headroom·exhaustion·rankAccountsByHeadroom을 계산한다. Gemma는 Gemini로 오인하지 않게 명시적으로 제외한다. (2) src/oauth/generic-account-failover.tshealthKey에 optional family를 붙여, Claude 429 쿨다운이 Gemini 선택에 계정을 숨기지 않게 한다. preferredInitialAccount / rotateGenericOAuthAccountOn429 / fill-first / eligible 필터에 requestedModelId를 흘린다. (3) src/server/responses/core.ts의 generic failover 호출 몇 곳에 Date.now()route.modelId를 넘겨, 실제 요청 모델이 가족 분류에 들어가게 한다. Codex·Anthropic 전용 경로는 손대지 않는다. Refs #3375(계정 풀 생애주기 epic)와 맞닿고, GUI pool-settings와 보완 관계라고 본문에도 적혀 있다.

현재 dev 방향(godfile round5: openai-responses → bridge → 다음 목표 server/index.ts, server/responses/core.ts는 스플릿 범위 밖)과 비교하면, 이 PR은 core.ts를 거대 리팩터가 아니라 호출 인자만 살짝 늘리는 수준이라 close-don't-rebase 대상(구 모놀리식 bridge/openai-responses 잔존 PR)은 아니다. types.ts/config.ts 스플릿에도 걸리지 않는다. 다만 oauth 인증/풀 표면이라 hygiene가 unsponsored_surface로 막혀 있고(intake: hygiene-blocked), 체크리스트·draft readiness도 아직 비어 있다. 로컬 검증 주장은 oauth/kiro/layout/lab 관련 테스트 109 + typecheck 통과다.

라인 16-40 (account-quota-rank.ts, PR head) - classifyModelFamilyForQuotagem 정규식은 Gemma를 먼저 걸러 두었지만, gemini가 아닌 단독 gem 토큰도 가족으로 잡는다. Antigravity 카탈로그에 gem-… 같은 약칭 id가 생기면 의도일 수 있고, 예상 밖 id면 잘못된 가족 랭킹이 된다. 허용 id 목록을 src/providers/antigravity-models.ts와 한 번 맞춰 보는 편이 안전하다.

라인 windowMatchesFamily - 라벨 첫 토큰만 Gem/Cla/Gemini/Claude로 본다. 지금 antigravity.ts PREFERRED_ORDER(Gem, Gem (Weekly), Cla, Cla (Weekly))와는 맞는다. 다만 요약 API가 Other/3P 계열 라벨만 주는 계정은 family 지정 시 percents.length === 0 → null → unranked로 떨어져, 가족 인식이 꺼진 것처럼 동작한다. 테스트도 그 fallback을 고정해 두었다.

경로 generic-account-failover.ts / noteGenericPoolSelection - 429·preferred 경로에는 family를 넣었지만, noteGenericPoolSelectioneligibleFailoverAccounts(providerName)는 여전히 family 없이 호출한다. family 키로만 쿨다운된 계정은 unmarked eligible에 남으므로 Gemini round-robin에는 유리하고, Claude 전용 커서를 따로 두지는 않는다. round-robin + Antigravity 동시 사용 시 의도인지 확인이 필요하다.

경로 server/responses/core.ts - 호출 6곳 근처에 route.modelId를 넣는 것은 맞다. 하지만 이 파일은 godfile round5에서 의도적으로 스플릿 밖인 초대형 모듈이다. 인자 전달만이면 허용 가능하나, 같은 PR에 oauth 로직 + core 배선이 묶여 리뷰 표면이 넓어졌다. 배선만 후속 PR로 쪼개면 스폰서 리뷰가 가벼워질 수 있다.

경로 tests/oauth/oauth-account-quota-rank.test.ts - Claude 429 후 preferredInitialAccount(..., gemini)null(활성 계정 유지)인 시나리오는 핵심 회귀를 잘 잡는다. 다만 fill-first / round-robin + family, 그리고 genericFailoverRetryAfterSeconds가 family 키를 prefix로 스캔하는 변경에 대한 직접 테스트는 약하다. 기존 generic-oauth-failover.test.ts는 modelId 없이 xai 위주라 회귀는 커버되지만 Antigravity family 쿨다운×전략 조합은 얇다.

메인테이너의 판단이 필요한 지점

너의 추천
위생(unsponsored_surface)과 draft checklist를 먼저 정리하고, 메인테이너가 oauth 동작만 짧게 확인한 뒤 maintainer-sponsored를 붙인 다음 랜딩을 검토한다. 코드 방향 자체(가족별 창 + 가족별 쿨다운 + core에 modelId 전달)는 dev의 Antigravity 풀 현실과 맞고 close 대상이 아니다. 머지 전에 (1) Antigravity 실제 모델 id 샘플로 classify 표 점검, (2) fill-first/round-robin×family 쿨다운 테스트 1~2개 보강, (3) core.ts 접촉을 이 PR에 둘지 한 줄로 결정하면 충분하다. 중복 open PR은 보이지 않았다.

이 댓글은 grok-bot이 작성했습니다

Keep Claude exhaustion from starving Gemini selection, and cool 429s per
model family so a Claude limit still leaves the account eligible for Gemini.

Co-authored-by: agentHits <140916359+agentHits@users.noreply.github.com>
Classify only gemini-* model ids, keep family cooldown off the other family's ring, and pass the request model into round-robin admission.
@agentHits
agentHits force-pushed the agentHits/antigravity-quota-family branch from 884518f to 3defbd0 Compare September 15, 2026 12:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request intake: hygiene-blocked Deterministic PR hygiene checks failed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants