FAILURE MAP
← Case archive

FA-59366 / Subscription proration billing / Open access

Second-granular proration line items: new quantity scaling · case 01

Seat upgrades are charged for a single seat on the new plan.

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

ROOT CAUSE

The remaining-time line ignores the new quantity.

VERIFIED REPAIR

Restore the contract rule at the new quantity scaling step: use `hu(x['new'] * x['qnew'] * left)`.

Unsuccessful approach: The attempt multiplies by the old quantity, so quantity changes are billed at the wrong count.

Case contract

Input unix-second {start, end, change} and {old, qold, new, qnew}. If change < start or change >= end return []. Otherwise left = end - change, span = end - start. An "unused" credit line of -(old*qold*left/span) and a "remaining" line of new*qnew*left/span are emitted, each magnitude rounded half-up (half away from zero), omitting a line whose price*quantity is 0. Return [[kind, amount]].

Why this case matters

Timestamp-based proration produces separate credit and debit lines whose rounding and emission rules show on the invoice.

1 / The failure

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

N = 1
observations = []
def solve(x):
    if x['change'] >= x['end'] or x['change'] < x['start']:
        return []
    span = x['end'] - x['start']
    left = x['end'] - x['change']
    def hu(n):
        return (n * 2 + span) // (2 * span)
    lines = []
    if x['old'] * x['qold']:
        lines.append(['unused', -hu(x['old'] * x['qold'] * left)])
    if x['new'] * x['qnew']:
        lines.append(['remaining', hu(x['new'] * left)])
    return lines
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'start': 1759524018, 'end': 1763871464, 'change': 1759976835, 'old': 0, 'qold': 0, 'new': 1500, 'qnew': 5}, [['remaining', 6719]]), ('regression', {'start': 1726496239, 'end': 1729174639, 'change': 1726496239, 'old': 73990, 'qold': 3, 'new': 47429, 'qnew': 5}, [['unused', -221970], ['remaining', 237145]]), ('partial-repair probe', {'start': 1718898066, 'end': 1722579184, 'change': 1721183532, 'old': 87270, 'qold': 0, 'new': 4900, 'qnew': 1}, [['remaining', 1858]]), ('partial-repair probe', {'start': 1739142581, 'end': 1739747381, 'change': 1739142581, 'old': 26706, 'qold': 3, 'new': 1500, 'qnew': 5}, [['unused', -80118], ['remaining', 7500]]), ('boundary control', {'start': 1000, 'end': 2000, 'change': 1500, 'old': 3, 'qold': 1, 'new': 5, 'qnew': 1}, [['unused', -2], ['remaining', 3]]), ('boundary control', {'start': 1000, 'end': 2000, 'change': 1500, 'old': 5, 'qold': 1, 'new': 7, 'qnew': 1}, [['unused', -3], ['remaining', 4]]), ('normal control', {'start': 1704011568, 'end': 1706689968, 'change': 1706689968, 'old': 1000, 'qold': 3, 'new': 1500, 'qnew': 3}, []), ('normal control', {'start': 1726549577, 'end': 1727154377, 'change': 1726962866, 'old': 2500, 'qold': 0, 'new': 0, 'qnew': 0}, []), ('normal control', {'start': 1737228310, 'end': 1739499785, 'change': 1739499795, 'old': 178, 'qold': 1, 'new': 1500, 'qnew': 1}, []), ('normal control', {'start': 1732894162, 'end': 1735486162, 'change': 1732894162, 'old': 1000, 'qold': 2, 'new': 91004, 'qnew': 0}, [['unused', -2000]])], [('regression', {'start': 1726496239, 'end': 1729174639, 'change': 1726496239, 'old': 73990, 'qold': 3, 'new': 47429, 'qnew': 5}, [['unused', -221970], ['remaining', 237145]]), ('regression', {'start': 1739142581, 'end': 1739747381, 'change': 1739142581, 'old': 26706, 'qold': 3, 'new': 1500, 'qnew': 5}, [['unused', -80118], ['remaining', 7500]]), ('partial-repair probe', {'start': 1733742690, 'end': 1736421090, 'change': 1733742690, 'old': 0, 'qold': 3, 'new': 4900, 'qnew': 14}, [['remaining', 68600]]), ('partial-repair probe', {'start': 1742110108, 'end': 1745693685, 'change': 1744431348, 'old': 2500, 'qold': 1, 'new': 1500, 'qnew': 5}, [['unused', -881], ['remaining', 2642]]), ('boundary control', {'start': 1000, 'end': 2000, 'change': 1500, 'old': 7, 'qold': 1, 'new': 9, 'qnew': 1}, [['unused', -4], ['remaining', 5]]), ('boundary control', {'start': 1000, 'end': 2000, 'change': 1500, 'old': 9, 'qold': 1, 'new': 11, 'qnew': 1}, [['unused', -5], ['remaining', 6]]), ('normal control', {'start': 1749969117, 'end': 1752647517, 'change': 1751393656, 'old': 63152, 'qold': 13, 'new': 0, 'qnew': 0}, [['unused', -384330]]), ('normal control', {'start': 1728579559, 'end': 1760115559, 'change': 1760115559, 'old': 0, 'qold': 0, 'new': 51264, 'qnew': 1}, []), ('normal control', {'start': 1700089359, 'end': 1702545450, 'change': 1702420392, 'old': 79079, 'qold': 0, 'new': 0, 'qnew': 5}, []), ('normal control', {'start': 1721814513, 'end': 1722419313, 'change': 1722419313, 'old': 0, 'qold': 3, 'new': 0, 'qnew': 5}, [])], [('regression', {'start': 1739142581, 'end': 1739747381, 'change': 1739142581, 'old': 26706, 'qold': 3, 'new': 1500, 'qnew': 5}, [['unused', -80118], ['remaining', 7500]]), ('regression', {'start': 1733742690, 'end': 1736421090, 'change': 1733742690, 'old': 0, 'qold': 3, 'new': 4900, 'qnew': 14}, [['remaining', 68600]]), ('partial-repair probe', {'start': 1742110108, 'end': 1745693685, 'change': 1744431348, 'old': 2500, 'qold': 1, 'new': 1500, 'qnew': 5}, [['unused', -881], ['remaining', 2642]]), ('partial-repair probe', {'start': 1702270224, 'end': 1702644112, 'change': 1702432315, 'old': 1000, 'qold': 0, 'new': 97578, 'qnew': 1}, [['remaining', 55275]]), ('boundary control', {'start': 1000, 'end': 2000, 'change': 1500, 'old': 11, 'qold': 1, 'new': 13, 'qnew': 1}, [['unused', -6], ['remaining', 7]]), ('boundary control', {'start': 1000, 'end': 2000, 'change': 1500, 'old': 13, 'qold': 1, 'new': 15, 'qnew': 1}, [['unused', -7], ['remaining', 8]]), ('normal control', {'start': 1720297909, 'end': 1720623118, 'change': 1720623118, 'old': 1000, 'qold': 17, 'new': 0, 'qnew': 0}, []), ('normal control', {'start': 1734629848, 'end': 1766165848, 'change': 1766165848, 'old': 1000, 'qold': 1, 'new': 4900, 'qnew': 1}, []), ('normal control', {'start': 1759898518, 'end': 1762576918, 'change': 1760952409, 'old': 0, 'qold': 3, 'new': 37669, 'qnew': 0}, []), ('normal control', {'start': 1724743049, 'end': 1756279049, 'change': 1724743049, 'old': 2500, 'qold': 1, 'new': 1500, 'qnew': 1}, [['unused', -2500], ['remaining', 1500]])], [('regression', {'start': 1733742690, 'end': 1736421090, 'change': 1733742690, 'old': 0, 'qold': 3, 'new': 4900, 'qnew': 14}, [['remaining', 68600]]), ('regression', {'start': 1742110108, 'end': 1745693685, 'change': 1744431348, 'old': 2500, 'qold': 1, 'new': 1500, 'qnew': 5}, [['unused', -881], ['remaining', 2642]]), ('partial-repair probe', {'start': 1702270224, 'end': 1702644112, 'change': 1702432315, 'old': 1000, 'qold': 0, 'new': 97578, 'qnew': 1}, [['remaining', 55275]]), ('partial-repair probe', {'start': 1742790755, 'end': 1743897100, 'change': 1742790755, 'old': 1000, 'qold': 20, 'new': 4900, 'qnew': 1}, [['unused', -20000], ['remaining', 4900]]), ('boundary control', {'start': 1000, 'end': 2000, 'change': 1500, 'old': 3, 'qold': 1, 'new': 5, 'qnew': 1}, [['unused', -2], ['remaining', 3]]), ('boundary control', {'start': 1000, 'end': 2000, 'change': 1500, 'old': 5, 'qold': 1, 'new': 7, 'qnew': 1}, [['unused', -3], ['remaining', 4]]), ('normal control', {'start': 1742436208, 'end': 1773972208, 'change': 1773972218, 'old': 0, 'qold': 3, 'new': 4900, 'qnew': 1}, []), ('normal control', {'start': 1757847857, 'end': 1760439857, 'change': 1757847852, 'old': 92286, 'qold': 0, 'new': 0, 'qnew': 4}, []), ('normal control', {'start': 1739738740, 'end': 1771274740, 'change': 1771274740, 'old': 2500, 'qold': 3, 'new': 1500, 'qnew': 5}, []), ('normal control', {'start': 1725551908, 'end': 1757087908, 'change': 1757087918, 'old': 67119, 'qold': 3, 'new': 4900, 'qnew': 13}, [])], [('regression', {'start': 1742110108, 'end': 1745693685, 'change': 1744431348, 'old': 2500, 'qold': 1, 'new': 1500, 'qnew': 5}, [['unused', -881], ['remaining', 2642]]), ('regression', {'start': 1716615435, 'end': 1718469212, 'change': 1718430872, 'old': 0, 'qold': 0, 'new': 4900, 'qnew': 5}, [['remaining', 507]]), ('partial-repair probe', {'start': 1744261612, 'end': 1748589217, 'change': 1744261612, 'old': 1000, 'qold': 4, 'new': 2084, 'qnew': 18}, [['unused', -4000], ['remaining', 37512]]), ('partial-repair probe', {'start': 1733908199, 'end': 1736586599, 'change': 1733908199, 'old': 32045, 'qold': 0, 'new': 4900, 'qnew': 19}, [['remaining', 93100]]), ('boundary control', {'start': 1000, 'end': 2000, 'change': 1500, 'old': 7, 'qold': 1, 'new': 9, 'qnew': 1}, [['unused', -4], ['remaining', 5]]), ('boundary control', {'start': 1000, 'end': 2000, 'change': 1500, 'old': 9, 'qold': 1, 'new': 11, 'qnew': 1}, [['unused', -5], ['remaining', 6]]), ('normal control', {'start': 1753105090, 'end': 1753709890, 'change': 1753105090, 'old': 1000, 'qold': 0, 'new': 0, 'qnew': 1}, []), ('normal control', {'start': 1742150000, 'end': 1745617539, 'change': 1744739339, 'old': 2500, 'qold': 3, 'new': 0, 'qnew': 1}, [['unused', -1899]]), ('normal control', {'start': 1734436882, 'end': 1765972882, 'change': 1756322121, 'old': 10374, 'qold': 1, 'new': 4900, 'qnew': 1}, [['unused', -3175], ['remaining', 1500]]), ('normal control', {'start': 1716957129, 'end': 1717561929, 'change': 1716957124, 'old': 1000, 'qold': 7, 'new': 0, 'qnew': 5}, [])]]
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[['remaining', 1344]][['remaining', 6719]]Failed
regression 1[['unused', -221970], ['remaining', 47429]][['unused', -221970], ['remaining', 237145]]Failed
partial-repair probe 2[['remaining', 1858]][['remaining', 1858]]Passed
partial-repair probe 3[['unused', -80118], ['remaining', 1500]][['unused', -80118], ['remaining', 7500]]Failed
boundary control 4[['unused', -2], ['remaining', 3]][['unused', -2], ['remaining', 3]]Passed
boundary control 5[['unused', -3], ['remaining', 4]][['unused', -3], ['remaining', 4]]Passed
normal control 6[][]Passed
normal control 7[][]Passed
normal control 8[][]Passed
normal control 9[['unused', -2000]][['unused', -2000]]Passed

SHA-256 / c24a8914d25d8e521f3a60afc164d635b820b0123739e7cc0d4122d58c5aaccf

2 / The unsuccessful fix

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

N = 1
observations = []
def solve(x):
    if x['change'] >= x['end'] or x['change'] < x['start']:
        return []
    span = x['end'] - x['start']
    left = x['end'] - x['change']
    def hu(n):
        return (n * 2 + span) // (2 * span)
    lines = []
    if x['old'] * x['qold']:
        lines.append(['unused', -hu(x['old'] * x['qold'] * left)])
    if x['new'] * x['qnew']:
        lines.append(['remaining', hu(x['new'] * x['qold'] * left)])
    return lines
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'start': 1759524018, 'end': 1763871464, 'change': 1759976835, 'old': 0, 'qold': 0, 'new': 1500, 'qnew': 5}, [['remaining', 6719]]), ('regression', {'start': 1726496239, 'end': 1729174639, 'change': 1726496239, 'old': 73990, 'qold': 3, 'new': 47429, 'qnew': 5}, [['unused', -221970], ['remaining', 237145]]), ('partial-repair probe', {'start': 1718898066, 'end': 1722579184, 'change': 1721183532, 'old': 87270, 'qold': 0, 'new': 4900, 'qnew': 1}, [['remaining', 1858]]), ('partial-repair probe', {'start': 1739142581, 'end': 1739747381, 'change': 1739142581, 'old': 26706, 'qold': 3, 'new': 1500, 'qnew': 5}, [['unused', -80118], ['remaining', 7500]]), ('boundary control', {'start': 1000, 'end': 2000, 'change': 1500, 'old': 3, 'qold': 1, 'new': 5, 'qnew': 1}, [['unused', -2], ['remaining', 3]]), ('boundary control', {'start': 1000, 'end': 2000, 'change': 1500, 'old': 5, 'qold': 1, 'new': 7, 'qnew': 1}, [['unused', -3], ['remaining', 4]]), ('normal control', {'start': 1704011568, 'end': 1706689968, 'change': 1706689968, 'old': 1000, 'qold': 3, 'new': 1500, 'qnew': 3}, []), ('normal control', {'start': 1726549577, 'end': 1727154377, 'change': 1726962866, 'old': 2500, 'qold': 0, 'new': 0, 'qnew': 0}, []), ('normal control', {'start': 1737228310, 'end': 1739499785, 'change': 1739499795, 'old': 178, 'qold': 1, 'new': 1500, 'qnew': 1}, []), ('normal control', {'start': 1732894162, 'end': 1735486162, 'change': 1732894162, 'old': 1000, 'qold': 2, 'new': 91004, 'qnew': 0}, [['unused', -2000]])], [('regression', {'start': 1726496239, 'end': 1729174639, 'change': 1726496239, 'old': 73990, 'qold': 3, 'new': 47429, 'qnew': 5}, [['unused', -221970], ['remaining', 237145]]), ('regression', {'start': 1739142581, 'end': 1739747381, 'change': 1739142581, 'old': 26706, 'qold': 3, 'new': 1500, 'qnew': 5}, [['unused', -80118], ['remaining', 7500]]), ('partial-repair probe', {'start': 1733742690, 'end': 1736421090, 'change': 1733742690, 'old': 0, 'qold': 3, 'new': 4900, 'qnew': 14}, [['remaining', 68600]]), ('partial-repair probe', {'start': 1742110108, 'end': 1745693685, 'change': 1744431348, 'old': 2500, 'qold': 1, 'new': 1500, 'qnew': 5}, [['unused', -881], ['remaining', 2642]]), ('boundary control', {'start': 1000, 'end': 2000, 'change': 1500, 'old': 7, 'qold': 1, 'new': 9, 'qnew': 1}, [['unused', -4], ['remaining', 5]]), ('boundary control', {'start': 1000, 'end': 2000, 'change': 1500, 'old': 9, 'qold': 1, 'new': 11, 'qnew': 1}, [['unused', -5], ['remaining', 6]]), ('normal control', {'start': 1749969117, 'end': 1752647517, 'change': 1751393656, 'old': 63152, 'qold': 13, 'new': 0, 'qnew': 0}, [['unused', -384330]]), ('normal control', {'start': 1728579559, 'end': 1760115559, 'change': 1760115559, 'old': 0, 'qold': 0, 'new': 51264, 'qnew': 1}, []), ('normal control', {'start': 1700089359, 'end': 1702545450, 'change': 1702420392, 'old': 79079, 'qold': 0, 'new': 0, 'qnew': 5}, []), ('normal control', {'start': 1721814513, 'end': 1722419313, 'change': 1722419313, 'old': 0, 'qold': 3, 'new': 0, 'qnew': 5}, [])], [('regression', {'start': 1739142581, 'end': 1739747381, 'change': 1739142581, 'old': 26706, 'qold': 3, 'new': 1500, 'qnew': 5}, [['unused', -80118], ['remaining', 7500]]), ('regression', {'start': 1733742690, 'end': 1736421090, 'change': 1733742690, 'old': 0, 'qold': 3, 'new': 4900, 'qnew': 14}, [['remaining', 68600]]), ('partial-repair probe', {'start': 1742110108, 'end': 1745693685, 'change': 1744431348, 'old': 2500, 'qold': 1, 'new': 1500, 'qnew': 5}, [['unused', -881], ['remaining', 2642]]), ('partial-repair probe', {'start': 1702270224, 'end': 1702644112, 'change': 1702432315, 'old': 1000, 'qold': 0, 'new': 97578, 'qnew': 1}, [['remaining', 55275]]), ('boundary control', {'start': 1000, 'end': 2000, 'change': 1500, 'old': 11, 'qold': 1, 'new': 13, 'qnew': 1}, [['unused', -6], ['remaining', 7]]), ('boundary control', {'start': 1000, 'end': 2000, 'change': 1500, 'old': 13, 'qold': 1, 'new': 15, 'qnew': 1}, [['unused', -7], ['remaining', 8]]), ('normal control', {'start': 1720297909, 'end': 1720623118, 'change': 1720623118, 'old': 1000, 'qold': 17, 'new': 0, 'qnew': 0}, []), ('normal control', {'start': 1734629848, 'end': 1766165848, 'change': 1766165848, 'old': 1000, 'qold': 1, 'new': 4900, 'qnew': 1}, []), ('normal control', {'start': 1759898518, 'end': 1762576918, 'change': 1760952409, 'old': 0, 'qold': 3, 'new': 37669, 'qnew': 0}, []), ('normal control', {'start': 1724743049, 'end': 1756279049, 'change': 1724743049, 'old': 2500, 'qold': 1, 'new': 1500, 'qnew': 1}, [['unused', -2500], ['remaining', 1500]])], [('regression', {'start': 1733742690, 'end': 1736421090, 'change': 1733742690, 'old': 0, 'qold': 3, 'new': 4900, 'qnew': 14}, [['remaining', 68600]]), ('regression', {'start': 1742110108, 'end': 1745693685, 'change': 1744431348, 'old': 2500, 'qold': 1, 'new': 1500, 'qnew': 5}, [['unused', -881], ['remaining', 2642]]), ('partial-repair probe', {'start': 1702270224, 'end': 1702644112, 'change': 1702432315, 'old': 1000, 'qold': 0, 'new': 97578, 'qnew': 1}, [['remaining', 55275]]), ('partial-repair probe', {'start': 1742790755, 'end': 1743897100, 'change': 1742790755, 'old': 1000, 'qold': 20, 'new': 4900, 'qnew': 1}, [['unused', -20000], ['remaining', 4900]]), ('boundary control', {'start': 1000, 'end': 2000, 'change': 1500, 'old': 3, 'qold': 1, 'new': 5, 'qnew': 1}, [['unused', -2], ['remaining', 3]]), ('boundary control', {'start': 1000, 'end': 2000, 'change': 1500, 'old': 5, 'qold': 1, 'new': 7, 'qnew': 1}, [['unused', -3], ['remaining', 4]]), ('normal control', {'start': 1742436208, 'end': 1773972208, 'change': 1773972218, 'old': 0, 'qold': 3, 'new': 4900, 'qnew': 1}, []), ('normal control', {'start': 1757847857, 'end': 1760439857, 'change': 1757847852, 'old': 92286, 'qold': 0, 'new': 0, 'qnew': 4}, []), ('normal control', {'start': 1739738740, 'end': 1771274740, 'change': 1771274740, 'old': 2500, 'qold': 3, 'new': 1500, 'qnew': 5}, []), ('normal control', {'start': 1725551908, 'end': 1757087908, 'change': 1757087918, 'old': 67119, 'qold': 3, 'new': 4900, 'qnew': 13}, [])], [('regression', {'start': 1742110108, 'end': 1745693685, 'change': 1744431348, 'old': 2500, 'qold': 1, 'new': 1500, 'qnew': 5}, [['unused', -881], ['remaining', 2642]]), ('regression', {'start': 1716615435, 'end': 1718469212, 'change': 1718430872, 'old': 0, 'qold': 0, 'new': 4900, 'qnew': 5}, [['remaining', 507]]), ('partial-repair probe', {'start': 1744261612, 'end': 1748589217, 'change': 1744261612, 'old': 1000, 'qold': 4, 'new': 2084, 'qnew': 18}, [['unused', -4000], ['remaining', 37512]]), ('partial-repair probe', {'start': 1733908199, 'end': 1736586599, 'change': 1733908199, 'old': 32045, 'qold': 0, 'new': 4900, 'qnew': 19}, [['remaining', 93100]]), ('boundary control', {'start': 1000, 'end': 2000, 'change': 1500, 'old': 7, 'qold': 1, 'new': 9, 'qnew': 1}, [['unused', -4], ['remaining', 5]]), ('boundary control', {'start': 1000, 'end': 2000, 'change': 1500, 'old': 9, 'qold': 1, 'new': 11, 'qnew': 1}, [['unused', -5], ['remaining', 6]]), ('normal control', {'start': 1753105090, 'end': 1753709890, 'change': 1753105090, 'old': 1000, 'qold': 0, 'new': 0, 'qnew': 1}, []), ('normal control', {'start': 1742150000, 'end': 1745617539, 'change': 1744739339, 'old': 2500, 'qold': 3, 'new': 0, 'qnew': 1}, [['unused', -1899]]), ('normal control', {'start': 1734436882, 'end': 1765972882, 'change': 1756322121, 'old': 10374, 'qold': 1, 'new': 4900, 'qnew': 1}, [['unused', -3175], ['remaining', 1500]]), ('normal control', {'start': 1716957129, 'end': 1717561929, 'change': 1716957124, 'old': 1000, 'qold': 7, 'new': 0, 'qnew': 5}, [])]]
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[['remaining', 0]][['remaining', 6719]]Failed
regression 1[['unused', -221970], ['remaining', 142287]][['unused', -221970], ['remaining', 237145]]Failed
partial-repair probe 2[['remaining', 0]][['remaining', 1858]]Failed
partial-repair probe 3[['unused', -80118], ['remaining', 4500]][['unused', -80118], ['remaining', 7500]]Failed
boundary control 4[['unused', -2], ['remaining', 3]][['unused', -2], ['remaining', 3]]Passed
boundary control 5[['unused', -3], ['remaining', 4]][['unused', -3], ['remaining', 4]]Passed
normal control 6[][]Passed
normal control 7[][]Passed
normal control 8[][]Passed
normal control 9[['unused', -2000]][['unused', -2000]]Passed

SHA-256 / 59eb5acd82bb0b441aa5cda40d43efa36b63396e135239cfdff0d7a21d853f6f

3 / The verified repair

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

N = 1
observations = []
def solve(x):
    if x['change'] >= x['end'] or x['change'] < x['start']:
        return []
    span = x['end'] - x['start']
    left = x['end'] - x['change']
    def hu(n):
        return (n * 2 + span) // (2 * span)
    lines = []
    if x['old'] * x['qold']:
        lines.append(['unused', -hu(x['old'] * x['qold'] * left)])
    if x['new'] * x['qnew']:
        lines.append(['remaining', hu(x['new'] * x['qnew'] * left)])
    return lines
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'start': 1759524018, 'end': 1763871464, 'change': 1759976835, 'old': 0, 'qold': 0, 'new': 1500, 'qnew': 5}, [['remaining', 6719]]), ('regression', {'start': 1726496239, 'end': 1729174639, 'change': 1726496239, 'old': 73990, 'qold': 3, 'new': 47429, 'qnew': 5}, [['unused', -221970], ['remaining', 237145]]), ('partial-repair probe', {'start': 1718898066, 'end': 1722579184, 'change': 1721183532, 'old': 87270, 'qold': 0, 'new': 4900, 'qnew': 1}, [['remaining', 1858]]), ('partial-repair probe', {'start': 1739142581, 'end': 1739747381, 'change': 1739142581, 'old': 26706, 'qold': 3, 'new': 1500, 'qnew': 5}, [['unused', -80118], ['remaining', 7500]]), ('boundary control', {'start': 1000, 'end': 2000, 'change': 1500, 'old': 3, 'qold': 1, 'new': 5, 'qnew': 1}, [['unused', -2], ['remaining', 3]]), ('boundary control', {'start': 1000, 'end': 2000, 'change': 1500, 'old': 5, 'qold': 1, 'new': 7, 'qnew': 1}, [['unused', -3], ['remaining', 4]]), ('normal control', {'start': 1704011568, 'end': 1706689968, 'change': 1706689968, 'old': 1000, 'qold': 3, 'new': 1500, 'qnew': 3}, []), ('normal control', {'start': 1726549577, 'end': 1727154377, 'change': 1726962866, 'old': 2500, 'qold': 0, 'new': 0, 'qnew': 0}, []), ('normal control', {'start': 1737228310, 'end': 1739499785, 'change': 1739499795, 'old': 178, 'qold': 1, 'new': 1500, 'qnew': 1}, []), ('normal control', {'start': 1732894162, 'end': 1735486162, 'change': 1732894162, 'old': 1000, 'qold': 2, 'new': 91004, 'qnew': 0}, [['unused', -2000]])], [('regression', {'start': 1726496239, 'end': 1729174639, 'change': 1726496239, 'old': 73990, 'qold': 3, 'new': 47429, 'qnew': 5}, [['unused', -221970], ['remaining', 237145]]), ('regression', {'start': 1739142581, 'end': 1739747381, 'change': 1739142581, 'old': 26706, 'qold': 3, 'new': 1500, 'qnew': 5}, [['unused', -80118], ['remaining', 7500]]), ('partial-repair probe', {'start': 1733742690, 'end': 1736421090, 'change': 1733742690, 'old': 0, 'qold': 3, 'new': 4900, 'qnew': 14}, [['remaining', 68600]]), ('partial-repair probe', {'start': 1742110108, 'end': 1745693685, 'change': 1744431348, 'old': 2500, 'qold': 1, 'new': 1500, 'qnew': 5}, [['unused', -881], ['remaining', 2642]]), ('boundary control', {'start': 1000, 'end': 2000, 'change': 1500, 'old': 7, 'qold': 1, 'new': 9, 'qnew': 1}, [['unused', -4], ['remaining', 5]]), ('boundary control', {'start': 1000, 'end': 2000, 'change': 1500, 'old': 9, 'qold': 1, 'new': 11, 'qnew': 1}, [['unused', -5], ['remaining', 6]]), ('normal control', {'start': 1749969117, 'end': 1752647517, 'change': 1751393656, 'old': 63152, 'qold': 13, 'new': 0, 'qnew': 0}, [['unused', -384330]]), ('normal control', {'start': 1728579559, 'end': 1760115559, 'change': 1760115559, 'old': 0, 'qold': 0, 'new': 51264, 'qnew': 1}, []), ('normal control', {'start': 1700089359, 'end': 1702545450, 'change': 1702420392, 'old': 79079, 'qold': 0, 'new': 0, 'qnew': 5}, []), ('normal control', {'start': 1721814513, 'end': 1722419313, 'change': 1722419313, 'old': 0, 'qold': 3, 'new': 0, 'qnew': 5}, [])], [('regression', {'start': 1739142581, 'end': 1739747381, 'change': 1739142581, 'old': 26706, 'qold': 3, 'new': 1500, 'qnew': 5}, [['unused', -80118], ['remaining', 7500]]), ('regression', {'start': 1733742690, 'end': 1736421090, 'change': 1733742690, 'old': 0, 'qold': 3, 'new': 4900, 'qnew': 14}, [['remaining', 68600]]), ('partial-repair probe', {'start': 1742110108, 'end': 1745693685, 'change': 1744431348, 'old': 2500, 'qold': 1, 'new': 1500, 'qnew': 5}, [['unused', -881], ['remaining', 2642]]), ('partial-repair probe', {'start': 1702270224, 'end': 1702644112, 'change': 1702432315, 'old': 1000, 'qold': 0, 'new': 97578, 'qnew': 1}, [['remaining', 55275]]), ('boundary control', {'start': 1000, 'end': 2000, 'change': 1500, 'old': 11, 'qold': 1, 'new': 13, 'qnew': 1}, [['unused', -6], ['remaining', 7]]), ('boundary control', {'start': 1000, 'end': 2000, 'change': 1500, 'old': 13, 'qold': 1, 'new': 15, 'qnew': 1}, [['unused', -7], ['remaining', 8]]), ('normal control', {'start': 1720297909, 'end': 1720623118, 'change': 1720623118, 'old': 1000, 'qold': 17, 'new': 0, 'qnew': 0}, []), ('normal control', {'start': 1734629848, 'end': 1766165848, 'change': 1766165848, 'old': 1000, 'qold': 1, 'new': 4900, 'qnew': 1}, []), ('normal control', {'start': 1759898518, 'end': 1762576918, 'change': 1760952409, 'old': 0, 'qold': 3, 'new': 37669, 'qnew': 0}, []), ('normal control', {'start': 1724743049, 'end': 1756279049, 'change': 1724743049, 'old': 2500, 'qold': 1, 'new': 1500, 'qnew': 1}, [['unused', -2500], ['remaining', 1500]])], [('regression', {'start': 1733742690, 'end': 1736421090, 'change': 1733742690, 'old': 0, 'qold': 3, 'new': 4900, 'qnew': 14}, [['remaining', 68600]]), ('regression', {'start': 1742110108, 'end': 1745693685, 'change': 1744431348, 'old': 2500, 'qold': 1, 'new': 1500, 'qnew': 5}, [['unused', -881], ['remaining', 2642]]), ('partial-repair probe', {'start': 1702270224, 'end': 1702644112, 'change': 1702432315, 'old': 1000, 'qold': 0, 'new': 97578, 'qnew': 1}, [['remaining', 55275]]), ('partial-repair probe', {'start': 1742790755, 'end': 1743897100, 'change': 1742790755, 'old': 1000, 'qold': 20, 'new': 4900, 'qnew': 1}, [['unused', -20000], ['remaining', 4900]]), ('boundary control', {'start': 1000, 'end': 2000, 'change': 1500, 'old': 3, 'qold': 1, 'new': 5, 'qnew': 1}, [['unused', -2], ['remaining', 3]]), ('boundary control', {'start': 1000, 'end': 2000, 'change': 1500, 'old': 5, 'qold': 1, 'new': 7, 'qnew': 1}, [['unused', -3], ['remaining', 4]]), ('normal control', {'start': 1742436208, 'end': 1773972208, 'change': 1773972218, 'old': 0, 'qold': 3, 'new': 4900, 'qnew': 1}, []), ('normal control', {'start': 1757847857, 'end': 1760439857, 'change': 1757847852, 'old': 92286, 'qold': 0, 'new': 0, 'qnew': 4}, []), ('normal control', {'start': 1739738740, 'end': 1771274740, 'change': 1771274740, 'old': 2500, 'qold': 3, 'new': 1500, 'qnew': 5}, []), ('normal control', {'start': 1725551908, 'end': 1757087908, 'change': 1757087918, 'old': 67119, 'qold': 3, 'new': 4900, 'qnew': 13}, [])], [('regression', {'start': 1742110108, 'end': 1745693685, 'change': 1744431348, 'old': 2500, 'qold': 1, 'new': 1500, 'qnew': 5}, [['unused', -881], ['remaining', 2642]]), ('regression', {'start': 1716615435, 'end': 1718469212, 'change': 1718430872, 'old': 0, 'qold': 0, 'new': 4900, 'qnew': 5}, [['remaining', 507]]), ('partial-repair probe', {'start': 1744261612, 'end': 1748589217, 'change': 1744261612, 'old': 1000, 'qold': 4, 'new': 2084, 'qnew': 18}, [['unused', -4000], ['remaining', 37512]]), ('partial-repair probe', {'start': 1733908199, 'end': 1736586599, 'change': 1733908199, 'old': 32045, 'qold': 0, 'new': 4900, 'qnew': 19}, [['remaining', 93100]]), ('boundary control', {'start': 1000, 'end': 2000, 'change': 1500, 'old': 7, 'qold': 1, 'new': 9, 'qnew': 1}, [['unused', -4], ['remaining', 5]]), ('boundary control', {'start': 1000, 'end': 2000, 'change': 1500, 'old': 9, 'qold': 1, 'new': 11, 'qnew': 1}, [['unused', -5], ['remaining', 6]]), ('normal control', {'start': 1753105090, 'end': 1753709890, 'change': 1753105090, 'old': 1000, 'qold': 0, 'new': 0, 'qnew': 1}, []), ('normal control', {'start': 1742150000, 'end': 1745617539, 'change': 1744739339, 'old': 2500, 'qold': 3, 'new': 0, 'qnew': 1}, [['unused', -1899]]), ('normal control', {'start': 1734436882, 'end': 1765972882, 'change': 1756322121, 'old': 10374, 'qold': 1, 'new': 4900, 'qnew': 1}, [['unused', -3175], ['remaining', 1500]]), ('normal control', {'start': 1716957129, 'end': 1717561929, 'change': 1716957124, 'old': 1000, 'qold': 7, 'new': 0, 'qnew': 5}, [])]]
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[['remaining', 6719]][['remaining', 6719]]Passed
regression 1[['unused', -221970], ['remaining', 237145]][['unused', -221970], ['remaining', 237145]]Passed
partial-repair probe 2[['remaining', 1858]][['remaining', 1858]]Passed
partial-repair probe 3[['unused', -80118], ['remaining', 7500]][['unused', -80118], ['remaining', 7500]]Passed
boundary control 4[['unused', -2], ['remaining', 3]][['unused', -2], ['remaining', 3]]Passed
boundary control 5[['unused', -3], ['remaining', 4]][['unused', -3], ['remaining', 4]]Passed
normal control 6[][]Passed
normal control 7[][]Passed
normal control 8[][]Passed
normal control 9[['unused', -2000]][['unused', -2000]]Passed

SHA-256 / 7b1fce293d87e01a1df4957cc9330935dfaab5bfbe2e27f287d2379f844727c4

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

Case digest / 26421b6c457c87668b46749a892eabf678f374395ad63ed2acbd1aa980f053a7