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 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']=len(ids)
    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']=max(state['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 server total 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 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']=state['loading']; 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)

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(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']=state['error']
    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 page loading clear 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 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']=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 page next boundary 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 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 True]
    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 in ids]
    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 deleted selection prune 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