The Tip That Didn't Add Up — JavaScript Bug Hunt
Inspired by the gig-economy payout scandals over vanishing cents: split a $1.00 tip among 3 drivers with floor(total/n) and one cent simply evaporates —…
- Language: JavaScript
- Layer: Backend
- Difficulty: Medium
- Concepts: Rounding, Money
- Modelled on: Gig-economy payouts
- Visible tests: the classic dollar-three-ways case conserves the cent; the sum is always exact; even divisions stay even
- Reward: 50 XP for a complete fix
Incident
- Severity: SEV-2 (priority: High (press risk))
- Ticket: BUG-1CENT-TIP
- Reported by: payouts
- Time to fix: 20 minutes, the target for a medium incident
Failing checks on the shipped build
- the classic dollar-three-ways case conserves the cent — expected [34,33,33] but got [33,33,33]
- the sum is always exact — expected 999 but got 996
How to work this incident
- Read the report: write down the expected behaviour and the actual one in a sentence each.
- Reproduce it: run the visible tests and find the failing check that matches the report.
- Read the logs and the failing checks for the first value that is wrong — the earliest wrong value is nearer the cause than the loudest error.
- Follow the request through the handler, the validation and the service it calls; find the first step whose output disagrees with the report.
- Fix the cause rather than the symptom, run the visible tests again, and submit against the hidden ones — then write the root cause down.
Briefing
Inspired by the gig-economy payout scandals over vanishing cents: split a $1.00 tip among 3 drivers with floor(total/n) and one cent simply evaporates — times millions of orders.
split.js must conserve every cent: parts differ by at most one, extra cents go to the earliest parts, and the sum is exact.
Bug report
BUG-1CENT-TIP · Priority: High (press risk) · Reported by: payouts
splitEvenly(totalCents, n):
- returns n integers summing EXACTLY to totalCents
- parts differ by at most 1; earlier parts get the extra cents
Observed: splitEvenly(100, 3) -> [33, 33, 33]. One cent gone, every order.
Logs
[payout] reconciliation: -$8,214.66 this quarter in vanished remaindersThe code as shipped
src/pay/split.js (editable)
// Splits a tip evenly across n recipients.
exports.splitEvenly = function (totalCents, n) {
var each = Math.floor(totalCents / n);
var out = [];
for (var i = 0; i < n; i++) {
out.push(each);
}
return out;
};
Open the hunt to start the incident clock, edit the files, run the visible tests and submit against the hidden ones, then write the root cause down. More JavaScript bug hunts.