Repository navigation
Conversation
Treat redis.Nil from LINDEX as an empty success-history window and preserve other errors, avoiding spurious HTTP 500s when keys expire between LLEN and LINDEX. Add deterministic miniredis regression coverage. Verified the focused model rate-limit test suite, go vet, and git diff --check.
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Handle missing timestamp entries middleware/model-rate-limit.go, middleware/model_rate_limit_test.go |
checkRedisRateLimit allows the request when LIndex returns redis.Nil and returns other lookup errors. Tests simulate key deletion after LLEN and an error after LINDEX. |
Priority:
Estimated code review effort: 2 (Simple) | ~8 minutes
Change: Bug fix · Severity of issue fixed: Medium
Suggested reviewers: calcium-ion
Merge Risk: 
Minimal · up to 1889c
-
Expired rate-limit keys no longer block requests, and successful requests remain counted. No merge-blocking issue was identified.
Pre-merge checks: 
5
-
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 2 files.
-
Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
A rabbit checks the list with care,
A missing key means room is there.
Other errors keep their name,
Tests now guard each lookup game.
Soft paws hop; the checks stay fair.
Comment @coderabbitai help to get the list of available commands.
Verify injected non-Nil LINDEX failures remain errors instead of being swallowed, alongside the existing key-expiry regression. Confirmed the new case fails on the unmodified main worktree and passes with the fix; reran the focused model rate-limit suite and go vet.
Add fail-closed shared principal budget ledgers with exact accounting, immutable archives and regression coverage. Refs: QuantumNous/new-api#5791 QuantumNous/new-api#5791 Refs: QuantumNous/new-api#3345 QuantumNous/new-api#3345 Refs: QuantumNous/new-api#6583 QuantumNous/new-api#6583 Refs: QuantumNous/new-api#8124 QuantumNous/new-api#8124 Refs: QuantumNous/new-api#1730 QuantumNous/new-api#1730 Refs: QuantumNous/new-api#8123 QuantumNous/new-api#8123
Delegate configured channel RPM and concurrency to Redis while keeping local discovered limits and cooldowns. Do not reintroduce the channel's configured defaults as local key/quota limits. Preserve explicit key safeguards even when a background refresher reapplies inherited settings. Add a real two-node regression that repeatedly rejects node B while A holds global capacity, then verifies B can send immediately after release without waiting for a non-refundable local RPM window. Refs: soulteary/yunqi PR #101 #101 Refs: QuantumNous/new-api issue #1730 QuantumNous/new-api#1730 Refs: QuantumNous/new-api PR #6583 QuantumNous/new-api#6583 Refs: QuantumNous/new-api PR #8124 QuantumNous/new-api#8124
Share configured channel limits and strict-session bindings across nodes. Keep explicit limits owned by Redis without consuming local RPM on rejected admission. Refs: QuantumNous/new-api#1730 QuantumNous/new-api#1730 Refs: QuantumNous/new-api#3240 QuantumNous/new-api#3240 Refs: QuantumNous/new-api#6583 QuantumNous/new-api#6583 Refs: QuantumNous/new-api#6264 QuantumNous/new-api#6264 Refs: QuantumNous/new-api#8350 QuantumNous/new-api#8350 Refs: QuantumNous/new-api#8124 QuantumNous/new-api#8124
docs: finalize community improvement batches and validation Document eight implemented capabilities, review fixes, exact commits, CI evidence and upstream correspondence. Preserve identity, Redis and evaluation boundaries, and provide the model governance lifecycle/API guide. All functional PRs were reviewed and merged after successful regression tests and Verify CI. The running checkout and services were not changed. Refs: QuantumNous/new-api issue #1730 QuantumNous/new-api#1730 Refs: QuantumNous/new-api issue #2841 QuantumNous/new-api#2841 Refs: QuantumNous/new-api issue #3240 QuantumNous/new-api#3240 Refs: QuantumNous/new-api PR #3345 QuantumNous/new-api#3345 Refs: QuantumNous/new-api issue #4328 QuantumNous/new-api#4328 Refs: QuantumNous/new-api PR #4329 QuantumNous/new-api#4329 Refs: QuantumNous/new-api PR #4492 QuantumNous/new-api#4492 Refs: QuantumNous/new-api PR #5431 QuantumNous/new-api#5431 Refs: QuantumNous/new-api PR #5791 QuantumNous/new-api#5791 Refs: QuantumNous/new-api PR #6264 QuantumNous/new-api#6264 Refs: QuantumNous/new-api PR #6583 QuantumNous/new-api#6583 Refs: QuantumNous/new-api PR #6620 QuantumNous/new-api#6620 Refs: QuantumNous/new-api PR #6673 QuantumNous/new-api#6673 Refs: QuantumNous/new-api issue #6972 QuantumNous/new-api#6972 Refs: QuantumNous/new-api PR #7028 QuantumNous/new-api#7028 Refs: QuantumNous/new-api issue #7951 QuantumNous/new-api#7951 Refs: QuantumNous/new-api issue #7952 QuantumNous/new-api#7952 Refs: QuantumNous/new-api PR #7953 QuantumNous/new-api#7953 Refs: QuantumNous/new-api PR #7955 QuantumNous/new-api#7955 Refs: QuantumNous/new-api issue #8034 QuantumNous/new-api#8034 Refs: QuantumNous/new-api PR #8076 QuantumNous/new-api#8076 Refs: QuantumNous/new-api issue #8123 QuantumNous/new-api#8123 Refs: QuantumNous/new-api PR #8124 QuantumNous/new-api#8124 Refs: QuantumNous/new-api issue #8232 QuantumNous/new-api#8232 Refs: QuantumNous/new-api PR #8233 QuantumNous/new-api#8233 Refs: QuantumNous/new-api issue #8295 QuantumNous/new-api#8295 Refs: QuantumNous/new-api PR #8296 QuantumNous/new-api#8296 Refs: QuantumNous/new-api PR #8350 QuantumNous/new-api#8350 Refs: QuantumNous/new-api PR #8357 QuantumNous/new-api#8357 Refs: QuantumNous/new-api PR #8363 QuantumNous/new-api#8363 Refs: #99 #99 Refs: #100 #100 Refs: #101 #101 Refs: #102 #102 Refs: #103 #103 Refs: #104 #104 Refs: #105 #105 Refs: #106 #106 Refs: #107 #107 Refs: #108 #108 Refs: #109 #109 Documentation Verify CI passed: https://github.com/soulteary/yunqi/actions/runs/45003986698
Agent
sstar16与仓库近期核心作者不同。Links
User request
Out of scope — refuse
Coding Plan
Reverse-engineered channels
Third-party API wrappers
Codex channel-type changes, or compatibility from exposing Codex as a general-purpose API
Codex API-specific protocol or behavior treated as standard OpenAI API behavior
Pass-through-only forwarding
Third-party hosting sites, relay services, or API services
Usage, configuration, or integration
Matched: no
If yes, what was told to the user (stop here; do not open a PR): 不适用。
Open gate — do not open unless all are satisfied
go buildor tests passed: yesKind
Issue facts
LLEN与LINDEX之间过期时,LINDEX返回redis.Nil;当前代码忽略错误并解析空字符串,最终返回 HTTP 500。LINDEX后端错误也被误报为时间格式错误。LLEN后删除 key 可确定性复现。middleware/model-rate-limit.go对LIndex(...).Result()使用空白标识符丢弃错误。直接调用该函数即可复现,不依赖客户端或 provider。Change
捕获
LINDEX错误:redis.Nil按列表不存在处理并返回(true, nil);其他错误原样返回,继续 fail closed。既有middleware/model_rate_limit_test.go增加 hook 驱动的确定性回归测试,不改变限流算法。Research
Duplicate / prior art
checkRedisRateLimit、LIndex、redis.Nil、rate_limit_check_failed、rate limiting failure LINDEX。LLEN/LPUSH整体原子性,Fix/rate limiting failure #2856 是已关闭的 Lua/NOSCRIPT 实现;未找到聚焦该LINDEX redis.Nil分支的开放 PR。本 PR 不声称解决整体并发限流。Docs and code
AGENTS.md、.agents/github/ISSUE.md和.agents/github/PR.md。checkRedisRateLimit只在LLEN达到上限后读取最旧时间戳;redis.Nil表示列表已不存在,与LLEN=0的现有放行语义一致。Alternatives considered
LINDEX错误都放行,会掩盖真实 Redis 故障。redis.Nil放行,其他错误原样返回。Files
middleware/model-rate-limit.goLINDEX错误。middleware/model_rate_limit_test.goBehavior
LINDEX错误也被吞掉。LLEN/LPUSH原子性、成功请求记录策略、计费或其他 Redis 操作。Verification
go test -mod=readonly ./middleware -run '^TestCheckRedisRateLimitAllowsKeyExpiringBeforeTimestampRead$' -count=1稳定失败,返回parsing time "" ... cannot parse "" as "2006"。ok github.com/QuantumNous/new-api/middleware 0.697s。go test -mod=readonly ./middleware -run '^TestCheckRedisRateLimitPreservesTimestampReadErrors$' -count=1失败,注入的LINDEX错误被吞掉并返回 nil;修复后该用例通过。go test -mod=readonly ./middleware -run '^TestCheckRedisRateLimit(AllowsKeyExpiringBeforeTimestampRead|PreservesTimestampReadErrors)$' -count=1通过,输出ok github.com/QuantumNous/new-api/middleware 0.741s。go test -mod=readonly ./middleware -run '^(TestCheckRedisRateLimit.*|TestModelRedisRateLimit.*|TestModelRateLimit.*|TestModelMemoryRateLimit.*)$' -count=1通过,输出ok github.com/QuantumNous/new-api/middleware 0.632s。go vet ./middleware退出码 0,无诊断。git diff --check无输出;提交仅含上述两个文件。LINDEX错误,测试通过 hook 在LLEN后删除 key;无内部地址、配置、凭据或用户正文。middleware/model_rate_limit_test.go,覆盖LLEN后、LINDEX前 key 消失,以及非redis.Nil的LINDEX错误必须原样返回两个确定性场景。-race因本机缺少 CGO 编译器未运行。完整go test ./middleware另有TestAccessAndPanicLogsFollowLogRotation的 Windows 日志文件占用清理失败,本 PR 不将其计为通过。Risks
LLEN=0语义一致。其他 Redis 错误不会被放行。LLEN/LPUSH原子性继续在 redisRateLimiter 高并发下存在竞态条件导致限流失效 #2841 等既有线程处理,不在本 PR 扩张。Scope check
Summary by CodeRabbit