Good Time on the Enhancement

Easy

· Backend

Incident

SEV-1

BUG-DOC-2015

Priority: Critical (public safety) · reported by victim's family / records office

Time to fix: 10 min

Failing checks on the shipped build

  • an enhancement is served in full

    no credit on the 365 enhancement days: expected 566 but got 446

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

Washington State DOC · 2015

Modelled on the Washington State Department of Corrections sentencing error disclosed in December 2015. From 2002, the department's software applied good-time credit to sentence enhancements — extra time, for example for using a weapon, that the law requires to be served in full. An estimated 3,200 prisoners were released early before it was corrected.

This project is a reconstruction: credit.py computes how many days a sentence requires after earned-release credit, using the percentages in the locked rules.py. It applies the credit to the whole sentence, enhancements included.

Fix days_to_serve so credit is earned only on the base term.

Code map

rules = bug_require("./rules.py")


def days_to_serve(base_days, enhancements, category):
    total = base_days + sum(enhancements)
    credit = total * rules.CREDIT_PERCENT[category] // 100
    return total - credit


def release_day(start_day, base_days, enhancements, category):
    return start_day + days_to_serve(base_days, enhancements, category)

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.

Good Time on the Enhancement — Python Bug Hunt

Modelled on the Washington State Department of Corrections sentencing error disclosed in December 2015.

  • Language: Python
  • Layer: Backend
  • Difficulty: Easy
  • Concepts: Validation, Time
  • Modelled on: Washington State DOC · 2015
  • Visible tests: a sentence without enhancements earns credit; an enhancement is served in full
  • Reward: 50 XP for a complete fix

Incident

  • Severity: SEV-1 (priority: Critical (public safety))
  • Ticket: BUG-DOC-2015
  • Reported by: victim's family / records office
  • Time to fix: 10 minutes, the target for an easy incident

Failing checks on the shipped build

  • an enhancement is served in full — no credit on the 365 enhancement days: expected 566 but got 446

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

Modelled on the Washington State Department of Corrections sentencing error disclosed in December 2015. From 2002, the department's software applied good-time credit to sentence enhancements — extra time, for example for using a weapon, that the law requires to be served in full. An estimated 3,200 prisoners were released early before it was corrected.

This project is a reconstruction: credit.py computes how many days a sentence requires after earned-release credit, using the percentages in the locked rules.py. It applies the credit to the whole sentence, enhancements included.

Fix days_to_serve so credit is earned only on the base term.

Bug report

BUG-DOC-2015 · Priority: Critical (public safety) · Reported by: victim's family / records office

days_to_serve(base_days, enhancements, category):

  • enhancements is a list of day counts; every one is served in FULL, with no credit of any kind
  • credit = base_days * rules.CREDIT_PERCENT[category] // 100 (integer floor), and applies to the base term only
  • result = (base_days - credit) + sum(enhancements)

release_day(start_day, base_days, enhancements, category) = start_day + days_to_serve(...).

Observed: 300 days base + a 365-day firearm enhancement at 33 % credit computes 446 days to serve instead of 566.

Logs

[offender-mgmt] DOC#8841 base=300 enh=[365] cat=standard -> 446 days
[offender-mgmt] DOC#8841 release scheduled 120 days early (unflagged)

The code as shipped

src/sentencing/credit.py (editable)

rules = bug_require("./rules.py")


def days_to_serve(base_days, enhancements, category):
    total = base_days + sum(enhancements)
    credit = total * rules.CREDIT_PERCENT[category] // 100
    return total - credit


def release_day(start_day, base_days, enhancements, category):
    return start_day + days_to_serve(base_days, enhancements, category)

Read-only context: src/sentencing/rules.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.