FAILURE MAP
← Case archive

FA-22156 / Autocomplete interactions / Open access

Completion replacement spans: caret uses replaced token length instead of inserted length · case 01

The caret completion transition produces an incorrect observable state.

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

ROOT CAUSE

At replacement-range/caret, the implementation evaluates `d['end']` instead of preserving the specified completion transition.

VERIFIED REPAIR

Implement the caret contract using `d['start']+len(d['insert'])`.

Unsuccessful approach: The attempted repair uses `len(d['insert'])`, which still violates a normal or boundary completion fixture.

Case contract

Suggestion insertion replaces the half-open token span [start,end), preserving surrounding text. Caret moves after inserted text, explicit selection takes precedence over token fallback, and a stale text epoch rejects replacement. These spans count Python code points, not browser UTF-16 units.

Why this case matters

Autocomplete couples draft text, suggestion identity and asynchronous presentation; this bounded lifecycle model isolates one observable interaction defect.

1 / The failure

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

N = 1
observations = []
def solve(event, d):
    if event == 'replace': return d['text'][:d['start']]+d['insert']+d['text'][d['end']:]
    if event == 'prefix': return d['text'][:d['start']]
    if event == 'suffix': return d['text'][d['end']:]
    if event == 'caret': return d['end']
    if event == 'selection': return d['selection'] if d['selection'][0]!=d['selection'][1] else [d['start'],d['end']]
    if event == 'stale-span': return d['span_epoch']==d['epoch']
    if event == 'collapse': return [d['start']+len(d['insert'])]*2
    if event == 'delimiter': return d['insert']+d['suffix']
    if event == 'delta': return len(d['insert'])-(d['end']-d['start'])
    if event == 'capture': return d['text'][d['start']:d['end']]
    return {'unchanged': True}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
normal = {'text':'red pea blue','start':4,'end':7,'insert':'pear','caret':6,'selection':[5,7],'epoch':N,'span_epoch':N-1,'suffix':' '}
boundary = {'text':'','start':0,'end':0,'insert':'x','caret':0,'selection':[0,0],'epoch':N,'span_epoch':N,'suffix':''}
check('normal replace', solve('replace', normal), 'red pear blue')
check('boundary replace', solve('replace', boundary), 'x')
check('normal prefix', solve('prefix', normal), 'red ')
check('boundary prefix', solve('prefix', boundary), '')
check('normal suffix', solve('suffix', normal), ' blue')
check('boundary suffix', solve('suffix', boundary), '')
check('normal caret', solve('caret', normal), 8)
check('boundary caret', solve('caret', boundary), 1)
check('normal selection', solve('selection', normal), [5,7])
check('boundary selection', solve('selection', boundary), [0,0])
check('normal stale-span', solve('stale-span', normal), False)
check('boundary stale-span', solve('stale-span', boundary), True)
check('normal collapse', solve('collapse', normal), [8,8])
check('boundary collapse', solve('collapse', boundary), [1,1])
check('normal delimiter', solve('delimiter', normal), 'pear ')
check('boundary delimiter', solve('delimiter', boundary), 'x')
check('normal delta', solve('delta', normal), 1)
check('boundary delta', solve('delta', boundary), 1)
check('normal capture', solve('capture', normal), 'pea')
check('boundary capture', solve('capture', boundary), '')
variant = dict(normal, **{'text':'x'*N,'start':0,'end':N})
check('variant query or selection payload', solve('capture', variant), 'x'*N)
check('unknown completion event', solve('unrecognized', normal), {'unchanged': True})
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
normal replacered pear bluered pear bluePassed
boundary replacexxPassed
normal prefixred red Passed
boundary prefixPassed
normal suffix blue bluePassed
boundary suffixPassed
normal caret78Failed
boundary caret01Failed
normal selection[5, 7][5, 7]Passed
boundary selection[0, 0][0, 0]Passed
normal stale-spanFalseFalsePassed
boundary stale-spanTrueTruePassed
normal collapse[8, 8][8, 8]Passed
boundary collapse[1, 1][1, 1]Passed
normal delimiterpear pear Passed
boundary delimiterxxPassed
normal delta11Passed
boundary delta11Passed
normal capturepeapeaPassed
boundary capturePassed
variant query or selection payloadxxPassed
unknown completion event{'unchanged': True}{'unchanged': True}Passed

SHA-256 / 8672cdcee5551f6f6cfb237493ed69f37197b5816d0d8450cc257e8931af021e

2 / The unsuccessful fix

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

N = 1
observations = []
def solve(event, d):
    if event == 'replace': return d['text'][:d['start']]+d['insert']+d['text'][d['end']:]
    if event == 'prefix': return d['text'][:d['start']]
    if event == 'suffix': return d['text'][d['end']:]
    if event == 'caret': return len(d['insert'])
    if event == 'selection': return d['selection'] if d['selection'][0]!=d['selection'][1] else [d['start'],d['end']]
    if event == 'stale-span': return d['span_epoch']==d['epoch']
    if event == 'collapse': return [d['start']+len(d['insert'])]*2
    if event == 'delimiter': return d['insert']+d['suffix']
    if event == 'delta': return len(d['insert'])-(d['end']-d['start'])
    if event == 'capture': return d['text'][d['start']:d['end']]
    return {'unchanged': True}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
normal = {'text':'red pea blue','start':4,'end':7,'insert':'pear','caret':6,'selection':[5,7],'epoch':N,'span_epoch':N-1,'suffix':' '}
boundary = {'text':'','start':0,'end':0,'insert':'x','caret':0,'selection':[0,0],'epoch':N,'span_epoch':N,'suffix':''}
check('normal replace', solve('replace', normal), 'red pear blue')
check('boundary replace', solve('replace', boundary), 'x')
check('normal prefix', solve('prefix', normal), 'red ')
check('boundary prefix', solve('prefix', boundary), '')
check('normal suffix', solve('suffix', normal), ' blue')
check('boundary suffix', solve('suffix', boundary), '')
check('normal caret', solve('caret', normal), 8)
check('boundary caret', solve('caret', boundary), 1)
check('normal selection', solve('selection', normal), [5,7])
check('boundary selection', solve('selection', boundary), [0,0])
check('normal stale-span', solve('stale-span', normal), False)
check('boundary stale-span', solve('stale-span', boundary), True)
check('normal collapse', solve('collapse', normal), [8,8])
check('boundary collapse', solve('collapse', boundary), [1,1])
check('normal delimiter', solve('delimiter', normal), 'pear ')
check('boundary delimiter', solve('delimiter', boundary), 'x')
check('normal delta', solve('delta', normal), 1)
check('boundary delta', solve('delta', boundary), 1)
check('normal capture', solve('capture', normal), 'pea')
check('boundary capture', solve('capture', boundary), '')
variant = dict(normal, **{'text':'x'*N,'start':0,'end':N})
check('variant query or selection payload', solve('capture', variant), 'x'*N)
check('unknown completion event', solve('unrecognized', normal), {'unchanged': True})
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
normal replacered pear bluered pear bluePassed
boundary replacexxPassed
normal prefixred red Passed
boundary prefixPassed
normal suffix blue bluePassed
boundary suffixPassed
normal caret48Failed
boundary caret11Passed
normal selection[5, 7][5, 7]Passed
boundary selection[0, 0][0, 0]Passed
normal stale-spanFalseFalsePassed
boundary stale-spanTrueTruePassed
normal collapse[8, 8][8, 8]Passed
boundary collapse[1, 1][1, 1]Passed
normal delimiterpear pear Passed
boundary delimiterxxPassed
normal delta11Passed
boundary delta11Passed
normal capturepeapeaPassed
boundary capturePassed
variant query or selection payloadxxPassed
unknown completion event{'unchanged': True}{'unchanged': True}Passed

SHA-256 / 7c4097be7dff6ab7fcd8a62e44a44500008f76070f9e853672b7643fd82e1781

3 / The verified repair

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

N = 1
observations = []
def solve(event, d):
    if event == 'replace': return d['text'][:d['start']]+d['insert']+d['text'][d['end']:]
    if event == 'prefix': return d['text'][:d['start']]
    if event == 'suffix': return d['text'][d['end']:]
    if event == 'caret': return d['start']+len(d['insert'])
    if event == 'selection': return d['selection'] if d['selection'][0]!=d['selection'][1] else [d['start'],d['end']]
    if event == 'stale-span': return d['span_epoch']==d['epoch']
    if event == 'collapse': return [d['start']+len(d['insert'])]*2
    if event == 'delimiter': return d['insert']+d['suffix']
    if event == 'delta': return len(d['insert'])-(d['end']-d['start'])
    if event == 'capture': return d['text'][d['start']:d['end']]
    return {'unchanged': True}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
normal = {'text':'red pea blue','start':4,'end':7,'insert':'pear','caret':6,'selection':[5,7],'epoch':N,'span_epoch':N-1,'suffix':' '}
boundary = {'text':'','start':0,'end':0,'insert':'x','caret':0,'selection':[0,0],'epoch':N,'span_epoch':N,'suffix':''}
check('normal replace', solve('replace', normal), 'red pear blue')
check('boundary replace', solve('replace', boundary), 'x')
check('normal prefix', solve('prefix', normal), 'red ')
check('boundary prefix', solve('prefix', boundary), '')
check('normal suffix', solve('suffix', normal), ' blue')
check('boundary suffix', solve('suffix', boundary), '')
check('normal caret', solve('caret', normal), 8)
check('boundary caret', solve('caret', boundary), 1)
check('normal selection', solve('selection', normal), [5,7])
check('boundary selection', solve('selection', boundary), [0,0])
check('normal stale-span', solve('stale-span', normal), False)
check('boundary stale-span', solve('stale-span', boundary), True)
check('normal collapse', solve('collapse', normal), [8,8])
check('boundary collapse', solve('collapse', boundary), [1,1])
check('normal delimiter', solve('delimiter', normal), 'pear ')
check('boundary delimiter', solve('delimiter', boundary), 'x')
check('normal delta', solve('delta', normal), 1)
check('boundary delta', solve('delta', boundary), 1)
check('normal capture', solve('capture', normal), 'pea')
check('boundary capture', solve('capture', boundary), '')
variant = dict(normal, **{'text':'x'*N,'start':0,'end':N})
check('variant query or selection payload', solve('capture', variant), 'x'*N)
check('unknown completion event', solve('unrecognized', normal), {'unchanged': True})
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
normal replacered pear bluered pear bluePassed
boundary replacexxPassed
normal prefixred red Passed
boundary prefixPassed
normal suffix blue bluePassed
boundary suffixPassed
normal caret88Passed
boundary caret11Passed
normal selection[5, 7][5, 7]Passed
boundary selection[0, 0][0, 0]Passed
normal stale-spanFalseFalsePassed
boundary stale-spanTrueTruePassed
normal collapse[8, 8][8, 8]Passed
boundary collapse[1, 1][1, 1]Passed
normal delimiterpear pear Passed
boundary delimiterxxPassed
normal delta11Passed
boundary delta11Passed
normal capturepeapeaPassed
boundary capturePassed
variant query or selection payloadxxPassed
unknown completion event{'unchanged': True}{'unchanged': True}Passed

SHA-256 / a486206721239e530d05ea6db2f429ed4e23ce9930d42829b0c2387ec99508ed

Verification & scope

Stipulated deterministic widget transition model; inputs are validated snapshots. It does not model browser event dispatch, network transport, or linguistic standards. This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.

Observations recorded using Python 3.12.14 at 2026-09-29T14:40:35.727280+00:00.

Case digest / cb6be5c86eb02f641be1d75671e7f3558797f35ce44c0d1ed184b2c9ebc8b27b