fix: 后台自动刷新纳入 setup-token 账号

setup-token 的 access_token 同为 8h 短期令牌(expires_in=28800),
此前被后台刷新服务排除,到期后请求返回 401 authentication_error。
放开 CanRefresh 与候选查询的 type='oauth' 限制,与手动刷新入口
(account.IsOAuth()) 保持一致;实际刷新仍由 NeedsRefresh 基于
expires_at 门控并在分布式锁下执行,不会过度刷新。
This commit is contained in:
Shumin
2026-07-09 11:05:05 -04:00
parent 1a3cc2a787
commit 99da308196
2 changed files with 7 additions and 5 deletions
+1 -1
View File
@@ -729,7 +729,7 @@ func (r *accountRepository) ListOAuthRefreshCandidates(ctx context.Context) ([]s
FROM accounts
WHERE deleted_at IS NULL
AND status = 'active'
AND type = 'oauth'
AND type IN ('oauth', 'setup-token')
AND platform IN ('anthropic', 'openai', 'gemini', 'antigravity')
AND credentials ? 'refresh_token'
AND btrim(credentials->>'refresh_token') <> ''
+6 -4
View File
@@ -38,11 +38,13 @@ func (r *ClaudeTokenRefresher) CacheKey(account *Account) string {
}
// CanRefresh 检查是否能处理此账号
// 只处理 anthropic 平台的 oauth 类型账号
// setup-token 虽然也是OAuth,但有效期1年,不需要频繁刷新
// 处理 anthropic 平台的 oauth 与 setup-token 类型账号。
// 两者的 access_token 均为短期令牌(expires_in=28800,即 8h),到期都需刷新;
// setup-token 之前被排除会导致其 access_token 过期后请求 401。
// 此处与手动刷新入口(account.IsOAuth())保持一致,实际是否刷新由 NeedsRefresh
// 基于 expires_at 门控,并在分布式锁保护下执行,不会造成过度刷新。
func (r *ClaudeTokenRefresher) CanRefresh(account *Account) bool {
return account.Platform == PlatformAnthropic &&
account.Type == AccountTypeOAuth
return account.Platform == PlatformAnthropic && account.IsOAuth()
}
// NeedsRefresh 检查token是否需要刷新