FAILURE MAP
← Case archive

FA-48741 / Delimited text / Open access

Earlier cell edits invalidate offsets used by later edits · case 01

A structured table violates the declared record or column contract.

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

ROOT CAUSE

Earlier cell edits invalidate offsets used by later edits.

VERIFIED REPAIR

Preserve the named invariant at the faulty decision: sorted(patches,reverse=True)

Unsuccessful approach: The alternate implementation still violates the same declared invariant: earlier cell edits invalidate offsets used by later edits.

Case contract

Apply cell text edits to an unquoted comma row without changing unedited spelling. Edits are [zero-based cell index,replacement text], unique indexes only; replacements cannot contain comma or newline. Compute all source spans before editing and apply from right to left. Out-of-range indexes reject.

Why this case matters

Delimited interchange needs explicit framing, schema and field semantics at ingestion and emission boundaries.

1 / The failure

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
def _vary(value):
    if value == '@END': return 3 + 4*N
    if isinstance(value, str): return value.replace('@', 'cell' * N)
    if isinstance(value, list): return [_vary(x) for x in value]
    if isinstance(value, dict): return {_vary(k): _vary(v) for k,v in value.items()}
    return value
N = 1
observations = []
def solve(data):
    text=data['row']; starts=[0]+[i+1 for i,ch in enumerate(text) if ch==',']
    ends=[i for i,ch in enumerate(text) if ch==',']+[len(text)]
    seen=set(); patches=[]
    for index,value in data['edits']:
        if not 0<=index<len(starts) or index in seen: return None
        if any(ch in value for ch in ',\r\n'): return None
        seen.add(index); patches.append((starts[index],ends[index],value))
    for start,end,value in sorted(patches):
        text=text[:start]+value+text[end:]
    return text
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('vary lengths', solve(_vary({'row': 'a,bbb,c', 'edits': [[0, '@long'], [2, 'z']]})), _vary('@long,bbb,z'))
check('empty field', solve(_vary({'row': 'a,,b', 'edits': [[1, '@']]})), _vary('a,@,b'))
check('empty replacement', solve(_vary({'row': 'a,b,c', 'edits': [[1, '']]})), _vary('a,,c'))
check('duplicate index', solve(_vary({'row': 'a,b', 'edits': [[0, 'x'], [0, 'y']]})), _vary(None))
check('invalid replacement', solve(_vary({'row': 'a,b', 'edits': [[1, 'x,y']]})), _vary(None))
check('out of range', solve(_vary({'row': 'a,b', 'edits': [[2, 'x']]})), _vary(None))
check('preserve spaces', solve(_vary({'row': ' a , b ', 'edits': [[1, '@']]})), _vary(' a ,@'))
check('unicode', solve(_vary({'row': 'é,😀,x', 'edits': [[1, '@']]})), _vary('é,@,x'))
check('no edits', solve(_vary({'row': '@,x', 'edits': []})), _vary('@,x'))
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
vary lengthscelllozg,bbb,ccelllong,bbb,zFailed
empty fielda,cell,ba,cell,bPassed
empty replacementa,,ca,,cPassed
duplicate indexNoneNonePassed
invalid replacementNoneNonePassed
out of rangeNoneNonePassed
preserve spaces a ,cell a ,cellPassed
unicodeé,cell,xé,cell,xPassed
no editscell,xcell,xPassed

SHA-256 / 918c7440d30552585ec60bfafc767db0cd10690b12d5a4325ff044d7d6cbe036

2 / The unsuccessful fix

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
def _vary(value):
    if value == '@END': return 3 + 4*N
    if isinstance(value, str): return value.replace('@', 'cell' * N)
    if isinstance(value, list): return [_vary(x) for x in value]
    if isinstance(value, dict): return {_vary(k): _vary(v) for k,v in value.items()}
    return value
N = 1
observations = []
def solve(data):
    text=data['row']; starts=[0]+[i+1 for i,ch in enumerate(text) if ch==',']
    ends=[i for i,ch in enumerate(text) if ch==',']+[len(text)]
    seen=set(); patches=[]
    for index,value in data['edits']:
        if not 0<=index<len(starts) or index in seen: return None
        if any(ch in value for ch in ',\r\n'): return None
        seen.add(index); patches.append((starts[index],ends[index],value))
    for start,end,value in patches:
        text=text[:start]+value+text[end:]
    return text
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('vary lengths', solve(_vary({'row': 'a,bbb,c', 'edits': [[0, '@long'], [2, 'z']]})), _vary('@long,bbb,z'))
check('empty field', solve(_vary({'row': 'a,,b', 'edits': [[1, '@']]})), _vary('a,@,b'))
check('empty replacement', solve(_vary({'row': 'a,b,c', 'edits': [[1, '']]})), _vary('a,,c'))
check('duplicate index', solve(_vary({'row': 'a,b', 'edits': [[0, 'x'], [0, 'y']]})), _vary(None))
check('invalid replacement', solve(_vary({'row': 'a,b', 'edits': [[1, 'x,y']]})), _vary(None))
check('out of range', solve(_vary({'row': 'a,b', 'edits': [[2, 'x']]})), _vary(None))
check('preserve spaces', solve(_vary({'row': ' a , b ', 'edits': [[1, '@']]})), _vary(' a ,@'))
check('unicode', solve(_vary({'row': 'é,😀,x', 'edits': [[1, '@']]})), _vary('é,@,x'))
check('no edits', solve(_vary({'row': '@,x', 'edits': []})), _vary('@,x'))
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
vary lengthscelllozg,bbb,ccelllong,bbb,zFailed
empty fielda,cell,ba,cell,bPassed
empty replacementa,,ca,,cPassed
duplicate indexNoneNonePassed
invalid replacementNoneNonePassed
out of rangeNoneNonePassed
preserve spaces a ,cell a ,cellPassed
unicodeé,cell,xé,cell,xPassed
no editscell,xcell,xPassed

SHA-256 / b6beb18aeacf54339f12fb565e38740563cc16eb5faeb9f82fbc50f22869ce77

3 / The verified repair

Exit 0
"""Failure Map reference implementation. Python standard library only."""
import json
def _vary(value):
    if value == '@END': return 3 + 4*N
    if isinstance(value, str): return value.replace('@', 'cell' * N)
    if isinstance(value, list): return [_vary(x) for x in value]
    if isinstance(value, dict): return {_vary(k): _vary(v) for k,v in value.items()}
    return value
N = 1
observations = []
def solve(data):
    text=data['row']; starts=[0]+[i+1 for i,ch in enumerate(text) if ch==',']
    ends=[i for i,ch in enumerate(text) if ch==',']+[len(text)]
    seen=set(); patches=[]
    for index,value in data['edits']:
        if not 0<=index<len(starts) or index in seen: return None
        if any(ch in value for ch in ',\r\n'): return None
        seen.add(index); patches.append((starts[index],ends[index],value))
    for start,end,value in sorted(patches,reverse=True):
        text=text[:start]+value+text[end:]
    return text
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('vary lengths', solve(_vary({'row': 'a,bbb,c', 'edits': [[0, '@long'], [2, 'z']]})), _vary('@long,bbb,z'))
check('empty field', solve(_vary({'row': 'a,,b', 'edits': [[1, '@']]})), _vary('a,@,b'))
check('empty replacement', solve(_vary({'row': 'a,b,c', 'edits': [[1, '']]})), _vary('a,,c'))
check('duplicate index', solve(_vary({'row': 'a,b', 'edits': [[0, 'x'], [0, 'y']]})), _vary(None))
check('invalid replacement', solve(_vary({'row': 'a,b', 'edits': [[1, 'x,y']]})), _vary(None))
check('out of range', solve(_vary({'row': 'a,b', 'edits': [[2, 'x']]})), _vary(None))
check('preserve spaces', solve(_vary({'row': ' a , b ', 'edits': [[1, '@']]})), _vary(' a ,@'))
check('unicode', solve(_vary({'row': 'é,😀,x', 'edits': [[1, '@']]})), _vary('é,@,x'))
check('no edits', solve(_vary({'row': '@,x', 'edits': []})), _vary('@,x'))
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
vary lengthscelllong,bbb,zcelllong,bbb,zPassed
empty fielda,cell,ba,cell,bPassed
empty replacementa,,ca,,cPassed
duplicate indexNoneNonePassed
invalid replacementNoneNonePassed
out of rangeNoneNonePassed
preserve spaces a ,cell a ,cellPassed
unicodeé,cell,xé,cell,xPassed
no editscell,xcell,xPassed

SHA-256 / e23f84ea66fae053bc4c869e52195c78fb7a7d544cd7a5a8ba18dd18fc67f595

Verification & scope

Deterministic bounded in-memory model. No claim of complete CSV or external format conformance. 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:44:53.432500+00:00.

Case digest / aa10be273e90c67c3ab48cc62e35a5d25846cd81d02b691fd8f3a7d1b26c72c3