{"abstract":"Customer balances after invoicing are wrong whenever credit notes were applied.","category":"Subscription proration billing","checks":10,"contract":"Input {total, credit_notes, balance, min_payment}. Credit notes apply first, capped at the total; any excess credit-note value joins the customer balance. The balance then applies up to the remaining due. A remaining due above 0 but below min_payment is carried to the next invoice instead of charged. Return [due, balance_after, carried].","contract_signature":"x","evaluation_group":"w2-subscription-proration-credit-balance-application","failed_approach":"The attempt recomputes from the starting balance, dropping the credit-note excess added to it.","family":"w2-subscription-proration-credit-balance-application-remaining-balance-update","id":"FA-59576","implementations":{"attempt":{"sha256":"fdc1eaf26074a848bf762c7abeadb0e727102b0ade7e10099e5c28b1833f3312","source":"\"\"\"Failure Map reference implementation. Python standard library only.\"\"\"\nimport json\n\nN = 1\nobservations = []\ndef solve(x):\n    due = x['total']\n    cn = sum(x['credit_notes'])\n    use_cn = min(cn, due)\n    due -= use_cn\n    bal = x['balance'] + (cn - use_cn)\n    use_bal = min(bal, due)\n    due -= use_bal\n    bal = x['balance'] - use_bal\n    carried = 0\n    if 0 < due < x['min_payment']:\n        carried = due\n        due = 0\n    return [due, bal, carried]\ndef check(label, actual, expected):\n    observations.append({\"check\": label, \"actual\": actual, \"expected\": expected, \"passed\": actual == expected})\nfixtures = [[('regression', {'total': 53, 'credit_notes': [2302], 'balance': 0, 'min_payment': 50}, [0, 2249, 0]), ('regression (boundary)', {'total': 1050, 'credit_notes': [1000], 'balance': 0, 'min_payment': 50}, [50, 0, 0]), ('partial-repair probe', {'total': 249, 'credit_notes': [6921, 1078, 7518], 'balance': 0, 'min_payment': 100}, [0, 15268, 0]), ('partial-repair probe', {'total': 299, 'credit_notes': [19966], 'balance': 0, 'min_payment': 0}, [0, 19667, 0]), ('boundary control', {'total': 50, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [50, 0, 0]), ('boundary control', {'total': 40, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [0, 0, 40]), ('normal control', {'total': 294, 'credit_notes': [], 'balance': 0, 'min_payment': 0}, [294, 0, 0]), ('normal control', {'total': 36738, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [36738, 0, 0]), ('normal control', {'total': 2985, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [2985, 0, 0]), ('normal control', {'total': 79, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [79, 0, 0])], [('regression', {'total': 249, 'credit_notes': [6921, 1078, 7518], 'balance': 0, 'min_payment': 100}, [0, 15268, 0]), ('regression (boundary)', {'total': 80, 'credit_notes': [], 'balance': 10, 'min_payment': 100}, [0, 0, 70]), ('partial-repair probe', {'total': 299, 'credit_notes': [19966], 'balance': 0, 'min_payment': 0}, [0, 19667, 0]), ('partial-repair probe', {'total': 7761, 'credit_notes': [6395, 18359, 7009], 'balance': 11062, 'min_payment': 100}, [0, 35064, 0]), ('boundary control', {'total': 100, 'credit_notes': [], 'balance': 0, 'min_payment': 100}, [100, 0, 0]), ('boundary control', {'total': 50, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [50, 0, 0]), ('normal control', {'total': 192, 'credit_notes': [], 'balance': 0, 'min_payment': 0}, [192, 0, 0]), ('normal control', {'total': 107, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [107, 0, 0]), ('normal control', {'total': 123, 'credit_notes': [], 'balance': 0, 'min_payment': 0}, [123, 0, 0]), ('normal control', {'total': 228, 'credit_notes': [], 'balance': 0, 'min_payment': 100}, [228, 0, 0])], [('regression', {'total': 299, 'credit_notes': [19966], 'balance': 0, 'min_payment': 0}, [0, 19667, 0]), ('regression (boundary)', {'total': 130, 'credit_notes': [], 'balance': 50, 'min_payment': 100}, [0, 0, 80]), ('partial-repair probe', {'total': 164, 'credit_notes': [3853, 15350, 168], 'balance': 6958, 'min_payment': 100}, [0, 26165, 0]), ('partial-repair probe', {'total': 46, 'credit_notes': [8883, 761], 'balance': 0, 'min_payment': 50}, [0, 9598, 0]), ('boundary control', {'total': 40, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [0, 0, 40]), ('boundary control', {'total': 100, 'credit_notes': [], 'balance': 0, 'min_payment': 100}, [100, 0, 0]), ('normal control', {'total': 288, 'credit_notes': [], 'balance': 0, 'min_payment': 100}, [288, 0, 0]), ('normal control', {'total': 38150, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [38150, 0, 0]), ('normal control', {'total': 165, 'credit_notes': [], 'balance': 0, 'min_payment': 100}, [165, 0, 0]), ('normal control', {'total': 141, 'credit_notes': [], 'balance': 0, 'min_payment': 0}, [141, 0, 0])], [('regression', {'total': 7761, 'credit_notes': [6395, 18359, 7009], 'balance': 11062, 'min_payment': 100}, [0, 35064, 0]), ('regression (boundary)', {'total': 1200, 'credit_notes': [1100], 'balance': 0, 'min_payment': 100}, [100, 0, 0]), ('partial-repair probe', {'total': 14659, 'credit_notes': [16457, 12670], 'balance': 0, 'min_payment': 50}, [0, 14468, 0]), ('partial-repair probe', {'total': 62, 'credit_notes': [3609], 'balance': 0, 'min_payment': 0}, [0, 3547, 0]), ('boundary control', {'total': 50, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [50, 0, 0]), ('boundary control', {'total': 40, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [0, 0, 40]), ('normal control', {'total': 42819, 'credit_notes': [], 'balance': 0, 'min_payment': 100}, [42819, 0, 0]), ('normal control', {'total': 192, 'credit_notes': [], 'balance': 0, 'min_payment': 100}, [192, 0, 0]), ('normal control', {'total': 291, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [291, 0, 0]), ('normal control', {'total': 237, 'credit_notes': [], 'balance': 0, 'min_payment': 100}, [237, 0, 0])], [('regression', {'total': 164, 'credit_notes': [3853, 15350, 168], 'balance': 6958, 'min_payment': 100}, [0, 26165, 0]), ('regression (boundary)', {'total': 160, 'credit_notes': [], 'balance': 60, 'min_payment': 100}, [100, 0, 0]), ('partial-repair probe', {'total': 10727, 'credit_notes': [13715], 'balance': 0, 'min_payment': 100}, [0, 2988, 0]), ('partial-repair probe', {'total': 211, 'credit_notes': [560, 8068, 6056], 'balance': 0, 'min_payment': 50}, [0, 14473, 0]), ('boundary control', {'total': 100, 'credit_notes': [], 'balance': 0, 'min_payment': 100}, [100, 0, 0]), ('boundary control', {'total': 50, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [50, 0, 0]), ('normal control', {'total': 57, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [57, 0, 0]), ('normal control', {'total': 11, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [0, 0, 11]), ('normal control', {'total': 103, 'credit_notes': [], 'balance': 0, 'min_payment': 0}, [103, 0, 0]), ('normal control', {'total': 18761, 'credit_notes': [], 'balance': 0, 'min_payment': 100}, [18761, 0, 0])]]\nfor i, (label, args, expected) in enumerate(fixtures[N-1]):\n    check(\"%s %d\" % (label, i), solve(args), expected)\nprint(json.dumps({\"observations\": observations, \"passed\": all(x[\"passed\"] for x in observations)}, ensure_ascii=False))\nraise SystemExit(0 if all(x[\"passed\"] for x in observations) else 1)\n"},"broken":{"sha256":"e95bdf2da28c976dd7a51781da7dc47c84ebb057213dc091f557abcb73e27b0c","source":"\"\"\"Failure Map reference implementation. Python standard library only.\"\"\"\nimport json\n\nN = 1\nobservations = []\ndef solve(x):\n    due = x['total']\n    cn = sum(x['credit_notes'])\n    use_cn = min(cn, due)\n    due -= use_cn\n    bal = x['balance'] + (cn - use_cn)\n    use_bal = min(bal, due)\n    due -= use_bal\n    bal -= use_cn\n    carried = 0\n    if 0 < due < x['min_payment']:\n        carried = due\n        due = 0\n    return [due, bal, carried]\ndef check(label, actual, expected):\n    observations.append({\"check\": label, \"actual\": actual, \"expected\": expected, \"passed\": actual == expected})\nfixtures = [[('regression', {'total': 53, 'credit_notes': [2302], 'balance': 0, 'min_payment': 50}, [0, 2249, 0]), ('regression (boundary)', {'total': 1050, 'credit_notes': [1000], 'balance': 0, 'min_payment': 50}, [50, 0, 0]), ('partial-repair probe', {'total': 249, 'credit_notes': [6921, 1078, 7518], 'balance': 0, 'min_payment': 100}, [0, 15268, 0]), ('partial-repair probe', {'total': 299, 'credit_notes': [19966], 'balance': 0, 'min_payment': 0}, [0, 19667, 0]), ('boundary control', {'total': 50, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [50, 0, 0]), ('boundary control', {'total': 40, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [0, 0, 40]), ('normal control', {'total': 294, 'credit_notes': [], 'balance': 0, 'min_payment': 0}, [294, 0, 0]), ('normal control', {'total': 36738, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [36738, 0, 0]), ('normal control', {'total': 2985, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [2985, 0, 0]), ('normal control', {'total': 79, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [79, 0, 0])], [('regression', {'total': 249, 'credit_notes': [6921, 1078, 7518], 'balance': 0, 'min_payment': 100}, [0, 15268, 0]), ('regression (boundary)', {'total': 80, 'credit_notes': [], 'balance': 10, 'min_payment': 100}, [0, 0, 70]), ('partial-repair probe', {'total': 299, 'credit_notes': [19966], 'balance': 0, 'min_payment': 0}, [0, 19667, 0]), ('partial-repair probe', {'total': 7761, 'credit_notes': [6395, 18359, 7009], 'balance': 11062, 'min_payment': 100}, [0, 35064, 0]), ('boundary control', {'total': 100, 'credit_notes': [], 'balance': 0, 'min_payment': 100}, [100, 0, 0]), ('boundary control', {'total': 50, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [50, 0, 0]), ('normal control', {'total': 192, 'credit_notes': [], 'balance': 0, 'min_payment': 0}, [192, 0, 0]), ('normal control', {'total': 107, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [107, 0, 0]), ('normal control', {'total': 123, 'credit_notes': [], 'balance': 0, 'min_payment': 0}, [123, 0, 0]), ('normal control', {'total': 228, 'credit_notes': [], 'balance': 0, 'min_payment': 100}, [228, 0, 0])], [('regression', {'total': 299, 'credit_notes': [19966], 'balance': 0, 'min_payment': 0}, [0, 19667, 0]), ('regression (boundary)', {'total': 130, 'credit_notes': [], 'balance': 50, 'min_payment': 100}, [0, 0, 80]), ('partial-repair probe', {'total': 164, 'credit_notes': [3853, 15350, 168], 'balance': 6958, 'min_payment': 100}, [0, 26165, 0]), ('partial-repair probe', {'total': 46, 'credit_notes': [8883, 761], 'balance': 0, 'min_payment': 50}, [0, 9598, 0]), ('boundary control', {'total': 40, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [0, 0, 40]), ('boundary control', {'total': 100, 'credit_notes': [], 'balance': 0, 'min_payment': 100}, [100, 0, 0]), ('normal control', {'total': 288, 'credit_notes': [], 'balance': 0, 'min_payment': 100}, [288, 0, 0]), ('normal control', {'total': 38150, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [38150, 0, 0]), ('normal control', {'total': 165, 'credit_notes': [], 'balance': 0, 'min_payment': 100}, [165, 0, 0]), ('normal control', {'total': 141, 'credit_notes': [], 'balance': 0, 'min_payment': 0}, [141, 0, 0])], [('regression', {'total': 7761, 'credit_notes': [6395, 18359, 7009], 'balance': 11062, 'min_payment': 100}, [0, 35064, 0]), ('regression (boundary)', {'total': 1200, 'credit_notes': [1100], 'balance': 0, 'min_payment': 100}, [100, 0, 0]), ('partial-repair probe', {'total': 14659, 'credit_notes': [16457, 12670], 'balance': 0, 'min_payment': 50}, [0, 14468, 0]), ('partial-repair probe', {'total': 62, 'credit_notes': [3609], 'balance': 0, 'min_payment': 0}, [0, 3547, 0]), ('boundary control', {'total': 50, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [50, 0, 0]), ('boundary control', {'total': 40, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [0, 0, 40]), ('normal control', {'total': 42819, 'credit_notes': [], 'balance': 0, 'min_payment': 100}, [42819, 0, 0]), ('normal control', {'total': 192, 'credit_notes': [], 'balance': 0, 'min_payment': 100}, [192, 0, 0]), ('normal control', {'total': 291, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [291, 0, 0]), ('normal control', {'total': 237, 'credit_notes': [], 'balance': 0, 'min_payment': 100}, [237, 0, 0])], [('regression', {'total': 164, 'credit_notes': [3853, 15350, 168], 'balance': 6958, 'min_payment': 100}, [0, 26165, 0]), ('regression (boundary)', {'total': 160, 'credit_notes': [], 'balance': 60, 'min_payment': 100}, [100, 0, 0]), ('partial-repair probe', {'total': 10727, 'credit_notes': [13715], 'balance': 0, 'min_payment': 100}, [0, 2988, 0]), ('partial-repair probe', {'total': 211, 'credit_notes': [560, 8068, 6056], 'balance': 0, 'min_payment': 50}, [0, 14473, 0]), ('boundary control', {'total': 100, 'credit_notes': [], 'balance': 0, 'min_payment': 100}, [100, 0, 0]), ('boundary control', {'total': 50, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [50, 0, 0]), ('normal control', {'total': 57, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [57, 0, 0]), ('normal control', {'total': 11, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [0, 0, 11]), ('normal control', {'total': 103, 'credit_notes': [], 'balance': 0, 'min_payment': 0}, [103, 0, 0]), ('normal control', {'total': 18761, 'credit_notes': [], 'balance': 0, 'min_payment': 100}, [18761, 0, 0])]]\nfor i, (label, args, expected) in enumerate(fixtures[N-1]):\n    check(\"%s %d\" % (label, i), solve(args), expected)\nprint(json.dumps({\"observations\": observations, \"passed\": all(x[\"passed\"] for x in observations)}, ensure_ascii=False))\nraise SystemExit(0 if all(x[\"passed\"] for x in observations) else 1)\n"}},"limitations":"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.","method":"Deterministic executable model with adversarial boundary fixtures.","provenance":{"created_by":"Failure Map","dependencies":"Python standard library","family":"w2-subscription-proration-credit-balance-application-remaining-balance-update","generated_at":"2026-09-29T14:46:37.597367+00:00","license":"CC0-1.0","python":"3.12.14","seed":1,"split":"open-access"},"relevance":"Proration credits land as credit notes and balances whose application order determines the charge.","root_cause":"The balance is reduced by the credit-note amount applied instead of the balance amount applied.","sha256":"6f5a0fee58e9a63bca9016b5f30c21e458761be76f4c6a2203cd3360adaca7d8","title":"Credit notes and customer balance on an invoice: remaining balance update · case 01","variant":1,"variant_policy":"Five numbered records share a model and may reuse boundary fixtures.","verified":true,"visibility":"public","verification":{"attempt":{"elapsed_ms":39.913,"exit_code":1,"observations":[{"actual":[0,0,0],"check":"regression 0","expected":[0,2249,0],"passed":false},{"actual":[50,0,0],"check":"regression (boundary) 1","expected":[50,0,0],"passed":true},{"actual":[0,0,0],"check":"partial-repair probe 2","expected":[0,15268,0],"passed":false},{"actual":[0,0,0],"check":"partial-repair probe 3","expected":[0,19667,0],"passed":false},{"actual":[50,0,0],"check":"boundary control 4","expected":[50,0,0],"passed":true},{"actual":[0,0,40],"check":"boundary control 5","expected":[0,0,40],"passed":true},{"actual":[294,0,0],"check":"normal control 6","expected":[294,0,0],"passed":true},{"actual":[36738,0,0],"check":"normal control 7","expected":[36738,0,0],"passed":true},{"actual":[2985,0,0],"check":"normal control 8","expected":[2985,0,0],"passed":true},{"actual":[79,0,0],"check":"normal control 9","expected":[79,0,0],"passed":true}],"passed":false,"stderr":"","stdout":"{\"observations\": [{\"check\": \"regression 0\", \"actual\": [0, 0, 0], \"expected\": [0, 2249, 0], \"passed\": false}, {\"check\": \"regression (boundary) 1\", \"actual\": [50, 0, 0], \"expected\": [50, 0, 0], \"passed\": true}, {\"check\": \"partial-repair probe 2\", \"actual\": [0, 0, 0], \"expected\": [0, 15268, 0], \"passed\": false}, {\"check\": \"partial-repair probe 3\", \"actual\": [0, 0, 0], \"expected\": [0, 19667, 0], \"passed\": false}, {\"check\": \"boundary control 4\", \"actual\": [50, 0, 0], \"expected\": [50, 0, 0], \"passed\": true}, {\"check\": \"boundary control 5\", \"actual\": [0, 0, 40], \"expected\": [0, 0, 40], \"passed\": true}, {\"check\": \"normal control 6\", \"actual\": [294, 0, 0], \"expected\": [294, 0, 0], \"passed\": true}, {\"check\": \"normal control 7\", \"actual\": [36738, 0, 0], \"expected\": [36738, 0, 0], \"passed\": true}, {\"check\": \"normal control 8\", \"actual\": [2985, 0, 0], \"expected\": [2985, 0, 0], \"passed\": true}, {\"check\": \"normal control 9\", \"actual\": [79, 0, 0], \"expected\": [79, 0, 0], \"passed\": true}], \"passed\": false}\n"},"broken":{"elapsed_ms":43.575,"exit_code":1,"observations":[{"actual":[0,2196,0],"check":"regression 0","expected":[0,2249,0],"passed":false},{"actual":[50,-1000,0],"check":"regression (boundary) 1","expected":[50,0,0],"passed":false},{"actual":[0,15019,0],"check":"partial-repair probe 2","expected":[0,15268,0],"passed":false},{"actual":[0,19368,0],"check":"partial-repair probe 3","expected":[0,19667,0],"passed":false},{"actual":[50,0,0],"check":"boundary control 4","expected":[50,0,0],"passed":true},{"actual":[0,0,40],"check":"boundary control 5","expected":[0,0,40],"passed":true},{"actual":[294,0,0],"check":"normal control 6","expected":[294,0,0],"passed":true},{"actual":[36738,0,0],"check":"normal control 7","expected":[36738,0,0],"passed":true},{"actual":[2985,0,0],"check":"normal control 8","expected":[2985,0,0],"passed":true},{"actual":[79,0,0],"check":"normal control 9","expected":[79,0,0],"passed":true}],"passed":false,"stderr":"","stdout":"{\"observations\": [{\"check\": \"regression 0\", \"actual\": [0, 2196, 0], \"expected\": [0, 2249, 0], \"passed\": false}, {\"check\": \"regression (boundary) 1\", \"actual\": [50, -1000, 0], \"expected\": [50, 0, 0], \"passed\": false}, {\"check\": \"partial-repair probe 2\", \"actual\": [0, 15019, 0], \"expected\": [0, 15268, 0], \"passed\": false}, {\"check\": \"partial-repair probe 3\", \"actual\": [0, 19368, 0], \"expected\": [0, 19667, 0], \"passed\": false}, {\"check\": \"boundary control 4\", \"actual\": [50, 0, 0], \"expected\": [50, 0, 0], \"passed\": true}, {\"check\": \"boundary control 5\", \"actual\": [0, 0, 40], \"expected\": [0, 0, 40], \"passed\": true}, {\"check\": \"normal control 6\", \"actual\": [294, 0, 0], \"expected\": [294, 0, 0], \"passed\": true}, {\"check\": \"normal control 7\", \"actual\": [36738, 0, 0], \"expected\": [36738, 0, 0], \"passed\": true}, {\"check\": \"normal control 8\", \"actual\": [2985, 0, 0], \"expected\": [2985, 0, 0], \"passed\": true}, {\"check\": \"normal control 9\", \"actual\": [79, 0, 0], \"expected\": [79, 0, 0], \"passed\": true}], \"passed\": false}\n"}},"member_only":{"stages":["fixed"],"fields":["implementations.fixed","verification.fixed","harness","repair"],"note":"The verified repair, its recorded checks, the repair description, and the scoring harness are available to members."}}