47ccdeb737 fix(openai): preserve OAuth recovery and token rotation (#853)
* fix(openai): refresh OAuth tokens rejected before expiry

A 401 on a model request marked a refreshable OAuth account Expired when
its access token had not reached its expiry. Expired accounts are left out
of both selection and scheduled refresh, so the account stayed out of
rotation until it was refreshed by hand, even though the refresh token was
still valid.

Expire the rejected access token instead and let the OAuth worker renew
it, as quota refresh already does for token_revoked. A renewed token that
is rejected again before any successful request still marks the account
Expired.

Constraint: Accounts without a refresh token or a known expiry keep the existing Expired outcome
Rejected: Match the "status=503" text inside the 401 body | free-text matching, and other 401s on unexpired tokens would still strand the account
Rejected: Refresh on every 401 without a bound | an account whose renewed tokens keep failing would refresh in a loop
Confidence: high
Scope-risk: narrow
Tested: Rust 1.99.1 fmt --check; clippy -p provider-openai --all-targets --all-features -D warnings; provider-openai tests (1264 passed); the new selector case and the adapter case fail without the selector change
Not-tested: A live upstream 401 against this build; workspace-wide clippy and tests are left to CI

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

* fix(openai): preserve OAuth recovery across concurrent feedback

Report success from native endpoints and upstream adapters, and keep stale
responses from clearing the current OAuth recovery bound. Serialize model
401 and Cookie feedback with token refresh through the account lease.
Recheck credential revisions after acquiring scheduled and manual refresh
leases so a queued snapshot cannot resend an already rotated refresh token.

Cookie feedback skips writes while refresh owns the lease; a later response
can capture cookies without discarding successfully exchanged tokens.

Validated: workspace fmt and strict Clippy; 1265 provider-openai tests;
48 gateway architecture and bootstrap tests. Real upstream and store service
integration remain for live verification and CI.

Co-authored-by: Codex <noreply@openai.com>

* fix(openai): retain token recovery across cookie revisions

Use the access token and revision that were sent upstream to recognize a successful OAuth request after a concurrent cookie write. Keep account and quota recovery fenced by revision, and preserve newer rejection records and replies from superseded tokens.

Co-authored-by: Codex <noreply@openai.com>

* fix(openai): preserve account feedback across cookie writes

Reset consecutive Cloudflare failures on a successful request using the current access token. Keep quota and account state fenced by the response revision. A model 401 can shorten expiry while the cookie writer holds the refresh lease; a conflicting write is retried only for the same token.

Co-authored-by: Codex <noreply@openai.com>

* test(openai): separate risk counters from OAuth rejection

Verify that a successful request using the rejected token breaks a path-block streak without allowing a refreshed token to be rejected indefinitely.

Co-authored-by: Codex <noreply@openai.com>

---------

Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
Co-authored-by: Zyy <zyycn@users.noreply.github.com>
Co-authored-by: Codex <noreply@openai.com>
2026-12-05 14:00:11 +08:00

Codex Proxy RS

Codex Proxy RS

多平台自托管多账号 AI 网关

CI Release GHCR License: Apache 2.0

快速预览 · 快速开始 · 文档 · 贡献者 · Star History · 社区 · 支持项目 · 许可证

Note

支持 OpenAI(Codex)、xAI(Grok)和 Google Antigravity 账号,以及兼容 OpenAI Responses 或 Anthropic Messages 的 API Key 服务,详见账号接入

快速预览

登录信息 默认值
地址 https://codex-proxy-rs.ainz.cc
账号 admin@cpr.local
密码 039c18de2aeac46d23ead7766bb07bbbe3747233c66a128e

快速开始

在已安装 Docker Engine、Docker Compose Plugin、curl 和 OpenSSL 的 Linux amd64/arm64 主机上运行

curl -fsSL https://raw.githubusercontent.com/zyycn/codex-proxy-rs/main/deploy/install.sh -o install.sh && bash install.sh

安装脚本选项 · macOS 发行包 · Windows 安装 · 已有部署升级

文档

主题 文档
部署与使用 部署、备份与恢复 · 客户端接入
接口集成 API 参考 · 模型目录 · 模型定价
使用插件 安装、配置与使用
开发插件 SDK 与合同 · 打包工具 · 官方示例
开发共用组件 组件库说明 · 组件参考 · Playground
开发宿主 开发与源码联调 · 系统架构 · 管理端主题 · 数据库迁移
参与协作 贡献、审查与验证

贡献者

查看 GitHub 贡献者列表

Star History

Codex Proxy RS 的 GitHub Star 增长趋势

社区

点击或扫码加入 Telegram 群 小酒馆

扫码加入小酒馆 Telegram 群

问题反馈与功能建议请使用 GitHub Issues,填写要求见 贡献说明

感谢 LINUX DO 社区提供开放、友善的技术交流平台

支持项目

如果 Codex Proxy RS 帮助到你了,欢迎请我喝杯咖啡 ☕

Support me on Ko-fi

WeChat appreciation code  Alipay QR code

许可证

本项目基于 Apache License 2.0 开源

S
Description
基于 Rust 的低风控、高性能、自托管多账号透明代理网关
Readme Apache-2.0
56 MiB
0 Stars 1 Watchers 0 Forks
Languages
Rust 90.4%
Vue 5.5%
TypeScript 3.4%
PLpgSQL 0.5%
Ruby 0.1%