ianshaw
25b00abca1
fix(网关): 修复账号选择中的调度器快照延迟问题
## 问题描述
调度器快照更新存在0.5-1秒的延迟(Outbox轮询间隔),导致在账号被限流或过载后的短时间窗口内,
可能仍会被选中,造成请求失败。
## 根本原因
账号选择逻辑依赖调度器快照(listSchedulableAccounts),但快照更新有延迟:
- Outbox轮询: 每1秒检查一次变更事件
- 全量重建: 每300秒重建一次
- 时间窗口: 账号状态变更后0.5-1秒内,快照可能未更新
## 解决方案
在账号选择循环中添加IsSchedulable()实时检查,作为第二道防线:
1. 第一道防线: 调度器快照过滤(可能有延迟)
2. 第二道防线: IsSchedulable()实时检查(本次修复)
IsSchedulable()会检查:
- RateLimitResetAt: 限流重置时间
- OverloadUntil: 过载持续时间
- TempUnschedulableUntil: 临时不可调度时间
- Status: 账号状态
- Schedulable: 可调度标志
## 修改范围
### OpenAI Gateway Service
- SelectAccountForModelWithExclusions: 添加IsSchedulable()检查
- SelectAccountWithLoadAwareness: 添加IsSchedulable()检查
### Gateway Service (Claude/Gemini/Antigravity)
- 负载感知选择候选账号筛选: 添加IsSchedulable()检查
- selectAccountForModelWithPlatform: 添加IsSchedulable()检查
- selectAccountWithMixedScheduling: 添加IsSchedulable()检查
### 测试用例
- OpenAI: 添加2个测试用例验证限流账号过滤
- Gateway: 添加2个测试用例验证限流和过载账号过滤
### 其他修复
- ops_repo_preagg.go: 修复platform为NULL时的聚合问题
## 测试结果
所有单元测试通过 ✅
2026-01-13 22:49:26 -08:00
..
2026-01-13 11:14:32 +08:00
2026-01-07 16:59:35 +08:00
2025-12-26 16:45:40 +08:00
2026-01-09 22:00:14 +08:00
2026-01-09 22:00:14 +08:00
2026-01-12 13:29:04 -08:00
2026-01-06 22:19:07 +08:00
2026-01-07 16:59:35 +08:00
2026-01-11 20:22:17 +08:00
2026-01-01 18:59:38 +08:00
2026-01-10 09:39:02 +08:00
2026-01-10 10:00:49 +08:00
2026-01-09 19:43:19 +08:00
2026-01-11 10:55:25 +08:00
2026-01-11 20:39:15 +08:00
2026-01-05 00:56:48 +08:00
2026-01-13 09:39:43 +08:00
2026-01-05 17:14:06 +08:00
2026-01-03 06:29:02 -08:00
2025-12-31 10:33:00 +08:00
2026-01-03 06:29:02 -08:00
2026-01-09 22:00:14 +08:00
2025-12-31 16:25:45 +08:00
2025-12-31 23:37:51 +08:00
2026-01-11 10:55:25 +08:00
2026-01-11 10:55:25 +08:00
2026-01-11 10:55:25 +08:00
2026-01-11 10:55:25 +08:00
2026-01-11 10:55:25 +08:00
2026-01-11 10:55:25 +08:00
2026-01-09 21:59:32 +08:00
2026-01-11 10:55:26 +08:00
2026-01-10 13:23:03 +08:00
2026-01-12 09:14:32 +08:00
2025-12-25 17:15:01 +08:00
2025-12-31 08:50:12 +08:00
2026-01-04 22:10:32 +08:00
2026-01-05 17:07:29 +08:00
2026-01-05 17:07:29 +08:00
2026-01-08 23:07:00 +08:00
2026-01-03 06:32:51 -08:00
2026-01-05 14:41:08 +08:00
2026-01-11 18:20:15 +08:00
2026-01-12 10:59:52 +08:00
2026-01-11 18:20:15 +08:00
2026-01-12 10:53:41 +08:00
2025-12-28 09:49:54 +08:00
2026-01-11 21:54:52 -08:00
2025-12-18 13:50:39 +08:00
2026-01-09 14:49:20 +08:00
2026-01-13 22:49:26 -08:00
2026-01-04 10:45:18 +08:00
2026-01-05 00:56:48 +08:00
2026-01-04 18:26:39 -08:00
2025-12-31 08:50:12 +08:00
2026-01-13 22:49:26 -08:00
2026-01-01 04:21:18 +08:00
2026-01-12 14:19:06 +08:00
2026-01-10 09:39:02 +08:00
2026-01-08 23:47:29 +08:00
2026-01-08 23:47:29 +08:00
2025-12-26 00:11:03 -08:00
2026-01-04 15:36:00 +08:00
2025-12-26 00:11:03 -08:00
2026-01-01 04:29:22 +08:00
2025-12-31 16:25:45 +08:00
2025-12-26 00:11:03 -08:00
2026-01-11 10:55:25 +08:00
2026-01-05 17:07:29 +08:00
2026-01-10 08:40:27 +08:00
2025-12-31 11:43:58 +08:00
2025-12-25 17:15:01 +08:00
2025-12-27 20:42:00 +08:00
2026-01-13 17:22:57 +08:00
2026-01-13 17:02:31 +08:00
2026-01-13 22:49:26 -08:00
2026-01-13 22:49:26 -08:00
2025-12-26 16:45:40 +08:00
2026-01-13 16:47:35 +08:00
2026-01-13 16:47:35 +08:00
2026-01-11 20:33:52 +08:00
2026-01-10 01:38:47 +08:00
2026-01-10 01:38:47 +08:00
2026-01-11 20:55:44 +08:00
2026-01-11 20:56:02 +08:00
2026-01-11 23:57:20 +08:00
2026-01-09 20:53:44 +08:00
2026-01-11 23:57:20 +08:00
2026-01-09 20:53:44 +08:00
2026-01-10 01:38:47 +08:00
2026-01-10 01:38:47 +08:00
2026-01-09 20:53:44 +08:00
2026-01-11 21:42:02 +08:00
2026-01-11 21:42:02 +08:00
2026-01-09 20:53:44 +08:00
2026-01-11 23:00:31 +08:00
2026-01-11 15:30:27 +08:00
2026-01-12 17:06:12 +08:00
2026-01-09 20:53:44 +08:00
2026-01-09 20:52:17 +08:00
2026-01-12 14:17:42 +08:00
2026-01-12 14:17:42 +08:00
2026-01-09 20:53:44 +08:00
2026-01-11 23:57:20 +08:00
2026-01-11 23:57:20 +08:00
2026-01-11 23:26:29 +08:00
2026-01-11 20:33:52 +08:00
2026-01-12 17:18:49 +08:00
2026-01-12 17:18:49 +08:00
2026-01-09 20:52:17 +08:00
2026-01-12 00:02:19 +08:00
2026-01-11 23:26:29 +08:00
2026-01-09 20:53:44 +08:00
2026-01-06 10:49:26 +08:00
2026-01-10 13:14:35 +08:00
2026-01-10 13:14:35 +08:00
2026-01-11 10:55:25 +08:00
2026-01-08 21:20:12 +08:00
2025-12-26 16:45:40 +08:00
2026-01-03 06:29:02 -08:00
2026-01-12 15:26:14 +08:00
2025-12-26 16:45:40 +08:00
2026-01-11 10:55:26 +08:00
2026-01-12 14:19:06 +08:00
2026-01-12 14:19:06 +08:00
2026-01-12 14:19:06 +08:00
2026-01-12 14:19:06 +08:00
2026-01-11 22:09:35 -08:00
2025-12-26 16:45:40 +08:00
2026-01-11 22:09:35 -08:00
2025-12-31 23:42:01 +08:00
2026-01-11 21:54:52 -08:00
2025-12-28 09:49:54 +08:00
2026-01-04 15:59:21 +08:00
2026-01-04 19:28:20 +08:00
2025-12-31 16:25:45 +08:00
2025-12-31 23:42:01 +08:00
2026-01-04 19:28:20 +08:00
2026-01-09 21:59:32 +08:00
2026-01-11 10:55:25 +08:00
2026-01-03 06:37:08 -08:00
2026-01-01 18:58:34 +08:00
2026-01-11 10:55:25 +08:00
2025-12-26 16:45:40 +08:00
2025-12-26 16:45:40 +08:00
2026-01-04 19:28:20 +08:00
2026-01-12 14:50:53 +08:00