Skip to content

fix(openai): unify OAuth expiry and recover HTTP/WS 401 once - #8034

Open
jaxxjj wants to merge 4 commits into
Wei-Shaw:mainfrom
jaxxjj:codex/openai-oauth-complete-recovery
Open

jaxxjj wants to merge 4 commits into
Wei-Shaw:mainfrom
jaxxjj:codex/openai-oauth-complete-recovery

Conversation

@jaxxjj

@jaxxjj jaxxjj commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

OAuth accounts imported without expires_at can keep using an expired access token: the provider requests a refresh, but the executor skips it unless the account is rate limited. A cached stale token or a rejected WebSocket handshake then leaves the request unable to recover.

  • Share the expiry rule between provider and executor. Prefer stored expiry, fall back to JWT exp, and refresh unknown expiry when a refresh token exists. Cache hits follow the same rule; JWT decoding does not authenticate a token.
  • Recover one eligible 401 through the existing OAuthRefreshAPI locks, durable reread and credential persistence. Reuse concurrent refresh winners; retain cancellation, proxy/owner and credential eligibility checks. Cover HTTP, pooled WS ingress, WS v2 forwarding and WS passthrough before any generation frame is sent.
  • Keep request payloads and continuation affinity intact. Revoked/scope failures, non-OAuth credentials and a second rejection retain existing handling. Gateway, token and WS helpers live in their existing owner files; tests use upstream's canonical OAuth model.

Related to #5542. Includes r266-tech's two HTTP recovery commits from #7826 (c737c7790, 387264922) with original author attribution, plus the missing-expiry and WS fixes. This PR is independently based on main.

Validation (Go 1.27.2, backend):

  • Full go test ./..., unit and integration suites passed for the functional change.
  • After file/owner/comment cleanup, go test -race -tags=unit ./internal/service -run '^TestOpenAIOAuth(Expiry|401)' -count=1 and CI-pinned golangci-lint 2.14.0 passed again.
  • Covers expired/fresh/malformed JWTs, cached stale credentials, concurrent winners, account changes, every WS entry path, second rejection, strict affinity and generation delivery exactly once.

The existing process-wide heap bound test failed once during concurrent suite execution; three isolated repetitions and the standalone full unit suite passed. Tests use synthetic credentials and local upstreams; no live OAuth refresh was performed. No schema or configuration change is required. AI-assisted implementation and validation.

@jaxxjj
jaxxjj marked this pull request as ready for review October 12, 2026 08:20
riofutab added a commit to riofutab/sub2api that referenced this pull request Oct 14, 2026
- 缺少 expires_at 的 OAuth 账号按 JWT exp 判断过期,有 refresh token 时提前刷新,缓存命中同样适用
- HTTP、WS 入口与 WS v2 转发遇到 401 时经现有刷新锁刷新一次后重试,第二次拒绝保持原处理
- 该 PR 已包含上游 Wei-Shaw#7826,删除 fork 中 Wei-Shaw#7826 的 openai_oauth_401_retry.go 及其两个测试文件,调用改为 tryRefreshOpenAIOAuth401

测试:service 包 OAuth、token 刷新与 WS 相关单测通过。
riofutab added a commit to riofutab/sub2api that referenced this pull request Oct 14, 2026
- OpenAI/Codex 稳定性:OAuth 缺过期时间时按 JWT 判定并在 WS 上恢复 401(Wei-Shaw#8034,替换 fork 原有的 Wei-Shaw#7826 实现)、模型拒绝不计入调度错误率(Wei-Shaw#8013)、首包前预算耗尽换号(Wei-Shaw#8005)、Sol 别名误判修正(Wei-Shaw#8063)
- 流与协议:原生 Claude 转 Chat 转发心跳(Wei-Shaw#8052)、Codex 流式出图兼容 JSON 响应(Wei-Shaw#8028)、Antigravity 工具结果图片(Wei-Shaw#8045)
- 用量显示:5h 换窗保留未到期周额度(Wei-Shaw#7990)、缓存命中率口径修正与单次命中率显示(Wei-Shaw#8018、Wei-Shaw#7995)

测试:go test -tags=unit ./... 全部通过,golangci-lint 0 issues;前端 make test-frontend 通过;集成测试交 CI。
riofutab added a commit to riofutab/sub2api that referenced this pull request Nov 13, 2026
- Claude 链路:令牌轮换后 401 同账号重试,per-turn beta 保留轮次输出配置,Stainless 版本头与抬升后的 UA 对齐(Wei-Shaw#8737 Wei-Shaw#8742 Wei-Shaw#8731 Wei-Shaw#8726 Wei-Shaw#8724 Wei-Shaw#8698)。
- Codex/OpenAI 链路:Desktop 独立上下文原样转发并删除 fork 的 bootstrap 扫描器,分叉会话沿用父会话缓存键,刷新后的令牌在补充信息超时时仍保存(Wei-Shaw#8680 Wei-Shaw#8664 Wei-Shaw#8671 Wei-Shaw#8735 Wei-Shaw#8682 Wei-Shaw#8703)。
- 构建:Go 升到 1.27.4 修复 GO-2026-6859(Wei-Shaw#8670);前端 Gemini 用量条刷新不再跳动(Wei-Shaw#8740)。
- fork 带的 Wei-Shaw#8034 测试改为断言轮换后的凭据被保存,并为测试桩补齐 CAS 方法。
- 后端全量 unit、golangci-lint、前端 lint/typecheck/账号组件测试通过;repository 集成测试未跑。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants