Skip to content

feat(openai): add scheduled account warmup for codex oauth accounts - #192

Merged
zyycn merged 2 commits into
zyycn:mainfrom
2han9wen71an:feat/codex-account-warmup
Sep 24, 2026
Merged

zyycn merged 2 commits into
zyycn:mainfrom
2han9wen71an:feat/codex-account-warmup

Conversation

@2han9wen71an

Copy link
Copy Markdown
Contributor

功能说明

针对 OpenAI Codex 账号的 5h 与周线双层配额窗口机制,新增 OAuth 账号每日预激活(Warmup) 功能:

  1. 机制背景:

    • 上游 5h 窗口倒计时只有在账号发起首个有效请求时才会启动。在多账号轮换池中,“用尽切号”会导致备用账号的 5h 倒计时延迟启动,无法并行恢复。
    • 每日预激活通过在预设时间向账号发起极轻量的请求,提前并行启动池内所有账号的 5h 配额计时器,从而显著提高每日有效可用额度。
  2. 核心实现:

    • 数据库迁移:0017_account_warmup.sql 在 runtime_settings 增加 account_warmup_enabled、account_warmup_schedule_time(默认 08:00,支持逗号分隔多个时间点)、account_warmup_model。
    • 安全保护策略:
      • 跳过已有活跃 5h 窗口且距重置时间 > 30 分钟的账号,避免浪费 token。
      • 跳过周线已耗尽(limit_reached 或 used_percent >= 100%)的账号。
      • 仅对有效 OAuth 账号生效,跳过已禁用/封禁账号。
      • 极简 payload:store: false、reasoning.effort: none、text.verbosity: low、service_tier: default,不污染会话历史。
      • 账号间增加 2 秒平滑错峰间隔,避免突发并发 429。
    • 被动额度同步:请求返回后自动复用 synchronize_passive_headers 更新最新的 5h 与周线配额快照。
    • 前端界面:在系统设置中新增「账号预激活(Warmup)」卡片,支持图形化配置开关、时间与模型。

验证情况

  • cargo check --workspace 通过
  • cargo test --workspace --no-run 通过
  • cargo test -p gateway-core -p gateway-admin -p gateway-api -p provider-openai 单元测试通过
  • pnpm run typecheck & pnpm run build 前端构建通过
  • pnpm run lint 前端代码校验通过

2han9wen71an added a commit to 2han9wen71an/codex-proxy-rs that referenced this pull request Sep 22, 2026
# Conflicts:
#	backend/migrations/.frozen-sha256
zyycn added a commit that referenced this pull request Sep 24, 2026
@zyycn
zyycn merged commit a7f7cdc into zyycn:main Sep 24, 2026
9 checks passed
zyycn pushed a commit that referenced this pull request Sep 24, 2026
Co-authored-by: Zyy <zyycn@users.noreply.github.com>

Co-authored-by: Codex <noreply@openai.com>
zyycn added a commit that referenced this pull request Sep 24, 2026
Integrate PR #276 on the current main baseline. Keep local connection
capacity failures out of upstream retry and WebSocket breaker accounting.
Keep existing settings assertions valid when the #192 migration adds columns.

Source-commit: f9828a5

Co-authored-by: Zyy <zyycn@users.noreply.github.com>
Co-authored-by: Codex <noreply@openai.com>
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