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

N = 1
observations = []
def solve(before, after, anchor, inset, old_scroll, viewport, old_columns, new_columns, column_anchor, column_inset):
    old_ids=[x['id'] for x in before]; new_ids=[x['id'] for x in after]
    if anchor in new_ids: chosen=anchor
    else:
        following=old_ids[old_ids.index(anchor)+1:] if anchor in old_ids else []
        chosen=next((x for x in following if x in new_ids),new_ids[-1] if new_ids else None)
    idx=new_ids.index(chosen) if chosen is not None else 0
    prefix=sum(x['height'] for x in after[:idx])
    local=min(max(inset,0),max(0,after[idx]['height']-1)) if chosen==anchor and after else 0
    y=min(max(prefix+local,0),max(0,sum(x['height'] for x in after)-viewport))
    cols=[x['id'] for x in new_columns]
    ci=cols.index(column_anchor) if column_anchor in cols else 0
    x=sum(c['width'] for c in new_columns[:ci+1])+(max(0,min(column_inset,new_columns[ci]['width']-1)) if column_anchor in cols else 0)
    return {'row':chosen,'scroll_y':y,'column':cols[ci] if cols else None,'scroll_x':x}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('insert before anchored row', solve([{'id':'a','height':5},{'id':'b','height':8}], [{'id':'x','height':1+2},{'id':'a','height':5},{'id':'b','height':8}], 'b', 2, 7, 4, [{'id':'a','width':5},{'id':'b','width':8}], [{'id':'x','width':3},{'id':'a','width':5},{'id':'b','width':8}], 'b', 2), {'row': 'b', 'scroll_y': 10, 'column': 'b', 'scroll_x': 10})
    check('removed anchor successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'c','height':9}], 'b', 3, 8, 4, [], [], 'gone', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('removed last anchor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8}], 'c', 3, 16, 4, [], [], 'gone', 0), {'row': 'b', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('shrunk anchored cell', solve([{'id':'a','height':20}], [{'id':'a','height':5}], 'a', 18, 18, 2, [{'id':'a','width':20}], [{'id':'a','width':5}], 'a', 18), {'row': 'a', 'scroll_y': 3, 'column': 'a', 'scroll_x': 4})
    check('bottom clamp', solve([{'id':'a','height':5},{'id':'b','height':10}], [{'id':'a','height':5},{'id':'b','height':4}], 'b', 3, 8, 7, [], [], '', 0), {'row': 'b', 'scroll_y': 2, 'column': None, 'scroll_x': 0})
    check('surviving middle', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'b', 'scroll_y': 7, 'column': None, 'scroll_x': 0})
    check('first successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9},{'id':'d','height':10}], [{'id':'a','height':5},{'id':'c','height':9},{'id':'d','height':10}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('interior shrink', solve([{'id':'a','height':20},{'id':'b','height':30}], [{'id':'a','height':5},{'id':'b','height':30}], 'a', 18, 18, 2, [], [], '', 0), {'row': 'a', 'scroll_y': 4, 'column': None, 'scroll_x': 0})
    check('empty table', solve([{'id':'a','height':5}], [], 'a', 2, 2, 4, [], [], '', 0), {'row': None, 'scroll_y': 0, 'column': None, 'scroll_x': 0})

if N == 2:
    check('insert before anchored row', solve([{'id':'a','height':5},{'id':'b','height':8}], [{'id':'x','height':2+2},{'id':'a','height':5},{'id':'b','height':8}], 'b', 2, 7, 4, [{'id':'a','width':5},{'id':'b','width':8}], [{'id':'x','width':3},{'id':'a','width':5},{'id':'b','width':8}], 'b', 2), {'row': 'b', 'scroll_y': 11, 'column': 'b', 'scroll_x': 10})
    check('removed anchor successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'c','height':9}], 'b', 3, 8, 4, [], [], 'gone', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('removed last anchor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8}], 'c', 3, 16, 4, [], [], 'gone', 0), {'row': 'b', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('shrunk anchored cell', solve([{'id':'a','height':20}], [{'id':'a','height':5}], 'a', 18, 18, 2, [{'id':'a','width':20}], [{'id':'a','width':5}], 'a', 18), {'row': 'a', 'scroll_y': 3, 'column': 'a', 'scroll_x': 4})
    check('bottom clamp', solve([{'id':'a','height':5},{'id':'b','height':10}], [{'id':'a','height':5},{'id':'b','height':4}], 'b', 3, 8, 7, [], [], '', 0), {'row': 'b', 'scroll_y': 2, 'column': None, 'scroll_x': 0})
    check('surviving middle', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'b', 'scroll_y': 7, 'column': None, 'scroll_x': 0})
    check('first successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9},{'id':'d','height':10}], [{'id':'a','height':5},{'id':'c','height':9},{'id':'d','height':10}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('interior shrink', solve([{'id':'a','height':20},{'id':'b','height':30}], [{'id':'a','height':5},{'id':'b','height':30}], 'a', 18, 18, 2, [], [], '', 0), {'row': 'a', 'scroll_y': 4, 'column': None, 'scroll_x': 0})
    check('empty table', solve([{'id':'a','height':5}], [], 'a', 2, 2, 4, [], [], '', 0), {'row': None, 'scroll_y': 0, 'column': None, 'scroll_x': 0})

if N == 3:
    check('insert before anchored row', solve([{'id':'a','height':5},{'id':'b','height':8}], [{'id':'x','height':3+2},{'id':'a','height':5},{'id':'b','height':8}], 'b', 2, 7, 4, [{'id':'a','width':5},{'id':'b','width':8}], [{'id':'x','width':3},{'id':'a','width':5},{'id':'b','width':8}], 'b', 2), {'row': 'b', 'scroll_y': 12, 'column': 'b', 'scroll_x': 10})
    check('removed anchor successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'c','height':9}], 'b', 3, 8, 4, [], [], 'gone', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('removed last anchor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8}], 'c', 3, 16, 4, [], [], 'gone', 0), {'row': 'b', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('shrunk anchored cell', solve([{'id':'a','height':20}], [{'id':'a','height':5}], 'a', 18, 18, 2, [{'id':'a','width':20}], [{'id':'a','width':5}], 'a', 18), {'row': 'a', 'scroll_y': 3, 'column': 'a', 'scroll_x': 4})
    check('bottom clamp', solve([{'id':'a','height':5},{'id':'b','height':10}], [{'id':'a','height':5},{'id':'b','height':4}], 'b', 3, 8, 7, [], [], '', 0), {'row': 'b', 'scroll_y': 2, 'column': None, 'scroll_x': 0})
    check('surviving middle', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'b', 'scroll_y': 7, 'column': None, 'scroll_x': 0})
    check('first successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9},{'id':'d','height':10}], [{'id':'a','height':5},{'id':'c','height':9},{'id':'d','height':10}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('interior shrink', solve([{'id':'a','height':20},{'id':'b','height':30}], [{'id':'a','height':5},{'id':'b','height':30}], 'a', 18, 18, 2, [], [], '', 0), {'row': 'a', 'scroll_y': 4, 'column': None, 'scroll_x': 0})
    check('empty table', solve([{'id':'a','height':5}], [], 'a', 2, 2, 4, [], [], '', 0), {'row': None, 'scroll_y': 0, 'column': None, 'scroll_x': 0})

if N == 4:
    check('insert before anchored row', solve([{'id':'a','height':5},{'id':'b','height':8}], [{'id':'x','height':4+2},{'id':'a','height':5},{'id':'b','height':8}], 'b', 2, 7, 4, [{'id':'a','width':5},{'id':'b','width':8}], [{'id':'x','width':3},{'id':'a','width':5},{'id':'b','width':8}], 'b', 2), {'row': 'b', 'scroll_y': 13, 'column': 'b', 'scroll_x': 10})
    check('removed anchor successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'c','height':9}], 'b', 3, 8, 4, [], [], 'gone', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('removed last anchor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8}], 'c', 3, 16, 4, [], [], 'gone', 0), {'row': 'b', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('shrunk anchored cell', solve([{'id':'a','height':20}], [{'id':'a','height':5}], 'a', 18, 18, 2, [{'id':'a','width':20}], [{'id':'a','width':5}], 'a', 18), {'row': 'a', 'scroll_y': 3, 'column': 'a', 'scroll_x': 4})
    check('bottom clamp', solve([{'id':'a','height':5},{'id':'b','height':10}], [{'id':'a','height':5},{'id':'b','height':4}], 'b', 3, 8, 7, [], [], '', 0), {'row': 'b', 'scroll_y': 2, 'column': None, 'scroll_x': 0})
    check('surviving middle', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'b', 'scroll_y': 7, 'column': None, 'scroll_x': 0})
    check('first successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9},{'id':'d','height':10}], [{'id':'a','height':5},{'id':'c','height':9},{'id':'d','height':10}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('interior shrink', solve([{'id':'a','height':20},{'id':'b','height':30}], [{'id':'a','height':5},{'id':'b','height':30}], 'a', 18, 18, 2, [], [], '', 0), {'row': 'a', 'scroll_y': 4, 'column': None, 'scroll_x': 0})
    check('empty table', solve([{'id':'a','height':5}], [], 'a', 2, 2, 4, [], [], '', 0), {'row': None, 'scroll_y': 0, 'column': None, 'scroll_x': 0})

if N == 5:
    check('insert before anchored row', solve([{'id':'a','height':5},{'id':'b','height':8}], [{'id':'x','height':5+2},{'id':'a','height':5},{'id':'b','height':8}], 'b', 2, 7, 4, [{'id':'a','width':5},{'id':'b','width':8}], [{'id':'x','width':3},{'id':'a','width':5},{'id':'b','width':8}], 'b', 2), {'row': 'b', 'scroll_y': 14, 'column': 'b', 'scroll_x': 10})
    check('removed anchor successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'c','height':9}], 'b', 3, 8, 4, [], [], 'gone', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('removed last anchor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8}], 'c', 3, 16, 4, [], [], 'gone', 0), {'row': 'b', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('shrunk anchored cell', solve([{'id':'a','height':20}], [{'id':'a','height':5}], 'a', 18, 18, 2, [{'id':'a','width':20}], [{'id':'a','width':5}], 'a', 18), {'row': 'a', 'scroll_y': 3, 'column': 'a', 'scroll_x': 4})
    check('bottom clamp', solve([{'id':'a','height':5},{'id':'b','height':10}], [{'id':'a','height':5},{'id':'b','height':4}], 'b', 3, 8, 7, [], [], '', 0), {'row': 'b', 'scroll_y': 2, 'column': None, 'scroll_x': 0})
    check('surviving middle', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'b', 'scroll_y': 7, 'column': None, 'scroll_x': 0})
    check('first successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9},{'id':'d','height':10}], [{'id':'a','height':5},{'id':'c','height':9},{'id':'d','height':10}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('interior shrink', solve([{'id':'a','height':20},{'id':'b','height':30}], [{'id':'a','height':5},{'id':'b','height':30}], 'a', 18, 18, 2, [], [], '', 0), {'row': 'a', 'scroll_y': 4, 'column': None, 'scroll_x': 0})
    check('empty table', solve([{'id':'a','height':5}], [], 'a', 2, 2, 4, [], [], '', 0), {'row': None, 'scroll_y': 0, 'column': None, 'scroll_x': 0})

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(before, after, anchor, inset, old_scroll, viewport, old_columns, new_columns, column_anchor, column_inset):
    old_ids=[x['id'] for x in before]; new_ids=[x['id'] for x in after]
    if anchor in new_ids: chosen=anchor
    else:
        following=old_ids[old_ids.index(anchor)+1:] if anchor in old_ids else []
        chosen=next((x for x in following if x in new_ids),new_ids[-1] if new_ids else None)
    idx=new_ids.index(chosen) if chosen is not None else 0
    prefix=sum(x['height'] for x in after[:idx])
    local=min(max(inset,0),max(0,after[idx]['height']-1)) if chosen==anchor and after else 0
    y=min(max(prefix+local,0),max(0,sum(x['height'] for x in after)-viewport))
    cols=[x['id'] for x in new_columns]
    ci=cols.index(column_anchor) if column_anchor in cols else 0
    x=sum(c['width'] for c in old_columns[:ci])+(max(0,min(column_inset,new_columns[ci]['width']-1)) if column_anchor in cols else 0)
    return {'row':chosen,'scroll_y':y,'column':cols[ci] if cols else None,'scroll_x':x}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('insert before anchored row', solve([{'id':'a','height':5},{'id':'b','height':8}], [{'id':'x','height':1+2},{'id':'a','height':5},{'id':'b','height':8}], 'b', 2, 7, 4, [{'id':'a','width':5},{'id':'b','width':8}], [{'id':'x','width':3},{'id':'a','width':5},{'id':'b','width':8}], 'b', 2), {'row': 'b', 'scroll_y': 10, 'column': 'b', 'scroll_x': 10})
    check('removed anchor successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'c','height':9}], 'b', 3, 8, 4, [], [], 'gone', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('removed last anchor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8}], 'c', 3, 16, 4, [], [], 'gone', 0), {'row': 'b', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('shrunk anchored cell', solve([{'id':'a','height':20}], [{'id':'a','height':5}], 'a', 18, 18, 2, [{'id':'a','width':20}], [{'id':'a','width':5}], 'a', 18), {'row': 'a', 'scroll_y': 3, 'column': 'a', 'scroll_x': 4})
    check('bottom clamp', solve([{'id':'a','height':5},{'id':'b','height':10}], [{'id':'a','height':5},{'id':'b','height':4}], 'b', 3, 8, 7, [], [], '', 0), {'row': 'b', 'scroll_y': 2, 'column': None, 'scroll_x': 0})
    check('surviving middle', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'b', 'scroll_y': 7, 'column': None, 'scroll_x': 0})
    check('first successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9},{'id':'d','height':10}], [{'id':'a','height':5},{'id':'c','height':9},{'id':'d','height':10}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('interior shrink', solve([{'id':'a','height':20},{'id':'b','height':30}], [{'id':'a','height':5},{'id':'b','height':30}], 'a', 18, 18, 2, [], [], '', 0), {'row': 'a', 'scroll_y': 4, 'column': None, 'scroll_x': 0})
    check('empty table', solve([{'id':'a','height':5}], [], 'a', 2, 2, 4, [], [], '', 0), {'row': None, 'scroll_y': 0, 'column': None, 'scroll_x': 0})

if N == 2:
    check('insert before anchored row', solve([{'id':'a','height':5},{'id':'b','height':8}], [{'id':'x','height':2+2},{'id':'a','height':5},{'id':'b','height':8}], 'b', 2, 7, 4, [{'id':'a','width':5},{'id':'b','width':8}], [{'id':'x','width':3},{'id':'a','width':5},{'id':'b','width':8}], 'b', 2), {'row': 'b', 'scroll_y': 11, 'column': 'b', 'scroll_x': 10})
    check('removed anchor successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'c','height':9}], 'b', 3, 8, 4, [], [], 'gone', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('removed last anchor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8}], 'c', 3, 16, 4, [], [], 'gone', 0), {'row': 'b', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('shrunk anchored cell', solve([{'id':'a','height':20}], [{'id':'a','height':5}], 'a', 18, 18, 2, [{'id':'a','width':20}], [{'id':'a','width':5}], 'a', 18), {'row': 'a', 'scroll_y': 3, 'column': 'a', 'scroll_x': 4})
    check('bottom clamp', solve([{'id':'a','height':5},{'id':'b','height':10}], [{'id':'a','height':5},{'id':'b','height':4}], 'b', 3, 8, 7, [], [], '', 0), {'row': 'b', 'scroll_y': 2, 'column': None, 'scroll_x': 0})
    check('surviving middle', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'b', 'scroll_y': 7, 'column': None, 'scroll_x': 0})
    check('first successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9},{'id':'d','height':10}], [{'id':'a','height':5},{'id':'c','height':9},{'id':'d','height':10}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('interior shrink', solve([{'id':'a','height':20},{'id':'b','height':30}], [{'id':'a','height':5},{'id':'b','height':30}], 'a', 18, 18, 2, [], [], '', 0), {'row': 'a', 'scroll_y': 4, 'column': None, 'scroll_x': 0})
    check('empty table', solve([{'id':'a','height':5}], [], 'a', 2, 2, 4, [], [], '', 0), {'row': None, 'scroll_y': 0, 'column': None, 'scroll_x': 0})

if N == 3:
    check('insert before anchored row', solve([{'id':'a','height':5},{'id':'b','height':8}], [{'id':'x','height':3+2},{'id':'a','height':5},{'id':'b','height':8}], 'b', 2, 7, 4, [{'id':'a','width':5},{'id':'b','width':8}], [{'id':'x','width':3},{'id':'a','width':5},{'id':'b','width':8}], 'b', 2), {'row': 'b', 'scroll_y': 12, 'column': 'b', 'scroll_x': 10})
    check('removed anchor successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'c','height':9}], 'b', 3, 8, 4, [], [], 'gone', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('removed last anchor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8}], 'c', 3, 16, 4, [], [], 'gone', 0), {'row': 'b', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('shrunk anchored cell', solve([{'id':'a','height':20}], [{'id':'a','height':5}], 'a', 18, 18, 2, [{'id':'a','width':20}], [{'id':'a','width':5}], 'a', 18), {'row': 'a', 'scroll_y': 3, 'column': 'a', 'scroll_x': 4})
    check('bottom clamp', solve([{'id':'a','height':5},{'id':'b','height':10}], [{'id':'a','height':5},{'id':'b','height':4}], 'b', 3, 8, 7, [], [], '', 0), {'row': 'b', 'scroll_y': 2, 'column': None, 'scroll_x': 0})
    check('surviving middle', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'b', 'scroll_y': 7, 'column': None, 'scroll_x': 0})
    check('first successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9},{'id':'d','height':10}], [{'id':'a','height':5},{'id':'c','height':9},{'id':'d','height':10}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('interior shrink', solve([{'id':'a','height':20},{'id':'b','height':30}], [{'id':'a','height':5},{'id':'b','height':30}], 'a', 18, 18, 2, [], [], '', 0), {'row': 'a', 'scroll_y': 4, 'column': None, 'scroll_x': 0})
    check('empty table', solve([{'id':'a','height':5}], [], 'a', 2, 2, 4, [], [], '', 0), {'row': None, 'scroll_y': 0, 'column': None, 'scroll_x': 0})

if N == 4:
    check('insert before anchored row', solve([{'id':'a','height':5},{'id':'b','height':8}], [{'id':'x','height':4+2},{'id':'a','height':5},{'id':'b','height':8}], 'b', 2, 7, 4, [{'id':'a','width':5},{'id':'b','width':8}], [{'id':'x','width':3},{'id':'a','width':5},{'id':'b','width':8}], 'b', 2), {'row': 'b', 'scroll_y': 13, 'column': 'b', 'scroll_x': 10})
    check('removed anchor successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'c','height':9}], 'b', 3, 8, 4, [], [], 'gone', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('removed last anchor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8}], 'c', 3, 16, 4, [], [], 'gone', 0), {'row': 'b', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('shrunk anchored cell', solve([{'id':'a','height':20}], [{'id':'a','height':5}], 'a', 18, 18, 2, [{'id':'a','width':20}], [{'id':'a','width':5}], 'a', 18), {'row': 'a', 'scroll_y': 3, 'column': 'a', 'scroll_x': 4})
    check('bottom clamp', solve([{'id':'a','height':5},{'id':'b','height':10}], [{'id':'a','height':5},{'id':'b','height':4}], 'b', 3, 8, 7, [], [], '', 0), {'row': 'b', 'scroll_y': 2, 'column': None, 'scroll_x': 0})
    check('surviving middle', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'b', 'scroll_y': 7, 'column': None, 'scroll_x': 0})
    check('first successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9},{'id':'d','height':10}], [{'id':'a','height':5},{'id':'c','height':9},{'id':'d','height':10}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('interior shrink', solve([{'id':'a','height':20},{'id':'b','height':30}], [{'id':'a','height':5},{'id':'b','height':30}], 'a', 18, 18, 2, [], [], '', 0), {'row': 'a', 'scroll_y': 4, 'column': None, 'scroll_x': 0})
    check('empty table', solve([{'id':'a','height':5}], [], 'a', 2, 2, 4, [], [], '', 0), {'row': None, 'scroll_y': 0, 'column': None, 'scroll_x': 0})

if N == 5:
    check('insert before anchored row', solve([{'id':'a','height':5},{'id':'b','height':8}], [{'id':'x','height':5+2},{'id':'a','height':5},{'id':'b','height':8}], 'b', 2, 7, 4, [{'id':'a','width':5},{'id':'b','width':8}], [{'id':'x','width':3},{'id':'a','width':5},{'id':'b','width':8}], 'b', 2), {'row': 'b', 'scroll_y': 14, 'column': 'b', 'scroll_x': 10})
    check('removed anchor successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'c','height':9}], 'b', 3, 8, 4, [], [], 'gone', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('removed last anchor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8}], 'c', 3, 16, 4, [], [], 'gone', 0), {'row': 'b', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('shrunk anchored cell', solve([{'id':'a','height':20}], [{'id':'a','height':5}], 'a', 18, 18, 2, [{'id':'a','width':20}], [{'id':'a','width':5}], 'a', 18), {'row': 'a', 'scroll_y': 3, 'column': 'a', 'scroll_x': 4})
    check('bottom clamp', solve([{'id':'a','height':5},{'id':'b','height':10}], [{'id':'a','height':5},{'id':'b','height':4}], 'b', 3, 8, 7, [], [], '', 0), {'row': 'b', 'scroll_y': 2, 'column': None, 'scroll_x': 0})
    check('surviving middle', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'b', 'scroll_y': 7, 'column': None, 'scroll_x': 0})
    check('first successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9},{'id':'d','height':10}], [{'id':'a','height':5},{'id':'c','height':9},{'id':'d','height':10}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('interior shrink', solve([{'id':'a','height':20},{'id':'b','height':30}], [{'id':'a','height':5},{'id':'b','height':30}], 'a', 18, 18, 2, [], [], '', 0), {'row': 'a', 'scroll_y': 4, 'column': None, 'scroll_x': 0})
    check('empty table', solve([{'id':'a','height':5}], [], 'a', 2, 2, 4, [], [], '', 0), {'row': None, 'scroll_y': 0, 'column': None, 'scroll_x': 0})

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 horizontal prefix result violates the stipulated table viewport anchor restoration contract.

Restore a table viewport by stable row and column anchors after structural changes. A removed row chooses its next surviving former successor or final row, resets its inset, clamps surviving insets to new sizes, and clamps vertical scroll to the viewport extent.

split: open-access


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

N = 1
observations = []
def solve(before, after, anchor, inset, old_scroll, viewport, old_columns, new_columns, column_anchor, column_inset):
    old_ids=[x['id'] for x in before]; new_ids=[x['id'] for x in after]
    if anchor in new_ids: chosen=anchor
    else:
        following=old_ids[old_ids.index(anchor)+1:] if anchor in old_ids else []
        chosen=next((x for x in following if x in new_ids),new_ids[-1] if new_ids else None)
    idx=new_ids.index(chosen) if chosen is not None else 0
    prefix=sum(x['height'] for x in after[:idx])
    local=min(max(inset,0),max(0,after[idx]['height']-1)) if chosen==anchor and after else 0
    y=min(max(prefix+local,0),max(0,sum(x['height'] for x in after)-viewport))
    cols=[x['id'] for x in new_columns]
    ci=cols.index(column_anchor) if column_anchor in cols else 0
    x=sum(c['width'] for c in new_columns[:ci])+(column_inset if column_anchor in cols else 0)
    return {'row':chosen,'scroll_y':y,'column':cols[ci] if cols else None,'scroll_x':x}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('insert before anchored row', solve([{'id':'a','height':5},{'id':'b','height':8}], [{'id':'x','height':1+2},{'id':'a','height':5},{'id':'b','height':8}], 'b', 2, 7, 4, [{'id':'a','width':5},{'id':'b','width':8}], [{'id':'x','width':3},{'id':'a','width':5},{'id':'b','width':8}], 'b', 2), {'row': 'b', 'scroll_y': 10, 'column': 'b', 'scroll_x': 10})
    check('removed anchor successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'c','height':9}], 'b', 3, 8, 4, [], [], 'gone', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('removed last anchor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8}], 'c', 3, 16, 4, [], [], 'gone', 0), {'row': 'b', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('shrunk anchored cell', solve([{'id':'a','height':20}], [{'id':'a','height':5}], 'a', 18, 18, 2, [{'id':'a','width':20}], [{'id':'a','width':5}], 'a', 18), {'row': 'a', 'scroll_y': 3, 'column': 'a', 'scroll_x': 4})
    check('bottom clamp', solve([{'id':'a','height':5},{'id':'b','height':10}], [{'id':'a','height':5},{'id':'b','height':4}], 'b', 3, 8, 7, [], [], '', 0), {'row': 'b', 'scroll_y': 2, 'column': None, 'scroll_x': 0})
    check('surviving middle', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'b', 'scroll_y': 7, 'column': None, 'scroll_x': 0})
    check('first successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9},{'id':'d','height':10}], [{'id':'a','height':5},{'id':'c','height':9},{'id':'d','height':10}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('interior shrink', solve([{'id':'a','height':20},{'id':'b','height':30}], [{'id':'a','height':5},{'id':'b','height':30}], 'a', 18, 18, 2, [], [], '', 0), {'row': 'a', 'scroll_y': 4, 'column': None, 'scroll_x': 0})
    check('empty table', solve([{'id':'a','height':5}], [], 'a', 2, 2, 4, [], [], '', 0), {'row': None, 'scroll_y': 0, 'column': None, 'scroll_x': 0})

if N == 2:
    check('insert before anchored row', solve([{'id':'a','height':5},{'id':'b','height':8}], [{'id':'x','height':2+2},{'id':'a','height':5},{'id':'b','height':8}], 'b', 2, 7, 4, [{'id':'a','width':5},{'id':'b','width':8}], [{'id':'x','width':3},{'id':'a','width':5},{'id':'b','width':8}], 'b', 2), {'row': 'b', 'scroll_y': 11, 'column': 'b', 'scroll_x': 10})
    check('removed anchor successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'c','height':9}], 'b', 3, 8, 4, [], [], 'gone', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('removed last anchor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8}], 'c', 3, 16, 4, [], [], 'gone', 0), {'row': 'b', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('shrunk anchored cell', solve([{'id':'a','height':20}], [{'id':'a','height':5}], 'a', 18, 18, 2, [{'id':'a','width':20}], [{'id':'a','width':5}], 'a', 18), {'row': 'a', 'scroll_y': 3, 'column': 'a', 'scroll_x': 4})
    check('bottom clamp', solve([{'id':'a','height':5},{'id':'b','height':10}], [{'id':'a','height':5},{'id':'b','height':4}], 'b', 3, 8, 7, [], [], '', 0), {'row': 'b', 'scroll_y': 2, 'column': None, 'scroll_x': 0})
    check('surviving middle', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'b', 'scroll_y': 7, 'column': None, 'scroll_x': 0})
    check('first successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9},{'id':'d','height':10}], [{'id':'a','height':5},{'id':'c','height':9},{'id':'d','height':10}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('interior shrink', solve([{'id':'a','height':20},{'id':'b','height':30}], [{'id':'a','height':5},{'id':'b','height':30}], 'a', 18, 18, 2, [], [], '', 0), {'row': 'a', 'scroll_y': 4, 'column': None, 'scroll_x': 0})
    check('empty table', solve([{'id':'a','height':5}], [], 'a', 2, 2, 4, [], [], '', 0), {'row': None, 'scroll_y': 0, 'column': None, 'scroll_x': 0})

if N == 3:
    check('insert before anchored row', solve([{'id':'a','height':5},{'id':'b','height':8}], [{'id':'x','height':3+2},{'id':'a','height':5},{'id':'b','height':8}], 'b', 2, 7, 4, [{'id':'a','width':5},{'id':'b','width':8}], [{'id':'x','width':3},{'id':'a','width':5},{'id':'b','width':8}], 'b', 2), {'row': 'b', 'scroll_y': 12, 'column': 'b', 'scroll_x': 10})
    check('removed anchor successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'c','height':9}], 'b', 3, 8, 4, [], [], 'gone', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('removed last anchor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8}], 'c', 3, 16, 4, [], [], 'gone', 0), {'row': 'b', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('shrunk anchored cell', solve([{'id':'a','height':20}], [{'id':'a','height':5}], 'a', 18, 18, 2, [{'id':'a','width':20}], [{'id':'a','width':5}], 'a', 18), {'row': 'a', 'scroll_y': 3, 'column': 'a', 'scroll_x': 4})
    check('bottom clamp', solve([{'id':'a','height':5},{'id':'b','height':10}], [{'id':'a','height':5},{'id':'b','height':4}], 'b', 3, 8, 7, [], [], '', 0), {'row': 'b', 'scroll_y': 2, 'column': None, 'scroll_x': 0})
    check('surviving middle', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'b', 'scroll_y': 7, 'column': None, 'scroll_x': 0})
    check('first successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9},{'id':'d','height':10}], [{'id':'a','height':5},{'id':'c','height':9},{'id':'d','height':10}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('interior shrink', solve([{'id':'a','height':20},{'id':'b','height':30}], [{'id':'a','height':5},{'id':'b','height':30}], 'a', 18, 18, 2, [], [], '', 0), {'row': 'a', 'scroll_y': 4, 'column': None, 'scroll_x': 0})
    check('empty table', solve([{'id':'a','height':5}], [], 'a', 2, 2, 4, [], [], '', 0), {'row': None, 'scroll_y': 0, 'column': None, 'scroll_x': 0})

if N == 4:
    check('insert before anchored row', solve([{'id':'a','height':5},{'id':'b','height':8}], [{'id':'x','height':4+2},{'id':'a','height':5},{'id':'b','height':8}], 'b', 2, 7, 4, [{'id':'a','width':5},{'id':'b','width':8}], [{'id':'x','width':3},{'id':'a','width':5},{'id':'b','width':8}], 'b', 2), {'row': 'b', 'scroll_y': 13, 'column': 'b', 'scroll_x': 10})
    check('removed anchor successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'c','height':9}], 'b', 3, 8, 4, [], [], 'gone', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('removed last anchor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8}], 'c', 3, 16, 4, [], [], 'gone', 0), {'row': 'b', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('shrunk anchored cell', solve([{'id':'a','height':20}], [{'id':'a','height':5}], 'a', 18, 18, 2, [{'id':'a','width':20}], [{'id':'a','width':5}], 'a', 18), {'row': 'a', 'scroll_y': 3, 'column': 'a', 'scroll_x': 4})
    check('bottom clamp', solve([{'id':'a','height':5},{'id':'b','height':10}], [{'id':'a','height':5},{'id':'b','height':4}], 'b', 3, 8, 7, [], [], '', 0), {'row': 'b', 'scroll_y': 2, 'column': None, 'scroll_x': 0})
    check('surviving middle', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'b', 'scroll_y': 7, 'column': None, 'scroll_x': 0})
    check('first successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9},{'id':'d','height':10}], [{'id':'a','height':5},{'id':'c','height':9},{'id':'d','height':10}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('interior shrink', solve([{'id':'a','height':20},{'id':'b','height':30}], [{'id':'a','height':5},{'id':'b','height':30}], 'a', 18, 18, 2, [], [], '', 0), {'row': 'a', 'scroll_y': 4, 'column': None, 'scroll_x': 0})
    check('empty table', solve([{'id':'a','height':5}], [], 'a', 2, 2, 4, [], [], '', 0), {'row': None, 'scroll_y': 0, 'column': None, 'scroll_x': 0})

if N == 5:
    check('insert before anchored row', solve([{'id':'a','height':5},{'id':'b','height':8}], [{'id':'x','height':5+2},{'id':'a','height':5},{'id':'b','height':8}], 'b', 2, 7, 4, [{'id':'a','width':5},{'id':'b','width':8}], [{'id':'x','width':3},{'id':'a','width':5},{'id':'b','width':8}], 'b', 2), {'row': 'b', 'scroll_y': 14, 'column': 'b', 'scroll_x': 10})
    check('removed anchor successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'c','height':9}], 'b', 3, 8, 4, [], [], 'gone', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('removed last anchor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8}], 'c', 3, 16, 4, [], [], 'gone', 0), {'row': 'b', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('shrunk anchored cell', solve([{'id':'a','height':20}], [{'id':'a','height':5}], 'a', 18, 18, 2, [{'id':'a','width':20}], [{'id':'a','width':5}], 'a', 18), {'row': 'a', 'scroll_y': 3, 'column': 'a', 'scroll_x': 4})
    check('bottom clamp', solve([{'id':'a','height':5},{'id':'b','height':10}], [{'id':'a','height':5},{'id':'b','height':4}], 'b', 3, 8, 7, [], [], '', 0), {'row': 'b', 'scroll_y': 2, 'column': None, 'scroll_x': 0})
    check('surviving middle', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'b', 'scroll_y': 7, 'column': None, 'scroll_x': 0})
    check('first successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9},{'id':'d','height':10}], [{'id':'a','height':5},{'id':'c','height':9},{'id':'d','height':10}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('interior shrink', solve([{'id':'a','height':20},{'id':'b','height':30}], [{'id':'a','height':5},{'id':'b','height':30}], 'a', 18, 18, 2, [], [], '', 0), {'row': 'a', 'scroll_y': 4, 'column': None, 'scroll_x': 0})
    check('empty table', solve([{'id':'a','height':5}], [], 'a', 2, 2, 4, [], [], '', 0), {'row': None, 'scroll_y': 0, 'column': None, 'scroll_x': 0})

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(before, after, anchor, inset, old_scroll, viewport, old_columns, new_columns, column_anchor, column_inset):
    old_ids=[x['id'] for x in before]; new_ids=[x['id'] for x in after]
    if anchor in new_ids: chosen=anchor
    else:
        following=old_ids[old_ids.index(anchor)+1:] if anchor in old_ids else []
        chosen=next((x for x in following if x in new_ids),new_ids[-1] if new_ids else None)
    idx=new_ids.index(chosen) if chosen is not None else 0
    prefix=sum(x['height'] for x in after[:idx])
    local=min(max(inset,0),max(0,after[idx]['height']-1)) if chosen==anchor and after else 0
    y=min(max(prefix+local,0),max(0,sum(x['height'] for x in after)-viewport))
    cols=[x['id'] for x in new_columns]
    ci=cols.index(column_anchor) if column_anchor in cols else 0
    x=sum(c['width'] for c in new_columns[:ci])+(0 if column_anchor in cols else 0)
    return {'row':chosen,'scroll_y':y,'column':cols[ci] if cols else None,'scroll_x':x}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('insert before anchored row', solve([{'id':'a','height':5},{'id':'b','height':8}], [{'id':'x','height':1+2},{'id':'a','height':5},{'id':'b','height':8}], 'b', 2, 7, 4, [{'id':'a','width':5},{'id':'b','width':8}], [{'id':'x','width':3},{'id':'a','width':5},{'id':'b','width':8}], 'b', 2), {'row': 'b', 'scroll_y': 10, 'column': 'b', 'scroll_x': 10})
    check('removed anchor successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'c','height':9}], 'b', 3, 8, 4, [], [], 'gone', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('removed last anchor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8}], 'c', 3, 16, 4, [], [], 'gone', 0), {'row': 'b', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('shrunk anchored cell', solve([{'id':'a','height':20}], [{'id':'a','height':5}], 'a', 18, 18, 2, [{'id':'a','width':20}], [{'id':'a','width':5}], 'a', 18), {'row': 'a', 'scroll_y': 3, 'column': 'a', 'scroll_x': 4})
    check('bottom clamp', solve([{'id':'a','height':5},{'id':'b','height':10}], [{'id':'a','height':5},{'id':'b','height':4}], 'b', 3, 8, 7, [], [], '', 0), {'row': 'b', 'scroll_y': 2, 'column': None, 'scroll_x': 0})
    check('surviving middle', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'b', 'scroll_y': 7, 'column': None, 'scroll_x': 0})
    check('first successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9},{'id':'d','height':10}], [{'id':'a','height':5},{'id':'c','height':9},{'id':'d','height':10}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('interior shrink', solve([{'id':'a','height':20},{'id':'b','height':30}], [{'id':'a','height':5},{'id':'b','height':30}], 'a', 18, 18, 2, [], [], '', 0), {'row': 'a', 'scroll_y': 4, 'column': None, 'scroll_x': 0})
    check('empty table', solve([{'id':'a','height':5}], [], 'a', 2, 2, 4, [], [], '', 0), {'row': None, 'scroll_y': 0, 'column': None, 'scroll_x': 0})

if N == 2:
    check('insert before anchored row', solve([{'id':'a','height':5},{'id':'b','height':8}], [{'id':'x','height':2+2},{'id':'a','height':5},{'id':'b','height':8}], 'b', 2, 7, 4, [{'id':'a','width':5},{'id':'b','width':8}], [{'id':'x','width':3},{'id':'a','width':5},{'id':'b','width':8}], 'b', 2), {'row': 'b', 'scroll_y': 11, 'column': 'b', 'scroll_x': 10})
    check('removed anchor successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'c','height':9}], 'b', 3, 8, 4, [], [], 'gone', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('removed last anchor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8}], 'c', 3, 16, 4, [], [], 'gone', 0), {'row': 'b', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('shrunk anchored cell', solve([{'id':'a','height':20}], [{'id':'a','height':5}], 'a', 18, 18, 2, [{'id':'a','width':20}], [{'id':'a','width':5}], 'a', 18), {'row': 'a', 'scroll_y': 3, 'column': 'a', 'scroll_x': 4})
    check('bottom clamp', solve([{'id':'a','height':5},{'id':'b','height':10}], [{'id':'a','height':5},{'id':'b','height':4}], 'b', 3, 8, 7, [], [], '', 0), {'row': 'b', 'scroll_y': 2, 'column': None, 'scroll_x': 0})
    check('surviving middle', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'b', 'scroll_y': 7, 'column': None, 'scroll_x': 0})
    check('first successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9},{'id':'d','height':10}], [{'id':'a','height':5},{'id':'c','height':9},{'id':'d','height':10}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('interior shrink', solve([{'id':'a','height':20},{'id':'b','height':30}], [{'id':'a','height':5},{'id':'b','height':30}], 'a', 18, 18, 2, [], [], '', 0), {'row': 'a', 'scroll_y': 4, 'column': None, 'scroll_x': 0})
    check('empty table', solve([{'id':'a','height':5}], [], 'a', 2, 2, 4, [], [], '', 0), {'row': None, 'scroll_y': 0, 'column': None, 'scroll_x': 0})

if N == 3:
    check('insert before anchored row', solve([{'id':'a','height':5},{'id':'b','height':8}], [{'id':'x','height':3+2},{'id':'a','height':5},{'id':'b','height':8}], 'b', 2, 7, 4, [{'id':'a','width':5},{'id':'b','width':8}], [{'id':'x','width':3},{'id':'a','width':5},{'id':'b','width':8}], 'b', 2), {'row': 'b', 'scroll_y': 12, 'column': 'b', 'scroll_x': 10})
    check('removed anchor successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'c','height':9}], 'b', 3, 8, 4, [], [], 'gone', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('removed last anchor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8}], 'c', 3, 16, 4, [], [], 'gone', 0), {'row': 'b', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('shrunk anchored cell', solve([{'id':'a','height':20}], [{'id':'a','height':5}], 'a', 18, 18, 2, [{'id':'a','width':20}], [{'id':'a','width':5}], 'a', 18), {'row': 'a', 'scroll_y': 3, 'column': 'a', 'scroll_x': 4})
    check('bottom clamp', solve([{'id':'a','height':5},{'id':'b','height':10}], [{'id':'a','height':5},{'id':'b','height':4}], 'b', 3, 8, 7, [], [], '', 0), {'row': 'b', 'scroll_y': 2, 'column': None, 'scroll_x': 0})
    check('surviving middle', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'b', 'scroll_y': 7, 'column': None, 'scroll_x': 0})
    check('first successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9},{'id':'d','height':10}], [{'id':'a','height':5},{'id':'c','height':9},{'id':'d','height':10}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('interior shrink', solve([{'id':'a','height':20},{'id':'b','height':30}], [{'id':'a','height':5},{'id':'b','height':30}], 'a', 18, 18, 2, [], [], '', 0), {'row': 'a', 'scroll_y': 4, 'column': None, 'scroll_x': 0})
    check('empty table', solve([{'id':'a','height':5}], [], 'a', 2, 2, 4, [], [], '', 0), {'row': None, 'scroll_y': 0, 'column': None, 'scroll_x': 0})

if N == 4:
    check('insert before anchored row', solve([{'id':'a','height':5},{'id':'b','height':8}], [{'id':'x','height':4+2},{'id':'a','height':5},{'id':'b','height':8}], 'b', 2, 7, 4, [{'id':'a','width':5},{'id':'b','width':8}], [{'id':'x','width':3},{'id':'a','width':5},{'id':'b','width':8}], 'b', 2), {'row': 'b', 'scroll_y': 13, 'column': 'b', 'scroll_x': 10})
    check('removed anchor successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'c','height':9}], 'b', 3, 8, 4, [], [], 'gone', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('removed last anchor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8}], 'c', 3, 16, 4, [], [], 'gone', 0), {'row': 'b', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('shrunk anchored cell', solve([{'id':'a','height':20}], [{'id':'a','height':5}], 'a', 18, 18, 2, [{'id':'a','width':20}], [{'id':'a','width':5}], 'a', 18), {'row': 'a', 'scroll_y': 3, 'column': 'a', 'scroll_x': 4})
    check('bottom clamp', solve([{'id':'a','height':5},{'id':'b','height':10}], [{'id':'a','height':5},{'id':'b','height':4}], 'b', 3, 8, 7, [], [], '', 0), {'row': 'b', 'scroll_y': 2, 'column': None, 'scroll_x': 0})
    check('surviving middle', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'b', 'scroll_y': 7, 'column': None, 'scroll_x': 0})
    check('first successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9},{'id':'d','height':10}], [{'id':'a','height':5},{'id':'c','height':9},{'id':'d','height':10}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('interior shrink', solve([{'id':'a','height':20},{'id':'b','height':30}], [{'id':'a','height':5},{'id':'b','height':30}], 'a', 18, 18, 2, [], [], '', 0), {'row': 'a', 'scroll_y': 4, 'column': None, 'scroll_x': 0})
    check('empty table', solve([{'id':'a','height':5}], [], 'a', 2, 2, 4, [], [], '', 0), {'row': None, 'scroll_y': 0, 'column': None, 'scroll_x': 0})

if N == 5:
    check('insert before anchored row', solve([{'id':'a','height':5},{'id':'b','height':8}], [{'id':'x','height':5+2},{'id':'a','height':5},{'id':'b','height':8}], 'b', 2, 7, 4, [{'id':'a','width':5},{'id':'b','width':8}], [{'id':'x','width':3},{'id':'a','width':5},{'id':'b','width':8}], 'b', 2), {'row': 'b', 'scroll_y': 14, 'column': 'b', 'scroll_x': 10})
    check('removed anchor successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'c','height':9}], 'b', 3, 8, 4, [], [], 'gone', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('removed last anchor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8}], 'c', 3, 16, 4, [], [], 'gone', 0), {'row': 'b', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('shrunk anchored cell', solve([{'id':'a','height':20}], [{'id':'a','height':5}], 'a', 18, 18, 2, [{'id':'a','width':20}], [{'id':'a','width':5}], 'a', 18), {'row': 'a', 'scroll_y': 3, 'column': 'a', 'scroll_x': 4})
    check('bottom clamp', solve([{'id':'a','height':5},{'id':'b','height':10}], [{'id':'a','height':5},{'id':'b','height':4}], 'b', 3, 8, 7, [], [], '', 0), {'row': 'b', 'scroll_y': 2, 'column': None, 'scroll_x': 0})
    check('surviving middle', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], [{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'b', 'scroll_y': 7, 'column': None, 'scroll_x': 0})
    check('first successor', solve([{'id':'a','height':5},{'id':'b','height':8},{'id':'c','height':9},{'id':'d','height':10}], [{'id':'a','height':5},{'id':'c','height':9},{'id':'d','height':10}], 'b', 2, 7, 4, [], [], '', 0), {'row': 'c', 'scroll_y': 5, 'column': None, 'scroll_x': 0})
    check('interior shrink', solve([{'id':'a','height':20},{'id':'b','height':30}], [{'id':'a','height':5},{'id':'b','height':30}], 'a', 18, 18, 2, [], [], '', 0), {'row': 'a', 'scroll_y': 4, 'column': None, 'scroll_x': 0})
    check('empty table', solve([{'id':'a','height':5}], [], 'a', 2, 2, 4, [], [], '', 0), {'row': None, 'scroll_y': 0, 'column': None, 'scroll_x': 0})

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 column inset clamp result violates the stipulated table viewport anchor restoration contract.

Restore a table viewport by stable row and column anchors after structural changes. A removed row chooses its next surviving former successor or final row, resets its inset, clamps surviving insets to new sizes, and clamps vertical scroll to the viewport extent.

split: open-access


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

N = 1
observations = []
def solve(state, response):
    out=dict(state)
    if False: return out
    if response['query']!=state['query']: return out
    if response['offset']!=state['offset']: return out
    if response.get('error') is not None:
        out.update(loading=False,error=response['error']); return out
    ids=[]; by={}
    for row in response['rows']:
        if row['id'] not in by: ids.append(row['id'])
        by[row['id']]=row
    out['rows']=[by[k] for k in ids]
    out['total']=response['total']
    out['loading']=False; out['error']=None
    out['has_next']=response['offset']+len(ids)<response['total']
    out['selected']=[k for k in state['selected'] if k not in response.get('deleted',[])]
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('fresh deduped page', solve({'request':2,'query':'q','offset':2,'rows':[{'id':'old'}],'total':20,'loading':True,'error':'old error','selected':['a','off','gone']}, {'request':2,'query':'q','offset':2,'rows':[{'id':'a','v':1},{'id':'b','v':1},{'id':'a','v':3}],'total':4,'deleted':['gone']}), {'request': 2, 'query': 'q', 'offset': 2, 'rows': [{'id': 'a', 'v': 3}, {'id': 'b', 'v': 1}], 'total': 4, 'loading': False, 'error': None, 'selected': ['a', 'off'], 'has_next': False})
    check('late request', solve({'request':2,'query':'q','offset':0,'rows':[],'total':0,'loading':True,'error':None,'selected':[]}, {'request':1,'query':'q','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [], 'total': 0, 'loading': True, 'error': None, 'selected': []})
    check('old query', solve({'request':2,'query':'q','offset':0,'rows':[],'total':0,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'old','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [], 'total': 0, 'loading': True, 'error': None, 'selected': []})
    check('old offset', solve({'request':2,'query':'q','offset':2,'rows':[],'total':0,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'q','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 2, 'rows': [], 'total': 0, 'loading': True, 'error': None, 'selected': []})
    check('error retains page', solve({'request':2,'query':'q','offset':0,'rows':[{'id':'old'}],'total':1,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'q','offset':0,'rows':[],'total':0,'error':'failed'}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [{'id': 'old'}], 'total': 1, 'loading': False, 'error': 'failed', 'selected': []})
    check('empty final page', solve({'request':2,'query':'q','offset':0,'rows':[],'total':2,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'q','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [], 'total': 0, 'loading': False, 'error': None, 'selected': [], 'has_next': False})

if N == 2:
    check('fresh deduped page', solve({'request':2,'query':'q','offset':2,'rows':[{'id':'old'}],'total':20,'loading':True,'error':'old error','selected':['a','off','gone']}, {'request':2,'query':'q','offset':2,'rows':[{'id':'a','v':1},{'id':'b','v':2},{'id':'a','v':3}],'total':4,'deleted':['gone']}), {'request': 2, 'query': 'q', 'offset': 2, 'rows': [{'id': 'a', 'v': 3}, {'id': 'b', 'v': 2}], 'total': 4, 'loading': False, 'error': None, 'selected': ['a', 'off'], 'has_next': False})
    check('late request', solve({'request':2,'query':'q','offset':0,'rows':[],'total':0,'loading':True,'error':None,'selected':[]}, {'request':1,'query':'q','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [], 'total': 0, 'loading': True, 'error': None, 'selected': []})
    check('old query', solve({'request':2,'query':'q','offset':0,'rows':[],'total':0,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'old','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [], 'total': 0, 'loading': True, 'error': None, 'selected': []})
    check('old offset', solve({'request':2,'query':'q','offset':2,'rows':[],'total':0,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'q','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 2, 'rows': [], 'total': 0, 'loading': True, 'error': None, 'selected': []})
    check('error retains page', solve({'request':2,'query':'q','offset':0,'rows':[{'id':'old'}],'total':1,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'q','offset':0,'rows':[],'total':0,'error':'failed'}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [{'id': 'old'}], 'total': 1, 'loading': False, 'error': 'failed', 'selected': []})
    check('empty final page', solve({'request':2,'query':'q','offset':0,'rows':[],'total':2,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'q','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [], 'total': 0, 'loading': False, 'error': None, 'selected': [], 'has_next': False})

if N == 3:
    check('fresh deduped page', solve({'request':2,'query':'q','offset':2,'rows':[{'id':'old'}],'total':20,'loading':True,'error':'old error','selected':['a','off','gone']}, {'request':2,'query':'q','offset':2,'rows':[{'id':'a','v':1},{'id':'b','v':3},{'id':'a','v':3}],'total':4,'deleted':['gone']}), {'request': 2, 'query': 'q', 'offset': 2, 'rows': [{'id': 'a', 'v': 3}, {'id': 'b', 'v': 3}], 'total': 4, 'loading': False, 'error': None, 'selected': ['a', 'off'], 'has_next': False})
    check('late request', solve({'request':2,'query':'q','offset':0,'rows':[],'total':0,'loading':True,'error':None,'selected':[]}, {'request':1,'query':'q','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [], 'total': 0, 'loading': True, 'error': None, 'selected': []})
    check('old query', solve({'request':2,'query':'q','offset':0,'rows':[],'total':0,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'old','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [], 'total': 0, 'loading': True, 'error': None, 'selected': []})
    check('old offset', solve({'request':2,'query':'q','offset':2,'rows':[],'total':0,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'q','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 2, 'rows': [], 'total': 0, 'loading': True, 'error': None, 'selected': []})
    check('error retains page', solve({'request':2,'query':'q','offset':0,'rows':[{'id':'old'}],'total':1,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'q','offset':0,'rows':[],'total':0,'error':'failed'}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [{'id': 'old'}], 'total': 1, 'loading': False, 'error': 'failed', 'selected': []})
    check('empty final page', solve({'request':2,'query':'q','offset':0,'rows':[],'total':2,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'q','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [], 'total': 0, 'loading': False, 'error': None, 'selected': [], 'has_next': False})

if N == 4:
    check('fresh deduped page', solve({'request':2,'query':'q','offset':2,'rows':[{'id':'old'}],'total':20,'loading':True,'error':'old error','selected':['a','off','gone']}, {'request':2,'query':'q','offset':2,'rows':[{'id':'a','v':1},{'id':'b','v':4},{'id':'a','v':3}],'total':4,'deleted':['gone']}), {'request': 2, 'query': 'q', 'offset': 2, 'rows': [{'id': 'a', 'v': 3}, {'id': 'b', 'v': 4}], 'total': 4, 'loading': False, 'error': None, 'selected': ['a', 'off'], 'has_next': False})
    check('late request', solve({'request':2,'query':'q','offset':0,'rows':[],'total':0,'loading':True,'error':None,'selected':[]}, {'request':1,'query':'q','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [], 'total': 0, 'loading': True, 'error': None, 'selected': []})
    check('old query', solve({'request':2,'query':'q','offset':0,'rows':[],'total':0,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'old','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [], 'total': 0, 'loading': True, 'error': None, 'selected': []})
    check('old offset', solve({'request':2,'query':'q','offset':2,'rows':[],'total':0,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'q','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 2, 'rows': [], 'total': 0, 'loading': True, 'error': None, 'selected': []})
    check('error retains page', solve({'request':2,'query':'q','offset':0,'rows':[{'id':'old'}],'total':1,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'q','offset':0,'rows':[],'total':0,'error':'failed'}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [{'id': 'old'}], 'total': 1, 'loading': False, 'error': 'failed', 'selected': []})
    check('empty final page', solve({'request':2,'query':'q','offset':0,'rows':[],'total':2,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'q','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [], 'total': 0, 'loading': False, 'error': None, 'selected': [], 'has_next': False})

if N == 5:
    check('fresh deduped page', solve({'request':2,'query':'q','offset':2,'rows':[{'id':'old'}],'total':20,'loading':True,'error':'old error','selected':['a','off','gone']}, {'request':2,'query':'q','offset':2,'rows':[{'id':'a','v':1},{'id':'b','v':5},{'id':'a','v':3}],'total':4,'deleted':['gone']}), {'request': 2, 'query': 'q', 'offset': 2, 'rows': [{'id': 'a', 'v': 3}, {'id': 'b', 'v': 5}], 'total': 4, 'loading': False, 'error': None, 'selected': ['a', 'off'], 'has_next': False})
    check('late request', solve({'request':2,'query':'q','offset':0,'rows':[],'total':0,'loading':True,'error':None,'selected':[]}, {'request':1,'query':'q','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [], 'total': 0, 'loading': True, 'error': None, 'selected': []})
    check('old query', solve({'request':2,'query':'q','offset':0,'rows':[],'total':0,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'old','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [], 'total': 0, 'loading': True, 'error': None, 'selected': []})
    check('old offset', solve({'request':2,'query':'q','offset':2,'rows':[],'total':0,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'q','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 2, 'rows': [], 'total': 0, 'loading': True, 'error': None, 'selected': []})
    check('error retains page', solve({'request':2,'query':'q','offset':0,'rows':[{'id':'old'}],'total':1,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'q','offset':0,'rows':[],'total':0,'error':'failed'}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [{'id': 'old'}], 'total': 1, 'loading': False, 'error': 'failed', 'selected': []})
    check('empty final page', solve({'request':2,'query':'q','offset':0,'rows':[],'total':2,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'q','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [], 'total': 0, 'loading': False, 'error': None, 'selected': [], 'has_next': False})

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(state, response):
    out=dict(state)
    if response['request']>state['request']: return out
    if response['query']!=state['query']: return out
    if response['offset']!=state['offset']: return out
    if response.get('error') is not None:
        out.update(loading=False,error=response['error']); return out
    ids=[]; by={}
    for row in response['rows']:
        if row['id'] not in by: ids.append(row['id'])
        by[row['id']]=row
    out['rows']=[by[k] for k in ids]
    out['total']=response['total']
    out['loading']=False; out['error']=None
    out['has_next']=response['offset']+len(ids)<response['total']
    out['selected']=[k for k in state['selected'] if k not in response.get('deleted',[])]
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('fresh deduped page', solve({'request':2,'query':'q','offset':2,'rows':[{'id':'old'}],'total':20,'loading':True,'error':'old error','selected':['a','off','gone']}, {'request':2,'query':'q','offset':2,'rows':[{'id':'a','v':1},{'id':'b','v':1},{'id':'a','v':3}],'total':4,'deleted':['gone']}), {'request': 2, 'query': 'q', 'offset': 2, 'rows': [{'id': 'a', 'v': 3}, {'id': 'b', 'v': 1}], 'total': 4, 'loading': False, 'error': None, 'selected': ['a', 'off'], 'has_next': False})
    check('late request', solve({'request':2,'query':'q','offset':0,'rows':[],'total':0,'loading':True,'error':None,'selected':[]}, {'request':1,'query':'q','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [], 'total': 0, 'loading': True, 'error': None, 'selected': []})
    check('old query', solve({'request':2,'query':'q','offset':0,'rows':[],'total':0,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'old','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [], 'total': 0, 'loading': True, 'error': None, 'selected': []})
    check('old offset', solve({'request':2,'query':'q','offset':2,'rows':[],'total':0,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'q','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 2, 'rows': [], 'total': 0, 'loading': True, 'error': None, 'selected': []})
    check('error retains page', solve({'request':2,'query':'q','offset':0,'rows':[{'id':'old'}],'total':1,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'q','offset':0,'rows':[],'total':0,'error':'failed'}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [{'id': 'old'}], 'total': 1, 'loading': False, 'error': 'failed', 'selected': []})
    check('empty final page', solve({'request':2,'query':'q','offset':0,'rows':[],'total':2,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'q','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [], 'total': 0, 'loading': False, 'error': None, 'selected': [], 'has_next': False})

if N == 2:
    check('fresh deduped page', solve({'request':2,'query':'q','offset':2,'rows':[{'id':'old'}],'total':20,'loading':True,'error':'old error','selected':['a','off','gone']}, {'request':2,'query':'q','offset':2,'rows':[{'id':'a','v':1},{'id':'b','v':2},{'id':'a','v':3}],'total':4,'deleted':['gone']}), {'request': 2, 'query': 'q', 'offset': 2, 'rows': [{'id': 'a', 'v': 3}, {'id': 'b', 'v': 2}], 'total': 4, 'loading': False, 'error': None, 'selected': ['a', 'off'], 'has_next': False})
    check('late request', solve({'request':2,'query':'q','offset':0,'rows':[],'total':0,'loading':True,'error':None,'selected':[]}, {'request':1,'query':'q','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [], 'total': 0, 'loading': True, 'error': None, 'selected': []})
    check('old query', solve({'request':2,'query':'q','offset':0,'rows':[],'total':0,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'old','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [], 'total': 0, 'loading': True, 'error': None, 'selected': []})
    check('old offset', solve({'request':2,'query':'q','offset':2,'rows':[],'total':0,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'q','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 2, 'rows': [], 'total': 0, 'loading': True, 'error': None, 'selected': []})
    check('error retains page', solve({'request':2,'query':'q','offset':0,'rows':[{'id':'old'}],'total':1,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'q','offset':0,'rows':[],'total':0,'error':'failed'}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [{'id': 'old'}], 'total': 1, 'loading': False, 'error': 'failed', 'selected': []})
    check('empty final page', solve({'request':2,'query':'q','offset':0,'rows':[],'total':2,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'q','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [], 'total': 0, 'loading': False, 'error': None, 'selected': [], 'has_next': False})

if N == 3:
    check('fresh deduped page', solve({'request':2,'query':'q','offset':2,'rows':[{'id':'old'}],'total':20,'loading':True,'error':'old error','selected':['a','off','gone']}, {'request':2,'query':'q','offset':2,'rows':[{'id':'a','v':1},{'id':'b','v':3},{'id':'a','v':3}],'total':4,'deleted':['gone']}), {'request': 2, 'query': 'q', 'offset': 2, 'rows': [{'id': 'a', 'v': 3}, {'id': 'b', 'v': 3}], 'total': 4, 'loading': False, 'error': None, 'selected': ['a', 'off'], 'has_next': False})
    check('late request', solve({'request':2,'query':'q','offset':0,'rows':[],'total':0,'loading':True,'error':None,'selected':[]}, {'request':1,'query':'q','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [], 'total': 0, 'loading': True, 'error': None, 'selected': []})
    check('old query', solve({'request':2,'query':'q','offset':0,'rows':[],'total':0,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'old','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [], 'total': 0, 'loading': True, 'error': None, 'selected': []})
    check('old offset', solve({'request':2,'query':'q','offset':2,'rows':[],'total':0,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'q','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 2, 'rows': [], 'total': 0, 'loading': True, 'error': None, 'selected': []})
    check('error retains page', solve({'request':2,'query':'q','offset':0,'rows':[{'id':'old'}],'total':1,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'q','offset':0,'rows':[],'total':0,'error':'failed'}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [{'id': 'old'}], 'total': 1, 'loading': False, 'error': 'failed', 'selected': []})
    check('empty final page', solve({'request':2,'query':'q','offset':0,'rows':[],'total':2,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'q','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [], 'total': 0, 'loading': False, 'error': None, 'selected': [], 'has_next': False})

if N == 4:
    check('fresh deduped page', solve({'request':2,'query':'q','offset':2,'rows':[{'id':'old'}],'total':20,'loading':True,'error':'old error','selected':['a','off','gone']}, {'request':2,'query':'q','offset':2,'rows':[{'id':'a','v':1},{'id':'b','v':4},{'id':'a','v':3}],'total':4,'deleted':['gone']}), {'request': 2, 'query': 'q', 'offset': 2, 'rows': [{'id': 'a', 'v': 3}, {'id': 'b', 'v': 4}], 'total': 4, 'loading': False, 'error': None, 'selected': ['a', 'off'], 'has_next': False})
    check('late request', solve({'request':2,'query':'q','offset':0,'rows':[],'total':0,'loading':True,'error':None,'selected':[]}, {'request':1,'query':'q','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [], 'total': 0, 'loading': True, 'error': None, 'selected': []})
    check('old query', solve({'request':2,'query':'q','offset':0,'rows':[],'total':0,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'old','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [], 'total': 0, 'loading': True, 'error': None, 'selected': []})
    check('old offset', solve({'request':2,'query':'q','offset':2,'rows':[],'total':0,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'q','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 2, 'rows': [], 'total': 0, 'loading': True, 'error': None, 'selected': []})
    check('error retains page', solve({'request':2,'query':'q','offset':0,'rows':[{'id':'old'}],'total':1,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'q','offset':0,'rows':[],'total':0,'error':'failed'}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [{'id': 'old'}], 'total': 1, 'loading': False, 'error': 'failed', 'selected': []})
    check('empty final page', solve({'request':2,'query':'q','offset':0,'rows':[],'total':2,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'q','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [], 'total': 0, 'loading': False, 'error': None, 'selected': [], 'has_next': False})

if N == 5:
    check('fresh deduped page', solve({'request':2,'query':'q','offset':2,'rows':[{'id':'old'}],'total':20,'loading':True,'error':'old error','selected':['a','off','gone']}, {'request':2,'query':'q','offset':2,'rows':[{'id':'a','v':1},{'id':'b','v':5},{'id':'a','v':3}],'total':4,'deleted':['gone']}), {'request': 2, 'query': 'q', 'offset': 2, 'rows': [{'id': 'a', 'v': 3}, {'id': 'b', 'v': 5}], 'total': 4, 'loading': False, 'error': None, 'selected': ['a', 'off'], 'has_next': False})
    check('late request', solve({'request':2,'query':'q','offset':0,'rows':[],'total':0,'loading':True,'error':None,'selected':[]}, {'request':1,'query':'q','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [], 'total': 0, 'loading': True, 'error': None, 'selected': []})
    check('old query', solve({'request':2,'query':'q','offset':0,'rows':[],'total':0,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'old','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [], 'total': 0, 'loading': True, 'error': None, 'selected': []})
    check('old offset', solve({'request':2,'query':'q','offset':2,'rows':[],'total':0,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'q','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 2, 'rows': [], 'total': 0, 'loading': True, 'error': None, 'selected': []})
    check('error retains page', solve({'request':2,'query':'q','offset':0,'rows':[{'id':'old'}],'total':1,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'q','offset':0,'rows':[],'total':0,'error':'failed'}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [{'id': 'old'}], 'total': 1, 'loading': False, 'error': 'failed', 'selected': []})
    check('empty final page', solve({'request':2,'query':'q','offset':0,'rows':[],'total':2,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'q','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [], 'total': 0, 'loading': False, 'error': None, 'selected': [], 'has_next': False})

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 request ownership result violates the stipulated remote table page response admission contract.

Admit remote table pages only for the exact request/query/offset. Errors retain displayed rows, duplicate row IDs retain first placement and last payload, successful totals may shrink, loading and old errors clear, and only explicit server deletions prune cross-page selection.

split: open-access


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

N = 1
observations = []
def solve(state, response):
    out=dict(state)
    if response['request']!=state['request']: return out
    if False: return out
    if response['offset']!=state['offset']: return out
    if response.get('error') is not None:
        out.update(loading=False,error=response['error']); return out
    ids=[]; by={}
    for row in response['rows']:
        if row['id'] not in by: ids.append(row['id'])
        by[row['id']]=row
    out['rows']=[by[k] for k in ids]
    out['total']=response['total']
    out['loading']=False; out['error']=None
    out['has_next']=response['offset']+len(ids)<response['total']
    out['selected']=[k for k in state['selected'] if k not in response.get('deleted',[])]
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('fresh deduped page', solve({'request':2,'query':'q','offset':2,'rows':[{'id':'old'}],'total':20,'loading':True,'error':'old error','selected':['a','off','gone']}, {'request':2,'query':'q','offset':2,'rows':[{'id':'a','v':1},{'id':'b','v':1},{'id':'a','v':3}],'total':4,'deleted':['gone']}), {'request': 2, 'query': 'q', 'offset': 2, 'rows': [{'id': 'a', 'v': 3}, {'id': 'b', 'v': 1}], 'total': 4, 'loading': False, 'error': None, 'selected': ['a', 'off'], 'has_next': False})
    check('late request', solve({'request':2,'query':'q','offset':0,'rows':[],'total':0,'loading':True,'error':None,'selected':[]}, {'request':1,'query':'q','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [], 'total': 0, 'loading': True, 'error': None, 'selected': []})
    check('old query', solve({'request':2,'query':'q','offset':0,'rows':[],'total':0,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'old','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [], 'total': 0, 'loading': True, 'error': None, 'selected': []})
    check('old offset', solve({'request':2,'query':'q','offset':2,'rows':[],'total':0,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'q','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 2, 'rows': [], 'total': 0, 'loading': True, 'error': None, 'selected': []})
    check('error retains page', solve({'request':2,'query':'q','offset':0,'rows':[{'id':'old'}],'total':1,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'q','offset':0,'rows':[],'total':0,'error':'failed'}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [{'id': 'old'}], 'total': 1, 'loading': False, 'error': 'failed', 'selected': []})
    check('empty final page', solve({'request':2,'query':'q','offset':0,'rows':[],'total':2,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'q','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [], 'total': 0, 'loading': False, 'error': None, 'selected': [], 'has_next': False})

if N == 2:
    check('fresh deduped page', solve({'request':2,'query':'q','offset':2,'rows':[{'id':'old'}],'total':20,'loading':True,'error':'old error','selected':['a','off','gone']}, {'request':2,'query':'q','offset':2,'rows':[{'id':'a','v':1},{'id':'b','v':2},{'id':'a','v':3}],'total':4,'deleted':['gone']}), {'request': 2, 'query': 'q', 'offset': 2, 'rows': [{'id': 'a', 'v': 3}, {'id': 'b', 'v': 2}], 'total': 4, 'loading': False, 'error': None, 'selected': ['a', 'off'], 'has_next': False})
    check('late request', solve({'request':2,'query':'q','offset':0,'rows':[],'total':0,'loading':True,'error':None,'selected':[]}, {'request':1,'query':'q','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [], 'total': 0, 'loading': True, 'error': None, 'selected': []})
    check('old query', solve({'request':2,'query':'q','offset':0,'rows':[],'total':0,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'old','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [], 'total': 0, 'loading': True, 'error': None, 'selected': []})
    check('old offset', solve({'request':2,'query':'q','offset':2,'rows':[],'total':0,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'q','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 2, 'rows': [], 'total': 0, 'loading': True, 'error': None, 'selected': []})
    check('error retains page', solve({'request':2,'query':'q','offset':0,'rows':[{'id':'old'}],'total':1,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'q','offset':0,'rows':[],'total':0,'error':'failed'}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [{'id': 'old'}], 'total': 1, 'loading': False, 'error': 'failed', 'selected': []})
    check('empty final page', solve({'request':2,'query':'q','offset':0,'rows':[],'total':2,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'q','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [], 'total': 0, 'loading': False, 'error': None, 'selected': [], 'has_next': False})

if N == 3:
    check('fresh deduped page', solve({'request':2,'query':'q','offset':2,'rows':[{'id':'old'}],'total':20,'loading':True,'error':'old error','selected':['a','off','gone']}, {'request':2,'query':'q','offset':2,'rows':[{'id':'a','v':1},{'id':'b','v':3},{'id':'a','v':3}],'total':4,'deleted':['gone']}), {'request': 2, 'query': 'q', 'offset': 2, 'rows': [{'id': 'a', 'v': 3}, {'id': 'b', 'v': 3}], 'total': 4, 'loading': False, 'error': None, 'selected': ['a', 'off'], 'has_next': False})
    check('late request', solve({'request':2,'query':'q','offset':0,'rows':[],'total':0,'loading':True,'error':None,'selected':[]}, {'request':1,'query':'q','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [], 'total': 0, 'loading': True, 'error': None, 'selected': []})
    check('old query', solve({'request':2,'query':'q','offset':0,'rows':[],'total':0,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'old','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [], 'total': 0, 'loading': True, 'error': None, 'selected': []})
    check('old offset', solve({'request':2,'query':'q','offset':2,'rows':[],'total':0,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'q','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 2, 'rows': [], 'total': 0, 'loading': True, 'error': None, 'selected': []})
    check('error retains page', solve({'request':2,'query':'q','offset':0,'rows':[{'id':'old'}],'total':1,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'q','offset':0,'rows':[],'total':0,'error':'failed'}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [{'id': 'old'}], 'total': 1, 'loading': False, 'error': 'failed', 'selected': []})
    check('empty final page', solve({'request':2,'query':'q','offset':0,'rows':[],'total':2,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'q','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [], 'total': 0, 'loading': False, 'error': None, 'selected': [], 'has_next': False})

if N == 4:
    check('fresh deduped page', solve({'request':2,'query':'q','offset':2,'rows':[{'id':'old'}],'total':20,'loading':True,'error':'old error','selected':['a','off','gone']}, {'request':2,'query':'q','offset':2,'rows':[{'id':'a','v':1},{'id':'b','v':4},{'id':'a','v':3}],'total':4,'deleted':['gone']}), {'request': 2, 'query': 'q', 'offset': 2, 'rows': [{'id': 'a', 'v': 3}, {'id': 'b', 'v': 4}], 'total': 4, 'loading': False, 'error': None, 'selected': ['a', 'off'], 'has_next': False})
    check('late request', solve({'request':2,'query':'q','offset':0,'rows':[],'total':0,'loading':True,'error':None,'selected':[]}, {'request':1,'query':'q','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [], 'total': 0, 'loading': True, 'error': None, 'selected': []})
    check('old query', solve({'request':2,'query':'q','offset':0,'rows':[],'total':0,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'old','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [], 'total': 0, 'loading': True, 'error': None, 'selected': []})
    check('old offset', solve({'request':2,'query':'q','offset':2,'rows':[],'total':0,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'q','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 2, 'rows': [], 'total': 0, 'loading': True, 'error': None, 'selected': []})
    check('error retains page', solve({'request':2,'query':'q','offset':0,'rows':[{'id':'old'}],'total':1,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'q','offset':0,'rows':[],'total':0,'error':'failed'}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [{'id': 'old'}], 'total': 1, 'loading': False, 'error': 'failed', 'selected': []})
    check('empty final page', solve({'request':2,'query':'q','offset':0,'rows':[],'total':2,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'q','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [], 'total': 0, 'loading': False, 'error': None, 'selected': [], 'has_next': False})

if N == 5:
    check('fresh deduped page', solve({'request':2,'query':'q','offset':2,'rows':[{'id':'old'}],'total':20,'loading':True,'error':'old error','selected':['a','off','gone']}, {'request':2,'query':'q','offset':2,'rows':[{'id':'a','v':1},{'id':'b','v':5},{'id':'a','v':3}],'total':4,'deleted':['gone']}), {'request': 2, 'query': 'q', 'offset': 2, 'rows': [{'id': 'a', 'v': 3}, {'id': 'b', 'v': 5}], 'total': 4, 'loading': False, 'error': None, 'selected': ['a', 'off'], 'has_next': False})
    check('late request', solve({'request':2,'query':'q','offset':0,'rows':[],'total':0,'loading':True,'error':None,'selected':[]}, {'request':1,'query':'q','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [], 'total': 0, 'loading': True, 'error': None, 'selected': []})
    check('old query', solve({'request':2,'query':'q','offset':0,'rows':[],'total':0,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'old','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [], 'total': 0, 'loading': True, 'error': None, 'selected': []})
    check('old offset', solve({'request':2,'query':'q','offset':2,'rows':[],'total':0,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'q','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 2, 'rows': [], 'total': 0, 'loading': True, 'error': None, 'selected': []})
    check('error retains page', solve({'request':2,'query':'q','offset':0,'rows':[{'id':'old'}],'total':1,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'q','offset':0,'rows':[],'total':0,'error':'failed'}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [{'id': 'old'}], 'total': 1, 'loading': False, 'error': 'failed', 'selected': []})
    check('empty final page', solve({'request':2,'query':'q','offset':0,'rows':[],'total':2,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'q','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [], 'total': 0, 'loading': False, 'error': None, 'selected': [], 'has_next': False})

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(state, response):
    out=dict(state)
    if response['request']!=state['request']: return out
    if False if response['offset']==0 else response['query']!=state['query']: return out
    if response['offset']!=state['offset']: return out
    if response.get('error') is not None:
        out.update(loading=False,error=response['error']); return out
    ids=[]; by={}
    for row in response['rows']:
        if row['id'] not in by: ids.append(row['id'])
        by[row['id']]=row
    out['rows']=[by[k] for k in ids]
    out['total']=response['total']
    out['loading']=False; out['error']=None
    out['has_next']=response['offset']+len(ids)<response['total']
    out['selected']=[k for k in state['selected'] if k not in response.get('deleted',[])]
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('fresh deduped page', solve({'request':2,'query':'q','offset':2,'rows':[{'id':'old'}],'total':20,'loading':True,'error':'old error','selected':['a','off','gone']}, {'request':2,'query':'q','offset':2,'rows':[{'id':'a','v':1},{'id':'b','v':1},{'id':'a','v':3}],'total':4,'deleted':['gone']}), {'request': 2, 'query': 'q', 'offset': 2, 'rows': [{'id': 'a', 'v': 3}, {'id': 'b', 'v': 1}], 'total': 4, 'loading': False, 'error': None, 'selected': ['a', 'off'], 'has_next': False})
    check('late request', solve({'request':2,'query':'q','offset':0,'rows':[],'total':0,'loading':True,'error':None,'selected':[]}, {'request':1,'query':'q','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [], 'total': 0, 'loading': True, 'error': None, 'selected': []})
    check('old query', solve({'request':2,'query':'q','offset':0,'rows':[],'total':0,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'old','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [], 'total': 0, 'loading': True, 'error': None, 'selected': []})
    check('old offset', solve({'request':2,'query':'q','offset':2,'rows':[],'total':0,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'q','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 2, 'rows': [], 'total': 0, 'loading': True, 'error': None, 'selected': []})
    check('error retains page', solve({'request':2,'query':'q','offset':0,'rows':[{'id':'old'}],'total':1,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'q','offset':0,'rows':[],'total':0,'error':'failed'}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [{'id': 'old'}], 'total': 1, 'loading': False, 'error': 'failed', 'selected': []})
    check('empty final page', solve({'request':2,'query':'q','offset':0,'rows':[],'total':2,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'q','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [], 'total': 0, 'loading': False, 'error': None, 'selected': [], 'has_next': False})

if N == 2:
    check('fresh deduped page', solve({'request':2,'query':'q','offset':2,'rows':[{'id':'old'}],'total':20,'loading':True,'error':'old error','selected':['a','off','gone']}, {'request':2,'query':'q','offset':2,'rows':[{'id':'a','v':1},{'id':'b','v':2},{'id':'a','v':3}],'total':4,'deleted':['gone']}), {'request': 2, 'query': 'q', 'offset': 2, 'rows': [{'id': 'a', 'v': 3}, {'id': 'b', 'v': 2}], 'total': 4, 'loading': False, 'error': None, 'selected': ['a', 'off'], 'has_next': False})
    check('late request', solve({'request':2,'query':'q','offset':0,'rows':[],'total':0,'loading':True,'error':None,'selected':[]}, {'request':1,'query':'q','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [], 'total': 0, 'loading': True, 'error': None, 'selected': []})
    check('old query', solve({'request':2,'query':'q','offset':0,'rows':[],'total':0,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'old','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [], 'total': 0, 'loading': True, 'error': None, 'selected': []})
    check('old offset', solve({'request':2,'query':'q','offset':2,'rows':[],'total':0,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'q','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 2, 'rows': [], 'total': 0, 'loading': True, 'error': None, 'selected': []})
    check('error retains page', solve({'request':2,'query':'q','offset':0,'rows':[{'id':'old'}],'total':1,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'q','offset':0,'rows':[],'total':0,'error':'failed'}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [{'id': 'old'}], 'total': 1, 'loading': False, 'error': 'failed', 'selected': []})
    check('empty final page', solve({'request':2,'query':'q','offset':0,'rows':[],'total':2,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'q','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [], 'total': 0, 'loading': False, 'error': None, 'selected': [], 'has_next': False})

if N == 3:
    check('fresh deduped page', solve({'request':2,'query':'q','offset':2,'rows':[{'id':'old'}],'total':20,'loading':True,'error':'old error','selected':['a','off','gone']}, {'request':2,'query':'q','offset':2,'rows':[{'id':'a','v':1},{'id':'b','v':3},{'id':'a','v':3}],'total':4,'deleted':['gone']}), {'request': 2, 'query': 'q', 'offset': 2, 'rows': [{'id': 'a', 'v': 3}, {'id': 'b', 'v': 3}], 'total': 4, 'loading': False, 'error': None, 'selected': ['a', 'off'], 'has_next': False})
    check('late request', solve({'request':2,'query':'q','offset':0,'rows':[],'total':0,'loading':True,'error':None,'selected':[]}, {'request':1,'query':'q','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [], 'total': 0, 'loading': True, 'error': None, 'selected': []})
    check('old query', solve({'request':2,'query':'q','offset':0,'rows':[],'total':0,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'old','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [], 'total': 0, 'loading': True, 'error': None, 'selected': []})
    check('old offset', solve({'request':2,'query':'q','offset':2,'rows':[],'total':0,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'q','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 2, 'rows': [], 'total': 0, 'loading': True, 'error': None, 'selected': []})
    check('error retains page', solve({'request':2,'query':'q','offset':0,'rows':[{'id':'old'}],'total':1,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'q','offset':0,'rows':[],'total':0,'error':'failed'}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [{'id': 'old'}], 'total': 1, 'loading': False, 'error': 'failed', 'selected': []})
    check('empty final page', solve({'request':2,'query':'q','offset':0,'rows':[],'total':2,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'q','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [], 'total': 0, 'loading': False, 'error': None, 'selected': [], 'has_next': False})

if N == 4:
    check('fresh deduped page', solve({'request':2,'query':'q','offset':2,'rows':[{'id':'old'}],'total':20,'loading':True,'error':'old error','selected':['a','off','gone']}, {'request':2,'query':'q','offset':2,'rows':[{'id':'a','v':1},{'id':'b','v':4},{'id':'a','v':3}],'total':4,'deleted':['gone']}), {'request': 2, 'query': 'q', 'offset': 2, 'rows': [{'id': 'a', 'v': 3}, {'id': 'b', 'v': 4}], 'total': 4, 'loading': False, 'error': None, 'selected': ['a', 'off'], 'has_next': False})
    check('late request', solve({'request':2,'query':'q','offset':0,'rows':[],'total':0,'loading':True,'error':None,'selected':[]}, {'request':1,'query':'q','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [], 'total': 0, 'loading': True, 'error': None, 'selected': []})
    check('old query', solve({'request':2,'query':'q','offset':0,'rows':[],'total':0,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'old','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [], 'total': 0, 'loading': True, 'error': None, 'selected': []})
    check('old offset', solve({'request':2,'query':'q','offset':2,'rows':[],'total':0,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'q','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 2, 'rows': [], 'total': 0, 'loading': True, 'error': None, 'selected': []})
    check('error retains page', solve({'request':2,'query':'q','offset':0,'rows':[{'id':'old'}],'total':1,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'q','offset':0,'rows':[],'total':0,'error':'failed'}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [{'id': 'old'}], 'total': 1, 'loading': False, 'error': 'failed', 'selected': []})
    check('empty final page', solve({'request':2,'query':'q','offset':0,'rows':[],'total':2,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'q','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [], 'total': 0, 'loading': False, 'error': None, 'selected': [], 'has_next': False})

if N == 5:
    check('fresh deduped page', solve({'request':2,'query':'q','offset':2,'rows':[{'id':'old'}],'total':20,'loading':True,'error':'old error','selected':['a','off','gone']}, {'request':2,'query':'q','offset':2,'rows':[{'id':'a','v':1},{'id':'b','v':5},{'id':'a','v':3}],'total':4,'deleted':['gone']}), {'request': 2, 'query': 'q', 'offset': 2, 'rows': [{'id': 'a', 'v': 3}, {'id': 'b', 'v': 5}], 'total': 4, 'loading': False, 'error': None, 'selected': ['a', 'off'], 'has_next': False})
    check('late request', solve({'request':2,'query':'q','offset':0,'rows':[],'total':0,'loading':True,'error':None,'selected':[]}, {'request':1,'query':'q','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [], 'total': 0, 'loading': True, 'error': None, 'selected': []})
    check('old query', solve({'request':2,'query':'q','offset':0,'rows':[],'total':0,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'old','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [], 'total': 0, 'loading': True, 'error': None, 'selected': []})
    check('old offset', solve({'request':2,'query':'q','offset':2,'rows':[],'total':0,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'q','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 2, 'rows': [], 'total': 0, 'loading': True, 'error': None, 'selected': []})
    check('error retains page', solve({'request':2,'query':'q','offset':0,'rows':[{'id':'old'}],'total':1,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'q','offset':0,'rows':[],'total':0,'error':'failed'}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [{'id': 'old'}], 'total': 1, 'loading': False, 'error': 'failed', 'selected': []})
    check('empty final page', solve({'request':2,'query':'q','offset':0,'rows':[],'total':2,'loading':True,'error':None,'selected':[]}, {'request':2,'query':'q','offset':0,'rows':[],'total':0}), {'request': 2, 'query': 'q', 'offset': 0, 'rows': [], 'total': 0, 'loading': False, 'error': None, 'selected': [], 'has_next': False})

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 query ownership result violates the stipulated remote table page response admission contract.

Admit remote table pages only for the exact request/query/offset. Errors retain displayed rows, duplicate row IDs retain first placement and last payload, successful totals may shrink, loading and old errors clear, and only explicit server deletions prune cross-page selection.

split: open-access