FAILURE MAP
← Case archive

FA-59421 / Subscription proration billing / Open access

Trial conversion stub period: stub cycle length · case 01

Stub invoices after a trial exceed the monthly price when the stub spans a 31-day cycle.

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

ROOT CAUSE

The stub cycle is fixed at 30 days instead of the actual anchor-to-anchor length.

VERIFIED REPAIR

Restore the contract rule at the stub cycle length step: use `cycle = (nxt - prev).days`.

Unsuccessful approach: The attempt uses the calendar month of the trial end, which differs from the anchor-to-anchor cycle.

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 = 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 = 30
    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': [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': [2025, 3, 15], 'anchor_day': 15, 'price': 2900}, [2900, '2025-04-15']), ('normal control', {'trial_end': [2024, 2, 8], 'anchor_day': 8, 'price': 999}, [999, '2024-03-08'])], [('regression', {'trial_end': [2024, 4, 1], 'anchor_day': 28, 'price': 78891}, [68712, '2024-04-28']), ('regression', {'trial_end': [2024, 12, 25], 'anchor_day': 1, 'price': 12600}, [2845, '2025-01-01']), ('partial-repair probe', {'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']), ('normal control', {'trial_end': [2024, 6, 25], 'anchor_day': 1, 'price': 2900}, [580, '2024-07-01']), ('normal control', {'trial_end': [2023, 4, 30], 'anchor_day': 15, 'price': 44760}, [22380, '2023-05-15']), ('normal control', {'trial_end': [2024, 6, 14], 'anchor_day': 1, 'price': 999}, [566, '2024-07-01']), ('normal control', {'trial_end': [2024, 7, 15], 'anchor_day': 15, 'price': 999}, [999, '2024-08-15'])], [('regression', {'trial_end': [2025, 2, 6], 'anchor_day': 15, 'price': 2900}, [842, '2025-02-15']), ('regression', {'trial_end': [2024, 12, 25], 'anchor_day': 1, 'price': 12600}, [2845, '2025-01-01']), ('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': [2023, 3, 26], 'anchor_day': 26, 'price': 2900}, [2900, '2023-04-26']), ('normal control', {'trial_end': [2023, 5, 22], 'anchor_day': 22, 'price': 47810}, [47810, '2023-06-22']), ('normal control', {'trial_end': [2025, 6, 10], 'anchor_day': 10, 'price': 999}, [999, '2025-07-10']), ('normal control', {'trial_end': [2023, 12, 2], 'anchor_day': 2, 'price': 999}, [999, '2024-01-02'])], [('regression', {'trial_end': [2024, 6, 4], 'anchor_day': 28, 'price': 999}, [773, '2024-06-28']), ('regression', {'trial_end': [2025, 2, 6], 'anchor_day': 15, 'price': 2900}, [842, '2025-02-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': [2023, 5, 29], 'anchor_day': 29, 'price': 15548}, [15548, '2023-06-29']), ('normal control', {'trial_end': [2024, 6, 15], 'anchor_day': 15, 'price': 8594}, [8594, '2024-07-15']), ('normal control', {'trial_end': [2023, 4, 17], 'anchor_day': 1, 'price': 2900}, [1353, '2023-05-01']), ('normal control', {'trial_end': [2023, 4, 6], 'anchor_day': 6, 'price': 999}, [999, '2023-05-06'])], [('regression', {'trial_end': [2024, 4, 10], 'anchor_day': 15, 'price': 2900}, [468, '2024-04-15']), ('regression', {'trial_end': [2023, 12, 16], 'anchor_day': 15, 'price': 2900}, [2806, '2024-01-15']), ('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': [2023, 11, 28], 'anchor_day': 28, 'price': 2900}, [2900, '2023-12-28']), ('normal control', {'trial_end': [2024, 4, 11], 'anchor_day': 1, 'price': 999}, [666, '2024-05-01']), ('normal control', {'trial_end': [2023, 3, 1], 'anchor_day': 1, 'price': 7363}, [7363, '2023-04-01']), ('normal control', {'trial_end': [2025, 4, 29], 'anchor_day': 15, 'price': 2900}, [1547, '2025-05-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[566, '2023-05-01'][566, '2023-05-01']Passed
normal control 5[999, '2023-07-15'][999, '2023-07-15']Passed
normal control 6[2900, '2025-04-15'][2900, '2025-04-15']Passed
normal control 7[999, '2024-03-08'][999, '2024-03-08']Passed

SHA-256 / 11e98f2c2b4c154529d50c45a6fa7377b88ba5a0d9587f3adf49e83f9f8fd765

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(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 = (datetime.date(t.year + t.month // 12, t.month % 12 + 1, 1) - datetime.date(t.year, t.month, 1)).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': [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': [2025, 3, 15], 'anchor_day': 15, 'price': 2900}, [2900, '2025-04-15']), ('normal control', {'trial_end': [2024, 2, 8], 'anchor_day': 8, 'price': 999}, [999, '2024-03-08'])], [('regression', {'trial_end': [2024, 4, 1], 'anchor_day': 28, 'price': 78891}, [68712, '2024-04-28']), ('regression', {'trial_end': [2024, 12, 25], 'anchor_day': 1, 'price': 12600}, [2845, '2025-01-01']), ('partial-repair probe', {'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']), ('normal control', {'trial_end': [2024, 6, 25], 'anchor_day': 1, 'price': 2900}, [580, '2024-07-01']), ('normal control', {'trial_end': [2023, 4, 30], 'anchor_day': 15, 'price': 44760}, [22380, '2023-05-15']), ('normal control', {'trial_end': [2024, 6, 14], 'anchor_day': 1, 'price': 999}, [566, '2024-07-01']), ('normal control', {'trial_end': [2024, 7, 15], 'anchor_day': 15, 'price': 999}, [999, '2024-08-15'])], [('regression', {'trial_end': [2025, 2, 6], 'anchor_day': 15, 'price': 2900}, [842, '2025-02-15']), ('regression', {'trial_end': [2024, 12, 25], 'anchor_day': 1, 'price': 12600}, [2845, '2025-01-01']), ('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': [2023, 3, 26], 'anchor_day': 26, 'price': 2900}, [2900, '2023-04-26']), ('normal control', {'trial_end': [2023, 5, 22], 'anchor_day': 22, 'price': 47810}, [47810, '2023-06-22']), ('normal control', {'trial_end': [2025, 6, 10], 'anchor_day': 10, 'price': 999}, [999, '2025-07-10']), ('normal control', {'trial_end': [2023, 12, 2], 'anchor_day': 2, 'price': 999}, [999, '2024-01-02'])], [('regression', {'trial_end': [2024, 6, 4], 'anchor_day': 28, 'price': 999}, [773, '2024-06-28']), ('regression', {'trial_end': [2025, 2, 6], 'anchor_day': 15, 'price': 2900}, [842, '2025-02-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': [2023, 5, 29], 'anchor_day': 29, 'price': 15548}, [15548, '2023-06-29']), ('normal control', {'trial_end': [2024, 6, 15], 'anchor_day': 15, 'price': 8594}, [8594, '2024-07-15']), ('normal control', {'trial_end': [2023, 4, 17], 'anchor_day': 1, 'price': 2900}, [1353, '2023-05-01']), ('normal control', {'trial_end': [2023, 4, 6], 'anchor_day': 6, 'price': 999}, [999, '2023-05-06'])], [('regression', {'trial_end': [2024, 4, 10], 'anchor_day': 15, 'price': 2900}, [468, '2024-04-15']), ('regression', {'trial_end': [2023, 12, 16], 'anchor_day': 15, 'price': 2900}, [2806, '2024-01-15']), ('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': [2023, 11, 28], 'anchor_day': 28, 'price': 2900}, [2900, '2023-12-28']), ('normal control', {'trial_end': [2024, 4, 11], 'anchor_day': 1, 'price': 999}, [666, '2024-05-01']), ('normal control', {'trial_end': [2023, 3, 1], 'anchor_day': 1, 'price': 7363}, [7363, '2023-04-01']), ('normal control', {'trial_end': [2025, 4, 29], 'anchor_day': 15, 'price': 2900}, [1547, '2025-05-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[1123, '2024-12-28'][1160, '2024-12-28']Failed
partial-repair probe 3[932, '2025-02-15'][842, '2025-02-15']Failed
normal control 4[566, '2023-05-01'][566, '2023-05-01']Passed
normal control 5[999, '2023-07-15'][999, '2023-07-15']Passed
normal control 6[2900, '2025-04-15'][2900, '2025-04-15']Passed
normal control 7[999, '2024-03-08'][999, '2024-03-08']Passed

SHA-256 / 7b676b326d421b13d54de7fe3eff2e74d7149b6eeda3564aca63fdc66facaf76

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': [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': [2025, 3, 15], 'anchor_day': 15, 'price': 2900}, [2900, '2025-04-15']), ('normal control', {'trial_end': [2024, 2, 8], 'anchor_day': 8, 'price': 999}, [999, '2024-03-08'])], [('regression', {'trial_end': [2024, 4, 1], 'anchor_day': 28, 'price': 78891}, [68712, '2024-04-28']), ('regression', {'trial_end': [2024, 12, 25], 'anchor_day': 1, 'price': 12600}, [2845, '2025-01-01']), ('partial-repair probe', {'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']), ('normal control', {'trial_end': [2024, 6, 25], 'anchor_day': 1, 'price': 2900}, [580, '2024-07-01']), ('normal control', {'trial_end': [2023, 4, 30], 'anchor_day': 15, 'price': 44760}, [22380, '2023-05-15']), ('normal control', {'trial_end': [2024, 6, 14], 'anchor_day': 1, 'price': 999}, [566, '2024-07-01']), ('normal control', {'trial_end': [2024, 7, 15], 'anchor_day': 15, 'price': 999}, [999, '2024-08-15'])], [('regression', {'trial_end': [2025, 2, 6], 'anchor_day': 15, 'price': 2900}, [842, '2025-02-15']), ('regression', {'trial_end': [2024, 12, 25], 'anchor_day': 1, 'price': 12600}, [2845, '2025-01-01']), ('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': [2023, 3, 26], 'anchor_day': 26, 'price': 2900}, [2900, '2023-04-26']), ('normal control', {'trial_end': [2023, 5, 22], 'anchor_day': 22, 'price': 47810}, [47810, '2023-06-22']), ('normal control', {'trial_end': [2025, 6, 10], 'anchor_day': 10, 'price': 999}, [999, '2025-07-10']), ('normal control', {'trial_end': [2023, 12, 2], 'anchor_day': 2, 'price': 999}, [999, '2024-01-02'])], [('regression', {'trial_end': [2024, 6, 4], 'anchor_day': 28, 'price': 999}, [773, '2024-06-28']), ('regression', {'trial_end': [2025, 2, 6], 'anchor_day': 15, 'price': 2900}, [842, '2025-02-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': [2023, 5, 29], 'anchor_day': 29, 'price': 15548}, [15548, '2023-06-29']), ('normal control', {'trial_end': [2024, 6, 15], 'anchor_day': 15, 'price': 8594}, [8594, '2024-07-15']), ('normal control', {'trial_end': [2023, 4, 17], 'anchor_day': 1, 'price': 2900}, [1353, '2023-05-01']), ('normal control', {'trial_end': [2023, 4, 6], 'anchor_day': 6, 'price': 999}, [999, '2023-05-06'])], [('regression', {'trial_end': [2024, 4, 10], 'anchor_day': 15, 'price': 2900}, [468, '2024-04-15']), ('regression', {'trial_end': [2023, 12, 16], 'anchor_day': 15, 'price': 2900}, [2806, '2024-01-15']), ('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': [2023, 11, 28], 'anchor_day': 28, 'price': 2900}, [2900, '2023-12-28']), ('normal control', {'trial_end': [2024, 4, 11], 'anchor_day': 1, 'price': 999}, [666, '2024-05-01']), ('normal control', {'trial_end': [2023, 3, 1], 'anchor_day': 1, 'price': 7363}, [7363, '2023-04-01']), ('normal control', {'trial_end': [2025, 4, 29], 'anchor_day': 15, 'price': 2900}, [1547, '2025-05-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[566, '2023-05-01'][566, '2023-05-01']Passed
normal control 5[999, '2023-07-15'][999, '2023-07-15']Passed
normal control 6[2900, '2025-04-15'][2900, '2025-04-15']Passed
normal control 7[999, '2024-03-08'][999, '2024-03-08']Passed

SHA-256 / a2c56f9dd3397cdc5d4c143530b07587df7c83483c3be84a15d16a51b4ac7f2d

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

Case digest / c5afbc96cc4aebdb40a6154fd277b64ddaa9d11c898ee0b75b68a52aa2da413c