fix(codex): 配额刷新 401/403 不再自动禁用 key,区分软性请求失败与账户封禁

- 新增 OAUTH_REQUEST_FAILED_PREFIX 标记非 token 失效的 403 请求失败
- 引入 _merge_invalid_reason 合并逻辑,避免低优先级原因覆盖高优先级状态
- account_state 中 REFRESH_FAILED/REQUEST_FAILED 前缀不再触发封禁判定
- 401/403 返回 auto_disabled=False,不再直接设置 is_active=False
This commit is contained in:
fawney19
2026-03-16 01:12:35 +08:00
parent 131471a13f
commit 025e979935
4 changed files with 141 additions and 22 deletions

View File

@@ -137,3 +137,21 @@ def test_resolve_from_structured_oauth_reason_token_invalidated() -> None:
assert state.blocked is True
assert state.code == "oauth_expired"
assert state.label == "Token 失效"
def test_refresh_failed_prefix_does_not_block_even_with_scary_keywords() -> None:
state = resolve_pool_account_state(
provider_type="codex",
upstream_metadata=None,
oauth_invalid_reason="[REFRESH_FAILED] Token 续期失败 (401): account_deactivated",
)
assert state.blocked is False
def test_request_failed_prefix_does_not_block() -> None:
state = resolve_pool_account_state(
provider_type="codex",
upstream_metadata=None,
oauth_invalid_reason="[REQUEST_FAILED] Codex 账户访问受限 (403)",
)
assert state.blocked is False