FA-59536 / Subscription proration billing / Open access
Sales tax on proration credit and debit lines: subtotal composition · case 01
Non-taxable lines disappear from the invoice subtotal.
ROOT CAUSE
The subtotal only sums taxable lines.
VERIFIED REPAIR
Restore the contract rule at the subtotal composition step: use `sub = sum(a for a, t in x['lines'])`.
Unsuccessful approach: The attempt sums charges but drops credit lines from the subtotal.
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:
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'] if t)
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': [[-51735, False]], 'rate_bp': 2267}, [-51735, 0, -51735]), ('partial-repair probe', {'lines': [[53, True], [-19388, True], [67, True]], 'rate_bp': 2000}, [-19268, -3854, -23122]), ('partial-repair probe', {'lines': [[27, True], [-11860, True], [-39505, True], [21922, True]], 'rate_bp': 825}, [-29416, -2426, -31842]), ('normal control', {'lines': [[70, True]], 'rate_bp': 825}, [70, 6, 76]), ('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]), ('normal control', {'lines': [[13, True]], 'rate_bp': 825}, [13, 1, 14])], [('regression', {'lines': [[-51735, False]], 'rate_bp': 2267}, [-51735, 0, -51735]), ('regression', {'lines': [[-42950, False], [83094, False], [74700, False], [-33526, False]], 'rate_bp': 725}, [81318, 0, 81318]), ('partial-repair probe', {'lines': [[53, True], [-19388, True], [67, True]], 'rate_bp': 2000}, [-19268, -3854, -23122]), ('partial-repair probe', {'lines': [[27, True], [-11860, True], [-39505, True], [21922, True]], 'rate_bp': 825}, [-29416, -2426, -31842]), ('normal control', {'lines': [[7, True]], 'rate_bp': 725}, [7, 1, 8]), ('normal control', {'lines': [[25, True]], 'rate_bp': 825}, [25, 2, 27]), ('normal control', {'lines': [[35, True]], 'rate_bp': 50}, [35, 0, 35]), ('normal control', {'lines': [[95, True]], 'rate_bp': 2000}, [95, 19, 114])], [('regression', {'lines': [[-42950, False], [83094, False], [74700, False], [-33526, False]], 'rate_bp': 725}, [81318, 0, 81318]), ('regression', {'lines': [[-12837, True], [-41474, True], [88408, True], [-5186, False]], 'rate_bp': 1738}, [28911, 5926, 34837]), ('partial-repair probe', {'lines': [[-17245, True], [79270, True], [25, True], [-36068, True]], 'rate_bp': 720}, [25982, 1870, 27852]), ('partial-repair probe', {'lines': [[74, True], [-48741, True], [16317, True], [-6432, True]], 'rate_bp': 1000}, [-38782, -3878, -42660]), ('normal control', {'lines': [[30480, True], [19, True], [32317, True]], 'rate_bp': 2002}, [62816, 12576, 75392]), ('normal control', {'lines': [[80389, True]], 'rate_bp': 725}, [80389, 5828, 86217]), ('normal control', {'lines': [[54, True], [71675, True]], 'rate_bp': 825}, [71729, 5917, 77646]), ('normal control', {'lines': [[5, True], [1, True], [7132, True]], 'rate_bp': 1000}, [7138, 714, 7852])], [('regression', {'lines': [[-12837, True], [-41474, True], [88408, True], [-5186, False]], 'rate_bp': 1738}, [28911, 5926, 34837]), ('regression', {'lines': [[30278, True], [-25624, False], [18105, True]], 'rate_bp': 50}, [22759, 242, 23001]), ('partial-repair probe', {'lines': [[74, True], [-48741, True], [16317, True], [-6432, True]], 'rate_bp': 1000}, [-38782, -3878, -42660]), ('partial-repair probe', {'lines': [[-7052, True]], 'rate_bp': 2000}, [-7052, -1410, -8462]), ('normal control', {'lines': [[32, True]], 'rate_bp': 725}, [32, 2, 34]), ('normal control', {'lines': [[79, True], [93, True]], 'rate_bp': 825}, [172, 15, 187]), ('normal control', {'lines': [[24815, True]], 'rate_bp': 1152}, [24815, 2859, 27674]), ('normal control', {'lines': [[6, True]], 'rate_bp': 825}, [6, 0, 6])], [('regression', {'lines': [[30278, True], [-25624, False], [18105, True]], 'rate_bp': 50}, [22759, 242, 23001]), ('regression', {'lines': [[73474, True], [48, False], [70693, False], [-3471, True]], 'rate_bp': 725}, [140744, 5075, 145819]), ('partial-repair probe', {'lines': [[-12837, True], [-41474, True], [88408, True], [-5186, False]], 'rate_bp': 1738}, [28911, 5926, 34837]), ('partial-repair probe', {'lines': [[49804, True], [5609, True], [29, True], [-28832, True]], 'rate_bp': 725}, [26610, 1930, 28540]), ('normal control', {'lines': [[54, True]], 'rate_bp': 725}, [54, 4, 58]), ('normal control', {'lines': [[78316, True], [34, True]], 'rate_bp': 2000}, [78350, 15670, 94020]), ('normal control', {'lines': [[79726, True]], 'rate_bp': 2000}, [79726, 15945, 95671]), ('normal control', {'lines': [[58, True], [26, True]], 'rate_bp': 1140}, [84, 10, 94])]]
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 | [115780, 579, 116359] | [97691, 579, 98270] | Failed |
| regression 1 | [0, 0, 0] | [-51735, 0, -51735] | Failed |
| partial-repair probe 2 | [-19268, -3854, -23122] | [-19268, -3854, -23122] | Passed |
| partial-repair probe 3 | [-29416, -2426, -31842] | [-29416, -2426, -31842] | Passed |
| normal control 4 | [70, 6, 76] | [70, 6, 76] | Passed |
| normal control 5 | [78656, 11783, 90439] | [78656, 11783, 90439] | Passed |
| normal control 6 | [151801, 12523, 164324] | [151801, 12523, 164324] | Passed |
| normal control 7 | [13, 1, 14] | [13, 1, 14] | Passed |
SHA-256 / a55a11cb62e93caf6837d0ad08e5c16ae681793b2f8f7075f65d82d368b8017b
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:
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'] if a > 0)
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': [[-51735, False]], 'rate_bp': 2267}, [-51735, 0, -51735]), ('partial-repair probe', {'lines': [[53, True], [-19388, True], [67, True]], 'rate_bp': 2000}, [-19268, -3854, -23122]), ('partial-repair probe', {'lines': [[27, True], [-11860, True], [-39505, True], [21922, True]], 'rate_bp': 825}, [-29416, -2426, -31842]), ('normal control', {'lines': [[70, True]], 'rate_bp': 825}, [70, 6, 76]), ('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]), ('normal control', {'lines': [[13, True]], 'rate_bp': 825}, [13, 1, 14])], [('regression', {'lines': [[-51735, False]], 'rate_bp': 2267}, [-51735, 0, -51735]), ('regression', {'lines': [[-42950, False], [83094, False], [74700, False], [-33526, False]], 'rate_bp': 725}, [81318, 0, 81318]), ('partial-repair probe', {'lines': [[53, True], [-19388, True], [67, True]], 'rate_bp': 2000}, [-19268, -3854, -23122]), ('partial-repair probe', {'lines': [[27, True], [-11860, True], [-39505, True], [21922, True]], 'rate_bp': 825}, [-29416, -2426, -31842]), ('normal control', {'lines': [[7, True]], 'rate_bp': 725}, [7, 1, 8]), ('normal control', {'lines': [[25, True]], 'rate_bp': 825}, [25, 2, 27]), ('normal control', {'lines': [[35, True]], 'rate_bp': 50}, [35, 0, 35]), ('normal control', {'lines': [[95, True]], 'rate_bp': 2000}, [95, 19, 114])], [('regression', {'lines': [[-42950, False], [83094, False], [74700, False], [-33526, False]], 'rate_bp': 725}, [81318, 0, 81318]), ('regression', {'lines': [[-12837, True], [-41474, True], [88408, True], [-5186, False]], 'rate_bp': 1738}, [28911, 5926, 34837]), ('partial-repair probe', {'lines': [[-17245, True], [79270, True], [25, True], [-36068, True]], 'rate_bp': 720}, [25982, 1870, 27852]), ('partial-repair probe', {'lines': [[74, True], [-48741, True], [16317, True], [-6432, True]], 'rate_bp': 1000}, [-38782, -3878, -42660]), ('normal control', {'lines': [[30480, True], [19, True], [32317, True]], 'rate_bp': 2002}, [62816, 12576, 75392]), ('normal control', {'lines': [[80389, True]], 'rate_bp': 725}, [80389, 5828, 86217]), ('normal control', {'lines': [[54, True], [71675, True]], 'rate_bp': 825}, [71729, 5917, 77646]), ('normal control', {'lines': [[5, True], [1, True], [7132, True]], 'rate_bp': 1000}, [7138, 714, 7852])], [('regression', {'lines': [[-12837, True], [-41474, True], [88408, True], [-5186, False]], 'rate_bp': 1738}, [28911, 5926, 34837]), ('regression', {'lines': [[30278, True], [-25624, False], [18105, True]], 'rate_bp': 50}, [22759, 242, 23001]), ('partial-repair probe', {'lines': [[74, True], [-48741, True], [16317, True], [-6432, True]], 'rate_bp': 1000}, [-38782, -3878, -42660]), ('partial-repair probe', {'lines': [[-7052, True]], 'rate_bp': 2000}, [-7052, -1410, -8462]), ('normal control', {'lines': [[32, True]], 'rate_bp': 725}, [32, 2, 34]), ('normal control', {'lines': [[79, True], [93, True]], 'rate_bp': 825}, [172, 15, 187]), ('normal control', {'lines': [[24815, True]], 'rate_bp': 1152}, [24815, 2859, 27674]), ('normal control', {'lines': [[6, True]], 'rate_bp': 825}, [6, 0, 6])], [('regression', {'lines': [[30278, True], [-25624, False], [18105, True]], 'rate_bp': 50}, [22759, 242, 23001]), ('regression', {'lines': [[73474, True], [48, False], [70693, False], [-3471, True]], 'rate_bp': 725}, [140744, 5075, 145819]), ('partial-repair probe', {'lines': [[-12837, True], [-41474, True], [88408, True], [-5186, False]], 'rate_bp': 1738}, [28911, 5926, 34837]), ('partial-repair probe', {'lines': [[49804, True], [5609, True], [29, True], [-28832, True]], 'rate_bp': 725}, [26610, 1930, 28540]), ('normal control', {'lines': [[54, True]], 'rate_bp': 725}, [54, 4, 58]), ('normal control', {'lines': [[78316, True], [34, True]], 'rate_bp': 2000}, [78350, 15670, 94020]), ('normal control', {'lines': [[79726, True]], 'rate_bp': 2000}, [79726, 15945, 95671]), ('normal control', {'lines': [[58, True], [26, True]], 'rate_bp': 1140}, [84, 10, 94])]]
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 | [146548, 579, 147127] | [97691, 579, 98270] | Failed |
| regression 1 | [0, 0, 0] | [-51735, 0, -51735] | Failed |
| partial-repair probe 2 | [120, -3854, -3734] | [-19268, -3854, -23122] | Failed |
| partial-repair probe 3 | [21949, -2426, 19523] | [-29416, -2426, -31842] | Failed |
| normal control 4 | [70, 6, 76] | [70, 6, 76] | Passed |
| normal control 5 | [78656, 11783, 90439] | [78656, 11783, 90439] | Passed |
| normal control 6 | [151801, 12523, 164324] | [151801, 12523, 164324] | Passed |
| normal control 7 | [13, 1, 14] | [13, 1, 14] | Passed |
SHA-256 / f50b90efc3351dd68671325c5cb1110f73aa307e4e704af94d4900bb510231fe
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': [[-51735, False]], 'rate_bp': 2267}, [-51735, 0, -51735]), ('partial-repair probe', {'lines': [[53, True], [-19388, True], [67, True]], 'rate_bp': 2000}, [-19268, -3854, -23122]), ('partial-repair probe', {'lines': [[27, True], [-11860, True], [-39505, True], [21922, True]], 'rate_bp': 825}, [-29416, -2426, -31842]), ('normal control', {'lines': [[70, True]], 'rate_bp': 825}, [70, 6, 76]), ('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]), ('normal control', {'lines': [[13, True]], 'rate_bp': 825}, [13, 1, 14])], [('regression', {'lines': [[-51735, False]], 'rate_bp': 2267}, [-51735, 0, -51735]), ('regression', {'lines': [[-42950, False], [83094, False], [74700, False], [-33526, False]], 'rate_bp': 725}, [81318, 0, 81318]), ('partial-repair probe', {'lines': [[53, True], [-19388, True], [67, True]], 'rate_bp': 2000}, [-19268, -3854, -23122]), ('partial-repair probe', {'lines': [[27, True], [-11860, True], [-39505, True], [21922, True]], 'rate_bp': 825}, [-29416, -2426, -31842]), ('normal control', {'lines': [[7, True]], 'rate_bp': 725}, [7, 1, 8]), ('normal control', {'lines': [[25, True]], 'rate_bp': 825}, [25, 2, 27]), ('normal control', {'lines': [[35, True]], 'rate_bp': 50}, [35, 0, 35]), ('normal control', {'lines': [[95, True]], 'rate_bp': 2000}, [95, 19, 114])], [('regression', {'lines': [[-42950, False], [83094, False], [74700, False], [-33526, False]], 'rate_bp': 725}, [81318, 0, 81318]), ('regression', {'lines': [[-12837, True], [-41474, True], [88408, True], [-5186, False]], 'rate_bp': 1738}, [28911, 5926, 34837]), ('partial-repair probe', {'lines': [[-17245, True], [79270, True], [25, True], [-36068, True]], 'rate_bp': 720}, [25982, 1870, 27852]), ('partial-repair probe', {'lines': [[74, True], [-48741, True], [16317, True], [-6432, True]], 'rate_bp': 1000}, [-38782, -3878, -42660]), ('normal control', {'lines': [[30480, True], [19, True], [32317, True]], 'rate_bp': 2002}, [62816, 12576, 75392]), ('normal control', {'lines': [[80389, True]], 'rate_bp': 725}, [80389, 5828, 86217]), ('normal control', {'lines': [[54, True], [71675, True]], 'rate_bp': 825}, [71729, 5917, 77646]), ('normal control', {'lines': [[5, True], [1, True], [7132, True]], 'rate_bp': 1000}, [7138, 714, 7852])], [('regression', {'lines': [[-12837, True], [-41474, True], [88408, True], [-5186, False]], 'rate_bp': 1738}, [28911, 5926, 34837]), ('regression', {'lines': [[30278, True], [-25624, False], [18105, True]], 'rate_bp': 50}, [22759, 242, 23001]), ('partial-repair probe', {'lines': [[74, True], [-48741, True], [16317, True], [-6432, True]], 'rate_bp': 1000}, [-38782, -3878, -42660]), ('partial-repair probe', {'lines': [[-7052, True]], 'rate_bp': 2000}, [-7052, -1410, -8462]), ('normal control', {'lines': [[32, True]], 'rate_bp': 725}, [32, 2, 34]), ('normal control', {'lines': [[79, True], [93, True]], 'rate_bp': 825}, [172, 15, 187]), ('normal control', {'lines': [[24815, True]], 'rate_bp': 1152}, [24815, 2859, 27674]), ('normal control', {'lines': [[6, True]], 'rate_bp': 825}, [6, 0, 6])], [('regression', {'lines': [[30278, True], [-25624, False], [18105, True]], 'rate_bp': 50}, [22759, 242, 23001]), ('regression', {'lines': [[73474, True], [48, False], [70693, False], [-3471, True]], 'rate_bp': 725}, [140744, 5075, 145819]), ('partial-repair probe', {'lines': [[-12837, True], [-41474, True], [88408, True], [-5186, False]], 'rate_bp': 1738}, [28911, 5926, 34837]), ('partial-repair probe', {'lines': [[49804, True], [5609, True], [29, True], [-28832, True]], 'rate_bp': 725}, [26610, 1930, 28540]), ('normal control', {'lines': [[54, True]], 'rate_bp': 725}, [54, 4, 58]), ('normal control', {'lines': [[78316, True], [34, True]], 'rate_bp': 2000}, [78350, 15670, 94020]), ('normal control', {'lines': [[79726, True]], 'rate_bp': 2000}, [79726, 15945, 95671]), ('normal control', {'lines': [[58, True], [26, True]], 'rate_bp': 1140}, [84, 10, 94])]]
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 | [-51735, 0, -51735] | [-51735, 0, -51735] | Passed |
| partial-repair probe 2 | [-19268, -3854, -23122] | [-19268, -3854, -23122] | Passed |
| partial-repair probe 3 | [-29416, -2426, -31842] | [-29416, -2426, -31842] | Passed |
| normal control 4 | [70, 6, 76] | [70, 6, 76] | Passed |
| normal control 5 | [78656, 11783, 90439] | [78656, 11783, 90439] | Passed |
| normal control 6 | [151801, 12523, 164324] | [151801, 12523, 164324] | Passed |
| normal control 7 | [13, 1, 14] | [13, 1, 14] | Passed |
SHA-256 / b005cf3e1de3f362560e037291ebe956dbc0642ac0abe9a7c0b2e5202630f286
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.219579+00:00.
Case digest / 203e0b40cf0408b4c456e5da3eb8ef928f6ead3dfb921805f9246e26fa0e6054