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