FAILURE MAP
← Case archive

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

Prepaid toll account auto-replenishment: a balance equal to the threshold triggers replenishment · case 01

Prepaid toll account auto-replenishment returns a wrong result when a balance equal to the threshold triggers replenishment.

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

ROOT CAUSE

Balances exactly at the threshold are topped up early.

VERIFIED REPAIR

Restore the replenish threshold rule so that the step reads `if bal < x['threshold'] and x['card_ok']:`.

Unsuccessful approach: Subtracting the charge a second time replenishes accounts that are still above threshold.

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 = 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': 2266, 'charges': [150, 1200, 3000, 400, 150, 650, 650], 'threshold': 500, 'min_replenish': 2500, 'usage_30d': 3563, 'card_ok': True}, {'balance': 1066, 'replenished': 2, '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': -441, 'charges': [150], 'threshold': 1000, 'min_replenish': 2000, 'usage_30d': 1094, 'card_ok': True}, {'balance': 1409, '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': 2855, 'charges': [650, 1200], 'threshold': 500, 'min_replenish': 2500, 'usage_30d': 5906, 'card_ok': True}, {'balance': 1005, 'replenished': 0, '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}), ({'balance': 2453, 'charges': [1200, 150, 650, 150, 150, 150, 275, 275], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 18693, 'card_ok': False}, {'balance': -547, 'replenished': 0, 'first_negative': 6})], [({'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': 500, 'charges': [3000], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 12686, 'card_ok': True}, {'balance': 1000, 'replenished': 1, 'first_negative': None}), ({'balance': 3332, 'charges': [150, 400, 275, 1200, 150, 150, 275, 3000], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 4983, 'card_ok': True}, {'balance': -768, 'replenished': 1, 'first_negative': 7}), ({'balance': 1400, 'charges': [400], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 1000, '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}), ({'balance': 2401, 'charges': [3000, 275, 150, 150, 275], 'threshold': 1000, 'min_replenish': 2500, 'usage_30d': 3761, 'card_ok': True}, {'balance': 1051, 'replenished': 1, 'first_negative': None}), ({'balance': 1390, 'charges': [150, 150, 1200, 150, 3000], 'threshold': 500, 'min_replenish': 2000, 'usage_30d': 10475, 'card_ok': True}, {'balance': 2740, 'replenished': 2, 'first_negative': None}), ({'balance': 3658, 'charges': [650, 150, 400, 275], 'threshold': 500, 'min_replenish': 2000, 'usage_30d': 12188, 'card_ok': True}, {'balance': 2183, 'replenished': 0, 'first_negative': None})], [({'balance': -192, 'charges': [650, 3000, 650, 3000], 'threshold': 500, 'min_replenish': 2500, 'usage_30d': 9701, 'card_ok': True}, {'balance': 8, 'replenished': 3, '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': 1210, 'charges': [400], 'threshold': 1500, 'min_replenish': 2000, 'usage_30d': 7111, 'card_ok': True}, {'balance': 2810, 'replenished': 1, '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': 252, 'charges': [400], 'threshold': 500, 'min_replenish': 2500, 'usage_30d': 7082, 'card_ok': True}, {'balance': 2352, 'replenished': 1, 'first_negative': None}), ({'balance': -78, 'charges': [650, 400], 'threshold': 1000, 'min_replenish': 2000, 'usage_30d': 12782, 'card_ok': True}, {'balance': 2372, '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': 2049, 'charges': [650, 275, 650, 3000, 650, 400, 275], 'threshold': 500, 'min_replenish': 2000, 'usage_30d': 12840, 'card_ok': True}, {'balance': 3149, 'replenished': 2, 'first_negative': None})], [({'balance': 2222, 'charges': [275, 650], 'threshold': 1500, 'min_replenish': 2500, 'usage_30d': 19460, 'card_ok': True}, {'balance': 6297, 'replenished': 1, 'first_negative': None}), ({'balance': 650, 'charges': [1200, 650, 150, 400, 650, 275, 150, 150], 'threshold': 1000, 'min_replenish': 2000, 'usage_30d': 15662, 'card_ok': True}, {'balance': 1025, 'replenished': 1, 'first_negative': None}), ({'balance': 1372, 'charges': [400, 400, 3000, 650], 'threshold': 1500, 'min_replenish': 2500, 'usage_30d': 1021, 'card_ok': True}, {'balance': 1922, 'replenished': 2, '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': 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], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 1000, 'replenished': 0, 'first_negative': None}), ({'balance': -398, 'charges': [150, 400, 3000, 275, 150, 400, 1200, 1200], 'threshold': 1500, 'min_replenish': 2000, 'usage_30d': 10518, 'card_ok': False}, {'balance': -7173, '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': 1400, 'charges': [400, 150], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 3350, 'replenished': 1, 'first_negative': None}), ({'balance': 587, 'charges': [1200, 3000, 650, 1200, 1200, 150], 'threshold': 1000, 'min_replenish': 2000, 'usage_30d': 12748, 'card_ok': True}, {'balance': 3687, 'replenished': 3, 'first_negative': None}), ({'balance': 1610, 'charges': [400, 1200, 150, 1200, 400, 650, 400], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 4096, 'card_ok': True}, {'balance': 1710, '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': 2876, 'charges': [3000, 400, 150, 275], 'threshold': 1000, 'min_replenish': 2000, 'usage_30d': 2566, 'card_ok': True}, {'balance': 1051, 'replenished': 1, 'first_negative': None}), ({'balance': 2382, 'charges': [400, 1200, 275], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 12535, 'card_ok': True}, {'balance': 507, 'replenished': 0, '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': 1299, 'charges': [3000, 3000, 650], 'threshold': 500, 'min_replenish': 2000, 'usage_30d': 8830, 'card_ok': True}, {'balance': 2149, 'replenished': 3, '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': 1066, 'first_negative': None, 'replenished': 2}{'balance': 1066, 'first_negative': None, 'replenished': 2}Passed
fee oracle 1{'balance': -525, 'first_negative': 0, 'replenished': 0}{'balance': -525, 'first_negative': 0, 'replenished': 0}Passed
fee oracle 2{'balance': 1409, 'first_negative': None, 'replenished': 1}{'balance': 1409, 'first_negative': None, 'replenished': 1}Passed
fee oracle 3{'balance': 3500, 'first_negative': None, 'replenished': 1}{'balance': 1000, 'first_negative': None, 'replenished': 0}Failed
fee oracle 4{'balance': 1005, 'first_negative': None, 'replenished': 0}{'balance': 1005, 'first_negative': None, 'replenished': 0}Passed
fee oracle 5{'balance': 0, 'first_negative': None, 'replenished': 0}{'balance': 0, 'first_negative': None, 'replenished': 0}Passed
fee oracle 6{'balance': 3350, 'first_negative': None, 'replenished': 1}{'balance': 3350, 'first_negative': None, 'replenished': 1}Passed
fee oracle 7{'balance': -547, 'first_negative': 6, 'replenished': 0}{'balance': -547, 'first_negative': 6, 'replenished': 0}Passed

SHA-256 / 79b1d65d3b7ea9881c818edcdeb06b62763f89e6578560e7497c8b35de2de87d

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 = max(x['min_replenish'], -(-x['usage_30d'] // 2000) * 500)
    for i, c in enumerate(x['charges']):
        bal -= c
        if bal - c < 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': 2266, 'charges': [150, 1200, 3000, 400, 150, 650, 650], 'threshold': 500, 'min_replenish': 2500, 'usage_30d': 3563, 'card_ok': True}, {'balance': 1066, 'replenished': 2, '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': -441, 'charges': [150], 'threshold': 1000, 'min_replenish': 2000, 'usage_30d': 1094, 'card_ok': True}, {'balance': 1409, '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': 2855, 'charges': [650, 1200], 'threshold': 500, 'min_replenish': 2500, 'usage_30d': 5906, 'card_ok': True}, {'balance': 1005, 'replenished': 0, '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}), ({'balance': 2453, 'charges': [1200, 150, 650, 150, 150, 150, 275, 275], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 18693, 'card_ok': False}, {'balance': -547, 'replenished': 0, 'first_negative': 6})], [({'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': 500, 'charges': [3000], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 12686, 'card_ok': True}, {'balance': 1000, 'replenished': 1, 'first_negative': None}), ({'balance': 3332, 'charges': [150, 400, 275, 1200, 150, 150, 275, 3000], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 4983, 'card_ok': True}, {'balance': -768, 'replenished': 1, 'first_negative': 7}), ({'balance': 1400, 'charges': [400], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 1000, '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}), ({'balance': 2401, 'charges': [3000, 275, 150, 150, 275], 'threshold': 1000, 'min_replenish': 2500, 'usage_30d': 3761, 'card_ok': True}, {'balance': 1051, 'replenished': 1, 'first_negative': None}), ({'balance': 1390, 'charges': [150, 150, 1200, 150, 3000], 'threshold': 500, 'min_replenish': 2000, 'usage_30d': 10475, 'card_ok': True}, {'balance': 2740, 'replenished': 2, 'first_negative': None}), ({'balance': 3658, 'charges': [650, 150, 400, 275], 'threshold': 500, 'min_replenish': 2000, 'usage_30d': 12188, 'card_ok': True}, {'balance': 2183, 'replenished': 0, 'first_negative': None})], [({'balance': -192, 'charges': [650, 3000, 650, 3000], 'threshold': 500, 'min_replenish': 2500, 'usage_30d': 9701, 'card_ok': True}, {'balance': 8, 'replenished': 3, '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': 1210, 'charges': [400], 'threshold': 1500, 'min_replenish': 2000, 'usage_30d': 7111, 'card_ok': True}, {'balance': 2810, 'replenished': 1, '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': 252, 'charges': [400], 'threshold': 500, 'min_replenish': 2500, 'usage_30d': 7082, 'card_ok': True}, {'balance': 2352, 'replenished': 1, 'first_negative': None}), ({'balance': -78, 'charges': [650, 400], 'threshold': 1000, 'min_replenish': 2000, 'usage_30d': 12782, 'card_ok': True}, {'balance': 2372, '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': 2049, 'charges': [650, 275, 650, 3000, 650, 400, 275], 'threshold': 500, 'min_replenish': 2000, 'usage_30d': 12840, 'card_ok': True}, {'balance': 3149, 'replenished': 2, 'first_negative': None})], [({'balance': 2222, 'charges': [275, 650], 'threshold': 1500, 'min_replenish': 2500, 'usage_30d': 19460, 'card_ok': True}, {'balance': 6297, 'replenished': 1, 'first_negative': None}), ({'balance': 650, 'charges': [1200, 650, 150, 400, 650, 275, 150, 150], 'threshold': 1000, 'min_replenish': 2000, 'usage_30d': 15662, 'card_ok': True}, {'balance': 1025, 'replenished': 1, 'first_negative': None}), ({'balance': 1372, 'charges': [400, 400, 3000, 650], 'threshold': 1500, 'min_replenish': 2500, 'usage_30d': 1021, 'card_ok': True}, {'balance': 1922, 'replenished': 2, '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': 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], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 1000, 'replenished': 0, 'first_negative': None}), ({'balance': -398, 'charges': [150, 400, 3000, 275, 150, 400, 1200, 1200], 'threshold': 1500, 'min_replenish': 2000, 'usage_30d': 10518, 'card_ok': False}, {'balance': -7173, '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': 1400, 'charges': [400, 150], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 3350, 'replenished': 1, 'first_negative': None}), ({'balance': 587, 'charges': [1200, 3000, 650, 1200, 1200, 150], 'threshold': 1000, 'min_replenish': 2000, 'usage_30d': 12748, 'card_ok': True}, {'balance': 3687, 'replenished': 3, 'first_negative': None}), ({'balance': 1610, 'charges': [400, 1200, 150, 1200, 400, 650, 400], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 4096, 'card_ok': True}, {'balance': 1710, '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': 2876, 'charges': [3000, 400, 150, 275], 'threshold': 1000, 'min_replenish': 2000, 'usage_30d': 2566, 'card_ok': True}, {'balance': 1051, 'replenished': 1, 'first_negative': None}), ({'balance': 2382, 'charges': [400, 1200, 275], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 12535, 'card_ok': True}, {'balance': 507, 'replenished': 0, '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': 1299, 'charges': [3000, 3000, 650], 'threshold': 500, 'min_replenish': 2000, 'usage_30d': 8830, 'card_ok': True}, {'balance': 2149, 'replenished': 3, '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': 3566, 'first_negative': None, 'replenished': 3}{'balance': 1066, 'first_negative': None, 'replenished': 2}Failed
fee oracle 1{'balance': -525, 'first_negative': 0, 'replenished': 0}{'balance': -525, 'first_negative': 0, 'replenished': 0}Passed
fee oracle 2{'balance': 1409, 'first_negative': None, 'replenished': 1}{'balance': 1409, 'first_negative': None, 'replenished': 1}Passed
fee oracle 3{'balance': 3500, 'first_negative': None, 'replenished': 1}{'balance': 1000, 'first_negative': None, 'replenished': 0}Failed
fee oracle 4{'balance': 3505, 'first_negative': None, 'replenished': 1}{'balance': 1005, 'first_negative': None, 'replenished': 0}Failed
fee oracle 5{'balance': 0, 'first_negative': None, 'replenished': 0}{'balance': 0, 'first_negative': None, 'replenished': 0}Passed
fee oracle 6{'balance': 3350, 'first_negative': None, 'replenished': 1}{'balance': 3350, 'first_negative': None, 'replenished': 1}Passed
fee oracle 7{'balance': -547, 'first_negative': 6, 'replenished': 0}{'balance': -547, 'first_negative': 6, 'replenished': 0}Passed

SHA-256 / f1a23af197fa1ce7f481079400f637af13f87f512e712c0b993923dbf3ecaa01

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': 2266, 'charges': [150, 1200, 3000, 400, 150, 650, 650], 'threshold': 500, 'min_replenish': 2500, 'usage_30d': 3563, 'card_ok': True}, {'balance': 1066, 'replenished': 2, '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': -441, 'charges': [150], 'threshold': 1000, 'min_replenish': 2000, 'usage_30d': 1094, 'card_ok': True}, {'balance': 1409, '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': 2855, 'charges': [650, 1200], 'threshold': 500, 'min_replenish': 2500, 'usage_30d': 5906, 'card_ok': True}, {'balance': 1005, 'replenished': 0, '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}), ({'balance': 2453, 'charges': [1200, 150, 650, 150, 150, 150, 275, 275], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 18693, 'card_ok': False}, {'balance': -547, 'replenished': 0, 'first_negative': 6})], [({'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': 500, 'charges': [3000], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 12686, 'card_ok': True}, {'balance': 1000, 'replenished': 1, 'first_negative': None}), ({'balance': 3332, 'charges': [150, 400, 275, 1200, 150, 150, 275, 3000], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 4983, 'card_ok': True}, {'balance': -768, 'replenished': 1, 'first_negative': 7}), ({'balance': 1400, 'charges': [400], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 1000, '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}), ({'balance': 2401, 'charges': [3000, 275, 150, 150, 275], 'threshold': 1000, 'min_replenish': 2500, 'usage_30d': 3761, 'card_ok': True}, {'balance': 1051, 'replenished': 1, 'first_negative': None}), ({'balance': 1390, 'charges': [150, 150, 1200, 150, 3000], 'threshold': 500, 'min_replenish': 2000, 'usage_30d': 10475, 'card_ok': True}, {'balance': 2740, 'replenished': 2, 'first_negative': None}), ({'balance': 3658, 'charges': [650, 150, 400, 275], 'threshold': 500, 'min_replenish': 2000, 'usage_30d': 12188, 'card_ok': True}, {'balance': 2183, 'replenished': 0, 'first_negative': None})], [({'balance': -192, 'charges': [650, 3000, 650, 3000], 'threshold': 500, 'min_replenish': 2500, 'usage_30d': 9701, 'card_ok': True}, {'balance': 8, 'replenished': 3, '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': 1210, 'charges': [400], 'threshold': 1500, 'min_replenish': 2000, 'usage_30d': 7111, 'card_ok': True}, {'balance': 2810, 'replenished': 1, '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': 252, 'charges': [400], 'threshold': 500, 'min_replenish': 2500, 'usage_30d': 7082, 'card_ok': True}, {'balance': 2352, 'replenished': 1, 'first_negative': None}), ({'balance': -78, 'charges': [650, 400], 'threshold': 1000, 'min_replenish': 2000, 'usage_30d': 12782, 'card_ok': True}, {'balance': 2372, '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': 2049, 'charges': [650, 275, 650, 3000, 650, 400, 275], 'threshold': 500, 'min_replenish': 2000, 'usage_30d': 12840, 'card_ok': True}, {'balance': 3149, 'replenished': 2, 'first_negative': None})], [({'balance': 2222, 'charges': [275, 650], 'threshold': 1500, 'min_replenish': 2500, 'usage_30d': 19460, 'card_ok': True}, {'balance': 6297, 'replenished': 1, 'first_negative': None}), ({'balance': 650, 'charges': [1200, 650, 150, 400, 650, 275, 150, 150], 'threshold': 1000, 'min_replenish': 2000, 'usage_30d': 15662, 'card_ok': True}, {'balance': 1025, 'replenished': 1, 'first_negative': None}), ({'balance': 1372, 'charges': [400, 400, 3000, 650], 'threshold': 1500, 'min_replenish': 2500, 'usage_30d': 1021, 'card_ok': True}, {'balance': 1922, 'replenished': 2, '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': 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], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 1000, 'replenished': 0, 'first_negative': None}), ({'balance': -398, 'charges': [150, 400, 3000, 275, 150, 400, 1200, 1200], 'threshold': 1500, 'min_replenish': 2000, 'usage_30d': 10518, 'card_ok': False}, {'balance': -7173, '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': 1400, 'charges': [400, 150], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 3350, 'replenished': 1, 'first_negative': None}), ({'balance': 587, 'charges': [1200, 3000, 650, 1200, 1200, 150], 'threshold': 1000, 'min_replenish': 2000, 'usage_30d': 12748, 'card_ok': True}, {'balance': 3687, 'replenished': 3, 'first_negative': None}), ({'balance': 1610, 'charges': [400, 1200, 150, 1200, 400, 650, 400], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 4096, 'card_ok': True}, {'balance': 1710, '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': 2876, 'charges': [3000, 400, 150, 275], 'threshold': 1000, 'min_replenish': 2000, 'usage_30d': 2566, 'card_ok': True}, {'balance': 1051, 'replenished': 1, 'first_negative': None}), ({'balance': 2382, 'charges': [400, 1200, 275], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 12535, 'card_ok': True}, {'balance': 507, 'replenished': 0, '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': 1299, 'charges': [3000, 3000, 650], 'threshold': 500, 'min_replenish': 2000, 'usage_30d': 8830, 'card_ok': True}, {'balance': 2149, 'replenished': 3, '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': 1066, 'first_negative': None, 'replenished': 2}{'balance': 1066, 'first_negative': None, 'replenished': 2}Passed
fee oracle 1{'balance': -525, 'first_negative': 0, 'replenished': 0}{'balance': -525, 'first_negative': 0, 'replenished': 0}Passed
fee oracle 2{'balance': 1409, 'first_negative': None, 'replenished': 1}{'balance': 1409, 'first_negative': None, 'replenished': 1}Passed
fee oracle 3{'balance': 1000, 'first_negative': None, 'replenished': 0}{'balance': 1000, 'first_negative': None, 'replenished': 0}Passed
fee oracle 4{'balance': 1005, 'first_negative': None, 'replenished': 0}{'balance': 1005, 'first_negative': None, 'replenished': 0}Passed
fee oracle 5{'balance': 0, 'first_negative': None, 'replenished': 0}{'balance': 0, 'first_negative': None, 'replenished': 0}Passed
fee oracle 6{'balance': 3350, 'first_negative': None, 'replenished': 1}{'balance': 3350, 'first_negative': None, 'replenished': 1}Passed
fee oracle 7{'balance': -547, 'first_negative': 6, 'replenished': 0}{'balance': -547, 'first_negative': 6, 'replenished': 0}Passed

SHA-256 / ac8f5c65bb9124c2c372bd4d8d4c148e224f46f12c5b22a7ecf1cdfcb5db009c

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

Case digest / e522fe29c50000f178add5e9c2058ed42bb3832350fda446ad3487ca67a56472