FA-58256 / Double-entry ledger accounting / Open access
Receivables subledger tie-out: subledger cutoff · case 01
Future-dated invoices appear in the customer balances.
ROOT CAUSE
The subledger sum ignores the as-of date.
VERIFIED REPAIR
Apply the as-of cutoff to subledger rows.
Unsuccessful approach: Letting credits through regardless of date still counts post-cutoff payments.
Case contract
x = {'control': [[day, amount]], 'sub': {customer: [[day, amount]]}, 'as_of': day}. Only rows dated on or before as_of count. The subledger total nets every customer balance, including credit (negative) balances. Return {'control', 'subledger', 'difference': control - subledger, 'credit_balances': customers with negative balance sorted by name, 'open_customers': count of nonzero balances}.
Why this case matters
Ledger software must keep debits equal to credits and apply normal-balance, period and cutoff rules exactly; small sign or boundary slips silently misstate financial statements.
1 / The failure
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(x):
cut = x['as_of']
control = sum(a for d, a in x['control'] if d <= cut)
per = {}
for cust, rows in x['sub'].items():
per[cust] = sum(a for d, a in rows)
sub_total = sum(per.values())
credit = sorted(c for c, v in per.items() if v < 0)
return {'control': control, 'subledger': sub_total, 'difference': control - sub_total, 'credit_balances': credit, 'open_customers': sum(1 for v in per.values() if v != 0)}
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: subledger cutoff', {'control': [[5, 100], [19, -80], [21, -80]], 'sub': {'bolt': [[5, -80], [1, 250], [5, -80]], 'acme': [[21, 100]], 'dyna': [[20, 400], [1, 250], [20, 100]], 'crux': [[20, 400], [5, 100]]}, 'as_of': 20}, {'control': 20, 'subledger': 1340, 'difference': -1320, 'credit_balances': [], 'open_customers': 3}], ['regression: subledger cutoff, partial-repair probe', {'control': [[5, 100], [21, 250], [19, 400], [5, 100]], 'sub': {'dyna': [[21, -80], [21, 100], [20, 400]], 'acme': [[5, 100], [20, -80], [21, -300]], 'bolt': [[5, -80], [21, -300]]}, 'as_of': 20}, {'control': 600, 'subledger': 340, 'difference': 260, 'credit_balances': ['bolt'], 'open_customers': 3}], ['control 1', {'control': [[21, 400], [5, 250], [19, 250], [20, 400], [19, -80]], 'sub': {'bolt': [[5, 250]]}, 'as_of': 20}, {'control': 820, 'subledger': 250, 'difference': 570, 'credit_balances': [], 'open_customers': 1}], ['control 2', {'control': [[20, 250], [21, 100], [1, 400], [5, 100]], 'sub': {'acme': [[20, -300]], 'dyna': [[5, 250], [1, -80]]}, 'as_of': 20}, {'control': 750, 'subledger': -130, 'difference': 880, 'credit_balances': ['acme'], 'open_customers': 2}], ['control 3', {'control': [[32, 100], [30, -80], [5, 100], [5, 100]], 'sub': {'crux': [[5, 100], [1, 250], [1, -300]], 'bolt': [[31, 250], [5, -300]]}, 'as_of': 31}, {'control': 120, 'subledger': 0, 'difference': 120, 'credit_balances': ['bolt'], 'open_customers': 2}], ['control 4', {'control': [[32, 400], [32, 250], [31, -80]], 'sub': {'dyna': [[31, 400], [1, -300]], 'bolt': [[5, 250], [5, 250], [1, -300]], 'crux': [[31, -300], [1, -80], [31, -300]], 'acme': [[31, 250]]}, 'as_of': 31}, {'control': -80, 'subledger': -130, 'difference': 50, 'credit_balances': ['crux'], 'open_customers': 4}], ['control 5', {'control': [[5, 400], [21, 400], [19, -80], [19, 400], [19, 250]], 'sub': {'bolt': [[5, 100]], 'acme': [[1, 250]]}, 'as_of': 20}, {'control': 970, 'subledger': 350, 'difference': 620, 'credit_balances': [], 'open_customers': 2}]], [['regression: subledger cutoff', {'control': [[1, 400], [11, 250]], 'sub': {'dyna': [[1, 250]], 'crux': [[1, 250], [1, 250], [1, 100]], 'acme': [[10, 250], [1, 250], [11, 250]], 'bolt': [[11, 250], [5, 400]]}, 'as_of': 10}, {'control': 400, 'subledger': 1750, 'difference': -1350, 'credit_balances': [], 'open_customers': 4}], ['regression: subledger cutoff, partial-repair probe', {'control': [[5, 400], [20, -80], [19, 250]], 'sub': {'acme': [[21, 250]], 'bolt': [[20, 250], [1, -80], [1, -80]], 'dyna': [[21, -80], [20, 100]], 'crux': [[5, 400], [21, 400], [20, -300]]}, 'as_of': 20}, {'control': 570, 'subledger': 290, 'difference': 280, 'credit_balances': [], 'open_customers': 3}], ['control 1', {'control': [[20, 250], [19, 100], [5, 400]], 'sub': {'bolt': [[20, 250]], 'acme': [[1, -300], [1, 100], [1, 250]]}, 'as_of': 20}, {'control': 750, 'subledger': 300, 'difference': 450, 'credit_balances': [], 'open_customers': 2}], ['control 2', {'control': [[32, 250], [32, 400], [5, 100], [31, -80], [1, 100], [1, 400]], 'sub': {'dyna': [[1, -300], [31, -300]], 'bolt': [[1, -80]]}, 'as_of': 31}, {'control': 520, 'subledger': -680, 'difference': 1200, 'credit_balances': ['bolt', 'dyna'], 'open_customers': 2}], ['control 3', {'control': [[10, 100], [5, 250], [5, 400], [11, -80], [1, 400], [9, 400]], 'sub': {'dyna': [[5, 250]]}, 'as_of': 10}, {'control': 1550, 'subledger': 250, 'difference': 1300, 'credit_balances': [], 'open_customers': 1}], ['control 4', {'control': [[31, 250], [1, 400], [31, 100], [31, 400], [30, -80]], 'sub': {'bolt': [[1, -80], [1, -300], [31, -300]], 'acme': [[31, 100], [1, -300]], 'crux': [[1, 100]]}, 'as_of': 31}, {'control': 1070, 'subledger': -780, 'difference': 1850, 'credit_balances': ['acme', 'bolt'], 'open_customers': 3}], ['control 5', {'control': [[5, -80], [1, 250], [20, 100]], 'sub': {'dyna': [[1, 400], [5, -300]], 'crux': [[20, -80], [5, -80]]}, 'as_of': 20}, {'control': 270, 'subledger': -60, 'difference': 330, 'credit_balances': ['crux'], 'open_customers': 2}]], [['regression: subledger cutoff', {'control': [[9, 250], [11, 100], [11, -80], [11, 250]], 'sub': {'dyna': [[1, 250], [11, 400], [10, -80]], 'acme': [[11, -300], [1, 400], [1, 400]], 'bolt': [[1, -300]]}, 'as_of': 10}, {'control': 250, 'subledger': 670, 'difference': -420, 'credit_balances': ['bolt'], 'open_customers': 3}], ['control 1', {'control': [[1, -80], [1, 100], [32, 400], [31, 250]], 'sub': {'bolt': [[1, 250]]}, 'as_of': 31}, {'control': 270, 'subledger': 250, 'difference': 20, 'credit_balances': [], 'open_customers': 1}], ['control 2', {'control': [[9, 250], [1, 400], [11, 100]], 'sub': {'crux': [[5, -80], [1, 250], [1, 250]]}, 'as_of': 10}, {'control': 650, 'subledger': 420, 'difference': 230, 'credit_balances': [], 'open_customers': 1}], ['control 3', {'control': [[21, 250], [1, 400]], 'sub': {'acme': [[5, -300], [5, -80]]}, 'as_of': 20}, {'control': 400, 'subledger': -380, 'difference': 780, 'credit_balances': ['acme'], 'open_customers': 1}], ['control 4', {'control': [[1, -80], [1, 250], [10, 250], [1, 250], [5, 400]], 'sub': {'crux': [[5, -300]]}, 'as_of': 10}, {'control': 1070, 'subledger': -300, 'difference': 1370, 'credit_balances': ['crux'], 'open_customers': 1}], ['control 5', {'control': [[5, 250], [30, 400], [30, -80], [1, -80], [5, 250]], 'sub': {'bolt': [[5, 250]], 'acme': [[1, 250]], 'dyna': [[31, 400]]}, 'as_of': 31}, {'control': 740, 'subledger': 900, 'difference': -160, 'credit_balances': [], 'open_customers': 3}], ['control 6', {'control': [[10, 100], [5, 400], [10, -80], [1, -80]], 'sub': {'bolt': [[1, -80]], 'crux': [[1, 400], [1, -80]]}, 'as_of': 10}, {'control': 340, 'subledger': 240, 'difference': 100, 'credit_balances': ['bolt'], 'open_customers': 2}]], [['regression: subledger cutoff', {'control': [[20, -80], [21, 100]], 'sub': {'dyna': [[1, -80], [20, 250]], 'bolt': [[1, -300], [20, 400], [21, -300]]}, 'as_of': 20}, {'control': -80, 'subledger': 270, 'difference': -350, 'credit_balances': [], 'open_customers': 2}], ['control 1', {'control': [[31, 250], [5, -80], [1, 400], [32, 400], [1, 400]], 'sub': {'crux': [[5, 250], [1, 400]]}, 'as_of': 31}, {'control': 970, 'subledger': 650, 'difference': 320, 'credit_balances': [], 'open_customers': 1}], ['control 2', {'control': [[1, 400], [20, -80], [19, 250], [20, 250], [20, 250]], 'sub': {'acme': [[20, -300]], 'dyna': [[20, 100], [5, 400], [5, 400]], 'bolt': [[1, 250]]}, 'as_of': 20}, {'control': 1070, 'subledger': 850, 'difference': 220, 'credit_balances': ['acme'], 'open_customers': 3}], ['control 3', {'control': [[1, 100], [11, 100], [1, 100], [9, 400], [9, 100], [9, 100]], 'sub': {'dyna': [[1, 100], [5, 100]]}, 'as_of': 10}, {'control': 800, 'subledger': 200, 'difference': 600, 'credit_balances': [], 'open_customers': 1}], ['control 4', {'control': [[31, -80], [5, 100], [30, -80], [5, -80]], 'sub': {'dyna': [[1, 250], [31, 250], [5, 400]]}, 'as_of': 31}, {'control': -140, 'subledger': 900, 'difference': -1040, 'credit_balances': [], 'open_customers': 1}], ['control 5', {'control': [[21, -80], [20, 400], [19, 100], [20, 100], [21, 400], [20, 250]], 'sub': {'bolt': [[20, -300], [20, -80], [5, 250]], 'crux': [[5, 100], [20, 100]]}, 'as_of': 20}, {'control': 850, 'subledger': 70, 'difference': 780, 'credit_balances': ['bolt'], 'open_customers': 2}], ['control 6', {'control': [[11, 400], [11, -80]], 'sub': {'dyna': [[5, 250]], 'crux': [[10, -300]]}, 'as_of': 10}, {'control': 0, 'subledger': -50, 'difference': 50, 'credit_balances': ['crux'], 'open_customers': 2}]], [['regression: subledger cutoff', {'control': [[5, 100], [5, 250], [19, -80], [21, 250], [21, 250]], 'sub': {'crux': [[20, -80], [20, -80]], 'acme': [[21, 100]]}, 'as_of': 20}, {'control': 270, 'subledger': -160, 'difference': 430, 'credit_balances': ['crux'], 'open_customers': 1}], ['regression: subledger cutoff, partial-repair probe', {'control': [[11, -80], [10, 400], [11, -80], [1, 100], [9, 100]], 'sub': {'crux': [[5, -300], [1, -300]], 'dyna': [[5, -80]], 'bolt': [[1, -300], [10, -80], [1, 100]], 'acme': [[10, 250], [11, -80]]}, 'as_of': 10}, {'control': 600, 'subledger': -710, 'difference': 1310, 'credit_balances': ['bolt', 'crux', 'dyna'], 'open_customers': 4}], ['control 1', {'control': [[10, -80], [9, 400], [1, 250]], 'sub': {'crux': [[5, 250], [1, 400], [5, 250]], 'acme': [[10, -80]]}, 'as_of': 10}, {'control': 570, 'subledger': 820, 'difference': -250, 'credit_balances': ['acme'], 'open_customers': 2}], ['control 2', {'control': [[1, -80], [5, 100], [20, 400], [19, 250], [1, 250]], 'sub': {'crux': [[20, 250], [20, -80], [20, 250]]}, 'as_of': 20}, {'control': 920, 'subledger': 420, 'difference': 500, 'credit_balances': [], 'open_customers': 1}], ['control 3', {'control': [[1, 100], [1, 250], [5, 250], [1, 100], [1, 400], [5, -80]], 'sub': {'bolt': [[10, -80], [10, 400]], 'crux': [[1, 250], [10, 250]]}, 'as_of': 10}, {'control': 1020, 'subledger': 820, 'difference': 200, 'credit_balances': [], 'open_customers': 2}], ['control 4', {'control': [[10, 100], [5, 250], [11, 400], [9, 400]], 'sub': {'bolt': [[1, -80], [5, -300]]}, 'as_of': 10}, {'control': 750, 'subledger': -380, 'difference': 1130, 'credit_balances': ['bolt'], 'open_customers': 1}], ['control 5', {'control': [[5, 400], [11, 100]], 'sub': {'bolt': [[5, 400], [1, -80]], 'acme': [[5, 400], [1, 100], [5, -300]], 'dyna': [[1, 100]]}, 'as_of': 10}, {'control': 400, 'subledger': 620, 'difference': -220, 'credit_balances': [], 'open_customers': 3}]]]
for label, args, expected in fixtures[N-1]:
try:
actual = solve(args)
except Exception as exc:
actual = 'raised ' + type(exc).__name__
check(label, actual, 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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| regression: subledger cutoff | {'control': 20, 'credit_balances': [], 'difference': -1420, 'open_customers': 4, 'subledger': 1440} | {'control': 20, 'credit_balances': [], 'difference': -1320, 'open_customers': 3, 'subledger': 1340} | Failed |
| regression: subledger cutoff, partial-repair probe | {'control': 600, 'credit_balances': ['acme', 'bolt'], 'difference': 840, 'open_customers': 3, 'subledger': -240} | {'control': 600, 'credit_balances': ['bolt'], 'difference': 260, 'open_customers': 3, 'subledger': 340} | Failed |
| control 1 | {'control': 820, 'credit_balances': [], 'difference': 570, 'open_customers': 1, 'subledger': 250} | {'control': 820, 'credit_balances': [], 'difference': 570, 'open_customers': 1, 'subledger': 250} | Passed |
| control 2 | {'control': 750, 'credit_balances': ['acme'], 'difference': 880, 'open_customers': 2, 'subledger': -130} | {'control': 750, 'credit_balances': ['acme'], 'difference': 880, 'open_customers': 2, 'subledger': -130} | Passed |
| control 3 | {'control': 120, 'credit_balances': ['bolt'], 'difference': 120, 'open_customers': 2, 'subledger': 0} | {'control': 120, 'credit_balances': ['bolt'], 'difference': 120, 'open_customers': 2, 'subledger': 0} | Passed |
| control 4 | {'control': -80, 'credit_balances': ['crux'], 'difference': 50, 'open_customers': 4, 'subledger': -130} | {'control': -80, 'credit_balances': ['crux'], 'difference': 50, 'open_customers': 4, 'subledger': -130} | Passed |
| control 5 | {'control': 970, 'credit_balances': [], 'difference': 620, 'open_customers': 2, 'subledger': 350} | {'control': 970, 'credit_balances': [], 'difference': 620, 'open_customers': 2, 'subledger': 350} | Passed |
SHA-256 / e6dd92ea9ae7cb5719d29ae15693a914ccaa3702ce450740fcfe1ccfd3b1042d
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(x):
cut = x['as_of']
control = sum(a for d, a in x['control'] if d <= cut)
per = {}
for cust, rows in x['sub'].items():
per[cust] = sum(a for d, a in rows if d <= cut or a < 0)
sub_total = sum(per.values())
credit = sorted(c for c, v in per.items() if v < 0)
return {'control': control, 'subledger': sub_total, 'difference': control - sub_total, 'credit_balances': credit, 'open_customers': sum(1 for v in per.values() if v != 0)}
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: subledger cutoff', {'control': [[5, 100], [19, -80], [21, -80]], 'sub': {'bolt': [[5, -80], [1, 250], [5, -80]], 'acme': [[21, 100]], 'dyna': [[20, 400], [1, 250], [20, 100]], 'crux': [[20, 400], [5, 100]]}, 'as_of': 20}, {'control': 20, 'subledger': 1340, 'difference': -1320, 'credit_balances': [], 'open_customers': 3}], ['regression: subledger cutoff, partial-repair probe', {'control': [[5, 100], [21, 250], [19, 400], [5, 100]], 'sub': {'dyna': [[21, -80], [21, 100], [20, 400]], 'acme': [[5, 100], [20, -80], [21, -300]], 'bolt': [[5, -80], [21, -300]]}, 'as_of': 20}, {'control': 600, 'subledger': 340, 'difference': 260, 'credit_balances': ['bolt'], 'open_customers': 3}], ['control 1', {'control': [[21, 400], [5, 250], [19, 250], [20, 400], [19, -80]], 'sub': {'bolt': [[5, 250]]}, 'as_of': 20}, {'control': 820, 'subledger': 250, 'difference': 570, 'credit_balances': [], 'open_customers': 1}], ['control 2', {'control': [[20, 250], [21, 100], [1, 400], [5, 100]], 'sub': {'acme': [[20, -300]], 'dyna': [[5, 250], [1, -80]]}, 'as_of': 20}, {'control': 750, 'subledger': -130, 'difference': 880, 'credit_balances': ['acme'], 'open_customers': 2}], ['control 3', {'control': [[32, 100], [30, -80], [5, 100], [5, 100]], 'sub': {'crux': [[5, 100], [1, 250], [1, -300]], 'bolt': [[31, 250], [5, -300]]}, 'as_of': 31}, {'control': 120, 'subledger': 0, 'difference': 120, 'credit_balances': ['bolt'], 'open_customers': 2}], ['control 4', {'control': [[32, 400], [32, 250], [31, -80]], 'sub': {'dyna': [[31, 400], [1, -300]], 'bolt': [[5, 250], [5, 250], [1, -300]], 'crux': [[31, -300], [1, -80], [31, -300]], 'acme': [[31, 250]]}, 'as_of': 31}, {'control': -80, 'subledger': -130, 'difference': 50, 'credit_balances': ['crux'], 'open_customers': 4}], ['control 5', {'control': [[5, 400], [21, 400], [19, -80], [19, 400], [19, 250]], 'sub': {'bolt': [[5, 100]], 'acme': [[1, 250]]}, 'as_of': 20}, {'control': 970, 'subledger': 350, 'difference': 620, 'credit_balances': [], 'open_customers': 2}]], [['regression: subledger cutoff', {'control': [[1, 400], [11, 250]], 'sub': {'dyna': [[1, 250]], 'crux': [[1, 250], [1, 250], [1, 100]], 'acme': [[10, 250], [1, 250], [11, 250]], 'bolt': [[11, 250], [5, 400]]}, 'as_of': 10}, {'control': 400, 'subledger': 1750, 'difference': -1350, 'credit_balances': [], 'open_customers': 4}], ['regression: subledger cutoff, partial-repair probe', {'control': [[5, 400], [20, -80], [19, 250]], 'sub': {'acme': [[21, 250]], 'bolt': [[20, 250], [1, -80], [1, -80]], 'dyna': [[21, -80], [20, 100]], 'crux': [[5, 400], [21, 400], [20, -300]]}, 'as_of': 20}, {'control': 570, 'subledger': 290, 'difference': 280, 'credit_balances': [], 'open_customers': 3}], ['control 1', {'control': [[20, 250], [19, 100], [5, 400]], 'sub': {'bolt': [[20, 250]], 'acme': [[1, -300], [1, 100], [1, 250]]}, 'as_of': 20}, {'control': 750, 'subledger': 300, 'difference': 450, 'credit_balances': [], 'open_customers': 2}], ['control 2', {'control': [[32, 250], [32, 400], [5, 100], [31, -80], [1, 100], [1, 400]], 'sub': {'dyna': [[1, -300], [31, -300]], 'bolt': [[1, -80]]}, 'as_of': 31}, {'control': 520, 'subledger': -680, 'difference': 1200, 'credit_balances': ['bolt', 'dyna'], 'open_customers': 2}], ['control 3', {'control': [[10, 100], [5, 250], [5, 400], [11, -80], [1, 400], [9, 400]], 'sub': {'dyna': [[5, 250]]}, 'as_of': 10}, {'control': 1550, 'subledger': 250, 'difference': 1300, 'credit_balances': [], 'open_customers': 1}], ['control 4', {'control': [[31, 250], [1, 400], [31, 100], [31, 400], [30, -80]], 'sub': {'bolt': [[1, -80], [1, -300], [31, -300]], 'acme': [[31, 100], [1, -300]], 'crux': [[1, 100]]}, 'as_of': 31}, {'control': 1070, 'subledger': -780, 'difference': 1850, 'credit_balances': ['acme', 'bolt'], 'open_customers': 3}], ['control 5', {'control': [[5, -80], [1, 250], [20, 100]], 'sub': {'dyna': [[1, 400], [5, -300]], 'crux': [[20, -80], [5, -80]]}, 'as_of': 20}, {'control': 270, 'subledger': -60, 'difference': 330, 'credit_balances': ['crux'], 'open_customers': 2}]], [['regression: subledger cutoff', {'control': [[9, 250], [11, 100], [11, -80], [11, 250]], 'sub': {'dyna': [[1, 250], [11, 400], [10, -80]], 'acme': [[11, -300], [1, 400], [1, 400]], 'bolt': [[1, -300]]}, 'as_of': 10}, {'control': 250, 'subledger': 670, 'difference': -420, 'credit_balances': ['bolt'], 'open_customers': 3}], ['control 1', {'control': [[1, -80], [1, 100], [32, 400], [31, 250]], 'sub': {'bolt': [[1, 250]]}, 'as_of': 31}, {'control': 270, 'subledger': 250, 'difference': 20, 'credit_balances': [], 'open_customers': 1}], ['control 2', {'control': [[9, 250], [1, 400], [11, 100]], 'sub': {'crux': [[5, -80], [1, 250], [1, 250]]}, 'as_of': 10}, {'control': 650, 'subledger': 420, 'difference': 230, 'credit_balances': [], 'open_customers': 1}], ['control 3', {'control': [[21, 250], [1, 400]], 'sub': {'acme': [[5, -300], [5, -80]]}, 'as_of': 20}, {'control': 400, 'subledger': -380, 'difference': 780, 'credit_balances': ['acme'], 'open_customers': 1}], ['control 4', {'control': [[1, -80], [1, 250], [10, 250], [1, 250], [5, 400]], 'sub': {'crux': [[5, -300]]}, 'as_of': 10}, {'control': 1070, 'subledger': -300, 'difference': 1370, 'credit_balances': ['crux'], 'open_customers': 1}], ['control 5', {'control': [[5, 250], [30, 400], [30, -80], [1, -80], [5, 250]], 'sub': {'bolt': [[5, 250]], 'acme': [[1, 250]], 'dyna': [[31, 400]]}, 'as_of': 31}, {'control': 740, 'subledger': 900, 'difference': -160, 'credit_balances': [], 'open_customers': 3}], ['control 6', {'control': [[10, 100], [5, 400], [10, -80], [1, -80]], 'sub': {'bolt': [[1, -80]], 'crux': [[1, 400], [1, -80]]}, 'as_of': 10}, {'control': 340, 'subledger': 240, 'difference': 100, 'credit_balances': ['bolt'], 'open_customers': 2}]], [['regression: subledger cutoff', {'control': [[20, -80], [21, 100]], 'sub': {'dyna': [[1, -80], [20, 250]], 'bolt': [[1, -300], [20, 400], [21, -300]]}, 'as_of': 20}, {'control': -80, 'subledger': 270, 'difference': -350, 'credit_balances': [], 'open_customers': 2}], ['control 1', {'control': [[31, 250], [5, -80], [1, 400], [32, 400], [1, 400]], 'sub': {'crux': [[5, 250], [1, 400]]}, 'as_of': 31}, {'control': 970, 'subledger': 650, 'difference': 320, 'credit_balances': [], 'open_customers': 1}], ['control 2', {'control': [[1, 400], [20, -80], [19, 250], [20, 250], [20, 250]], 'sub': {'acme': [[20, -300]], 'dyna': [[20, 100], [5, 400], [5, 400]], 'bolt': [[1, 250]]}, 'as_of': 20}, {'control': 1070, 'subledger': 850, 'difference': 220, 'credit_balances': ['acme'], 'open_customers': 3}], ['control 3', {'control': [[1, 100], [11, 100], [1, 100], [9, 400], [9, 100], [9, 100]], 'sub': {'dyna': [[1, 100], [5, 100]]}, 'as_of': 10}, {'control': 800, 'subledger': 200, 'difference': 600, 'credit_balances': [], 'open_customers': 1}], ['control 4', {'control': [[31, -80], [5, 100], [30, -80], [5, -80]], 'sub': {'dyna': [[1, 250], [31, 250], [5, 400]]}, 'as_of': 31}, {'control': -140, 'subledger': 900, 'difference': -1040, 'credit_balances': [], 'open_customers': 1}], ['control 5', {'control': [[21, -80], [20, 400], [19, 100], [20, 100], [21, 400], [20, 250]], 'sub': {'bolt': [[20, -300], [20, -80], [5, 250]], 'crux': [[5, 100], [20, 100]]}, 'as_of': 20}, {'control': 850, 'subledger': 70, 'difference': 780, 'credit_balances': ['bolt'], 'open_customers': 2}], ['control 6', {'control': [[11, 400], [11, -80]], 'sub': {'dyna': [[5, 250]], 'crux': [[10, -300]]}, 'as_of': 10}, {'control': 0, 'subledger': -50, 'difference': 50, 'credit_balances': ['crux'], 'open_customers': 2}]], [['regression: subledger cutoff', {'control': [[5, 100], [5, 250], [19, -80], [21, 250], [21, 250]], 'sub': {'crux': [[20, -80], [20, -80]], 'acme': [[21, 100]]}, 'as_of': 20}, {'control': 270, 'subledger': -160, 'difference': 430, 'credit_balances': ['crux'], 'open_customers': 1}], ['regression: subledger cutoff, partial-repair probe', {'control': [[11, -80], [10, 400], [11, -80], [1, 100], [9, 100]], 'sub': {'crux': [[5, -300], [1, -300]], 'dyna': [[5, -80]], 'bolt': [[1, -300], [10, -80], [1, 100]], 'acme': [[10, 250], [11, -80]]}, 'as_of': 10}, {'control': 600, 'subledger': -710, 'difference': 1310, 'credit_balances': ['bolt', 'crux', 'dyna'], 'open_customers': 4}], ['control 1', {'control': [[10, -80], [9, 400], [1, 250]], 'sub': {'crux': [[5, 250], [1, 400], [5, 250]], 'acme': [[10, -80]]}, 'as_of': 10}, {'control': 570, 'subledger': 820, 'difference': -250, 'credit_balances': ['acme'], 'open_customers': 2}], ['control 2', {'control': [[1, -80], [5, 100], [20, 400], [19, 250], [1, 250]], 'sub': {'crux': [[20, 250], [20, -80], [20, 250]]}, 'as_of': 20}, {'control': 920, 'subledger': 420, 'difference': 500, 'credit_balances': [], 'open_customers': 1}], ['control 3', {'control': [[1, 100], [1, 250], [5, 250], [1, 100], [1, 400], [5, -80]], 'sub': {'bolt': [[10, -80], [10, 400]], 'crux': [[1, 250], [10, 250]]}, 'as_of': 10}, {'control': 1020, 'subledger': 820, 'difference': 200, 'credit_balances': [], 'open_customers': 2}], ['control 4', {'control': [[10, 100], [5, 250], [11, 400], [9, 400]], 'sub': {'bolt': [[1, -80], [5, -300]]}, 'as_of': 10}, {'control': 750, 'subledger': -380, 'difference': 1130, 'credit_balances': ['bolt'], 'open_customers': 1}], ['control 5', {'control': [[5, 400], [11, 100]], 'sub': {'bolt': [[5, 400], [1, -80]], 'acme': [[5, 400], [1, 100], [5, -300]], 'dyna': [[1, 100]]}, 'as_of': 10}, {'control': 400, 'subledger': 620, 'difference': -220, 'credit_balances': [], 'open_customers': 3}]]]
for label, args, expected in fixtures[N-1]:
try:
actual = solve(args)
except Exception as exc:
actual = 'raised ' + type(exc).__name__
check(label, actual, 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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| regression: subledger cutoff | {'control': 20, 'credit_balances': [], 'difference': -1320, 'open_customers': 3, 'subledger': 1340} | {'control': 20, 'credit_balances': [], 'difference': -1320, 'open_customers': 3, 'subledger': 1340} | Passed |
| regression: subledger cutoff, partial-repair probe | {'control': 600, 'credit_balances': ['acme', 'bolt'], 'difference': 940, 'open_customers': 3, 'subledger': -340} | {'control': 600, 'credit_balances': ['bolt'], 'difference': 260, 'open_customers': 3, 'subledger': 340} | Failed |
| control 1 | {'control': 820, 'credit_balances': [], 'difference': 570, 'open_customers': 1, 'subledger': 250} | {'control': 820, 'credit_balances': [], 'difference': 570, 'open_customers': 1, 'subledger': 250} | Passed |
| control 2 | {'control': 750, 'credit_balances': ['acme'], 'difference': 880, 'open_customers': 2, 'subledger': -130} | {'control': 750, 'credit_balances': ['acme'], 'difference': 880, 'open_customers': 2, 'subledger': -130} | Passed |
| control 3 | {'control': 120, 'credit_balances': ['bolt'], 'difference': 120, 'open_customers': 2, 'subledger': 0} | {'control': 120, 'credit_balances': ['bolt'], 'difference': 120, 'open_customers': 2, 'subledger': 0} | Passed |
| control 4 | {'control': -80, 'credit_balances': ['crux'], 'difference': 50, 'open_customers': 4, 'subledger': -130} | {'control': -80, 'credit_balances': ['crux'], 'difference': 50, 'open_customers': 4, 'subledger': -130} | Passed |
| control 5 | {'control': 970, 'credit_balances': [], 'difference': 620, 'open_customers': 2, 'subledger': 350} | {'control': 970, 'credit_balances': [], 'difference': 620, 'open_customers': 2, 'subledger': 350} | Passed |
SHA-256 / 9b6da7e04ace759e5fc531df4892af28d0df3cdf9c1110a3ec3c817011343beb
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(x):
cut = x['as_of']
control = sum(a for d, a in x['control'] if d <= cut)
per = {}
for cust, rows in x['sub'].items():
per[cust] = sum(a for d, a in rows if d <= cut)
sub_total = sum(per.values())
credit = sorted(c for c, v in per.items() if v < 0)
return {'control': control, 'subledger': sub_total, 'difference': control - sub_total, 'credit_balances': credit, 'open_customers': sum(1 for v in per.values() if v != 0)}
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: subledger cutoff', {'control': [[5, 100], [19, -80], [21, -80]], 'sub': {'bolt': [[5, -80], [1, 250], [5, -80]], 'acme': [[21, 100]], 'dyna': [[20, 400], [1, 250], [20, 100]], 'crux': [[20, 400], [5, 100]]}, 'as_of': 20}, {'control': 20, 'subledger': 1340, 'difference': -1320, 'credit_balances': [], 'open_customers': 3}], ['regression: subledger cutoff, partial-repair probe', {'control': [[5, 100], [21, 250], [19, 400], [5, 100]], 'sub': {'dyna': [[21, -80], [21, 100], [20, 400]], 'acme': [[5, 100], [20, -80], [21, -300]], 'bolt': [[5, -80], [21, -300]]}, 'as_of': 20}, {'control': 600, 'subledger': 340, 'difference': 260, 'credit_balances': ['bolt'], 'open_customers': 3}], ['control 1', {'control': [[21, 400], [5, 250], [19, 250], [20, 400], [19, -80]], 'sub': {'bolt': [[5, 250]]}, 'as_of': 20}, {'control': 820, 'subledger': 250, 'difference': 570, 'credit_balances': [], 'open_customers': 1}], ['control 2', {'control': [[20, 250], [21, 100], [1, 400], [5, 100]], 'sub': {'acme': [[20, -300]], 'dyna': [[5, 250], [1, -80]]}, 'as_of': 20}, {'control': 750, 'subledger': -130, 'difference': 880, 'credit_balances': ['acme'], 'open_customers': 2}], ['control 3', {'control': [[32, 100], [30, -80], [5, 100], [5, 100]], 'sub': {'crux': [[5, 100], [1, 250], [1, -300]], 'bolt': [[31, 250], [5, -300]]}, 'as_of': 31}, {'control': 120, 'subledger': 0, 'difference': 120, 'credit_balances': ['bolt'], 'open_customers': 2}], ['control 4', {'control': [[32, 400], [32, 250], [31, -80]], 'sub': {'dyna': [[31, 400], [1, -300]], 'bolt': [[5, 250], [5, 250], [1, -300]], 'crux': [[31, -300], [1, -80], [31, -300]], 'acme': [[31, 250]]}, 'as_of': 31}, {'control': -80, 'subledger': -130, 'difference': 50, 'credit_balances': ['crux'], 'open_customers': 4}], ['control 5', {'control': [[5, 400], [21, 400], [19, -80], [19, 400], [19, 250]], 'sub': {'bolt': [[5, 100]], 'acme': [[1, 250]]}, 'as_of': 20}, {'control': 970, 'subledger': 350, 'difference': 620, 'credit_balances': [], 'open_customers': 2}]], [['regression: subledger cutoff', {'control': [[1, 400], [11, 250]], 'sub': {'dyna': [[1, 250]], 'crux': [[1, 250], [1, 250], [1, 100]], 'acme': [[10, 250], [1, 250], [11, 250]], 'bolt': [[11, 250], [5, 400]]}, 'as_of': 10}, {'control': 400, 'subledger': 1750, 'difference': -1350, 'credit_balances': [], 'open_customers': 4}], ['regression: subledger cutoff, partial-repair probe', {'control': [[5, 400], [20, -80], [19, 250]], 'sub': {'acme': [[21, 250]], 'bolt': [[20, 250], [1, -80], [1, -80]], 'dyna': [[21, -80], [20, 100]], 'crux': [[5, 400], [21, 400], [20, -300]]}, 'as_of': 20}, {'control': 570, 'subledger': 290, 'difference': 280, 'credit_balances': [], 'open_customers': 3}], ['control 1', {'control': [[20, 250], [19, 100], [5, 400]], 'sub': {'bolt': [[20, 250]], 'acme': [[1, -300], [1, 100], [1, 250]]}, 'as_of': 20}, {'control': 750, 'subledger': 300, 'difference': 450, 'credit_balances': [], 'open_customers': 2}], ['control 2', {'control': [[32, 250], [32, 400], [5, 100], [31, -80], [1, 100], [1, 400]], 'sub': {'dyna': [[1, -300], [31, -300]], 'bolt': [[1, -80]]}, 'as_of': 31}, {'control': 520, 'subledger': -680, 'difference': 1200, 'credit_balances': ['bolt', 'dyna'], 'open_customers': 2}], ['control 3', {'control': [[10, 100], [5, 250], [5, 400], [11, -80], [1, 400], [9, 400]], 'sub': {'dyna': [[5, 250]]}, 'as_of': 10}, {'control': 1550, 'subledger': 250, 'difference': 1300, 'credit_balances': [], 'open_customers': 1}], ['control 4', {'control': [[31, 250], [1, 400], [31, 100], [31, 400], [30, -80]], 'sub': {'bolt': [[1, -80], [1, -300], [31, -300]], 'acme': [[31, 100], [1, -300]], 'crux': [[1, 100]]}, 'as_of': 31}, {'control': 1070, 'subledger': -780, 'difference': 1850, 'credit_balances': ['acme', 'bolt'], 'open_customers': 3}], ['control 5', {'control': [[5, -80], [1, 250], [20, 100]], 'sub': {'dyna': [[1, 400], [5, -300]], 'crux': [[20, -80], [5, -80]]}, 'as_of': 20}, {'control': 270, 'subledger': -60, 'difference': 330, 'credit_balances': ['crux'], 'open_customers': 2}]], [['regression: subledger cutoff', {'control': [[9, 250], [11, 100], [11, -80], [11, 250]], 'sub': {'dyna': [[1, 250], [11, 400], [10, -80]], 'acme': [[11, -300], [1, 400], [1, 400]], 'bolt': [[1, -300]]}, 'as_of': 10}, {'control': 250, 'subledger': 670, 'difference': -420, 'credit_balances': ['bolt'], 'open_customers': 3}], ['control 1', {'control': [[1, -80], [1, 100], [32, 400], [31, 250]], 'sub': {'bolt': [[1, 250]]}, 'as_of': 31}, {'control': 270, 'subledger': 250, 'difference': 20, 'credit_balances': [], 'open_customers': 1}], ['control 2', {'control': [[9, 250], [1, 400], [11, 100]], 'sub': {'crux': [[5, -80], [1, 250], [1, 250]]}, 'as_of': 10}, {'control': 650, 'subledger': 420, 'difference': 230, 'credit_balances': [], 'open_customers': 1}], ['control 3', {'control': [[21, 250], [1, 400]], 'sub': {'acme': [[5, -300], [5, -80]]}, 'as_of': 20}, {'control': 400, 'subledger': -380, 'difference': 780, 'credit_balances': ['acme'], 'open_customers': 1}], ['control 4', {'control': [[1, -80], [1, 250], [10, 250], [1, 250], [5, 400]], 'sub': {'crux': [[5, -300]]}, 'as_of': 10}, {'control': 1070, 'subledger': -300, 'difference': 1370, 'credit_balances': ['crux'], 'open_customers': 1}], ['control 5', {'control': [[5, 250], [30, 400], [30, -80], [1, -80], [5, 250]], 'sub': {'bolt': [[5, 250]], 'acme': [[1, 250]], 'dyna': [[31, 400]]}, 'as_of': 31}, {'control': 740, 'subledger': 900, 'difference': -160, 'credit_balances': [], 'open_customers': 3}], ['control 6', {'control': [[10, 100], [5, 400], [10, -80], [1, -80]], 'sub': {'bolt': [[1, -80]], 'crux': [[1, 400], [1, -80]]}, 'as_of': 10}, {'control': 340, 'subledger': 240, 'difference': 100, 'credit_balances': ['bolt'], 'open_customers': 2}]], [['regression: subledger cutoff', {'control': [[20, -80], [21, 100]], 'sub': {'dyna': [[1, -80], [20, 250]], 'bolt': [[1, -300], [20, 400], [21, -300]]}, 'as_of': 20}, {'control': -80, 'subledger': 270, 'difference': -350, 'credit_balances': [], 'open_customers': 2}], ['control 1', {'control': [[31, 250], [5, -80], [1, 400], [32, 400], [1, 400]], 'sub': {'crux': [[5, 250], [1, 400]]}, 'as_of': 31}, {'control': 970, 'subledger': 650, 'difference': 320, 'credit_balances': [], 'open_customers': 1}], ['control 2', {'control': [[1, 400], [20, -80], [19, 250], [20, 250], [20, 250]], 'sub': {'acme': [[20, -300]], 'dyna': [[20, 100], [5, 400], [5, 400]], 'bolt': [[1, 250]]}, 'as_of': 20}, {'control': 1070, 'subledger': 850, 'difference': 220, 'credit_balances': ['acme'], 'open_customers': 3}], ['control 3', {'control': [[1, 100], [11, 100], [1, 100], [9, 400], [9, 100], [9, 100]], 'sub': {'dyna': [[1, 100], [5, 100]]}, 'as_of': 10}, {'control': 800, 'subledger': 200, 'difference': 600, 'credit_balances': [], 'open_customers': 1}], ['control 4', {'control': [[31, -80], [5, 100], [30, -80], [5, -80]], 'sub': {'dyna': [[1, 250], [31, 250], [5, 400]]}, 'as_of': 31}, {'control': -140, 'subledger': 900, 'difference': -1040, 'credit_balances': [], 'open_customers': 1}], ['control 5', {'control': [[21, -80], [20, 400], [19, 100], [20, 100], [21, 400], [20, 250]], 'sub': {'bolt': [[20, -300], [20, -80], [5, 250]], 'crux': [[5, 100], [20, 100]]}, 'as_of': 20}, {'control': 850, 'subledger': 70, 'difference': 780, 'credit_balances': ['bolt'], 'open_customers': 2}], ['control 6', {'control': [[11, 400], [11, -80]], 'sub': {'dyna': [[5, 250]], 'crux': [[10, -300]]}, 'as_of': 10}, {'control': 0, 'subledger': -50, 'difference': 50, 'credit_balances': ['crux'], 'open_customers': 2}]], [['regression: subledger cutoff', {'control': [[5, 100], [5, 250], [19, -80], [21, 250], [21, 250]], 'sub': {'crux': [[20, -80], [20, -80]], 'acme': [[21, 100]]}, 'as_of': 20}, {'control': 270, 'subledger': -160, 'difference': 430, 'credit_balances': ['crux'], 'open_customers': 1}], ['regression: subledger cutoff, partial-repair probe', {'control': [[11, -80], [10, 400], [11, -80], [1, 100], [9, 100]], 'sub': {'crux': [[5, -300], [1, -300]], 'dyna': [[5, -80]], 'bolt': [[1, -300], [10, -80], [1, 100]], 'acme': [[10, 250], [11, -80]]}, 'as_of': 10}, {'control': 600, 'subledger': -710, 'difference': 1310, 'credit_balances': ['bolt', 'crux', 'dyna'], 'open_customers': 4}], ['control 1', {'control': [[10, -80], [9, 400], [1, 250]], 'sub': {'crux': [[5, 250], [1, 400], [5, 250]], 'acme': [[10, -80]]}, 'as_of': 10}, {'control': 570, 'subledger': 820, 'difference': -250, 'credit_balances': ['acme'], 'open_customers': 2}], ['control 2', {'control': [[1, -80], [5, 100], [20, 400], [19, 250], [1, 250]], 'sub': {'crux': [[20, 250], [20, -80], [20, 250]]}, 'as_of': 20}, {'control': 920, 'subledger': 420, 'difference': 500, 'credit_balances': [], 'open_customers': 1}], ['control 3', {'control': [[1, 100], [1, 250], [5, 250], [1, 100], [1, 400], [5, -80]], 'sub': {'bolt': [[10, -80], [10, 400]], 'crux': [[1, 250], [10, 250]]}, 'as_of': 10}, {'control': 1020, 'subledger': 820, 'difference': 200, 'credit_balances': [], 'open_customers': 2}], ['control 4', {'control': [[10, 100], [5, 250], [11, 400], [9, 400]], 'sub': {'bolt': [[1, -80], [5, -300]]}, 'as_of': 10}, {'control': 750, 'subledger': -380, 'difference': 1130, 'credit_balances': ['bolt'], 'open_customers': 1}], ['control 5', {'control': [[5, 400], [11, 100]], 'sub': {'bolt': [[5, 400], [1, -80]], 'acme': [[5, 400], [1, 100], [5, -300]], 'dyna': [[1, 100]]}, 'as_of': 10}, {'control': 400, 'subledger': 620, 'difference': -220, 'credit_balances': [], 'open_customers': 3}]]]
for label, args, expected in fixtures[N-1]:
try:
actual = solve(args)
except Exception as exc:
actual = 'raised ' + type(exc).__name__
check(label, actual, 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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| regression: subledger cutoff | {'control': 20, 'credit_balances': [], 'difference': -1320, 'open_customers': 3, 'subledger': 1340} | {'control': 20, 'credit_balances': [], 'difference': -1320, 'open_customers': 3, 'subledger': 1340} | Passed |
| regression: subledger cutoff, partial-repair probe | {'control': 600, 'credit_balances': ['bolt'], 'difference': 260, 'open_customers': 3, 'subledger': 340} | {'control': 600, 'credit_balances': ['bolt'], 'difference': 260, 'open_customers': 3, 'subledger': 340} | Passed |
| control 1 | {'control': 820, 'credit_balances': [], 'difference': 570, 'open_customers': 1, 'subledger': 250} | {'control': 820, 'credit_balances': [], 'difference': 570, 'open_customers': 1, 'subledger': 250} | Passed |
| control 2 | {'control': 750, 'credit_balances': ['acme'], 'difference': 880, 'open_customers': 2, 'subledger': -130} | {'control': 750, 'credit_balances': ['acme'], 'difference': 880, 'open_customers': 2, 'subledger': -130} | Passed |
| control 3 | {'control': 120, 'credit_balances': ['bolt'], 'difference': 120, 'open_customers': 2, 'subledger': 0} | {'control': 120, 'credit_balances': ['bolt'], 'difference': 120, 'open_customers': 2, 'subledger': 0} | Passed |
| control 4 | {'control': -80, 'credit_balances': ['crux'], 'difference': 50, 'open_customers': 4, 'subledger': -130} | {'control': -80, 'credit_balances': ['crux'], 'difference': 50, 'open_customers': 4, 'subledger': -130} | Passed |
| control 5 | {'control': 970, 'credit_balances': [], 'difference': 620, 'open_customers': 2, 'subledger': 350} | {'control': 970, 'credit_balances': [], 'difference': 620, 'open_customers': 2, 'subledger': 350} | Passed |
SHA-256 / a7dd49e20c6d43fa17338930c3667d8c0854d592a1b07f72ee927207cfd5c055
Verification & scope
A deterministic bounded teaching model with stipulated toy bookkeeping rules stated in the contract; amounts are integer cents; it makes no claim of conformance to any accounting standard or product. 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:24.860920+00:00.
Case digest / 1ba880603d2267d3a4373c90b4fa90c5791ec725c82bd3bb36345e783703b3e3