feat(gateway): enforce abuse rule actions#3504
Conversation
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Executive SummaryIncremental review of one new commit ( Resolved Issues (click to expand)| File | Line | Issue | Status | Files Reviewed (3 files)
Reviewed by claude-sonnet-4.6 · 326,877 tokens Review guidance: REVIEW.md from base branch |
…re paths When quarantine-3 model-override provider lookup fails (not-found or unavailable), the delay was silently bypassed. Now the delay is applied before returning the error response, preserving the quarantine penalty. Also adds test coverage for quarantine-1 and quarantine-2 (latency-only actions that previously had no tests).
c46b25f to
d97a3c8
Compare
|
Addressed the outstanding review summary items: the quarantine-3 unsupported-API-kind model override path now applies delay before returning, and cached rules-engine JSON now validates through Zod. Also replied to and resolved all review threads. |
Summary
Makes our gateway enforce abuse rules-engine actions. We keep the normal request path fast by using Redis as a lightweight action cache (only identities with a cached blocking/quarantine action wait on a fresh abuse check).
nothing: no gateway enforcement; cached asnone.log: no gateway enforcement, but the action is cached so future requests stay on the nonblocking path.rate-limit: return a request-local429 rate_limit_exceededbefore upstream.block: return a request-local403 abuse_blockedbefore upstream.quarantine-1: add 2s of artificial latency, then continue normally.quarantine-2: add 6s of artificial latency, then continue normally.quarantine-3: add 6s of artificial latency and, for non-BYOK requests, rewrite to an auto-free model when one is available; BYOK and no-candidate cases are latency-only.Verification
http://localhost:5173and the cloud web server athttp://localhost:3000withABUSE_SERVICE_URL=http://localhost:5173, backed by local Postgres and Redis./trpc/rules.createforblock,rate-limit,quarantine-1,quarantine-2,quarantine-3, andlog, each matching a uniquerequest.user_agentmarker./api/classifyrequests to confirm each temporary rule resolved to the expectedrules_engine.resolved_actionand matched the expected rule ID./api/openrouter/v1/chat/completionsand confirmed the Redis-gated behavior: the first request classified/cached, and the second request enforced cached blocking actions.blockreturned403 abuse_blocked,rate-limitreturned429 rate_limit_exceeded,quarantine-1added about 2s latency,quarantine-2added about 6s latency,quarantine-3added about 6s latency, andlogcontinued without enforcement.quarantine-3rewrote to a free Nemotron model before proxying./trpc/rules.delete, cleared Redis abuse classification cache keys, removed the seeded OpenRouter metadata cache, and restarted the web server to clear in-memory metadata.Visual Changes
N/A
Reviewer Notes
blockremains request-local and does not mutatekilocode_users.blocked_reason.block,rate-limit,quarantine-*,log, ornone) with no expiry, keyed by the abuse identity shape for users/fingerprints.