FAILURE MAP
← Case archive

FA-59431 / Subscription proration billing / Open access

Trial conversion stub period: previous anchor January wrap · case 01

January trials that end before the anchor day produce a negative stub charge.

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

ROOT CAUSE

The previous anchor for a January trial end is placed in December of the same year.

VERIFIED REPAIR

Restore the contract rule at the previous anchor January wrap step: use `py, pm = (t.year - 1, 12) if t.month == 1 else (t.year, t.month - 1)`.

Unsuccessful approach: The attempt computes year and month with divmod but keeps the month zero-based, landing one month early.

Case contract

Input {trial_end date, anchor_day 1..28, price}. If trial_end.day equals anchor_day, charge the full price and the next anchor is one month later. Otherwise charge price*days/cycle half-up, where days runs from trial_end to the next anchor date strictly after it and cycle is the length of the anchor-to-anchor month containing trial_end. Return [amount, next anchor ISO].

Why this case matters

Converting a trial onto a fixed billing anchor produces a stub invoice whose length depends on real month boundaries.

1 / The failure

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
import datetime
import calendar
N = 1
observations = []
def solve(x):
    t = datetime.date(*x['trial_end'])
    a = x['anchor_day']
    if t.day == a:
        ny, nm = (t.year + 1, 1) if t.month == 12 else (t.year, t.month + 1)
        return [x['price'], datetime.date(ny, nm, a).isoformat()]
    if t.day < a:
        nxt = datetime.date(t.year, t.month, a)
        py, pm = (t.year, 12) if t.month == 1 else (t.year, t.month - 1)
        prev = datetime.date(py, pm, a)
    else:
        ey, em = (t.year + 1, 1) if t.month == 12 else (t.year, t.month + 1)
        nxt = datetime.date(ey, em, a)
        prev = datetime.date(t.year, t.month, a)
    days = (nxt - t).days
    cycle = (nxt - prev).days
    return [(x['price'] * days * 2 + cycle) // (2 * cycle), nxt.isoformat()]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'trial_end': [2023, 1, 5], 'anchor_day': 28, 'price': 999}, [741, '2023-01-28']), ('regression', {'trial_end': [2025, 1, 1], 'anchor_day': 13, 'price': 2900}, [1123, '2025-01-13']), ('partial-repair probe', {'trial_end': [2024, 4, 27], 'anchor_day': 28, 'price': 999}, [32, '2024-04-28']), ('partial-repair probe', {'trial_end': [2024, 12, 16], 'anchor_day': 28, 'price': 2900}, [1160, '2024-12-28']), ('normal control', {'trial_end': [2024, 12, 25], 'anchor_day': 1, 'price': 12600}, [2845, '2025-01-01']), ('normal control', {'trial_end': [2023, 4, 14], 'anchor_day': 1, 'price': 999}, [566, '2023-05-01']), ('normal control', {'trial_end': [2023, 6, 15], 'anchor_day': 15, 'price': 999}, [999, '2023-07-15']), ('normal control', {'trial_end': [2023, 12, 16], 'anchor_day': 15, 'price': 2900}, [2806, '2024-01-15'])], [('regression', {'trial_end': [2025, 1, 1], 'anchor_day': 13, 'price': 2900}, [1123, '2025-01-13']), ('regression', {'trial_end': [2024, 1, 1], 'anchor_day': 28, 'price': 2900}, [2526, '2024-01-28']), ('partial-repair probe', {'trial_end': [2024, 4, 1], 'anchor_day': 28, 'price': 78891}, [68712, '2024-04-28']), ('partial-repair probe', {'trial_end': [2024, 6, 4], 'anchor_day': 28, 'price': 999}, [773, '2024-06-28']), ('normal control', {'trial_end': [2025, 3, 15], 'anchor_day': 15, 'price': 2900}, [2900, '2025-04-15']), ('normal control', {'trial_end': [2023, 12, 15], 'anchor_day': 1, 'price': 47732}, [26176, '2024-01-01']), ('normal control', {'trial_end': [2024, 2, 8], 'anchor_day': 8, 'price': 999}, [999, '2024-03-08']), ('normal control', {'trial_end': [2024, 6, 25], 'anchor_day': 1, 'price': 2900}, [580, '2024-07-01'])], [('regression', {'trial_end': [2024, 1, 1], 'anchor_day': 28, 'price': 2900}, [2526, '2024-01-28']), ('regression', {'trial_end': [2025, 1, 2], 'anchor_day': 28, 'price': 999}, [838, '2025-01-28']), ('partial-repair probe', {'trial_end': [2024, 4, 10], 'anchor_day': 15, 'price': 2900}, [468, '2024-04-15']), ('partial-repair probe', {'trial_end': [2023, 10, 3], 'anchor_day': 16, 'price': 999}, [433, '2023-10-16']), ('normal control', {'trial_end': [2023, 12, 26], 'anchor_day': 21, 'price': 999}, [838, '2024-01-21']), ('normal control', {'trial_end': [2023, 5, 26], 'anchor_day': 1, 'price': 62316}, [12061, '2023-06-01']), ('normal control', {'trial_end': [2023, 4, 30], 'anchor_day': 15, 'price': 44760}, [22380, '2023-05-15']), ('normal control', {'trial_end': [2025, 5, 3], 'anchor_day': 1, 'price': 2900}, [2713, '2025-06-01'])], [('regression', {'trial_end': [2025, 1, 2], 'anchor_day': 28, 'price': 999}, [838, '2025-01-28']), ('regression', {'trial_end': [2024, 1, 7], 'anchor_day': 15, 'price': 28964}, [7475, '2024-01-15']), ('partial-repair probe', {'trial_end': [2023, 6, 18], 'anchor_day': 28, 'price': 2900}, [935, '2023-06-28']), ('partial-repair probe', {'trial_end': [2025, 3, 22], 'anchor_day': 28, 'price': 58121}, [12455, '2025-03-28']), ('normal control', {'trial_end': [2024, 6, 14], 'anchor_day': 1, 'price': 999}, [566, '2024-07-01']), ('normal control', {'trial_end': [2023, 5, 23], 'anchor_day': 15, 'price': 2900}, [2152, '2023-06-15']), ('normal control', {'trial_end': [2023, 5, 31], 'anchor_day': 4, 'price': 999}, [129, '2023-06-04']), ('normal control', {'trial_end': [2023, 3, 16], 'anchor_day': 15, 'price': 9250}, [8952, '2023-04-15'])], [('regression', {'trial_end': [2024, 1, 7], 'anchor_day': 15, 'price': 28964}, [7475, '2024-01-15']), ('regression', {'trial_end': [2025, 1, 2], 'anchor_day': 28, 'price': 2360}, [1979, '2025-01-28']), ('partial-repair probe', {'trial_end': [2024, 3, 15], 'anchor_day': 28, 'price': 999}, [448, '2024-03-28']), ('partial-repair probe', {'trial_end': [2024, 12, 11], 'anchor_day': 15, 'price': 2900}, [387, '2024-12-15']), ('normal control', {'trial_end': [2025, 2, 28], 'anchor_day': 1, 'price': 999}, [36, '2025-03-01']), ('normal control', {'trial_end': [2023, 8, 18], 'anchor_day': 1, 'price': 2900}, [1310, '2023-09-01']), ('normal control', {'trial_end': [2025, 1, 4], 'anchor_day': 1, 'price': 39775}, [35926, '2025-02-01']), ('normal control', {'trial_end': [2024, 7, 15], 'anchor_day': 15, 'price': 999}, [999, '2024-08-15'])]]
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[-69, '2023-01-28'][741, '2023-01-28']Failed
regression 1[-104, '2025-01-13'][1123, '2025-01-13']Failed
partial-repair probe 2[32, '2024-04-28'][32, '2024-04-28']Passed
partial-repair probe 3[1160, '2024-12-28'][1160, '2024-12-28']Passed
normal control 4[2845, '2025-01-01'][2845, '2025-01-01']Passed
normal control 5[566, '2023-05-01'][566, '2023-05-01']Passed
normal control 6[999, '2023-07-15'][999, '2023-07-15']Passed
normal control 7[2806, '2024-01-15'][2806, '2024-01-15']Passed

SHA-256 / 1385c015bf6b8241e0aebc4cf39f26650ece323e6ea6a903801124a1bf4b4a6e

2 / The unsuccessful fix

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
import datetime
import calendar
N = 1
observations = []
def solve(x):
    t = datetime.date(*x['trial_end'])
    a = x['anchor_day']
    if t.day == a:
        ny, nm = (t.year + 1, 1) if t.month == 12 else (t.year, t.month + 1)
        return [x['price'], datetime.date(ny, nm, a).isoformat()]
    if t.day < a:
        nxt = datetime.date(t.year, t.month, a)
        py, pm = divmod(t.year * 12 + t.month - 2, 12)
        prev = datetime.date(py, pm, a)
    else:
        ey, em = (t.year + 1, 1) if t.month == 12 else (t.year, t.month + 1)
        nxt = datetime.date(ey, em, a)
        prev = datetime.date(t.year, t.month, a)
    days = (nxt - t).days
    cycle = (nxt - prev).days
    return [(x['price'] * days * 2 + cycle) // (2 * cycle), nxt.isoformat()]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'trial_end': [2023, 1, 5], 'anchor_day': 28, 'price': 999}, [741, '2023-01-28']), ('regression', {'trial_end': [2025, 1, 1], 'anchor_day': 13, 'price': 2900}, [1123, '2025-01-13']), ('partial-repair probe', {'trial_end': [2024, 4, 27], 'anchor_day': 28, 'price': 999}, [32, '2024-04-28']), ('partial-repair probe', {'trial_end': [2024, 12, 16], 'anchor_day': 28, 'price': 2900}, [1160, '2024-12-28']), ('normal control', {'trial_end': [2024, 12, 25], 'anchor_day': 1, 'price': 12600}, [2845, '2025-01-01']), ('normal control', {'trial_end': [2023, 4, 14], 'anchor_day': 1, 'price': 999}, [566, '2023-05-01']), ('normal control', {'trial_end': [2023, 6, 15], 'anchor_day': 15, 'price': 999}, [999, '2023-07-15']), ('normal control', {'trial_end': [2023, 12, 16], 'anchor_day': 15, 'price': 2900}, [2806, '2024-01-15'])], [('regression', {'trial_end': [2025, 1, 1], 'anchor_day': 13, 'price': 2900}, [1123, '2025-01-13']), ('regression', {'trial_end': [2024, 1, 1], 'anchor_day': 28, 'price': 2900}, [2526, '2024-01-28']), ('partial-repair probe', {'trial_end': [2024, 4, 1], 'anchor_day': 28, 'price': 78891}, [68712, '2024-04-28']), ('partial-repair probe', {'trial_end': [2024, 6, 4], 'anchor_day': 28, 'price': 999}, [773, '2024-06-28']), ('normal control', {'trial_end': [2025, 3, 15], 'anchor_day': 15, 'price': 2900}, [2900, '2025-04-15']), ('normal control', {'trial_end': [2023, 12, 15], 'anchor_day': 1, 'price': 47732}, [26176, '2024-01-01']), ('normal control', {'trial_end': [2024, 2, 8], 'anchor_day': 8, 'price': 999}, [999, '2024-03-08']), ('normal control', {'trial_end': [2024, 6, 25], 'anchor_day': 1, 'price': 2900}, [580, '2024-07-01'])], [('regression', {'trial_end': [2024, 1, 1], 'anchor_day': 28, 'price': 2900}, [2526, '2024-01-28']), ('regression', {'trial_end': [2025, 1, 2], 'anchor_day': 28, 'price': 999}, [838, '2025-01-28']), ('partial-repair probe', {'trial_end': [2024, 4, 10], 'anchor_day': 15, 'price': 2900}, [468, '2024-04-15']), ('partial-repair probe', {'trial_end': [2023, 10, 3], 'anchor_day': 16, 'price': 999}, [433, '2023-10-16']), ('normal control', {'trial_end': [2023, 12, 26], 'anchor_day': 21, 'price': 999}, [838, '2024-01-21']), ('normal control', {'trial_end': [2023, 5, 26], 'anchor_day': 1, 'price': 62316}, [12061, '2023-06-01']), ('normal control', {'trial_end': [2023, 4, 30], 'anchor_day': 15, 'price': 44760}, [22380, '2023-05-15']), ('normal control', {'trial_end': [2025, 5, 3], 'anchor_day': 1, 'price': 2900}, [2713, '2025-06-01'])], [('regression', {'trial_end': [2025, 1, 2], 'anchor_day': 28, 'price': 999}, [838, '2025-01-28']), ('regression', {'trial_end': [2024, 1, 7], 'anchor_day': 15, 'price': 28964}, [7475, '2024-01-15']), ('partial-repair probe', {'trial_end': [2023, 6, 18], 'anchor_day': 28, 'price': 2900}, [935, '2023-06-28']), ('partial-repair probe', {'trial_end': [2025, 3, 22], 'anchor_day': 28, 'price': 58121}, [12455, '2025-03-28']), ('normal control', {'trial_end': [2024, 6, 14], 'anchor_day': 1, 'price': 999}, [566, '2024-07-01']), ('normal control', {'trial_end': [2023, 5, 23], 'anchor_day': 15, 'price': 2900}, [2152, '2023-06-15']), ('normal control', {'trial_end': [2023, 5, 31], 'anchor_day': 4, 'price': 999}, [129, '2023-06-04']), ('normal control', {'trial_end': [2023, 3, 16], 'anchor_day': 15, 'price': 9250}, [8952, '2023-04-15'])], [('regression', {'trial_end': [2024, 1, 7], 'anchor_day': 15, 'price': 28964}, [7475, '2024-01-15']), ('regression', {'trial_end': [2025, 1, 2], 'anchor_day': 28, 'price': 2360}, [1979, '2025-01-28']), ('partial-repair probe', {'trial_end': [2024, 3, 15], 'anchor_day': 28, 'price': 999}, [448, '2024-03-28']), ('partial-repair probe', {'trial_end': [2024, 12, 11], 'anchor_day': 15, 'price': 2900}, [387, '2024-12-15']), ('normal control', {'trial_end': [2025, 2, 28], 'anchor_day': 1, 'price': 999}, [36, '2025-03-01']), ('normal control', {'trial_end': [2023, 8, 18], 'anchor_day': 1, 'price': 2900}, [1310, '2023-09-01']), ('normal control', {'trial_end': [2025, 1, 4], 'anchor_day': 1, 'price': 39775}, [35926, '2025-02-01']), ('normal control', {'trial_end': [2024, 7, 15], 'anchor_day': 15, 'price': 999}, [999, '2024-08-15'])]]
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[377, '2023-01-28'][741, '2023-01-28']Failed
regression 1[570, '2025-01-13'][1123, '2025-01-13']Failed
partial-repair probe 2[17, '2024-04-28'][32, '2024-04-28']Failed
partial-repair probe 3[570, '2024-12-28'][1160, '2024-12-28']Failed
normal control 4[2845, '2025-01-01'][2845, '2025-01-01']Passed
normal control 5[566, '2023-05-01'][566, '2023-05-01']Passed
normal control 6[999, '2023-07-15'][999, '2023-07-15']Passed
normal control 7[2806, '2024-01-15'][2806, '2024-01-15']Passed

SHA-256 / fdf3dbef7dc80da51f19447355fae4caa56aa58496912e607e0591705abd9340

3 / The verified repair

Exit 0
"""Failure Map reference implementation. Python standard library only."""
import json
import datetime
import calendar
N = 1
observations = []
def solve(x):
    t = datetime.date(*x['trial_end'])
    a = x['anchor_day']
    if t.day == a:
        ny, nm = (t.year + 1, 1) if t.month == 12 else (t.year, t.month + 1)
        return [x['price'], datetime.date(ny, nm, a).isoformat()]
    if t.day < a:
        nxt = datetime.date(t.year, t.month, a)
        py, pm = (t.year - 1, 12) if t.month == 1 else (t.year, t.month - 1)
        prev = datetime.date(py, pm, a)
    else:
        ey, em = (t.year + 1, 1) if t.month == 12 else (t.year, t.month + 1)
        nxt = datetime.date(ey, em, a)
        prev = datetime.date(t.year, t.month, a)
    days = (nxt - t).days
    cycle = (nxt - prev).days
    return [(x['price'] * days * 2 + cycle) // (2 * cycle), nxt.isoformat()]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'trial_end': [2023, 1, 5], 'anchor_day': 28, 'price': 999}, [741, '2023-01-28']), ('regression', {'trial_end': [2025, 1, 1], 'anchor_day': 13, 'price': 2900}, [1123, '2025-01-13']), ('partial-repair probe', {'trial_end': [2024, 4, 27], 'anchor_day': 28, 'price': 999}, [32, '2024-04-28']), ('partial-repair probe', {'trial_end': [2024, 12, 16], 'anchor_day': 28, 'price': 2900}, [1160, '2024-12-28']), ('normal control', {'trial_end': [2024, 12, 25], 'anchor_day': 1, 'price': 12600}, [2845, '2025-01-01']), ('normal control', {'trial_end': [2023, 4, 14], 'anchor_day': 1, 'price': 999}, [566, '2023-05-01']), ('normal control', {'trial_end': [2023, 6, 15], 'anchor_day': 15, 'price': 999}, [999, '2023-07-15']), ('normal control', {'trial_end': [2023, 12, 16], 'anchor_day': 15, 'price': 2900}, [2806, '2024-01-15'])], [('regression', {'trial_end': [2025, 1, 1], 'anchor_day': 13, 'price': 2900}, [1123, '2025-01-13']), ('regression', {'trial_end': [2024, 1, 1], 'anchor_day': 28, 'price': 2900}, [2526, '2024-01-28']), ('partial-repair probe', {'trial_end': [2024, 4, 1], 'anchor_day': 28, 'price': 78891}, [68712, '2024-04-28']), ('partial-repair probe', {'trial_end': [2024, 6, 4], 'anchor_day': 28, 'price': 999}, [773, '2024-06-28']), ('normal control', {'trial_end': [2025, 3, 15], 'anchor_day': 15, 'price': 2900}, [2900, '2025-04-15']), ('normal control', {'trial_end': [2023, 12, 15], 'anchor_day': 1, 'price': 47732}, [26176, '2024-01-01']), ('normal control', {'trial_end': [2024, 2, 8], 'anchor_day': 8, 'price': 999}, [999, '2024-03-08']), ('normal control', {'trial_end': [2024, 6, 25], 'anchor_day': 1, 'price': 2900}, [580, '2024-07-01'])], [('regression', {'trial_end': [2024, 1, 1], 'anchor_day': 28, 'price': 2900}, [2526, '2024-01-28']), ('regression', {'trial_end': [2025, 1, 2], 'anchor_day': 28, 'price': 999}, [838, '2025-01-28']), ('partial-repair probe', {'trial_end': [2024, 4, 10], 'anchor_day': 15, 'price': 2900}, [468, '2024-04-15']), ('partial-repair probe', {'trial_end': [2023, 10, 3], 'anchor_day': 16, 'price': 999}, [433, '2023-10-16']), ('normal control', {'trial_end': [2023, 12, 26], 'anchor_day': 21, 'price': 999}, [838, '2024-01-21']), ('normal control', {'trial_end': [2023, 5, 26], 'anchor_day': 1, 'price': 62316}, [12061, '2023-06-01']), ('normal control', {'trial_end': [2023, 4, 30], 'anchor_day': 15, 'price': 44760}, [22380, '2023-05-15']), ('normal control', {'trial_end': [2025, 5, 3], 'anchor_day': 1, 'price': 2900}, [2713, '2025-06-01'])], [('regression', {'trial_end': [2025, 1, 2], 'anchor_day': 28, 'price': 999}, [838, '2025-01-28']), ('regression', {'trial_end': [2024, 1, 7], 'anchor_day': 15, 'price': 28964}, [7475, '2024-01-15']), ('partial-repair probe', {'trial_end': [2023, 6, 18], 'anchor_day': 28, 'price': 2900}, [935, '2023-06-28']), ('partial-repair probe', {'trial_end': [2025, 3, 22], 'anchor_day': 28, 'price': 58121}, [12455, '2025-03-28']), ('normal control', {'trial_end': [2024, 6, 14], 'anchor_day': 1, 'price': 999}, [566, '2024-07-01']), ('normal control', {'trial_end': [2023, 5, 23], 'anchor_day': 15, 'price': 2900}, [2152, '2023-06-15']), ('normal control', {'trial_end': [2023, 5, 31], 'anchor_day': 4, 'price': 999}, [129, '2023-06-04']), ('normal control', {'trial_end': [2023, 3, 16], 'anchor_day': 15, 'price': 9250}, [8952, '2023-04-15'])], [('regression', {'trial_end': [2024, 1, 7], 'anchor_day': 15, 'price': 28964}, [7475, '2024-01-15']), ('regression', {'trial_end': [2025, 1, 2], 'anchor_day': 28, 'price': 2360}, [1979, '2025-01-28']), ('partial-repair probe', {'trial_end': [2024, 3, 15], 'anchor_day': 28, 'price': 999}, [448, '2024-03-28']), ('partial-repair probe', {'trial_end': [2024, 12, 11], 'anchor_day': 15, 'price': 2900}, [387, '2024-12-15']), ('normal control', {'trial_end': [2025, 2, 28], 'anchor_day': 1, 'price': 999}, [36, '2025-03-01']), ('normal control', {'trial_end': [2023, 8, 18], 'anchor_day': 1, 'price': 2900}, [1310, '2023-09-01']), ('normal control', {'trial_end': [2025, 1, 4], 'anchor_day': 1, 'price': 39775}, [35926, '2025-02-01']), ('normal control', {'trial_end': [2024, 7, 15], 'anchor_day': 15, 'price': 999}, [999, '2024-08-15'])]]
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[741, '2023-01-28'][741, '2023-01-28']Passed
regression 1[1123, '2025-01-13'][1123, '2025-01-13']Passed
partial-repair probe 2[32, '2024-04-28'][32, '2024-04-28']Passed
partial-repair probe 3[1160, '2024-12-28'][1160, '2024-12-28']Passed
normal control 4[2845, '2025-01-01'][2845, '2025-01-01']Passed
normal control 5[566, '2023-05-01'][566, '2023-05-01']Passed
normal control 6[999, '2023-07-15'][999, '2023-07-15']Passed
normal control 7[2806, '2024-01-15'][2806, '2024-01-15']Passed

SHA-256 / 28149ef1c434403d3803c9d2ba00915ff6c205e739155fe165bb22a97b9ace43

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

Case digest / 09b2f0f51fcfdb6be4dd9c0465c12a82cb5bdd97d2ef8361b8b874d1fcb5186c