FAILURE MAP
← Case archive

FA-59811 / Subscription proration billing / Open access

Package pricing with milli-unit usage: unit rounding grain · case 01

Customers with many small events are billed for far more units than they used.

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

ROOT CAUSE

Each event is rounded up to a whole unit instead of rounding the invoice total once.

VERIFIED REPAIR

Restore the contract rule at the unit rounding grain step: use `units = -(-milli // 1000)`.

Unsuccessful approach: The attempt rounds the total down, giving away partial units.

Case contract

Input {events in milli-units, free units, div (units per package), round up|down, price per package}. Units = ceil(sum(events)/1000) once per invoice. Billable = max(0, units - free). Packages = ceil or floor(billable/div) by round. Return [units, packages, packages*price].

Why this case matters

Package pricing rounds usage twice, and doing either rounding at the wrong grain changes the bill.

1 / The failure

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    milli = sum(x['events'])
    units = sum(-(-e // 1000) for e in x['events'])
    billable = max(0, units - x['free'])
    if x['round'] == 'up':
        packs = -(-billable // x['div'])
    else:
        packs = billable // x['div']
    return [units, packs, packs * x['price']]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'events': [4863, 300, 2484, 893, 1000, 741], 'free': 10, 'div': 5, 'round': 'down', 'price': 999}, [11, 0, 0]), ('regression', {'events': [1332, 1000, 3819, 645, 1000, 333], 'free': 0, 'div': 10, 'round': 'up', 'price': 250}, [9, 1, 250]), ('partial-repair probe', {'events': [1000, 452], 'free': 5, 'div': 100, 'round': 'up', 'price': 999}, [2, 0, 0]), ('partial-repair probe', {'events': [35, 1000, 2766, 1000, 937], 'free': 0, 'div': 10, 'round': 'up', 'price': 100}, [6, 1, 100]), ('normal control', {'events': [], 'free': 10, 'div': 100, 'round': 'up', 'price': 100}, [0, 0, 0]), ('normal control', {'events': [1000], 'free': 10, 'div': 100, 'round': 'down', 'price': 999}, [1, 0, 0]), ('normal control', {'events': [1000], 'free': 10, 'div': 10, 'round': 'down', 'price': 999}, [1, 0, 0]), ('normal control', {'events': [1000], 'free': 10, 'div': 1, 'round': 'down', 'price': 999}, [1, 0, 0])], [('regression', {'events': [1332, 1000, 3819, 645, 1000, 333], 'free': 0, 'div': 10, 'round': 'up', 'price': 250}, [9, 1, 250]), ('regression', {'events': [35, 1000, 2766, 1000, 937], 'free': 0, 'div': 10, 'round': 'up', 'price': 100}, [6, 1, 100]), ('partial-repair probe', {'events': [1000, 1000, 577, 2375], 'free': 10, 'div': 1, 'round': 'down', 'price': 250}, [5, 0, 0]), ('partial-repair probe', {'events': [4706], 'free': 5, 'div': 10, 'round': 'down', 'price': 250}, [5, 0, 0]), ('normal control', {'events': [], 'free': 10, 'div': 1, 'round': 'up', 'price': 999}, [0, 0, 0]), ('normal control', {'events': [], 'free': 0, 'div': 10, 'round': 'down', 'price': 999}, [0, 0, 0]), ('normal control', {'events': [1000], 'free': 5, 'div': 1, 'round': 'up', 'price': 100}, [1, 0, 0]), ('normal control', {'events': [], 'free': 0, 'div': 1, 'round': 'down', 'price': 999}, [0, 0, 0])], [('regression', {'events': [35, 1000, 2766, 1000, 937], 'free': 0, 'div': 10, 'round': 'up', 'price': 100}, [6, 1, 100]), ('regression', {'events': [1000, 1000, 577, 2375], 'free': 10, 'div': 1, 'round': 'down', 'price': 250}, [5, 0, 0]), ('partial-repair probe', {'events': [4706], 'free': 5, 'div': 10, 'round': 'down', 'price': 250}, [5, 0, 0]), ('partial-repair probe', {'events': [460, 1000], 'free': 10, 'div': 100, 'round': 'up', 'price': 100}, [2, 0, 0]), ('normal control', {'events': [], 'free': 0, 'div': 100, 'round': 'down', 'price': 999}, [0, 0, 0]), ('normal control', {'events': [], 'free': 5, 'div': 100, 'round': 'down', 'price': 250}, [0, 0, 0]), ('normal control', {'events': [1000], 'free': 0, 'div': 10, 'round': 'up', 'price': 100}, [1, 1, 100]), ('normal control', {'events': [], 'free': 10, 'div': 5, 'round': 'down', 'price': 999}, [0, 0, 0])], [('regression', {'events': [1000, 1000, 577, 2375], 'free': 10, 'div': 1, 'round': 'down', 'price': 250}, [5, 0, 0]), ('regression', {'events': [3902, 1000, 1000, 2138, 771, 1712], 'free': 0, 'div': 10, 'round': 'up', 'price': 100}, [11, 2, 200]), ('partial-repair probe', {'events': [460, 1000], 'free': 10, 'div': 100, 'round': 'up', 'price': 100}, [2, 0, 0]), ('partial-repair probe', {'events': [716, 4530], 'free': 10, 'div': 10, 'round': 'up', 'price': 100}, [6, 0, 0]), ('normal control', {'events': [1000], 'free': 0, 'div': 5, 'round': 'down', 'price': 100}, [1, 0, 0]), ('normal control', {'events': [], 'free': 5, 'div': 10, 'round': 'up', 'price': 999}, [0, 0, 0]), ('normal control', {'events': [], 'free': 0, 'div': 100, 'round': 'up', 'price': 250}, [0, 0, 0]), ('normal control', {'events': [], 'free': 10, 'div': 5, 'round': 'down', 'price': 250}, [0, 0, 0])], [('regression', {'events': [3902, 1000, 1000, 2138, 771, 1712], 'free': 0, 'div': 10, 'round': 'up', 'price': 100}, [11, 2, 200]), ('regression', {'events': [321, 1000, 593, 354, 2136], 'free': 5, 'div': 100, 'round': 'up', 'price': 100}, [5, 0, 0]), ('partial-repair probe', {'events': [576, 688, 449, 1000, 815], 'free': 0, 'div': 5, 'round': 'down', 'price': 999}, [4, 0, 0]), ('partial-repair probe', {'events': [1000, 1000, 919, 1000, 4033], 'free': 5, 'div': 1, 'round': 'up', 'price': 250}, [8, 3, 750]), ('normal control', {'events': [1000, 1000], 'free': 5, 'div': 10, 'round': 'down', 'price': 250}, [2, 0, 0]), ('normal control', {'events': [], 'free': 10, 'div': 5, 'round': 'up', 'price': 100}, [0, 0, 0]), ('normal control', {'events': [], 'free': 5, 'div': 5, 'round': 'up', 'price': 999}, [0, 0, 0]), ('normal control', {'events': [], 'free': 5, 'div': 10, 'round': 'down', 'price': 250}, [0, 0, 0])]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), 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
regression 0[12, 0, 0][11, 0, 0]Failed
regression 1[10, 1, 250][9, 1, 250]Failed
partial-repair probe 2[2, 0, 0][2, 0, 0]Passed
partial-repair probe 3[7, 1, 100][6, 1, 100]Failed
normal control 4[0, 0, 0][0, 0, 0]Passed
normal control 5[1, 0, 0][1, 0, 0]Passed
normal control 6[1, 0, 0][1, 0, 0]Passed
normal control 7[1, 0, 0][1, 0, 0]Passed

SHA-256 / 13a8466fd22a50b1b7e62002b944c0b1cdcc9fd1032c78f785e47663e1c8c85d

2 / The unsuccessful fix

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    milli = sum(x['events'])
    units = milli // 1000
    billable = max(0, units - x['free'])
    if x['round'] == 'up':
        packs = -(-billable // x['div'])
    else:
        packs = billable // x['div']
    return [units, packs, packs * x['price']]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'events': [4863, 300, 2484, 893, 1000, 741], 'free': 10, 'div': 5, 'round': 'down', 'price': 999}, [11, 0, 0]), ('regression', {'events': [1332, 1000, 3819, 645, 1000, 333], 'free': 0, 'div': 10, 'round': 'up', 'price': 250}, [9, 1, 250]), ('partial-repair probe', {'events': [1000, 452], 'free': 5, 'div': 100, 'round': 'up', 'price': 999}, [2, 0, 0]), ('partial-repair probe', {'events': [35, 1000, 2766, 1000, 937], 'free': 0, 'div': 10, 'round': 'up', 'price': 100}, [6, 1, 100]), ('normal control', {'events': [], 'free': 10, 'div': 100, 'round': 'up', 'price': 100}, [0, 0, 0]), ('normal control', {'events': [1000], 'free': 10, 'div': 100, 'round': 'down', 'price': 999}, [1, 0, 0]), ('normal control', {'events': [1000], 'free': 10, 'div': 10, 'round': 'down', 'price': 999}, [1, 0, 0]), ('normal control', {'events': [1000], 'free': 10, 'div': 1, 'round': 'down', 'price': 999}, [1, 0, 0])], [('regression', {'events': [1332, 1000, 3819, 645, 1000, 333], 'free': 0, 'div': 10, 'round': 'up', 'price': 250}, [9, 1, 250]), ('regression', {'events': [35, 1000, 2766, 1000, 937], 'free': 0, 'div': 10, 'round': 'up', 'price': 100}, [6, 1, 100]), ('partial-repair probe', {'events': [1000, 1000, 577, 2375], 'free': 10, 'div': 1, 'round': 'down', 'price': 250}, [5, 0, 0]), ('partial-repair probe', {'events': [4706], 'free': 5, 'div': 10, 'round': 'down', 'price': 250}, [5, 0, 0]), ('normal control', {'events': [], 'free': 10, 'div': 1, 'round': 'up', 'price': 999}, [0, 0, 0]), ('normal control', {'events': [], 'free': 0, 'div': 10, 'round': 'down', 'price': 999}, [0, 0, 0]), ('normal control', {'events': [1000], 'free': 5, 'div': 1, 'round': 'up', 'price': 100}, [1, 0, 0]), ('normal control', {'events': [], 'free': 0, 'div': 1, 'round': 'down', 'price': 999}, [0, 0, 0])], [('regression', {'events': [35, 1000, 2766, 1000, 937], 'free': 0, 'div': 10, 'round': 'up', 'price': 100}, [6, 1, 100]), ('regression', {'events': [1000, 1000, 577, 2375], 'free': 10, 'div': 1, 'round': 'down', 'price': 250}, [5, 0, 0]), ('partial-repair probe', {'events': [4706], 'free': 5, 'div': 10, 'round': 'down', 'price': 250}, [5, 0, 0]), ('partial-repair probe', {'events': [460, 1000], 'free': 10, 'div': 100, 'round': 'up', 'price': 100}, [2, 0, 0]), ('normal control', {'events': [], 'free': 0, 'div': 100, 'round': 'down', 'price': 999}, [0, 0, 0]), ('normal control', {'events': [], 'free': 5, 'div': 100, 'round': 'down', 'price': 250}, [0, 0, 0]), ('normal control', {'events': [1000], 'free': 0, 'div': 10, 'round': 'up', 'price': 100}, [1, 1, 100]), ('normal control', {'events': [], 'free': 10, 'div': 5, 'round': 'down', 'price': 999}, [0, 0, 0])], [('regression', {'events': [1000, 1000, 577, 2375], 'free': 10, 'div': 1, 'round': 'down', 'price': 250}, [5, 0, 0]), ('regression', {'events': [3902, 1000, 1000, 2138, 771, 1712], 'free': 0, 'div': 10, 'round': 'up', 'price': 100}, [11, 2, 200]), ('partial-repair probe', {'events': [460, 1000], 'free': 10, 'div': 100, 'round': 'up', 'price': 100}, [2, 0, 0]), ('partial-repair probe', {'events': [716, 4530], 'free': 10, 'div': 10, 'round': 'up', 'price': 100}, [6, 0, 0]), ('normal control', {'events': [1000], 'free': 0, 'div': 5, 'round': 'down', 'price': 100}, [1, 0, 0]), ('normal control', {'events': [], 'free': 5, 'div': 10, 'round': 'up', 'price': 999}, [0, 0, 0]), ('normal control', {'events': [], 'free': 0, 'div': 100, 'round': 'up', 'price': 250}, [0, 0, 0]), ('normal control', {'events': [], 'free': 10, 'div': 5, 'round': 'down', 'price': 250}, [0, 0, 0])], [('regression', {'events': [3902, 1000, 1000, 2138, 771, 1712], 'free': 0, 'div': 10, 'round': 'up', 'price': 100}, [11, 2, 200]), ('regression', {'events': [321, 1000, 593, 354, 2136], 'free': 5, 'div': 100, 'round': 'up', 'price': 100}, [5, 0, 0]), ('partial-repair probe', {'events': [576, 688, 449, 1000, 815], 'free': 0, 'div': 5, 'round': 'down', 'price': 999}, [4, 0, 0]), ('partial-repair probe', {'events': [1000, 1000, 919, 1000, 4033], 'free': 5, 'div': 1, 'round': 'up', 'price': 250}, [8, 3, 750]), ('normal control', {'events': [1000, 1000], 'free': 5, 'div': 10, 'round': 'down', 'price': 250}, [2, 0, 0]), ('normal control', {'events': [], 'free': 10, 'div': 5, 'round': 'up', 'price': 100}, [0, 0, 0]), ('normal control', {'events': [], 'free': 5, 'div': 5, 'round': 'up', 'price': 999}, [0, 0, 0]), ('normal control', {'events': [], 'free': 5, 'div': 10, 'round': 'down', 'price': 250}, [0, 0, 0])]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), 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
regression 0[10, 0, 0][11, 0, 0]Failed
regression 1[8, 1, 250][9, 1, 250]Failed
partial-repair probe 2[1, 0, 0][2, 0, 0]Failed
partial-repair probe 3[5, 1, 100][6, 1, 100]Failed
normal control 4[0, 0, 0][0, 0, 0]Passed
normal control 5[1, 0, 0][1, 0, 0]Passed
normal control 6[1, 0, 0][1, 0, 0]Passed
normal control 7[1, 0, 0][1, 0, 0]Passed

SHA-256 / 51b86aaa0eb98c42ba97cf440b4b4788f66f02d156da664be1fff358e309b012

3 / The verified repair

Exit 0
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    milli = sum(x['events'])
    units = -(-milli // 1000)
    billable = max(0, units - x['free'])
    if x['round'] == 'up':
        packs = -(-billable // x['div'])
    else:
        packs = billable // x['div']
    return [units, packs, packs * x['price']]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'events': [4863, 300, 2484, 893, 1000, 741], 'free': 10, 'div': 5, 'round': 'down', 'price': 999}, [11, 0, 0]), ('regression', {'events': [1332, 1000, 3819, 645, 1000, 333], 'free': 0, 'div': 10, 'round': 'up', 'price': 250}, [9, 1, 250]), ('partial-repair probe', {'events': [1000, 452], 'free': 5, 'div': 100, 'round': 'up', 'price': 999}, [2, 0, 0]), ('partial-repair probe', {'events': [35, 1000, 2766, 1000, 937], 'free': 0, 'div': 10, 'round': 'up', 'price': 100}, [6, 1, 100]), ('normal control', {'events': [], 'free': 10, 'div': 100, 'round': 'up', 'price': 100}, [0, 0, 0]), ('normal control', {'events': [1000], 'free': 10, 'div': 100, 'round': 'down', 'price': 999}, [1, 0, 0]), ('normal control', {'events': [1000], 'free': 10, 'div': 10, 'round': 'down', 'price': 999}, [1, 0, 0]), ('normal control', {'events': [1000], 'free': 10, 'div': 1, 'round': 'down', 'price': 999}, [1, 0, 0])], [('regression', {'events': [1332, 1000, 3819, 645, 1000, 333], 'free': 0, 'div': 10, 'round': 'up', 'price': 250}, [9, 1, 250]), ('regression', {'events': [35, 1000, 2766, 1000, 937], 'free': 0, 'div': 10, 'round': 'up', 'price': 100}, [6, 1, 100]), ('partial-repair probe', {'events': [1000, 1000, 577, 2375], 'free': 10, 'div': 1, 'round': 'down', 'price': 250}, [5, 0, 0]), ('partial-repair probe', {'events': [4706], 'free': 5, 'div': 10, 'round': 'down', 'price': 250}, [5, 0, 0]), ('normal control', {'events': [], 'free': 10, 'div': 1, 'round': 'up', 'price': 999}, [0, 0, 0]), ('normal control', {'events': [], 'free': 0, 'div': 10, 'round': 'down', 'price': 999}, [0, 0, 0]), ('normal control', {'events': [1000], 'free': 5, 'div': 1, 'round': 'up', 'price': 100}, [1, 0, 0]), ('normal control', {'events': [], 'free': 0, 'div': 1, 'round': 'down', 'price': 999}, [0, 0, 0])], [('regression', {'events': [35, 1000, 2766, 1000, 937], 'free': 0, 'div': 10, 'round': 'up', 'price': 100}, [6, 1, 100]), ('regression', {'events': [1000, 1000, 577, 2375], 'free': 10, 'div': 1, 'round': 'down', 'price': 250}, [5, 0, 0]), ('partial-repair probe', {'events': [4706], 'free': 5, 'div': 10, 'round': 'down', 'price': 250}, [5, 0, 0]), ('partial-repair probe', {'events': [460, 1000], 'free': 10, 'div': 100, 'round': 'up', 'price': 100}, [2, 0, 0]), ('normal control', {'events': [], 'free': 0, 'div': 100, 'round': 'down', 'price': 999}, [0, 0, 0]), ('normal control', {'events': [], 'free': 5, 'div': 100, 'round': 'down', 'price': 250}, [0, 0, 0]), ('normal control', {'events': [1000], 'free': 0, 'div': 10, 'round': 'up', 'price': 100}, [1, 1, 100]), ('normal control', {'events': [], 'free': 10, 'div': 5, 'round': 'down', 'price': 999}, [0, 0, 0])], [('regression', {'events': [1000, 1000, 577, 2375], 'free': 10, 'div': 1, 'round': 'down', 'price': 250}, [5, 0, 0]), ('regression', {'events': [3902, 1000, 1000, 2138, 771, 1712], 'free': 0, 'div': 10, 'round': 'up', 'price': 100}, [11, 2, 200]), ('partial-repair probe', {'events': [460, 1000], 'free': 10, 'div': 100, 'round': 'up', 'price': 100}, [2, 0, 0]), ('partial-repair probe', {'events': [716, 4530], 'free': 10, 'div': 10, 'round': 'up', 'price': 100}, [6, 0, 0]), ('normal control', {'events': [1000], 'free': 0, 'div': 5, 'round': 'down', 'price': 100}, [1, 0, 0]), ('normal control', {'events': [], 'free': 5, 'div': 10, 'round': 'up', 'price': 999}, [0, 0, 0]), ('normal control', {'events': [], 'free': 0, 'div': 100, 'round': 'up', 'price': 250}, [0, 0, 0]), ('normal control', {'events': [], 'free': 10, 'div': 5, 'round': 'down', 'price': 250}, [0, 0, 0])], [('regression', {'events': [3902, 1000, 1000, 2138, 771, 1712], 'free': 0, 'div': 10, 'round': 'up', 'price': 100}, [11, 2, 200]), ('regression', {'events': [321, 1000, 593, 354, 2136], 'free': 5, 'div': 100, 'round': 'up', 'price': 100}, [5, 0, 0]), ('partial-repair probe', {'events': [576, 688, 449, 1000, 815], 'free': 0, 'div': 5, 'round': 'down', 'price': 999}, [4, 0, 0]), ('partial-repair probe', {'events': [1000, 1000, 919, 1000, 4033], 'free': 5, 'div': 1, 'round': 'up', 'price': 250}, [8, 3, 750]), ('normal control', {'events': [1000, 1000], 'free': 5, 'div': 10, 'round': 'down', 'price': 250}, [2, 0, 0]), ('normal control', {'events': [], 'free': 10, 'div': 5, 'round': 'up', 'price': 100}, [0, 0, 0]), ('normal control', {'events': [], 'free': 5, 'div': 5, 'round': 'up', 'price': 999}, [0, 0, 0]), ('normal control', {'events': [], 'free': 5, 'div': 10, 'round': 'down', 'price': 250}, [0, 0, 0])]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), 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
regression 0[11, 0, 0][11, 0, 0]Passed
regression 1[9, 1, 250][9, 1, 250]Passed
partial-repair probe 2[2, 0, 0][2, 0, 0]Passed
partial-repair probe 3[6, 1, 100][6, 1, 100]Passed
normal control 4[0, 0, 0][0, 0, 0]Passed
normal control 5[1, 0, 0][1, 0, 0]Passed
normal control 6[1, 0, 0][1, 0, 0]Passed
normal control 7[1, 0, 0][1, 0, 0]Passed

SHA-256 / 85e56e2ea5e64e324bbb2703cebc54a3f969e74cdc8f79d3e4a5cfa7eaa7d507

Verification & scope

A deterministic teaching model of a stipulated billing rule. It makes no claim to reproduce any billing provider's exact behaviour and is not billing software. 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:46:39.788579+00:00.

Case digest / 9c6f318f184cb4db9dca8181299f23afb531a12e216c85bb37a3d82770a122e4