FAILURE MAP
← Case archive

FA-59821 / Subscription proration billing / Open access

Package pricing with milli-unit usage: round-up packaging · case 01

Exact package multiples and zero usage are billed an extra package.

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

ROOT CAUSE

Round-up is implemented as floor plus one.

VERIFIED REPAIR

Restore the contract rule at the round-up packaging step: use `packs = -(-billable // x['div'])`.

Unsuccessful approach: The attempt uses round() on a half-shifted float, which rounds exact multiples to even and still adds packages.

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 = max(0, units - x['free'])
    if x['round'] == 'up':
        packs = billable // x['div'] + 1
    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': [1000, 1000, 919, 1000, 4033], 'free': 5, 'div': 1, 'round': 'up', 'price': 250}, [8, 3, 750]), ('regression', {'events': [1000, 452], 'free': 5, 'div': 100, 'round': 'up', 'price': 999}, [2, 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': [3529, 608], 'free': 0, 'div': 5, 'round': 'up', 'price': 250}, [5, 1, 250]), ('normal control', {'events': [4863, 300, 2484, 893, 1000, 741], 'free': 10, 'div': 5, 'round': 'down', 'price': 999}, [11, 0, 0]), ('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': [1000, 1000, 577, 2375], 'free': 10, 'div': 1, 'round': 'down', 'price': 250}, [5, 0, 0])], [('regression', {'events': [673, 4210, 1000, 3643], 'free': 5, 'div': 5, 'round': 'up', 'price': 250}, [10, 1, 250]), ('regression', {'events': [], 'free': 10, 'div': 100, 'round': 'up', 'price': 100}, [0, 0, 0]), ('partial-repair probe', {'events': [3529, 608], 'free': 0, 'div': 5, 'round': 'up', 'price': 250}, [5, 1, 250]), ('partial-repair probe', {'events': [982, 260, 2668, 1000, 3988, 800], 'free': 0, 'div': 10, 'round': 'up', 'price': 999}, [10, 1, 999]), ('normal control', {'events': [1000], 'free': 10, 'div': 100, 'round': 'down', 'price': 999}, [1, 0, 0]), ('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])], [('regression', {'events': [3529, 608], 'free': 0, 'div': 5, 'round': 'up', 'price': 250}, [5, 1, 250]), ('regression', {'events': [460, 1000], 'free': 10, 'div': 100, 'round': 'up', 'price': 100}, [2, 0, 0]), ('partial-repair probe', {'events': [880, 518, 41, 3687, 1000, 180], 'free': 0, 'div': 1, 'round': 'up', 'price': 250}, [7, 7, 1750]), ('partial-repair probe', {'events': [4250, 1000], 'free': 5, 'div': 1, 'round': 'up', 'price': 250}, [6, 1, 250]), ('normal control', {'events': [1000], 'free': 10, 'div': 1, 'round': 'down', 'price': 999}, [1, 0, 0]), ('normal control', {'events': [576, 688, 449, 1000, 815], 'free': 0, 'div': 5, 'round': 'down', 'price': 999}, [4, 0, 0]), ('normal control', {'events': [339, 1000, 1810, 2557, 4715], 'free': 10, 'div': 100, 'round': 'down', 'price': 100}, [11, 0, 0]), ('normal control', {'events': [391, 8, 2736, 4419], 'free': 5, 'div': 100, 'round': 'up', 'price': 250}, [8, 1, 250])], [('regression', {'events': [982, 260, 2668, 1000, 3988, 800], 'free': 0, 'div': 10, 'round': 'up', 'price': 999}, [10, 1, 999]), ('regression', {'events': [716, 4530], 'free': 10, 'div': 10, 'round': 'up', 'price': 100}, [6, 0, 0]), ('partial-repair probe', {'events': [155, 3403, 470], 'free': 0, 'div': 5, 'round': 'up', 'price': 100}, [5, 1, 100]), ('partial-repair probe', {'events': [1000, 42, 2623, 1000, 3087], 'free': 5, 'div': 1, 'round': 'up', 'price': 100}, [8, 3, 300]), ('normal control', {'events': [4324, 534, 615, 25], 'free': 5, 'div': 100, 'round': 'up', 'price': 999}, [6, 1, 999]), ('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]), ('normal control', {'events': [604, 2714, 1000, 776, 1000, 4405], 'free': 5, 'div': 5, 'round': 'up', 'price': 250}, [11, 2, 500])], [('regression', {'events': [880, 518, 41, 3687, 1000, 180], 'free': 0, 'div': 1, 'round': 'up', 'price': 250}, [7, 7, 1750]), ('regression', {'events': [321, 1000, 593, 354, 2136], 'free': 5, 'div': 100, 'round': 'up', 'price': 100}, [5, 0, 0]), ('partial-repair probe', {'events': [235, 462, 166, 353, 1000], 'free': 0, 'div': 1, 'round': 'up', 'price': 250}, [3, 3, 750]), ('partial-repair probe', {'events': [1000, 4365, 1000, 3571, 76], 'free': 0, 'div': 1, 'round': 'up', 'price': 999}, [11, 11, 10989]), ('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': [1000, 679], 'free': 10, 'div': 1, 'round': 'down', 'price': 250}, [2, 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[8, 4, 1000][8, 3, 750]Failed
regression 1[2, 1, 999][2, 0, 0]Failed
partial-repair probe 2[10, 2, 500][10, 1, 250]Failed
partial-repair probe 3[5, 2, 500][5, 1, 250]Failed
normal control 4[11, 0, 0][11, 0, 0]Passed
normal control 5[9, 1, 250][9, 1, 250]Passed
normal control 6[6, 1, 100][6, 1, 100]Passed
normal control 7[5, 0, 0][5, 0, 0]Passed

SHA-256 / daf2b60237ad92e9e6766346960a419f614422979a9113ead32f6fec3782bcdd

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 = round(billable / x['div'] + 0.5)
    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': [1000, 1000, 919, 1000, 4033], 'free': 5, 'div': 1, 'round': 'up', 'price': 250}, [8, 3, 750]), ('regression', {'events': [1000, 452], 'free': 5, 'div': 100, 'round': 'up', 'price': 999}, [2, 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': [3529, 608], 'free': 0, 'div': 5, 'round': 'up', 'price': 250}, [5, 1, 250]), ('normal control', {'events': [4863, 300, 2484, 893, 1000, 741], 'free': 10, 'div': 5, 'round': 'down', 'price': 999}, [11, 0, 0]), ('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': [1000, 1000, 577, 2375], 'free': 10, 'div': 1, 'round': 'down', 'price': 250}, [5, 0, 0])], [('regression', {'events': [673, 4210, 1000, 3643], 'free': 5, 'div': 5, 'round': 'up', 'price': 250}, [10, 1, 250]), ('regression', {'events': [], 'free': 10, 'div': 100, 'round': 'up', 'price': 100}, [0, 0, 0]), ('partial-repair probe', {'events': [3529, 608], 'free': 0, 'div': 5, 'round': 'up', 'price': 250}, [5, 1, 250]), ('partial-repair probe', {'events': [982, 260, 2668, 1000, 3988, 800], 'free': 0, 'div': 10, 'round': 'up', 'price': 999}, [10, 1, 999]), ('normal control', {'events': [1000], 'free': 10, 'div': 100, 'round': 'down', 'price': 999}, [1, 0, 0]), ('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])], [('regression', {'events': [3529, 608], 'free': 0, 'div': 5, 'round': 'up', 'price': 250}, [5, 1, 250]), ('regression', {'events': [460, 1000], 'free': 10, 'div': 100, 'round': 'up', 'price': 100}, [2, 0, 0]), ('partial-repair probe', {'events': [880, 518, 41, 3687, 1000, 180], 'free': 0, 'div': 1, 'round': 'up', 'price': 250}, [7, 7, 1750]), ('partial-repair probe', {'events': [4250, 1000], 'free': 5, 'div': 1, 'round': 'up', 'price': 250}, [6, 1, 250]), ('normal control', {'events': [1000], 'free': 10, 'div': 1, 'round': 'down', 'price': 999}, [1, 0, 0]), ('normal control', {'events': [576, 688, 449, 1000, 815], 'free': 0, 'div': 5, 'round': 'down', 'price': 999}, [4, 0, 0]), ('normal control', {'events': [339, 1000, 1810, 2557, 4715], 'free': 10, 'div': 100, 'round': 'down', 'price': 100}, [11, 0, 0]), ('normal control', {'events': [391, 8, 2736, 4419], 'free': 5, 'div': 100, 'round': 'up', 'price': 250}, [8, 1, 250])], [('regression', {'events': [982, 260, 2668, 1000, 3988, 800], 'free': 0, 'div': 10, 'round': 'up', 'price': 999}, [10, 1, 999]), ('regression', {'events': [716, 4530], 'free': 10, 'div': 10, 'round': 'up', 'price': 100}, [6, 0, 0]), ('partial-repair probe', {'events': [155, 3403, 470], 'free': 0, 'div': 5, 'round': 'up', 'price': 100}, [5, 1, 100]), ('partial-repair probe', {'events': [1000, 42, 2623, 1000, 3087], 'free': 5, 'div': 1, 'round': 'up', 'price': 100}, [8, 3, 300]), ('normal control', {'events': [4324, 534, 615, 25], 'free': 5, 'div': 100, 'round': 'up', 'price': 999}, [6, 1, 999]), ('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]), ('normal control', {'events': [604, 2714, 1000, 776, 1000, 4405], 'free': 5, 'div': 5, 'round': 'up', 'price': 250}, [11, 2, 500])], [('regression', {'events': [880, 518, 41, 3687, 1000, 180], 'free': 0, 'div': 1, 'round': 'up', 'price': 250}, [7, 7, 1750]), ('regression', {'events': [321, 1000, 593, 354, 2136], 'free': 5, 'div': 100, 'round': 'up', 'price': 100}, [5, 0, 0]), ('partial-repair probe', {'events': [235, 462, 166, 353, 1000], 'free': 0, 'div': 1, 'round': 'up', 'price': 250}, [3, 3, 750]), ('partial-repair probe', {'events': [1000, 4365, 1000, 3571, 76], 'free': 0, 'div': 1, 'round': 'up', 'price': 999}, [11, 11, 10989]), ('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': [1000, 679], 'free': 10, 'div': 1, 'round': 'down', 'price': 250}, [2, 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[8, 4, 1000][8, 3, 750]Failed
regression 1[2, 0, 0][2, 0, 0]Passed
partial-repair probe 2[10, 2, 500][10, 1, 250]Failed
partial-repair probe 3[5, 2, 500][5, 1, 250]Failed
normal control 4[11, 0, 0][11, 0, 0]Passed
normal control 5[9, 1, 250][9, 1, 250]Passed
normal control 6[6, 1, 100][6, 1, 100]Passed
normal control 7[5, 0, 0][5, 0, 0]Passed

SHA-256 / 091cc678d94506a3a50b64e1d1f6f5d064f4cbe7c1e32b8248147d29d2f81761

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': [1000, 1000, 919, 1000, 4033], 'free': 5, 'div': 1, 'round': 'up', 'price': 250}, [8, 3, 750]), ('regression', {'events': [1000, 452], 'free': 5, 'div': 100, 'round': 'up', 'price': 999}, [2, 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': [3529, 608], 'free': 0, 'div': 5, 'round': 'up', 'price': 250}, [5, 1, 250]), ('normal control', {'events': [4863, 300, 2484, 893, 1000, 741], 'free': 10, 'div': 5, 'round': 'down', 'price': 999}, [11, 0, 0]), ('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': [1000, 1000, 577, 2375], 'free': 10, 'div': 1, 'round': 'down', 'price': 250}, [5, 0, 0])], [('regression', {'events': [673, 4210, 1000, 3643], 'free': 5, 'div': 5, 'round': 'up', 'price': 250}, [10, 1, 250]), ('regression', {'events': [], 'free': 10, 'div': 100, 'round': 'up', 'price': 100}, [0, 0, 0]), ('partial-repair probe', {'events': [3529, 608], 'free': 0, 'div': 5, 'round': 'up', 'price': 250}, [5, 1, 250]), ('partial-repair probe', {'events': [982, 260, 2668, 1000, 3988, 800], 'free': 0, 'div': 10, 'round': 'up', 'price': 999}, [10, 1, 999]), ('normal control', {'events': [1000], 'free': 10, 'div': 100, 'round': 'down', 'price': 999}, [1, 0, 0]), ('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])], [('regression', {'events': [3529, 608], 'free': 0, 'div': 5, 'round': 'up', 'price': 250}, [5, 1, 250]), ('regression', {'events': [460, 1000], 'free': 10, 'div': 100, 'round': 'up', 'price': 100}, [2, 0, 0]), ('partial-repair probe', {'events': [880, 518, 41, 3687, 1000, 180], 'free': 0, 'div': 1, 'round': 'up', 'price': 250}, [7, 7, 1750]), ('partial-repair probe', {'events': [4250, 1000], 'free': 5, 'div': 1, 'round': 'up', 'price': 250}, [6, 1, 250]), ('normal control', {'events': [1000], 'free': 10, 'div': 1, 'round': 'down', 'price': 999}, [1, 0, 0]), ('normal control', {'events': [576, 688, 449, 1000, 815], 'free': 0, 'div': 5, 'round': 'down', 'price': 999}, [4, 0, 0]), ('normal control', {'events': [339, 1000, 1810, 2557, 4715], 'free': 10, 'div': 100, 'round': 'down', 'price': 100}, [11, 0, 0]), ('normal control', {'events': [391, 8, 2736, 4419], 'free': 5, 'div': 100, 'round': 'up', 'price': 250}, [8, 1, 250])], [('regression', {'events': [982, 260, 2668, 1000, 3988, 800], 'free': 0, 'div': 10, 'round': 'up', 'price': 999}, [10, 1, 999]), ('regression', {'events': [716, 4530], 'free': 10, 'div': 10, 'round': 'up', 'price': 100}, [6, 0, 0]), ('partial-repair probe', {'events': [155, 3403, 470], 'free': 0, 'div': 5, 'round': 'up', 'price': 100}, [5, 1, 100]), ('partial-repair probe', {'events': [1000, 42, 2623, 1000, 3087], 'free': 5, 'div': 1, 'round': 'up', 'price': 100}, [8, 3, 300]), ('normal control', {'events': [4324, 534, 615, 25], 'free': 5, 'div': 100, 'round': 'up', 'price': 999}, [6, 1, 999]), ('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]), ('normal control', {'events': [604, 2714, 1000, 776, 1000, 4405], 'free': 5, 'div': 5, 'round': 'up', 'price': 250}, [11, 2, 500])], [('regression', {'events': [880, 518, 41, 3687, 1000, 180], 'free': 0, 'div': 1, 'round': 'up', 'price': 250}, [7, 7, 1750]), ('regression', {'events': [321, 1000, 593, 354, 2136], 'free': 5, 'div': 100, 'round': 'up', 'price': 100}, [5, 0, 0]), ('partial-repair probe', {'events': [235, 462, 166, 353, 1000], 'free': 0, 'div': 1, 'round': 'up', 'price': 250}, [3, 3, 750]), ('partial-repair probe', {'events': [1000, 4365, 1000, 3571, 76], 'free': 0, 'div': 1, 'round': 'up', 'price': 999}, [11, 11, 10989]), ('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': [1000, 679], 'free': 10, 'div': 1, 'round': 'down', 'price': 250}, [2, 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[8, 3, 750][8, 3, 750]Passed
regression 1[2, 0, 0][2, 0, 0]Passed
partial-repair probe 2[10, 1, 250][10, 1, 250]Passed
partial-repair probe 3[5, 1, 250][5, 1, 250]Passed
normal control 4[11, 0, 0][11, 0, 0]Passed
normal control 5[9, 1, 250][9, 1, 250]Passed
normal control 6[6, 1, 100][6, 1, 100]Passed
normal control 7[5, 0, 0][5, 0, 0]Passed

SHA-256 / 34726787d2d4eab6dd31b8f1ebb55c262b0f55c85947af0925b0e30645c4c8e9

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

Case digest / 7a7f9cd8f877be063ed5243607eac4a8f4c8e04cc7f70914fec8e813044dfe7d