yangjianbo
a5f29019d9
test(ops): 提升日志链路覆盖率并修复lint阻塞
2026-02-12 16:25:44 +08:00
yangjianbo
af3069073a
chore(lint): 修复 golangci-lint unused
...
- 移除 OpenAIGatewayHandler 未使用字段
- 删除并发缓存中未使用的 Redis 脚本常量
- 将仅供 unit 测试使用的 parseIntegralNumber 移入 unit build tag 文件
2026-02-12 14:20:56 +08:00
yangjianbo
65661f24e2
feat(ops): 运维监控新增 OpenAI Token 请求统计表
...
- 新增管理端接口 /api/v1/admin/ops/dashboard/openai-token-stats,按模型聚合统计 gpt% 请求
- 支持 time_range=30m|1h|1d|15d|30d(默认 30d),支持 platform/group_id 过滤
- 支持分页(page/page_size)或 TopN(top_n)互斥查询
- 前端运维监控页新增统计表卡片,包含空态/错误态与分页/TopN 交互
- 补齐后端与前端测试
2026-02-12 14:20:14 +08:00
yangjianbo
ed2eba9028
fix(gateway): 默认过滤OpenAI透传超时头并补充断流告警
2026-02-12 14:16:18 +08:00
yangjianbo
114e172603
test(repository): 补充 JWT 密钥引导并发与兼容性单测
2026-02-12 12:07:20 +08:00
yangjianbo
09c8380b3d
fix(repository): 修复 JWT 密钥引导冲突一致性与并发读取竞态
2026-02-12 12:04:13 +08:00
yangjianbo
9403aa9bd1
feat: version 0.1.74.4
2026-02-12 11:44:45 +08:00
yangjianbo
6b36992d34
feat(security): 启动时自动迁移并持久化JWT密钥
...
- 新增 security_secrets 表及 Ent schema 用于存储系统级密钥
- 启动阶段支持无 jwt.secret 配置并在数据库中自动生成持久化
- 在 Ent 初始化后补齐密钥并执行完整配置校验
- 增加并发与异常分支单元测试,覆盖密钥引导核心路径
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com >
2026-02-12 11:41:20 +08:00
yangjianbo
6533a4647d
fix(openai): 增强自动透传命中日志
2026-02-12 11:41:06 +08:00
yangjianbo
9c910c2049
feat(openai): 支持自动透传开关并透传 User-Agent
...
- OpenAI OAuth/API Key 统一支持自动透传开关,编辑页可开关\n- 透传模式仅替换认证并保留计费/并发/审计,修复 API Key responses 端点拼接\n- Usage 页面显示原始 User-Agent 且不截断,补充回归测试与清单
2026-02-12 10:56:07 +08:00
yangjianbo
61a2bf469a
feat(openai): 极致优化 OAuth 链路并补齐性能守护
...
- 优化 /v1/responses 热路径,减少重复解析与不必要拷贝\n- 优化并发与 token 竞争路径并补齐运行指标\n- 补充 OpenAI/Ops 相关单元测试与回归用例\n- 新增灰度阈值守护与压测脚本,支撑发布验收
2026-02-12 09:41:37 +08:00
yangjianbo
a88bb8684f
fix(openai): 修复 OAuth 透传流式断开与压缩头问题
...
- 透传流式在客户端断开后继续 drain 上游并解析 usage,避免计费信息丢失
- 阻断透传 accept-encoding,避免压缩响应影响 SSE/usage 解析
- 阻断 proxy-authorization,避免透传代理鉴权信息
- 补充回归测试:请求头阻断与断流后 usage 采集
2026-02-11 22:17:38 +08:00
yangjianbo
f1e884ce2b
feat(openai): 增加 OAuth 透传开关
...
- 仅对 Codex CLI 且账号开启时走原样透传(只替换认证)
- 透传模式禁用工具修正/模型替换,并旁路解析 usage 用于计费
- 管理后台增加开关与文案,ops upstream error 记录 passthrough 标记
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com >
2026-02-11 00:59:39 +08:00
yangjianbo
86f3124720
perf(service): 优化重试场景 thinking 过滤性能
...
- 避免全量 Unmarshal 请求体,改为仅解析 messages 子树
- 顶层 thinking 使用 sjson 直接删除,减少整体重写
- content 仅在需要修改时延迟分配 new slice
- 增加 FilterThinkingBlocksForRetry 基准测试
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com >
2026-02-11 00:47:26 +08:00
yangjianbo
4b309fa8b5
fix(gateway): 优化 ParseGatewayRequest 函数,使用 unsafe 提高性能并增加 JSON 校验
2026-02-10 22:12:24 +08:00
yangjianbo
166080b29c
chore: 更新版本号至 0.1.74.3
2026-02-10 18:02:02 +08:00
yangjianbo
3b0910f664
Merge branch 'main' into test-sora
2026-02-10 18:01:17 +08:00
yangjianbo
e489996713
test(backend): 补充改动代码单元测试覆盖率至 85%+
...
新增 48 个测试用例覆盖修复代码的各分支路径:
- subscription_maintenance_queue: nil receiver/task、Stop 幂等、零值参数 (+6)
- billing_service: CalculateCostWithConfig、错误传播、SoraImageCost 等 (+12)
- timing_wheel_service: Schedule/ScheduleRecurring after Stop (+3)
- sora_media_cleanup_service: nil guard、Start/Stop 各分支、timezone (+10)
- sora_gateway_service: normalizeSoraMediaURLs、buildSoraContent 等辅助函数 (+17)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com >
2026-02-10 17:52:10 +08:00
yangjianbo
54fe363257
fix(backend): 修复代码审核发现的 8 个确认问题
...
- P0-1: subscription_maintenance_queue 使用 RWMutex 防止 channel close/send 竞态
- P0-2: billing_service CalculateCostWithLongContext 修复被吞没的 out-range 错误
- P1-1: timing_wheel_service Schedule/ScheduleRecurring 添加 SetTimer 错误日志
- P1-2: sora_gateway_service StoreFromURLs 失败时降级使用原始 URL
- P1-3: concurrency_cache 用 Pipeline 替代 Lua 脚本兼容 Redis Cluster
- P1-6: sora_media_cleanup_service runCleanup 添加 nil cfg/storage 防护
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com >
2026-02-10 17:51:49 +08:00
程序猿MT
1dd3158c7e
Merge branch 'Wei-Shaw:main' into main
2026-02-10 13:55:51 +08:00
shaw
5dd83d3cf2
fix: 移除特定system以适配新版cc客户端缓存失效的bug
2026-02-10 10:28:34 +08:00
Wesley Liddick
14e1aac9b5
Merge pull request #533 from GuangYiDing/feat/antigravity-single-account-503-retry
...
feat: Antigravity 单账号分组 503 退避重试机制
2026-02-10 09:59:48 +08:00
yangjianbo
5d1c51a37f
fix(handler): 修复 gjson 迁移后的请求校验语义回退
...
- OpenAI handler: 添加 gjson.ValidBytes 校验 JSON 合法性;model 校验改为
检查 gjson.String 类型而非仅判断非空(拒绝 model:123 等非法类型);stream
字段添加 True/False 类型检查;sjson.SetBytes 返回值显式处理错误
- Sora handler: 添加 gjson.ValidBytes 校验;model 校验同上改为类型检查;
messages 校验从 Exists+Type==JSON 改为 IsArray+len>0(拒绝空数组和对象)
- 补充 TestOpenAIHandler_GjsonValidation 和更新 TestSoraHandler_ValidationExtraction
覆盖新增的边界校验场景
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com >
2026-02-10 09:13:20 +08:00
yangjianbo
58912d4ac5
perf(backend): 使用 gjson/sjson 优化热路径 JSON 处理
...
将 API 网关热路径中的 json.Unmarshal+json.Marshal 替换为 gjson 零拷贝查询和 sjson 精准写入:
- unwrapV1InternalResponse 性能提升 22x(4009ns→182ns),内存分配减少 28.5x
- unwrapGeminiResponse、extractGeminiUsage、estimateGeminiCountTokens、ParseGeminiRateLimitResetTime 改为接收 []byte 使用 gjson 提取
- ParseGatewayRequest 的 model/stream/metadata/thinking/max_tokens 改用 gjson 类型安全提取
- Handler 层(sora/openai)改用 gjson 提取字段、sjson 注入/修改字段,移除 map[string]any 中间变量
- Sora Client 响应解析改用 gjson ForEach 遍历,减少内存分配
- 新增约 100 个单元测试用例,所有改动函数覆盖率 >85%
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com >
2026-02-10 08:59:30 +08:00
yangjianbo
29ca1290b3
chore(test): 清理测试用例与类型导入
2026-02-10 00:37:56 +08:00
yangjianbo
3fcb0cc37c
feat(subscription): 有界队列执行维护并改进鉴权解析
2026-02-10 00:37:47 +08:00
Rose Ding
e4bc35151f
test: 添加单账号 503 退避重试机制的单元测试
...
覆盖 Service 层和 Handler 层的所有新增逻辑:
- isSingleAccountRetry context 标记检查
- handleSmartRetry 中 503 + SingleAccountRetry 分支
- handleSingleAccountRetryInPlace 原地重试逻辑
- antigravityRetryLoop 预检查跳过限流
- sleepAntigravitySingleAccountBackoff 固定延迟退避
- 端到端集成场景验证
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com >
2026-02-09 22:06:06 +08:00
yangjianbo
2bfb16291f
fix(unit): 修复 unit tag 测试编译与账号选择用例
2026-02-09 21:35:41 +08:00
Wesley Liddick
56da498b7e
Merge pull request #532 from touwaeriol/fix/clear-model-rate-limits
...
fix: support clearing model-level rate limits from action menu and temp-unsched reset
2026-02-09 20:52:44 +08:00
yangjianbo
d367d1cde6
Merge branch 'main' into test-sora
2026-02-09 20:40:09 +08:00
erio
4a84ca9a02
fix: support clearing model-level rate limits from action menu and temp-unsched reset
2026-02-09 20:37:30 +08:00
yangjianbo
16131c3d3f
Merge branch 'main' of https://github.com/mt21625457/aicodex2api
2026-02-09 20:26:03 +08:00
erio
a70d37a676
fix: Gemini error policy check should precede retry logic
2026-02-09 19:55:17 +08:00
erio
6892e84ad2
fix: skip rate limiting when custom error codes don't match upstream status
...
Add ShouldHandleErrorCode guard at the entry of handleGeminiUpstreamError
and AntigravityGatewayService.handleUpstreamError so that accounts with
custom error codes (e.g. [599]) are not rate-limited when the upstream
returns a non-matching status (e.g. 429).
2026-02-09 19:55:05 +08:00
erio
73f455745c
feat: ErrorPolicySkipped returns 500 instead of upstream status code
...
When custom error codes are enabled and the upstream error code is NOT
in the configured list, return HTTP 500 to the client instead of
transparently forwarding the original status code.
Also adds integration test TestCustomErrorCode599 verifying that 429,
500, 503, 401, 403 all return 500 without triggering SetRateLimited
or SetError.
2026-02-09 19:54:54 +08:00
Rose Ding
021abfca18
fix: 单账号分组首次 503 不设模型限流标记,避免后续请求雪崩
...
单账号 antigravity 分组收到 503 (MODEL_CAPACITY_EXHAUSTED) 时,
原逻辑会设置 ~29s 模型限流标记。由于只有一个账号无法切换,
后续所有新请求在预检查时命中限流 → 几毫秒内直接返回 503,
导致约 30 秒的雪崩窗口。
修复:在 Handler 入口处检查分组是否只有单个 antigravity 账号,
如果是则提前设置 SingleAccountRetry context 标记,让 Service 层
首次 503 就走原地重试逻辑(不设限流标记),避免污染后续请求。
2026-02-09 17:25:36 +08:00
Rose Ding
f6cfab9901
feat: 添加 Antigravity 单账号 503 退避重试机制
...
当分组内只有一个可用账号且上游返回 503 (MODEL_CAPACITY_EXHAUSTED) 时,
不再设置模型限流+切换账号(因为切换回来还是同一个账号),而是在 Service 层
原地等待+重试,避免双重等待问题。
主要变更:
- Handler 层:检测单账号 503 场景,清除排除列表并设置 SingleAccountRetry 标记
- Service 层:新增 handleSingleAccountRetryInPlace 原地重试逻辑
- Service 层:预检查跳过单账号模式下的限流检查
- 新增 ctxkey.SingleAccountRetry 上下文标记
2026-02-09 14:26:01 +08:00
shaw
51572b5da0
chore: update version
2026-02-09 12:00:03 +08:00
QTom
04cedce9a1
test: 为 stubAccountRepo 添加 ListCRSAccountIDs 方法实现
2026-02-09 11:40:37 +08:00
QTom
5e0d789440
feat(admin): 新增 CRS 同步预览和账号选择功能
...
- 后端新增 PreviewFromCRS 接口,允许用户先预览 CRS 中的账号
- 后端支持在同步时选择特定账号,不选中的账号将被跳过
- 前端重构 SyncFromCrsModal 为三步向导:输入凭据 → 预览账号 → 执行同步
- 改进表单无障碍性:添加 for/id 关联和 required 属性
- 修复 Back 按钮返回时的状态清理
- 新增 buildSelectedSet 和 shouldCreateAccount 的单元测试
- 完整的向后兼容性:旧客户端不发送 selected_account_ids 时行为不变
2026-02-09 10:39:09 +08:00
yangjianbo
d7011163b8
fix: 修复代码审核发现的安全和质量问题
...
安全修复(P0):
- 移除硬编码的 OAuth client_secret(Antigravity、Gemini CLI),
改为通过环境变量注入(ANTIGRAVITY_OAUTH_CLIENT_SECRET、
GEMINI_CLI_OAUTH_CLIENT_SECRET)
- 新增 logredact.RedactText() 对非结构化文本做敏感信息脱敏,
覆盖 GOCSPX-*/AIza* 令牌和常见 key=value 模式
- 日志中不再打印 org_uuid、account_uuid、email_address 等敏感值
安全修复(P1):
- URL 验证增强:新增 ValidateHTTPURL 统一入口,支持 allowlist 和
私网地址阻断(localhost/内网 IP)
- 代理回退安全:代理初始化失败时默认阻止直连回退,防止 IP 泄露,
可通过 security.proxy_fallback.allow_direct_on_error 显式开启
- Gemini OAuth 配置校验:client_id 与 client_secret 必须同时
设置或同时留空
其他改进:
- 新增 tools/secret_scan.py 密钥扫描工具和 Makefile secret-scan 目标
- 更新所有 docker-compose 和部署配置,传递 OAuth secret 环境变量
- google_one OAuth 类型使用固定 redirectURI,与 code_assist 对齐
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com >
2026-02-09 09:58:13 +08:00
yangjianbo
fc8a39e0f5
test: 删除CI工作流,大幅提升后端单元测试覆盖率至50%+
...
删除因GitHub计费锁定而失败的CI工作流。
为6个核心Go源文件补充单元测试,全部达到50%以上覆盖率:
- response/response.go: 97.6%
- antigravity/oauth.go: 90.1%
- antigravity/client.go: 88.6% (新增27个HTTP客户端测试)
- geminicli/oauth.go: 91.8%
- service/oauth_service.go: 61.2%
- service/gemini_oauth_service.go: 51.9%
新增/增强8个测试文件,共计5600+行测试代码。
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com >
2026-02-09 09:07:58 +08:00
erio
9a479d1b55
fix: resolve CI failures from scope removal refactor
...
- Fix gofmt alignment in ops_realtime_models.go
- Remove SetAntigravityQuotaScopeLimit mock from api_contract_test.go
- Add UpdateSortOrders mock to mockGroupRepoForGateway
2026-02-09 08:27:14 +08:00
erio
fc095bf054
refactor: replace scope-level rate limiting with model-level rate limiting
...
Merge functional changes from develop branch:
- Remove AntigravityQuotaScope system (claude/gemini_text/gemini_image)
- Replace with per-model rate limiting using resolveAntigravityModelKey
- Remove model load statistics (IncrModelCallCount/GetModelLoadBatch)
- Simplify account selection to unified priority→load→LRU algorithm
- Remove SetAntigravityQuotaScopeLimit from AccountRepository
- Clean up scope-related UI indicators and API fields
2026-02-09 08:19:01 +08:00
erio
1af06aed96
feat: shuffle accounts within same sort group to prevent thundering herd
...
Add post-sort shuffle for accounts with identical (priority, loadRate,
lastUsedAt) to break deterministic ordering when concurrent requests
read the same scheduler snapshot. Applies to both Antigravity and
OpenAI scheduling paths, plus the sortAccountsByPriorityAndLastUsed
helper.
Keeps upstream CallCount/ModelLoadInfo scheduling intact; shuffle is
additive and only randomises within equivalent-rank groups.
2026-02-09 07:33:17 +08:00
erio
9236936a55
feat: route AccountTypeUpstream to ForwardUpstream in Forward() entry
...
Without this routing guard, ForwardUpstream is never called because
Forward() always proceeds with the standard OAuth/cookie flow.
2026-02-09 07:27:10 +08:00
erio
125152460f
fix: use upstream retryDelay for rate limit duration instead of fixed default
...
- In handleSmartRetry, use the actual upstream retryDelay to set model
rate limit duration instead of always using the 30s default
- Return info.RetryDelay from shouldTriggerAntigravitySmartRetry when
shouldRateLimitModel=true, so callers know the actual delay
- Extract getDefaultRateLimitDuration() and resolveResetTime() helpers
to reduce duplication in handleUpstreamError 429 handling
- Improve debug logging with upstream_retry_delay and response body
2026-02-09 07:11:29 +08:00
erio
6d90fb0bc3
feat: detect client disconnect during streaming and continue draining upstream for billing
2026-02-09 07:06:26 +08:00
erio
b889d5017b
refactor: replace Trie-based digest session store with flat cache
2026-02-09 07:02:12 +08:00
erio
72b08f9cc5
fix: ensure sticky session failover triggers cache billing exemption
2026-02-09 06:57:07 +08:00