FAILURE MAP
← Case archive

FA-68626 / Toll and parking fee computation / Open access

Prepaid toll account auto-replenishment: the minimum replenishment acts as a ceiling · case 01

Prepaid toll account auto-replenishment returns a wrong result when the minimum replenishment acts as a ceiling.

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

ROOT CAUSE

Heavy users are replenished only the minimum, draining the account repeatedly.

VERIFIED REPAIR

Restore the replenish minimum rule so that the step reads `max(x['min_replenish'],`.

Unsuccessful approach: Adding the minimum to the usage-based amount overcharges the card.

Case contract

Input {balance, charges, threshold, min_replenish, usage_30d, card_ok}. The replenish amount is max(min_replenish, ceil(usage_30d/4) rounded up to a multiple of 500). After each charge, if the balance is strictly below threshold and the card works, one replenishment is added. first_negative is the index of the first charge after which the balance is negative (or null). Return {balance, replenished, first_negative}.

Why this case matters

Fee engines bill customers in integer cents; a wrong boundary, rounding stage or cap scope silently over- or under-charges.

1 / The failure

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

N = 1
observations = []
def solve(x):
    bal = x['balance']
    n = 0
    first = None
    amt = min(x['min_replenish'], -(-x['usage_30d'] // 2000) * 500)
    for i, c in enumerate(x['charges']):
        bal -= c
        if bal < x['threshold'] and x['card_ok']:
            bal += amt
            n += 1
        if bal < 0 and first is None:
            first = i
    return {'balance': bal, 'replenished': n, 'first_negative': first}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'balance': 1400, 'charges': [400, 150], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 3350, 'replenished': 1, 'first_negative': None}), ({'balance': 1400, 'charges': [400], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 1000, 'replenished': 0, 'first_negative': None}), ({'balance': 300, 'charges': [400, 150, 275], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': -525, 'replenished': 0, 'first_negative': 0}), ({'balance': 1707, 'charges': [1200, 275, 1200, 3000, 400, 650, 1200, 400], 'threshold': 500, 'min_replenish': 2000, 'usage_30d': 8158, 'card_ok': True}, {'balance': 882, 'replenished': 3, 'first_negative': None}), ({'balance': 3418, 'charges': [1200, 650], 'threshold': 1500, 'min_replenish': 2500, 'usage_30d': 8208, 'card_ok': True}, {'balance': 1568, 'replenished': 0, 'first_negative': None}), ({'balance': 2115, 'charges': [275, 650], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9524, 'card_ok': True}, {'balance': 1190, 'replenished': 0, 'first_negative': None}), ({'balance': -378, 'charges': [150, 650], 'threshold': 1500, 'min_replenish': 2000, 'usage_30d': 3777, 'card_ok': True}, {'balance': 2822, 'replenished': 2, 'first_negative': None}), ({'balance': 2921, 'charges': [650, 400, 3000, 650, 275], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 6113, 'card_ok': True}, {'balance': 1946, 'replenished': 2, 'first_negative': None})], [({'balance': 1400, 'charges': [400], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 1000, 'replenished': 0, 'first_negative': None}), ({'balance': 3451, 'charges': [275, 150, 3000, 275, 3000, 275, 275], 'threshold': 500, 'min_replenish': 2500, 'usage_30d': 5768, 'card_ok': False}, {'balance': -3799, 'replenished': 0, 'first_negative': 3}), ({'balance': 1654, 'charges': [3000, 275, 150, 150, 275, 3000, 150, 3000], 'threshold': 1500, 'min_replenish': 2000, 'usage_30d': 17737, 'card_ok': False}, {'balance': -8346, 'replenished': 0, 'first_negative': 0}), ({'balance': 300, 'charges': [400, 150, 275], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': -525, 'replenished': 0, 'first_negative': 0}), ({'balance': 400, 'charges': [400], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': 0, 'replenished': 0, 'first_negative': None}), ({'balance': 245, 'charges': [400], 'threshold': 1500, 'min_replenish': 1000, 'usage_30d': 19631, 'card_ok': True}, {'balance': 4845, 'replenished': 1, 'first_negative': None}), ({'balance': 586, 'charges': [275, 1200, 150, 1200], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 10288, 'card_ok': True}, {'balance': 3761, 'replenished': 2, 'first_negative': None}), ({'balance': 3891, 'charges': [400, 400, 3000], 'threshold': 1500, 'min_replenish': 1000, 'usage_30d': 4479, 'card_ok': True}, {'balance': 1591, 'replenished': 1, 'first_negative': None})], [({'balance': 1400, 'charges': [400], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 1000, 'replenished': 0, 'first_negative': None}), ({'balance': 300, 'charges': [400, 150, 275], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': -525, 'replenished': 0, 'first_negative': 0}), ({'balance': 1400, 'charges': [400, 150], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 3350, 'replenished': 1, 'first_negative': None}), ({'balance': 2953, 'charges': [150, 275, 400, 3000, 275], 'threshold': 500, 'min_replenish': 2500, 'usage_30d': 2114, 'card_ok': False}, {'balance': -1147, 'replenished': 0, 'first_negative': 3}), ({'balance': 1665, 'charges': [275, 1200, 650, 150, 400, 650, 1200, 400], 'threshold': 1000, 'min_replenish': 2500, 'usage_30d': 4211, 'card_ok': True}, {'balance': 1740, 'replenished': 2, 'first_negative': None}), ({'balance': 2509, 'charges': [275], 'threshold': 1000, 'min_replenish': 2500, 'usage_30d': 14637, 'card_ok': True}, {'balance': 2234, 'replenished': 0, 'first_negative': None}), ({'balance': 3938, 'charges': [150, 1200], 'threshold': 500, 'min_replenish': 2000, 'usage_30d': 160, 'card_ok': True}, {'balance': 2588, 'replenished': 0, 'first_negative': None}), ({'balance': 1796, 'charges': [650, 400, 1200, 150, 3000, 150, 275, 1200], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 17989, 'card_ok': True}, {'balance': 3771, 'replenished': 2, 'first_negative': None})], [({'balance': 2033, 'charges': [3000, 650, 1200, 275, 3000, 3000, 650, 400], 'threshold': 1500, 'min_replenish': 1000, 'usage_30d': 18614, 'card_ok': True}, {'balance': 4858, 'replenished': 3, 'first_negative': None}), ({'balance': 2484, 'charges': [650, 150, 1200, 1200, 400, 150, 650, 150], 'threshold': 1000, 'min_replenish': 2000, 'usage_30d': 18653, 'card_ok': False}, {'balance': -2066, 'replenished': 0, 'first_negative': 3}), ({'balance': 400, 'charges': [400], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': 0, 'replenished': 0, 'first_negative': None}), ({'balance': 2629, 'charges': [3000, 275, 150], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 12751, 'card_ok': True}, {'balance': 2704, 'replenished': 1, 'first_negative': None}), ({'balance': 1400, 'charges': [400, 150], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 3350, 'replenished': 1, 'first_negative': None}), ({'balance': 3615, 'charges': [650, 400, 1200, 150, 650], 'threshold': 1500, 'min_replenish': 1000, 'usage_30d': 16149, 'card_ok': True}, {'balance': 5065, 'replenished': 1, 'first_negative': None}), ({'balance': 725, 'charges': [150, 1200, 3000, 275], 'threshold': 1500, 'min_replenish': 2000, 'usage_30d': 12916, 'card_ok': False}, {'balance': -3900, 'replenished': 0, 'first_negative': 1}), ({'balance': 1400, 'charges': [400], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 1000, 'replenished': 0, 'first_negative': None})], [({'balance': 1270, 'charges': [1200, 150, 3000, 400, 650, 150, 650, 1200], 'threshold': 1500, 'min_replenish': 2000, 'usage_30d': 16340, 'card_ok': False}, {'balance': -6130, 'replenished': 0, 'first_negative': 1}), ({'balance': 300, 'charges': [400, 150, 275], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': -525, 'replenished': 0, 'first_negative': 0}), ({'balance': 3058, 'charges': [150, 1200, 275, 1200], 'threshold': 500, 'min_replenish': 2000, 'usage_30d': 19841, 'card_ok': True}, {'balance': 5233, 'replenished': 1, 'first_negative': None}), ({'balance': 2750, 'charges': [275, 150, 400, 3000, 150], 'threshold': 1500, 'min_replenish': 1000, 'usage_30d': 6142, 'card_ok': True}, {'balance': 2775, 'replenished': 2, 'first_negative': None}), ({'balance': 1212, 'charges': [275, 400, 400], 'threshold': 500, 'min_replenish': 2500, 'usage_30d': 9849, 'card_ok': False}, {'balance': 137, 'replenished': 0, 'first_negative': None}), ({'balance': 1525, 'charges': [275, 1200, 650, 400, 1200, 3000], 'threshold': 1000, 'min_replenish': 2000, 'usage_30d': 8087, 'card_ok': True}, {'balance': 2300, 'replenished': 3, 'first_negative': None}), ({'balance': 400, 'charges': [400], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': 0, 'replenished': 0, 'first_negative': None}), ({'balance': 1400, 'charges': [400, 150], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 3350, 'replenished': 1, 'first_negative': None})]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check('fee oracle' + ' %d' % 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
fee oracle 0{'balance': 1850, 'first_negative': None, 'replenished': 1}{'balance': 3350, 'first_negative': None, 'replenished': 1}Failed
fee oracle 1{'balance': 1000, 'first_negative': None, 'replenished': 0}{'balance': 1000, 'first_negative': None, 'replenished': 0}Passed
fee oracle 2{'balance': -525, 'first_negative': 0, 'replenished': 0}{'balance': -525, 'first_negative': 0, 'replenished': 0}Passed
fee oracle 3{'balance': 1382, 'first_negative': None, 'replenished': 4}{'balance': 882, 'first_negative': None, 'replenished': 3}Failed
fee oracle 4{'balance': 1568, 'first_negative': None, 'replenished': 0}{'balance': 1568, 'first_negative': None, 'replenished': 0}Passed
fee oracle 5{'balance': 1190, 'first_negative': None, 'replenished': 0}{'balance': 1190, 'first_negative': None, 'replenished': 0}Passed
fee oracle 6{'balance': 822, 'first_negative': None, 'replenished': 2}{'balance': 2822, 'first_negative': None, 'replenished': 2}Failed
fee oracle 7{'balance': 946, 'first_negative': 2, 'replenished': 3}{'balance': 1946, 'first_negative': None, 'replenished': 2}Failed

SHA-256 / b6631e865fac370527d30436119c72ff4a0911a49fc47bcd30ad37b2044e1462

2 / The unsuccessful fix

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

N = 1
observations = []
def solve(x):
    bal = x['balance']
    n = 0
    first = None
    amt = (x['min_replenish'] + -(-x['usage_30d'] // 2000) * 500)
    for i, c in enumerate(x['charges']):
        bal -= c
        if bal < x['threshold'] and x['card_ok']:
            bal += amt
            n += 1
        if bal < 0 and first is None:
            first = i
    return {'balance': bal, 'replenished': n, 'first_negative': first}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'balance': 1400, 'charges': [400, 150], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 3350, 'replenished': 1, 'first_negative': None}), ({'balance': 1400, 'charges': [400], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 1000, 'replenished': 0, 'first_negative': None}), ({'balance': 300, 'charges': [400, 150, 275], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': -525, 'replenished': 0, 'first_negative': 0}), ({'balance': 1707, 'charges': [1200, 275, 1200, 3000, 400, 650, 1200, 400], 'threshold': 500, 'min_replenish': 2000, 'usage_30d': 8158, 'card_ok': True}, {'balance': 882, 'replenished': 3, 'first_negative': None}), ({'balance': 3418, 'charges': [1200, 650], 'threshold': 1500, 'min_replenish': 2500, 'usage_30d': 8208, 'card_ok': True}, {'balance': 1568, 'replenished': 0, 'first_negative': None}), ({'balance': 2115, 'charges': [275, 650], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9524, 'card_ok': True}, {'balance': 1190, 'replenished': 0, 'first_negative': None}), ({'balance': -378, 'charges': [150, 650], 'threshold': 1500, 'min_replenish': 2000, 'usage_30d': 3777, 'card_ok': True}, {'balance': 2822, 'replenished': 2, 'first_negative': None}), ({'balance': 2921, 'charges': [650, 400, 3000, 650, 275], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 6113, 'card_ok': True}, {'balance': 1946, 'replenished': 2, 'first_negative': None})], [({'balance': 1400, 'charges': [400], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 1000, 'replenished': 0, 'first_negative': None}), ({'balance': 3451, 'charges': [275, 150, 3000, 275, 3000, 275, 275], 'threshold': 500, 'min_replenish': 2500, 'usage_30d': 5768, 'card_ok': False}, {'balance': -3799, 'replenished': 0, 'first_negative': 3}), ({'balance': 1654, 'charges': [3000, 275, 150, 150, 275, 3000, 150, 3000], 'threshold': 1500, 'min_replenish': 2000, 'usage_30d': 17737, 'card_ok': False}, {'balance': -8346, 'replenished': 0, 'first_negative': 0}), ({'balance': 300, 'charges': [400, 150, 275], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': -525, 'replenished': 0, 'first_negative': 0}), ({'balance': 400, 'charges': [400], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': 0, 'replenished': 0, 'first_negative': None}), ({'balance': 245, 'charges': [400], 'threshold': 1500, 'min_replenish': 1000, 'usage_30d': 19631, 'card_ok': True}, {'balance': 4845, 'replenished': 1, 'first_negative': None}), ({'balance': 586, 'charges': [275, 1200, 150, 1200], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 10288, 'card_ok': True}, {'balance': 3761, 'replenished': 2, 'first_negative': None}), ({'balance': 3891, 'charges': [400, 400, 3000], 'threshold': 1500, 'min_replenish': 1000, 'usage_30d': 4479, 'card_ok': True}, {'balance': 1591, 'replenished': 1, 'first_negative': None})], [({'balance': 1400, 'charges': [400], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 1000, 'replenished': 0, 'first_negative': None}), ({'balance': 300, 'charges': [400, 150, 275], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': -525, 'replenished': 0, 'first_negative': 0}), ({'balance': 1400, 'charges': [400, 150], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 3350, 'replenished': 1, 'first_negative': None}), ({'balance': 2953, 'charges': [150, 275, 400, 3000, 275], 'threshold': 500, 'min_replenish': 2500, 'usage_30d': 2114, 'card_ok': False}, {'balance': -1147, 'replenished': 0, 'first_negative': 3}), ({'balance': 1665, 'charges': [275, 1200, 650, 150, 400, 650, 1200, 400], 'threshold': 1000, 'min_replenish': 2500, 'usage_30d': 4211, 'card_ok': True}, {'balance': 1740, 'replenished': 2, 'first_negative': None}), ({'balance': 2509, 'charges': [275], 'threshold': 1000, 'min_replenish': 2500, 'usage_30d': 14637, 'card_ok': True}, {'balance': 2234, 'replenished': 0, 'first_negative': None}), ({'balance': 3938, 'charges': [150, 1200], 'threshold': 500, 'min_replenish': 2000, 'usage_30d': 160, 'card_ok': True}, {'balance': 2588, 'replenished': 0, 'first_negative': None}), ({'balance': 1796, 'charges': [650, 400, 1200, 150, 3000, 150, 275, 1200], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 17989, 'card_ok': True}, {'balance': 3771, 'replenished': 2, 'first_negative': None})], [({'balance': 2033, 'charges': [3000, 650, 1200, 275, 3000, 3000, 650, 400], 'threshold': 1500, 'min_replenish': 1000, 'usage_30d': 18614, 'card_ok': True}, {'balance': 4858, 'replenished': 3, 'first_negative': None}), ({'balance': 2484, 'charges': [650, 150, 1200, 1200, 400, 150, 650, 150], 'threshold': 1000, 'min_replenish': 2000, 'usage_30d': 18653, 'card_ok': False}, {'balance': -2066, 'replenished': 0, 'first_negative': 3}), ({'balance': 400, 'charges': [400], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': 0, 'replenished': 0, 'first_negative': None}), ({'balance': 2629, 'charges': [3000, 275, 150], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 12751, 'card_ok': True}, {'balance': 2704, 'replenished': 1, 'first_negative': None}), ({'balance': 1400, 'charges': [400, 150], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 3350, 'replenished': 1, 'first_negative': None}), ({'balance': 3615, 'charges': [650, 400, 1200, 150, 650], 'threshold': 1500, 'min_replenish': 1000, 'usage_30d': 16149, 'card_ok': True}, {'balance': 5065, 'replenished': 1, 'first_negative': None}), ({'balance': 725, 'charges': [150, 1200, 3000, 275], 'threshold': 1500, 'min_replenish': 2000, 'usage_30d': 12916, 'card_ok': False}, {'balance': -3900, 'replenished': 0, 'first_negative': 1}), ({'balance': 1400, 'charges': [400], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 1000, 'replenished': 0, 'first_negative': None})], [({'balance': 1270, 'charges': [1200, 150, 3000, 400, 650, 150, 650, 1200], 'threshold': 1500, 'min_replenish': 2000, 'usage_30d': 16340, 'card_ok': False}, {'balance': -6130, 'replenished': 0, 'first_negative': 1}), ({'balance': 300, 'charges': [400, 150, 275], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': -525, 'replenished': 0, 'first_negative': 0}), ({'balance': 3058, 'charges': [150, 1200, 275, 1200], 'threshold': 500, 'min_replenish': 2000, 'usage_30d': 19841, 'card_ok': True}, {'balance': 5233, 'replenished': 1, 'first_negative': None}), ({'balance': 2750, 'charges': [275, 150, 400, 3000, 150], 'threshold': 1500, 'min_replenish': 1000, 'usage_30d': 6142, 'card_ok': True}, {'balance': 2775, 'replenished': 2, 'first_negative': None}), ({'balance': 1212, 'charges': [275, 400, 400], 'threshold': 500, 'min_replenish': 2500, 'usage_30d': 9849, 'card_ok': False}, {'balance': 137, 'replenished': 0, 'first_negative': None}), ({'balance': 1525, 'charges': [275, 1200, 650, 400, 1200, 3000], 'threshold': 1000, 'min_replenish': 2000, 'usage_30d': 8087, 'card_ok': True}, {'balance': 2300, 'replenished': 3, 'first_negative': None}), ({'balance': 400, 'charges': [400], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': 0, 'replenished': 0, 'first_negative': None}), ({'balance': 1400, 'charges': [400, 150], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 3350, 'replenished': 1, 'first_negative': None})]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check('fee oracle' + ' %d' % 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
fee oracle 0{'balance': 4350, 'first_negative': None, 'replenished': 1}{'balance': 3350, 'first_negative': None, 'replenished': 1}Failed
fee oracle 1{'balance': 1000, 'first_negative': None, 'replenished': 0}{'balance': 1000, 'first_negative': None, 'replenished': 0}Passed
fee oracle 2{'balance': -525, 'first_negative': 0, 'replenished': 0}{'balance': -525, 'first_negative': 0, 'replenished': 0}Passed
fee oracle 3{'balance': 2382, 'first_negative': None, 'replenished': 2}{'balance': 882, 'first_negative': None, 'replenished': 3}Failed
fee oracle 4{'balance': 1568, 'first_negative': None, 'replenished': 0}{'balance': 1568, 'first_negative': None, 'replenished': 0}Passed
fee oracle 5{'balance': 1190, 'first_negative': None, 'replenished': 0}{'balance': 1190, 'first_negative': None, 'replenished': 0}Passed
fee oracle 6{'balance': 1822, 'first_negative': None, 'replenished': 1}{'balance': 2822, 'first_negative': None, 'replenished': 2}Failed
fee oracle 7{'balance': 3946, 'first_negative': None, 'replenished': 2}{'balance': 1946, 'first_negative': None, 'replenished': 2}Failed

SHA-256 / 64ce4f0980e0a84464833caa819540255819459e04d166ac21bddbe5a33577bf

3 / The verified repair

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

N = 1
observations = []
def solve(x):
    bal = x['balance']
    n = 0
    first = None
    amt = max(x['min_replenish'], -(-x['usage_30d'] // 2000) * 500)
    for i, c in enumerate(x['charges']):
        bal -= c
        if bal < x['threshold'] and x['card_ok']:
            bal += amt
            n += 1
        if bal < 0 and first is None:
            first = i
    return {'balance': bal, 'replenished': n, 'first_negative': first}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'balance': 1400, 'charges': [400, 150], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 3350, 'replenished': 1, 'first_negative': None}), ({'balance': 1400, 'charges': [400], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 1000, 'replenished': 0, 'first_negative': None}), ({'balance': 300, 'charges': [400, 150, 275], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': -525, 'replenished': 0, 'first_negative': 0}), ({'balance': 1707, 'charges': [1200, 275, 1200, 3000, 400, 650, 1200, 400], 'threshold': 500, 'min_replenish': 2000, 'usage_30d': 8158, 'card_ok': True}, {'balance': 882, 'replenished': 3, 'first_negative': None}), ({'balance': 3418, 'charges': [1200, 650], 'threshold': 1500, 'min_replenish': 2500, 'usage_30d': 8208, 'card_ok': True}, {'balance': 1568, 'replenished': 0, 'first_negative': None}), ({'balance': 2115, 'charges': [275, 650], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9524, 'card_ok': True}, {'balance': 1190, 'replenished': 0, 'first_negative': None}), ({'balance': -378, 'charges': [150, 650], 'threshold': 1500, 'min_replenish': 2000, 'usage_30d': 3777, 'card_ok': True}, {'balance': 2822, 'replenished': 2, 'first_negative': None}), ({'balance': 2921, 'charges': [650, 400, 3000, 650, 275], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 6113, 'card_ok': True}, {'balance': 1946, 'replenished': 2, 'first_negative': None})], [({'balance': 1400, 'charges': [400], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 1000, 'replenished': 0, 'first_negative': None}), ({'balance': 3451, 'charges': [275, 150, 3000, 275, 3000, 275, 275], 'threshold': 500, 'min_replenish': 2500, 'usage_30d': 5768, 'card_ok': False}, {'balance': -3799, 'replenished': 0, 'first_negative': 3}), ({'balance': 1654, 'charges': [3000, 275, 150, 150, 275, 3000, 150, 3000], 'threshold': 1500, 'min_replenish': 2000, 'usage_30d': 17737, 'card_ok': False}, {'balance': -8346, 'replenished': 0, 'first_negative': 0}), ({'balance': 300, 'charges': [400, 150, 275], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': -525, 'replenished': 0, 'first_negative': 0}), ({'balance': 400, 'charges': [400], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': 0, 'replenished': 0, 'first_negative': None}), ({'balance': 245, 'charges': [400], 'threshold': 1500, 'min_replenish': 1000, 'usage_30d': 19631, 'card_ok': True}, {'balance': 4845, 'replenished': 1, 'first_negative': None}), ({'balance': 586, 'charges': [275, 1200, 150, 1200], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 10288, 'card_ok': True}, {'balance': 3761, 'replenished': 2, 'first_negative': None}), ({'balance': 3891, 'charges': [400, 400, 3000], 'threshold': 1500, 'min_replenish': 1000, 'usage_30d': 4479, 'card_ok': True}, {'balance': 1591, 'replenished': 1, 'first_negative': None})], [({'balance': 1400, 'charges': [400], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 1000, 'replenished': 0, 'first_negative': None}), ({'balance': 300, 'charges': [400, 150, 275], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': -525, 'replenished': 0, 'first_negative': 0}), ({'balance': 1400, 'charges': [400, 150], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 3350, 'replenished': 1, 'first_negative': None}), ({'balance': 2953, 'charges': [150, 275, 400, 3000, 275], 'threshold': 500, 'min_replenish': 2500, 'usage_30d': 2114, 'card_ok': False}, {'balance': -1147, 'replenished': 0, 'first_negative': 3}), ({'balance': 1665, 'charges': [275, 1200, 650, 150, 400, 650, 1200, 400], 'threshold': 1000, 'min_replenish': 2500, 'usage_30d': 4211, 'card_ok': True}, {'balance': 1740, 'replenished': 2, 'first_negative': None}), ({'balance': 2509, 'charges': [275], 'threshold': 1000, 'min_replenish': 2500, 'usage_30d': 14637, 'card_ok': True}, {'balance': 2234, 'replenished': 0, 'first_negative': None}), ({'balance': 3938, 'charges': [150, 1200], 'threshold': 500, 'min_replenish': 2000, 'usage_30d': 160, 'card_ok': True}, {'balance': 2588, 'replenished': 0, 'first_negative': None}), ({'balance': 1796, 'charges': [650, 400, 1200, 150, 3000, 150, 275, 1200], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 17989, 'card_ok': True}, {'balance': 3771, 'replenished': 2, 'first_negative': None})], [({'balance': 2033, 'charges': [3000, 650, 1200, 275, 3000, 3000, 650, 400], 'threshold': 1500, 'min_replenish': 1000, 'usage_30d': 18614, 'card_ok': True}, {'balance': 4858, 'replenished': 3, 'first_negative': None}), ({'balance': 2484, 'charges': [650, 150, 1200, 1200, 400, 150, 650, 150], 'threshold': 1000, 'min_replenish': 2000, 'usage_30d': 18653, 'card_ok': False}, {'balance': -2066, 'replenished': 0, 'first_negative': 3}), ({'balance': 400, 'charges': [400], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': 0, 'replenished': 0, 'first_negative': None}), ({'balance': 2629, 'charges': [3000, 275, 150], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 12751, 'card_ok': True}, {'balance': 2704, 'replenished': 1, 'first_negative': None}), ({'balance': 1400, 'charges': [400, 150], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 3350, 'replenished': 1, 'first_negative': None}), ({'balance': 3615, 'charges': [650, 400, 1200, 150, 650], 'threshold': 1500, 'min_replenish': 1000, 'usage_30d': 16149, 'card_ok': True}, {'balance': 5065, 'replenished': 1, 'first_negative': None}), ({'balance': 725, 'charges': [150, 1200, 3000, 275], 'threshold': 1500, 'min_replenish': 2000, 'usage_30d': 12916, 'card_ok': False}, {'balance': -3900, 'replenished': 0, 'first_negative': 1}), ({'balance': 1400, 'charges': [400], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 1000, 'replenished': 0, 'first_negative': None})], [({'balance': 1270, 'charges': [1200, 150, 3000, 400, 650, 150, 650, 1200], 'threshold': 1500, 'min_replenish': 2000, 'usage_30d': 16340, 'card_ok': False}, {'balance': -6130, 'replenished': 0, 'first_negative': 1}), ({'balance': 300, 'charges': [400, 150, 275], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': -525, 'replenished': 0, 'first_negative': 0}), ({'balance': 3058, 'charges': [150, 1200, 275, 1200], 'threshold': 500, 'min_replenish': 2000, 'usage_30d': 19841, 'card_ok': True}, {'balance': 5233, 'replenished': 1, 'first_negative': None}), ({'balance': 2750, 'charges': [275, 150, 400, 3000, 150], 'threshold': 1500, 'min_replenish': 1000, 'usage_30d': 6142, 'card_ok': True}, {'balance': 2775, 'replenished': 2, 'first_negative': None}), ({'balance': 1212, 'charges': [275, 400, 400], 'threshold': 500, 'min_replenish': 2500, 'usage_30d': 9849, 'card_ok': False}, {'balance': 137, 'replenished': 0, 'first_negative': None}), ({'balance': 1525, 'charges': [275, 1200, 650, 400, 1200, 3000], 'threshold': 1000, 'min_replenish': 2000, 'usage_30d': 8087, 'card_ok': True}, {'balance': 2300, 'replenished': 3, 'first_negative': None}), ({'balance': 400, 'charges': [400], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': 0, 'replenished': 0, 'first_negative': None}), ({'balance': 1400, 'charges': [400, 150], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 3350, 'replenished': 1, 'first_negative': None})]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check('fee oracle' + ' %d' % 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
fee oracle 0{'balance': 3350, 'first_negative': None, 'replenished': 1}{'balance': 3350, 'first_negative': None, 'replenished': 1}Passed
fee oracle 1{'balance': 1000, 'first_negative': None, 'replenished': 0}{'balance': 1000, 'first_negative': None, 'replenished': 0}Passed
fee oracle 2{'balance': -525, 'first_negative': 0, 'replenished': 0}{'balance': -525, 'first_negative': 0, 'replenished': 0}Passed
fee oracle 3{'balance': 882, 'first_negative': None, 'replenished': 3}{'balance': 882, 'first_negative': None, 'replenished': 3}Passed
fee oracle 4{'balance': 1568, 'first_negative': None, 'replenished': 0}{'balance': 1568, 'first_negative': None, 'replenished': 0}Passed
fee oracle 5{'balance': 1190, 'first_negative': None, 'replenished': 0}{'balance': 1190, 'first_negative': None, 'replenished': 0}Passed
fee oracle 6{'balance': 2822, 'first_negative': None, 'replenished': 2}{'balance': 2822, 'first_negative': None, 'replenished': 2}Passed
fee oracle 7{'balance': 1946, 'first_negative': None, 'replenished': 2}{'balance': 1946, 'first_negative': None, 'replenished': 2}Passed

SHA-256 / 6d5120ffa2ac149f148d666d5364921854db4347b21d166c188631e2ede02553

Verification & scope

A deterministic, bounded toy model with a stipulated contract; it makes no claim of conformance to any agency manual or standard. 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:48:04.004316+00:00.

Case digest / 8d33525eedf0919afccf9fb1420b516ad52af9b3cfc51a2ca0bb324a297335ba