fix(api): rate-limit ingestion-quality and eval-cases admin routes (audit H2 remainder)#731
Conversation
…udit H2 remainder) Completes Wave-H finding H2 (S6). The H2 PR (#727) rate-limited the document-admin write routes; this covers the remaining two authenticated admin routes it named: `ingestion/quality` (GET dashboard) and `eval-cases` (POST capture), which still had no per-owner rate-limit bucket. Adds an `ingestion_admin` bucket (60/min per owner) and consults it — before any table access — in both routes; exhaustion returns the shared 429 + `Retry-After` envelope via `rateLimitJsonResponse`. Like the document-admin bucket, it uses `allowInMemoryFallbackOnUnavailable: true`, so a durable-limiter outage degrades these authenticated routes to per-instance limiting rather than failing them closed. Tests: new tests/ingestion-admin-rate-limit.test.ts proves a 429 + Retry-After when the durable limiter reports the bucket exhausted (no table access occurs). Added a not-limited rpc stub to tests/eval-cases-route.test.ts and tests/ingestion-quality-route.test.ts so their functional cases exercise the happy path through the new limiter check. Verification: the 5 affected suites pass (29); api-rate-limit-fallback passes; tsc/eslint/prettier clean on all changed files. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011Zbpyexer9cLgxhrB61RCU
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
|
Warning Review limit reached
Next review available in: 31 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: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (6)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
…mit buckets) Resolves the expected conflict in src/lib/api-rate-limit.ts after #731 (the H2 remainder) merged first: #731 added the `ingestion_admin` bucket and this PR adds `document_admin`. Keep-both resolution — both entries retained in the ApiRateLimitBucket union and apiRateLimitDefaults. No behaviour change; the two buckets are independent. Verified: document-admin-rate-limit + api-rate-limit-fallback + document-mutation-routes pass (19); tsc/eslint/prettier clean on api-rate-limit.ts. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011Zbpyexer9cLgxhrB61RCU
Summary
Completes Wave-H finding H2 (S6). PR #727 rate-limited the document-admin write routes; this covers the remaining two authenticated admin routes H2 named —
ingestion/quality(GET dashboard) andeval-cases(POST capture) — which still had no per-owner rate-limit bucket.ingestion_adminbucket (60/min per owner) insrc/lib/api-rate-limit.ts.ingestion/quality(GET) andeval-cases(POST).Retry-Afterenvelope viarateLimitJsonResponse.allowInMemoryFallbackOnUnavailable: true(matching the read/registry anddocument_adminbuckets), so a durable-limiter outage degrades these authenticated routes to per-instance limiting rather than failing them closed.With this, all six routes H2 named (bulk, labels, table-facts via #727; ingestion-quality, eval-cases here; jobs already hardened in H6) are rate-limited.
Verification
tests/ingestion-admin-rate-limit.test.ts— 429 +Retry-Afterwhen the durable limiter reports the bucket exhausted, and no table access occurs.rpcstub to the eval-cases and ingestion-quality mocks so their functional cases exercise the happy path through the new limiter check.tsc,eslint,prettierclean on every changed file.npm run verify:pr-localnot run: the repo-wide typecheck fails only on pre-existing missing optional test dev deps (@testing-library/*,@axe-core/playwright) absent in this container and unrelated to this change.npm run verify:ui— N/A; no UI, routing, or styling code changed (onlysrc/app/api/**+src/lib).Risk and rollout
ingestion_adminbucket is application config only, so reverting fully removes the limiter with no cleanup or backfill.Clinical Governance Preflight
Clinical KB Database(sjrfecxgysukkwxsowpy)Notes
ApiRateLimitBucketunion/defaults inapi-rate-limit.ts, so whichever merges second will need a trivial keep-both resolution on those two lines.Generated by Claude Code