feat(scheduling): add opt-in "prefer soonest reset" account selection

Adds a use-it-or-lose-it scheduling strategy: prefer accounts whose
session window resets soonest, so near-reset accounts get drained first
instead of accounts whose reset is still far away.

Both schedulers, opt-in, default behavior unchanged:

- Anthropic (gateway_service.go): new GatewaySchedulingConfig
  .PreferSoonestReset flag. When on, the layered load-aware selection
  inserts a filterBySoonestReset stage (priority -> soonest-reset ->
  load -> LRU). Accounts with no active SessionWindowEnd are treated as
  lowest priority; ties fall through to LRU.

- OpenAI/Codex (openai_account_scheduler.go): new "reset" score weight
  in GatewayOpenAIWSSchedulerScoreWeights. Soonest-reset accounts score
  higher; weight defaults to 0 (no effect).

SessionWindowEnd (upstream 5h/quota ResetsAt) is already carried in the
scheduler snapshot, so no snapshot changes are needed.

Documented in deploy/config.example.yaml. Adds unit tests for the
Anthropic filter and the OpenAI reset factor.
This commit is contained in:
kangjwme
2026-06-18 22:50:46 +08:00
parent 4a5665da5b
commit 510adf703c
6 changed files with 261 additions and 4 deletions
+7
View File
@@ -320,6 +320,9 @@ gateway:
queue: 0.7
error_rate: 0.8
ttft: 0.5
# use-it-or-lose-it:倾向「会话窗口最早重置」的账号,剩余重置时间越短得分越高。
# 0 表示关闭(默认,不改变原有行为);调大可让即将重置的账号被优先用尽。
reset: 0.0
# OpenAI 高级调度器补充配置
openai_scheduler:
# 是否允许 session_hash sticky 在账号健康度恶化时临时逃逸;false 可一键回退旧行为
@@ -421,6 +424,10 @@ gateway:
# Fallback max waiting queue size
# 兜底最大排队长度
fallback_max_waiting: 100
# Prefer the account whose session window resets soonest (use-it-or-lose-it).
# 负载感知选择时优先用尽「会话窗口最早重置」的账号;false 保持
# 原有「优先级 → 负载率 → LRU」行为(默认)。
prefer_soonest_reset: false
# Enable batch load calculation for scheduling
# 启用调度批量负载计算
load_batch_enabled: true