The Alarm That Slept In — Python Bug Hunt
Inspired by the iPhone alarm bugs that made global news two New Years in a row — recurring alarms simply didn't fire when the date math wrapped wrong.
- Language: Python
- Layer: Backend
- Difficulty: Easy
- Concepts: Time, Modulo
- Modelled on: Apple iOS alarms
- Visible tests: an alarm later today is a simple difference; an alarm earlier than now wraps to tomorrow; an alarm for right now fires now
- Reward: 50 XP for a complete fix
Incident
- Severity: SEV-3 (priority: Everyone overslept)
- Ticket: BUG-0700
- Reported by: the internet
- Time to fix: 10 minutes, the target for an easy incident
Failing checks on the shipped build
- an alarm earlier than now wraps to tomorrow — 7.5 hours to 07:00: expected 450 but got -990
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 iPhone alarm bugs that made global news two New Years in a row — recurring alarms simply didn't fire when the date math wrapped wrong.
alarm.py: given the current time and a daily alarm time, return the minutes until it next fires. An alarm set for right now fires now (0 minutes).
Bug report
BUG-0700 · Priority: Everyone overslept · Reported by: the internet
minutes_until(now_h, now_m, alarm_h, alarm_m):
- alarm later today -> simple difference
- alarm earlier than now -> wraps to tomorrow
- alarm exactly now -> 0
Observed: alarms earlier in the day return NEGATIVE minutes, and the scheduler treats negatives as "never".
Logs
[alarm] now=23:30 alarm=07:00 -> -990 minutes -> skippedThe code as shipped
src/clock/alarm.py (editable)
# Minutes until the daily alarm next fires.
def minutes_until(now_h, now_m, alarm_h, alarm_m):
now = now_h * 60 + now_m
alarm = alarm_h * 60 + alarm_m
return alarm - now
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.