broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(rows, measurements, generation, width_key, minimum, estimate, details):
    heights={}
    for r in rows:
        k=r['id']; m=measurements.get(k)
        valid=m is not None and m['generation']==generation and m['width_key']==width_key
        h=m['height'] if valid else estimate
        heights[k]=h+details.get(k,0)
    ids=[r['id'] for r in rows]
    offsets={k:sum(heights[x] for x in ids[:i]) for i,k in enumerate(ids)}
    return {'heights':heights,'offsets':offsets,'total':sum(heights.values()),'remeasure':[r['id'] for r in rows if r['id'] not in measurements or measurements[r['id']]['generation']!=generation or measurements[r['id']]['width_key']!=width_key],'retained':{k:v for k,v in measurements.items() if k in ids}}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('fresh variable rows', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1+3,'generation':2,'width_key':'w'},'b':{'height':8,'generation':2,'width_key':'w'}}, 2, 'w', 2, 10, {'a':3}), {'heights': {'a': 7, 'b': 8}, 'offsets': {'a': 0, 'b': 7}, 'total': 15, 'remeasure': [], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'w'}, 'b': {'height': 8, 'generation': 2, 'width_key': 'w'}}})
    check('stale generation', solve([{'id':'a'}], {'a':{'height':4,'generation':1,'width_key':'w'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 1, 'width_key': 'w'}}})
    check('changed widths', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':'old'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'old'}}})
    check('typed width key', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':1}}, 2, '1', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 1}}})
    check('zero and stale id', solve([{'id':'a'}], {'a':{'height':0,'generation':2,'width_key':'w'},'gone':{'height':7,'generation':2,'width_key':'w'}}, 2, 'w', 0, 10, {}), {'heights': {'a': 0}, 'offsets': {'a': 0}, 'total': 0, 'remeasure': [], 'retained': {'a': {'height': 0, 'generation': 2, 'width_key': 'w'}}})
    check('minimum clamp', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1,'generation':2,'width_key':'w'}}, 2, 'w', 3, 10, {'b':2}), {'heights': {'a': 3, 'b': 12}, 'offsets': {'a': 0, 'b': 3}, 'total': 15, 'remeasure': ['b'], 'retained': {'a': {'height': 1, 'generation': 2, 'width_key': 'w'}}})
    check('empty', solve([], {}, 2, 'w', 3, 10, {}), {'heights': {}, 'offsets': {}, 'total': 0, 'remeasure': [], 'retained': {}})

if N == 2:
    check('fresh variable rows', solve([{'id':'a'},{'id':'b'}], {'a':{'height':2+3,'generation':2,'width_key':'w'},'b':{'height':8,'generation':2,'width_key':'w'}}, 2, 'w', 2, 10, {'a':3}), {'heights': {'a': 8, 'b': 8}, 'offsets': {'a': 0, 'b': 8}, 'total': 16, 'remeasure': [], 'retained': {'a': {'height': 5, 'generation': 2, 'width_key': 'w'}, 'b': {'height': 8, 'generation': 2, 'width_key': 'w'}}})
    check('stale generation', solve([{'id':'a'}], {'a':{'height':4,'generation':1,'width_key':'w'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 1, 'width_key': 'w'}}})
    check('changed widths', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':'old'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'old'}}})
    check('typed width key', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':1}}, 2, '1', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 1}}})
    check('zero and stale id', solve([{'id':'a'}], {'a':{'height':0,'generation':2,'width_key':'w'},'gone':{'height':7,'generation':2,'width_key':'w'}}, 2, 'w', 0, 10, {}), {'heights': {'a': 0}, 'offsets': {'a': 0}, 'total': 0, 'remeasure': [], 'retained': {'a': {'height': 0, 'generation': 2, 'width_key': 'w'}}})
    check('minimum clamp', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1,'generation':2,'width_key':'w'}}, 2, 'w', 3, 10, {'b':2}), {'heights': {'a': 3, 'b': 12}, 'offsets': {'a': 0, 'b': 3}, 'total': 15, 'remeasure': ['b'], 'retained': {'a': {'height': 1, 'generation': 2, 'width_key': 'w'}}})
    check('empty', solve([], {}, 2, 'w', 3, 10, {}), {'heights': {}, 'offsets': {}, 'total': 0, 'remeasure': [], 'retained': {}})

if N == 3:
    check('fresh variable rows', solve([{'id':'a'},{'id':'b'}], {'a':{'height':3+3,'generation':2,'width_key':'w'},'b':{'height':8,'generation':2,'width_key':'w'}}, 2, 'w', 2, 10, {'a':3}), {'heights': {'a': 9, 'b': 8}, 'offsets': {'a': 0, 'b': 9}, 'total': 17, 'remeasure': [], 'retained': {'a': {'height': 6, 'generation': 2, 'width_key': 'w'}, 'b': {'height': 8, 'generation': 2, 'width_key': 'w'}}})
    check('stale generation', solve([{'id':'a'}], {'a':{'height':4,'generation':1,'width_key':'w'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 1, 'width_key': 'w'}}})
    check('changed widths', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':'old'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'old'}}})
    check('typed width key', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':1}}, 2, '1', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 1}}})
    check('zero and stale id', solve([{'id':'a'}], {'a':{'height':0,'generation':2,'width_key':'w'},'gone':{'height':7,'generation':2,'width_key':'w'}}, 2, 'w', 0, 10, {}), {'heights': {'a': 0}, 'offsets': {'a': 0}, 'total': 0, 'remeasure': [], 'retained': {'a': {'height': 0, 'generation': 2, 'width_key': 'w'}}})
    check('minimum clamp', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1,'generation':2,'width_key':'w'}}, 2, 'w', 3, 10, {'b':2}), {'heights': {'a': 3, 'b': 12}, 'offsets': {'a': 0, 'b': 3}, 'total': 15, 'remeasure': ['b'], 'retained': {'a': {'height': 1, 'generation': 2, 'width_key': 'w'}}})
    check('empty', solve([], {}, 2, 'w', 3, 10, {}), {'heights': {}, 'offsets': {}, 'total': 0, 'remeasure': [], 'retained': {}})

if N == 4:
    check('fresh variable rows', solve([{'id':'a'},{'id':'b'}], {'a':{'height':4+3,'generation':2,'width_key':'w'},'b':{'height':8,'generation':2,'width_key':'w'}}, 2, 'w', 2, 10, {'a':3}), {'heights': {'a': 10, 'b': 8}, 'offsets': {'a': 0, 'b': 10}, 'total': 18, 'remeasure': [], 'retained': {'a': {'height': 7, 'generation': 2, 'width_key': 'w'}, 'b': {'height': 8, 'generation': 2, 'width_key': 'w'}}})
    check('stale generation', solve([{'id':'a'}], {'a':{'height':4,'generation':1,'width_key':'w'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 1, 'width_key': 'w'}}})
    check('changed widths', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':'old'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'old'}}})
    check('typed width key', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':1}}, 2, '1', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 1}}})
    check('zero and stale id', solve([{'id':'a'}], {'a':{'height':0,'generation':2,'width_key':'w'},'gone':{'height':7,'generation':2,'width_key':'w'}}, 2, 'w', 0, 10, {}), {'heights': {'a': 0}, 'offsets': {'a': 0}, 'total': 0, 'remeasure': [], 'retained': {'a': {'height': 0, 'generation': 2, 'width_key': 'w'}}})
    check('minimum clamp', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1,'generation':2,'width_key':'w'}}, 2, 'w', 3, 10, {'b':2}), {'heights': {'a': 3, 'b': 12}, 'offsets': {'a': 0, 'b': 3}, 'total': 15, 'remeasure': ['b'], 'retained': {'a': {'height': 1, 'generation': 2, 'width_key': 'w'}}})
    check('empty', solve([], {}, 2, 'w', 3, 10, {}), {'heights': {}, 'offsets': {}, 'total': 0, 'remeasure': [], 'retained': {}})

if N == 5:
    check('fresh variable rows', solve([{'id':'a'},{'id':'b'}], {'a':{'height':5+3,'generation':2,'width_key':'w'},'b':{'height':8,'generation':2,'width_key':'w'}}, 2, 'w', 2, 10, {'a':3}), {'heights': {'a': 11, 'b': 8}, 'offsets': {'a': 0, 'b': 11}, 'total': 19, 'remeasure': [], 'retained': {'a': {'height': 8, 'generation': 2, 'width_key': 'w'}, 'b': {'height': 8, 'generation': 2, 'width_key': 'w'}}})
    check('stale generation', solve([{'id':'a'}], {'a':{'height':4,'generation':1,'width_key':'w'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 1, 'width_key': 'w'}}})
    check('changed widths', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':'old'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'old'}}})
    check('typed width key', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':1}}, 2, '1', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 1}}})
    check('zero and stale id', solve([{'id':'a'}], {'a':{'height':0,'generation':2,'width_key':'w'},'gone':{'height':7,'generation':2,'width_key':'w'}}, 2, 'w', 0, 10, {}), {'heights': {'a': 0}, 'offsets': {'a': 0}, 'total': 0, 'remeasure': [], 'retained': {'a': {'height': 0, 'generation': 2, 'width_key': 'w'}}})
    check('minimum clamp', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1,'generation':2,'width_key':'w'}}, 2, 'w', 3, 10, {'b':2}), {'heights': {'a': 3, 'b': 12}, 'offsets': {'a': 0, 'b': 3}, 'total': 15, 'remeasure': ['b'], 'retained': {'a': {'height': 1, 'generation': 2, 'width_key': 'w'}}})
    check('empty', solve([], {}, 2, 'w', 3, 10, {}), {'heights': {}, 'offsets': {}, 'total': 0, 'remeasure': [], 'retained': {}})

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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(rows, measurements, generation, width_key, minimum, estimate, details):
    heights={}
    for r in rows:
        k=r['id']; m=measurements.get(k)
        valid=m is not None and m['generation']==generation and m['width_key']==width_key
        h=m['height'] if valid else estimate
        heights[k]=min(minimum,h)+details.get(k,0)
    ids=[r['id'] for r in rows]
    offsets={k:sum(heights[x] for x in ids[:i]) for i,k in enumerate(ids)}
    return {'heights':heights,'offsets':offsets,'total':sum(heights.values()),'remeasure':[r['id'] for r in rows if r['id'] not in measurements or measurements[r['id']]['generation']!=generation or measurements[r['id']]['width_key']!=width_key],'retained':{k:v for k,v in measurements.items() if k in ids}}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('fresh variable rows', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1+3,'generation':2,'width_key':'w'},'b':{'height':8,'generation':2,'width_key':'w'}}, 2, 'w', 2, 10, {'a':3}), {'heights': {'a': 7, 'b': 8}, 'offsets': {'a': 0, 'b': 7}, 'total': 15, 'remeasure': [], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'w'}, 'b': {'height': 8, 'generation': 2, 'width_key': 'w'}}})
    check('stale generation', solve([{'id':'a'}], {'a':{'height':4,'generation':1,'width_key':'w'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 1, 'width_key': 'w'}}})
    check('changed widths', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':'old'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'old'}}})
    check('typed width key', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':1}}, 2, '1', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 1}}})
    check('zero and stale id', solve([{'id':'a'}], {'a':{'height':0,'generation':2,'width_key':'w'},'gone':{'height':7,'generation':2,'width_key':'w'}}, 2, 'w', 0, 10, {}), {'heights': {'a': 0}, 'offsets': {'a': 0}, 'total': 0, 'remeasure': [], 'retained': {'a': {'height': 0, 'generation': 2, 'width_key': 'w'}}})
    check('minimum clamp', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1,'generation':2,'width_key':'w'}}, 2, 'w', 3, 10, {'b':2}), {'heights': {'a': 3, 'b': 12}, 'offsets': {'a': 0, 'b': 3}, 'total': 15, 'remeasure': ['b'], 'retained': {'a': {'height': 1, 'generation': 2, 'width_key': 'w'}}})
    check('empty', solve([], {}, 2, 'w', 3, 10, {}), {'heights': {}, 'offsets': {}, 'total': 0, 'remeasure': [], 'retained': {}})

if N == 2:
    check('fresh variable rows', solve([{'id':'a'},{'id':'b'}], {'a':{'height':2+3,'generation':2,'width_key':'w'},'b':{'height':8,'generation':2,'width_key':'w'}}, 2, 'w', 2, 10, {'a':3}), {'heights': {'a': 8, 'b': 8}, 'offsets': {'a': 0, 'b': 8}, 'total': 16, 'remeasure': [], 'retained': {'a': {'height': 5, 'generation': 2, 'width_key': 'w'}, 'b': {'height': 8, 'generation': 2, 'width_key': 'w'}}})
    check('stale generation', solve([{'id':'a'}], {'a':{'height':4,'generation':1,'width_key':'w'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 1, 'width_key': 'w'}}})
    check('changed widths', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':'old'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'old'}}})
    check('typed width key', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':1}}, 2, '1', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 1}}})
    check('zero and stale id', solve([{'id':'a'}], {'a':{'height':0,'generation':2,'width_key':'w'},'gone':{'height':7,'generation':2,'width_key':'w'}}, 2, 'w', 0, 10, {}), {'heights': {'a': 0}, 'offsets': {'a': 0}, 'total': 0, 'remeasure': [], 'retained': {'a': {'height': 0, 'generation': 2, 'width_key': 'w'}}})
    check('minimum clamp', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1,'generation':2,'width_key':'w'}}, 2, 'w', 3, 10, {'b':2}), {'heights': {'a': 3, 'b': 12}, 'offsets': {'a': 0, 'b': 3}, 'total': 15, 'remeasure': ['b'], 'retained': {'a': {'height': 1, 'generation': 2, 'width_key': 'w'}}})
    check('empty', solve([], {}, 2, 'w', 3, 10, {}), {'heights': {}, 'offsets': {}, 'total': 0, 'remeasure': [], 'retained': {}})

if N == 3:
    check('fresh variable rows', solve([{'id':'a'},{'id':'b'}], {'a':{'height':3+3,'generation':2,'width_key':'w'},'b':{'height':8,'generation':2,'width_key':'w'}}, 2, 'w', 2, 10, {'a':3}), {'heights': {'a': 9, 'b': 8}, 'offsets': {'a': 0, 'b': 9}, 'total': 17, 'remeasure': [], 'retained': {'a': {'height': 6, 'generation': 2, 'width_key': 'w'}, 'b': {'height': 8, 'generation': 2, 'width_key': 'w'}}})
    check('stale generation', solve([{'id':'a'}], {'a':{'height':4,'generation':1,'width_key':'w'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 1, 'width_key': 'w'}}})
    check('changed widths', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':'old'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'old'}}})
    check('typed width key', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':1}}, 2, '1', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 1}}})
    check('zero and stale id', solve([{'id':'a'}], {'a':{'height':0,'generation':2,'width_key':'w'},'gone':{'height':7,'generation':2,'width_key':'w'}}, 2, 'w', 0, 10, {}), {'heights': {'a': 0}, 'offsets': {'a': 0}, 'total': 0, 'remeasure': [], 'retained': {'a': {'height': 0, 'generation': 2, 'width_key': 'w'}}})
    check('minimum clamp', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1,'generation':2,'width_key':'w'}}, 2, 'w', 3, 10, {'b':2}), {'heights': {'a': 3, 'b': 12}, 'offsets': {'a': 0, 'b': 3}, 'total': 15, 'remeasure': ['b'], 'retained': {'a': {'height': 1, 'generation': 2, 'width_key': 'w'}}})
    check('empty', solve([], {}, 2, 'w', 3, 10, {}), {'heights': {}, 'offsets': {}, 'total': 0, 'remeasure': [], 'retained': {}})

if N == 4:
    check('fresh variable rows', solve([{'id':'a'},{'id':'b'}], {'a':{'height':4+3,'generation':2,'width_key':'w'},'b':{'height':8,'generation':2,'width_key':'w'}}, 2, 'w', 2, 10, {'a':3}), {'heights': {'a': 10, 'b': 8}, 'offsets': {'a': 0, 'b': 10}, 'total': 18, 'remeasure': [], 'retained': {'a': {'height': 7, 'generation': 2, 'width_key': 'w'}, 'b': {'height': 8, 'generation': 2, 'width_key': 'w'}}})
    check('stale generation', solve([{'id':'a'}], {'a':{'height':4,'generation':1,'width_key':'w'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 1, 'width_key': 'w'}}})
    check('changed widths', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':'old'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'old'}}})
    check('typed width key', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':1}}, 2, '1', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 1}}})
    check('zero and stale id', solve([{'id':'a'}], {'a':{'height':0,'generation':2,'width_key':'w'},'gone':{'height':7,'generation':2,'width_key':'w'}}, 2, 'w', 0, 10, {}), {'heights': {'a': 0}, 'offsets': {'a': 0}, 'total': 0, 'remeasure': [], 'retained': {'a': {'height': 0, 'generation': 2, 'width_key': 'w'}}})
    check('minimum clamp', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1,'generation':2,'width_key':'w'}}, 2, 'w', 3, 10, {'b':2}), {'heights': {'a': 3, 'b': 12}, 'offsets': {'a': 0, 'b': 3}, 'total': 15, 'remeasure': ['b'], 'retained': {'a': {'height': 1, 'generation': 2, 'width_key': 'w'}}})
    check('empty', solve([], {}, 2, 'w', 3, 10, {}), {'heights': {}, 'offsets': {}, 'total': 0, 'remeasure': [], 'retained': {}})

if N == 5:
    check('fresh variable rows', solve([{'id':'a'},{'id':'b'}], {'a':{'height':5+3,'generation':2,'width_key':'w'},'b':{'height':8,'generation':2,'width_key':'w'}}, 2, 'w', 2, 10, {'a':3}), {'heights': {'a': 11, 'b': 8}, 'offsets': {'a': 0, 'b': 11}, 'total': 19, 'remeasure': [], 'retained': {'a': {'height': 8, 'generation': 2, 'width_key': 'w'}, 'b': {'height': 8, 'generation': 2, 'width_key': 'w'}}})
    check('stale generation', solve([{'id':'a'}], {'a':{'height':4,'generation':1,'width_key':'w'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 1, 'width_key': 'w'}}})
    check('changed widths', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':'old'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'old'}}})
    check('typed width key', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':1}}, 2, '1', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 1}}})
    check('zero and stale id', solve([{'id':'a'}], {'a':{'height':0,'generation':2,'width_key':'w'},'gone':{'height':7,'generation':2,'width_key':'w'}}, 2, 'w', 0, 10, {}), {'heights': {'a': 0}, 'offsets': {'a': 0}, 'total': 0, 'remeasure': [], 'retained': {'a': {'height': 0, 'generation': 2, 'width_key': 'w'}}})
    check('minimum clamp', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1,'generation':2,'width_key':'w'}}, 2, 'w', 3, 10, {'b':2}), {'heights': {'a': 3, 'b': 12}, 'offsets': {'a': 0, 'b': 3}, 'total': 15, 'remeasure': ['b'], 'retained': {'a': {'height': 1, 'generation': 2, 'width_key': 'w'}}})
    check('empty', solve([], {}, 2, 'w', 3, 10, {}), {'heights': {}, 'offsets': {}, 'total': 0, 'remeasure': [], 'retained': {}})

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)

prompt:
The table minimum row height result violates the stipulated table row height measurement cache contract.

Measured row heights are keyed by stable row ID plus row-data generation and column-width fingerprint. Invalid measurements use an estimate, minimum applies before detail height, positions are ordered prefixes, and stale row measurements are pruned.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(rows, measurements, generation, width_key, minimum, estimate, details):
    heights={}
    for r in rows:
        k=r['id']; m=measurements.get(k)
        valid=m is not None and m['generation']==generation and m['width_key']==width_key
        h=m['height'] if valid else estimate
        heights[k]=max(minimum,h)
    ids=[r['id'] for r in rows]
    offsets={k:sum(heights[x] for x in ids[:i]) for i,k in enumerate(ids)}
    return {'heights':heights,'offsets':offsets,'total':sum(heights.values()),'remeasure':[r['id'] for r in rows if r['id'] not in measurements or measurements[r['id']]['generation']!=generation or measurements[r['id']]['width_key']!=width_key],'retained':{k:v for k,v in measurements.items() if k in ids}}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('fresh variable rows', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1+3,'generation':2,'width_key':'w'},'b':{'height':8,'generation':2,'width_key':'w'}}, 2, 'w', 2, 10, {'a':3}), {'heights': {'a': 7, 'b': 8}, 'offsets': {'a': 0, 'b': 7}, 'total': 15, 'remeasure': [], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'w'}, 'b': {'height': 8, 'generation': 2, 'width_key': 'w'}}})
    check('stale generation', solve([{'id':'a'}], {'a':{'height':4,'generation':1,'width_key':'w'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 1, 'width_key': 'w'}}})
    check('changed widths', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':'old'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'old'}}})
    check('typed width key', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':1}}, 2, '1', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 1}}})
    check('zero and stale id', solve([{'id':'a'}], {'a':{'height':0,'generation':2,'width_key':'w'},'gone':{'height':7,'generation':2,'width_key':'w'}}, 2, 'w', 0, 10, {}), {'heights': {'a': 0}, 'offsets': {'a': 0}, 'total': 0, 'remeasure': [], 'retained': {'a': {'height': 0, 'generation': 2, 'width_key': 'w'}}})
    check('minimum clamp', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1,'generation':2,'width_key':'w'}}, 2, 'w', 3, 10, {'b':2}), {'heights': {'a': 3, 'b': 12}, 'offsets': {'a': 0, 'b': 3}, 'total': 15, 'remeasure': ['b'], 'retained': {'a': {'height': 1, 'generation': 2, 'width_key': 'w'}}})
    check('empty', solve([], {}, 2, 'w', 3, 10, {}), {'heights': {}, 'offsets': {}, 'total': 0, 'remeasure': [], 'retained': {}})

if N == 2:
    check('fresh variable rows', solve([{'id':'a'},{'id':'b'}], {'a':{'height':2+3,'generation':2,'width_key':'w'},'b':{'height':8,'generation':2,'width_key':'w'}}, 2, 'w', 2, 10, {'a':3}), {'heights': {'a': 8, 'b': 8}, 'offsets': {'a': 0, 'b': 8}, 'total': 16, 'remeasure': [], 'retained': {'a': {'height': 5, 'generation': 2, 'width_key': 'w'}, 'b': {'height': 8, 'generation': 2, 'width_key': 'w'}}})
    check('stale generation', solve([{'id':'a'}], {'a':{'height':4,'generation':1,'width_key':'w'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 1, 'width_key': 'w'}}})
    check('changed widths', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':'old'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'old'}}})
    check('typed width key', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':1}}, 2, '1', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 1}}})
    check('zero and stale id', solve([{'id':'a'}], {'a':{'height':0,'generation':2,'width_key':'w'},'gone':{'height':7,'generation':2,'width_key':'w'}}, 2, 'w', 0, 10, {}), {'heights': {'a': 0}, 'offsets': {'a': 0}, 'total': 0, 'remeasure': [], 'retained': {'a': {'height': 0, 'generation': 2, 'width_key': 'w'}}})
    check('minimum clamp', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1,'generation':2,'width_key':'w'}}, 2, 'w', 3, 10, {'b':2}), {'heights': {'a': 3, 'b': 12}, 'offsets': {'a': 0, 'b': 3}, 'total': 15, 'remeasure': ['b'], 'retained': {'a': {'height': 1, 'generation': 2, 'width_key': 'w'}}})
    check('empty', solve([], {}, 2, 'w', 3, 10, {}), {'heights': {}, 'offsets': {}, 'total': 0, 'remeasure': [], 'retained': {}})

if N == 3:
    check('fresh variable rows', solve([{'id':'a'},{'id':'b'}], {'a':{'height':3+3,'generation':2,'width_key':'w'},'b':{'height':8,'generation':2,'width_key':'w'}}, 2, 'w', 2, 10, {'a':3}), {'heights': {'a': 9, 'b': 8}, 'offsets': {'a': 0, 'b': 9}, 'total': 17, 'remeasure': [], 'retained': {'a': {'height': 6, 'generation': 2, 'width_key': 'w'}, 'b': {'height': 8, 'generation': 2, 'width_key': 'w'}}})
    check('stale generation', solve([{'id':'a'}], {'a':{'height':4,'generation':1,'width_key':'w'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 1, 'width_key': 'w'}}})
    check('changed widths', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':'old'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'old'}}})
    check('typed width key', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':1}}, 2, '1', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 1}}})
    check('zero and stale id', solve([{'id':'a'}], {'a':{'height':0,'generation':2,'width_key':'w'},'gone':{'height':7,'generation':2,'width_key':'w'}}, 2, 'w', 0, 10, {}), {'heights': {'a': 0}, 'offsets': {'a': 0}, 'total': 0, 'remeasure': [], 'retained': {'a': {'height': 0, 'generation': 2, 'width_key': 'w'}}})
    check('minimum clamp', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1,'generation':2,'width_key':'w'}}, 2, 'w', 3, 10, {'b':2}), {'heights': {'a': 3, 'b': 12}, 'offsets': {'a': 0, 'b': 3}, 'total': 15, 'remeasure': ['b'], 'retained': {'a': {'height': 1, 'generation': 2, 'width_key': 'w'}}})
    check('empty', solve([], {}, 2, 'w', 3, 10, {}), {'heights': {}, 'offsets': {}, 'total': 0, 'remeasure': [], 'retained': {}})

if N == 4:
    check('fresh variable rows', solve([{'id':'a'},{'id':'b'}], {'a':{'height':4+3,'generation':2,'width_key':'w'},'b':{'height':8,'generation':2,'width_key':'w'}}, 2, 'w', 2, 10, {'a':3}), {'heights': {'a': 10, 'b': 8}, 'offsets': {'a': 0, 'b': 10}, 'total': 18, 'remeasure': [], 'retained': {'a': {'height': 7, 'generation': 2, 'width_key': 'w'}, 'b': {'height': 8, 'generation': 2, 'width_key': 'w'}}})
    check('stale generation', solve([{'id':'a'}], {'a':{'height':4,'generation':1,'width_key':'w'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 1, 'width_key': 'w'}}})
    check('changed widths', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':'old'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'old'}}})
    check('typed width key', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':1}}, 2, '1', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 1}}})
    check('zero and stale id', solve([{'id':'a'}], {'a':{'height':0,'generation':2,'width_key':'w'},'gone':{'height':7,'generation':2,'width_key':'w'}}, 2, 'w', 0, 10, {}), {'heights': {'a': 0}, 'offsets': {'a': 0}, 'total': 0, 'remeasure': [], 'retained': {'a': {'height': 0, 'generation': 2, 'width_key': 'w'}}})
    check('minimum clamp', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1,'generation':2,'width_key':'w'}}, 2, 'w', 3, 10, {'b':2}), {'heights': {'a': 3, 'b': 12}, 'offsets': {'a': 0, 'b': 3}, 'total': 15, 'remeasure': ['b'], 'retained': {'a': {'height': 1, 'generation': 2, 'width_key': 'w'}}})
    check('empty', solve([], {}, 2, 'w', 3, 10, {}), {'heights': {}, 'offsets': {}, 'total': 0, 'remeasure': [], 'retained': {}})

if N == 5:
    check('fresh variable rows', solve([{'id':'a'},{'id':'b'}], {'a':{'height':5+3,'generation':2,'width_key':'w'},'b':{'height':8,'generation':2,'width_key':'w'}}, 2, 'w', 2, 10, {'a':3}), {'heights': {'a': 11, 'b': 8}, 'offsets': {'a': 0, 'b': 11}, 'total': 19, 'remeasure': [], 'retained': {'a': {'height': 8, 'generation': 2, 'width_key': 'w'}, 'b': {'height': 8, 'generation': 2, 'width_key': 'w'}}})
    check('stale generation', solve([{'id':'a'}], {'a':{'height':4,'generation':1,'width_key':'w'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 1, 'width_key': 'w'}}})
    check('changed widths', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':'old'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'old'}}})
    check('typed width key', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':1}}, 2, '1', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 1}}})
    check('zero and stale id', solve([{'id':'a'}], {'a':{'height':0,'generation':2,'width_key':'w'},'gone':{'height':7,'generation':2,'width_key':'w'}}, 2, 'w', 0, 10, {}), {'heights': {'a': 0}, 'offsets': {'a': 0}, 'total': 0, 'remeasure': [], 'retained': {'a': {'height': 0, 'generation': 2, 'width_key': 'w'}}})
    check('minimum clamp', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1,'generation':2,'width_key':'w'}}, 2, 'w', 3, 10, {'b':2}), {'heights': {'a': 3, 'b': 12}, 'offsets': {'a': 0, 'b': 3}, 'total': 15, 'remeasure': ['b'], 'retained': {'a': {'height': 1, 'generation': 2, 'width_key': 'w'}}})
    check('empty', solve([], {}, 2, 'w', 3, 10, {}), {'heights': {}, 'offsets': {}, 'total': 0, 'remeasure': [], 'retained': {}})

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)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(rows, measurements, generation, width_key, minimum, estimate, details):
    heights={}
    for r in rows:
        k=r['id']; m=measurements.get(k)
        valid=m is not None and m['generation']==generation and m['width_key']==width_key
        h=m['height'] if valid else estimate
        heights[k]=max(minimum,h)+max(details.values(),default=0)
    ids=[r['id'] for r in rows]
    offsets={k:sum(heights[x] for x in ids[:i]) for i,k in enumerate(ids)}
    return {'heights':heights,'offsets':offsets,'total':sum(heights.values()),'remeasure':[r['id'] for r in rows if r['id'] not in measurements or measurements[r['id']]['generation']!=generation or measurements[r['id']]['width_key']!=width_key],'retained':{k:v for k,v in measurements.items() if k in ids}}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('fresh variable rows', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1+3,'generation':2,'width_key':'w'},'b':{'height':8,'generation':2,'width_key':'w'}}, 2, 'w', 2, 10, {'a':3}), {'heights': {'a': 7, 'b': 8}, 'offsets': {'a': 0, 'b': 7}, 'total': 15, 'remeasure': [], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'w'}, 'b': {'height': 8, 'generation': 2, 'width_key': 'w'}}})
    check('stale generation', solve([{'id':'a'}], {'a':{'height':4,'generation':1,'width_key':'w'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 1, 'width_key': 'w'}}})
    check('changed widths', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':'old'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'old'}}})
    check('typed width key', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':1}}, 2, '1', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 1}}})
    check('zero and stale id', solve([{'id':'a'}], {'a':{'height':0,'generation':2,'width_key':'w'},'gone':{'height':7,'generation':2,'width_key':'w'}}, 2, 'w', 0, 10, {}), {'heights': {'a': 0}, 'offsets': {'a': 0}, 'total': 0, 'remeasure': [], 'retained': {'a': {'height': 0, 'generation': 2, 'width_key': 'w'}}})
    check('minimum clamp', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1,'generation':2,'width_key':'w'}}, 2, 'w', 3, 10, {'b':2}), {'heights': {'a': 3, 'b': 12}, 'offsets': {'a': 0, 'b': 3}, 'total': 15, 'remeasure': ['b'], 'retained': {'a': {'height': 1, 'generation': 2, 'width_key': 'w'}}})
    check('empty', solve([], {}, 2, 'w', 3, 10, {}), {'heights': {}, 'offsets': {}, 'total': 0, 'remeasure': [], 'retained': {}})

if N == 2:
    check('fresh variable rows', solve([{'id':'a'},{'id':'b'}], {'a':{'height':2+3,'generation':2,'width_key':'w'},'b':{'height':8,'generation':2,'width_key':'w'}}, 2, 'w', 2, 10, {'a':3}), {'heights': {'a': 8, 'b': 8}, 'offsets': {'a': 0, 'b': 8}, 'total': 16, 'remeasure': [], 'retained': {'a': {'height': 5, 'generation': 2, 'width_key': 'w'}, 'b': {'height': 8, 'generation': 2, 'width_key': 'w'}}})
    check('stale generation', solve([{'id':'a'}], {'a':{'height':4,'generation':1,'width_key':'w'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 1, 'width_key': 'w'}}})
    check('changed widths', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':'old'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'old'}}})
    check('typed width key', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':1}}, 2, '1', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 1}}})
    check('zero and stale id', solve([{'id':'a'}], {'a':{'height':0,'generation':2,'width_key':'w'},'gone':{'height':7,'generation':2,'width_key':'w'}}, 2, 'w', 0, 10, {}), {'heights': {'a': 0}, 'offsets': {'a': 0}, 'total': 0, 'remeasure': [], 'retained': {'a': {'height': 0, 'generation': 2, 'width_key': 'w'}}})
    check('minimum clamp', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1,'generation':2,'width_key':'w'}}, 2, 'w', 3, 10, {'b':2}), {'heights': {'a': 3, 'b': 12}, 'offsets': {'a': 0, 'b': 3}, 'total': 15, 'remeasure': ['b'], 'retained': {'a': {'height': 1, 'generation': 2, 'width_key': 'w'}}})
    check('empty', solve([], {}, 2, 'w', 3, 10, {}), {'heights': {}, 'offsets': {}, 'total': 0, 'remeasure': [], 'retained': {}})

if N == 3:
    check('fresh variable rows', solve([{'id':'a'},{'id':'b'}], {'a':{'height':3+3,'generation':2,'width_key':'w'},'b':{'height':8,'generation':2,'width_key':'w'}}, 2, 'w', 2, 10, {'a':3}), {'heights': {'a': 9, 'b': 8}, 'offsets': {'a': 0, 'b': 9}, 'total': 17, 'remeasure': [], 'retained': {'a': {'height': 6, 'generation': 2, 'width_key': 'w'}, 'b': {'height': 8, 'generation': 2, 'width_key': 'w'}}})
    check('stale generation', solve([{'id':'a'}], {'a':{'height':4,'generation':1,'width_key':'w'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 1, 'width_key': 'w'}}})
    check('changed widths', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':'old'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'old'}}})
    check('typed width key', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':1}}, 2, '1', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 1}}})
    check('zero and stale id', solve([{'id':'a'}], {'a':{'height':0,'generation':2,'width_key':'w'},'gone':{'height':7,'generation':2,'width_key':'w'}}, 2, 'w', 0, 10, {}), {'heights': {'a': 0}, 'offsets': {'a': 0}, 'total': 0, 'remeasure': [], 'retained': {'a': {'height': 0, 'generation': 2, 'width_key': 'w'}}})
    check('minimum clamp', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1,'generation':2,'width_key':'w'}}, 2, 'w', 3, 10, {'b':2}), {'heights': {'a': 3, 'b': 12}, 'offsets': {'a': 0, 'b': 3}, 'total': 15, 'remeasure': ['b'], 'retained': {'a': {'height': 1, 'generation': 2, 'width_key': 'w'}}})
    check('empty', solve([], {}, 2, 'w', 3, 10, {}), {'heights': {}, 'offsets': {}, 'total': 0, 'remeasure': [], 'retained': {}})

if N == 4:
    check('fresh variable rows', solve([{'id':'a'},{'id':'b'}], {'a':{'height':4+3,'generation':2,'width_key':'w'},'b':{'height':8,'generation':2,'width_key':'w'}}, 2, 'w', 2, 10, {'a':3}), {'heights': {'a': 10, 'b': 8}, 'offsets': {'a': 0, 'b': 10}, 'total': 18, 'remeasure': [], 'retained': {'a': {'height': 7, 'generation': 2, 'width_key': 'w'}, 'b': {'height': 8, 'generation': 2, 'width_key': 'w'}}})
    check('stale generation', solve([{'id':'a'}], {'a':{'height':4,'generation':1,'width_key':'w'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 1, 'width_key': 'w'}}})
    check('changed widths', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':'old'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'old'}}})
    check('typed width key', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':1}}, 2, '1', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 1}}})
    check('zero and stale id', solve([{'id':'a'}], {'a':{'height':0,'generation':2,'width_key':'w'},'gone':{'height':7,'generation':2,'width_key':'w'}}, 2, 'w', 0, 10, {}), {'heights': {'a': 0}, 'offsets': {'a': 0}, 'total': 0, 'remeasure': [], 'retained': {'a': {'height': 0, 'generation': 2, 'width_key': 'w'}}})
    check('minimum clamp', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1,'generation':2,'width_key':'w'}}, 2, 'w', 3, 10, {'b':2}), {'heights': {'a': 3, 'b': 12}, 'offsets': {'a': 0, 'b': 3}, 'total': 15, 'remeasure': ['b'], 'retained': {'a': {'height': 1, 'generation': 2, 'width_key': 'w'}}})
    check('empty', solve([], {}, 2, 'w', 3, 10, {}), {'heights': {}, 'offsets': {}, 'total': 0, 'remeasure': [], 'retained': {}})

if N == 5:
    check('fresh variable rows', solve([{'id':'a'},{'id':'b'}], {'a':{'height':5+3,'generation':2,'width_key':'w'},'b':{'height':8,'generation':2,'width_key':'w'}}, 2, 'w', 2, 10, {'a':3}), {'heights': {'a': 11, 'b': 8}, 'offsets': {'a': 0, 'b': 11}, 'total': 19, 'remeasure': [], 'retained': {'a': {'height': 8, 'generation': 2, 'width_key': 'w'}, 'b': {'height': 8, 'generation': 2, 'width_key': 'w'}}})
    check('stale generation', solve([{'id':'a'}], {'a':{'height':4,'generation':1,'width_key':'w'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 1, 'width_key': 'w'}}})
    check('changed widths', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':'old'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'old'}}})
    check('typed width key', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':1}}, 2, '1', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 1}}})
    check('zero and stale id', solve([{'id':'a'}], {'a':{'height':0,'generation':2,'width_key':'w'},'gone':{'height':7,'generation':2,'width_key':'w'}}, 2, 'w', 0, 10, {}), {'heights': {'a': 0}, 'offsets': {'a': 0}, 'total': 0, 'remeasure': [], 'retained': {'a': {'height': 0, 'generation': 2, 'width_key': 'w'}}})
    check('minimum clamp', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1,'generation':2,'width_key':'w'}}, 2, 'w', 3, 10, {'b':2}), {'heights': {'a': 3, 'b': 12}, 'offsets': {'a': 0, 'b': 3}, 'total': 15, 'remeasure': ['b'], 'retained': {'a': {'height': 1, 'generation': 2, 'width_key': 'w'}}})
    check('empty', solve([], {}, 2, 'w', 3, 10, {}), {'heights': {}, 'offsets': {}, 'total': 0, 'remeasure': [], 'retained': {}})

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)

prompt:
The table detail height composition result violates the stipulated table row height measurement cache contract.

Measured row heights are keyed by stable row ID plus row-data generation and column-width fingerprint. Invalid measurements use an estimate, minimum applies before detail height, positions are ordered prefixes, and stale row measurements are pruned.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(rows, measurements, generation, width_key, minimum, estimate, details):
    heights={}
    for r in rows:
        k=r['id']; m=measurements.get(k)
        valid=m is not None and m['generation']==generation and m['width_key']==width_key
        h=m['height'] if valid else estimate
        heights[k]=max(minimum,h)+details.get(k,0)
    ids=[r['id'] for r in rows]
    offsets={k:sum(heights[x] for x in ids[:i+1]) for i,k in enumerate(ids)}
    return {'heights':heights,'offsets':offsets,'total':sum(heights.values()),'remeasure':[r['id'] for r in rows if r['id'] not in measurements or measurements[r['id']]['generation']!=generation or measurements[r['id']]['width_key']!=width_key],'retained':{k:v for k,v in measurements.items() if k in ids}}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('fresh variable rows', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1+3,'generation':2,'width_key':'w'},'b':{'height':8,'generation':2,'width_key':'w'}}, 2, 'w', 2, 10, {'a':3}), {'heights': {'a': 7, 'b': 8}, 'offsets': {'a': 0, 'b': 7}, 'total': 15, 'remeasure': [], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'w'}, 'b': {'height': 8, 'generation': 2, 'width_key': 'w'}}})
    check('stale generation', solve([{'id':'a'}], {'a':{'height':4,'generation':1,'width_key':'w'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 1, 'width_key': 'w'}}})
    check('changed widths', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':'old'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'old'}}})
    check('typed width key', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':1}}, 2, '1', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 1}}})
    check('zero and stale id', solve([{'id':'a'}], {'a':{'height':0,'generation':2,'width_key':'w'},'gone':{'height':7,'generation':2,'width_key':'w'}}, 2, 'w', 0, 10, {}), {'heights': {'a': 0}, 'offsets': {'a': 0}, 'total': 0, 'remeasure': [], 'retained': {'a': {'height': 0, 'generation': 2, 'width_key': 'w'}}})
    check('minimum clamp', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1,'generation':2,'width_key':'w'}}, 2, 'w', 3, 10, {'b':2}), {'heights': {'a': 3, 'b': 12}, 'offsets': {'a': 0, 'b': 3}, 'total': 15, 'remeasure': ['b'], 'retained': {'a': {'height': 1, 'generation': 2, 'width_key': 'w'}}})
    check('empty', solve([], {}, 2, 'w', 3, 10, {}), {'heights': {}, 'offsets': {}, 'total': 0, 'remeasure': [], 'retained': {}})

if N == 2:
    check('fresh variable rows', solve([{'id':'a'},{'id':'b'}], {'a':{'height':2+3,'generation':2,'width_key':'w'},'b':{'height':8,'generation':2,'width_key':'w'}}, 2, 'w', 2, 10, {'a':3}), {'heights': {'a': 8, 'b': 8}, 'offsets': {'a': 0, 'b': 8}, 'total': 16, 'remeasure': [], 'retained': {'a': {'height': 5, 'generation': 2, 'width_key': 'w'}, 'b': {'height': 8, 'generation': 2, 'width_key': 'w'}}})
    check('stale generation', solve([{'id':'a'}], {'a':{'height':4,'generation':1,'width_key':'w'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 1, 'width_key': 'w'}}})
    check('changed widths', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':'old'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'old'}}})
    check('typed width key', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':1}}, 2, '1', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 1}}})
    check('zero and stale id', solve([{'id':'a'}], {'a':{'height':0,'generation':2,'width_key':'w'},'gone':{'height':7,'generation':2,'width_key':'w'}}, 2, 'w', 0, 10, {}), {'heights': {'a': 0}, 'offsets': {'a': 0}, 'total': 0, 'remeasure': [], 'retained': {'a': {'height': 0, 'generation': 2, 'width_key': 'w'}}})
    check('minimum clamp', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1,'generation':2,'width_key':'w'}}, 2, 'w', 3, 10, {'b':2}), {'heights': {'a': 3, 'b': 12}, 'offsets': {'a': 0, 'b': 3}, 'total': 15, 'remeasure': ['b'], 'retained': {'a': {'height': 1, 'generation': 2, 'width_key': 'w'}}})
    check('empty', solve([], {}, 2, 'w', 3, 10, {}), {'heights': {}, 'offsets': {}, 'total': 0, 'remeasure': [], 'retained': {}})

if N == 3:
    check('fresh variable rows', solve([{'id':'a'},{'id':'b'}], {'a':{'height':3+3,'generation':2,'width_key':'w'},'b':{'height':8,'generation':2,'width_key':'w'}}, 2, 'w', 2, 10, {'a':3}), {'heights': {'a': 9, 'b': 8}, 'offsets': {'a': 0, 'b': 9}, 'total': 17, 'remeasure': [], 'retained': {'a': {'height': 6, 'generation': 2, 'width_key': 'w'}, 'b': {'height': 8, 'generation': 2, 'width_key': 'w'}}})
    check('stale generation', solve([{'id':'a'}], {'a':{'height':4,'generation':1,'width_key':'w'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 1, 'width_key': 'w'}}})
    check('changed widths', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':'old'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'old'}}})
    check('typed width key', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':1}}, 2, '1', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 1}}})
    check('zero and stale id', solve([{'id':'a'}], {'a':{'height':0,'generation':2,'width_key':'w'},'gone':{'height':7,'generation':2,'width_key':'w'}}, 2, 'w', 0, 10, {}), {'heights': {'a': 0}, 'offsets': {'a': 0}, 'total': 0, 'remeasure': [], 'retained': {'a': {'height': 0, 'generation': 2, 'width_key': 'w'}}})
    check('minimum clamp', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1,'generation':2,'width_key':'w'}}, 2, 'w', 3, 10, {'b':2}), {'heights': {'a': 3, 'b': 12}, 'offsets': {'a': 0, 'b': 3}, 'total': 15, 'remeasure': ['b'], 'retained': {'a': {'height': 1, 'generation': 2, 'width_key': 'w'}}})
    check('empty', solve([], {}, 2, 'w', 3, 10, {}), {'heights': {}, 'offsets': {}, 'total': 0, 'remeasure': [], 'retained': {}})

if N == 4:
    check('fresh variable rows', solve([{'id':'a'},{'id':'b'}], {'a':{'height':4+3,'generation':2,'width_key':'w'},'b':{'height':8,'generation':2,'width_key':'w'}}, 2, 'w', 2, 10, {'a':3}), {'heights': {'a': 10, 'b': 8}, 'offsets': {'a': 0, 'b': 10}, 'total': 18, 'remeasure': [], 'retained': {'a': {'height': 7, 'generation': 2, 'width_key': 'w'}, 'b': {'height': 8, 'generation': 2, 'width_key': 'w'}}})
    check('stale generation', solve([{'id':'a'}], {'a':{'height':4,'generation':1,'width_key':'w'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 1, 'width_key': 'w'}}})
    check('changed widths', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':'old'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'old'}}})
    check('typed width key', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':1}}, 2, '1', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 1}}})
    check('zero and stale id', solve([{'id':'a'}], {'a':{'height':0,'generation':2,'width_key':'w'},'gone':{'height':7,'generation':2,'width_key':'w'}}, 2, 'w', 0, 10, {}), {'heights': {'a': 0}, 'offsets': {'a': 0}, 'total': 0, 'remeasure': [], 'retained': {'a': {'height': 0, 'generation': 2, 'width_key': 'w'}}})
    check('minimum clamp', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1,'generation':2,'width_key':'w'}}, 2, 'w', 3, 10, {'b':2}), {'heights': {'a': 3, 'b': 12}, 'offsets': {'a': 0, 'b': 3}, 'total': 15, 'remeasure': ['b'], 'retained': {'a': {'height': 1, 'generation': 2, 'width_key': 'w'}}})
    check('empty', solve([], {}, 2, 'w', 3, 10, {}), {'heights': {}, 'offsets': {}, 'total': 0, 'remeasure': [], 'retained': {}})

if N == 5:
    check('fresh variable rows', solve([{'id':'a'},{'id':'b'}], {'a':{'height':5+3,'generation':2,'width_key':'w'},'b':{'height':8,'generation':2,'width_key':'w'}}, 2, 'w', 2, 10, {'a':3}), {'heights': {'a': 11, 'b': 8}, 'offsets': {'a': 0, 'b': 11}, 'total': 19, 'remeasure': [], 'retained': {'a': {'height': 8, 'generation': 2, 'width_key': 'w'}, 'b': {'height': 8, 'generation': 2, 'width_key': 'w'}}})
    check('stale generation', solve([{'id':'a'}], {'a':{'height':4,'generation':1,'width_key':'w'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 1, 'width_key': 'w'}}})
    check('changed widths', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':'old'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'old'}}})
    check('typed width key', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':1}}, 2, '1', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 1}}})
    check('zero and stale id', solve([{'id':'a'}], {'a':{'height':0,'generation':2,'width_key':'w'},'gone':{'height':7,'generation':2,'width_key':'w'}}, 2, 'w', 0, 10, {}), {'heights': {'a': 0}, 'offsets': {'a': 0}, 'total': 0, 'remeasure': [], 'retained': {'a': {'height': 0, 'generation': 2, 'width_key': 'w'}}})
    check('minimum clamp', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1,'generation':2,'width_key':'w'}}, 2, 'w', 3, 10, {'b':2}), {'heights': {'a': 3, 'b': 12}, 'offsets': {'a': 0, 'b': 3}, 'total': 15, 'remeasure': ['b'], 'retained': {'a': {'height': 1, 'generation': 2, 'width_key': 'w'}}})
    check('empty', solve([], {}, 2, 'w', 3, 10, {}), {'heights': {}, 'offsets': {}, 'total': 0, 'remeasure': [], 'retained': {}})

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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(rows, measurements, generation, width_key, minimum, estimate, details):
    heights={}
    for r in rows:
        k=r['id']; m=measurements.get(k)
        valid=m is not None and m['generation']==generation and m['width_key']==width_key
        h=m['height'] if valid else estimate
        heights[k]=max(minimum,h)+details.get(k,0)
    ids=[r['id'] for r in rows]
    offsets={k:sum(heights[x] for x in ids[i+1:]) for i,k in enumerate(ids)}
    return {'heights':heights,'offsets':offsets,'total':sum(heights.values()),'remeasure':[r['id'] for r in rows if r['id'] not in measurements or measurements[r['id']]['generation']!=generation or measurements[r['id']]['width_key']!=width_key],'retained':{k:v for k,v in measurements.items() if k in ids}}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('fresh variable rows', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1+3,'generation':2,'width_key':'w'},'b':{'height':8,'generation':2,'width_key':'w'}}, 2, 'w', 2, 10, {'a':3}), {'heights': {'a': 7, 'b': 8}, 'offsets': {'a': 0, 'b': 7}, 'total': 15, 'remeasure': [], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'w'}, 'b': {'height': 8, 'generation': 2, 'width_key': 'w'}}})
    check('stale generation', solve([{'id':'a'}], {'a':{'height':4,'generation':1,'width_key':'w'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 1, 'width_key': 'w'}}})
    check('changed widths', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':'old'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'old'}}})
    check('typed width key', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':1}}, 2, '1', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 1}}})
    check('zero and stale id', solve([{'id':'a'}], {'a':{'height':0,'generation':2,'width_key':'w'},'gone':{'height':7,'generation':2,'width_key':'w'}}, 2, 'w', 0, 10, {}), {'heights': {'a': 0}, 'offsets': {'a': 0}, 'total': 0, 'remeasure': [], 'retained': {'a': {'height': 0, 'generation': 2, 'width_key': 'w'}}})
    check('minimum clamp', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1,'generation':2,'width_key':'w'}}, 2, 'w', 3, 10, {'b':2}), {'heights': {'a': 3, 'b': 12}, 'offsets': {'a': 0, 'b': 3}, 'total': 15, 'remeasure': ['b'], 'retained': {'a': {'height': 1, 'generation': 2, 'width_key': 'w'}}})
    check('empty', solve([], {}, 2, 'w', 3, 10, {}), {'heights': {}, 'offsets': {}, 'total': 0, 'remeasure': [], 'retained': {}})

if N == 2:
    check('fresh variable rows', solve([{'id':'a'},{'id':'b'}], {'a':{'height':2+3,'generation':2,'width_key':'w'},'b':{'height':8,'generation':2,'width_key':'w'}}, 2, 'w', 2, 10, {'a':3}), {'heights': {'a': 8, 'b': 8}, 'offsets': {'a': 0, 'b': 8}, 'total': 16, 'remeasure': [], 'retained': {'a': {'height': 5, 'generation': 2, 'width_key': 'w'}, 'b': {'height': 8, 'generation': 2, 'width_key': 'w'}}})
    check('stale generation', solve([{'id':'a'}], {'a':{'height':4,'generation':1,'width_key':'w'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 1, 'width_key': 'w'}}})
    check('changed widths', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':'old'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'old'}}})
    check('typed width key', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':1}}, 2, '1', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 1}}})
    check('zero and stale id', solve([{'id':'a'}], {'a':{'height':0,'generation':2,'width_key':'w'},'gone':{'height':7,'generation':2,'width_key':'w'}}, 2, 'w', 0, 10, {}), {'heights': {'a': 0}, 'offsets': {'a': 0}, 'total': 0, 'remeasure': [], 'retained': {'a': {'height': 0, 'generation': 2, 'width_key': 'w'}}})
    check('minimum clamp', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1,'generation':2,'width_key':'w'}}, 2, 'w', 3, 10, {'b':2}), {'heights': {'a': 3, 'b': 12}, 'offsets': {'a': 0, 'b': 3}, 'total': 15, 'remeasure': ['b'], 'retained': {'a': {'height': 1, 'generation': 2, 'width_key': 'w'}}})
    check('empty', solve([], {}, 2, 'w', 3, 10, {}), {'heights': {}, 'offsets': {}, 'total': 0, 'remeasure': [], 'retained': {}})

if N == 3:
    check('fresh variable rows', solve([{'id':'a'},{'id':'b'}], {'a':{'height':3+3,'generation':2,'width_key':'w'},'b':{'height':8,'generation':2,'width_key':'w'}}, 2, 'w', 2, 10, {'a':3}), {'heights': {'a': 9, 'b': 8}, 'offsets': {'a': 0, 'b': 9}, 'total': 17, 'remeasure': [], 'retained': {'a': {'height': 6, 'generation': 2, 'width_key': 'w'}, 'b': {'height': 8, 'generation': 2, 'width_key': 'w'}}})
    check('stale generation', solve([{'id':'a'}], {'a':{'height':4,'generation':1,'width_key':'w'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 1, 'width_key': 'w'}}})
    check('changed widths', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':'old'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'old'}}})
    check('typed width key', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':1}}, 2, '1', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 1}}})
    check('zero and stale id', solve([{'id':'a'}], {'a':{'height':0,'generation':2,'width_key':'w'},'gone':{'height':7,'generation':2,'width_key':'w'}}, 2, 'w', 0, 10, {}), {'heights': {'a': 0}, 'offsets': {'a': 0}, 'total': 0, 'remeasure': [], 'retained': {'a': {'height': 0, 'generation': 2, 'width_key': 'w'}}})
    check('minimum clamp', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1,'generation':2,'width_key':'w'}}, 2, 'w', 3, 10, {'b':2}), {'heights': {'a': 3, 'b': 12}, 'offsets': {'a': 0, 'b': 3}, 'total': 15, 'remeasure': ['b'], 'retained': {'a': {'height': 1, 'generation': 2, 'width_key': 'w'}}})
    check('empty', solve([], {}, 2, 'w', 3, 10, {}), {'heights': {}, 'offsets': {}, 'total': 0, 'remeasure': [], 'retained': {}})

if N == 4:
    check('fresh variable rows', solve([{'id':'a'},{'id':'b'}], {'a':{'height':4+3,'generation':2,'width_key':'w'},'b':{'height':8,'generation':2,'width_key':'w'}}, 2, 'w', 2, 10, {'a':3}), {'heights': {'a': 10, 'b': 8}, 'offsets': {'a': 0, 'b': 10}, 'total': 18, 'remeasure': [], 'retained': {'a': {'height': 7, 'generation': 2, 'width_key': 'w'}, 'b': {'height': 8, 'generation': 2, 'width_key': 'w'}}})
    check('stale generation', solve([{'id':'a'}], {'a':{'height':4,'generation':1,'width_key':'w'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 1, 'width_key': 'w'}}})
    check('changed widths', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':'old'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'old'}}})
    check('typed width key', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':1}}, 2, '1', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 1}}})
    check('zero and stale id', solve([{'id':'a'}], {'a':{'height':0,'generation':2,'width_key':'w'},'gone':{'height':7,'generation':2,'width_key':'w'}}, 2, 'w', 0, 10, {}), {'heights': {'a': 0}, 'offsets': {'a': 0}, 'total': 0, 'remeasure': [], 'retained': {'a': {'height': 0, 'generation': 2, 'width_key': 'w'}}})
    check('minimum clamp', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1,'generation':2,'width_key':'w'}}, 2, 'w', 3, 10, {'b':2}), {'heights': {'a': 3, 'b': 12}, 'offsets': {'a': 0, 'b': 3}, 'total': 15, 'remeasure': ['b'], 'retained': {'a': {'height': 1, 'generation': 2, 'width_key': 'w'}}})
    check('empty', solve([], {}, 2, 'w', 3, 10, {}), {'heights': {}, 'offsets': {}, 'total': 0, 'remeasure': [], 'retained': {}})

if N == 5:
    check('fresh variable rows', solve([{'id':'a'},{'id':'b'}], {'a':{'height':5+3,'generation':2,'width_key':'w'},'b':{'height':8,'generation':2,'width_key':'w'}}, 2, 'w', 2, 10, {'a':3}), {'heights': {'a': 11, 'b': 8}, 'offsets': {'a': 0, 'b': 11}, 'total': 19, 'remeasure': [], 'retained': {'a': {'height': 8, 'generation': 2, 'width_key': 'w'}, 'b': {'height': 8, 'generation': 2, 'width_key': 'w'}}})
    check('stale generation', solve([{'id':'a'}], {'a':{'height':4,'generation':1,'width_key':'w'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 1, 'width_key': 'w'}}})
    check('changed widths', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':'old'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'old'}}})
    check('typed width key', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':1}}, 2, '1', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 1}}})
    check('zero and stale id', solve([{'id':'a'}], {'a':{'height':0,'generation':2,'width_key':'w'},'gone':{'height':7,'generation':2,'width_key':'w'}}, 2, 'w', 0, 10, {}), {'heights': {'a': 0}, 'offsets': {'a': 0}, 'total': 0, 'remeasure': [], 'retained': {'a': {'height': 0, 'generation': 2, 'width_key': 'w'}}})
    check('minimum clamp', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1,'generation':2,'width_key':'w'}}, 2, 'w', 3, 10, {'b':2}), {'heights': {'a': 3, 'b': 12}, 'offsets': {'a': 0, 'b': 3}, 'total': 15, 'remeasure': ['b'], 'retained': {'a': {'height': 1, 'generation': 2, 'width_key': 'w'}}})
    check('empty', solve([], {}, 2, 'w', 3, 10, {}), {'heights': {}, 'offsets': {}, 'total': 0, 'remeasure': [], 'retained': {}})

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)

prompt:
The table prefix row offset result violates the stipulated table row height measurement cache contract.

Measured row heights are keyed by stable row ID plus row-data generation and column-width fingerprint. Invalid measurements use an estimate, minimum applies before detail height, positions are ordered prefixes, and stale row measurements are pruned.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(rows, measurements, generation, width_key, minimum, estimate, details):
    heights={}
    for r in rows:
        k=r['id']; m=measurements.get(k)
        valid=m is not None and m['generation']==generation and m['width_key']==width_key
        h=m['height'] if valid else estimate
        heights[k]=max(minimum,h)+details.get(k,0)
    ids=[r['id'] for r in rows]
    offsets={k:sum(heights[x] for x in ids[:i]) for i,k in enumerate(ids)}
    return {'heights':heights,'offsets':offsets,'total':max(heights.values(),default=0),'remeasure':[r['id'] for r in rows if r['id'] not in measurements or measurements[r['id']]['generation']!=generation or measurements[r['id']]['width_key']!=width_key],'retained':{k:v for k,v in measurements.items() if k in ids}}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('fresh variable rows', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1+3,'generation':2,'width_key':'w'},'b':{'height':8,'generation':2,'width_key':'w'}}, 2, 'w', 2, 10, {'a':3}), {'heights': {'a': 7, 'b': 8}, 'offsets': {'a': 0, 'b': 7}, 'total': 15, 'remeasure': [], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'w'}, 'b': {'height': 8, 'generation': 2, 'width_key': 'w'}}})
    check('stale generation', solve([{'id':'a'}], {'a':{'height':4,'generation':1,'width_key':'w'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 1, 'width_key': 'w'}}})
    check('changed widths', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':'old'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'old'}}})
    check('typed width key', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':1}}, 2, '1', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 1}}})
    check('zero and stale id', solve([{'id':'a'}], {'a':{'height':0,'generation':2,'width_key':'w'},'gone':{'height':7,'generation':2,'width_key':'w'}}, 2, 'w', 0, 10, {}), {'heights': {'a': 0}, 'offsets': {'a': 0}, 'total': 0, 'remeasure': [], 'retained': {'a': {'height': 0, 'generation': 2, 'width_key': 'w'}}})
    check('minimum clamp', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1,'generation':2,'width_key':'w'}}, 2, 'w', 3, 10, {'b':2}), {'heights': {'a': 3, 'b': 12}, 'offsets': {'a': 0, 'b': 3}, 'total': 15, 'remeasure': ['b'], 'retained': {'a': {'height': 1, 'generation': 2, 'width_key': 'w'}}})
    check('empty', solve([], {}, 2, 'w', 3, 10, {}), {'heights': {}, 'offsets': {}, 'total': 0, 'remeasure': [], 'retained': {}})

if N == 2:
    check('fresh variable rows', solve([{'id':'a'},{'id':'b'}], {'a':{'height':2+3,'generation':2,'width_key':'w'},'b':{'height':8,'generation':2,'width_key':'w'}}, 2, 'w', 2, 10, {'a':3}), {'heights': {'a': 8, 'b': 8}, 'offsets': {'a': 0, 'b': 8}, 'total': 16, 'remeasure': [], 'retained': {'a': {'height': 5, 'generation': 2, 'width_key': 'w'}, 'b': {'height': 8, 'generation': 2, 'width_key': 'w'}}})
    check('stale generation', solve([{'id':'a'}], {'a':{'height':4,'generation':1,'width_key':'w'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 1, 'width_key': 'w'}}})
    check('changed widths', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':'old'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'old'}}})
    check('typed width key', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':1}}, 2, '1', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 1}}})
    check('zero and stale id', solve([{'id':'a'}], {'a':{'height':0,'generation':2,'width_key':'w'},'gone':{'height':7,'generation':2,'width_key':'w'}}, 2, 'w', 0, 10, {}), {'heights': {'a': 0}, 'offsets': {'a': 0}, 'total': 0, 'remeasure': [], 'retained': {'a': {'height': 0, 'generation': 2, 'width_key': 'w'}}})
    check('minimum clamp', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1,'generation':2,'width_key':'w'}}, 2, 'w', 3, 10, {'b':2}), {'heights': {'a': 3, 'b': 12}, 'offsets': {'a': 0, 'b': 3}, 'total': 15, 'remeasure': ['b'], 'retained': {'a': {'height': 1, 'generation': 2, 'width_key': 'w'}}})
    check('empty', solve([], {}, 2, 'w', 3, 10, {}), {'heights': {}, 'offsets': {}, 'total': 0, 'remeasure': [], 'retained': {}})

if N == 3:
    check('fresh variable rows', solve([{'id':'a'},{'id':'b'}], {'a':{'height':3+3,'generation':2,'width_key':'w'},'b':{'height':8,'generation':2,'width_key':'w'}}, 2, 'w', 2, 10, {'a':3}), {'heights': {'a': 9, 'b': 8}, 'offsets': {'a': 0, 'b': 9}, 'total': 17, 'remeasure': [], 'retained': {'a': {'height': 6, 'generation': 2, 'width_key': 'w'}, 'b': {'height': 8, 'generation': 2, 'width_key': 'w'}}})
    check('stale generation', solve([{'id':'a'}], {'a':{'height':4,'generation':1,'width_key':'w'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 1, 'width_key': 'w'}}})
    check('changed widths', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':'old'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'old'}}})
    check('typed width key', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':1}}, 2, '1', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 1}}})
    check('zero and stale id', solve([{'id':'a'}], {'a':{'height':0,'generation':2,'width_key':'w'},'gone':{'height':7,'generation':2,'width_key':'w'}}, 2, 'w', 0, 10, {}), {'heights': {'a': 0}, 'offsets': {'a': 0}, 'total': 0, 'remeasure': [], 'retained': {'a': {'height': 0, 'generation': 2, 'width_key': 'w'}}})
    check('minimum clamp', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1,'generation':2,'width_key':'w'}}, 2, 'w', 3, 10, {'b':2}), {'heights': {'a': 3, 'b': 12}, 'offsets': {'a': 0, 'b': 3}, 'total': 15, 'remeasure': ['b'], 'retained': {'a': {'height': 1, 'generation': 2, 'width_key': 'w'}}})
    check('empty', solve([], {}, 2, 'w', 3, 10, {}), {'heights': {}, 'offsets': {}, 'total': 0, 'remeasure': [], 'retained': {}})

if N == 4:
    check('fresh variable rows', solve([{'id':'a'},{'id':'b'}], {'a':{'height':4+3,'generation':2,'width_key':'w'},'b':{'height':8,'generation':2,'width_key':'w'}}, 2, 'w', 2, 10, {'a':3}), {'heights': {'a': 10, 'b': 8}, 'offsets': {'a': 0, 'b': 10}, 'total': 18, 'remeasure': [], 'retained': {'a': {'height': 7, 'generation': 2, 'width_key': 'w'}, 'b': {'height': 8, 'generation': 2, 'width_key': 'w'}}})
    check('stale generation', solve([{'id':'a'}], {'a':{'height':4,'generation':1,'width_key':'w'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 1, 'width_key': 'w'}}})
    check('changed widths', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':'old'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'old'}}})
    check('typed width key', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':1}}, 2, '1', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 1}}})
    check('zero and stale id', solve([{'id':'a'}], {'a':{'height':0,'generation':2,'width_key':'w'},'gone':{'height':7,'generation':2,'width_key':'w'}}, 2, 'w', 0, 10, {}), {'heights': {'a': 0}, 'offsets': {'a': 0}, 'total': 0, 'remeasure': [], 'retained': {'a': {'height': 0, 'generation': 2, 'width_key': 'w'}}})
    check('minimum clamp', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1,'generation':2,'width_key':'w'}}, 2, 'w', 3, 10, {'b':2}), {'heights': {'a': 3, 'b': 12}, 'offsets': {'a': 0, 'b': 3}, 'total': 15, 'remeasure': ['b'], 'retained': {'a': {'height': 1, 'generation': 2, 'width_key': 'w'}}})
    check('empty', solve([], {}, 2, 'w', 3, 10, {}), {'heights': {}, 'offsets': {}, 'total': 0, 'remeasure': [], 'retained': {}})

if N == 5:
    check('fresh variable rows', solve([{'id':'a'},{'id':'b'}], {'a':{'height':5+3,'generation':2,'width_key':'w'},'b':{'height':8,'generation':2,'width_key':'w'}}, 2, 'w', 2, 10, {'a':3}), {'heights': {'a': 11, 'b': 8}, 'offsets': {'a': 0, 'b': 11}, 'total': 19, 'remeasure': [], 'retained': {'a': {'height': 8, 'generation': 2, 'width_key': 'w'}, 'b': {'height': 8, 'generation': 2, 'width_key': 'w'}}})
    check('stale generation', solve([{'id':'a'}], {'a':{'height':4,'generation':1,'width_key':'w'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 1, 'width_key': 'w'}}})
    check('changed widths', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':'old'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'old'}}})
    check('typed width key', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':1}}, 2, '1', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 1}}})
    check('zero and stale id', solve([{'id':'a'}], {'a':{'height':0,'generation':2,'width_key':'w'},'gone':{'height':7,'generation':2,'width_key':'w'}}, 2, 'w', 0, 10, {}), {'heights': {'a': 0}, 'offsets': {'a': 0}, 'total': 0, 'remeasure': [], 'retained': {'a': {'height': 0, 'generation': 2, 'width_key': 'w'}}})
    check('minimum clamp', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1,'generation':2,'width_key':'w'}}, 2, 'w', 3, 10, {'b':2}), {'heights': {'a': 3, 'b': 12}, 'offsets': {'a': 0, 'b': 3}, 'total': 15, 'remeasure': ['b'], 'retained': {'a': {'height': 1, 'generation': 2, 'width_key': 'w'}}})
    check('empty', solve([], {}, 2, 'w', 3, 10, {}), {'heights': {}, 'offsets': {}, 'total': 0, 'remeasure': [], 'retained': {}})

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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(rows, measurements, generation, width_key, minimum, estimate, details):
    heights={}
    for r in rows:
        k=r['id']; m=measurements.get(k)
        valid=m is not None and m['generation']==generation and m['width_key']==width_key
        h=m['height'] if valid else estimate
        heights[k]=max(minimum,h)+details.get(k,0)
    ids=[r['id'] for r in rows]
    offsets={k:sum(heights[x] for x in ids[:i]) for i,k in enumerate(ids)}
    return {'heights':heights,'offsets':offsets,'total':estimate*len(rows),'remeasure':[r['id'] for r in rows if r['id'] not in measurements or measurements[r['id']]['generation']!=generation or measurements[r['id']]['width_key']!=width_key],'retained':{k:v for k,v in measurements.items() if k in ids}}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('fresh variable rows', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1+3,'generation':2,'width_key':'w'},'b':{'height':8,'generation':2,'width_key':'w'}}, 2, 'w', 2, 10, {'a':3}), {'heights': {'a': 7, 'b': 8}, 'offsets': {'a': 0, 'b': 7}, 'total': 15, 'remeasure': [], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'w'}, 'b': {'height': 8, 'generation': 2, 'width_key': 'w'}}})
    check('stale generation', solve([{'id':'a'}], {'a':{'height':4,'generation':1,'width_key':'w'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 1, 'width_key': 'w'}}})
    check('changed widths', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':'old'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'old'}}})
    check('typed width key', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':1}}, 2, '1', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 1}}})
    check('zero and stale id', solve([{'id':'a'}], {'a':{'height':0,'generation':2,'width_key':'w'},'gone':{'height':7,'generation':2,'width_key':'w'}}, 2, 'w', 0, 10, {}), {'heights': {'a': 0}, 'offsets': {'a': 0}, 'total': 0, 'remeasure': [], 'retained': {'a': {'height': 0, 'generation': 2, 'width_key': 'w'}}})
    check('minimum clamp', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1,'generation':2,'width_key':'w'}}, 2, 'w', 3, 10, {'b':2}), {'heights': {'a': 3, 'b': 12}, 'offsets': {'a': 0, 'b': 3}, 'total': 15, 'remeasure': ['b'], 'retained': {'a': {'height': 1, 'generation': 2, 'width_key': 'w'}}})
    check('empty', solve([], {}, 2, 'w', 3, 10, {}), {'heights': {}, 'offsets': {}, 'total': 0, 'remeasure': [], 'retained': {}})

if N == 2:
    check('fresh variable rows', solve([{'id':'a'},{'id':'b'}], {'a':{'height':2+3,'generation':2,'width_key':'w'},'b':{'height':8,'generation':2,'width_key':'w'}}, 2, 'w', 2, 10, {'a':3}), {'heights': {'a': 8, 'b': 8}, 'offsets': {'a': 0, 'b': 8}, 'total': 16, 'remeasure': [], 'retained': {'a': {'height': 5, 'generation': 2, 'width_key': 'w'}, 'b': {'height': 8, 'generation': 2, 'width_key': 'w'}}})
    check('stale generation', solve([{'id':'a'}], {'a':{'height':4,'generation':1,'width_key':'w'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 1, 'width_key': 'w'}}})
    check('changed widths', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':'old'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'old'}}})
    check('typed width key', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':1}}, 2, '1', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 1}}})
    check('zero and stale id', solve([{'id':'a'}], {'a':{'height':0,'generation':2,'width_key':'w'},'gone':{'height':7,'generation':2,'width_key':'w'}}, 2, 'w', 0, 10, {}), {'heights': {'a': 0}, 'offsets': {'a': 0}, 'total': 0, 'remeasure': [], 'retained': {'a': {'height': 0, 'generation': 2, 'width_key': 'w'}}})
    check('minimum clamp', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1,'generation':2,'width_key':'w'}}, 2, 'w', 3, 10, {'b':2}), {'heights': {'a': 3, 'b': 12}, 'offsets': {'a': 0, 'b': 3}, 'total': 15, 'remeasure': ['b'], 'retained': {'a': {'height': 1, 'generation': 2, 'width_key': 'w'}}})
    check('empty', solve([], {}, 2, 'w', 3, 10, {}), {'heights': {}, 'offsets': {}, 'total': 0, 'remeasure': [], 'retained': {}})

if N == 3:
    check('fresh variable rows', solve([{'id':'a'},{'id':'b'}], {'a':{'height':3+3,'generation':2,'width_key':'w'},'b':{'height':8,'generation':2,'width_key':'w'}}, 2, 'w', 2, 10, {'a':3}), {'heights': {'a': 9, 'b': 8}, 'offsets': {'a': 0, 'b': 9}, 'total': 17, 'remeasure': [], 'retained': {'a': {'height': 6, 'generation': 2, 'width_key': 'w'}, 'b': {'height': 8, 'generation': 2, 'width_key': 'w'}}})
    check('stale generation', solve([{'id':'a'}], {'a':{'height':4,'generation':1,'width_key':'w'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 1, 'width_key': 'w'}}})
    check('changed widths', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':'old'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'old'}}})
    check('typed width key', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':1}}, 2, '1', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 1}}})
    check('zero and stale id', solve([{'id':'a'}], {'a':{'height':0,'generation':2,'width_key':'w'},'gone':{'height':7,'generation':2,'width_key':'w'}}, 2, 'w', 0, 10, {}), {'heights': {'a': 0}, 'offsets': {'a': 0}, 'total': 0, 'remeasure': [], 'retained': {'a': {'height': 0, 'generation': 2, 'width_key': 'w'}}})
    check('minimum clamp', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1,'generation':2,'width_key':'w'}}, 2, 'w', 3, 10, {'b':2}), {'heights': {'a': 3, 'b': 12}, 'offsets': {'a': 0, 'b': 3}, 'total': 15, 'remeasure': ['b'], 'retained': {'a': {'height': 1, 'generation': 2, 'width_key': 'w'}}})
    check('empty', solve([], {}, 2, 'w', 3, 10, {}), {'heights': {}, 'offsets': {}, 'total': 0, 'remeasure': [], 'retained': {}})

if N == 4:
    check('fresh variable rows', solve([{'id':'a'},{'id':'b'}], {'a':{'height':4+3,'generation':2,'width_key':'w'},'b':{'height':8,'generation':2,'width_key':'w'}}, 2, 'w', 2, 10, {'a':3}), {'heights': {'a': 10, 'b': 8}, 'offsets': {'a': 0, 'b': 10}, 'total': 18, 'remeasure': [], 'retained': {'a': {'height': 7, 'generation': 2, 'width_key': 'w'}, 'b': {'height': 8, 'generation': 2, 'width_key': 'w'}}})
    check('stale generation', solve([{'id':'a'}], {'a':{'height':4,'generation':1,'width_key':'w'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 1, 'width_key': 'w'}}})
    check('changed widths', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':'old'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'old'}}})
    check('typed width key', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':1}}, 2, '1', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 1}}})
    check('zero and stale id', solve([{'id':'a'}], {'a':{'height':0,'generation':2,'width_key':'w'},'gone':{'height':7,'generation':2,'width_key':'w'}}, 2, 'w', 0, 10, {}), {'heights': {'a': 0}, 'offsets': {'a': 0}, 'total': 0, 'remeasure': [], 'retained': {'a': {'height': 0, 'generation': 2, 'width_key': 'w'}}})
    check('minimum clamp', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1,'generation':2,'width_key':'w'}}, 2, 'w', 3, 10, {'b':2}), {'heights': {'a': 3, 'b': 12}, 'offsets': {'a': 0, 'b': 3}, 'total': 15, 'remeasure': ['b'], 'retained': {'a': {'height': 1, 'generation': 2, 'width_key': 'w'}}})
    check('empty', solve([], {}, 2, 'w', 3, 10, {}), {'heights': {}, 'offsets': {}, 'total': 0, 'remeasure': [], 'retained': {}})

if N == 5:
    check('fresh variable rows', solve([{'id':'a'},{'id':'b'}], {'a':{'height':5+3,'generation':2,'width_key':'w'},'b':{'height':8,'generation':2,'width_key':'w'}}, 2, 'w', 2, 10, {'a':3}), {'heights': {'a': 11, 'b': 8}, 'offsets': {'a': 0, 'b': 11}, 'total': 19, 'remeasure': [], 'retained': {'a': {'height': 8, 'generation': 2, 'width_key': 'w'}, 'b': {'height': 8, 'generation': 2, 'width_key': 'w'}}})
    check('stale generation', solve([{'id':'a'}], {'a':{'height':4,'generation':1,'width_key':'w'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 1, 'width_key': 'w'}}})
    check('changed widths', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':'old'}}, 2, 'w', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 'old'}}})
    check('typed width key', solve([{'id':'a'}], {'a':{'height':4,'generation':2,'width_key':1}}, 2, '1', 2, 10, {}), {'heights': {'a': 10}, 'offsets': {'a': 0}, 'total': 10, 'remeasure': ['a'], 'retained': {'a': {'height': 4, 'generation': 2, 'width_key': 1}}})
    check('zero and stale id', solve([{'id':'a'}], {'a':{'height':0,'generation':2,'width_key':'w'},'gone':{'height':7,'generation':2,'width_key':'w'}}, 2, 'w', 0, 10, {}), {'heights': {'a': 0}, 'offsets': {'a': 0}, 'total': 0, 'remeasure': [], 'retained': {'a': {'height': 0, 'generation': 2, 'width_key': 'w'}}})
    check('minimum clamp', solve([{'id':'a'},{'id':'b'}], {'a':{'height':1,'generation':2,'width_key':'w'}}, 2, 'w', 3, 10, {'b':2}), {'heights': {'a': 3, 'b': 12}, 'offsets': {'a': 0, 'b': 3}, 'total': 15, 'remeasure': ['b'], 'retained': {'a': {'height': 1, 'generation': 2, 'width_key': 'w'}}})
    check('empty', solve([], {}, 2, 'w', 3, 10, {}), {'heights': {}, 'offsets': {}, 'total': 0, 'remeasure': [], 'retained': {}})

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)

prompt:
The table table total height result violates the stipulated table row height measurement cache contract.

Measured row heights are keyed by stable row ID plus row-data generation and column-width fingerprint. Invalid measurements use an estimate, minimum applies before detail height, positions are ordered prefixes, and stale row measurements are pruned.

split: open-access