FAILURE MAP
← Case archive

FA-22166 / Autocomplete interactions / Open access

Completion replacement spans: a token span from an earlier edit is still applied · case 01

The stale-span completion transition produces an incorrect observable state.

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

ROOT CAUSE

At replacement-range/stale-span, the implementation evaluates `d['span_epoch']<=d['epoch']` instead of preserving the specified completion transition.

THE FAILURE

At replacement-range/stale-span, the implementation evaluates `d['span_epoch']<=d['epoch']` instead of preserving the specified completion transition.

Unsuccessful approach: The attempted repair uses `d['span_epoch']<d['epoch']`, 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['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-spanTrueFalseFailed
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 / 8bf0e177faa1f0a2a4f58d3144b9b693fb54b41fb36eb2cd5c90e43c96f21c89

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 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-spanTrueFalseFailed
boundary stale-spanFalseTrueFailed
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 / 0e8fed134f8c4aa12370cf4b91309549ab82ae3c81d78c74369f93c76befd307

HELD IN THE MEMBER ARCHIVE

The verified repair and its recorded checks are member-only.

This mechanism has 22 recorded checks per implementation. The open-access tier publishes the failure and the unsuccessful fix; the repaired source that passes every check, and the observations that prove it, are available to members.

Every case sharing this mechanism uses the same contract and the same repair, so this one record is held back for all of them.

Member access is invitation-based. Sign in with your invited account to inspect the repair.

Sign in to the archive ↗

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

Case digest / 223313e5caee31d8bc44d421e9e035951dca75b5c0ffe7b3ea36b1e7f634437e