fix: OAuth 401 不再永久锁死账号,改用临时不可调度实现自动恢复#723
Open
zqq-nuli wants to merge 1 commit intoWei-Shaw:mainfrom
Open
Conversation
OAuth 账号收到 401 时,原逻辑同时设置 expires_at=now() 和 SetError(), 但刷新服务只查询 status=active 的账号,导致 error 状态的账号永远无法 被刷新服务拾取,expires_at=now() 实际上是死代码。 修复: - OAuth 401 使用 SetTempUnschedulable 替代 SetError,保持 status=active - 新增 oauth_401_cooldown_minutes 配置项(默认 10 分钟) - 刷新成功后同步清除 DB 和 Redis 中的临时不可调度状态 - 不可重试错误检查(invalid_grant 等)从 Antigravity 推广到所有平台 - 可重试错误耗尽后不再标记 error,下个刷新周期继续重试 恢复流程: OAuth 401 → temp_unschedulable + expires_at=now → 刷新服务拾取 → 成功: 清除 temp_unschedulable → 自动恢复 → invalid_grant: SetError → 永久禁用 → 网络错误: 仅记日志 → 下周期重试
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.
Summary
expires_at=now()和SetError(),但TokenRefreshService.listActiveAccounts()只查询status=active的账号,导致 error 状态的账号永远无法被刷新服务拾取,expires_at=now()实际上是死代码SetTempUnschedulable替代SetError,保持status=active,让刷新服务能自动恢复账号Changes
oauth_401_cooldown_minutes配置项(默认 10 分钟)SetTempUnschedulable替代handleAuthError/SetError;非 OAuth 账号(APIKey)行为不变isNonRetryableRefreshError检查从 Antigravity 推广到所有平台SetError,下个刷新周期继续重试TempUnschedCache到TokenRefreshService恢复流程
Test plan
ratelimit_service_401_test.go: OAuth 401 调用 SetTempUnschedulable(非 SetError)ratelimit_service_401_test.go: 非 OAuth(APIKey)401 行为不变token_refresh_service_test.go: 刷新成功清除 temp_unschedulable(DB + Redis)token_refresh_service_test.go: 所有平台不可重试错误 SetErrortoken_refresh_service_test.go: 可重试错误耗尽不标记 errorgo test -tags unit ./internal/service/ -run "401|TokenRefresh" -v