The Negative-Price Flash Sale

Easy

· Backend

Incident

SEV-1

BUG-125PCT

Priority: Critical · reported by storefront

Time to fix: 10 min

Failing checks on the shipped build

  • stacked discounts compound, never sum

    expected 125 but got -250

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

Steam-class sales

Inspired by the seasonal-sale pricing bugs that turn storefronts into charities: stacking a 50% banner discount with a 75% coupon by adding the percentages takes 125% off. The store briefly paid customers to take games.

Discounts compound multiplicatively — fix discounts.js.

Code map

// Applies stacked percentage discounts to a price in cents.
exports.applyDiscounts = function (priceCents, percents) {
  var totalPercent = 0;
  for (var i = 0; i < percents.length; i++) {
    totalPercent += percents[i];
  }
  return Math.floor(priceCents * (100 - totalPercent) / 100);
};

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 Negative-Price Flash Sale — JavaScript Bug Hunt

Inspired by the seasonal-sale pricing bugs that turn storefronts into charities: stacking a 50% banner discount with a 75% coupon by adding the percentages…

  • Language: JavaScript
  • Layer: Backend
  • Difficulty: Easy
  • Concepts: Pricing, Math
  • Modelled on: Steam-class sales
  • Visible tests: stacked discounts compound, never sum; a single discount is simple
  • Reward: 50 XP for a complete fix

Incident

  • Severity: SEV-1 (priority: Critical)
  • Ticket: BUG-125PCT
  • Reported by: storefront
  • Time to fix: 10 minutes, the target for an easy incident

Failing checks on the shipped build

  • stacked discounts compound, never sum — expected 125 but got -250

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 seasonal-sale pricing bugs that turn storefronts into charities: stacking a 50% banner discount with a 75% coupon by adding the percentages takes 125% off. The store briefly paid customers to take games.

Discounts compound multiplicatively — fix discounts.js.

Bug report

BUG-125PCT · Priority: Critical · Reported by: storefront

applyDiscounts(priceCents, percents):

  • apply each percentage to the RUNNING price (integer floor each step)
  • 1000 with [50, 75] -> 500 -> 125

Observed: percentages are summed first — [50, 75] takes 125% off and the checkout total goes negative.

Logs

[cart] total: -250 cents ("you earn $2.50 buying this")

The code as shipped

src/store/discounts.js (editable)

// Applies stacked percentage discounts to a price in cents.
exports.applyDiscounts = function (priceCents, percents) {
  var totalPercent = 0;
  for (var i = 0; i < percents.length; i++) {
    totalPercent += percents[i];
  }
  return Math.floor(priceCents * (100 - totalPercent) / 100);
};

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.