Six characters aren't an address
Every Wi-Fi controller issues its own voucher codes, so the same six characters can exist on two networks at once. How a balance check works out which voucher you actually mean, and refuses to guess.
Lodge Internet · 14 November 2026 · 6 min read
For a while, each of our backend workers kept a small memory of where it had last found a voucher code, so the next check could go straight to the right controller. It was a sensible speed-up, and it was wrong. The note left in find_voucher explains why: it sent a 6GB voucher's balance check to another network's 150GB voucher with the same code.
The code is not the voucher
Each hostel's Wi-Fi runs on a TP-Link Omada controller, and the vouchers we sell are issued by those controllers. A voucher code is six characters. Every controller issues its own, independently, and none of them knows the others exist.
So the same six characters can be a live voucher on two networks at once, with different sizes and owners. A code on its own doesn't name a voucher. It names a voucher on a particular controller, and the controller is the part the customer doesn't type.
Our first balance checks treated the code as the whole address. They tried the caller's hostel first, swept the remaining controllers if that missed, and reported the first match. Most of the time that is the right voucher. When it isn't, the customer gets a confident, wrong answer about data they didn't buy, and we have no way of knowing it happened.
Decide where to look before looking
The balance route in backend/app/routers/bot_balance.py now works out where to look, and what it must find, from our own records, before it asks any controller anything. The bot only sends the code. The customer comes from their sign-in, never from the message.
Here is the decision, trimmed:
def _plan(code, email):
sales = sales_of(code) # our sales of these characters
mine = [s for s in sales if buyer(s) == email]
theirs = [s for s in sales if buyer(s) and buyer(s) != email]
own_controller = controller_for_hostel(caller_hostel(email))
if mine:
# Only where we sold it.
return {"sale": mine[0], "targets": [controller_of_sale(mine[0])]}
if theirs:
if own_controller is None or own_controller in controllers_of(theirs):
return {"refuse": True}
if own_controller is not None:
return {"sale": None, "targets": [own_controller]}
return {"sale": None, "targets": all_controllers(), "sweep": True}Four cases fall out of it.
A code we sold to you is looked up only on the controller that sale recorded. Codes from a shared pool record their controller at the sale. Older codes, sold per hostel, use that hostel's controller. A namesake on another network is never consulted, so it can never be reported as yours.
A code we have no sale of is still a real voucher. Admin, cash and free vouchers never get a sale record, because only a sale through our platform writes one. Those are looked up on your own hostel's controller. Only an account with no hostel on file sweeps every controller, and if the sweep finds the code on two of them, we say so and ask you to contact support. We don't pick one.
A code we sold to someone else is refused, with a plain message that it was bought on a different account. There is one exception. If your own hostel is on a different controller from every network it was sold on, then the code you're holding is another voucher with the same characters, and we look it up on your network.
Everything else goes to your own controller.
Storing the voucher's size
Knowing the right controller isn't quite enough. One controller can, in principle, hold two vouchers with the same code in different groups. So a sale now records the size of the voucher it handed over.
Migration 0005, dated 6 October 2026, added that column. At the moment of sale we record the data total the controller reported for that exact voucher. A balance check on a code you bought then has to find a voucher of that size:
def _same_size(balance, expected_gb):
# Generous enough for rounding and GB/GiB differences between the
# sync and the balance reading; a 6GB voucher is never a 150GB one.
total = balance.data_total_gb
return total is not None and abs(total - expected_gb) <= max(0.25, 0.1 * expected_gb)Older sales from before the column have no recorded size. For those, we read the size from the plan's name, so a plan called "6GB" is checked as 6GB. Unlimited plans, and plan names that don't state a size, aren't size-checked at all.
The migration taught us one small Postgres lesson. We read live purchases through a view defined as SELECT * over the table. A view made that way keeps the columns it had when it was created, so adding a column to the table doesn't add it to the view. The migration rebuilds the view after adding the column, and the downgrade drops the view, drops the column and builds the view again.
Say the same thing for "unknown" and "not sold"
A voucher sitting unused in a pool, waiting to be sold, is a working Wi-Fi code. If a balance check confirmed that one existed, let alone showed its data, anyone typing six characters at random would eventually be handed free access.
So an unused code that nobody bought gets exactly the same answer as a code that doesn't exist: not found. The wording is the same, and so is the response the bot gets. Someone guessing learns nothing from the difference, because there is none.
The other outcomes are kept apart on purpose, because each asks something different of the person reading it:
- Found: your balance.
- Not found: check the code you typed.
- Found, but we can't prove it's the voucher you bought: we tell you we couldn't match it, and alert the team so someone checks it for you.
- The code exists on more than one network: contact support with your hostel name.
- We couldn't check: the controller was slow or unreachable. Try again in a minute.
That last one matters more than it looks. "We couldn't check" is never reported as "not found". A student told their code doesn't exist has every reason to think something went wrong with their purchase, when the truth is that a controller was slow.
The trade-offs
A code bought on one account and handed to a roommate is refused when the roommate checks it from their own account on the same network. That's the rule doing its job, since we can't tell a gift from a guess. The buyer can still check it themselves.
A size mismatch gives the customer no number at all, just a message that the team has been told. We would rather show nothing than show a balance from someone else's voucher.
Accounts with no hostel still sweep every controller. That is slower, and it is the one path where a namesake could turn up. When it does, we refuse to choose between them.
What's still open
Codes we didn't sell carry no recorded size, so on your own controller they are matched by code alone. On a controller that does hold two vouchers with the same code, that check ends up as the "more than one network" answer. The wording isn't quite right for two vouchers on one network.
The daily allowance on balance checks, and why it exists only on WhatsApp, is covered in Designing a chatbot when every message costs money.
Last checked against the product on 14 November 2026.