Build the rate limiter on the new CounterStore, so limits hold across server instances
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 83/100
- issue の種類
- 機能追加
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- node.js, typescript
調査の方向性
Read packages/core/src/storage/types.ts for the CounterStore contract, then review packages/server/src/rate-limit.ts and its tests for existing behavior. Implement the algorithm in packages/core/src/limits/rate-limit.ts and add fake-clock and concurrency coverage in packages/core/tests/limits/rate-limit.test.ts, using the in-memory counter store. Done means the listed acceptance criteria pass and the core package exports the limiter with a minor changeset.
索引モデルが issue の本文から書いたものです。
説明
The server's rate limiter keeps its counts in a Map in the process (packages/server/src/rate-limit.ts). On Vercel or Workers every instance has its own map, so a visitor spread over five instances gets five times the limit. It also needs a setInterval for cleanup (packages/server/src/handler.ts, line 35), and Workers don't allow timers at global scope.
@chatcops/core now has a CounterStore interface (packages/core/src/storage/types.ts): atomic counters that reset after a while, backed by Redis, Postgres and so on. This issue is the rate limit algorithm on top of it. Wiring it into the server comes in a later PR.
What to do
Create packages/core/src/limits/rate-limit.ts:
export interface RateLimitRule {
limit: number; // requests allowed per window
windowMs: number;
}
export interface RateLimitResult {
allowed: boolean;
/** Requests left in the current window, never below 0. */
remaining: number;
/** When denied: how long until a request would be allowed again. */
retryAfterMs?: number;
}
export function createRateLimiter(counters: CounterStore, rule: RateLimitRule, options?: { prefix?: string; now?: () => number }): {
check(key: string): Promise<RateLimitResult>;
};
Use a sliding window built from two fixed windows. It's smooth at window edges (no burst of 2x the limit at the boundary) and needs only two counters:
- The window index is
Math.floor(now / windowMs). Count this request withcounters.increment(${prefix}:${key}:${index}, 1, 2 * windowMs), and read the previous window's counter withget. - The estimated count is
previous * (1 - elapsedInWindow / windowMs) + current. Allow the request when it's at mostlimit. - Denied requests still count, so a client that keeps hammering stays limited.
retryAfterMsis an estimate: the time until the estimate drops back under the limit, at least 1 ms and at mostwindowMs. Explain the formula in a comment.prefixdefaults to'rl'. Validatelimit > 0andwindowMs > 0likeRateLimiterdoes.
Where to look
packages/server/src/rate-limit.ts(today's limiter and its tests inpackages/server/tests/rate-limit.test.ts)packages/core/src/storage/memory.ts(memoryStorage().counters, use it in the tests with a fakenow)- Cloudflare's write-up of the same sliding window idea
Acceptance criteria
- New
packages/core/src/limits/rate-limit.tsandpackages/core/tests/limits/rate-limit.test.ts, exported from@chatcops/core - Tests with a fake clock: the first
limitrequests pass and the next one doesn't; the count decays across the window boundary (half the previous window still counts at the midpoint); keys don't affect each other;retryAfterMsis set when denied and within bounds - A test with 30 concurrent
check()calls against a limit of 10 allows exactly 10 - Changeset for
@chatcops/core(minor) -
pnpm test:coverageandpnpm lintpass
Want to work on this? Comment below and I'll assign it to you. Please take one issue at a time, branch off dev, and open your PR against dev with Closes #<this issue number>. Setup notes (pnpm, build before test) are in CONTRIBUTING.md.
- 主要言語
- TypeScript
- スター
- 13
- フォーク
- 7
- 平均マージ
- 4時間 11分
- マージ済み PR(30日)
- 122
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
codercops/chatcops のほかの issue
-
enhancement hacktoberfest help wanted server
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
メンテナーはふだん 1 日以内に返信
-
Document the pre-chat form対応中かも @masyarakatai が 5 日前に担当しました。 オープンdocumentation good first issue hacktoberfest widget
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
codercops/chatcops#70 · コメント 3 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
enhancement hacktoberfest help wanted server
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
メンテナーはふだん 1 日以内に返信
-
Create @chatcops/store-redis for Upstash and other Redis clients対応中かも @bhushan4work が 1 日前に担当しました。 オープンenhancement hacktoberfest help wanted server
codercops/chatcops#248 · コメント 2 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
Create @chatcops/store-sqlite, a store for single-server setups対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープンenhancement hacktoberfest help wanted server
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
メンテナーはふだん 1 日以内に返信
codercops/chatcops の issue をすべて見る
似ている issue
-
ready-for-agent
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
xavxyz/bei-shan-lin-shui#57 ·
メンテナーはふだん 1 日以内に返信
-
[BUG] rag: sentence content can cross the reported sentence boundaries対応中かも @LJK-ikun が今日担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
メンテナーはふだん 1 日以内に返信
-
bug needs-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
メンテナーはふだん 1 日以内に返信
-
README: the Resource URI Schemas example's file://documents/* pattern only matches that literal URIオープン
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
platformatic/mcp#361 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
siyuan-note/siyuan#20799 · コメント 7 件 ·
メンテナーはふだん 1 日以内に返信