feat(agent): ユーザ単位の日次レート制限を導入(#521 / ADR-0023)#533
Conversation
プリペイド課金撤去(#522)で消える abuse 防止の代替を先行導入する。Agent の LLM を叩くエンドポイントにユーザ×日の回数上限を設ける。 - services/agent/rate_limit.py(決定論ロジック・mutmut 対象)を TDD で実装。 今日(JST)のカウントを原子的に増やし、AGENT_DAILY_LIMIT 超過で AgentRateLimitExceededError。limit=N なら N 回目まで許可・N+1 で拒否 - models/agent_usage.py(AgentDailyUsage)+ repositories/agent_rate_limit.py。 ADR-0005 単一インスタンス前提の原子的 UPDATE(billing で実証済みパターン) - drop→create マイグレーション 0050(agent_daily_usage) - /agent/chat・/agent/resume-draft/run に適用し、超過で 429 + AGENT_DAILY_LIMIT_EXCEEDED を返す(既存 AppErrorResponse 契約) - env AGENT_DAILY_LIMIT(既定 50)を env_keys / docker-compose / docs/api.md に同期 - web: errorCodes.ts / errorMessages.ts に AGENT_DAILY_LIMIT_EXCEEDED を追加 - test: 単体 6(境界・超過・日次リセット・ユーザ独立・env 解決)+ 統合 1(429) Tdd-Red: assert 0 == 1(enforce_daily_limit スタブが増分しない失敗を確認済み) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Warning Review limit reached
Next review available in: 54 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (16)
✨ 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 |
概要
機能整理ロードマップ #517 のサブ issue #521。ADR-0023(#520 / PR #532)の撤去順序に従い、プリペイド課金撤去(#522)で消える abuse 防止の代替を先行導入する。Agent の LLM を叩くエンドポイントにユーザ×日の回数上限を設ける。
実装
services/agent/rate_limit.py(決定論ロジック・mutmut 対象)を TDD(red→green→refactor)で実装。今日(JST)のカウントを原子的に増やし、AGENT_DAILY_LIMIT超過でAgentRateLimitExceededError。limit=N なら N 回目まで許可・N+1 で拒否models/agent_usage.py(AgentDailyUsage) +repositories/agent_rate_limit.py。ADR-0005 単一インスタンス前提の原子的 UPDATE(billing で実証済みパターンの再利用。IntegrityError は再取得で吸収)agent_daily_usageテーブル。down_revision =0049_drop_blog_tables)/agent/chat・/agent/resume-draft/runに適用(LLM を起動する側。/pdfはキャッシュ再レンダリングで LLM 非呼び出しのため対象外 — ユーザー確認済み)。超過で 429 +AGENT_DAILY_LIMIT_EXCEEDED(既存AppErrorResponse契約)AGENT_DAILY_LIMIT(既定 50) を env_keys / docker-compose / docs/api.md に同期errorCodes.ts/errorMessages.tsにAGENT_DAILY_LIMIT_EXCEEDEDを追加テスト
Tdd-Red:assert 0 == 1(enforce_daily_limit スタブが増分しない失敗を確認済み)検証
make cigreen(backend 650 passed / web 376 passed / ruff・pyright 0 / lint-env-keys・lint-adr-index・lint-tdd OK)0048 → 0049_drop_blog_tables → 0050_create_agent_daily_usage(単一 head。実 SQLite で確認)受け入れ条件
make cigreenAGENT_DAILY_LIMIT_EXCEEDED)Closes #521
🤖 Generated with Claude Code