FAILURE MAP
← Case archive

FA-63976 / Medication dosing calculations / Open access

Meal and correction insulin bolus with insulin on board: hypoglycaemia hold threshold · case 01

A glucose of exactly 70 mg/dL blocks a meal bolus.

Verified by executionVariant 1 · 8 checks per implementationDownload source bundle ↓JSON ↗

ROOT CAUSE

The hold check uses <= 70, although only readings below 70 are stipulated to hold.

VERIFIED REPAIR

Hold only when bg < 70.

Unsuccessful approach: Holding only when no carbohydrate is entered lets a hypoglycaemic patient receive a meal bolus.

Case contract

Input {bg, target, isf, carbs_g, icr, iob, max_units}. Toy rule: bg < 70 returns HOLD with 0 units. correction = (bg-target)/isf; when positive, insulin on board is subtracted from it and the result floored at 0; a negative correction (bg below target) is kept and reduces the meal dose. meal = carbs_g/icr. total = max(0, meal + correction), capped at max_units, then rounded DOWN to 0.5 units. Return {action GIVE|HOLD, units}.

Why this case matters

Bolus calculators combine several unit ratios and safety rules; insulin-on-board, hypoglycaemia holds and pen resolution are separate decision points.

1 / The failure

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    bg, tgt = x['bg'], x['target']
    if bg <= 70:
        return {'action': 'HOLD', 'units': 0.0}
    corr = Fraction(bg - tgt, x['isf'])
    if corr > 0:
        corr = max(Fraction(0), corr - Fraction(str(x['iob'])))
    meal = Fraction(x['carbs_g'], x['icr'])
    total = max(Fraction(0), meal + corr)
    total = min(total, Fraction(str(x['max_units'])))
    units = Fraction(math.floor(total * 2), 2)
    return {'action': 'GIVE', 'units': float(units)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('low glucose with meal is held',
   {'bg': 61, 'target': 110, 'isf': 40, 'carbs_g': 45, 'icr': 10, 'iob': 0, 'max_units': 15},
   {'action': 'HOLD', 'units': 0.0}),
  ('glucose exactly 70 is dosed',
   {'bg': 70, 'target': 110, 'isf': 40, 'carbs_g': 50, 'icr': 10, 'iob': 0, 'max_units': 15},
   {'action': 'GIVE', 'units': 4.0}),
  ('high glucose with insulin on board',
   {'bg': 250, 'target': 120, 'isf': 40, 'carbs_g': 65, 'icr': 10, 'iob': 1, 'max_units': 15},
   {'action': 'GIVE', 'units': 8.5}),
  ('below target with insulin on board',
   {'bg': 90, 'target': 120, 'isf': 30, 'carbs_g': 50, 'icr': 10, 'iob': 1, 'max_units': 15},
   {'action': 'GIVE', 'units': 4.0}),
  ('insulin on board exceeds correction',
   {'bg': 160, 'target': 120, 'isf': 40, 'carbs_g': 40, 'icr': 10, 'iob': 3, 'max_units': 15},
   {'action': 'GIVE', 'units': 4.0}),
  ('pen resolution rounds down',
   {'bg': 120, 'target': 120, 'isf': 40, 'carbs_g': 59, 'icr': 10, 'iob': 0, 'max_units': 15},
   {'action': 'GIVE', 'units': 5.5}),
  ('maximum bolus cap not on half unit',
   {'bg': 200, 'target': 120, 'isf': 40, 'carbs_g': 120, 'icr': 10, 'iob': 0, 'max_units': '7.8'},
   {'action': 'GIVE', 'units': 7.5}),
  ('correction only control',
   {'bg': 200, 'target': 100, 'isf': 50, 'carbs_g': 0, 'icr': 10, 'iob': 0, 'max_units': 11},
   {'action': 'GIVE', 'units': 2.0})],
 [('low glucose with meal is held',
   {'bg': 62, 'target': 110, 'isf': 40, 'carbs_g': 45, 'icr': 10, 'iob': 0, 'max_units': 15},
   {'action': 'HOLD', 'units': 0.0}),
  ('glucose exactly 70 is dosed',
   {'bg': 70, 'target': 110, 'isf': 40, 'carbs_g': 60, 'icr': 10, 'iob': 0, 'max_units': 15},
   {'action': 'GIVE', 'units': 5.0}),
  ('high glucose with insulin on board',
   {'bg': 250, 'target': 120, 'isf': 40, 'carbs_g': 70, 'icr': 10, 'iob': 1, 'max_units': 15},
   {'action': 'GIVE', 'units': 9.0}),
  ('below target with insulin on board',
   {'bg': 90, 'target': 120, 'isf': 30, 'carbs_g': 50, 'icr': 10, 'iob': 2, 'max_units': 15},
   {'action': 'GIVE', 'units': 4.0}),
  ('insulin on board exceeds correction',
   {'bg': 160, 'target': 120, 'isf': 40, 'carbs_g': 50, 'icr': 10, 'iob': 3, 'max_units': 15},
   {'action': 'GIVE', 'units': 5.0}),
  ('pen resolution rounds down',
   {'bg': 120, 'target': 120, 'isf': 40, 'carbs_g': 49, 'icr': 10, 'iob': 0, 'max_units': 15},
   {'action': 'GIVE', 'units': 4.5}),
  ('maximum bolus cap not on half unit',
   {'bg': 200, 'target': 120, 'isf': 40, 'carbs_g': 120, 'icr': 10, 'iob': 0, 'max_units': '7.6'},
   {'action': 'GIVE', 'units': 7.5}),
  ('correction only control',
   {'bg': 200, 'target': 100, 'isf': 50, 'carbs_g': 0, 'icr': 10, 'iob': 0, 'max_units': 12},
   {'action': 'GIVE', 'units': 2.0})],
 [('low glucose with meal is held',
   {'bg': 63, 'target': 110, 'isf': 40, 'carbs_g': 45, 'icr': 10, 'iob': 0, 'max_units': 15},
   {'action': 'HOLD', 'units': 0.0}),
  ('glucose exactly 70 is dosed',
   {'bg': 70, 'target': 110, 'isf': 40, 'carbs_g': 70, 'icr': 10, 'iob': 0, 'max_units': 15},
   {'action': 'GIVE', 'units': 6.0}),
  ('high glucose with insulin on board',
   {'bg': 250, 'target': 120, 'isf': 40, 'carbs_g': 75, 'icr': 10, 'iob': 1, 'max_units': 15},
   {'action': 'GIVE', 'units': 9.5}),
  ('below target with insulin on board',
   {'bg': 90, 'target': 120, 'isf': 30, 'carbs_g': 50, 'icr': 10, 'iob': 3, 'max_units': 15},
   {'action': 'GIVE', 'units': 4.0}),
  ('insulin on board exceeds correction',
   {'bg': 160, 'target': 120, 'isf': 40, 'carbs_g': 60, 'icr': 10, 'iob': 3, 'max_units': 15},
   {'action': 'GIVE', 'units': 6.0}),
  ('pen resolution rounds down',
   {'bg': 120, 'target': 120, 'isf': 40, 'carbs_g': 38, 'icr': 10, 'iob': 0, 'max_units': 15},
   {'action': 'GIVE', 'units': 3.5}),
  ('maximum bolus cap not on half unit',
   {'bg': 200, 'target': 120, 'isf': 40, 'carbs_g': 120, 'icr': 10, 'iob': 0, 'max_units': '4.7'},
   {'action': 'GIVE', 'units': 4.5}),
  ('correction only control',
   {'bg': 200, 'target': 100, 'isf': 50, 'carbs_g': 0, 'icr': 10, 'iob': 0, 'max_units': 13},
   {'action': 'GIVE', 'units': 2.0})],
 [('low glucose with meal is held',
   {'bg': 64, 'target': 110, 'isf': 40, 'carbs_g': 45, 'icr': 10, 'iob': 0, 'max_units': 15},
   {'action': 'HOLD', 'units': 0.0}),
  ('glucose exactly 70 is dosed',
   {'bg': 70, 'target': 110, 'isf': 40, 'carbs_g': 80, 'icr': 10, 'iob': 0, 'max_units': 15},
   {'action': 'GIVE', 'units': 7.0}),
  ('high glucose with insulin on board',
   {'bg': 250, 'target': 120, 'isf': 40, 'carbs_g': 80, 'icr': 10, 'iob': 1, 'max_units': 15},
   {'action': 'GIVE', 'units': 10.0}),
  ('below target with insulin on board',
   {'bg': 90, 'target': 120, 'isf': 30, 'carbs_g': 50, 'icr': 10, 'iob': 4, 'max_units': 15},
   {'action': 'GIVE', 'units': 4.0}),
  ('insulin on board exceeds correction',
   {'bg': 160, 'target': 120, 'isf': 40, 'carbs_g': 70, 'icr': 10, 'iob': 3, 'max_units': 15},
   {'action': 'GIVE', 'units': 7.0}),
  ('pen resolution rounds down',
   {'bg': 120, 'target': 120, 'isf': 40, 'carbs_g': 69, 'icr': 10, 'iob': 0, 'max_units': 15},
   {'action': 'GIVE', 'units': 6.5}),
  ('maximum bolus cap not on half unit',
   {'bg': 200, 'target': 120, 'isf': 40, 'carbs_g': 120, 'icr': 10, 'iob': 0, 'max_units': '6.9'},
   {'action': 'GIVE', 'units': 6.5}),
  ('correction only control',
   {'bg': 200, 'target': 100, 'isf': 50, 'carbs_g': 0, 'icr': 10, 'iob': 0, 'max_units': 14},
   {'action': 'GIVE', 'units': 2.0})],
 [('low glucose with meal is held',
   {'bg': 65, 'target': 110, 'isf': 40, 'carbs_g': 45, 'icr': 10, 'iob': 0, 'max_units': 15},
   {'action': 'HOLD', 'units': 0.0}),
  ('glucose exactly 70 is dosed',
   {'bg': 70, 'target': 110, 'isf': 40, 'carbs_g': 90, 'icr': 10, 'iob': 0, 'max_units': 15},
   {'action': 'GIVE', 'units': 8.0}),
  ('high glucose with insulin on board',
   {'bg': 250, 'target': 120, 'isf': 40, 'carbs_g': 85, 'icr': 10, 'iob': 1, 'max_units': 15},
   {'action': 'GIVE', 'units': 10.5}),
  ('below target with insulin on board',
   {'bg': 90, 'target': 120, 'isf': 30, 'carbs_g': 50, 'icr': 10, 'iob': 5, 'max_units': 15},
   {'action': 'GIVE', 'units': 4.0}),
  ('insulin on board exceeds correction',
   {'bg': 160, 'target': 120, 'isf': 40, 'carbs_g': 80, 'icr': 10, 'iob': 3, 'max_units': 15},
   {'action': 'GIVE', 'units': 8.0}),
  ('pen resolution rounds down',
   {'bg': 120, 'target': 120, 'isf': 40, 'carbs_g': 29, 'icr': 10, 'iob': 0, 'max_units': 15},
   {'action': 'GIVE', 'units': 2.5}),
  ('maximum bolus cap not on half unit',
   {'bg': 200, 'target': 120, 'isf': 40, 'carbs_g': 120, 'icr': 10, 'iob': 0, 'max_units': '10.6'},
   {'action': 'GIVE', 'units': 10.5}),
  ('correction only control',
   {'bg': 200, 'target': 100, 'isf': 50, 'carbs_g': 0, 'icr': 10, 'iob': 0, 'max_units': 15},
   {'action': 'GIVE', 'units': 2.0})]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
low glucose with meal is held{'action': 'HOLD', 'units': 0.0}{'action': 'HOLD', 'units': 0.0}Passed
glucose exactly 70 is dosed{'action': 'HOLD', 'units': 0.0}{'action': 'GIVE', 'units': 4.0}Failed
high glucose with insulin on board{'action': 'GIVE', 'units': 8.5}{'action': 'GIVE', 'units': 8.5}Passed
below target with insulin on board{'action': 'GIVE', 'units': 4.0}{'action': 'GIVE', 'units': 4.0}Passed
insulin on board exceeds correction{'action': 'GIVE', 'units': 4.0}{'action': 'GIVE', 'units': 4.0}Passed
pen resolution rounds down{'action': 'GIVE', 'units': 5.5}{'action': 'GIVE', 'units': 5.5}Passed
maximum bolus cap not on half unit{'action': 'GIVE', 'units': 7.5}{'action': 'GIVE', 'units': 7.5}Passed
correction only control{'action': 'GIVE', 'units': 2.0}{'action': 'GIVE', 'units': 2.0}Passed

SHA-256 / 4cac7c4b3f5f07d049dee92b0e2c694251efc9691910c513ccba8dfc9e225dd8

2 / The unsuccessful fix

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    bg, tgt = x['bg'], x['target']
    if bg < 70 and x['carbs_g'] == 0:
        return {'action': 'HOLD', 'units': 0.0}
    corr = Fraction(bg - tgt, x['isf'])
    if corr > 0:
        corr = max(Fraction(0), corr - Fraction(str(x['iob'])))
    meal = Fraction(x['carbs_g'], x['icr'])
    total = max(Fraction(0), meal + corr)
    total = min(total, Fraction(str(x['max_units'])))
    units = Fraction(math.floor(total * 2), 2)
    return {'action': 'GIVE', 'units': float(units)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('low glucose with meal is held',
   {'bg': 61, 'target': 110, 'isf': 40, 'carbs_g': 45, 'icr': 10, 'iob': 0, 'max_units': 15},
   {'action': 'HOLD', 'units': 0.0}),
  ('glucose exactly 70 is dosed',
   {'bg': 70, 'target': 110, 'isf': 40, 'carbs_g': 50, 'icr': 10, 'iob': 0, 'max_units': 15},
   {'action': 'GIVE', 'units': 4.0}),
  ('high glucose with insulin on board',
   {'bg': 250, 'target': 120, 'isf': 40, 'carbs_g': 65, 'icr': 10, 'iob': 1, 'max_units': 15},
   {'action': 'GIVE', 'units': 8.5}),
  ('below target with insulin on board',
   {'bg': 90, 'target': 120, 'isf': 30, 'carbs_g': 50, 'icr': 10, 'iob': 1, 'max_units': 15},
   {'action': 'GIVE', 'units': 4.0}),
  ('insulin on board exceeds correction',
   {'bg': 160, 'target': 120, 'isf': 40, 'carbs_g': 40, 'icr': 10, 'iob': 3, 'max_units': 15},
   {'action': 'GIVE', 'units': 4.0}),
  ('pen resolution rounds down',
   {'bg': 120, 'target': 120, 'isf': 40, 'carbs_g': 59, 'icr': 10, 'iob': 0, 'max_units': 15},
   {'action': 'GIVE', 'units': 5.5}),
  ('maximum bolus cap not on half unit',
   {'bg': 200, 'target': 120, 'isf': 40, 'carbs_g': 120, 'icr': 10, 'iob': 0, 'max_units': '7.8'},
   {'action': 'GIVE', 'units': 7.5}),
  ('correction only control',
   {'bg': 200, 'target': 100, 'isf': 50, 'carbs_g': 0, 'icr': 10, 'iob': 0, 'max_units': 11},
   {'action': 'GIVE', 'units': 2.0})],
 [('low glucose with meal is held',
   {'bg': 62, 'target': 110, 'isf': 40, 'carbs_g': 45, 'icr': 10, 'iob': 0, 'max_units': 15},
   {'action': 'HOLD', 'units': 0.0}),
  ('glucose exactly 70 is dosed',
   {'bg': 70, 'target': 110, 'isf': 40, 'carbs_g': 60, 'icr': 10, 'iob': 0, 'max_units': 15},
   {'action': 'GIVE', 'units': 5.0}),
  ('high glucose with insulin on board',
   {'bg': 250, 'target': 120, 'isf': 40, 'carbs_g': 70, 'icr': 10, 'iob': 1, 'max_units': 15},
   {'action': 'GIVE', 'units': 9.0}),
  ('below target with insulin on board',
   {'bg': 90, 'target': 120, 'isf': 30, 'carbs_g': 50, 'icr': 10, 'iob': 2, 'max_units': 15},
   {'action': 'GIVE', 'units': 4.0}),
  ('insulin on board exceeds correction',
   {'bg': 160, 'target': 120, 'isf': 40, 'carbs_g': 50, 'icr': 10, 'iob': 3, 'max_units': 15},
   {'action': 'GIVE', 'units': 5.0}),
  ('pen resolution rounds down',
   {'bg': 120, 'target': 120, 'isf': 40, 'carbs_g': 49, 'icr': 10, 'iob': 0, 'max_units': 15},
   {'action': 'GIVE', 'units': 4.5}),
  ('maximum bolus cap not on half unit',
   {'bg': 200, 'target': 120, 'isf': 40, 'carbs_g': 120, 'icr': 10, 'iob': 0, 'max_units': '7.6'},
   {'action': 'GIVE', 'units': 7.5}),
  ('correction only control',
   {'bg': 200, 'target': 100, 'isf': 50, 'carbs_g': 0, 'icr': 10, 'iob': 0, 'max_units': 12},
   {'action': 'GIVE', 'units': 2.0})],
 [('low glucose with meal is held',
   {'bg': 63, 'target': 110, 'isf': 40, 'carbs_g': 45, 'icr': 10, 'iob': 0, 'max_units': 15},
   {'action': 'HOLD', 'units': 0.0}),
  ('glucose exactly 70 is dosed',
   {'bg': 70, 'target': 110, 'isf': 40, 'carbs_g': 70, 'icr': 10, 'iob': 0, 'max_units': 15},
   {'action': 'GIVE', 'units': 6.0}),
  ('high glucose with insulin on board',
   {'bg': 250, 'target': 120, 'isf': 40, 'carbs_g': 75, 'icr': 10, 'iob': 1, 'max_units': 15},
   {'action': 'GIVE', 'units': 9.5}),
  ('below target with insulin on board',
   {'bg': 90, 'target': 120, 'isf': 30, 'carbs_g': 50, 'icr': 10, 'iob': 3, 'max_units': 15},
   {'action': 'GIVE', 'units': 4.0}),
  ('insulin on board exceeds correction',
   {'bg': 160, 'target': 120, 'isf': 40, 'carbs_g': 60, 'icr': 10, 'iob': 3, 'max_units': 15},
   {'action': 'GIVE', 'units': 6.0}),
  ('pen resolution rounds down',
   {'bg': 120, 'target': 120, 'isf': 40, 'carbs_g': 38, 'icr': 10, 'iob': 0, 'max_units': 15},
   {'action': 'GIVE', 'units': 3.5}),
  ('maximum bolus cap not on half unit',
   {'bg': 200, 'target': 120, 'isf': 40, 'carbs_g': 120, 'icr': 10, 'iob': 0, 'max_units': '4.7'},
   {'action': 'GIVE', 'units': 4.5}),
  ('correction only control',
   {'bg': 200, 'target': 100, 'isf': 50, 'carbs_g': 0, 'icr': 10, 'iob': 0, 'max_units': 13},
   {'action': 'GIVE', 'units': 2.0})],
 [('low glucose with meal is held',
   {'bg': 64, 'target': 110, 'isf': 40, 'carbs_g': 45, 'icr': 10, 'iob': 0, 'max_units': 15},
   {'action': 'HOLD', 'units': 0.0}),
  ('glucose exactly 70 is dosed',
   {'bg': 70, 'target': 110, 'isf': 40, 'carbs_g': 80, 'icr': 10, 'iob': 0, 'max_units': 15},
   {'action': 'GIVE', 'units': 7.0}),
  ('high glucose with insulin on board',
   {'bg': 250, 'target': 120, 'isf': 40, 'carbs_g': 80, 'icr': 10, 'iob': 1, 'max_units': 15},
   {'action': 'GIVE', 'units': 10.0}),
  ('below target with insulin on board',
   {'bg': 90, 'target': 120, 'isf': 30, 'carbs_g': 50, 'icr': 10, 'iob': 4, 'max_units': 15},
   {'action': 'GIVE', 'units': 4.0}),
  ('insulin on board exceeds correction',
   {'bg': 160, 'target': 120, 'isf': 40, 'carbs_g': 70, 'icr': 10, 'iob': 3, 'max_units': 15},
   {'action': 'GIVE', 'units': 7.0}),
  ('pen resolution rounds down',
   {'bg': 120, 'target': 120, 'isf': 40, 'carbs_g': 69, 'icr': 10, 'iob': 0, 'max_units': 15},
   {'action': 'GIVE', 'units': 6.5}),
  ('maximum bolus cap not on half unit',
   {'bg': 200, 'target': 120, 'isf': 40, 'carbs_g': 120, 'icr': 10, 'iob': 0, 'max_units': '6.9'},
   {'action': 'GIVE', 'units': 6.5}),
  ('correction only control',
   {'bg': 200, 'target': 100, 'isf': 50, 'carbs_g': 0, 'icr': 10, 'iob': 0, 'max_units': 14},
   {'action': 'GIVE', 'units': 2.0})],
 [('low glucose with meal is held',
   {'bg': 65, 'target': 110, 'isf': 40, 'carbs_g': 45, 'icr': 10, 'iob': 0, 'max_units': 15},
   {'action': 'HOLD', 'units': 0.0}),
  ('glucose exactly 70 is dosed',
   {'bg': 70, 'target': 110, 'isf': 40, 'carbs_g': 90, 'icr': 10, 'iob': 0, 'max_units': 15},
   {'action': 'GIVE', 'units': 8.0}),
  ('high glucose with insulin on board',
   {'bg': 250, 'target': 120, 'isf': 40, 'carbs_g': 85, 'icr': 10, 'iob': 1, 'max_units': 15},
   {'action': 'GIVE', 'units': 10.5}),
  ('below target with insulin on board',
   {'bg': 90, 'target': 120, 'isf': 30, 'carbs_g': 50, 'icr': 10, 'iob': 5, 'max_units': 15},
   {'action': 'GIVE', 'units': 4.0}),
  ('insulin on board exceeds correction',
   {'bg': 160, 'target': 120, 'isf': 40, 'carbs_g': 80, 'icr': 10, 'iob': 3, 'max_units': 15},
   {'action': 'GIVE', 'units': 8.0}),
  ('pen resolution rounds down',
   {'bg': 120, 'target': 120, 'isf': 40, 'carbs_g': 29, 'icr': 10, 'iob': 0, 'max_units': 15},
   {'action': 'GIVE', 'units': 2.5}),
  ('maximum bolus cap not on half unit',
   {'bg': 200, 'target': 120, 'isf': 40, 'carbs_g': 120, 'icr': 10, 'iob': 0, 'max_units': '10.6'},
   {'action': 'GIVE', 'units': 10.5}),
  ('correction only control',
   {'bg': 200, 'target': 100, 'isf': 50, 'carbs_g': 0, 'icr': 10, 'iob': 0, 'max_units': 15},
   {'action': 'GIVE', 'units': 2.0})]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
low glucose with meal is held{'action': 'GIVE', 'units': 3.0}{'action': 'HOLD', 'units': 0.0}Failed
glucose exactly 70 is dosed{'action': 'GIVE', 'units': 4.0}{'action': 'GIVE', 'units': 4.0}Passed
high glucose with insulin on board{'action': 'GIVE', 'units': 8.5}{'action': 'GIVE', 'units': 8.5}Passed
below target with insulin on board{'action': 'GIVE', 'units': 4.0}{'action': 'GIVE', 'units': 4.0}Passed
insulin on board exceeds correction{'action': 'GIVE', 'units': 4.0}{'action': 'GIVE', 'units': 4.0}Passed
pen resolution rounds down{'action': 'GIVE', 'units': 5.5}{'action': 'GIVE', 'units': 5.5}Passed
maximum bolus cap not on half unit{'action': 'GIVE', 'units': 7.5}{'action': 'GIVE', 'units': 7.5}Passed
correction only control{'action': 'GIVE', 'units': 2.0}{'action': 'GIVE', 'units': 2.0}Passed

SHA-256 / 845a913dee42293516591d94ca65dc6274aa36e36b544df2533ce9293e4d8bea

3 / The verified repair

Exit 0
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    bg, tgt = x['bg'], x['target']
    if bg < 70:
        return {'action': 'HOLD', 'units': 0.0}
    corr = Fraction(bg - tgt, x['isf'])
    if corr > 0:
        corr = max(Fraction(0), corr - Fraction(str(x['iob'])))
    meal = Fraction(x['carbs_g'], x['icr'])
    total = max(Fraction(0), meal + corr)
    total = min(total, Fraction(str(x['max_units'])))
    units = Fraction(math.floor(total * 2), 2)
    return {'action': 'GIVE', 'units': float(units)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('low glucose with meal is held',
   {'bg': 61, 'target': 110, 'isf': 40, 'carbs_g': 45, 'icr': 10, 'iob': 0, 'max_units': 15},
   {'action': 'HOLD', 'units': 0.0}),
  ('glucose exactly 70 is dosed',
   {'bg': 70, 'target': 110, 'isf': 40, 'carbs_g': 50, 'icr': 10, 'iob': 0, 'max_units': 15},
   {'action': 'GIVE', 'units': 4.0}),
  ('high glucose with insulin on board',
   {'bg': 250, 'target': 120, 'isf': 40, 'carbs_g': 65, 'icr': 10, 'iob': 1, 'max_units': 15},
   {'action': 'GIVE', 'units': 8.5}),
  ('below target with insulin on board',
   {'bg': 90, 'target': 120, 'isf': 30, 'carbs_g': 50, 'icr': 10, 'iob': 1, 'max_units': 15},
   {'action': 'GIVE', 'units': 4.0}),
  ('insulin on board exceeds correction',
   {'bg': 160, 'target': 120, 'isf': 40, 'carbs_g': 40, 'icr': 10, 'iob': 3, 'max_units': 15},
   {'action': 'GIVE', 'units': 4.0}),
  ('pen resolution rounds down',
   {'bg': 120, 'target': 120, 'isf': 40, 'carbs_g': 59, 'icr': 10, 'iob': 0, 'max_units': 15},
   {'action': 'GIVE', 'units': 5.5}),
  ('maximum bolus cap not on half unit',
   {'bg': 200, 'target': 120, 'isf': 40, 'carbs_g': 120, 'icr': 10, 'iob': 0, 'max_units': '7.8'},
   {'action': 'GIVE', 'units': 7.5}),
  ('correction only control',
   {'bg': 200, 'target': 100, 'isf': 50, 'carbs_g': 0, 'icr': 10, 'iob': 0, 'max_units': 11},
   {'action': 'GIVE', 'units': 2.0})],
 [('low glucose with meal is held',
   {'bg': 62, 'target': 110, 'isf': 40, 'carbs_g': 45, 'icr': 10, 'iob': 0, 'max_units': 15},
   {'action': 'HOLD', 'units': 0.0}),
  ('glucose exactly 70 is dosed',
   {'bg': 70, 'target': 110, 'isf': 40, 'carbs_g': 60, 'icr': 10, 'iob': 0, 'max_units': 15},
   {'action': 'GIVE', 'units': 5.0}),
  ('high glucose with insulin on board',
   {'bg': 250, 'target': 120, 'isf': 40, 'carbs_g': 70, 'icr': 10, 'iob': 1, 'max_units': 15},
   {'action': 'GIVE', 'units': 9.0}),
  ('below target with insulin on board',
   {'bg': 90, 'target': 120, 'isf': 30, 'carbs_g': 50, 'icr': 10, 'iob': 2, 'max_units': 15},
   {'action': 'GIVE', 'units': 4.0}),
  ('insulin on board exceeds correction',
   {'bg': 160, 'target': 120, 'isf': 40, 'carbs_g': 50, 'icr': 10, 'iob': 3, 'max_units': 15},
   {'action': 'GIVE', 'units': 5.0}),
  ('pen resolution rounds down',
   {'bg': 120, 'target': 120, 'isf': 40, 'carbs_g': 49, 'icr': 10, 'iob': 0, 'max_units': 15},
   {'action': 'GIVE', 'units': 4.5}),
  ('maximum bolus cap not on half unit',
   {'bg': 200, 'target': 120, 'isf': 40, 'carbs_g': 120, 'icr': 10, 'iob': 0, 'max_units': '7.6'},
   {'action': 'GIVE', 'units': 7.5}),
  ('correction only control',
   {'bg': 200, 'target': 100, 'isf': 50, 'carbs_g': 0, 'icr': 10, 'iob': 0, 'max_units': 12},
   {'action': 'GIVE', 'units': 2.0})],
 [('low glucose with meal is held',
   {'bg': 63, 'target': 110, 'isf': 40, 'carbs_g': 45, 'icr': 10, 'iob': 0, 'max_units': 15},
   {'action': 'HOLD', 'units': 0.0}),
  ('glucose exactly 70 is dosed',
   {'bg': 70, 'target': 110, 'isf': 40, 'carbs_g': 70, 'icr': 10, 'iob': 0, 'max_units': 15},
   {'action': 'GIVE', 'units': 6.0}),
  ('high glucose with insulin on board',
   {'bg': 250, 'target': 120, 'isf': 40, 'carbs_g': 75, 'icr': 10, 'iob': 1, 'max_units': 15},
   {'action': 'GIVE', 'units': 9.5}),
  ('below target with insulin on board',
   {'bg': 90, 'target': 120, 'isf': 30, 'carbs_g': 50, 'icr': 10, 'iob': 3, 'max_units': 15},
   {'action': 'GIVE', 'units': 4.0}),
  ('insulin on board exceeds correction',
   {'bg': 160, 'target': 120, 'isf': 40, 'carbs_g': 60, 'icr': 10, 'iob': 3, 'max_units': 15},
   {'action': 'GIVE', 'units': 6.0}),
  ('pen resolution rounds down',
   {'bg': 120, 'target': 120, 'isf': 40, 'carbs_g': 38, 'icr': 10, 'iob': 0, 'max_units': 15},
   {'action': 'GIVE', 'units': 3.5}),
  ('maximum bolus cap not on half unit',
   {'bg': 200, 'target': 120, 'isf': 40, 'carbs_g': 120, 'icr': 10, 'iob': 0, 'max_units': '4.7'},
   {'action': 'GIVE', 'units': 4.5}),
  ('correction only control',
   {'bg': 200, 'target': 100, 'isf': 50, 'carbs_g': 0, 'icr': 10, 'iob': 0, 'max_units': 13},
   {'action': 'GIVE', 'units': 2.0})],
 [('low glucose with meal is held',
   {'bg': 64, 'target': 110, 'isf': 40, 'carbs_g': 45, 'icr': 10, 'iob': 0, 'max_units': 15},
   {'action': 'HOLD', 'units': 0.0}),
  ('glucose exactly 70 is dosed',
   {'bg': 70, 'target': 110, 'isf': 40, 'carbs_g': 80, 'icr': 10, 'iob': 0, 'max_units': 15},
   {'action': 'GIVE', 'units': 7.0}),
  ('high glucose with insulin on board',
   {'bg': 250, 'target': 120, 'isf': 40, 'carbs_g': 80, 'icr': 10, 'iob': 1, 'max_units': 15},
   {'action': 'GIVE', 'units': 10.0}),
  ('below target with insulin on board',
   {'bg': 90, 'target': 120, 'isf': 30, 'carbs_g': 50, 'icr': 10, 'iob': 4, 'max_units': 15},
   {'action': 'GIVE', 'units': 4.0}),
  ('insulin on board exceeds correction',
   {'bg': 160, 'target': 120, 'isf': 40, 'carbs_g': 70, 'icr': 10, 'iob': 3, 'max_units': 15},
   {'action': 'GIVE', 'units': 7.0}),
  ('pen resolution rounds down',
   {'bg': 120, 'target': 120, 'isf': 40, 'carbs_g': 69, 'icr': 10, 'iob': 0, 'max_units': 15},
   {'action': 'GIVE', 'units': 6.5}),
  ('maximum bolus cap not on half unit',
   {'bg': 200, 'target': 120, 'isf': 40, 'carbs_g': 120, 'icr': 10, 'iob': 0, 'max_units': '6.9'},
   {'action': 'GIVE', 'units': 6.5}),
  ('correction only control',
   {'bg': 200, 'target': 100, 'isf': 50, 'carbs_g': 0, 'icr': 10, 'iob': 0, 'max_units': 14},
   {'action': 'GIVE', 'units': 2.0})],
 [('low glucose with meal is held',
   {'bg': 65, 'target': 110, 'isf': 40, 'carbs_g': 45, 'icr': 10, 'iob': 0, 'max_units': 15},
   {'action': 'HOLD', 'units': 0.0}),
  ('glucose exactly 70 is dosed',
   {'bg': 70, 'target': 110, 'isf': 40, 'carbs_g': 90, 'icr': 10, 'iob': 0, 'max_units': 15},
   {'action': 'GIVE', 'units': 8.0}),
  ('high glucose with insulin on board',
   {'bg': 250, 'target': 120, 'isf': 40, 'carbs_g': 85, 'icr': 10, 'iob': 1, 'max_units': 15},
   {'action': 'GIVE', 'units': 10.5}),
  ('below target with insulin on board',
   {'bg': 90, 'target': 120, 'isf': 30, 'carbs_g': 50, 'icr': 10, 'iob': 5, 'max_units': 15},
   {'action': 'GIVE', 'units': 4.0}),
  ('insulin on board exceeds correction',
   {'bg': 160, 'target': 120, 'isf': 40, 'carbs_g': 80, 'icr': 10, 'iob': 3, 'max_units': 15},
   {'action': 'GIVE', 'units': 8.0}),
  ('pen resolution rounds down',
   {'bg': 120, 'target': 120, 'isf': 40, 'carbs_g': 29, 'icr': 10, 'iob': 0, 'max_units': 15},
   {'action': 'GIVE', 'units': 2.5}),
  ('maximum bolus cap not on half unit',
   {'bg': 200, 'target': 120, 'isf': 40, 'carbs_g': 120, 'icr': 10, 'iob': 0, 'max_units': '10.6'},
   {'action': 'GIVE', 'units': 10.5}),
  ('correction only control',
   {'bg': 200, 'target': 100, 'isf': 50, 'carbs_g': 0, 'icr': 10, 'iob': 0, 'max_units': 15},
   {'action': 'GIVE', 'units': 2.0})]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
low glucose with meal is held{'action': 'HOLD', 'units': 0.0}{'action': 'HOLD', 'units': 0.0}Passed
glucose exactly 70 is dosed{'action': 'GIVE', 'units': 4.0}{'action': 'GIVE', 'units': 4.0}Passed
high glucose with insulin on board{'action': 'GIVE', 'units': 8.5}{'action': 'GIVE', 'units': 8.5}Passed
below target with insulin on board{'action': 'GIVE', 'units': 4.0}{'action': 'GIVE', 'units': 4.0}Passed
insulin on board exceeds correction{'action': 'GIVE', 'units': 4.0}{'action': 'GIVE', 'units': 4.0}Passed
pen resolution rounds down{'action': 'GIVE', 'units': 5.5}{'action': 'GIVE', 'units': 5.5}Passed
maximum bolus cap not on half unit{'action': 'GIVE', 'units': 7.5}{'action': 'GIVE', 'units': 7.5}Passed
correction only control{'action': 'GIVE', 'units': 2.0}{'action': 'GIVE', 'units': 2.0}Passed

SHA-256 / 83a53204570077d92ce524dde2f25d1630a6f0850a027abf8e070f15326367b8

Verification & scope

A deterministic toy software model with explicitly stipulated thresholds and formulas; it is not clinical guidance, not a validated medical calculator, and makes no claim of conformance to any published protocol. Numbered variants vary patient and order inputs. This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.

Observations recorded using Python 3.12.14 at 2026-09-29T14:47:19.848372+00:00.

Case digest / 2c511c0545f7f2fc058dbe53fbf232d0cc7ff97b20958c1abf1c9b5e51f34bf8