The Tip That Didn't Add Up

Medium

· Backend

Incident

SEV-2

BUG-1CENT-TIP

Priority: High (press risk) · reported by payouts

Time to fix: 20 min

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

  1. Read the report: write down the expected behaviour and the actual one in a sentence each.
  2. Reproduce it: run the visible tests and find the failing check that matches the report.
  3. 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.
  4. Follow the request through the handler, the validation and the service it calls; find the first step whose output disagrees with the report.
  5. Fix the cause rather than the symptom, run the visible tests again, and submit against the hidden ones — then write the root cause down.

Inspired by

Gig-economy payouts

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.

Code map

// 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;
};

Sign in to edit the file, run the tests and submit a fix

A free account — no card, no trial clock. You come straight back here.

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

  1. Read the report: write down the expected behaviour and the actual one in a sentence each.
  2. Reproduce it: run the visible tests and find the failing check that matches the report.
  3. 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.
  4. Follow the request through the handler, the validation and the service it calls; find the first step whose output disagrees with the report.
  5. 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 remainders

The 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.