FAILURE MAP
← Case archive

FA-59651 / Subscription proration billing / Open access

Minimum threshold for invoicing prorations: credit threshold · case 01

Tiny credits are applied to balances immediately instead of being carried.

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

ROOT CAUSE

Any negative pending amount is credited regardless of the threshold.

VERIFIED REPAIR

Restore the contract rule at the credit threshold step: use `if pending <= -x['threshold']:`.

Unsuccessful approach: The attempt credits only when the carried amount was not positive.

Case contract

Input {lines, threshold, carried}. Pending = carried + sum(lines). Pending >= threshold is invoiced now; pending <= -threshold is credited to the balance now; anything in between is carried to the next cycle. Return [invoiced, credited, carry].

Why this case matters

Tiny proration amounts are deferred to avoid micro-charges, but must not be lost.

1 / The failure

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

N = 1
observations = []
def solve(x):
    pending = x['carried'] + sum(x['lines'])
    if pending >= x['threshold']:
        return [pending, 0, 0]
    if pending < 0:
        return [0, -pending, 0]
    return [0, 0, pending]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'lines': [-381, 116], 'threshold': 500, 'carried': 0}, [0, 0, -265]), ('regression', {'lines': [], 'threshold': 500, 'carried': -499}, [0, 0, -499]), ('partial-repair probe (boundary)', {'lines': [-60], 'threshold': 50, 'carried': 10}, [0, 50, 0]), ('partial-repair probe', {'lines': [-336, -428, -165, 586], 'threshold': 50, 'carried': 49}, [0, 294, 0]), ('boundary control', {'lines': [30], 'threshold': 50, 'carried': 20}, [50, 0, 0]), ('boundary control', {'lines': [], 'threshold': 100, 'carried': 100}, [100, 0, 0]), ('normal control', {'lines': [61, 426, -138, 400], 'threshold': 50, 'carried': 0}, [749, 0, 0]), ('normal control', {'lines': [], 'threshold': 500, 'carried': 499}, [0, 0, 499]), ('normal control', {'lines': [518, -386], 'threshold': 500, 'carried': 499}, [631, 0, 0]), ('normal control', {'lines': [340, -379, -241], 'threshold': 50, 'carried': -6}, [0, 286, 0])], [('regression', {'lines': [], 'threshold': 500, 'carried': -499}, [0, 0, -499]), ('regression', {'lines': [], 'threshold': 100, 'carried': -99}, [0, 0, -99]), ('partial-repair probe', {'lines': [-451, 120, 343, -367], 'threshold': 100, 'carried': 99}, [0, 256, 0]), ('partial-repair probe', {'lines': [179, 224, -295, -260], 'threshold': 50, 'carried': 26}, [0, 126, 0]), ('boundary control', {'lines': [250, 250], 'threshold': 500, 'carried': 0}, [500, 0, 0]), ('boundary control', {'lines': [-50, 150], 'threshold': 100, 'carried': 0}, [100, 0, 0]), ('normal control', {'lines': [-497, -497, -32, -352], 'threshold': 50, 'carried': -49}, [0, 1427, 0]), ('normal control', {'lines': [-95, 305], 'threshold': 100, 'carried': 0}, [210, 0, 0]), ('normal control', {'lines': [145, -201, 592, 509], 'threshold': 500, 'carried': 0}, [1045, 0, 0]), ('normal control', {'lines': [382, -579, 100], 'threshold': 500, 'carried': 299}, [0, 0, 202])], [('regression', {'lines': [], 'threshold': 100, 'carried': -99}, [0, 0, -99]), ('regression', {'lines': [], 'threshold': 50, 'carried': -41}, [0, 0, -41]), ('partial-repair probe', {'lines': [-362, -501], 'threshold': 100, 'carried': 99}, [0, 764, 0]), ('partial-repair probe', {'lines': [-584], 'threshold': 100, 'carried': 99}, [0, 485, 0]), ('boundary control', {'lines': [-100], 'threshold': 100, 'carried': 0}, [0, 100, 0]), ('boundary control', {'lines': [40, 10], 'threshold': 50, 'carried': 0}, [50, 0, 0]), ('normal control', {'lines': [2, -134, -347, 119], 'threshold': 50, 'carried': 0}, [0, 360, 0]), ('normal control', {'lines': [-325], 'threshold': 500, 'carried': -499}, [0, 824, 0]), ('normal control', {'lines': [3], 'threshold': 100, 'carried': 49}, [0, 0, 52]), ('normal control', {'lines': [481], 'threshold': 100, 'carried': 0}, [481, 0, 0])], [('regression', {'lines': [], 'threshold': 50, 'carried': -41}, [0, 0, -41]), ('regression', {'lines': [295], 'threshold': 500, 'carried': -499}, [0, 0, -204]), ('partial-repair probe', {'lines': [-209, -185, -52], 'threshold': 50, 'carried': 49}, [0, 397, 0]), ('partial-repair probe', {'lines': [-560, 416], 'threshold': 50, 'carried': 49}, [0, 95, 0]), ('boundary control', {'lines': [30], 'threshold': 50, 'carried': 20}, [50, 0, 0]), ('boundary control', {'lines': [], 'threshold': 100, 'carried': 100}, [100, 0, 0]), ('normal control', {'lines': [184, -104], 'threshold': 50, 'carried': 0}, [80, 0, 0]), ('normal control', {'lines': [131], 'threshold': 100, 'carried': 99}, [230, 0, 0]), ('normal control', {'lines': [140, 140], 'threshold': 100, 'carried': -99}, [181, 0, 0]), ('normal control', {'lines': [], 'threshold': 50, 'carried': 49}, [0, 0, 49])], [('regression', {'lines': [295], 'threshold': 500, 'carried': -499}, [0, 0, -204]), ('regression', {'lines': [], 'threshold': 50, 'carried': -49}, [0, 0, -49]), ('partial-repair probe', {'lines': [-500, -443, -151], 'threshold': 100, 'carried': 79}, [0, 1015, 0]), ('partial-repair probe', {'lines': [-319, -173, -554], 'threshold': 500, 'carried': 499}, [0, 547, 0]), ('boundary control', {'lines': [250, 250], 'threshold': 500, 'carried': 0}, [500, 0, 0]), ('boundary control', {'lines': [-50, 150], 'threshold': 100, 'carried': 0}, [100, 0, 0]), ('normal control', {'lines': [218, -553], 'threshold': 100, 'carried': -99}, [0, 434, 0]), ('normal control', {'lines': [489], 'threshold': 50, 'carried': -49}, [440, 0, 0]), ('normal control', {'lines': [462, -187], 'threshold': 50, 'carried': 49}, [324, 0, 0]), ('normal control', {'lines': [425, 134, -443, 185], 'threshold': 100, 'carried': -99}, [202, 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[0, 265, 0][0, 0, -265]Failed
regression 1[0, 499, 0][0, 0, -499]Failed
partial-repair probe (boundary) 2[0, 50, 0][0, 50, 0]Passed
partial-repair probe 3[0, 294, 0][0, 294, 0]Passed
boundary control 4[50, 0, 0][50, 0, 0]Passed
boundary control 5[100, 0, 0][100, 0, 0]Passed
normal control 6[749, 0, 0][749, 0, 0]Passed
normal control 7[0, 0, 499][0, 0, 499]Passed
normal control 8[631, 0, 0][631, 0, 0]Passed
normal control 9[0, 286, 0][0, 286, 0]Passed

SHA-256 / 4d6a774345d6afae1ce66c58f792af548dcc75fc7b9aa27b593be717620453b9

2 / The unsuccessful fix

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

N = 1
observations = []
def solve(x):
    pending = x['carried'] + sum(x['lines'])
    if pending >= x['threshold']:
        return [pending, 0, 0]
    if pending <= -x['threshold'] and x['carried'] <= 0:
        return [0, -pending, 0]
    return [0, 0, pending]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'lines': [-381, 116], 'threshold': 500, 'carried': 0}, [0, 0, -265]), ('regression', {'lines': [], 'threshold': 500, 'carried': -499}, [0, 0, -499]), ('partial-repair probe (boundary)', {'lines': [-60], 'threshold': 50, 'carried': 10}, [0, 50, 0]), ('partial-repair probe', {'lines': [-336, -428, -165, 586], 'threshold': 50, 'carried': 49}, [0, 294, 0]), ('boundary control', {'lines': [30], 'threshold': 50, 'carried': 20}, [50, 0, 0]), ('boundary control', {'lines': [], 'threshold': 100, 'carried': 100}, [100, 0, 0]), ('normal control', {'lines': [61, 426, -138, 400], 'threshold': 50, 'carried': 0}, [749, 0, 0]), ('normal control', {'lines': [], 'threshold': 500, 'carried': 499}, [0, 0, 499]), ('normal control', {'lines': [518, -386], 'threshold': 500, 'carried': 499}, [631, 0, 0]), ('normal control', {'lines': [340, -379, -241], 'threshold': 50, 'carried': -6}, [0, 286, 0])], [('regression', {'lines': [], 'threshold': 500, 'carried': -499}, [0, 0, -499]), ('regression', {'lines': [], 'threshold': 100, 'carried': -99}, [0, 0, -99]), ('partial-repair probe', {'lines': [-451, 120, 343, -367], 'threshold': 100, 'carried': 99}, [0, 256, 0]), ('partial-repair probe', {'lines': [179, 224, -295, -260], 'threshold': 50, 'carried': 26}, [0, 126, 0]), ('boundary control', {'lines': [250, 250], 'threshold': 500, 'carried': 0}, [500, 0, 0]), ('boundary control', {'lines': [-50, 150], 'threshold': 100, 'carried': 0}, [100, 0, 0]), ('normal control', {'lines': [-497, -497, -32, -352], 'threshold': 50, 'carried': -49}, [0, 1427, 0]), ('normal control', {'lines': [-95, 305], 'threshold': 100, 'carried': 0}, [210, 0, 0]), ('normal control', {'lines': [145, -201, 592, 509], 'threshold': 500, 'carried': 0}, [1045, 0, 0]), ('normal control', {'lines': [382, -579, 100], 'threshold': 500, 'carried': 299}, [0, 0, 202])], [('regression', {'lines': [], 'threshold': 100, 'carried': -99}, [0, 0, -99]), ('regression', {'lines': [], 'threshold': 50, 'carried': -41}, [0, 0, -41]), ('partial-repair probe', {'lines': [-362, -501], 'threshold': 100, 'carried': 99}, [0, 764, 0]), ('partial-repair probe', {'lines': [-584], 'threshold': 100, 'carried': 99}, [0, 485, 0]), ('boundary control', {'lines': [-100], 'threshold': 100, 'carried': 0}, [0, 100, 0]), ('boundary control', {'lines': [40, 10], 'threshold': 50, 'carried': 0}, [50, 0, 0]), ('normal control', {'lines': [2, -134, -347, 119], 'threshold': 50, 'carried': 0}, [0, 360, 0]), ('normal control', {'lines': [-325], 'threshold': 500, 'carried': -499}, [0, 824, 0]), ('normal control', {'lines': [3], 'threshold': 100, 'carried': 49}, [0, 0, 52]), ('normal control', {'lines': [481], 'threshold': 100, 'carried': 0}, [481, 0, 0])], [('regression', {'lines': [], 'threshold': 50, 'carried': -41}, [0, 0, -41]), ('regression', {'lines': [295], 'threshold': 500, 'carried': -499}, [0, 0, -204]), ('partial-repair probe', {'lines': [-209, -185, -52], 'threshold': 50, 'carried': 49}, [0, 397, 0]), ('partial-repair probe', {'lines': [-560, 416], 'threshold': 50, 'carried': 49}, [0, 95, 0]), ('boundary control', {'lines': [30], 'threshold': 50, 'carried': 20}, [50, 0, 0]), ('boundary control', {'lines': [], 'threshold': 100, 'carried': 100}, [100, 0, 0]), ('normal control', {'lines': [184, -104], 'threshold': 50, 'carried': 0}, [80, 0, 0]), ('normal control', {'lines': [131], 'threshold': 100, 'carried': 99}, [230, 0, 0]), ('normal control', {'lines': [140, 140], 'threshold': 100, 'carried': -99}, [181, 0, 0]), ('normal control', {'lines': [], 'threshold': 50, 'carried': 49}, [0, 0, 49])], [('regression', {'lines': [295], 'threshold': 500, 'carried': -499}, [0, 0, -204]), ('regression', {'lines': [], 'threshold': 50, 'carried': -49}, [0, 0, -49]), ('partial-repair probe', {'lines': [-500, -443, -151], 'threshold': 100, 'carried': 79}, [0, 1015, 0]), ('partial-repair probe', {'lines': [-319, -173, -554], 'threshold': 500, 'carried': 499}, [0, 547, 0]), ('boundary control', {'lines': [250, 250], 'threshold': 500, 'carried': 0}, [500, 0, 0]), ('boundary control', {'lines': [-50, 150], 'threshold': 100, 'carried': 0}, [100, 0, 0]), ('normal control', {'lines': [218, -553], 'threshold': 100, 'carried': -99}, [0, 434, 0]), ('normal control', {'lines': [489], 'threshold': 50, 'carried': -49}, [440, 0, 0]), ('normal control', {'lines': [462, -187], 'threshold': 50, 'carried': 49}, [324, 0, 0]), ('normal control', {'lines': [425, 134, -443, 185], 'threshold': 100, 'carried': -99}, [202, 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[0, 0, -265][0, 0, -265]Passed
regression 1[0, 0, -499][0, 0, -499]Passed
partial-repair probe (boundary) 2[0, 0, -50][0, 50, 0]Failed
partial-repair probe 3[0, 0, -294][0, 294, 0]Failed
boundary control 4[50, 0, 0][50, 0, 0]Passed
boundary control 5[100, 0, 0][100, 0, 0]Passed
normal control 6[749, 0, 0][749, 0, 0]Passed
normal control 7[0, 0, 499][0, 0, 499]Passed
normal control 8[631, 0, 0][631, 0, 0]Passed
normal control 9[0, 286, 0][0, 286, 0]Passed

SHA-256 / 9a2998ebf547bad87b7f177e920ffbfe6606b36a6c974f181d4a1ce7d37b6f79

3 / The verified repair

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

N = 1
observations = []
def solve(x):
    pending = x['carried'] + sum(x['lines'])
    if pending >= x['threshold']:
        return [pending, 0, 0]
    if pending <= -x['threshold']:
        return [0, -pending, 0]
    return [0, 0, pending]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'lines': [-381, 116], 'threshold': 500, 'carried': 0}, [0, 0, -265]), ('regression', {'lines': [], 'threshold': 500, 'carried': -499}, [0, 0, -499]), ('partial-repair probe (boundary)', {'lines': [-60], 'threshold': 50, 'carried': 10}, [0, 50, 0]), ('partial-repair probe', {'lines': [-336, -428, -165, 586], 'threshold': 50, 'carried': 49}, [0, 294, 0]), ('boundary control', {'lines': [30], 'threshold': 50, 'carried': 20}, [50, 0, 0]), ('boundary control', {'lines': [], 'threshold': 100, 'carried': 100}, [100, 0, 0]), ('normal control', {'lines': [61, 426, -138, 400], 'threshold': 50, 'carried': 0}, [749, 0, 0]), ('normal control', {'lines': [], 'threshold': 500, 'carried': 499}, [0, 0, 499]), ('normal control', {'lines': [518, -386], 'threshold': 500, 'carried': 499}, [631, 0, 0]), ('normal control', {'lines': [340, -379, -241], 'threshold': 50, 'carried': -6}, [0, 286, 0])], [('regression', {'lines': [], 'threshold': 500, 'carried': -499}, [0, 0, -499]), ('regression', {'lines': [], 'threshold': 100, 'carried': -99}, [0, 0, -99]), ('partial-repair probe', {'lines': [-451, 120, 343, -367], 'threshold': 100, 'carried': 99}, [0, 256, 0]), ('partial-repair probe', {'lines': [179, 224, -295, -260], 'threshold': 50, 'carried': 26}, [0, 126, 0]), ('boundary control', {'lines': [250, 250], 'threshold': 500, 'carried': 0}, [500, 0, 0]), ('boundary control', {'lines': [-50, 150], 'threshold': 100, 'carried': 0}, [100, 0, 0]), ('normal control', {'lines': [-497, -497, -32, -352], 'threshold': 50, 'carried': -49}, [0, 1427, 0]), ('normal control', {'lines': [-95, 305], 'threshold': 100, 'carried': 0}, [210, 0, 0]), ('normal control', {'lines': [145, -201, 592, 509], 'threshold': 500, 'carried': 0}, [1045, 0, 0]), ('normal control', {'lines': [382, -579, 100], 'threshold': 500, 'carried': 299}, [0, 0, 202])], [('regression', {'lines': [], 'threshold': 100, 'carried': -99}, [0, 0, -99]), ('regression', {'lines': [], 'threshold': 50, 'carried': -41}, [0, 0, -41]), ('partial-repair probe', {'lines': [-362, -501], 'threshold': 100, 'carried': 99}, [0, 764, 0]), ('partial-repair probe', {'lines': [-584], 'threshold': 100, 'carried': 99}, [0, 485, 0]), ('boundary control', {'lines': [-100], 'threshold': 100, 'carried': 0}, [0, 100, 0]), ('boundary control', {'lines': [40, 10], 'threshold': 50, 'carried': 0}, [50, 0, 0]), ('normal control', {'lines': [2, -134, -347, 119], 'threshold': 50, 'carried': 0}, [0, 360, 0]), ('normal control', {'lines': [-325], 'threshold': 500, 'carried': -499}, [0, 824, 0]), ('normal control', {'lines': [3], 'threshold': 100, 'carried': 49}, [0, 0, 52]), ('normal control', {'lines': [481], 'threshold': 100, 'carried': 0}, [481, 0, 0])], [('regression', {'lines': [], 'threshold': 50, 'carried': -41}, [0, 0, -41]), ('regression', {'lines': [295], 'threshold': 500, 'carried': -499}, [0, 0, -204]), ('partial-repair probe', {'lines': [-209, -185, -52], 'threshold': 50, 'carried': 49}, [0, 397, 0]), ('partial-repair probe', {'lines': [-560, 416], 'threshold': 50, 'carried': 49}, [0, 95, 0]), ('boundary control', {'lines': [30], 'threshold': 50, 'carried': 20}, [50, 0, 0]), ('boundary control', {'lines': [], 'threshold': 100, 'carried': 100}, [100, 0, 0]), ('normal control', {'lines': [184, -104], 'threshold': 50, 'carried': 0}, [80, 0, 0]), ('normal control', {'lines': [131], 'threshold': 100, 'carried': 99}, [230, 0, 0]), ('normal control', {'lines': [140, 140], 'threshold': 100, 'carried': -99}, [181, 0, 0]), ('normal control', {'lines': [], 'threshold': 50, 'carried': 49}, [0, 0, 49])], [('regression', {'lines': [295], 'threshold': 500, 'carried': -499}, [0, 0, -204]), ('regression', {'lines': [], 'threshold': 50, 'carried': -49}, [0, 0, -49]), ('partial-repair probe', {'lines': [-500, -443, -151], 'threshold': 100, 'carried': 79}, [0, 1015, 0]), ('partial-repair probe', {'lines': [-319, -173, -554], 'threshold': 500, 'carried': 499}, [0, 547, 0]), ('boundary control', {'lines': [250, 250], 'threshold': 500, 'carried': 0}, [500, 0, 0]), ('boundary control', {'lines': [-50, 150], 'threshold': 100, 'carried': 0}, [100, 0, 0]), ('normal control', {'lines': [218, -553], 'threshold': 100, 'carried': -99}, [0, 434, 0]), ('normal control', {'lines': [489], 'threshold': 50, 'carried': -49}, [440, 0, 0]), ('normal control', {'lines': [462, -187], 'threshold': 50, 'carried': 49}, [324, 0, 0]), ('normal control', {'lines': [425, 134, -443, 185], 'threshold': 100, 'carried': -99}, [202, 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[0, 0, -265][0, 0, -265]Passed
regression 1[0, 0, -499][0, 0, -499]Passed
partial-repair probe (boundary) 2[0, 50, 0][0, 50, 0]Passed
partial-repair probe 3[0, 294, 0][0, 294, 0]Passed
boundary control 4[50, 0, 0][50, 0, 0]Passed
boundary control 5[100, 0, 0][100, 0, 0]Passed
normal control 6[749, 0, 0][749, 0, 0]Passed
normal control 7[0, 0, 499][0, 0, 499]Passed
normal control 8[631, 0, 0][631, 0, 0]Passed
normal control 9[0, 286, 0][0, 286, 0]Passed

SHA-256 / 0a76c973aab8c32a1d269e5885de80f562aec409debfd9b107427db90ec4622f

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

Case digest / 692e6d374b2485cedc5ad63db90623df3c804a56a0973ea532fade772582c0f1