Rounded Out of a Refund

Medium

· Backend

Incident

SEV-2

BUG-HALFUP

Priority: High · reported by billing disputes

Time to fix: 20 min

Failing checks on the shipped build

  • positive halves round up

    expected 3 but got 2

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

Python round()

Inspired by the invoicing disputes born from Python's own round() — it's banker's rounding: round(2.5) is 2, round(3.5) is 4. Finance signed off on classic half-up ("half away from zero"). The refunds engine uses the built-in.

rounding.py — implement true half-up.

Code map

# Rounds to the nearest whole unit, halves away from zero.

def half_up(x):
    return round(x)

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.

Rounded Out of a Refund — Python Bug Hunt

Inspired by the invoicing disputes born from Python's own round() — it's banker's rounding: round(2.5) is 2, round(3.5) is 4.

  • Language: Python
  • Layer: Backend
  • Difficulty: Medium
  • Concepts: Rounding, Money
  • Modelled on: Python round()
  • Visible tests: positive halves round up; non-halves round normally
  • Reward: 50 XP for a complete fix

Incident

  • Severity: SEV-2 (priority: High)
  • Ticket: BUG-HALFUP
  • Reported by: billing disputes
  • Time to fix: 20 minutes, the target for a medium incident

Failing checks on the shipped build

  • positive halves round up — expected 3 but got 2

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 invoicing disputes born from Python's own round() — it's banker's rounding: round(2.5) is 2, round(3.5) is 4. Finance signed off on classic half-up ("half away from zero"). The refunds engine uses the built-in.

rounding.py — implement true half-up.

Bug report

BUG-HALFUP · Priority: High · Reported by: billing disputes

half_up(x) — round half AWAY from zero:

  • 2.5 -> 3, 3.5 -> 4, 2.4 -> 2
  • -2.5 -> -3

Observed: round(2.5) == 2 shaved cents off exactly-half refunds; the ombudsman letter cites 40,000 affected invoices.

Logs

[refund] 2.5 -> 2 (customer expected 3)

The code as shipped

src/fin/rounding.py (editable)

# Rounds to the nearest whole unit, halves away from zero.

def half_up(x):
    return round(x)

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 Python bug hunts.