FAILURE MAP
← Case archive

FA-58071 / Double-entry ledger accounting / Open access

Account running balance report: report opening cutoff · case 01

Lines dated on the first report day are counted in the opening and again in the rows.

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

ROOT CAUSE

The opening balance includes lines dated on the from day.

VERIFIED REPAIR

Include only lines before the from day in the opening.

Unsuccessful approach: Dropping from-day lines from the rows hides them from the report even though the opening now absorbs them.

Case contract

x = {'normal': 'D'|'C', 'opening': balance before all lines, 'lines': [[seq, day, side, amount]], 'from': day, 'to': day}. Balances are signed positive on the normal side. The report opening is the opening plus every line dated before 'from'. Lines dated from..to inclusive are listed in (day, seq) order with the running balance after each; closing is the last running balance (the report opening if none). Return {'opening', 'rows': [[seq, day, running]], 'closing'}.

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):
    sign = {'D': 1, 'C': -1} if x['normal'] == 'D' else {'D': -1, 'C': 1}
    lines = sorted(x['lines'], key=lambda l: (l[1], l[0]))
    opening = x['opening'] + sum(sign[s] * a for q, d, s, a in lines if d <= x['from'])
    bal = opening
    rows = []
    for seq, date, side, amt in lines:
        if x['from'] <= date <= x['to']:
            bal += sign[side] * amt
            rows.append([seq, date, bal])
    return {'opening': opening, 'rows': rows, 'closing': bal}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: report opening cutoff', {'normal': 'D', 'opening': 1000, 'lines': [[4, 5, 'C', 300], [2, 1, 'C', 300], [1, 3, 'C', 50], [3, 12, 'C', 125], [5, 5, 'D', 50]], 'from': 3, 'to': 10}, {'opening': 700, 'rows': [[1, 3, 650], [4, 5, 350], [5, 5, 400]], 'closing': 400}], ['control 1', {'normal': 'C', 'opening': 0, 'lines': [[3, 5, 'C', 50], [6, 1, 'C', 10], [5, 10, 'C', 50], [4, 12, 'D', 300], [8, 5, 'D', 125], [2, 5, 'C', 125], [7, 12, 'D', 125], [1, 12, 'C', 50]], 'from': 6, 'to': 6}, {'opening': 60, 'rows': [], 'closing': 60}], ['control 2', {'normal': 'D', 'opening': 1000, 'lines': [[1, 8, 'D', 125], [8, 1, 'D', 125], [2, 10, 'D', 125], [7, 10, 'D', 50], [6, 5, 'C', 300], [3, 12, 'D', 300], [5, 12, 'C', 125], [4, 1, 'C', 125]], 'from': 6, 'to': 8}, {'opening': 700, 'rows': [[1, 8, 825]], 'closing': 825}], ['control 3', {'normal': 'D', 'opening': 250, 'lines': [[4, 5, 'D', 300], [3, 8, 'C', 125], [2, 5, 'C', 10], [1, 8, 'D', 50]], 'from': 6, 'to': 8}, {'opening': 540, 'rows': [[1, 8, 590], [3, 8, 465]], 'closing': 465}], ['control 4', {'normal': 'C', 'opening': 0, 'lines': [[5, 12, 'C', 125], [3, 5, 'C', 10], [4, 1, 'D', 50], [8, 5, 'C', 125], [1, 10, 'C', 10], [6, 1, 'C', 10], [7, 8, 'C', 125], [2, 3, 'C', 10]], 'from': 6, 'to': 6}, {'opening': 105, 'rows': [], 'closing': 105}], ['control 5', {'normal': 'D', 'opening': 250, 'lines': [[1, 8, 'D', 50], [2, 3, 'D', 125], [3, 10, 'C', 125]], 'from': 1, 'to': 1}, {'opening': 250, 'rows': [], 'closing': 250}], ['control 6', {'normal': 'C', 'opening': 1000, 'lines': [[7, 12, 'D', 50], [6, 3, 'D', 50], [3, 12, 'C', 50], [1, 3, 'C', 10], [5, 10, 'D', 125], [8, 10, 'D', 300], [4, 10, 'C', 50], [2, 3, 'D', 10]], 'from': 6, 'to': 8}, {'opening': 950, 'rows': [], 'closing': 950}]], [['regression: report opening cutoff', {'normal': 'D', 'opening': 1000, 'lines': [[2, 5, 'C', 300], [3, 3, 'D', 125], [4, 8, 'C', 50], [1, 5, 'C', 125], [5, 3, 'C', 300]], 'from': 5, 'to': 10}, {'opening': 825, 'rows': [[1, 5, 700], [2, 5, 400], [4, 8, 350]], 'closing': 350}], ['control 1', {'normal': 'C', 'opening': 250, 'lines': [[4, 8, 'C', 50], [1, 10, 'C', 50], [2, 12, 'D', 125], [6, 10, 'D', 125], [5, 5, 'D', 10], [3, 12, 'D', 50]], 'from': 3, 'to': 8}, {'opening': 250, 'rows': [[5, 5, 240], [4, 8, 290]], 'closing': 290}], ['control 2', {'normal': 'C', 'opening': 250, 'lines': [[2, 8, 'C', 125], [3, 3, 'D', 300], [1, 8, 'D', 50]], 'from': 1, 'to': 8}, {'opening': 250, 'rows': [[3, 3, -50], [1, 8, -100], [2, 8, 25]], 'closing': 25}], ['control 3', {'normal': 'C', 'opening': 250, 'lines': [[1, 8, 'D', 300], [2, 3, 'D', 10], [3, 3, 'D', 10], [4, 12, 'C', 300], [5, 12, 'D', 10]], 'from': 1, 'to': 1}, {'opening': 250, 'rows': [], 'closing': 250}], ['control 4', {'normal': 'C', 'opening': 250, 'lines': [[3, 3, 'C', 125], [2, 10, 'D', 125], [6, 12, 'D', 125], [5, 3, 'D', 50], [1, 8, 'C', 50], [4, 3, 'C', 125]], 'from': 1, 'to': 3}, {'opening': 250, 'rows': [[3, 3, 375], [4, 3, 500], [5, 3, 450]], 'closing': 450}], ['control 5', {'normal': 'D', 'opening': 1000, 'lines': [[4, 8, 'D', 300], [2, 5, 'D', 125], [1, 10, 'D', 125], [3, 10, 'D', 125]], 'from': 6, 'to': 8}, {'opening': 1125, 'rows': [[4, 8, 1425]], 'closing': 1425}], ['control 6', {'normal': 'D', 'opening': 250, 'lines': [[4, 5, 'C', 10], [5, 5, 'C', 50], [1, 12, 'C', 300], [3, 5, 'C', 10], [2, 8, 'D', 50]], 'from': 1, 'to': 6}, {'opening': 250, 'rows': [[3, 5, 240], [4, 5, 230], [5, 5, 180]], 'closing': 180}]], [['regression: report opening cutoff', {'normal': 'C', 'opening': 250, 'lines': [[2, 12, 'C', 50], [1, 8, 'C', 125], [3, 5, 'D', 125]], 'from': 5, 'to': 7}, {'opening': 250, 'rows': [[3, 5, 125]], 'closing': 125}], ['control 1', {'normal': 'D', 'opening': 1000, 'lines': [[2, 8, 'C', 125], [1, 8, 'D', 50], [3, 5, 'D', 125]], 'from': 3, 'to': 5}, {'opening': 1000, 'rows': [[3, 5, 1125]], 'closing': 1125}], ['control 2', {'normal': 'D', 'opening': 0, 'lines': [[3, 5, 'C', 10], [1, 10, 'D', 125], [5, 5, 'C', 300], [2, 8, 'C', 50], [4, 5, 'D', 10]], 'from': 6, 'to': 11}, {'opening': -300, 'rows': [[2, 8, -350], [1, 10, -225]], 'closing': -225}], ['control 3', {'normal': 'D', 'opening': 1000, 'lines': [[2, 8, 'C', 10], [1, 12, 'C', 10], [3, 5, 'C', 50]], 'from': 6, 'to': 8}, {'opening': 950, 'rows': [[2, 8, 940]], 'closing': 940}], ['control 4', {'normal': 'C', 'opening': 250, 'lines': [[2, 8, 'D', 125], [1, 12, 'C', 10], [3, 12, 'C', 50]], 'from': 1, 'to': 6}, {'opening': 250, 'rows': [], 'closing': 250}], ['control 5', {'normal': 'C', 'opening': 250, 'lines': [[1, 10, 'C', 10], [3, 8, 'C', 50], [2, 10, 'D', 10]], 'from': 5, 'to': 10}, {'opening': 250, 'rows': [[3, 8, 300], [1, 10, 310], [2, 10, 300]], 'closing': 300}], ['control 6', {'normal': 'D', 'opening': 0, 'lines': [[2, 3, 'D', 50], [3, 12, 'D', 300], [1, 3, 'C', 50]], 'from': 6, 'to': 11}, {'opening': 0, 'rows': [], 'closing': 0}]], [['regression: report opening cutoff', {'normal': 'C', 'opening': 1000, 'lines': [[5, 5, 'C', 300], [3, 1, 'D', 10], [2, 10, 'D', 10], [4, 5, 'C', 300], [1, 5, 'C', 10]], 'from': 1, 'to': 3}, {'opening': 1000, 'rows': [[3, 1, 990]], 'closing': 990}], ['control 1', {'normal': 'C', 'opening': 250, 'lines': [[2, 3, 'D', 10], [3, 5, 'D', 50], [4, 8, 'D', 10], [1, 5, 'D', 300]], 'from': 6, 'to': 6}, {'opening': -110, 'rows': [], 'closing': -110}], ['control 2', {'normal': 'D', 'opening': 1000, 'lines': [[7, 8, 'C', 125], [5, 12, 'C', 10], [6, 5, 'D', 10], [4, 10, 'D', 10], [3, 8, 'C', 10], [2, 8, 'D', 50], [1, 5, 'D', 10]], 'from': 3, 'to': 5}, {'opening': 1000, 'rows': [[1, 5, 1010], [6, 5, 1020]], 'closing': 1020}], ['control 3', {'normal': 'C', 'opening': 0, 'lines': [[1, 5, 'D', 300], [4, 8, 'C', 300], [3, 12, 'C', 50], [2, 10, 'C', 125]], 'from': 1, 'to': 6}, {'opening': 0, 'rows': [[1, 5, -300]], 'closing': -300}], ['control 4', {'normal': 'C', 'opening': 1000, 'lines': [[2, 12, 'C', 50], [1, 3, 'C', 125], [3, 1, 'D', 10], [4, 5, 'D', 50]], 'from': 6, 'to': 11}, {'opening': 1065, 'rows': [], 'closing': 1065}], ['control 5', {'normal': 'D', 'opening': 0, 'lines': [[1, 8, 'D', 50], [2, 12, 'C', 50], [4, 1, 'D', 50], [5, 1, 'C', 50], [3, 10, 'D', 125]], 'from': 6, 'to': 8}, {'opening': 0, 'rows': [[1, 8, 50]], 'closing': 50}], ['control 6', {'normal': 'C', 'opening': 1000, 'lines': [[3, 10, 'C', 125], [6, 8, 'C', 10], [1, 10, 'D', 50], [2, 12, 'D', 300], [5, 3, 'D', 10], [4, 12, 'C', 300]], 'from': 1, 'to': 1}, {'opening': 1000, 'rows': [], 'closing': 1000}]], [['regression: report opening cutoff', {'normal': 'C', 'opening': 250, 'lines': [[3, 5, 'C', 300], [5, 5, 'C', 50], [4, 5, 'C', 300], [2, 10, 'D', 300], [1, 12, 'D', 300]], 'from': 5, 'to': 5}, {'opening': 250, 'rows': [[3, 5, 550], [4, 5, 850], [5, 5, 900]], 'closing': 900}], ['control 1', {'normal': 'C', 'opening': 250, 'lines': [[3, 8, 'C', 10], [2, 5, 'C', 10], [1, 8, 'C', 300]], 'from': 1, 'to': 8}, {'opening': 250, 'rows': [[2, 5, 260], [1, 8, 560], [3, 8, 570]], 'closing': 570}], ['control 2', {'normal': 'D', 'opening': 1000, 'lines': [[3, 3, 'D', 125], [6, 5, 'C', 125], [2, 8, 'C', 125], [1, 10, 'C', 125], [5, 12, 'C', 125], [7, 5, 'C', 300], [4, 5, 'D', 300]], 'from': 6, 'to': 8}, {'opening': 1000, 'rows': [[2, 8, 875]], 'closing': 875}], ['control 3', {'normal': 'C', 'opening': 0, 'lines': [[3, 8, 'C', 300], [1, 1, 'C', 10], [2, 12, 'C', 125]], 'from': 3, 'to': 3}, {'opening': 10, 'rows': [], 'closing': 10}], ['control 4', {'normal': 'D', 'opening': 1000, 'lines': [[4, 5, 'D', 300], [5, 12, 'D', 125], [3, 12, 'D', 125], [1, 1, 'D', 300], [2, 8, 'C', 10]], 'from': 3, 'to': 5}, {'opening': 1300, 'rows': [[4, 5, 1600]], 'closing': 1600}], ['control 5', {'normal': 'C', 'opening': 1000, 'lines': [[2, 8, 'C', 300], [3, 5, 'D', 300], [4, 8, 'C', 50], [5, 1, 'C', 300], [1, 5, 'C', 10]], 'from': 6, 'to': 11}, {'opening': 1010, 'rows': [[2, 8, 1310], [4, 8, 1360]], 'closing': 1360}], ['control 6', {'normal': 'D', 'opening': 1000, 'lines': [[1, 1, 'D', 300], [2, 1, 'D', 50], [3, 8, 'C', 10]], 'from': 5, 'to': 10}, {'opening': 1350, 'rows': [[3, 8, 1340]], 'closing': 1340}]]]
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 fixtureActualExpectedOutcome
regression: report opening cutoff{'closing': 350, 'opening': 650, 'rows': [[1, 3, 600], [4, 5, 300], [5, 5, 350]]}{'closing': 400, 'opening': 700, 'rows': [[1, 3, 650], [4, 5, 350], [5, 5, 400]]}Failed
control 1{'closing': 60, 'opening': 60, 'rows': []}{'closing': 60, 'opening': 60, 'rows': []}Passed
control 2{'closing': 825, 'opening': 700, 'rows': [[1, 8, 825]]}{'closing': 825, 'opening': 700, 'rows': [[1, 8, 825]]}Passed
control 3{'closing': 465, 'opening': 540, 'rows': [[1, 8, 590], [3, 8, 465]]}{'closing': 465, 'opening': 540, 'rows': [[1, 8, 590], [3, 8, 465]]}Passed
control 4{'closing': 105, 'opening': 105, 'rows': []}{'closing': 105, 'opening': 105, 'rows': []}Passed
control 5{'closing': 250, 'opening': 250, 'rows': []}{'closing': 250, 'opening': 250, 'rows': []}Passed
control 6{'closing': 950, 'opening': 950, 'rows': []}{'closing': 950, 'opening': 950, 'rows': []}Passed

SHA-256 / b9d3162314cf8ae054b4c83ace0a737633b0ae7b8c6741c0b6ca0f07cc2233d3

2 / The unsuccessful fix

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

N = 1
observations = []
def solve(x):
    sign = {'D': 1, 'C': -1} if x['normal'] == 'D' else {'D': -1, 'C': 1}
    lines = sorted(x['lines'], key=lambda l: (l[1], l[0]))
    opening = x['opening'] + sum(sign[s] * a for q, d, s, a in lines if d <= x['from'])
    bal = opening
    rows = []
    for seq, date, side, amt in lines:
        if x['from'] < date <= x['to']:
            bal += sign[side] * amt
            rows.append([seq, date, bal])
    return {'opening': opening, 'rows': rows, 'closing': bal}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: report opening cutoff', {'normal': 'D', 'opening': 1000, 'lines': [[4, 5, 'C', 300], [2, 1, 'C', 300], [1, 3, 'C', 50], [3, 12, 'C', 125], [5, 5, 'D', 50]], 'from': 3, 'to': 10}, {'opening': 700, 'rows': [[1, 3, 650], [4, 5, 350], [5, 5, 400]], 'closing': 400}], ['control 1', {'normal': 'C', 'opening': 0, 'lines': [[3, 5, 'C', 50], [6, 1, 'C', 10], [5, 10, 'C', 50], [4, 12, 'D', 300], [8, 5, 'D', 125], [2, 5, 'C', 125], [7, 12, 'D', 125], [1, 12, 'C', 50]], 'from': 6, 'to': 6}, {'opening': 60, 'rows': [], 'closing': 60}], ['control 2', {'normal': 'D', 'opening': 1000, 'lines': [[1, 8, 'D', 125], [8, 1, 'D', 125], [2, 10, 'D', 125], [7, 10, 'D', 50], [6, 5, 'C', 300], [3, 12, 'D', 300], [5, 12, 'C', 125], [4, 1, 'C', 125]], 'from': 6, 'to': 8}, {'opening': 700, 'rows': [[1, 8, 825]], 'closing': 825}], ['control 3', {'normal': 'D', 'opening': 250, 'lines': [[4, 5, 'D', 300], [3, 8, 'C', 125], [2, 5, 'C', 10], [1, 8, 'D', 50]], 'from': 6, 'to': 8}, {'opening': 540, 'rows': [[1, 8, 590], [3, 8, 465]], 'closing': 465}], ['control 4', {'normal': 'C', 'opening': 0, 'lines': [[5, 12, 'C', 125], [3, 5, 'C', 10], [4, 1, 'D', 50], [8, 5, 'C', 125], [1, 10, 'C', 10], [6, 1, 'C', 10], [7, 8, 'C', 125], [2, 3, 'C', 10]], 'from': 6, 'to': 6}, {'opening': 105, 'rows': [], 'closing': 105}], ['control 5', {'normal': 'D', 'opening': 250, 'lines': [[1, 8, 'D', 50], [2, 3, 'D', 125], [3, 10, 'C', 125]], 'from': 1, 'to': 1}, {'opening': 250, 'rows': [], 'closing': 250}], ['control 6', {'normal': 'C', 'opening': 1000, 'lines': [[7, 12, 'D', 50], [6, 3, 'D', 50], [3, 12, 'C', 50], [1, 3, 'C', 10], [5, 10, 'D', 125], [8, 10, 'D', 300], [4, 10, 'C', 50], [2, 3, 'D', 10]], 'from': 6, 'to': 8}, {'opening': 950, 'rows': [], 'closing': 950}]], [['regression: report opening cutoff', {'normal': 'D', 'opening': 1000, 'lines': [[2, 5, 'C', 300], [3, 3, 'D', 125], [4, 8, 'C', 50], [1, 5, 'C', 125], [5, 3, 'C', 300]], 'from': 5, 'to': 10}, {'opening': 825, 'rows': [[1, 5, 700], [2, 5, 400], [4, 8, 350]], 'closing': 350}], ['control 1', {'normal': 'C', 'opening': 250, 'lines': [[4, 8, 'C', 50], [1, 10, 'C', 50], [2, 12, 'D', 125], [6, 10, 'D', 125], [5, 5, 'D', 10], [3, 12, 'D', 50]], 'from': 3, 'to': 8}, {'opening': 250, 'rows': [[5, 5, 240], [4, 8, 290]], 'closing': 290}], ['control 2', {'normal': 'C', 'opening': 250, 'lines': [[2, 8, 'C', 125], [3, 3, 'D', 300], [1, 8, 'D', 50]], 'from': 1, 'to': 8}, {'opening': 250, 'rows': [[3, 3, -50], [1, 8, -100], [2, 8, 25]], 'closing': 25}], ['control 3', {'normal': 'C', 'opening': 250, 'lines': [[1, 8, 'D', 300], [2, 3, 'D', 10], [3, 3, 'D', 10], [4, 12, 'C', 300], [5, 12, 'D', 10]], 'from': 1, 'to': 1}, {'opening': 250, 'rows': [], 'closing': 250}], ['control 4', {'normal': 'C', 'opening': 250, 'lines': [[3, 3, 'C', 125], [2, 10, 'D', 125], [6, 12, 'D', 125], [5, 3, 'D', 50], [1, 8, 'C', 50], [4, 3, 'C', 125]], 'from': 1, 'to': 3}, {'opening': 250, 'rows': [[3, 3, 375], [4, 3, 500], [5, 3, 450]], 'closing': 450}], ['control 5', {'normal': 'D', 'opening': 1000, 'lines': [[4, 8, 'D', 300], [2, 5, 'D', 125], [1, 10, 'D', 125], [3, 10, 'D', 125]], 'from': 6, 'to': 8}, {'opening': 1125, 'rows': [[4, 8, 1425]], 'closing': 1425}], ['control 6', {'normal': 'D', 'opening': 250, 'lines': [[4, 5, 'C', 10], [5, 5, 'C', 50], [1, 12, 'C', 300], [3, 5, 'C', 10], [2, 8, 'D', 50]], 'from': 1, 'to': 6}, {'opening': 250, 'rows': [[3, 5, 240], [4, 5, 230], [5, 5, 180]], 'closing': 180}]], [['regression: report opening cutoff', {'normal': 'C', 'opening': 250, 'lines': [[2, 12, 'C', 50], [1, 8, 'C', 125], [3, 5, 'D', 125]], 'from': 5, 'to': 7}, {'opening': 250, 'rows': [[3, 5, 125]], 'closing': 125}], ['control 1', {'normal': 'D', 'opening': 1000, 'lines': [[2, 8, 'C', 125], [1, 8, 'D', 50], [3, 5, 'D', 125]], 'from': 3, 'to': 5}, {'opening': 1000, 'rows': [[3, 5, 1125]], 'closing': 1125}], ['control 2', {'normal': 'D', 'opening': 0, 'lines': [[3, 5, 'C', 10], [1, 10, 'D', 125], [5, 5, 'C', 300], [2, 8, 'C', 50], [4, 5, 'D', 10]], 'from': 6, 'to': 11}, {'opening': -300, 'rows': [[2, 8, -350], [1, 10, -225]], 'closing': -225}], ['control 3', {'normal': 'D', 'opening': 1000, 'lines': [[2, 8, 'C', 10], [1, 12, 'C', 10], [3, 5, 'C', 50]], 'from': 6, 'to': 8}, {'opening': 950, 'rows': [[2, 8, 940]], 'closing': 940}], ['control 4', {'normal': 'C', 'opening': 250, 'lines': [[2, 8, 'D', 125], [1, 12, 'C', 10], [3, 12, 'C', 50]], 'from': 1, 'to': 6}, {'opening': 250, 'rows': [], 'closing': 250}], ['control 5', {'normal': 'C', 'opening': 250, 'lines': [[1, 10, 'C', 10], [3, 8, 'C', 50], [2, 10, 'D', 10]], 'from': 5, 'to': 10}, {'opening': 250, 'rows': [[3, 8, 300], [1, 10, 310], [2, 10, 300]], 'closing': 300}], ['control 6', {'normal': 'D', 'opening': 0, 'lines': [[2, 3, 'D', 50], [3, 12, 'D', 300], [1, 3, 'C', 50]], 'from': 6, 'to': 11}, {'opening': 0, 'rows': [], 'closing': 0}]], [['regression: report opening cutoff', {'normal': 'C', 'opening': 1000, 'lines': [[5, 5, 'C', 300], [3, 1, 'D', 10], [2, 10, 'D', 10], [4, 5, 'C', 300], [1, 5, 'C', 10]], 'from': 1, 'to': 3}, {'opening': 1000, 'rows': [[3, 1, 990]], 'closing': 990}], ['control 1', {'normal': 'C', 'opening': 250, 'lines': [[2, 3, 'D', 10], [3, 5, 'D', 50], [4, 8, 'D', 10], [1, 5, 'D', 300]], 'from': 6, 'to': 6}, {'opening': -110, 'rows': [], 'closing': -110}], ['control 2', {'normal': 'D', 'opening': 1000, 'lines': [[7, 8, 'C', 125], [5, 12, 'C', 10], [6, 5, 'D', 10], [4, 10, 'D', 10], [3, 8, 'C', 10], [2, 8, 'D', 50], [1, 5, 'D', 10]], 'from': 3, 'to': 5}, {'opening': 1000, 'rows': [[1, 5, 1010], [6, 5, 1020]], 'closing': 1020}], ['control 3', {'normal': 'C', 'opening': 0, 'lines': [[1, 5, 'D', 300], [4, 8, 'C', 300], [3, 12, 'C', 50], [2, 10, 'C', 125]], 'from': 1, 'to': 6}, {'opening': 0, 'rows': [[1, 5, -300]], 'closing': -300}], ['control 4', {'normal': 'C', 'opening': 1000, 'lines': [[2, 12, 'C', 50], [1, 3, 'C', 125], [3, 1, 'D', 10], [4, 5, 'D', 50]], 'from': 6, 'to': 11}, {'opening': 1065, 'rows': [], 'closing': 1065}], ['control 5', {'normal': 'D', 'opening': 0, 'lines': [[1, 8, 'D', 50], [2, 12, 'C', 50], [4, 1, 'D', 50], [5, 1, 'C', 50], [3, 10, 'D', 125]], 'from': 6, 'to': 8}, {'opening': 0, 'rows': [[1, 8, 50]], 'closing': 50}], ['control 6', {'normal': 'C', 'opening': 1000, 'lines': [[3, 10, 'C', 125], [6, 8, 'C', 10], [1, 10, 'D', 50], [2, 12, 'D', 300], [5, 3, 'D', 10], [4, 12, 'C', 300]], 'from': 1, 'to': 1}, {'opening': 1000, 'rows': [], 'closing': 1000}]], [['regression: report opening cutoff', {'normal': 'C', 'opening': 250, 'lines': [[3, 5, 'C', 300], [5, 5, 'C', 50], [4, 5, 'C', 300], [2, 10, 'D', 300], [1, 12, 'D', 300]], 'from': 5, 'to': 5}, {'opening': 250, 'rows': [[3, 5, 550], [4, 5, 850], [5, 5, 900]], 'closing': 900}], ['control 1', {'normal': 'C', 'opening': 250, 'lines': [[3, 8, 'C', 10], [2, 5, 'C', 10], [1, 8, 'C', 300]], 'from': 1, 'to': 8}, {'opening': 250, 'rows': [[2, 5, 260], [1, 8, 560], [3, 8, 570]], 'closing': 570}], ['control 2', {'normal': 'D', 'opening': 1000, 'lines': [[3, 3, 'D', 125], [6, 5, 'C', 125], [2, 8, 'C', 125], [1, 10, 'C', 125], [5, 12, 'C', 125], [7, 5, 'C', 300], [4, 5, 'D', 300]], 'from': 6, 'to': 8}, {'opening': 1000, 'rows': [[2, 8, 875]], 'closing': 875}], ['control 3', {'normal': 'C', 'opening': 0, 'lines': [[3, 8, 'C', 300], [1, 1, 'C', 10], [2, 12, 'C', 125]], 'from': 3, 'to': 3}, {'opening': 10, 'rows': [], 'closing': 10}], ['control 4', {'normal': 'D', 'opening': 1000, 'lines': [[4, 5, 'D', 300], [5, 12, 'D', 125], [3, 12, 'D', 125], [1, 1, 'D', 300], [2, 8, 'C', 10]], 'from': 3, 'to': 5}, {'opening': 1300, 'rows': [[4, 5, 1600]], 'closing': 1600}], ['control 5', {'normal': 'C', 'opening': 1000, 'lines': [[2, 8, 'C', 300], [3, 5, 'D', 300], [4, 8, 'C', 50], [5, 1, 'C', 300], [1, 5, 'C', 10]], 'from': 6, 'to': 11}, {'opening': 1010, 'rows': [[2, 8, 1310], [4, 8, 1360]], 'closing': 1360}], ['control 6', {'normal': 'D', 'opening': 1000, 'lines': [[1, 1, 'D', 300], [2, 1, 'D', 50], [3, 8, 'C', 10]], 'from': 5, 'to': 10}, {'opening': 1350, 'rows': [[3, 8, 1340]], 'closing': 1340}]]]
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 fixtureActualExpectedOutcome
regression: report opening cutoff{'closing': 400, 'opening': 650, 'rows': [[4, 5, 350], [5, 5, 400]]}{'closing': 400, 'opening': 700, 'rows': [[1, 3, 650], [4, 5, 350], [5, 5, 400]]}Failed
control 1{'closing': 60, 'opening': 60, 'rows': []}{'closing': 60, 'opening': 60, 'rows': []}Passed
control 2{'closing': 825, 'opening': 700, 'rows': [[1, 8, 825]]}{'closing': 825, 'opening': 700, 'rows': [[1, 8, 825]]}Passed
control 3{'closing': 465, 'opening': 540, 'rows': [[1, 8, 590], [3, 8, 465]]}{'closing': 465, 'opening': 540, 'rows': [[1, 8, 590], [3, 8, 465]]}Passed
control 4{'closing': 105, 'opening': 105, 'rows': []}{'closing': 105, 'opening': 105, 'rows': []}Passed
control 5{'closing': 250, 'opening': 250, 'rows': []}{'closing': 250, 'opening': 250, 'rows': []}Passed
control 6{'closing': 950, 'opening': 950, 'rows': []}{'closing': 950, 'opening': 950, 'rows': []}Passed

SHA-256 / 03c680ae1824a33b97356cff7f7ce11012d6fe169d0e3dd075594497031bed20

3 / The verified repair

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

N = 1
observations = []
def solve(x):
    sign = {'D': 1, 'C': -1} if x['normal'] == 'D' else {'D': -1, 'C': 1}
    lines = sorted(x['lines'], key=lambda l: (l[1], l[0]))
    opening = x['opening'] + sum(sign[s] * a for q, d, s, a in lines if d < x['from'])
    bal = opening
    rows = []
    for seq, date, side, amt in lines:
        if x['from'] <= date <= x['to']:
            bal += sign[side] * amt
            rows.append([seq, date, bal])
    return {'opening': opening, 'rows': rows, 'closing': bal}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: report opening cutoff', {'normal': 'D', 'opening': 1000, 'lines': [[4, 5, 'C', 300], [2, 1, 'C', 300], [1, 3, 'C', 50], [3, 12, 'C', 125], [5, 5, 'D', 50]], 'from': 3, 'to': 10}, {'opening': 700, 'rows': [[1, 3, 650], [4, 5, 350], [5, 5, 400]], 'closing': 400}], ['control 1', {'normal': 'C', 'opening': 0, 'lines': [[3, 5, 'C', 50], [6, 1, 'C', 10], [5, 10, 'C', 50], [4, 12, 'D', 300], [8, 5, 'D', 125], [2, 5, 'C', 125], [7, 12, 'D', 125], [1, 12, 'C', 50]], 'from': 6, 'to': 6}, {'opening': 60, 'rows': [], 'closing': 60}], ['control 2', {'normal': 'D', 'opening': 1000, 'lines': [[1, 8, 'D', 125], [8, 1, 'D', 125], [2, 10, 'D', 125], [7, 10, 'D', 50], [6, 5, 'C', 300], [3, 12, 'D', 300], [5, 12, 'C', 125], [4, 1, 'C', 125]], 'from': 6, 'to': 8}, {'opening': 700, 'rows': [[1, 8, 825]], 'closing': 825}], ['control 3', {'normal': 'D', 'opening': 250, 'lines': [[4, 5, 'D', 300], [3, 8, 'C', 125], [2, 5, 'C', 10], [1, 8, 'D', 50]], 'from': 6, 'to': 8}, {'opening': 540, 'rows': [[1, 8, 590], [3, 8, 465]], 'closing': 465}], ['control 4', {'normal': 'C', 'opening': 0, 'lines': [[5, 12, 'C', 125], [3, 5, 'C', 10], [4, 1, 'D', 50], [8, 5, 'C', 125], [1, 10, 'C', 10], [6, 1, 'C', 10], [7, 8, 'C', 125], [2, 3, 'C', 10]], 'from': 6, 'to': 6}, {'opening': 105, 'rows': [], 'closing': 105}], ['control 5', {'normal': 'D', 'opening': 250, 'lines': [[1, 8, 'D', 50], [2, 3, 'D', 125], [3, 10, 'C', 125]], 'from': 1, 'to': 1}, {'opening': 250, 'rows': [], 'closing': 250}], ['control 6', {'normal': 'C', 'opening': 1000, 'lines': [[7, 12, 'D', 50], [6, 3, 'D', 50], [3, 12, 'C', 50], [1, 3, 'C', 10], [5, 10, 'D', 125], [8, 10, 'D', 300], [4, 10, 'C', 50], [2, 3, 'D', 10]], 'from': 6, 'to': 8}, {'opening': 950, 'rows': [], 'closing': 950}]], [['regression: report opening cutoff', {'normal': 'D', 'opening': 1000, 'lines': [[2, 5, 'C', 300], [3, 3, 'D', 125], [4, 8, 'C', 50], [1, 5, 'C', 125], [5, 3, 'C', 300]], 'from': 5, 'to': 10}, {'opening': 825, 'rows': [[1, 5, 700], [2, 5, 400], [4, 8, 350]], 'closing': 350}], ['control 1', {'normal': 'C', 'opening': 250, 'lines': [[4, 8, 'C', 50], [1, 10, 'C', 50], [2, 12, 'D', 125], [6, 10, 'D', 125], [5, 5, 'D', 10], [3, 12, 'D', 50]], 'from': 3, 'to': 8}, {'opening': 250, 'rows': [[5, 5, 240], [4, 8, 290]], 'closing': 290}], ['control 2', {'normal': 'C', 'opening': 250, 'lines': [[2, 8, 'C', 125], [3, 3, 'D', 300], [1, 8, 'D', 50]], 'from': 1, 'to': 8}, {'opening': 250, 'rows': [[3, 3, -50], [1, 8, -100], [2, 8, 25]], 'closing': 25}], ['control 3', {'normal': 'C', 'opening': 250, 'lines': [[1, 8, 'D', 300], [2, 3, 'D', 10], [3, 3, 'D', 10], [4, 12, 'C', 300], [5, 12, 'D', 10]], 'from': 1, 'to': 1}, {'opening': 250, 'rows': [], 'closing': 250}], ['control 4', {'normal': 'C', 'opening': 250, 'lines': [[3, 3, 'C', 125], [2, 10, 'D', 125], [6, 12, 'D', 125], [5, 3, 'D', 50], [1, 8, 'C', 50], [4, 3, 'C', 125]], 'from': 1, 'to': 3}, {'opening': 250, 'rows': [[3, 3, 375], [4, 3, 500], [5, 3, 450]], 'closing': 450}], ['control 5', {'normal': 'D', 'opening': 1000, 'lines': [[4, 8, 'D', 300], [2, 5, 'D', 125], [1, 10, 'D', 125], [3, 10, 'D', 125]], 'from': 6, 'to': 8}, {'opening': 1125, 'rows': [[4, 8, 1425]], 'closing': 1425}], ['control 6', {'normal': 'D', 'opening': 250, 'lines': [[4, 5, 'C', 10], [5, 5, 'C', 50], [1, 12, 'C', 300], [3, 5, 'C', 10], [2, 8, 'D', 50]], 'from': 1, 'to': 6}, {'opening': 250, 'rows': [[3, 5, 240], [4, 5, 230], [5, 5, 180]], 'closing': 180}]], [['regression: report opening cutoff', {'normal': 'C', 'opening': 250, 'lines': [[2, 12, 'C', 50], [1, 8, 'C', 125], [3, 5, 'D', 125]], 'from': 5, 'to': 7}, {'opening': 250, 'rows': [[3, 5, 125]], 'closing': 125}], ['control 1', {'normal': 'D', 'opening': 1000, 'lines': [[2, 8, 'C', 125], [1, 8, 'D', 50], [3, 5, 'D', 125]], 'from': 3, 'to': 5}, {'opening': 1000, 'rows': [[3, 5, 1125]], 'closing': 1125}], ['control 2', {'normal': 'D', 'opening': 0, 'lines': [[3, 5, 'C', 10], [1, 10, 'D', 125], [5, 5, 'C', 300], [2, 8, 'C', 50], [4, 5, 'D', 10]], 'from': 6, 'to': 11}, {'opening': -300, 'rows': [[2, 8, -350], [1, 10, -225]], 'closing': -225}], ['control 3', {'normal': 'D', 'opening': 1000, 'lines': [[2, 8, 'C', 10], [1, 12, 'C', 10], [3, 5, 'C', 50]], 'from': 6, 'to': 8}, {'opening': 950, 'rows': [[2, 8, 940]], 'closing': 940}], ['control 4', {'normal': 'C', 'opening': 250, 'lines': [[2, 8, 'D', 125], [1, 12, 'C', 10], [3, 12, 'C', 50]], 'from': 1, 'to': 6}, {'opening': 250, 'rows': [], 'closing': 250}], ['control 5', {'normal': 'C', 'opening': 250, 'lines': [[1, 10, 'C', 10], [3, 8, 'C', 50], [2, 10, 'D', 10]], 'from': 5, 'to': 10}, {'opening': 250, 'rows': [[3, 8, 300], [1, 10, 310], [2, 10, 300]], 'closing': 300}], ['control 6', {'normal': 'D', 'opening': 0, 'lines': [[2, 3, 'D', 50], [3, 12, 'D', 300], [1, 3, 'C', 50]], 'from': 6, 'to': 11}, {'opening': 0, 'rows': [], 'closing': 0}]], [['regression: report opening cutoff', {'normal': 'C', 'opening': 1000, 'lines': [[5, 5, 'C', 300], [3, 1, 'D', 10], [2, 10, 'D', 10], [4, 5, 'C', 300], [1, 5, 'C', 10]], 'from': 1, 'to': 3}, {'opening': 1000, 'rows': [[3, 1, 990]], 'closing': 990}], ['control 1', {'normal': 'C', 'opening': 250, 'lines': [[2, 3, 'D', 10], [3, 5, 'D', 50], [4, 8, 'D', 10], [1, 5, 'D', 300]], 'from': 6, 'to': 6}, {'opening': -110, 'rows': [], 'closing': -110}], ['control 2', {'normal': 'D', 'opening': 1000, 'lines': [[7, 8, 'C', 125], [5, 12, 'C', 10], [6, 5, 'D', 10], [4, 10, 'D', 10], [3, 8, 'C', 10], [2, 8, 'D', 50], [1, 5, 'D', 10]], 'from': 3, 'to': 5}, {'opening': 1000, 'rows': [[1, 5, 1010], [6, 5, 1020]], 'closing': 1020}], ['control 3', {'normal': 'C', 'opening': 0, 'lines': [[1, 5, 'D', 300], [4, 8, 'C', 300], [3, 12, 'C', 50], [2, 10, 'C', 125]], 'from': 1, 'to': 6}, {'opening': 0, 'rows': [[1, 5, -300]], 'closing': -300}], ['control 4', {'normal': 'C', 'opening': 1000, 'lines': [[2, 12, 'C', 50], [1, 3, 'C', 125], [3, 1, 'D', 10], [4, 5, 'D', 50]], 'from': 6, 'to': 11}, {'opening': 1065, 'rows': [], 'closing': 1065}], ['control 5', {'normal': 'D', 'opening': 0, 'lines': [[1, 8, 'D', 50], [2, 12, 'C', 50], [4, 1, 'D', 50], [5, 1, 'C', 50], [3, 10, 'D', 125]], 'from': 6, 'to': 8}, {'opening': 0, 'rows': [[1, 8, 50]], 'closing': 50}], ['control 6', {'normal': 'C', 'opening': 1000, 'lines': [[3, 10, 'C', 125], [6, 8, 'C', 10], [1, 10, 'D', 50], [2, 12, 'D', 300], [5, 3, 'D', 10], [4, 12, 'C', 300]], 'from': 1, 'to': 1}, {'opening': 1000, 'rows': [], 'closing': 1000}]], [['regression: report opening cutoff', {'normal': 'C', 'opening': 250, 'lines': [[3, 5, 'C', 300], [5, 5, 'C', 50], [4, 5, 'C', 300], [2, 10, 'D', 300], [1, 12, 'D', 300]], 'from': 5, 'to': 5}, {'opening': 250, 'rows': [[3, 5, 550], [4, 5, 850], [5, 5, 900]], 'closing': 900}], ['control 1', {'normal': 'C', 'opening': 250, 'lines': [[3, 8, 'C', 10], [2, 5, 'C', 10], [1, 8, 'C', 300]], 'from': 1, 'to': 8}, {'opening': 250, 'rows': [[2, 5, 260], [1, 8, 560], [3, 8, 570]], 'closing': 570}], ['control 2', {'normal': 'D', 'opening': 1000, 'lines': [[3, 3, 'D', 125], [6, 5, 'C', 125], [2, 8, 'C', 125], [1, 10, 'C', 125], [5, 12, 'C', 125], [7, 5, 'C', 300], [4, 5, 'D', 300]], 'from': 6, 'to': 8}, {'opening': 1000, 'rows': [[2, 8, 875]], 'closing': 875}], ['control 3', {'normal': 'C', 'opening': 0, 'lines': [[3, 8, 'C', 300], [1, 1, 'C', 10], [2, 12, 'C', 125]], 'from': 3, 'to': 3}, {'opening': 10, 'rows': [], 'closing': 10}], ['control 4', {'normal': 'D', 'opening': 1000, 'lines': [[4, 5, 'D', 300], [5, 12, 'D', 125], [3, 12, 'D', 125], [1, 1, 'D', 300], [2, 8, 'C', 10]], 'from': 3, 'to': 5}, {'opening': 1300, 'rows': [[4, 5, 1600]], 'closing': 1600}], ['control 5', {'normal': 'C', 'opening': 1000, 'lines': [[2, 8, 'C', 300], [3, 5, 'D', 300], [4, 8, 'C', 50], [5, 1, 'C', 300], [1, 5, 'C', 10]], 'from': 6, 'to': 11}, {'opening': 1010, 'rows': [[2, 8, 1310], [4, 8, 1360]], 'closing': 1360}], ['control 6', {'normal': 'D', 'opening': 1000, 'lines': [[1, 1, 'D', 300], [2, 1, 'D', 50], [3, 8, 'C', 10]], 'from': 5, 'to': 10}, {'opening': 1350, 'rows': [[3, 8, 1340]], 'closing': 1340}]]]
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 fixtureActualExpectedOutcome
regression: report opening cutoff{'closing': 400, 'opening': 700, 'rows': [[1, 3, 650], [4, 5, 350], [5, 5, 400]]}{'closing': 400, 'opening': 700, 'rows': [[1, 3, 650], [4, 5, 350], [5, 5, 400]]}Passed
control 1{'closing': 60, 'opening': 60, 'rows': []}{'closing': 60, 'opening': 60, 'rows': []}Passed
control 2{'closing': 825, 'opening': 700, 'rows': [[1, 8, 825]]}{'closing': 825, 'opening': 700, 'rows': [[1, 8, 825]]}Passed
control 3{'closing': 465, 'opening': 540, 'rows': [[1, 8, 590], [3, 8, 465]]}{'closing': 465, 'opening': 540, 'rows': [[1, 8, 590], [3, 8, 465]]}Passed
control 4{'closing': 105, 'opening': 105, 'rows': []}{'closing': 105, 'opening': 105, 'rows': []}Passed
control 5{'closing': 250, 'opening': 250, 'rows': []}{'closing': 250, 'opening': 250, 'rows': []}Passed
control 6{'closing': 950, 'opening': 950, 'rows': []}{'closing': 950, 'opening': 950, 'rows': []}Passed

SHA-256 / 7f585d4cd5645b8b8b71665aa19d04700b25a7b521903e4ca5306569e54baeaa

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

Case digest / 6e5171dca654d6095f721599ef6bc327b2a615a3cc92423269f9cdf179847487