FA-59531 / Subscription proration billing / Open access
Sales tax on proration credit and debit lines: per-line tax rounding · case 01
Invoice tax differs by a cent from the sum of the per-line tax amounts shown.
ROOT CAUSE
Tax is rounded once on the invoice total instead of per line.
VERIFIED REPAIR
Restore the contract rule at the per-line tax rounding step: use `tax = sum(hr(n) for n in parts)`.
Unsuccessful approach: The attempt computes per line but floors, rounding negative lines away and positive lines down.
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 = hr(sum(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': [[27, True], [-11860, True], [-39505, True], [21922, True]], 'rate_bp': 825}, [-29416, -2426, -31842]), ('regression', {'lines': [[-17245, True], [79270, True], [25, True], [-36068, True]], 'rate_bp': 720}, [25982, 1870, 27852]), ('partial-repair probe', {'lines': [[-30768, True], [88008, True], [58540, True], [-18089, False]], 'rate_bp': 50}, [97691, 579, 98270]), ('partial-repair probe', {'lines': [[53, True], [-19388, True], [67, True]], 'rate_bp': 2000}, [-19268, -3854, -23122]), ('normal control', {'lines': [[-51735, False]], 'rate_bp': 2267}, [-51735, 0, -51735]), ('normal control', {'lines': [[-42950, False], [83094, False], [74700, False], [-33526, False]], 'rate_bp': 725}, [81318, 0, 81318]), ('normal control', {'lines': [[1785, False]], 'rate_bp': 1510}, [1785, 0, 1785]), ('normal control', {'lines': [[11, True], [30948, False]], 'rate_bp': 1000}, [30959, 1, 30960])], [('regression', {'lines': [[-17245, True], [79270, True], [25, True], [-36068, True]], 'rate_bp': 720}, [25982, 1870, 27852]), ('regression', {'lines': [[49804, True], [5609, True], [29, True], [-28832, True]], 'rate_bp': 725}, [26610, 1930, 28540]), ('partial-repair probe', {'lines': [[27, True], [-11860, True], [-39505, True], [21922, True]], 'rate_bp': 825}, [-29416, -2426, -31842]), ('partial-repair probe', {'lines': [[74, True], [-48741, True], [16317, True], [-6432, True]], 'rate_bp': 1000}, [-38782, -3878, -42660]), ('normal control', {'lines': [[-25891, False]], 'rate_bp': 50}, [-25891, 0, -25891]), ('normal control', {'lines': [[20, False]], 'rate_bp': 50}, [20, 0, 20]), ('normal control', {'lines': [[13, True]], 'rate_bp': 825}, [13, 1, 14]), ('normal control', {'lines': [[49780, False], [72791, False]], 'rate_bp': 725}, [122571, 0, 122571])], [('regression', {'lines': [[49804, True], [5609, True], [29, True], [-28832, True]], 'rate_bp': 725}, [26610, 1930, 28540]), ('regression', {'lines': [[52, True], [19, False], [14472, True], [91, False]], 'rate_bp': 297}, [14634, 432, 15066]), ('partial-repair probe', {'lines': [[74, True], [-48741, True], [16317, True], [-6432, True]], 'rate_bp': 1000}, [-38782, -3878, -42660]), ('partial-repair probe', {'lines': [[70, True]], 'rate_bp': 825}, [70, 6, 76]), ('normal control', {'lines': [[91, False]], 'rate_bp': 12}, [91, 0, 91]), ('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])], [('regression', {'lines': [[52, True], [19, False], [14472, True], [91, False]], 'rate_bp': 297}, [14634, 432, 15066]), ('regression', {'lines': [[-46622, True], [77, True], [83716, False], [46, True], [37, True]], 'rate_bp': 1000}, [37254, -4645, 32609]), ('partial-repair probe', {'lines': [[-7052, True]], 'rate_bp': 2000}, [-7052, -1410, -8462]), ('partial-repair probe', {'lines': [[-12837, True], [-41474, True], [88408, True], [-5186, False]], 'rate_bp': 1738}, [28911, 5926, 34837]), ('normal control', {'lines': [[35, True]], 'rate_bp': 50}, [35, 0, 35]), ('normal control', {'lines': [[-17532, True]], 'rate_bp': 50}, [-17532, -88, -17620]), ('normal control', {'lines': [[95, True]], 'rate_bp': 2000}, [95, 19, 114]), ('normal control', {'lines': [[1, False]], 'rate_bp': 50}, [1, 0, 1])], [('regression', {'lines': [[-46622, True], [77, True], [83716, False], [46, True], [37, True]], 'rate_bp': 1000}, [37254, -4645, 32609]), ('regression', {'lines': [[74, True], [81059, True], [70668, True]], 'rate_bp': 825}, [151801, 12523, 164324]), ('partial-repair probe', {'lines': [[30278, True], [-25624, False], [18105, True]], 'rate_bp': 50}, [22759, 242, 23001]), ('partial-repair probe', {'lines': [[73474, True], [48, False], [70693, False], [-3471, True]], 'rate_bp': 725}, [140744, 5075, 145819]), ('normal control', {'lines': [[80389, True]], 'rate_bp': 725}, [80389, 5828, 86217]), ('normal control', {'lines': [[19, False], [1, True], [-36175, False], [25, True]], 'rate_bp': 2000}, [-36130, 5, -36125]), ('normal control', {'lines': [[-28065, False], [42, False]], 'rate_bp': 725}, [-28023, 0, -28023]), ('normal control', {'lines': [[6941, True], [925, False]], 'rate_bp': 725}, [7866, 503, 8369])]]
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 | [-29416, -2427, -31843] | [-29416, -2426, -31842] | Failed |
| regression 1 | [25982, 1871, 27853] | [25982, 1870, 27852] | Failed |
| partial-repair probe 2 | [97691, 579, 98270] | [97691, 579, 98270] | Passed |
| partial-repair probe 3 | [-19268, -3854, -23122] | [-19268, -3854, -23122] | Passed |
| normal control 4 | [-51735, 0, -51735] | [-51735, 0, -51735] | Passed |
| normal control 5 | [81318, 0, 81318] | [81318, 0, 81318] | Passed |
| normal control 6 | [1785, 0, 1785] | [1785, 0, 1785] | Passed |
| normal control 7 | [30959, 1, 30960] | [30959, 1, 30960] | Passed |
SHA-256 / 4fc6a3398e7952e3adcfd05c1843e951a1dc5f5a28a23a00f79b646572856cbe
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(n // 10000 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': [[27, True], [-11860, True], [-39505, True], [21922, True]], 'rate_bp': 825}, [-29416, -2426, -31842]), ('regression', {'lines': [[-17245, True], [79270, True], [25, True], [-36068, True]], 'rate_bp': 720}, [25982, 1870, 27852]), ('partial-repair probe', {'lines': [[-30768, True], [88008, True], [58540, True], [-18089, False]], 'rate_bp': 50}, [97691, 579, 98270]), ('partial-repair probe', {'lines': [[53, True], [-19388, True], [67, True]], 'rate_bp': 2000}, [-19268, -3854, -23122]), ('normal control', {'lines': [[-51735, False]], 'rate_bp': 2267}, [-51735, 0, -51735]), ('normal control', {'lines': [[-42950, False], [83094, False], [74700, False], [-33526, False]], 'rate_bp': 725}, [81318, 0, 81318]), ('normal control', {'lines': [[1785, False]], 'rate_bp': 1510}, [1785, 0, 1785]), ('normal control', {'lines': [[11, True], [30948, False]], 'rate_bp': 1000}, [30959, 1, 30960])], [('regression', {'lines': [[-17245, True], [79270, True], [25, True], [-36068, True]], 'rate_bp': 720}, [25982, 1870, 27852]), ('regression', {'lines': [[49804, True], [5609, True], [29, True], [-28832, True]], 'rate_bp': 725}, [26610, 1930, 28540]), ('partial-repair probe', {'lines': [[27, True], [-11860, True], [-39505, True], [21922, True]], 'rate_bp': 825}, [-29416, -2426, -31842]), ('partial-repair probe', {'lines': [[74, True], [-48741, True], [16317, True], [-6432, True]], 'rate_bp': 1000}, [-38782, -3878, -42660]), ('normal control', {'lines': [[-25891, False]], 'rate_bp': 50}, [-25891, 0, -25891]), ('normal control', {'lines': [[20, False]], 'rate_bp': 50}, [20, 0, 20]), ('normal control', {'lines': [[13, True]], 'rate_bp': 825}, [13, 1, 14]), ('normal control', {'lines': [[49780, False], [72791, False]], 'rate_bp': 725}, [122571, 0, 122571])], [('regression', {'lines': [[49804, True], [5609, True], [29, True], [-28832, True]], 'rate_bp': 725}, [26610, 1930, 28540]), ('regression', {'lines': [[52, True], [19, False], [14472, True], [91, False]], 'rate_bp': 297}, [14634, 432, 15066]), ('partial-repair probe', {'lines': [[74, True], [-48741, True], [16317, True], [-6432, True]], 'rate_bp': 1000}, [-38782, -3878, -42660]), ('partial-repair probe', {'lines': [[70, True]], 'rate_bp': 825}, [70, 6, 76]), ('normal control', {'lines': [[91, False]], 'rate_bp': 12}, [91, 0, 91]), ('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])], [('regression', {'lines': [[52, True], [19, False], [14472, True], [91, False]], 'rate_bp': 297}, [14634, 432, 15066]), ('regression', {'lines': [[-46622, True], [77, True], [83716, False], [46, True], [37, True]], 'rate_bp': 1000}, [37254, -4645, 32609]), ('partial-repair probe', {'lines': [[-7052, True]], 'rate_bp': 2000}, [-7052, -1410, -8462]), ('partial-repair probe', {'lines': [[-12837, True], [-41474, True], [88408, True], [-5186, False]], 'rate_bp': 1738}, [28911, 5926, 34837]), ('normal control', {'lines': [[35, True]], 'rate_bp': 50}, [35, 0, 35]), ('normal control', {'lines': [[-17532, True]], 'rate_bp': 50}, [-17532, -88, -17620]), ('normal control', {'lines': [[95, True]], 'rate_bp': 2000}, [95, 19, 114]), ('normal control', {'lines': [[1, False]], 'rate_bp': 50}, [1, 0, 1])], [('regression', {'lines': [[-46622, True], [77, True], [83716, False], [46, True], [37, True]], 'rate_bp': 1000}, [37254, -4645, 32609]), ('regression', {'lines': [[74, True], [81059, True], [70668, True]], 'rate_bp': 825}, [151801, 12523, 164324]), ('partial-repair probe', {'lines': [[30278, True], [-25624, False], [18105, True]], 'rate_bp': 50}, [22759, 242, 23001]), ('partial-repair probe', {'lines': [[73474, True], [48, False], [70693, False], [-3471, True]], 'rate_bp': 725}, [140744, 5075, 145819]), ('normal control', {'lines': [[80389, True]], 'rate_bp': 725}, [80389, 5828, 86217]), ('normal control', {'lines': [[19, False], [1, True], [-36175, False], [25, True]], 'rate_bp': 2000}, [-36130, 5, -36125]), ('normal control', {'lines': [[-28065, False], [42, False]], 'rate_bp': 725}, [-28023, 0, -28023]), ('normal control', {'lines': [[6941, True], [925, False]], 'rate_bp': 725}, [7866, 503, 8369])]]
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 | [-29416, -2429, -31845] | [-29416, -2426, -31842] | Failed |
| regression 1 | [25982, 1869, 27851] | [25982, 1870, 27852] | Failed |
| partial-repair probe 2 | [97691, 578, 98269] | [97691, 579, 98270] | Failed |
| partial-repair probe 3 | [-19268, -3855, -23123] | [-19268, -3854, -23122] | Failed |
| normal control 4 | [-51735, 0, -51735] | [-51735, 0, -51735] | Passed |
| normal control 5 | [81318, 0, 81318] | [81318, 0, 81318] | Passed |
| normal control 6 | [1785, 0, 1785] | [1785, 0, 1785] | Passed |
| normal control 7 | [30959, 1, 30960] | [30959, 1, 30960] | Passed |
SHA-256 / 1f4078638176354e2b1cf09a4e3080d2392a1893770e2db1e393695187017b61
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': [[27, True], [-11860, True], [-39505, True], [21922, True]], 'rate_bp': 825}, [-29416, -2426, -31842]), ('regression', {'lines': [[-17245, True], [79270, True], [25, True], [-36068, True]], 'rate_bp': 720}, [25982, 1870, 27852]), ('partial-repair probe', {'lines': [[-30768, True], [88008, True], [58540, True], [-18089, False]], 'rate_bp': 50}, [97691, 579, 98270]), ('partial-repair probe', {'lines': [[53, True], [-19388, True], [67, True]], 'rate_bp': 2000}, [-19268, -3854, -23122]), ('normal control', {'lines': [[-51735, False]], 'rate_bp': 2267}, [-51735, 0, -51735]), ('normal control', {'lines': [[-42950, False], [83094, False], [74700, False], [-33526, False]], 'rate_bp': 725}, [81318, 0, 81318]), ('normal control', {'lines': [[1785, False]], 'rate_bp': 1510}, [1785, 0, 1785]), ('normal control', {'lines': [[11, True], [30948, False]], 'rate_bp': 1000}, [30959, 1, 30960])], [('regression', {'lines': [[-17245, True], [79270, True], [25, True], [-36068, True]], 'rate_bp': 720}, [25982, 1870, 27852]), ('regression', {'lines': [[49804, True], [5609, True], [29, True], [-28832, True]], 'rate_bp': 725}, [26610, 1930, 28540]), ('partial-repair probe', {'lines': [[27, True], [-11860, True], [-39505, True], [21922, True]], 'rate_bp': 825}, [-29416, -2426, -31842]), ('partial-repair probe', {'lines': [[74, True], [-48741, True], [16317, True], [-6432, True]], 'rate_bp': 1000}, [-38782, -3878, -42660]), ('normal control', {'lines': [[-25891, False]], 'rate_bp': 50}, [-25891, 0, -25891]), ('normal control', {'lines': [[20, False]], 'rate_bp': 50}, [20, 0, 20]), ('normal control', {'lines': [[13, True]], 'rate_bp': 825}, [13, 1, 14]), ('normal control', {'lines': [[49780, False], [72791, False]], 'rate_bp': 725}, [122571, 0, 122571])], [('regression', {'lines': [[49804, True], [5609, True], [29, True], [-28832, True]], 'rate_bp': 725}, [26610, 1930, 28540]), ('regression', {'lines': [[52, True], [19, False], [14472, True], [91, False]], 'rate_bp': 297}, [14634, 432, 15066]), ('partial-repair probe', {'lines': [[74, True], [-48741, True], [16317, True], [-6432, True]], 'rate_bp': 1000}, [-38782, -3878, -42660]), ('partial-repair probe', {'lines': [[70, True]], 'rate_bp': 825}, [70, 6, 76]), ('normal control', {'lines': [[91, False]], 'rate_bp': 12}, [91, 0, 91]), ('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])], [('regression', {'lines': [[52, True], [19, False], [14472, True], [91, False]], 'rate_bp': 297}, [14634, 432, 15066]), ('regression', {'lines': [[-46622, True], [77, True], [83716, False], [46, True], [37, True]], 'rate_bp': 1000}, [37254, -4645, 32609]), ('partial-repair probe', {'lines': [[-7052, True]], 'rate_bp': 2000}, [-7052, -1410, -8462]), ('partial-repair probe', {'lines': [[-12837, True], [-41474, True], [88408, True], [-5186, False]], 'rate_bp': 1738}, [28911, 5926, 34837]), ('normal control', {'lines': [[35, True]], 'rate_bp': 50}, [35, 0, 35]), ('normal control', {'lines': [[-17532, True]], 'rate_bp': 50}, [-17532, -88, -17620]), ('normal control', {'lines': [[95, True]], 'rate_bp': 2000}, [95, 19, 114]), ('normal control', {'lines': [[1, False]], 'rate_bp': 50}, [1, 0, 1])], [('regression', {'lines': [[-46622, True], [77, True], [83716, False], [46, True], [37, True]], 'rate_bp': 1000}, [37254, -4645, 32609]), ('regression', {'lines': [[74, True], [81059, True], [70668, True]], 'rate_bp': 825}, [151801, 12523, 164324]), ('partial-repair probe', {'lines': [[30278, True], [-25624, False], [18105, True]], 'rate_bp': 50}, [22759, 242, 23001]), ('partial-repair probe', {'lines': [[73474, True], [48, False], [70693, False], [-3471, True]], 'rate_bp': 725}, [140744, 5075, 145819]), ('normal control', {'lines': [[80389, True]], 'rate_bp': 725}, [80389, 5828, 86217]), ('normal control', {'lines': [[19, False], [1, True], [-36175, False], [25, True]], 'rate_bp': 2000}, [-36130, 5, -36125]), ('normal control', {'lines': [[-28065, False], [42, False]], 'rate_bp': 725}, [-28023, 0, -28023]), ('normal control', {'lines': [[6941, True], [925, False]], 'rate_bp': 725}, [7866, 503, 8369])]]
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 | [-29416, -2426, -31842] | [-29416, -2426, -31842] | Passed |
| regression 1 | [25982, 1870, 27852] | [25982, 1870, 27852] | Passed |
| partial-repair probe 2 | [97691, 579, 98270] | [97691, 579, 98270] | Passed |
| partial-repair probe 3 | [-19268, -3854, -23122] | [-19268, -3854, -23122] | Passed |
| normal control 4 | [-51735, 0, -51735] | [-51735, 0, -51735] | Passed |
| normal control 5 | [81318, 0, 81318] | [81318, 0, 81318] | Passed |
| normal control 6 | [1785, 0, 1785] | [1785, 0, 1785] | Passed |
| normal control 7 | [30959, 1, 30960] | [30959, 1, 30960] | Passed |
SHA-256 / 2a55d82133ecbb0006fe031fea737a507f8671602b970f1afbb63b765a0863ab
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.209771+00:00.
Case digest / 8efd2aa69a409312b56862c54717d3afbe268228ff7f4eda47296cbd344bf31a