Skip to content

feat: configurable 429 rate-limit degradation threshold - #3

Closed
teamilkman wants to merge 2 commits into
gakiyukr:masterfrom
teamilkman:feat/rate-limit-threshold
Closed

teamilkman wants to merge 2 commits into
gakiyukr:masterfrom
teamilkman:feat/rate-limit-threshold

Conversation

@teamilkman

@teamilkman teamilkman commented Sep 6, 2026 •

Copy link
Copy Markdown

Summary

  • 新增「限流降级阈值」设置(后台设置页 + 环境变量 ZCODE_RATE_LIMIT_THRESHOLD,默认 1 保持现有行为):账号连续收到 N 次上游 429 后才标记为「限流」冷却;设为 0 则完全不因 429 降级(429 仍会为当前请求切换下一个账号,只是不进入冷却)
  • 账号模型新增连续 429 计数 rate_limit_count,成功请求后清零;进入冷却时归零重新计数。主网关 /v1/messages 与 /async/* 两处 429 路径使用同一套阈值逻辑,503 行为不变
  • 顺带修复:部分测试用例在 patch 之外消费流式响应,导致跑测试套件会向真实 data/accounts.db 写入测试账号;已补上 store.update_account 的 patch

Test plan

  • 新增 6 个测试:默认阈值一次 429 即冷却、未达阈值保持 active、连续 429 达标后冷却、成功请求清零计数、阈值 0 永不冷却、async 池未达阈值不冷却
  • 全量测试套件通过(96 tests, 1 skipped),运行后确认 data/accounts.db 无测试账号残留
  • 本地起服务验证后台设置页:新字段加载默认值 1 → 保存 3 → 刷新后仍为 3 → DB meta 表确认 → 恢复默认 1

🤖 Generated with Claude Code

PapperMirror and others added 2 commits September 6, 2026 20:52
A single upstream 429 used to immediately mark an account as cooling.
Add a rate_limit_threshold setting (admin settings page +
ZCODE_RATE_LIMIT_THRESHOLD, default 1 = previous behavior): accounts
only enter cooling after N consecutive 429s, and 0 disables
degradation entirely. 429s still switch to the next account for the
current request in all cases. The consecutive counter resets on a
successful request and when cooling is applied.

Also patch store.update_account in tests that stream success
responses so running the suite no longer persists test accounts
into the live data/accounts.db.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
The old admin settings.html was replaced by the React SPA upstream;
add the rate_limit_threshold field to frontend settings page and the
SettingsResponse type.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@teamilkman
teamilkman force-pushed the feat/rate-limit-threshold branch from 4566ef8 to 5766aef Compare September 6, 2026 13:03
@teamilkman teamilkman closed this Sep 10, 2026
@teamilkman
teamilkman deleted the feat/rate-limit-threshold branch September 10, 2026 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants