FAILURE MAP
← Case archive

FA-59426 / Subscription proration billing / Open access

Trial conversion stub period: previous anchor date · case 01

Stub invoices for trials ending early in the month use a 30-day cycle regardless of the real anchor cycle.

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

ROOT CAUSE

The previous anchor is approximated as 30 days before the next anchor instead of the same day one month earlier.

VERIFIED REPAIR

Restore the contract rule at the previous anchor date step: use `prev = datetime.date(py, pm, a)`.

Unsuccessful approach: The attempt uses the first of the month as the previous anchor, shrinking the cycle to a partial month.

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 - 1, 12) if t.month == 1 else (t.year, t.month - 1)
        prev = nxt - datetime.timedelta(days=30)
    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': [2024, 4, 27], 'anchor_day': 28, 'price': 999}, [32, '2024-04-28']), ('regression', {'trial_end': [2024, 4, 1], 'anchor_day': 28, 'price': 78891}, [68712, '2024-04-28']), ('partial-repair probe', {'trial_end': [2024, 12, 16], 'anchor_day': 28, 'price': 2900}, [1160, '2024-12-28']), ('partial-repair probe', {'trial_end': [2025, 2, 6], 'anchor_day': 15, 'price': 2900}, [842, '2025-02-15']), ('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': [2024, 4, 1], 'anchor_day': 28, 'price': 78891}, [68712, '2024-04-28']), ('regression', {'trial_end': [2025, 2, 6], 'anchor_day': 15, 'price': 2900}, [842, '2025-02-15']), ('partial-repair probe', {'trial_end': [2024, 6, 4], 'anchor_day': 28, 'price': 999}, [773, '2024-06-28']), ('partial-repair probe', {'trial_end': [2024, 4, 10], 'anchor_day': 15, 'price': 2900}, [468, '2024-04-15']), ('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': [2025, 2, 6], 'anchor_day': 15, 'price': 2900}, [842, '2025-02-15']), ('regression', {'trial_end': [2024, 6, 4], 'anchor_day': 28, 'price': 999}, [773, '2024-06-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': [2024, 6, 4], 'anchor_day': 28, 'price': 999}, [773, '2024-06-28']), ('regression', {'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']), ('partial-repair probe', {'trial_end': [2023, 6, 18], 'anchor_day': 28, 'price': 2900}, [935, '2023-06-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, 4, 10], 'anchor_day': 15, 'price': 2900}, [468, '2024-04-15']), ('regression', {'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']), ('partial-repair probe', {'trial_end': [2024, 3, 15], 'anchor_day': 28, 'price': 999}, [448, '2024-03-28']), ('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[33, '2024-04-28'][32, '2024-04-28']Failed
regression 1[71002, '2024-04-28'][68712, '2024-04-28']Failed
partial-repair probe 2[1160, '2024-12-28'][1160, '2024-12-28']Passed
partial-repair probe 3[870, '2025-02-15'][842, '2025-02-15']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 / f520a4d155d1d46eb0f64f14bac737b3d1e94bd44e69ef600cb8bf43b1e2fc5c

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 = (t.year - 1, 12) if t.month == 1 else (t.year, t.month - 1)
        prev = datetime.date(t.year, t.month, 1)
    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': [2024, 4, 27], 'anchor_day': 28, 'price': 999}, [32, '2024-04-28']), ('regression', {'trial_end': [2024, 4, 1], 'anchor_day': 28, 'price': 78891}, [68712, '2024-04-28']), ('partial-repair probe', {'trial_end': [2024, 12, 16], 'anchor_day': 28, 'price': 2900}, [1160, '2024-12-28']), ('partial-repair probe', {'trial_end': [2025, 2, 6], 'anchor_day': 15, 'price': 2900}, [842, '2025-02-15']), ('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': [2024, 4, 1], 'anchor_day': 28, 'price': 78891}, [68712, '2024-04-28']), ('regression', {'trial_end': [2025, 2, 6], 'anchor_day': 15, 'price': 2900}, [842, '2025-02-15']), ('partial-repair probe', {'trial_end': [2024, 6, 4], 'anchor_day': 28, 'price': 999}, [773, '2024-06-28']), ('partial-repair probe', {'trial_end': [2024, 4, 10], 'anchor_day': 15, 'price': 2900}, [468, '2024-04-15']), ('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': [2025, 2, 6], 'anchor_day': 15, 'price': 2900}, [842, '2025-02-15']), ('regression', {'trial_end': [2024, 6, 4], 'anchor_day': 28, 'price': 999}, [773, '2024-06-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': [2024, 6, 4], 'anchor_day': 28, 'price': 999}, [773, '2024-06-28']), ('regression', {'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']), ('partial-repair probe', {'trial_end': [2023, 6, 18], 'anchor_day': 28, 'price': 2900}, [935, '2023-06-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, 4, 10], 'anchor_day': 15, 'price': 2900}, [468, '2024-04-15']), ('regression', {'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']), ('partial-repair probe', {'trial_end': [2024, 3, 15], 'anchor_day': 28, 'price': 999}, [448, '2024-03-28']), ('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[37, '2024-04-28'][32, '2024-04-28']Failed
regression 1[78891, '2024-04-28'][68712, '2024-04-28']Failed
partial-repair probe 2[1289, '2024-12-28'][1160, '2024-12-28']Failed
partial-repair probe 3[1864, '2025-02-15'][842, '2025-02-15']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 / 1a2f1c904bec40bc88623295e623169947b4a1024a616f300038b56591639cb2

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': [2024, 4, 27], 'anchor_day': 28, 'price': 999}, [32, '2024-04-28']), ('regression', {'trial_end': [2024, 4, 1], 'anchor_day': 28, 'price': 78891}, [68712, '2024-04-28']), ('partial-repair probe', {'trial_end': [2024, 12, 16], 'anchor_day': 28, 'price': 2900}, [1160, '2024-12-28']), ('partial-repair probe', {'trial_end': [2025, 2, 6], 'anchor_day': 15, 'price': 2900}, [842, '2025-02-15']), ('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': [2024, 4, 1], 'anchor_day': 28, 'price': 78891}, [68712, '2024-04-28']), ('regression', {'trial_end': [2025, 2, 6], 'anchor_day': 15, 'price': 2900}, [842, '2025-02-15']), ('partial-repair probe', {'trial_end': [2024, 6, 4], 'anchor_day': 28, 'price': 999}, [773, '2024-06-28']), ('partial-repair probe', {'trial_end': [2024, 4, 10], 'anchor_day': 15, 'price': 2900}, [468, '2024-04-15']), ('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': [2025, 2, 6], 'anchor_day': 15, 'price': 2900}, [842, '2025-02-15']), ('regression', {'trial_end': [2024, 6, 4], 'anchor_day': 28, 'price': 999}, [773, '2024-06-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': [2024, 6, 4], 'anchor_day': 28, 'price': 999}, [773, '2024-06-28']), ('regression', {'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']), ('partial-repair probe', {'trial_end': [2023, 6, 18], 'anchor_day': 28, 'price': 2900}, [935, '2023-06-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, 4, 10], 'anchor_day': 15, 'price': 2900}, [468, '2024-04-15']), ('regression', {'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']), ('partial-repair probe', {'trial_end': [2024, 3, 15], 'anchor_day': 28, 'price': 999}, [448, '2024-03-28']), ('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[32, '2024-04-28'][32, '2024-04-28']Passed
regression 1[68712, '2024-04-28'][68712, '2024-04-28']Passed
partial-repair probe 2[1160, '2024-12-28'][1160, '2024-12-28']Passed
partial-repair probe 3[842, '2025-02-15'][842, '2025-02-15']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 / 7b2d4a04dee39b1daa988ae4013690955451d157c954ef72668e61c4dc5b01dc

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

Case digest / 4d40218470004997b5fc86a224a1683df14777326a582d1d127c4a5c11b87a87