Skip to content

fix(gemini): 请求级 403 不再逐账号停用和换号重放 - #8730

Open
Henglie wants to merge 2 commits into
Wei-Shaw:mainfrom
Henglie:fix/gemini-403-no-account-replay
Open

Henglie wants to merge 2 commits into
Wei-Shaw:mainfrom
Henglie:fix/gemini-403-no-account-replay

Conversation

@Henglie

@Henglie Henglie commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Fixes #8442

问题

Gemini 入口把上游 403 一律当作账号错误:首次 403 就 SetError,而 403 又在可换号状态码里,于是同一个坏请求会逐个账号重放,把分组内 Gemini 账号依次停用。请求内容导致的 403(例如 fileData.fileUri 指向私有/已删除的 YouTube 视频)与账号鉴权/额度 403 在上游文案上无法区分。

改动

  • 同一请求首次 403 只返回 failover,暂缓账号状态与错误策略处理。
  • 另一个账号成功时,按原有错误策略回补处理第一个账号;两个不同账号都 403 时停止换号,返回固定 400 INVALID_ARGUMENT,不透传上游原文,两个账号状态都不变。
  • 403 不再在重试循环内触发临时不可调度;状态保存在 gin.Context,覆盖原生 /v1beta、/v1/messages、/v1/chat/completions 三条入口。
  • 保留 CachedContent not found 等已知请求级 403 的原有直返逻辑。

测试

  • go test -tags=unit ./internal/service/ -run 'TestGemini403|TestGeminiForwardNative_OtherForbiddenDefersAccountPenalty|TestGeminiForwardNative_CachedContent' -count=1 通过
  • go test -tags=unit ./internal/handler/ -run 'Gemini|Failover' -count=1 通过
  • go vet -tags=unit ./internal/service/ 通过
  • go test -tags=unit ./... 在本机仍有与本次改动无关的既有失败:TestAliyunCaptchaVerifier_TransportError、TestPgDumper*(环境缺少 sh)、TestOllamaProbeCallback_StaleLongDoesNotOverrideNewShort;这些用例在未修改的 main 上同样失败。

同一请求的首次 403 只换号并暂缓账号处理;另一账号成功后再按原有策略回补,两个不同账号都返回 403 时判为请求级,返回固定 400 INVALID_ARGUMENT,账号状态保持不变。原生、Messages 兼容和 Chat Completions 兼容入口均适用;403 不再在重试循环内写入临时不可调度状态。
@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

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

@Henglie

Henglie commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA

github-actions Bot added a commit that referenced this pull request Nov 12, 2026
Warren-W pushed a commit to Warren-W/sub2api that referenced this pull request Nov 20, 2026
Warren-W added a commit to Warren-W/sub2api that referenced this pull request Nov 20, 2026
Warren-W pushed a commit to Warren-W/sub2api that referenced this pull request Nov 20, 2026
Warren-W added a commit to Warren-W/sub2api that referenced this pull request Nov 20, 2026
xiaoguai1818 pushed a commit to xiaoguai1818/sub2api that referenced this pull request Nov 21, 2026
Restore Antigravity Responses custom-tool roundtrips and correct Embeddings platform scheduling. Harden OAuth probe fencing, request-scoped Gemini 403 behavior, OpenAI stream failover and WebSocket current-turn safety.

Preserve Claude/GPT-6.2/Grok protocol details and model observations; correct Fable/Kimi quota refreshes and user-vs-account cost reporting. Bound scheduler fallback, request memory retention and shutdown/stream lifecycles without unapproved pricing or schema changes.

Local checks: complete Go unit packages, PostgreSQL 18.1/Redis 8.4 repository and audit integration, focused -race, frontend typecheck/lint/1858 Vitest/build, backend lint 0 issues and embedded server build. Remote CI/Security Scan remain pending.

Upstream references: Wei-Shaw/sub2api Wei-Shaw#8833 Wei-Shaw#8875 Wei-Shaw#8856 Wei-Shaw#8730 Wei-Shaw#8990 Wei-Shaw#8806 Wei-Shaw#8832 Wei-Shaw#8809 Wei-Shaw#8164 Wei-Shaw#8804 Wei-Shaw#8773 Wei-Shaw#8309.
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.

Gemini 平台:请求内容导致的 403 会被换号重放,一个坏请求即可让分组内所有 Gemini 账号被停用

1 participant