The Streak That Died at Midnight

Medium

· Backend

Incident

SEV-2

BUG-STREAK

Priority: High (App Store reviews) · reported by growth

Time to fix: 20 min

Failing checks on the shipped build

  • practicing today keeps the streak

    same-day practice is alive: expected a truthy value but got false

  • the local day respects the offset

    22:13 UTC is past midnight at UTC+2: expected 19676 but got 19675

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

Duolingo-class apps

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.

Code map

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

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.

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

Incident

  • Severity: SEV-2 (priority: High (App Store reviews))
  • Ticket: BUG-STREAK
  • Reported by: growth
  • Time to fix: 20 minutes, the target for a medium incident

Failing checks on the shipped build

  • practicing today keeps the streak — same-day practice is alive: expected a truthy value but got false
  • the local day respects the offset — 22:13 UTC is past midnight at UTC+2: expected 19676 but got 19675

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

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