FAILURE MAP
← Case archive

FA-59826 / Subscription proration billing / Open access

Unused-time credit based on amount paid: credit basis · case 01

Customers who paid with a discount receive credits at the full list price.

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

ROOT CAUSE

The credit is based on the list price rather than the amount paid.

VERIFIED REPAIR

Restore the contract rule at the credit basis step: use `x['paid'] * x['left'] * 2`.

Unsuccessful approach: The attempt floors the basis at half the list price, still over-crediting heavily discounted periods.

Case contract

Input {list, paid, status paid|partial|open|void|refunded, left, period}. Open, void and refunded invoices earn no unused-time credit. Paid and partially paid invoices earn paid*left/period half-up (the amount actually collected, not the list price). Return cents.

Why this case matters

Credits for unused time must not exceed what the customer actually paid for the period.

1 / The failure

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

N = 1
observations = []
def solve(x):
    if x['status'] in ('open', 'void', 'refunded'):
        return 0
    return (x['list'] * x['left'] * 2 + x['period']) // (2 * x['period'])
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'list': 1000, 'paid': 0, 'status': 'partial', 'left': 13, 'period': 31}, 0), ('regression', {'list': 4900, 'paid': 2450, 'status': 'partial', 'left': 24, 'period': 31}, 1897), ('partial-repair probe', {'list': 4900, 'paid': 935, 'status': 'partial', 'left': 23, 'period': 31}, 694), ('partial-repair probe', {'list': 1000, 'paid': 0, 'status': 'partial', 'left': 3, 'period': 31}, 0), ('normal control', {'list': 9900, 'paid': 4950, 'status': 'void', 'left': 9, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 0, 'status': 'void', 'left': 9, 'period': 31}, 0), ('normal control', {'list': 9900, 'paid': 0, 'status': 'open', 'left': 4, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 2450, 'status': 'open', 'left': 29, 'period': 31}, 0)], [('regression', {'list': 4900, 'paid': 935, 'status': 'partial', 'left': 23, 'period': 31}, 694), ('regression', {'list': 4900, 'paid': 2450, 'status': 'paid', 'left': 6, 'period': 31}, 474), ('partial-repair probe', {'list': 1000, 'paid': 0, 'status': 'partial', 'left': 3, 'period': 31}, 0), ('partial-repair probe', {'list': 4900, 'paid': 311, 'status': 'partial', 'left': 2, 'period': 31}, 20), ('normal control', {'list': 4900, 'paid': 4900, 'status': 'paid', 'left': 19, 'period': 31}, 3003), ('normal control', {'list': 1000, 'paid': 500, 'status': 'open', 'left': 15, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 0, 'status': 'refunded', 'left': 1, 'period': 31}, 0), ('normal control', {'list': 1000, 'paid': 500, 'status': 'open', 'left': 9, 'period': 31}, 0)], [('regression', {'list': 1000, 'paid': 0, 'status': 'partial', 'left': 3, 'period': 31}, 0), ('regression', {'list': 1000, 'paid': 0, 'status': 'partial', 'left': 13, 'period': 31}, 0), ('partial-repair probe', {'list': 9900, 'paid': 0, 'status': 'partial', 'left': 9, 'period': 31}, 0), ('partial-repair probe', {'list': 4900, 'paid': 0, 'status': 'paid', 'left': 31, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 2450, 'status': 'open', 'left': 20, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 4900, 'status': 'void', 'left': 3, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 4900, 'status': 'open', 'left': 25, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 0, 'status': 'void', 'left': 29, 'period': 31}, 0)], [('regression', {'list': 4900, 'paid': 311, 'status': 'partial', 'left': 2, 'period': 31}, 20), ('regression', {'list': 4900, 'paid': 935, 'status': 'partial', 'left': 23, 'period': 31}, 694), ('partial-repair probe', {'list': 4900, 'paid': 1180, 'status': 'paid', 'left': 4, 'period': 31}, 152), ('partial-repair probe', {'list': 1000, 'paid': 0, 'status': 'paid', 'left': 5, 'period': 31}, 0), ('normal control', {'list': 9900, 'paid': 2540, 'status': 'open', 'left': 27, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 0, 'status': 'refunded', 'left': 6, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 786, 'status': 'open', 'left': 21, 'period': 31}, 0), ('normal control', {'list': 1000, 'paid': 0, 'status': 'refunded', 'left': 28, 'period': 31}, 0)], [('regression', {'list': 9900, 'paid': 0, 'status': 'partial', 'left': 9, 'period': 31}, 0), ('regression', {'list': 9900, 'paid': 4950, 'status': 'paid', 'left': 25, 'period': 31}, 3992), ('partial-repair probe', {'list': 9900, 'paid': 3829, 'status': 'paid', 'left': 13, 'period': 31}, 1606), ('partial-repair probe', {'list': 1000, 'paid': 0, 'status': 'paid', 'left': 27, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 4900, 'status': 'paid', 'left': 29, 'period': 31}, 4584), ('normal control', {'list': 1000, 'paid': 461, 'status': 'refunded', 'left': 10, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 2450, 'status': 'refunded', 'left': 20, 'period': 31}, 0), ('normal control', {'list': 9900, 'paid': 4739, 'status': 'refunded', 'left': 24, 'period': 31}, 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 04190Failed
regression 137941897Failed
partial-repair probe 23635694Failed
partial-repair probe 3970Failed
normal control 400Passed
normal control 500Passed
normal control 600Passed
normal control 700Passed

SHA-256 / c3fed32413cd0afe195bd0c88d01daead10f2c9f09f1c45b70818fea03a71a47

2 / The unsuccessful fix

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

N = 1
observations = []
def solve(x):
    if x['status'] in ('open', 'void', 'refunded'):
        return 0
    return (max(x['paid'], x['list'] // 2) * x['left'] * 2 + x['period']) // (2 * x['period'])
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'list': 1000, 'paid': 0, 'status': 'partial', 'left': 13, 'period': 31}, 0), ('regression', {'list': 4900, 'paid': 2450, 'status': 'partial', 'left': 24, 'period': 31}, 1897), ('partial-repair probe', {'list': 4900, 'paid': 935, 'status': 'partial', 'left': 23, 'period': 31}, 694), ('partial-repair probe', {'list': 1000, 'paid': 0, 'status': 'partial', 'left': 3, 'period': 31}, 0), ('normal control', {'list': 9900, 'paid': 4950, 'status': 'void', 'left': 9, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 0, 'status': 'void', 'left': 9, 'period': 31}, 0), ('normal control', {'list': 9900, 'paid': 0, 'status': 'open', 'left': 4, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 2450, 'status': 'open', 'left': 29, 'period': 31}, 0)], [('regression', {'list': 4900, 'paid': 935, 'status': 'partial', 'left': 23, 'period': 31}, 694), ('regression', {'list': 4900, 'paid': 2450, 'status': 'paid', 'left': 6, 'period': 31}, 474), ('partial-repair probe', {'list': 1000, 'paid': 0, 'status': 'partial', 'left': 3, 'period': 31}, 0), ('partial-repair probe', {'list': 4900, 'paid': 311, 'status': 'partial', 'left': 2, 'period': 31}, 20), ('normal control', {'list': 4900, 'paid': 4900, 'status': 'paid', 'left': 19, 'period': 31}, 3003), ('normal control', {'list': 1000, 'paid': 500, 'status': 'open', 'left': 15, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 0, 'status': 'refunded', 'left': 1, 'period': 31}, 0), ('normal control', {'list': 1000, 'paid': 500, 'status': 'open', 'left': 9, 'period': 31}, 0)], [('regression', {'list': 1000, 'paid': 0, 'status': 'partial', 'left': 3, 'period': 31}, 0), ('regression', {'list': 1000, 'paid': 0, 'status': 'partial', 'left': 13, 'period': 31}, 0), ('partial-repair probe', {'list': 9900, 'paid': 0, 'status': 'partial', 'left': 9, 'period': 31}, 0), ('partial-repair probe', {'list': 4900, 'paid': 0, 'status': 'paid', 'left': 31, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 2450, 'status': 'open', 'left': 20, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 4900, 'status': 'void', 'left': 3, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 4900, 'status': 'open', 'left': 25, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 0, 'status': 'void', 'left': 29, 'period': 31}, 0)], [('regression', {'list': 4900, 'paid': 311, 'status': 'partial', 'left': 2, 'period': 31}, 20), ('regression', {'list': 4900, 'paid': 935, 'status': 'partial', 'left': 23, 'period': 31}, 694), ('partial-repair probe', {'list': 4900, 'paid': 1180, 'status': 'paid', 'left': 4, 'period': 31}, 152), ('partial-repair probe', {'list': 1000, 'paid': 0, 'status': 'paid', 'left': 5, 'period': 31}, 0), ('normal control', {'list': 9900, 'paid': 2540, 'status': 'open', 'left': 27, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 0, 'status': 'refunded', 'left': 6, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 786, 'status': 'open', 'left': 21, 'period': 31}, 0), ('normal control', {'list': 1000, 'paid': 0, 'status': 'refunded', 'left': 28, 'period': 31}, 0)], [('regression', {'list': 9900, 'paid': 0, 'status': 'partial', 'left': 9, 'period': 31}, 0), ('regression', {'list': 9900, 'paid': 4950, 'status': 'paid', 'left': 25, 'period': 31}, 3992), ('partial-repair probe', {'list': 9900, 'paid': 3829, 'status': 'paid', 'left': 13, 'period': 31}, 1606), ('partial-repair probe', {'list': 1000, 'paid': 0, 'status': 'paid', 'left': 27, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 4900, 'status': 'paid', 'left': 29, 'period': 31}, 4584), ('normal control', {'list': 1000, 'paid': 461, 'status': 'refunded', 'left': 10, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 2450, 'status': 'refunded', 'left': 20, 'period': 31}, 0), ('normal control', {'list': 9900, 'paid': 4739, 'status': 'refunded', 'left': 24, 'period': 31}, 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 02100Failed
regression 118971897Passed
partial-repair probe 21818694Failed
partial-repair probe 3480Failed
normal control 400Passed
normal control 500Passed
normal control 600Passed
normal control 700Passed

SHA-256 / 8c89c5f021c9102f25ae6929c5991ba4b5603fcbb2eafea04ce6fe498eec76c5

3 / The verified repair

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

N = 1
observations = []
def solve(x):
    if x['status'] in ('open', 'void', 'refunded'):
        return 0
    return (x['paid'] * x['left'] * 2 + x['period']) // (2 * x['period'])
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'list': 1000, 'paid': 0, 'status': 'partial', 'left': 13, 'period': 31}, 0), ('regression', {'list': 4900, 'paid': 2450, 'status': 'partial', 'left': 24, 'period': 31}, 1897), ('partial-repair probe', {'list': 4900, 'paid': 935, 'status': 'partial', 'left': 23, 'period': 31}, 694), ('partial-repair probe', {'list': 1000, 'paid': 0, 'status': 'partial', 'left': 3, 'period': 31}, 0), ('normal control', {'list': 9900, 'paid': 4950, 'status': 'void', 'left': 9, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 0, 'status': 'void', 'left': 9, 'period': 31}, 0), ('normal control', {'list': 9900, 'paid': 0, 'status': 'open', 'left': 4, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 2450, 'status': 'open', 'left': 29, 'period': 31}, 0)], [('regression', {'list': 4900, 'paid': 935, 'status': 'partial', 'left': 23, 'period': 31}, 694), ('regression', {'list': 4900, 'paid': 2450, 'status': 'paid', 'left': 6, 'period': 31}, 474), ('partial-repair probe', {'list': 1000, 'paid': 0, 'status': 'partial', 'left': 3, 'period': 31}, 0), ('partial-repair probe', {'list': 4900, 'paid': 311, 'status': 'partial', 'left': 2, 'period': 31}, 20), ('normal control', {'list': 4900, 'paid': 4900, 'status': 'paid', 'left': 19, 'period': 31}, 3003), ('normal control', {'list': 1000, 'paid': 500, 'status': 'open', 'left': 15, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 0, 'status': 'refunded', 'left': 1, 'period': 31}, 0), ('normal control', {'list': 1000, 'paid': 500, 'status': 'open', 'left': 9, 'period': 31}, 0)], [('regression', {'list': 1000, 'paid': 0, 'status': 'partial', 'left': 3, 'period': 31}, 0), ('regression', {'list': 1000, 'paid': 0, 'status': 'partial', 'left': 13, 'period': 31}, 0), ('partial-repair probe', {'list': 9900, 'paid': 0, 'status': 'partial', 'left': 9, 'period': 31}, 0), ('partial-repair probe', {'list': 4900, 'paid': 0, 'status': 'paid', 'left': 31, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 2450, 'status': 'open', 'left': 20, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 4900, 'status': 'void', 'left': 3, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 4900, 'status': 'open', 'left': 25, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 0, 'status': 'void', 'left': 29, 'period': 31}, 0)], [('regression', {'list': 4900, 'paid': 311, 'status': 'partial', 'left': 2, 'period': 31}, 20), ('regression', {'list': 4900, 'paid': 935, 'status': 'partial', 'left': 23, 'period': 31}, 694), ('partial-repair probe', {'list': 4900, 'paid': 1180, 'status': 'paid', 'left': 4, 'period': 31}, 152), ('partial-repair probe', {'list': 1000, 'paid': 0, 'status': 'paid', 'left': 5, 'period': 31}, 0), ('normal control', {'list': 9900, 'paid': 2540, 'status': 'open', 'left': 27, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 0, 'status': 'refunded', 'left': 6, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 786, 'status': 'open', 'left': 21, 'period': 31}, 0), ('normal control', {'list': 1000, 'paid': 0, 'status': 'refunded', 'left': 28, 'period': 31}, 0)], [('regression', {'list': 9900, 'paid': 0, 'status': 'partial', 'left': 9, 'period': 31}, 0), ('regression', {'list': 9900, 'paid': 4950, 'status': 'paid', 'left': 25, 'period': 31}, 3992), ('partial-repair probe', {'list': 9900, 'paid': 3829, 'status': 'paid', 'left': 13, 'period': 31}, 1606), ('partial-repair probe', {'list': 1000, 'paid': 0, 'status': 'paid', 'left': 27, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 4900, 'status': 'paid', 'left': 29, 'period': 31}, 4584), ('normal control', {'list': 1000, 'paid': 461, 'status': 'refunded', 'left': 10, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 2450, 'status': 'refunded', 'left': 20, 'period': 31}, 0), ('normal control', {'list': 9900, 'paid': 4739, 'status': 'refunded', 'left': 24, 'period': 31}, 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 000Passed
regression 118971897Passed
partial-repair probe 2694694Passed
partial-repair probe 300Passed
normal control 400Passed
normal control 500Passed
normal control 600Passed
normal control 700Passed

SHA-256 / 950df9901717bec1074815bb1cd925682d0c20fd8503b5c60b0611768e807dcc

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

Case digest / 8e991ae187e9fc77cebc8a19070a5b0ef437d225c76604897d74497022172325