FAILURE MAP
← Case archive

FA-59816 / Subscription proration billing / Open access

Package pricing with milli-unit usage: free units before packaging · case 01

The free allowance never reduces the bill.

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

ROOT CAUSE

Free units are not subtracted before packaging.

VERIFIED REPAIR

Restore the contract rule at the free units before packaging step: use `billable = max(0, units - x['free'])`.

Unsuccessful approach: The attempt treats the free allowance as packages instead of 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 = -(-milli // 1000)
    billable = units
    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': [604, 2714, 1000, 776, 1000, 4405], 'free': 5, 'div': 5, 'round': 'up', 'price': 250}, [11, 2, 500]), ('regression', {'events': [4863, 300, 2484, 893, 1000, 741], 'free': 10, 'div': 5, 'round': 'down', 'price': 999}, [11, 0, 0]), ('partial-repair probe', {'events': [391, 8, 2736, 4419], 'free': 5, 'div': 100, 'round': 'up', 'price': 250}, [8, 1, 250]), ('partial-repair probe', {'events': [4324, 534, 615, 25], 'free': 5, 'div': 100, 'round': 'up', 'price': 999}, [6, 1, 999]), ('normal control', {'events': [1332, 1000, 3819, 645, 1000, 333], 'free': 0, 'div': 10, 'round': 'up', 'price': 250}, [9, 1, 250]), ('normal control', {'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])], [('regression', {'events': [673, 4210, 1000, 3643], 'free': 5, 'div': 5, 'round': 'up', 'price': 250}, [10, 1, 250]), ('regression', {'events': [1000, 452], 'free': 5, 'div': 100, 'round': 'up', 'price': 999}, [2, 0, 0]), ('partial-repair probe', {'events': [604, 2714, 1000, 776, 1000, 4405], 'free': 5, 'div': 5, 'round': 'up', 'price': 250}, [11, 2, 500]), ('partial-repair probe', {'events': [905, 3643, 1000, 755, 4581], 'free': 5, 'div': 100, 'round': 'up', 'price': 250}, [11, 1, 250]), ('normal control', {'events': [4706], 'free': 5, 'div': 10, 'round': 'down', 'price': 250}, [5, 0, 0]), ('normal control', {'events': [1000], 'free': 10, 'div': 10, 'round': 'down', 'price': 999}, [1, 0, 0]), ('normal control', {'events': [3902, 1000, 1000, 2138, 771, 1712], 'free': 0, 'div': 10, 'round': 'up', 'price': 100}, [11, 2, 200]), ('normal control', {'events': [576, 688, 449, 1000, 815], 'free': 0, 'div': 5, 'round': 'down', 'price': 999}, [4, 0, 0])], [('regression', {'events': [1000, 2653, 1000, 4233], 'free': 5, 'div': 5, 'round': 'up', 'price': 999}, [9, 1, 999]), ('regression', {'events': [1000, 1000, 577, 2375], 'free': 10, 'div': 1, 'round': 'down', 'price': 250}, [5, 0, 0]), ('partial-repair probe', {'events': [673, 4210, 1000, 3643], 'free': 5, 'div': 5, 'round': 'up', 'price': 250}, [10, 1, 250]), ('partial-repair probe', {'events': [233, 824, 4771, 633, 598], 'free': 5, 'div': 10, 'round': 'up', 'price': 250}, [8, 1, 250]), ('normal control', {'events': [], 'free': 10, 'div': 1, 'round': 'up', 'price': 999}, [0, 0, 0]), ('normal control', {'events': [339, 1000, 1810, 2557, 4715], 'free': 10, 'div': 100, 'round': 'down', 'price': 100}, [11, 0, 0]), ('normal control', {'events': [959, 514, 670, 1000], 'free': 0, 'div': 1, 'round': 'down', 'price': 250}, [4, 4, 1000]), ('normal control', {'events': [1000, 3934, 1000, 1000], 'free': 10, 'div': 100, 'round': 'down', 'price': 100}, [7, 0, 0])], [('regression', {'events': [3797, 1000, 1000, 932], 'free': 5, 'div': 5, 'round': 'up', 'price': 250}, [7, 1, 250]), ('regression', {'events': [460, 1000], 'free': 10, 'div': 100, 'round': 'up', 'price': 100}, [2, 0, 0]), ('partial-repair probe', {'events': [1000, 2653, 1000, 4233], 'free': 5, 'div': 5, 'round': 'up', 'price': 999}, [9, 1, 999]), ('partial-repair probe', {'events': [2261, 1497, 1000, 778, 722], 'free': 5, 'div': 100, 'round': 'up', 'price': 250}, [7, 1, 250]), ('normal control', {'events': [], 'free': 0, 'div': 10, 'round': 'down', 'price': 999}, [0, 0, 0]), ('normal control', {'events': [487, 2432, 2028, 558], 'free': 0, 'div': 10, 'round': 'up', 'price': 250}, [6, 1, 250]), ('normal control', {'events': [402], 'free': 0, 'div': 5, 'round': 'down', 'price': 100}, [1, 0, 0]), ('normal control', {'events': [], 'free': 0, 'div': 1, 'round': 'down', 'price': 999}, [0, 0, 0])], [('regression', {'events': [2133, 1366, 1000, 1863, 1000], 'free': 5, 'div': 5, 'round': 'up', 'price': 999}, [8, 1, 999]), ('regression', {'events': [716, 4530], 'free': 10, 'div': 10, 'round': 'up', 'price': 100}, [6, 0, 0]), ('partial-repair probe', {'events': [934, 3399, 485, 1083, 1187, 1000], 'free': 5, 'div': 10, 'round': 'up', 'price': 999}, [9, 1, 999]), ('partial-repair probe', {'events': [3797, 1000, 1000, 932], 'free': 5, 'div': 5, 'round': 'up', 'price': 250}, [7, 1, 250]), ('normal control', {'events': [4797, 2089, 1000, 1954], 'free': 0, 'div': 10, 'round': 'down', 'price': 100}, [10, 1, 100]), ('normal control', {'events': [532, 140, 780, 1000], 'free': 0, 'div': 10, 'round': 'up', 'price': 250}, [3, 1, 250]), ('normal control', {'events': [], 'free': 0, 'div': 100, 'round': 'down', 'price': 999}, [0, 0, 0]), ('normal control', {'events': [1000, 2646], 'free': 0, 'div': 10, 'round': 'down', 'price': 100}, [4, 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, 3, 750][11, 2, 500]Failed
regression 1[11, 2, 1998][11, 0, 0]Failed
partial-repair probe 2[8, 1, 250][8, 1, 250]Passed
partial-repair probe 3[6, 1, 999][6, 1, 999]Passed
normal control 4[9, 1, 250][9, 1, 250]Passed
normal control 5[6, 1, 100][6, 1, 100]Passed
normal control 6[0, 0, 0][0, 0, 0]Passed
normal control 7[1, 0, 0][1, 0, 0]Passed

SHA-256 / 02af113b0b670066c716a627316170f1c4a43444d9df1f20269c9cb78807f26e

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'] * x['div'])
    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': [604, 2714, 1000, 776, 1000, 4405], 'free': 5, 'div': 5, 'round': 'up', 'price': 250}, [11, 2, 500]), ('regression', {'events': [4863, 300, 2484, 893, 1000, 741], 'free': 10, 'div': 5, 'round': 'down', 'price': 999}, [11, 0, 0]), ('partial-repair probe', {'events': [391, 8, 2736, 4419], 'free': 5, 'div': 100, 'round': 'up', 'price': 250}, [8, 1, 250]), ('partial-repair probe', {'events': [4324, 534, 615, 25], 'free': 5, 'div': 100, 'round': 'up', 'price': 999}, [6, 1, 999]), ('normal control', {'events': [1332, 1000, 3819, 645, 1000, 333], 'free': 0, 'div': 10, 'round': 'up', 'price': 250}, [9, 1, 250]), ('normal control', {'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])], [('regression', {'events': [673, 4210, 1000, 3643], 'free': 5, 'div': 5, 'round': 'up', 'price': 250}, [10, 1, 250]), ('regression', {'events': [1000, 452], 'free': 5, 'div': 100, 'round': 'up', 'price': 999}, [2, 0, 0]), ('partial-repair probe', {'events': [604, 2714, 1000, 776, 1000, 4405], 'free': 5, 'div': 5, 'round': 'up', 'price': 250}, [11, 2, 500]), ('partial-repair probe', {'events': [905, 3643, 1000, 755, 4581], 'free': 5, 'div': 100, 'round': 'up', 'price': 250}, [11, 1, 250]), ('normal control', {'events': [4706], 'free': 5, 'div': 10, 'round': 'down', 'price': 250}, [5, 0, 0]), ('normal control', {'events': [1000], 'free': 10, 'div': 10, 'round': 'down', 'price': 999}, [1, 0, 0]), ('normal control', {'events': [3902, 1000, 1000, 2138, 771, 1712], 'free': 0, 'div': 10, 'round': 'up', 'price': 100}, [11, 2, 200]), ('normal control', {'events': [576, 688, 449, 1000, 815], 'free': 0, 'div': 5, 'round': 'down', 'price': 999}, [4, 0, 0])], [('regression', {'events': [1000, 2653, 1000, 4233], 'free': 5, 'div': 5, 'round': 'up', 'price': 999}, [9, 1, 999]), ('regression', {'events': [1000, 1000, 577, 2375], 'free': 10, 'div': 1, 'round': 'down', 'price': 250}, [5, 0, 0]), ('partial-repair probe', {'events': [673, 4210, 1000, 3643], 'free': 5, 'div': 5, 'round': 'up', 'price': 250}, [10, 1, 250]), ('partial-repair probe', {'events': [233, 824, 4771, 633, 598], 'free': 5, 'div': 10, 'round': 'up', 'price': 250}, [8, 1, 250]), ('normal control', {'events': [], 'free': 10, 'div': 1, 'round': 'up', 'price': 999}, [0, 0, 0]), ('normal control', {'events': [339, 1000, 1810, 2557, 4715], 'free': 10, 'div': 100, 'round': 'down', 'price': 100}, [11, 0, 0]), ('normal control', {'events': [959, 514, 670, 1000], 'free': 0, 'div': 1, 'round': 'down', 'price': 250}, [4, 4, 1000]), ('normal control', {'events': [1000, 3934, 1000, 1000], 'free': 10, 'div': 100, 'round': 'down', 'price': 100}, [7, 0, 0])], [('regression', {'events': [3797, 1000, 1000, 932], 'free': 5, 'div': 5, 'round': 'up', 'price': 250}, [7, 1, 250]), ('regression', {'events': [460, 1000], 'free': 10, 'div': 100, 'round': 'up', 'price': 100}, [2, 0, 0]), ('partial-repair probe', {'events': [1000, 2653, 1000, 4233], 'free': 5, 'div': 5, 'round': 'up', 'price': 999}, [9, 1, 999]), ('partial-repair probe', {'events': [2261, 1497, 1000, 778, 722], 'free': 5, 'div': 100, 'round': 'up', 'price': 250}, [7, 1, 250]), ('normal control', {'events': [], 'free': 0, 'div': 10, 'round': 'down', 'price': 999}, [0, 0, 0]), ('normal control', {'events': [487, 2432, 2028, 558], 'free': 0, 'div': 10, 'round': 'up', 'price': 250}, [6, 1, 250]), ('normal control', {'events': [402], 'free': 0, 'div': 5, 'round': 'down', 'price': 100}, [1, 0, 0]), ('normal control', {'events': [], 'free': 0, 'div': 1, 'round': 'down', 'price': 999}, [0, 0, 0])], [('regression', {'events': [2133, 1366, 1000, 1863, 1000], 'free': 5, 'div': 5, 'round': 'up', 'price': 999}, [8, 1, 999]), ('regression', {'events': [716, 4530], 'free': 10, 'div': 10, 'round': 'up', 'price': 100}, [6, 0, 0]), ('partial-repair probe', {'events': [934, 3399, 485, 1083, 1187, 1000], 'free': 5, 'div': 10, 'round': 'up', 'price': 999}, [9, 1, 999]), ('partial-repair probe', {'events': [3797, 1000, 1000, 932], 'free': 5, 'div': 5, 'round': 'up', 'price': 250}, [7, 1, 250]), ('normal control', {'events': [4797, 2089, 1000, 1954], 'free': 0, 'div': 10, 'round': 'down', 'price': 100}, [10, 1, 100]), ('normal control', {'events': [532, 140, 780, 1000], 'free': 0, 'div': 10, 'round': 'up', 'price': 250}, [3, 1, 250]), ('normal control', {'events': [], 'free': 0, 'div': 100, 'round': 'down', 'price': 999}, [0, 0, 0]), ('normal control', {'events': [1000, 2646], 'free': 0, 'div': 10, 'round': 'down', 'price': 100}, [4, 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, 2, 500]Failed
regression 1[11, 0, 0][11, 0, 0]Passed
partial-repair probe 2[8, 0, 0][8, 1, 250]Failed
partial-repair probe 3[6, 0, 0][6, 1, 999]Failed
normal control 4[9, 1, 250][9, 1, 250]Passed
normal control 5[6, 1, 100][6, 1, 100]Passed
normal control 6[0, 0, 0][0, 0, 0]Passed
normal control 7[1, 0, 0][1, 0, 0]Passed

SHA-256 / e6f6b79a1059eacd3425239737bbc423e91933ac81aefe19be8de92f82b0ea9c

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': [604, 2714, 1000, 776, 1000, 4405], 'free': 5, 'div': 5, 'round': 'up', 'price': 250}, [11, 2, 500]), ('regression', {'events': [4863, 300, 2484, 893, 1000, 741], 'free': 10, 'div': 5, 'round': 'down', 'price': 999}, [11, 0, 0]), ('partial-repair probe', {'events': [391, 8, 2736, 4419], 'free': 5, 'div': 100, 'round': 'up', 'price': 250}, [8, 1, 250]), ('partial-repair probe', {'events': [4324, 534, 615, 25], 'free': 5, 'div': 100, 'round': 'up', 'price': 999}, [6, 1, 999]), ('normal control', {'events': [1332, 1000, 3819, 645, 1000, 333], 'free': 0, 'div': 10, 'round': 'up', 'price': 250}, [9, 1, 250]), ('normal control', {'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])], [('regression', {'events': [673, 4210, 1000, 3643], 'free': 5, 'div': 5, 'round': 'up', 'price': 250}, [10, 1, 250]), ('regression', {'events': [1000, 452], 'free': 5, 'div': 100, 'round': 'up', 'price': 999}, [2, 0, 0]), ('partial-repair probe', {'events': [604, 2714, 1000, 776, 1000, 4405], 'free': 5, 'div': 5, 'round': 'up', 'price': 250}, [11, 2, 500]), ('partial-repair probe', {'events': [905, 3643, 1000, 755, 4581], 'free': 5, 'div': 100, 'round': 'up', 'price': 250}, [11, 1, 250]), ('normal control', {'events': [4706], 'free': 5, 'div': 10, 'round': 'down', 'price': 250}, [5, 0, 0]), ('normal control', {'events': [1000], 'free': 10, 'div': 10, 'round': 'down', 'price': 999}, [1, 0, 0]), ('normal control', {'events': [3902, 1000, 1000, 2138, 771, 1712], 'free': 0, 'div': 10, 'round': 'up', 'price': 100}, [11, 2, 200]), ('normal control', {'events': [576, 688, 449, 1000, 815], 'free': 0, 'div': 5, 'round': 'down', 'price': 999}, [4, 0, 0])], [('regression', {'events': [1000, 2653, 1000, 4233], 'free': 5, 'div': 5, 'round': 'up', 'price': 999}, [9, 1, 999]), ('regression', {'events': [1000, 1000, 577, 2375], 'free': 10, 'div': 1, 'round': 'down', 'price': 250}, [5, 0, 0]), ('partial-repair probe', {'events': [673, 4210, 1000, 3643], 'free': 5, 'div': 5, 'round': 'up', 'price': 250}, [10, 1, 250]), ('partial-repair probe', {'events': [233, 824, 4771, 633, 598], 'free': 5, 'div': 10, 'round': 'up', 'price': 250}, [8, 1, 250]), ('normal control', {'events': [], 'free': 10, 'div': 1, 'round': 'up', 'price': 999}, [0, 0, 0]), ('normal control', {'events': [339, 1000, 1810, 2557, 4715], 'free': 10, 'div': 100, 'round': 'down', 'price': 100}, [11, 0, 0]), ('normal control', {'events': [959, 514, 670, 1000], 'free': 0, 'div': 1, 'round': 'down', 'price': 250}, [4, 4, 1000]), ('normal control', {'events': [1000, 3934, 1000, 1000], 'free': 10, 'div': 100, 'round': 'down', 'price': 100}, [7, 0, 0])], [('regression', {'events': [3797, 1000, 1000, 932], 'free': 5, 'div': 5, 'round': 'up', 'price': 250}, [7, 1, 250]), ('regression', {'events': [460, 1000], 'free': 10, 'div': 100, 'round': 'up', 'price': 100}, [2, 0, 0]), ('partial-repair probe', {'events': [1000, 2653, 1000, 4233], 'free': 5, 'div': 5, 'round': 'up', 'price': 999}, [9, 1, 999]), ('partial-repair probe', {'events': [2261, 1497, 1000, 778, 722], 'free': 5, 'div': 100, 'round': 'up', 'price': 250}, [7, 1, 250]), ('normal control', {'events': [], 'free': 0, 'div': 10, 'round': 'down', 'price': 999}, [0, 0, 0]), ('normal control', {'events': [487, 2432, 2028, 558], 'free': 0, 'div': 10, 'round': 'up', 'price': 250}, [6, 1, 250]), ('normal control', {'events': [402], 'free': 0, 'div': 5, 'round': 'down', 'price': 100}, [1, 0, 0]), ('normal control', {'events': [], 'free': 0, 'div': 1, 'round': 'down', 'price': 999}, [0, 0, 0])], [('regression', {'events': [2133, 1366, 1000, 1863, 1000], 'free': 5, 'div': 5, 'round': 'up', 'price': 999}, [8, 1, 999]), ('regression', {'events': [716, 4530], 'free': 10, 'div': 10, 'round': 'up', 'price': 100}, [6, 0, 0]), ('partial-repair probe', {'events': [934, 3399, 485, 1083, 1187, 1000], 'free': 5, 'div': 10, 'round': 'up', 'price': 999}, [9, 1, 999]), ('partial-repair probe', {'events': [3797, 1000, 1000, 932], 'free': 5, 'div': 5, 'round': 'up', 'price': 250}, [7, 1, 250]), ('normal control', {'events': [4797, 2089, 1000, 1954], 'free': 0, 'div': 10, 'round': 'down', 'price': 100}, [10, 1, 100]), ('normal control', {'events': [532, 140, 780, 1000], 'free': 0, 'div': 10, 'round': 'up', 'price': 250}, [3, 1, 250]), ('normal control', {'events': [], 'free': 0, 'div': 100, 'round': 'down', 'price': 999}, [0, 0, 0]), ('normal control', {'events': [1000, 2646], 'free': 0, 'div': 10, 'round': 'down', 'price': 100}, [4, 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, 2, 500][11, 2, 500]Passed
regression 1[11, 0, 0][11, 0, 0]Passed
partial-repair probe 2[8, 1, 250][8, 1, 250]Passed
partial-repair probe 3[6, 1, 999][6, 1, 999]Passed
normal control 4[9, 1, 250][9, 1, 250]Passed
normal control 5[6, 1, 100][6, 1, 100]Passed
normal control 6[0, 0, 0][0, 0, 0]Passed
normal control 7[1, 0, 0][1, 0, 0]Passed

SHA-256 / 22dc179f263ac7df76aca5a793953ef3e8227346edfb9796154a05696e05e430

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

Case digest / 697a1b0d62a5799fde6cd205ead9af9faceafbe8f685805f759dcc0cc0eda43d