feat(chat): add a per-minute message limit per plan #65
All Vouch review confidence checks passed
Residual risk 0.17 = Change Risk (0.43) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.43 · 398 lines diff across 4 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.358
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #65"
general
weight: 0.35
mangeshraut712
Problem
The chat route only enforced
maxMessagesPerMonth. Nothing limited bursts, so one client or script could spend an owner's whole monthly quota, and the matching model spend, in seconds.Change
PlanLimitsgainsmaxMessagesPerMinute: free 10, pro 100, business 1000, matching the hard rule inAGENTS.md.chat_rate_reservationstable (supabase/schema.sql, RLS on, service role only). It then counts the owner's slots in the last 60 s, up to and including its own.- Over the cap: the slot is given back and the route returns 429 with
Retry-After: 60.- Count query error: the slot is given back and the route returns 503, so an unknown count is never admitted.
- In-flight requests hold capacity, so a concurrent burst can't overshoot. Because the count is in the database, the limit holds across serverless instances.
analytics_events, which stays append-only (AGENTS.md rule 3).message_sentis still inserted only after a reply, so slots never count toward the monthly quota or usage pages. An abandoned slot just ages out of the window, and slots older than 10 minutes are pruned.supabase/schema.sqlbefore shipping this.Tests
api-routes.test.ts:- at the cap: 429 with
Retry-After, and the gateway is never called;- 20 concurrent free-plan requests: exactly 10 reach the gateway, and only those write
message_sent;- a failed count query: 503 and the slot is freed;
- a failed reply records no usage, and stale slots are pruned.
billing-plans.test.tsis updated for the new field.<!-- CURSOR_SUMMARY -->
---
<!-- /CURSOR_SUMMARY -->