fix(openai): trigger account failover on passthrough 403 forbidden_error#2213
Open
Nimm0ny wants to merge 1 commit intoWei-Shaw:mainfrom
Open
fix(openai): trigger account failover on passthrough 403 forbidden_error#2213Nimm0ny wants to merge 1 commit intoWei-Shaw:mainfrom
Nimm0ny wants to merge 1 commit intoWei-Shaw:mainfrom
Conversation
OpenAI passthrough mode (OAuth-bridged Codex / ChatGPT subscription accounts)
previously only failed over on 429/529, returning upstream 403 unchanged to
the client. This means a Codex usage-limit-reached response (403 with
{"error": {"type": "forbidden_error"}}) would terminate the user's request
even though the same group has other healthy accounts available.
Add http.StatusForbidden to shouldFailoverOpenAIPassthroughResponse so the
existing handler.FailoverState loop kicks in. Test coverage extended:
oauth_403_temp_unschedulable verifies the account is temp-unscheduled with
"OpenAI 403 temporary cooldown" reason (10min) + IncrementOpenAI403Count
threshold (3 strikes before hard-disable) — same shape as the 429/529
paths, no new state machine.
Verified locally with go test; ready to send upstream as a separate PR.
Contributor
|
Thank you for your contribution! Before we can merge this PR, we need you to sign our Contributor License Agreement (CLA). To sign, please reply with the following comment:
You only need to sign once — it will be valid for all your future contributions to this project. I have read the CLA Document and I hereby sign the CLA You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot. |
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
问题
OpenAI passthrough 模式(走 OAuth 桥接的 Codex / ChatGPT 订阅账号)的失败转移决策函数
shouldFailoverOpenAIPassthroughResponse当前只把429和529当作可 failover 状态码:但 Codex / ChatGPT 订阅账号的"用量配额耗尽"信号实际是
403 forbidden_error(例如{"error": {"message": "usage limit reached", "type": "forbidden_error"}}),不是 429。这意味着:跟
shouldFailoverUpstreamError(用于非 passthrough 的标准模式)对比,后者已经包含case 401, 402, 403, 429, 529— passthrough 路径漏掉了 403。改动
shouldFailoverOpenAIPassthroughResponse增加http.StatusForbidden,让 passthrough 模式也能在 403 时触发handler.FailoverState循环。复用现有的 cooldown 状态机(
SetTempUnschedulable+IncrementOpenAI403Count),不引入新状态:SetError路径)测试
TestOpenAIGatewayService_OpenAIPassthrough_FailoverStatusesTriggerAccountSwitch增加oauth_403_temp_unschedulablecase,验证:repo.tempUnschedulableIDs == [123]until在 9 分钟之后(=10 分钟 cooldown)repo.tempUnschedulableWhy[0]包含"OpenAI 403 temporary cooldown"本地
go test ./internal/service -run TestOpenAIGatewayService_OpenAIPassthrough_FailoverStatusesTriggerAccountSwitch -count=1 -v全部通过(5 个 subcase)。兼容性
11cf23da提过同样思路)