FA-59526 / Subscription proration billing / Open access
Sales tax on proration credit and debit lines: credit line tax reversal · case 01
Downgrade invoices over-collect tax because unused-time credits carry no tax reversal.
ROOT CAUSE
Negative credit lines are skipped when computing tax.
VERIFIED REPAIR
Restore the contract rule at the credit line tax reversal step: use `if taxable:`.
Unsuccessful approach: The attempt includes credit lines even when they are not taxable.
Case contract
Input {lines: [[signed cents, taxable]], rate_bp}. Tax is computed per taxable line, including negative credit lines (negative tax), each rounded half away from zero, then summed. Subtotal is the sum of all lines. Return [subtotal, tax, subtotal + tax].
Why this case matters
Credit lines on a prorated invoice must reverse the tax charged on the original period.
1 / The failure
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(x):
parts = []
for amt, taxable in x['lines']:
if taxable and amt > 0:
parts.append(amt * x['rate_bp'])
def hr(n):
t = (abs(n) * 2 + 10000) // 20000
return t if n >= 0 else -t
tax = sum(hr(n) for n in parts)
sub = sum(a for a, t in x['lines'])
return [sub, tax, sub + tax]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'lines': [[-30768, True], [88008, True], [58540, True], [-18089, False]], 'rate_bp': 50}, [97691, 579, 98270]), ('regression', {'lines': [[53, True], [-19388, True], [67, True]], 'rate_bp': 2000}, [-19268, -3854, -23122]), ('partial-repair probe', {'lines': [[-51735, False]], 'rate_bp': 2267}, [-51735, 0, -51735]), ('partial-repair probe', {'lines': [[-42950, False], [83094, False], [74700, False], [-33526, False]], 'rate_bp': 725}, [81318, 0, 81318]), ('normal control', {'lines': [[70, True]], 'rate_bp': 825}, [70, 6, 76]), ('normal control', {'lines': [[52, True], [19, False], [14472, True], [91, False]], 'rate_bp': 297}, [14634, 432, 15066]), ('normal control', {'lines': [[78656, True]], 'rate_bp': 1498}, [78656, 11783, 90439]), ('normal control', {'lines': [[74, True], [81059, True], [70668, True]], 'rate_bp': 825}, [151801, 12523, 164324])], [('regression', {'lines': [[-12837, True], [-41474, True], [88408, True], [-5186, False]], 'rate_bp': 1738}, [28911, 5926, 34837]), ('regression', {'lines': [[53, True], [-19388, True], [67, True]], 'rate_bp': 2000}, [-19268, -3854, -23122]), ('partial-repair probe', {'lines': [[-42950, False], [83094, False], [74700, False], [-33526, False]], 'rate_bp': 725}, [81318, 0, 81318]), ('partial-repair probe', {'lines': [[30278, True], [-25624, False], [18105, True]], 'rate_bp': 50}, [22759, 242, 23001]), ('normal control', {'lines': [[1785, False]], 'rate_bp': 1510}, [1785, 0, 1785]), ('normal control', {'lines': [[11, True], [30948, False]], 'rate_bp': 1000}, [30959, 1, 30960]), ('normal control', {'lines': [[20, False]], 'rate_bp': 50}, [20, 0, 20]), ('normal control', {'lines': [[13, True]], 'rate_bp': 825}, [13, 1, 14])], [('regression', {'lines': [[-30781, False], [-35543, True], [34368, True]], 'rate_bp': 50}, [-31956, -6, -31962]), ('regression', {'lines': [[27, True], [-11860, True], [-39505, True], [21922, True]], 'rate_bp': 825}, [-29416, -2426, -31842]), ('partial-repair probe', {'lines': [[30278, True], [-25624, False], [18105, True]], 'rate_bp': 50}, [22759, 242, 23001]), ('partial-repair probe', {'lines': [[-25232, False], [10, True]], 'rate_bp': 825}, [-25222, 1, -25221]), ('normal control', {'lines': [[7, True]], 'rate_bp': 725}, [7, 1, 8]), ('normal control', {'lines': [[49780, False], [72791, False]], 'rate_bp': 725}, [122571, 0, 122571]), ('normal control', {'lines': [[66301, True], [16, True], [10, False], [37, False]], 'rate_bp': 725}, [66364, 4808, 71172]), ('normal control', {'lines': [[91, False]], 'rate_bp': 12}, [91, 0, 91])], [('regression', {'lines': [[3, True], [-21770, True], [51, True], [-55198, False], [12289, False]], 'rate_bp': 825}, [-64625, -1792, -66417]), ('regression', {'lines': [[-17245, True], [79270, True], [25, True], [-36068, True]], 'rate_bp': 720}, [25982, 1870, 27852]), ('partial-repair probe', {'lines': [[-25232, False], [10, True]], 'rate_bp': 825}, [-25222, 1, -25221]), ('partial-repair probe', {'lines': [[-59554, False], [89, True], [-10465, False], [69423, False]], 'rate_bp': 1000}, [-507, 9, -498]), ('normal control', {'lines': [[25, True]], 'rate_bp': 825}, [25, 2, 27]), ('normal control', {'lines': [[19129, False]], 'rate_bp': 725}, [19129, 0, 19129]), ('normal control', {'lines': [[84, False]], 'rate_bp': 1355}, [84, 0, 84]), ('normal control', {'lines': [[35, True]], 'rate_bp': 50}, [35, 0, 35])], [('regression', {'lines': [[-45541, False], [-19439, False], [-33085, True], [-32736, True], [-53476, False]], 'rate_bp': 2000}, [-184277, -13164, -197441]), ('regression', {'lines': [[74, True], [-48741, True], [16317, True], [-6432, True]], 'rate_bp': 1000}, [-38782, -3878, -42660]), ('partial-repair probe', {'lines': [[-59554, False], [89, True], [-10465, False], [69423, False]], 'rate_bp': 1000}, [-507, 9, -498]), ('partial-repair probe', {'lines': [[-25891, False]], 'rate_bp': 50}, [-25891, 0, -25891]), ('normal control', {'lines': [[95, True]], 'rate_bp': 2000}, [95, 19, 114]), ('normal control', {'lines': [[30480, True], [19, True], [32317, True]], 'rate_bp': 2002}, [62816, 12576, 75392]), ('normal control', {'lines': [[1, False]], 'rate_bp': 50}, [1, 0, 1]), ('normal control', {'lines': [[95, True], [43198, False], [26, True], [47914, True], [10383, True]], 'rate_bp': 1897}, [101616, 11082, 112698])]]
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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| regression 0 | [97691, 733, 98424] | [97691, 579, 98270] | Failed |
| regression 1 | [-19268, 24, -19244] | [-19268, -3854, -23122] | Failed |
| partial-repair probe 2 | [-51735, 0, -51735] | [-51735, 0, -51735] | Passed |
| partial-repair probe 3 | [81318, 0, 81318] | [81318, 0, 81318] | Passed |
| normal control 4 | [70, 6, 76] | [70, 6, 76] | Passed |
| normal control 5 | [14634, 432, 15066] | [14634, 432, 15066] | Passed |
| normal control 6 | [78656, 11783, 90439] | [78656, 11783, 90439] | Passed |
| normal control 7 | [151801, 12523, 164324] | [151801, 12523, 164324] | Passed |
SHA-256 / edea3153b3616a084733e511edf358d8ef9bc41e3e04752be34145355e9467f2
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(x):
parts = []
for amt, taxable in x['lines']:
if taxable or amt < 0:
parts.append(amt * x['rate_bp'])
def hr(n):
t = (abs(n) * 2 + 10000) // 20000
return t if n >= 0 else -t
tax = sum(hr(n) for n in parts)
sub = sum(a for a, t in x['lines'])
return [sub, tax, sub + tax]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'lines': [[-30768, True], [88008, True], [58540, True], [-18089, False]], 'rate_bp': 50}, [97691, 579, 98270]), ('regression', {'lines': [[53, True], [-19388, True], [67, True]], 'rate_bp': 2000}, [-19268, -3854, -23122]), ('partial-repair probe', {'lines': [[-51735, False]], 'rate_bp': 2267}, [-51735, 0, -51735]), ('partial-repair probe', {'lines': [[-42950, False], [83094, False], [74700, False], [-33526, False]], 'rate_bp': 725}, [81318, 0, 81318]), ('normal control', {'lines': [[70, True]], 'rate_bp': 825}, [70, 6, 76]), ('normal control', {'lines': [[52, True], [19, False], [14472, True], [91, False]], 'rate_bp': 297}, [14634, 432, 15066]), ('normal control', {'lines': [[78656, True]], 'rate_bp': 1498}, [78656, 11783, 90439]), ('normal control', {'lines': [[74, True], [81059, True], [70668, True]], 'rate_bp': 825}, [151801, 12523, 164324])], [('regression', {'lines': [[-12837, True], [-41474, True], [88408, True], [-5186, False]], 'rate_bp': 1738}, [28911, 5926, 34837]), ('regression', {'lines': [[53, True], [-19388, True], [67, True]], 'rate_bp': 2000}, [-19268, -3854, -23122]), ('partial-repair probe', {'lines': [[-42950, False], [83094, False], [74700, False], [-33526, False]], 'rate_bp': 725}, [81318, 0, 81318]), ('partial-repair probe', {'lines': [[30278, True], [-25624, False], [18105, True]], 'rate_bp': 50}, [22759, 242, 23001]), ('normal control', {'lines': [[1785, False]], 'rate_bp': 1510}, [1785, 0, 1785]), ('normal control', {'lines': [[11, True], [30948, False]], 'rate_bp': 1000}, [30959, 1, 30960]), ('normal control', {'lines': [[20, False]], 'rate_bp': 50}, [20, 0, 20]), ('normal control', {'lines': [[13, True]], 'rate_bp': 825}, [13, 1, 14])], [('regression', {'lines': [[-30781, False], [-35543, True], [34368, True]], 'rate_bp': 50}, [-31956, -6, -31962]), ('regression', {'lines': [[27, True], [-11860, True], [-39505, True], [21922, True]], 'rate_bp': 825}, [-29416, -2426, -31842]), ('partial-repair probe', {'lines': [[30278, True], [-25624, False], [18105, True]], 'rate_bp': 50}, [22759, 242, 23001]), ('partial-repair probe', {'lines': [[-25232, False], [10, True]], 'rate_bp': 825}, [-25222, 1, -25221]), ('normal control', {'lines': [[7, True]], 'rate_bp': 725}, [7, 1, 8]), ('normal control', {'lines': [[49780, False], [72791, False]], 'rate_bp': 725}, [122571, 0, 122571]), ('normal control', {'lines': [[66301, True], [16, True], [10, False], [37, False]], 'rate_bp': 725}, [66364, 4808, 71172]), ('normal control', {'lines': [[91, False]], 'rate_bp': 12}, [91, 0, 91])], [('regression', {'lines': [[3, True], [-21770, True], [51, True], [-55198, False], [12289, False]], 'rate_bp': 825}, [-64625, -1792, -66417]), ('regression', {'lines': [[-17245, True], [79270, True], [25, True], [-36068, True]], 'rate_bp': 720}, [25982, 1870, 27852]), ('partial-repair probe', {'lines': [[-25232, False], [10, True]], 'rate_bp': 825}, [-25222, 1, -25221]), ('partial-repair probe', {'lines': [[-59554, False], [89, True], [-10465, False], [69423, False]], 'rate_bp': 1000}, [-507, 9, -498]), ('normal control', {'lines': [[25, True]], 'rate_bp': 825}, [25, 2, 27]), ('normal control', {'lines': [[19129, False]], 'rate_bp': 725}, [19129, 0, 19129]), ('normal control', {'lines': [[84, False]], 'rate_bp': 1355}, [84, 0, 84]), ('normal control', {'lines': [[35, True]], 'rate_bp': 50}, [35, 0, 35])], [('regression', {'lines': [[-45541, False], [-19439, False], [-33085, True], [-32736, True], [-53476, False]], 'rate_bp': 2000}, [-184277, -13164, -197441]), ('regression', {'lines': [[74, True], [-48741, True], [16317, True], [-6432, True]], 'rate_bp': 1000}, [-38782, -3878, -42660]), ('partial-repair probe', {'lines': [[-59554, False], [89, True], [-10465, False], [69423, False]], 'rate_bp': 1000}, [-507, 9, -498]), ('partial-repair probe', {'lines': [[-25891, False]], 'rate_bp': 50}, [-25891, 0, -25891]), ('normal control', {'lines': [[95, True]], 'rate_bp': 2000}, [95, 19, 114]), ('normal control', {'lines': [[30480, True], [19, True], [32317, True]], 'rate_bp': 2002}, [62816, 12576, 75392]), ('normal control', {'lines': [[1, False]], 'rate_bp': 50}, [1, 0, 1]), ('normal control', {'lines': [[95, True], [43198, False], [26, True], [47914, True], [10383, True]], 'rate_bp': 1897}, [101616, 11082, 112698])]]
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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| regression 0 | [97691, 489, 98180] | [97691, 579, 98270] | Failed |
| regression 1 | [-19268, -3854, -23122] | [-19268, -3854, -23122] | Passed |
| partial-repair probe 2 | [-51735, -11728, -63463] | [-51735, 0, -51735] | Failed |
| partial-repair probe 3 | [81318, -5545, 75773] | [81318, 0, 81318] | Failed |
| normal control 4 | [70, 6, 76] | [70, 6, 76] | Passed |
| normal control 5 | [14634, 432, 15066] | [14634, 432, 15066] | Passed |
| normal control 6 | [78656, 11783, 90439] | [78656, 11783, 90439] | Passed |
| normal control 7 | [151801, 12523, 164324] | [151801, 12523, 164324] | Passed |
SHA-256 / 98840712827ae55daf081ad0739f1dc27b6c6cf8e979aac5d4a4a2c3f0a0943b
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(x):
parts = []
for amt, taxable in x['lines']:
if taxable:
parts.append(amt * x['rate_bp'])
def hr(n):
t = (abs(n) * 2 + 10000) // 20000
return t if n >= 0 else -t
tax = sum(hr(n) for n in parts)
sub = sum(a for a, t in x['lines'])
return [sub, tax, sub + tax]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'lines': [[-30768, True], [88008, True], [58540, True], [-18089, False]], 'rate_bp': 50}, [97691, 579, 98270]), ('regression', {'lines': [[53, True], [-19388, True], [67, True]], 'rate_bp': 2000}, [-19268, -3854, -23122]), ('partial-repair probe', {'lines': [[-51735, False]], 'rate_bp': 2267}, [-51735, 0, -51735]), ('partial-repair probe', {'lines': [[-42950, False], [83094, False], [74700, False], [-33526, False]], 'rate_bp': 725}, [81318, 0, 81318]), ('normal control', {'lines': [[70, True]], 'rate_bp': 825}, [70, 6, 76]), ('normal control', {'lines': [[52, True], [19, False], [14472, True], [91, False]], 'rate_bp': 297}, [14634, 432, 15066]), ('normal control', {'lines': [[78656, True]], 'rate_bp': 1498}, [78656, 11783, 90439]), ('normal control', {'lines': [[74, True], [81059, True], [70668, True]], 'rate_bp': 825}, [151801, 12523, 164324])], [('regression', {'lines': [[-12837, True], [-41474, True], [88408, True], [-5186, False]], 'rate_bp': 1738}, [28911, 5926, 34837]), ('regression', {'lines': [[53, True], [-19388, True], [67, True]], 'rate_bp': 2000}, [-19268, -3854, -23122]), ('partial-repair probe', {'lines': [[-42950, False], [83094, False], [74700, False], [-33526, False]], 'rate_bp': 725}, [81318, 0, 81318]), ('partial-repair probe', {'lines': [[30278, True], [-25624, False], [18105, True]], 'rate_bp': 50}, [22759, 242, 23001]), ('normal control', {'lines': [[1785, False]], 'rate_bp': 1510}, [1785, 0, 1785]), ('normal control', {'lines': [[11, True], [30948, False]], 'rate_bp': 1000}, [30959, 1, 30960]), ('normal control', {'lines': [[20, False]], 'rate_bp': 50}, [20, 0, 20]), ('normal control', {'lines': [[13, True]], 'rate_bp': 825}, [13, 1, 14])], [('regression', {'lines': [[-30781, False], [-35543, True], [34368, True]], 'rate_bp': 50}, [-31956, -6, -31962]), ('regression', {'lines': [[27, True], [-11860, True], [-39505, True], [21922, True]], 'rate_bp': 825}, [-29416, -2426, -31842]), ('partial-repair probe', {'lines': [[30278, True], [-25624, False], [18105, True]], 'rate_bp': 50}, [22759, 242, 23001]), ('partial-repair probe', {'lines': [[-25232, False], [10, True]], 'rate_bp': 825}, [-25222, 1, -25221]), ('normal control', {'lines': [[7, True]], 'rate_bp': 725}, [7, 1, 8]), ('normal control', {'lines': [[49780, False], [72791, False]], 'rate_bp': 725}, [122571, 0, 122571]), ('normal control', {'lines': [[66301, True], [16, True], [10, False], [37, False]], 'rate_bp': 725}, [66364, 4808, 71172]), ('normal control', {'lines': [[91, False]], 'rate_bp': 12}, [91, 0, 91])], [('regression', {'lines': [[3, True], [-21770, True], [51, True], [-55198, False], [12289, False]], 'rate_bp': 825}, [-64625, -1792, -66417]), ('regression', {'lines': [[-17245, True], [79270, True], [25, True], [-36068, True]], 'rate_bp': 720}, [25982, 1870, 27852]), ('partial-repair probe', {'lines': [[-25232, False], [10, True]], 'rate_bp': 825}, [-25222, 1, -25221]), ('partial-repair probe', {'lines': [[-59554, False], [89, True], [-10465, False], [69423, False]], 'rate_bp': 1000}, [-507, 9, -498]), ('normal control', {'lines': [[25, True]], 'rate_bp': 825}, [25, 2, 27]), ('normal control', {'lines': [[19129, False]], 'rate_bp': 725}, [19129, 0, 19129]), ('normal control', {'lines': [[84, False]], 'rate_bp': 1355}, [84, 0, 84]), ('normal control', {'lines': [[35, True]], 'rate_bp': 50}, [35, 0, 35])], [('regression', {'lines': [[-45541, False], [-19439, False], [-33085, True], [-32736, True], [-53476, False]], 'rate_bp': 2000}, [-184277, -13164, -197441]), ('regression', {'lines': [[74, True], [-48741, True], [16317, True], [-6432, True]], 'rate_bp': 1000}, [-38782, -3878, -42660]), ('partial-repair probe', {'lines': [[-59554, False], [89, True], [-10465, False], [69423, False]], 'rate_bp': 1000}, [-507, 9, -498]), ('partial-repair probe', {'lines': [[-25891, False]], 'rate_bp': 50}, [-25891, 0, -25891]), ('normal control', {'lines': [[95, True]], 'rate_bp': 2000}, [95, 19, 114]), ('normal control', {'lines': [[30480, True], [19, True], [32317, True]], 'rate_bp': 2002}, [62816, 12576, 75392]), ('normal control', {'lines': [[1, False]], 'rate_bp': 50}, [1, 0, 1]), ('normal control', {'lines': [[95, True], [43198, False], [26, True], [47914, True], [10383, True]], 'rate_bp': 1897}, [101616, 11082, 112698])]]
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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| regression 0 | [97691, 579, 98270] | [97691, 579, 98270] | Passed |
| regression 1 | [-19268, -3854, -23122] | [-19268, -3854, -23122] | Passed |
| partial-repair probe 2 | [-51735, 0, -51735] | [-51735, 0, -51735] | Passed |
| partial-repair probe 3 | [81318, 0, 81318] | [81318, 0, 81318] | Passed |
| normal control 4 | [70, 6, 76] | [70, 6, 76] | Passed |
| normal control 5 | [14634, 432, 15066] | [14634, 432, 15066] | Passed |
| normal control 6 | [78656, 11783, 90439] | [78656, 11783, 90439] | Passed |
| normal control 7 | [151801, 12523, 164324] | [151801, 12523, 164324] | Passed |
SHA-256 / 370d98e60be45db47c0d1f1ae0e96fc36c690a3be5b641e38b728e4e2ed8c622
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:37.195247+00:00.
Case digest / 5585828f6082b8d5ac68499d3db5f5fe9163b0181a91fbc7234de06d309756d1