FAILURE MAP
← Case archive

FA-64296 / Medication dosing calculations / Open access

Infusion bag run-out time across rate changes: rate per minute conversion · case 01

A 125 mL/h bag is predicted to empty in minutes.

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

ROOT CAUSE

mL/h is treated as mL/min when computing consumption.

VERIFIED REPAIR

Divide the hourly rate by 60 to get mL per minute.

Unsuccessful approach: Inverting the conversion gives minutes per mL, not mL per minute.

Case contract

Input {bag_ml, segments [[start_min, rate_ml_h], ...] ascending from 0}. Each segment runs until the next start; the last segment is open-ended. Paused segments (rate 0) consume nothing. Return {empty_min, alarm_min = max(0, empty-30)} rounded to 0.1 min, or both None when the bag never empties.

Why this case matters

Run-out prediction walks piecewise-constant rates; segment edges, open-ended tails and unit conversion fail independently.

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):
    left = Fraction(x['bag_ml'])
    segs = x['segments']
    for i, (t0, rate) in enumerate(segs):
        t1 = segs[i + 1][0] if i + 1 < len(segs) else None
        if rate == 0:
            continue
        per_min = Fraction(rate)
        need = left / per_min
        if t1 is None or t0 + need <= t1:
            empty = t0 + need
            return {'empty_min': round(float(empty), 1), 'alarm_min': round(float(max(Fraction(0), empty - 30)), 1)}
        left -= per_min * (t1 - t0)
    return {'empty_min': None, 'alarm_min': None}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('single rate', {'bag_ml': 500, 'segments': [[0, 125]]}, {'empty_min': 240.0, 'alarm_min': 210.0}),
  ('rate change mid bag',
   {'bag_ml': 1000, 'segments': [[0, 125], [240, 260]]},
   {'empty_min': 355.4, 'alarm_min': 325.4}),
  ('empties exactly at pause',
   {'bag_ml': 250, 'segments': [[0, 125], [120, 0], [150, 60]]},
   {'empty_min': 120.0, 'alarm_min': 90.0}),
  ('empties exactly at end of final paused tail',
   {'bag_ml': 100, 'segments': [[0, 50], [120, 0]]},
   {'empty_min': 120.0, 'alarm_min': 90.0}),
  ('bag outlasts second segment before pause',
   {'bag_ml': 110, 'segments': [[0, 60], [60, 60], [100, 0]]},
   {'empty_min': None, 'alarm_min': None}),
  ('completed middle segment consumption',
   {'bag_ml': 200, 'segments': [[0, 60], [30, 120], [60, 31]]},
   {'empty_min': 272.9, 'alarm_min': 242.9}),
  ('small bag alarm clamps at zero',
   {'bag_ml': 20, 'segments': [[0, 80]]},
   {'empty_min': 15.0, 'alarm_min': 0.0}),
  ('pause then resume',
   {'bag_ml': 100, 'segments': [[0, 60], [30, 0], [90, 30]]},
   {'empty_min': 230.0, 'alarm_min': 200.0}),
  ('very slow multi-day tail',
   {'bag_ml': 1000, 'segments': [[0, 50], [60, 11]]},
   {'empty_min': 5241.8, 'alarm_min': 5211.8})],
 [('single rate', {'bag_ml': 500, 'segments': [[0, 150]]}, {'empty_min': 200.0, 'alarm_min': 170.0}),
  ('rate change mid bag',
   {'bag_ml': 1000, 'segments': [[0, 125], [240, 270]]},
   {'empty_min': 351.1, 'alarm_min': 321.1}),
  ('empties exactly at pause',
   {'bag_ml': 250, 'segments': [[0, 125], [120, 0], [180, 60]]},
   {'empty_min': 120.0, 'alarm_min': 90.0}),
  ('empties exactly at end of final paused tail',
   {'bag_ml': 100, 'segments': [[0, 50], [120, 0]]},
   {'empty_min': 120.0, 'alarm_min': 90.0}),
  ('bag outlasts second segment before pause',
   {'bag_ml': 120, 'segments': [[0, 60], [60, 60], [100, 0]]},
   {'empty_min': None, 'alarm_min': None}),
  ('completed middle segment consumption',
   {'bag_ml': 200, 'segments': [[0, 60], [30, 120], [60, 32]]},
   {'empty_min': 266.2, 'alarm_min': 236.2}),
  ('small bag alarm clamps at zero',
   {'bag_ml': 20, 'segments': [[0, 100]]},
   {'empty_min': 12.0, 'alarm_min': 0.0}),
  ('pause then resume',
   {'bag_ml': 100, 'segments': [[0, 60], [30, 0], [90, 60]]},
   {'empty_min': 160.0, 'alarm_min': 130.0}),
  ('very slow multi-day tail',
   {'bag_ml': 1000, 'segments': [[0, 50], [60, 12]]},
   {'empty_min': 4810.0, 'alarm_min': 4780.0})],
 [('single rate', {'bag_ml': 500, 'segments': [[0, 175]]}, {'empty_min': 171.4, 'alarm_min': 141.4}),
  ('rate change mid bag',
   {'bag_ml': 1000, 'segments': [[0, 125], [240, 280]]},
   {'empty_min': 347.1, 'alarm_min': 317.1}),
  ('empties exactly at pause',
   {'bag_ml': 250, 'segments': [[0, 125], [120, 0], [210, 60]]},
   {'empty_min': 120.0, 'alarm_min': 90.0}),
  ('empties exactly at end of final paused tail',
   {'bag_ml': 100, 'segments': [[0, 50], [120, 0]]},
   {'empty_min': 120.0, 'alarm_min': 90.0}),
  ('bag outlasts second segment before pause',
   {'bag_ml': 130, 'segments': [[0, 60], [60, 60], [100, 0]]},
   {'empty_min': None, 'alarm_min': None}),
  ('completed middle segment consumption',
   {'bag_ml': 200, 'segments': [[0, 60], [30, 120], [60, 33]]},
   {'empty_min': 260.0, 'alarm_min': 230.0}),
  ('small bag alarm clamps at zero',
   {'bag_ml': 20, 'segments': [[0, 120]]},
   {'empty_min': 10.0, 'alarm_min': 0.0}),
  ('pause then resume',
   {'bag_ml': 100, 'segments': [[0, 60], [30, 0], [90, 90]]},
   {'empty_min': 136.7, 'alarm_min': 106.7}),
  ('very slow multi-day tail',
   {'bag_ml': 1000, 'segments': [[0, 50], [60, 13]]},
   {'empty_min': 4444.6, 'alarm_min': 4414.6})],
 [('single rate', {'bag_ml': 500, 'segments': [[0, 200]]}, {'empty_min': 150.0, 'alarm_min': 120.0}),
  ('rate change mid bag',
   {'bag_ml': 1000, 'segments': [[0, 125], [240, 290]]},
   {'empty_min': 343.4, 'alarm_min': 313.4}),
  ('empties exactly at pause',
   {'bag_ml': 250, 'segments': [[0, 125], [120, 0], [240, 60]]},
   {'empty_min': 120.0, 'alarm_min': 90.0}),
  ('empties exactly at end of final paused tail',
   {'bag_ml': 100, 'segments': [[0, 50], [120, 0]]},
   {'empty_min': 120.0, 'alarm_min': 90.0}),
  ('bag outlasts second segment before pause',
   {'bag_ml': 140, 'segments': [[0, 60], [60, 60], [100, 0]]},
   {'empty_min': None, 'alarm_min': None}),
  ('completed middle segment consumption',
   {'bag_ml': 200, 'segments': [[0, 60], [30, 120], [60, 34]]},
   {'empty_min': 254.1, 'alarm_min': 224.1}),
  ('small bag alarm clamps at zero',
   {'bag_ml': 20, 'segments': [[0, 140]]},
   {'empty_min': 8.6, 'alarm_min': 0.0}),
  ('pause then resume',
   {'bag_ml': 100, 'segments': [[0, 60], [30, 0], [90, 120]]},
   {'empty_min': 125.0, 'alarm_min': 95.0}),
  ('very slow multi-day tail',
   {'bag_ml': 1000, 'segments': [[0, 50], [60, 14]]},
   {'empty_min': 4131.4, 'alarm_min': 4101.4})],
 [('single rate', {'bag_ml': 500, 'segments': [[0, 225]]}, {'empty_min': 133.3, 'alarm_min': 103.3}),
  ('rate change mid bag',
   {'bag_ml': 1000, 'segments': [[0, 125], [240, 300]]},
   {'empty_min': 340.0, 'alarm_min': 310.0}),
  ('empties exactly at pause',
   {'bag_ml': 250, 'segments': [[0, 125], [120, 0], [270, 60]]},
   {'empty_min': 120.0, 'alarm_min': 90.0}),
  ('empties exactly at end of final paused tail',
   {'bag_ml': 100, 'segments': [[0, 50], [120, 0]]},
   {'empty_min': 120.0, 'alarm_min': 90.0}),
  ('bag outlasts second segment before pause',
   {'bag_ml': 150, 'segments': [[0, 60], [60, 60], [100, 0]]},
   {'empty_min': None, 'alarm_min': None}),
  ('completed middle segment consumption',
   {'bag_ml': 200, 'segments': [[0, 60], [30, 120], [60, 35]]},
   {'empty_min': 248.6, 'alarm_min': 218.6}),
  ('small bag alarm clamps at zero',
   {'bag_ml': 20, 'segments': [[0, 160]]},
   {'empty_min': 7.5, 'alarm_min': 0.0}),
  ('pause then resume',
   {'bag_ml': 100, 'segments': [[0, 60], [30, 0], [90, 150]]},
   {'empty_min': 118.0, 'alarm_min': 88.0}),
  ('very slow multi-day tail',
   {'bag_ml': 1000, 'segments': [[0, 50], [60, 15]]},
   {'empty_min': 3860.0, 'alarm_min': 3830.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
single rate{'alarm_min': 0.0, 'empty_min': 4.0}{'alarm_min': 210.0, 'empty_min': 240.0}Failed
rate change mid bag{'alarm_min': 0.0, 'empty_min': 8.0}{'alarm_min': 325.4, 'empty_min': 355.4}Failed
empties exactly at pause{'alarm_min': 0.0, 'empty_min': 2.0}{'alarm_min': 90.0, 'empty_min': 120.0}Failed
empties exactly at end of final paused tail{'alarm_min': 0.0, 'empty_min': 2.0}{'alarm_min': 90.0, 'empty_min': 120.0}Failed
bag outlasts second segment before pause{'alarm_min': 0.0, 'empty_min': 1.8}{'alarm_min': None, 'empty_min': None}Failed
completed middle segment consumption{'alarm_min': 0.0, 'empty_min': 3.3}{'alarm_min': 242.9, 'empty_min': 272.9}Failed
small bag alarm clamps at zero{'alarm_min': 0.0, 'empty_min': 0.2}{'alarm_min': 0.0, 'empty_min': 15.0}Failed
pause then resume{'alarm_min': 0.0, 'empty_min': 1.7}{'alarm_min': 200.0, 'empty_min': 230.0}Failed
very slow multi-day tail{'alarm_min': 0.0, 'empty_min': 20.0}{'alarm_min': 5211.8, 'empty_min': 5241.8}Failed

SHA-256 / 5f618fc8131f7dabc50ca7cbcfd702d4cc09fe4afd653c2a3f0136adfb842346

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):
    left = Fraction(x['bag_ml'])
    segs = x['segments']
    for i, (t0, rate) in enumerate(segs):
        t1 = segs[i + 1][0] if i + 1 < len(segs) else None
        if rate == 0:
            continue
        per_min = Fraction(60, rate)
        need = left / per_min
        if t1 is None or t0 + need <= t1:
            empty = t0 + need
            return {'empty_min': round(float(empty), 1), 'alarm_min': round(float(max(Fraction(0), empty - 30)), 1)}
        left -= per_min * (t1 - t0)
    return {'empty_min': None, 'alarm_min': None}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('single rate', {'bag_ml': 500, 'segments': [[0, 125]]}, {'empty_min': 240.0, 'alarm_min': 210.0}),
  ('rate change mid bag',
   {'bag_ml': 1000, 'segments': [[0, 125], [240, 260]]},
   {'empty_min': 355.4, 'alarm_min': 325.4}),
  ('empties exactly at pause',
   {'bag_ml': 250, 'segments': [[0, 125], [120, 0], [150, 60]]},
   {'empty_min': 120.0, 'alarm_min': 90.0}),
  ('empties exactly at end of final paused tail',
   {'bag_ml': 100, 'segments': [[0, 50], [120, 0]]},
   {'empty_min': 120.0, 'alarm_min': 90.0}),
  ('bag outlasts second segment before pause',
   {'bag_ml': 110, 'segments': [[0, 60], [60, 60], [100, 0]]},
   {'empty_min': None, 'alarm_min': None}),
  ('completed middle segment consumption',
   {'bag_ml': 200, 'segments': [[0, 60], [30, 120], [60, 31]]},
   {'empty_min': 272.9, 'alarm_min': 242.9}),
  ('small bag alarm clamps at zero',
   {'bag_ml': 20, 'segments': [[0, 80]]},
   {'empty_min': 15.0, 'alarm_min': 0.0}),
  ('pause then resume',
   {'bag_ml': 100, 'segments': [[0, 60], [30, 0], [90, 30]]},
   {'empty_min': 230.0, 'alarm_min': 200.0}),
  ('very slow multi-day tail',
   {'bag_ml': 1000, 'segments': [[0, 50], [60, 11]]},
   {'empty_min': 5241.8, 'alarm_min': 5211.8})],
 [('single rate', {'bag_ml': 500, 'segments': [[0, 150]]}, {'empty_min': 200.0, 'alarm_min': 170.0}),
  ('rate change mid bag',
   {'bag_ml': 1000, 'segments': [[0, 125], [240, 270]]},
   {'empty_min': 351.1, 'alarm_min': 321.1}),
  ('empties exactly at pause',
   {'bag_ml': 250, 'segments': [[0, 125], [120, 0], [180, 60]]},
   {'empty_min': 120.0, 'alarm_min': 90.0}),
  ('empties exactly at end of final paused tail',
   {'bag_ml': 100, 'segments': [[0, 50], [120, 0]]},
   {'empty_min': 120.0, 'alarm_min': 90.0}),
  ('bag outlasts second segment before pause',
   {'bag_ml': 120, 'segments': [[0, 60], [60, 60], [100, 0]]},
   {'empty_min': None, 'alarm_min': None}),
  ('completed middle segment consumption',
   {'bag_ml': 200, 'segments': [[0, 60], [30, 120], [60, 32]]},
   {'empty_min': 266.2, 'alarm_min': 236.2}),
  ('small bag alarm clamps at zero',
   {'bag_ml': 20, 'segments': [[0, 100]]},
   {'empty_min': 12.0, 'alarm_min': 0.0}),
  ('pause then resume',
   {'bag_ml': 100, 'segments': [[0, 60], [30, 0], [90, 60]]},
   {'empty_min': 160.0, 'alarm_min': 130.0}),
  ('very slow multi-day tail',
   {'bag_ml': 1000, 'segments': [[0, 50], [60, 12]]},
   {'empty_min': 4810.0, 'alarm_min': 4780.0})],
 [('single rate', {'bag_ml': 500, 'segments': [[0, 175]]}, {'empty_min': 171.4, 'alarm_min': 141.4}),
  ('rate change mid bag',
   {'bag_ml': 1000, 'segments': [[0, 125], [240, 280]]},
   {'empty_min': 347.1, 'alarm_min': 317.1}),
  ('empties exactly at pause',
   {'bag_ml': 250, 'segments': [[0, 125], [120, 0], [210, 60]]},
   {'empty_min': 120.0, 'alarm_min': 90.0}),
  ('empties exactly at end of final paused tail',
   {'bag_ml': 100, 'segments': [[0, 50], [120, 0]]},
   {'empty_min': 120.0, 'alarm_min': 90.0}),
  ('bag outlasts second segment before pause',
   {'bag_ml': 130, 'segments': [[0, 60], [60, 60], [100, 0]]},
   {'empty_min': None, 'alarm_min': None}),
  ('completed middle segment consumption',
   {'bag_ml': 200, 'segments': [[0, 60], [30, 120], [60, 33]]},
   {'empty_min': 260.0, 'alarm_min': 230.0}),
  ('small bag alarm clamps at zero',
   {'bag_ml': 20, 'segments': [[0, 120]]},
   {'empty_min': 10.0, 'alarm_min': 0.0}),
  ('pause then resume',
   {'bag_ml': 100, 'segments': [[0, 60], [30, 0], [90, 90]]},
   {'empty_min': 136.7, 'alarm_min': 106.7}),
  ('very slow multi-day tail',
   {'bag_ml': 1000, 'segments': [[0, 50], [60, 13]]},
   {'empty_min': 4444.6, 'alarm_min': 4414.6})],
 [('single rate', {'bag_ml': 500, 'segments': [[0, 200]]}, {'empty_min': 150.0, 'alarm_min': 120.0}),
  ('rate change mid bag',
   {'bag_ml': 1000, 'segments': [[0, 125], [240, 290]]},
   {'empty_min': 343.4, 'alarm_min': 313.4}),
  ('empties exactly at pause',
   {'bag_ml': 250, 'segments': [[0, 125], [120, 0], [240, 60]]},
   {'empty_min': 120.0, 'alarm_min': 90.0}),
  ('empties exactly at end of final paused tail',
   {'bag_ml': 100, 'segments': [[0, 50], [120, 0]]},
   {'empty_min': 120.0, 'alarm_min': 90.0}),
  ('bag outlasts second segment before pause',
   {'bag_ml': 140, 'segments': [[0, 60], [60, 60], [100, 0]]},
   {'empty_min': None, 'alarm_min': None}),
  ('completed middle segment consumption',
   {'bag_ml': 200, 'segments': [[0, 60], [30, 120], [60, 34]]},
   {'empty_min': 254.1, 'alarm_min': 224.1}),
  ('small bag alarm clamps at zero',
   {'bag_ml': 20, 'segments': [[0, 140]]},
   {'empty_min': 8.6, 'alarm_min': 0.0}),
  ('pause then resume',
   {'bag_ml': 100, 'segments': [[0, 60], [30, 0], [90, 120]]},
   {'empty_min': 125.0, 'alarm_min': 95.0}),
  ('very slow multi-day tail',
   {'bag_ml': 1000, 'segments': [[0, 50], [60, 14]]},
   {'empty_min': 4131.4, 'alarm_min': 4101.4})],
 [('single rate', {'bag_ml': 500, 'segments': [[0, 225]]}, {'empty_min': 133.3, 'alarm_min': 103.3}),
  ('rate change mid bag',
   {'bag_ml': 1000, 'segments': [[0, 125], [240, 300]]},
   {'empty_min': 340.0, 'alarm_min': 310.0}),
  ('empties exactly at pause',
   {'bag_ml': 250, 'segments': [[0, 125], [120, 0], [270, 60]]},
   {'empty_min': 120.0, 'alarm_min': 90.0}),
  ('empties exactly at end of final paused tail',
   {'bag_ml': 100, 'segments': [[0, 50], [120, 0]]},
   {'empty_min': 120.0, 'alarm_min': 90.0}),
  ('bag outlasts second segment before pause',
   {'bag_ml': 150, 'segments': [[0, 60], [60, 60], [100, 0]]},
   {'empty_min': None, 'alarm_min': None}),
  ('completed middle segment consumption',
   {'bag_ml': 200, 'segments': [[0, 60], [30, 120], [60, 35]]},
   {'empty_min': 248.6, 'alarm_min': 218.6}),
  ('small bag alarm clamps at zero',
   {'bag_ml': 20, 'segments': [[0, 160]]},
   {'empty_min': 7.5, 'alarm_min': 0.0}),
  ('pause then resume',
   {'bag_ml': 100, 'segments': [[0, 60], [30, 0], [90, 150]]},
   {'empty_min': 118.0, 'alarm_min': 88.0}),
  ('very slow multi-day tail',
   {'bag_ml': 1000, 'segments': [[0, 50], [60, 15]]},
   {'empty_min': 3860.0, 'alarm_min': 3830.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
single rate{'alarm_min': 1011.7, 'empty_min': 1041.7}{'alarm_min': 210.0, 'empty_min': 240.0}Failed
rate change mid bag{'alarm_min': 4044.1, 'empty_min': 4074.1}{'alarm_min': 325.4, 'empty_min': 355.4}Failed
empties exactly at pause{'alarm_min': 312.4, 'empty_min': 342.4}{'alarm_min': 90.0, 'empty_min': 120.0}Failed
empties exactly at end of final paused tail{'alarm_min': 53.3, 'empty_min': 83.3}{'alarm_min': 90.0, 'empty_min': 120.0}Failed
bag outlasts second segment before pause{'alarm_min': None, 'empty_min': None}{'alarm_min': None, 'empty_min': None}Passed
completed middle segment consumption{'alarm_min': 110.1, 'empty_min': 140.1}{'alarm_min': 242.9, 'empty_min': 272.9}Failed
small bag alarm clamps at zero{'alarm_min': 0.0, 'empty_min': 26.7}{'alarm_min': 0.0, 'empty_min': 15.0}Failed
pause then resume{'alarm_min': 95.0, 'empty_min': 125.0}{'alarm_min': 200.0, 'empty_min': 230.0}Failed
very slow multi-day tail{'alarm_min': 200.1, 'empty_min': 230.1}{'alarm_min': 5211.8, 'empty_min': 5241.8}Failed

SHA-256 / 737cd70e7deca677bd8b06bddb13683df15be2a05bfe437489b03dda7d050da0

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):
    left = Fraction(x['bag_ml'])
    segs = x['segments']
    for i, (t0, rate) in enumerate(segs):
        t1 = segs[i + 1][0] if i + 1 < len(segs) else None
        if rate == 0:
            continue
        per_min = Fraction(rate, 60)
        need = left / per_min
        if t1 is None or t0 + need <= t1:
            empty = t0 + need
            return {'empty_min': round(float(empty), 1), 'alarm_min': round(float(max(Fraction(0), empty - 30)), 1)}
        left -= per_min * (t1 - t0)
    return {'empty_min': None, 'alarm_min': None}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('single rate', {'bag_ml': 500, 'segments': [[0, 125]]}, {'empty_min': 240.0, 'alarm_min': 210.0}),
  ('rate change mid bag',
   {'bag_ml': 1000, 'segments': [[0, 125], [240, 260]]},
   {'empty_min': 355.4, 'alarm_min': 325.4}),
  ('empties exactly at pause',
   {'bag_ml': 250, 'segments': [[0, 125], [120, 0], [150, 60]]},
   {'empty_min': 120.0, 'alarm_min': 90.0}),
  ('empties exactly at end of final paused tail',
   {'bag_ml': 100, 'segments': [[0, 50], [120, 0]]},
   {'empty_min': 120.0, 'alarm_min': 90.0}),
  ('bag outlasts second segment before pause',
   {'bag_ml': 110, 'segments': [[0, 60], [60, 60], [100, 0]]},
   {'empty_min': None, 'alarm_min': None}),
  ('completed middle segment consumption',
   {'bag_ml': 200, 'segments': [[0, 60], [30, 120], [60, 31]]},
   {'empty_min': 272.9, 'alarm_min': 242.9}),
  ('small bag alarm clamps at zero',
   {'bag_ml': 20, 'segments': [[0, 80]]},
   {'empty_min': 15.0, 'alarm_min': 0.0}),
  ('pause then resume',
   {'bag_ml': 100, 'segments': [[0, 60], [30, 0], [90, 30]]},
   {'empty_min': 230.0, 'alarm_min': 200.0}),
  ('very slow multi-day tail',
   {'bag_ml': 1000, 'segments': [[0, 50], [60, 11]]},
   {'empty_min': 5241.8, 'alarm_min': 5211.8})],
 [('single rate', {'bag_ml': 500, 'segments': [[0, 150]]}, {'empty_min': 200.0, 'alarm_min': 170.0}),
  ('rate change mid bag',
   {'bag_ml': 1000, 'segments': [[0, 125], [240, 270]]},
   {'empty_min': 351.1, 'alarm_min': 321.1}),
  ('empties exactly at pause',
   {'bag_ml': 250, 'segments': [[0, 125], [120, 0], [180, 60]]},
   {'empty_min': 120.0, 'alarm_min': 90.0}),
  ('empties exactly at end of final paused tail',
   {'bag_ml': 100, 'segments': [[0, 50], [120, 0]]},
   {'empty_min': 120.0, 'alarm_min': 90.0}),
  ('bag outlasts second segment before pause',
   {'bag_ml': 120, 'segments': [[0, 60], [60, 60], [100, 0]]},
   {'empty_min': None, 'alarm_min': None}),
  ('completed middle segment consumption',
   {'bag_ml': 200, 'segments': [[0, 60], [30, 120], [60, 32]]},
   {'empty_min': 266.2, 'alarm_min': 236.2}),
  ('small bag alarm clamps at zero',
   {'bag_ml': 20, 'segments': [[0, 100]]},
   {'empty_min': 12.0, 'alarm_min': 0.0}),
  ('pause then resume',
   {'bag_ml': 100, 'segments': [[0, 60], [30, 0], [90, 60]]},
   {'empty_min': 160.0, 'alarm_min': 130.0}),
  ('very slow multi-day tail',
   {'bag_ml': 1000, 'segments': [[0, 50], [60, 12]]},
   {'empty_min': 4810.0, 'alarm_min': 4780.0})],
 [('single rate', {'bag_ml': 500, 'segments': [[0, 175]]}, {'empty_min': 171.4, 'alarm_min': 141.4}),
  ('rate change mid bag',
   {'bag_ml': 1000, 'segments': [[0, 125], [240, 280]]},
   {'empty_min': 347.1, 'alarm_min': 317.1}),
  ('empties exactly at pause',
   {'bag_ml': 250, 'segments': [[0, 125], [120, 0], [210, 60]]},
   {'empty_min': 120.0, 'alarm_min': 90.0}),
  ('empties exactly at end of final paused tail',
   {'bag_ml': 100, 'segments': [[0, 50], [120, 0]]},
   {'empty_min': 120.0, 'alarm_min': 90.0}),
  ('bag outlasts second segment before pause',
   {'bag_ml': 130, 'segments': [[0, 60], [60, 60], [100, 0]]},
   {'empty_min': None, 'alarm_min': None}),
  ('completed middle segment consumption',
   {'bag_ml': 200, 'segments': [[0, 60], [30, 120], [60, 33]]},
   {'empty_min': 260.0, 'alarm_min': 230.0}),
  ('small bag alarm clamps at zero',
   {'bag_ml': 20, 'segments': [[0, 120]]},
   {'empty_min': 10.0, 'alarm_min': 0.0}),
  ('pause then resume',
   {'bag_ml': 100, 'segments': [[0, 60], [30, 0], [90, 90]]},
   {'empty_min': 136.7, 'alarm_min': 106.7}),
  ('very slow multi-day tail',
   {'bag_ml': 1000, 'segments': [[0, 50], [60, 13]]},
   {'empty_min': 4444.6, 'alarm_min': 4414.6})],
 [('single rate', {'bag_ml': 500, 'segments': [[0, 200]]}, {'empty_min': 150.0, 'alarm_min': 120.0}),
  ('rate change mid bag',
   {'bag_ml': 1000, 'segments': [[0, 125], [240, 290]]},
   {'empty_min': 343.4, 'alarm_min': 313.4}),
  ('empties exactly at pause',
   {'bag_ml': 250, 'segments': [[0, 125], [120, 0], [240, 60]]},
   {'empty_min': 120.0, 'alarm_min': 90.0}),
  ('empties exactly at end of final paused tail',
   {'bag_ml': 100, 'segments': [[0, 50], [120, 0]]},
   {'empty_min': 120.0, 'alarm_min': 90.0}),
  ('bag outlasts second segment before pause',
   {'bag_ml': 140, 'segments': [[0, 60], [60, 60], [100, 0]]},
   {'empty_min': None, 'alarm_min': None}),
  ('completed middle segment consumption',
   {'bag_ml': 200, 'segments': [[0, 60], [30, 120], [60, 34]]},
   {'empty_min': 254.1, 'alarm_min': 224.1}),
  ('small bag alarm clamps at zero',
   {'bag_ml': 20, 'segments': [[0, 140]]},
   {'empty_min': 8.6, 'alarm_min': 0.0}),
  ('pause then resume',
   {'bag_ml': 100, 'segments': [[0, 60], [30, 0], [90, 120]]},
   {'empty_min': 125.0, 'alarm_min': 95.0}),
  ('very slow multi-day tail',
   {'bag_ml': 1000, 'segments': [[0, 50], [60, 14]]},
   {'empty_min': 4131.4, 'alarm_min': 4101.4})],
 [('single rate', {'bag_ml': 500, 'segments': [[0, 225]]}, {'empty_min': 133.3, 'alarm_min': 103.3}),
  ('rate change mid bag',
   {'bag_ml': 1000, 'segments': [[0, 125], [240, 300]]},
   {'empty_min': 340.0, 'alarm_min': 310.0}),
  ('empties exactly at pause',
   {'bag_ml': 250, 'segments': [[0, 125], [120, 0], [270, 60]]},
   {'empty_min': 120.0, 'alarm_min': 90.0}),
  ('empties exactly at end of final paused tail',
   {'bag_ml': 100, 'segments': [[0, 50], [120, 0]]},
   {'empty_min': 120.0, 'alarm_min': 90.0}),
  ('bag outlasts second segment before pause',
   {'bag_ml': 150, 'segments': [[0, 60], [60, 60], [100, 0]]},
   {'empty_min': None, 'alarm_min': None}),
  ('completed middle segment consumption',
   {'bag_ml': 200, 'segments': [[0, 60], [30, 120], [60, 35]]},
   {'empty_min': 248.6, 'alarm_min': 218.6}),
  ('small bag alarm clamps at zero',
   {'bag_ml': 20, 'segments': [[0, 160]]},
   {'empty_min': 7.5, 'alarm_min': 0.0}),
  ('pause then resume',
   {'bag_ml': 100, 'segments': [[0, 60], [30, 0], [90, 150]]},
   {'empty_min': 118.0, 'alarm_min': 88.0}),
  ('very slow multi-day tail',
   {'bag_ml': 1000, 'segments': [[0, 50], [60, 15]]},
   {'empty_min': 3860.0, 'alarm_min': 3830.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
single rate{'alarm_min': 210.0, 'empty_min': 240.0}{'alarm_min': 210.0, 'empty_min': 240.0}Passed
rate change mid bag{'alarm_min': 325.4, 'empty_min': 355.4}{'alarm_min': 325.4, 'empty_min': 355.4}Passed
empties exactly at pause{'alarm_min': 90.0, 'empty_min': 120.0}{'alarm_min': 90.0, 'empty_min': 120.0}Passed
empties exactly at end of final paused tail{'alarm_min': 90.0, 'empty_min': 120.0}{'alarm_min': 90.0, 'empty_min': 120.0}Passed
bag outlasts second segment before pause{'alarm_min': None, 'empty_min': None}{'alarm_min': None, 'empty_min': None}Passed
completed middle segment consumption{'alarm_min': 242.9, 'empty_min': 272.9}{'alarm_min': 242.9, 'empty_min': 272.9}Passed
small bag alarm clamps at zero{'alarm_min': 0.0, 'empty_min': 15.0}{'alarm_min': 0.0, 'empty_min': 15.0}Passed
pause then resume{'alarm_min': 200.0, 'empty_min': 230.0}{'alarm_min': 200.0, 'empty_min': 230.0}Passed
very slow multi-day tail{'alarm_min': 5211.8, 'empty_min': 5241.8}{'alarm_min': 5211.8, 'empty_min': 5241.8}Passed

SHA-256 / cbb41fa490a85e762772542c51ce7ddfa4fdef8ba989c6a6780c3a2b383702d4

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:23.106811+00:00.

Case digest / 5c032a07be9cbe6544de97371eec38147cd072fe888f8fcb814a597a8e150121