Every 256th Setup

Medium

· Backend

Incident

SEV-1

BUG-CLASS3

Priority: Critical (patient safety) · reported by physics QA

Time to fix: 20 min

Failing checks on the shipped build

  • pass 256 still checks the position

    pass 256: expected "HOLD" but got "READY"

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

Therac-25 · 1985–87

Modelled on the Therac-25 radiation therapy accidents (1985–1987), analysed by Nancy Leveson and Clark Turner. In one of the software faults they documented, a one-byte flag was incremented on every pass of the set-up routine instead of being set to a fixed non-zero value. On every 256th pass it rolled over to zero — and zero meant "skip the check" that the turntable was in the right position. If the operator pressed the set button at that moment, treatment could proceed with the turntable out of place.

setup.py reconstructs that routine; hardware.py models the one-byte register.

Fix setup_pass so the position check runs on every single pass.

Code map

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


def setup_pass(state, collimator_in_position):
    state["passes"] += 1
    state["class3"] = (state["class3"] + 1) & hardware.BYTE_MASK
    if state["class3"] != 0:
        if not collimator_in_position:
            return "HOLD"
    return "READY"

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.

Every 256th Setup — Python Bug Hunt

Modelled on the Therac-25 radiation therapy accidents (1985–1987), analysed by Nancy Leveson and Clark Turner.

  • Language: Python
  • Layer: Backend
  • Difficulty: Medium
  • Concepts: Overflow, State
  • Modelled on: Therac-25 · 1985–87
  • Visible tests: the first pass holds when out of position; pass 256 still checks the position
  • Reward: 50 XP for a complete fix

Incident

  • Severity: SEV-1 (priority: Critical (patient safety))
  • Ticket: BUG-CLASS3
  • Reported by: physics QA
  • Time to fix: 20 minutes, the target for a medium incident

Failing checks on the shipped build

  • pass 256 still checks the position — pass 256: expected "HOLD" but got "READY"

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 Therac-25 radiation therapy accidents (1985–1987), analysed by Nancy Leveson and Clark Turner. In one of the software faults they documented, a one-byte flag was incremented on every pass of the set-up routine instead of being set to a fixed non-zero value. On every 256th pass it rolled over to zero — and zero meant "skip the check" that the turntable was in the right position. If the operator pressed the set button at that moment, treatment could proceed with the turntable out of place.

setup.py reconstructs that routine; hardware.py models the one-byte register.

Fix setup_pass so the position check runs on every single pass.

Bug report

BUG-CLASS3 · Priority: Critical (patient safety) · Reported by: physics QA

setup_pass(state, collimator_in_position) runs one pass of the set-up test:

  • state["passes"] increases by 1
  • state["class3"] is a one-byte flag (0..255) meaning "a position check is pending"; after every pass it must be non-zero
  • returns "HOLD" whenever the collimator is NOT in position and "READY" when it is — on every pass, however many passes have already run

Observed: during a long set-up, pass 256 reported READY with the collimator out of position.

Logs

[setup] pass 255 class3=255 chkcol=HOLD
[setup] pass 256 class3=0 chkcol=skipped -> READY
[setup] operator SET accepted

The code as shipped

src/therac/setup.py (editable)

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


def setup_pass(state, collimator_in_position):
    state["passes"] += 1
    state["class3"] = (state["class3"] + 1) & hardware.BYTE_MASK
    if state["class3"] != 0:
        if not collimator_in_position:
            return "HOLD"
    return "READY"

Read-only context: src/therac/hardware.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.