The Streak That Died at Midnight — Python Bug Hunt
Inspired by the streak-loss support tickets every habit app drowns in.
- Language: Python
- Layer: Backend
- Difficulty: Medium
- Concepts: Time, Timezones
- Modelled on: Duolingo-class apps
- Visible tests: practicing today keeps the streak; yesterday keeps it, two days ago kills it; the local day respects the offset
- Reward: 50 XP for a complete fix
Briefing
Inspired by the streak-loss support tickets every habit app drowns in. Two bugs conspire: the "did they practice yesterday?" check is off by one, and the local-day computation ignores the user's timezone, so evening sessions land on the wrong day.
streak.py — days are integer day-numbers; offsets are minutes east of UTC.
Bug report
BUG-STREAK · Priority: High (App Store reviews) · Reported by: growth
- local_day(epoch_seconds, offset_minutes) = the user's local day number
- is_alive(last_practice_day, today) — alive if last practice was today OR yesterday
Observed: practicing twice in one day KILLS the streak, and a 22:13 UTC session for a UTC+2 user is credited to the previous local day.
Logs
[streak] user practiced today -> streak reset (?!)
[streak] 22:13Z @ UTC+2 -> counted for yesterdayThe code as shipped
src/habit/streak.py (editable)
SECONDS_PER_DAY = 86400
def local_day(epoch_seconds, offset_minutes):
return epoch_seconds // SECONDS_PER_DAY
def is_alive(last_practice_day, today):
return 0 < today - last_practice_day < 2
Open the hunt to edit the files, run the visible tests and submit against the hidden ones. More Python bug hunts.