This is a write-up of a bug I found while auditing a subscription app I run. I work with a small team of AI agents, and I keep the details general on purpose. What matters is the pattern, because a bug that leaks money quietly is easy to miss in any subscription app.
What the app sells
The app sells subscriptions through the app stores, in several tiers. Each tier unlocks a different level of access. Paying for a tier should give you that tier's access, no more and no less.
The quiet job that can lose money
Behind the app runs a background job that re-checks each subscriber's purchases against the records of a subscription billing provider. If a person's access level has drifted from what they paid for, the job repairs it.
It is a good idea. It also means one wrong assumption in that job can quietly change what many people receive.
The bug
The job has a map from product ID to tier. The store had introduced a newer product-ID format, and the map did not know the new IDs for the lower tier or for the top tier.
When the map met an ID it did not recognise, it treated it as the middle tier.
| Product ID known to the map? | Tier the job assigned | What the payer should get | Consequence |
|---|---|---|---|
| No (lower tier, new ID format) | middle tier | lower tier | Over-grant: they get more than they paid for. Lost revenue. |
| No (top tier, new ID format) | middle tier | top tier | Under-grant: a paying customer gets less than they paid for. The worse failure. |
Lower-tier payers could be repaired up to the middle tier. Top-tier payers could be repaired down to the middle tier. The second case is worse because it takes something away from someone who paid.
How it was found and confirmed
An AI scan of the codebase for places where money could leak flagged it. A second agent then re-verified the finding against the current code, down to the file and line. Finally, a human re-read the code. Three looks, and the first one was a machine.
Confirmation came from tests, not from the scan. I had tests written for the new ID cases and ran them against the code before changing anything. Several of the job's tests failed. That is the fail-before: proof the tests actually catch the bug.
The fix was written and tested. With it in place, the new tests passed, the wider purchase-flow test suites passed, and the type checker was clean.
A fix without a failing test first is a guess. A failing test that turns green is evidence.
The AI reviewer that got it backwards
An automated AI review looked at the fix. It described the direction of the bug wrongly. It said lower-tier payers were under-granted.
The owner of the change caught it by comparing prices. The lower tier costs less than the middle tier. A lower-tier payer moved to the middle tier gets more than they paid for, so it is an over-grant, not an under-grant.
The reviewer had not been given the file that defines the tiers. It reasoned without the one fact it needed.
The lesson is small and practical: an AI review is a hint. Check it against the code.
The safe default
The old behaviour was "anything unknown is the middle tier". The fix removes that. Unknown product IDs no longer default to any tier.
With the fix, when the job meets an ID it does not know, it does three things. It keeps the user's current access. It makes no database write. It raises a warning so a human looks.
A default tier is a guess about someone else's money. Keeping what the person already has is the one choice that cannot take access away or give it away by accident.
The fix also reuses the strict rules of the real-time purchase-event path instead of keeping a second copy, so the repair job follows the same rules as the live path.
Did it hurt anyone?
The way to answer that is to read the live purchase records for the affected ID format and count whom the job has actually changed, with the date you looked written down.
Even a count of zero does not make the exposure unreal. Any payer already buying through the new ID format is exposed the moment the job next runs over them. The bug was about what the job could do, not only about what it had done.
What this teaches any subscription app
Three checks you can run on your own app:
- List every product ID your stores sell, then compare it to every place your code maps IDs to tiers. Any ID that appears in the store but not in the map is a candidate bug. Pay special attention to newer ID formats.
- Find your default branch. What does your code do with an ID it does not recognise? If the answer is "treat it as a paid tier", change it to "keep current access and warn a human".
- Check which direction each mistake costs. Over-granting loses revenue. Under-granting hurts a paying customer. Know which one your code can produce, and test both.
Get in touch
If you run a subscription app and want to compare notes on how purchases turn into access, write to [email protected].
You steer. We prove.