Pounds Where Kilograms Should Be — Python Bug Hunt
Modelled on Air Canada Flight 143, the "Gimli Glider" (23 July 1983).
- Language: Python
- Layer: Backend
- Difficulty: Easy
- Concepts: Units, Math
- Modelled on: Air Canada · 1983
- Visible tests: no uplift when the tanks already hold enough; litres convert to kilograms
- Reward: 50 XP for a complete fix
Incident
- Severity: SEV-1 (priority: Critical (safety))
- Ticket: BUG-FUEL-143
- Reported by: line maintenance
- Time to fix: 10 minutes, the target for an easy incident
Failing checks on the shipped build
- litres convert to kilograms — 1000 L should be 800 kg, got 1770.0: expected a truthy value but got false
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
Modelled on Air Canada Flight 143, the "Gimli Glider" (23 July 1983). The Boeing 767's fuel gauges were inoperative, so the fuel on board was measured with drip sticks in litres and converted by hand. The conversion used 1.77 — the density of jet fuel in pounds per litre — where the new metric aircraft needed about 0.8 kilograms per litre. The crew believed they had more than twice the fuel they actually carried; the aircraft ran dry in flight and glided to a landing on a former air-force runway at Gimli, Manitoba. Everyone on board survived.
fuel.py is the fuel sheet: it converts a drip-stick reading into mass and works out how many litres to uplift. Every mass on the sheet is in kilograms.
Fix the conversions.
Bug report
BUG-FUEL-143 · Priority: Critical (safety) · Reported by: line maintenance
- mass_on_board_kg(litres) = litres * units.KG_PER_LITRE
- litres_to_uplift(dipstick_litres, required_kg): shortfall_kg = required_kg - mass_on_board_kg(dipstick_litres) 0 when shortfall_kg <= 0, otherwise shortfall_kg / KG_PER_LITRE rounded to the nearest whole litre (an int)
All masses are kilograms; the pounds factor has no place on this sheet.
Observed: 1,000 litres are booked as 1,770 kg of fuel, and the uplift comes out at less than half of what the aircraft needs.
Logs
[fuel-sheet] dipstick=7682 L -> on board 13597 kg (factor 1.77)
[fuel-sheet] required 22300 kg -> uplift 4917 L
[fdr] FUEL QTY LOW both tanks, FL410The code as shipped
src/fuel/fuel.py (editable)
units = bug_require("./units.py")
def mass_on_board_kg(litres):
return litres * units.LB_PER_LITRE
def litres_to_uplift(dipstick_litres, required_kg):
shortfall_kg = required_kg - mass_on_board_kg(dipstick_litres)
if shortfall_kg <= 0:
return 0
return int(round(shortfall_kg / units.LB_PER_LITRE))
Read-only context: src/fuel/units.py.
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.