Skip to content

fix(antigravity): 无重置时间的裸 429 只冷却失败的模型 / Cool only the failed model on a bare 429 - #8836

Open
Oracle0703 wants to merge 1 commit into
Wei-Shaw:mainfrom
Oracle0703:fix/antigravity-bare-429-model-scope
Open

Oracle0703 wants to merge 1 commit into
Wei-Shaw:mainfrom
Oracle0703:fix/antigravity-bare-429-model-scope

Conversation

@Oracle0703

Copy link
Copy Markdown

Refs #8824(issue 里的建议 3)。#8829 删掉了这次触发 429 的句子,但没有改冷却范围;本 PR 只改冷却范围。

问题

上游对按内容拒绝的请求也会返回裸 429:Resource has been exhausted (e.g. check quota).,不带 quotaResetDelay / RetryInfo。handleUpstreamError 的 429 兜底分支在这种情况下使用默认冷却时长,并且同时写入模型 key 和家族 key antigravity:gemini(Pro 账号的 Argon 是 antigravity:gemini:argon)。结果一个请求被拒,同账号的所有 Gemini 模型都要等冷却结束,期间无关请求返回 503 No available accounts。

改动

只改 handleUpstreamError 的 429 兜底分支:如果响应里解析不出重置时间(ParseGeminiRateLimitResetTime 返回 nil),就只冷却失败的那个模型 key,不写家族 key。冷却时长不变。日志 model_rate_limited 增加 keys= 字段,便于确认写了哪些 key。

下面这些情况不变,仍然写家族 key:

  • 带 quotaResetDelay、RetryInfo.retryDelay、Please retry in Xs 或按天配额的 429;
  • 带 RATE_LIMIT_EXCEEDED 的智能重试路径(handleSmartRetry、handleModelRateLimit、handleAntigravityModelRateLimitBeforePolicy)。

图片模型和 Claude 模型本来就不写家族 key,不受影响。

取舍:如果某个裸 429 其实是整个 Gemini 配额池耗尽,同账号的其他 Gemini 模型各会多失败一次,然后再各自冷却。失败的模型本身仍按原时长冷却,所以不会回到 #2902 那种反复调度同一账号的情况。

验证

  • 新增 backend/internal/service/antigravity_bare_429_scope_test.go:
    • 裸 429(共享 Gemini、Pro Argon 两种情况)只写失败模型的 key,不做账号级限流。按调度器的方式经 JSON 重建账号快照后,失败模型不可调度,同账号其他 Gemini 模型可以调度。
    • quotaResetDelay、RetryInfo、Please retry in 三种带重置时间的 429 仍写家族 key,同族其他模型不可调度。
    • 未修改的代码上,裸 429 用例失败;修改后通过。
  • go build ./...、go vet -tags=unit ./internal/service/、gofmt 通过。
  • golangci-lint v2.14.0:全仓 0 issues;GOOS=linux 下 ./internal/service/... 0 issues。
  • go test -tags=unit ./...(Windows):60 个包通过。internal/service 有 3 个失败,都不涉及 Antigravity:
    • TestOllamaProbeCallback_StaleLongDoesNotOverrideNewShort:在未修改的 main@530c5e3a4 上单独跑同样失败(fix(openai): preserve Codex standalone context on Responses #8680 也提到过 Windows 下复现);
    • TestCommandCodeGatewayPassesThroughCatalogProtocols:在未修改的 main@530c5e3a4 上单独跑 10 次失败 6 次;
    • TestOpenAIWSPassthroughFirstTokenFollowsTTFTMode:1.099s < 1.1s 的计时边界抖动;本次在未修改的 main 上单独跑通过,我们之前在同一份上游代码上复现过。

未验证,请帮忙试一下

我们没有 Gemini / Antigravity 账号,没有对真实上游做过端到端验证。

@yanhexiong 方便的话,能否在 #8824 的环境里用这个分支试一下?本分支基于 main,没有包含 #8829,所以原来那个 Claude Code 请求应该仍会触发裸 429:

  1. 用原来的 Claude Code 请求触发一次裸 429;
  2. 日志应为 model_rate_limited model=<模型> keys=<模型>,不再出现 antigravity:gemini;
  3. 冷却期间,同一账号上其他 Gemini 模型的请求应该能正常返回,不再是 503 No available accounts。

是否合并由维护者决定。

🤖 Generated with Claude Code

A 429 without quotaResetDelay or RetryInfo does not show that the shared
Gemini quota is exhausted: the upstream also returns this body for
requests it rejects by content (Wei-Shaw#8824). The 429 fallback in
handleUpstreamError still wrote the antigravity:gemini family key, so one
rejected request made every Gemini model on the account unschedulable
until the cooldown ended.

When no reset time can be parsed, cool only the failed model. 429s with
quotaResetDelay, RetryInfo, "Please retry in" or a daily quota, and the
RATE_LIMIT_EXCEEDED smart-retry paths, still write the family key.

Refs Wei-Shaw#8824

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA. ✅
Posted by the CLA Assistant Lite bot.

doublepi123 added a commit to doublepi123/sub2api that referenced this pull request Nov 17, 2026
Port upstream Wei-Shaw#8836.

A 429 without quotaResetDelay / RetryInfo does not prove the shared Gemini
quota is exhausted (content-based rejections look identical), so it now cools
only the failed model key instead of also writing the antigravity:gemini
family key. One rejected request no longer turns every other Gemini model on
the account into 503 "No available accounts" for a minute. 429s that carry a
reset time keep the family scope.

The ported tests expect the key the fork actually cools: since the Claude
5.5 / Hydrogen port, cooldowns are keyed on the forwarded variant
(gemini-3.8-flash resolves to gemini-3.8-flash-high).
@Oracle0703

Copy link
Copy Markdown
Author

recheck

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.

1 participant