Repository navigation
fix(gemini): Vertex SA 已删除时停用账号并换号,401 临时不可调度规则首次命中不再永久停用 - #8076
Merged
Wei-Shaw merged 2 commits intoOct 15, 2026
Merged
Conversation
- 换取 SA access token 时 token 端点返回 400
{"error":"invalid_grant","error_description":"Invalid grant: account not found"}
表示服务账号已被删除,凭据再也换不到 token;此前三条 Gemini 转发路径把它当作
本地构造请求失败直接回 502,不换号也不改账号状态,账号持续被调度
- 识别该错误后账号置为 error 并停止调度(Service account token rejected (400): …),
记录凭据获取阶段(stage=account_auth)的 Ops 事件,请求交给 handler 换号
- 只匹配 400 + invalid_grant + account not found:invalid_grant 还涵盖时钟偏差、
签名无效等情况,其他换 token 失败保持原行为
- token 端点地址改为包级变量,测试中替换为本地服务
- 三条 Gemini 转发路径在重试循环内和循环外各对最终上游错误响应检查一次错误策略。 配了账号级 401 临时不可调度规则的 API Key / Vertex 账号首次收到 401 时,第一次 检查写入 401 暂停记录,第二次检查读回该记录判定为重复 401,同一请求内即升级为 error 永久停用 - 循环内的检查结果带到循环外复用;循环内未检查的最终响应(Claude 兼容层的签名 400 分支、原生路径的 cachedContent 透传分支)仍在循环外检查
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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
背景
修复 Gemini 账号停用判定的两个问题,分两个提交。
400 {"error":"invalid_grant","error_description":"Invalid grant: account not found"}。三条转发路径把它当成本地构造请求失败直接回 502,账号一直可调度。生产上出现过恢复账号后一小时内持续产生数千次 502 的情况。SetError。改动
invalid_grant还涵盖时钟偏差等情况,不放宽)。命中后把账号置为 error 并停止调度,Ops 事件按stage=account_auth记录,返回 401 failover 换号。其他换 token 失败保持现状。行为变化
/v1/messages路径为 502,/v1/chat/completions路径为 401。测试
新增 unit 用例覆盖三条转发路径:SA 已删除时停号并换号、其他
invalid_grant不受影响、首次 401 只临时不可调度(在 main 上会失败)、重复 401 升级为error、循环内未检查的响应在循环外检查。
go test -tags=unit ./internal/service/ ./internal/handler/...通过,golangci-lint v2.14.0 无问题。