Giving away unlimited AI without giving away the business
The problem
Some accounts had to be permanently free, the client's own and everyone on a partner domain, but free meant unmetered access to a paid model API. The obvious implementation, writing a plan and a large credit balance onto the account, was the wrong one: the Stripe webhook, the team-sync trigger and the nightly trial-expiry job all write to those same columns, and any of them could silently revoke the exemption.
What we did
We made comp status derived, never stored. It is resolved at read time from the verified session email against an exemptions table, and nothing in the feature ever writes to the plan or credit columns, so no existing write path can undo it. Domain matching is exact equality rather than a suffix test, because a suffix check would have matched an attacker-registered lookalike domain and handed it unlimited model spend. The lookup fails closed: any database error grants nothing.
The outcome
A nineteen-commit feature ending with the matcher covered by sixteen unit tests, including the revoked-row path. It also surfaced a live billing trap, where a comped user who also held a real subscription lost their cancel button and could be charged with no way to stop it, fixed in the same series.


















