fix(log): preserve quota in usage statistics - #7108
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. Walkthrough
ChangesQuota statistics
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to This change corrects usage statistics so quota is preserved while RPM and TPM remain available, without changing billing, authorization, logging, API shape, or deployment behavior. No actionable merge-blocking risk remains beyond normal checks and review. Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…tions Upstream picks: quota preservation in usage stats (QuantumNous#7108), legacy token key constraint migration, README Video API link fixes. Conflict resolutions: - model/log.go: combine both halves of the same double-Scan fix (fork scans quota into quotaStat, upstream scans rpm/tpm into rateStat) - 6x README: keep fork condensed version (ours); upstream link fix targets the upstream doc list section that the fork README replaced Co-Authored-By: Claude <noreply@anthropic.com>
* fix(log): preserve quota in usage statistics
* fix(log): preserve quota in usage statistics (cherry picked from commit 8c8c415)
Agent
Links
User request
修复使用日志统计中 quota 始终为 0、但消费日志明细和 RPM/TPM 正常的问题,并确认问题存在于未修改的上游代码。
Out of scope — refuse
本变更不涉及 Coding Plan、逆向渠道、第三方 API wrapper、Codex 协议、透传模式或第三方托管服务。
Kind
Issue facts
/api/log/stat返回的quota为 0,但 RPM/TPM、消费日志明细以及数据库中的logs.quota均为非零。v1.25.12下,只要 quota 聚合结果非零并继续执行 RPM/TPM 扫描,该问题即可稳定复现。main仍将两个不同投影的查询结果扫描到同一个Stat。logs.quota为非零,但统计接口返回的data.quota为 0。Scan会将第一次扫描得到的Quota清零。Change
SumUsedQuota原先依次将 quota 查询和 RPM/TPM 查询扫描到同一个Stat:第一个查询只返回
quota,第二个查询只返回rpm和tpm。GORMv1.25.12初始化第二次结构体扫描时会清零目标值,因此第一次查询写入的Quota被重置为 0。本 PR 将 RPM/TPM 查询扫描到独立的局部结构体,然后只把
Rpm和Tpm赋回最终结果:这样可以保留第一次聚合得到的 quota,同时维持原有 RPM/TPM 查询及最近 60 秒统计规则。
新增回归测试,验证一次统计请求能够同时返回正确的 quota、RPM 和 TPM。
Research
Duplicate / prior art
SumUsedQuotarpmTpmQueryusage quota 0log stat quotaquota RPM TPMDocs and code
controller/log.go:GetLogsStat和GetLogsSelfStat调用model.SumUsedQuota。model/log.go:quota 查询和 RPM/TPM 查询原先扫描到同一个Stat。web/src/features/usage-logs/api.ts:使用日志统计请求/api/log/stat或/api/log/self/stat。Alternatives considered
Files
model/log.gomodel/log_stat_test.goBehavior
Scan(&stat)将其清零,最终接口返回quota: 0。Verification
Only what was actually run.
go test ./model -run TestSumUsedQuotaPreservesQuotaWhenLoadingRateStats -count=1 -p 1 -parallel 1go test ./model -count=1 -p 1 -parallel 1go test ./controller -count=1 -p 1 -parallel 1git diff --cached --checkGetLogsStat,GetLogsSelfStatv1.25.2和v1.25.12。v1.25.2第二次扫描后保留Quota: 12345。v1.25.12第二次扫描后将其重置为Quota: 0。Quota: 12345、Rpm: 1、Tpm: 30。TestSumUsedQuotaPreservesQuotaWhenLoadingRateStats。Risks
Rpm或Tpm,速率统计可能返回 0;新增回归测试同时覆盖 quota、RPM 和 TPM。Scope check
Summary by CodeRabbit
Bug Fixes
Tests