[Feature]: fair session ring across Anthropic OAuth, API keys, and Codex API pools

Đang mở
#8,178 4 bình luận 1 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
25/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
typescript

Hướng nghiên cứu

Start with the existing affinity and pool-session files named in the issue, then read the related issues #7738, #8098, and #7813 to understand the existing binding behavior. The request spans Anthropic OAuth, API-key pools, and Codex API pools, with persistence, failure handling, configuration, and diagnostics. Done means an opt-in ring assigns new sessions fairly, preserves session bindings across turns and restarts, and follows the listed quota and credential lifecycle rules.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

account-pool enhancement needs-info
Area

Authentication and account pool

What are you trying to accomplish?

We want fair, session-pinned rotation for new sessions across Anthropic OAuth accounts, Anthropic API-key pool entries, and Codex pool accounts. One session should stay on one credential while new sessions are spread evenly. This should work for Claude Code and Codex API clients.

What prevents this today?

Round-robin chooses a new account per request, and affinity only binds after a session key exists. There is no shared ring that assigns new sessions fairly and keeps each session pinned across the Anthropic OAuth pool, single-key Anthropic providers, and the Codex pool. Existing pieces are partial:

  • Anthropic OAuth affinity persists bindings (src/oauth/anthropic-session-affinity-store.ts).
  • The Claude Messages bridge now has a pool session (src/server/claude-bridge-pool-session.ts).
  • Codex pool pins survive restarts (#8098).
  • API-key cache affinity is proposed in #7738.
  • None of these provides one fair ring across those credential families, including Codex API clients.

We run a local anthropic-session-ring patch for the Anthropic side and want to retire it once upstream provides the behavior.

What should OpenCodex do?

Add an opt-in per-provider session ring:

  • Maintain an ordered ring of eligible credentials.
  • Assign each new session to the next eligible credential.
  • Keep the session on that credential across turns and proxy restarts.
  • On a credential failure, cooldown, pause, reauthentication, or removal, advance the ring and rebind once.
  • Preserve existing bindings and quota rules.
  • Include Anthropic OAuth accounts, Anthropic API-key pool entries, and Codex pool accounts (Codex API/Responses).
  • Use a bounded idle TTL and entry cap.
  • Expose the selected credential and ring position in request logs or diagnostics.
Example usage or interface
{
  "providers": {
    "anthropic": {
      "sessionRing": { "enabled": true, "idleTtlMs": 86400000 }
    },
    "codex": {
      "sessionRing": { "enabled": true, "idleTtlMs": 86400000 }
    }
  }
}
ocx account pool anthropic --session-ring on
ocx account pool codex --session-ring on
Alternatives or workarounds

Round-robin without a ring moves a session between accounts. Affinity alone does not spread new sessions fairly across credential types. Running one credential per proxy instance avoids the problem but loses pool capacity.

Additional context

Related: #3375 (generic OAuth pool lifecycle), #7738 (API-key cache affinity), #8098 (Codex pool pins across restart), #8092 (round-robin quota headroom), #7813 (Anthropic affinity persistence). This request is the fair ring plus one-session-one-credential contract, including Codex API.

Checks
  • I searched existing issues and documentation.
  • This request describes a concrete OpenCodex workflow rather than merely naming a desired technology.
  • I removed secrets and personal data.
Ngôn ngữ chính
TypeScript
Star
16.9k
Fork
1.3k
Merge trung bình
1 ngày 4 giờ
Pull request đã merge (30 ngày)
814

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của lidge-jun/opencodex

Tất cả issue của lidge-jun/opencodex

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.