amal66 puts a real lock on the meter

Per-user message limits now get enforced on the server before any expensive AI call fires - not just shown in the interface.

infrastructuremulti-tenant

Until now, the cap on how many messages a user could send each month lived only in the interface: a counter that looked like a limit but stopped nothing. A user who knew where to push could keep firing off costly AI requests well past their allowance, and the bill kept climbing.

amal66 moved the check to the backend, so the limit is verified before the system ever calls the AI. The work comes with a careful set of tests covering the awkward edges - what happens at the exact limit, when the monthly counter resets, and when the database hiccups. One caveat for anyone borrowing it: the enforcement is wired to this fork's specific credit-tracking setup, so it isn't a drop-in part.

So what Anyone running a hosted, pay-or-rate-limited legal-AI product should look here - this is the correct place to enforce billing, and it's been done properly.

View this fork on GitHub →

Spotted something wrong? Or know the PR text has fresher detail than the writeup above?

Commits in this thread

2 commits from amal66/mike, oldest first. Source extracted verbatim from the harvested git log.

SHA Subject Author Date
41ede550 fix(chapter-23): enforce monthly message credits before LLM calls Amal 2026-05-24 ↗ GitHub
commit body
Chapter: 23 - Server-side quota enforcement.

Plain-English map:
Check a user's monthly message credits before making chat LLM calls.

Why it matters:
A UI counter alone does not enforce anything. The backend must stop expensive
provider calls when a user has reached the configured limit.

Principle:
Billing and quota rules must be enforced server-side.

Precedent borrowed:
Upstream PR #157.

Upstream base: willchen96/mike@d39f580.
Original local commit: fa433e1.
27694ca4 test(chapter-34): cover message-credit enforcement edges Amal 2026-05-24 ↗ GitHub
commit body
Chapter: 34 - Quota regression tests.

Plain-English map:
Add unit tests for the monthly message-credit gate, including reset dates,
limit boundaries, null counters, and database-error behavior.

Why it matters:
A quota bug can either block legitimate users or make the limit meaningless.
The important edge cases need to be pinned down.

Principle:
Server-side gates need boundary tests.

Precedent borrowed:
Chapter 23 and the fork report's testing-focused active forks.

Upstream base: willchen96/mike@d39f580.
Original local commit: 919665e.

Capture this thread into my fork

Download a single Markdown prompt that tells Claude how to port every commit above into your working tree — adapting paths and structure to match your repo. Run it via claude -p < capture-thread-590.md from inside the repo you want the changes in.

⬇ Download capture-thread-590.md