FAILURE MAP
← Case archive

FA-48231 / Delimited text / Open access

An empty append operation writes a header or terminator · case 01

A structured table violates the declared record or column contract.

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

ROOT CAUSE

An empty append operation writes a header or terminator.

VERIFIED REPAIR

Preserve the named invariant at the faulty decision: if not data['rows']: return data['existing']

Unsuccessful approach: The alternate implementation still violates the same declared invariant: an empty append operation writes a header or terminator.

Case contract

Append comma rows to existing serialized text. Existing text is either empty or ends in a complete physical record, optionally lacking its final LF. On an empty file emit the supplied header once, followed by new rows. For a nonempty unterminated tail insert exactly one LF before new rows. With no new rows return existing text unchanged.

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):
    if False: return data['existing']
    text=data['existing']
    if not text: text=','.join(data['header']) + '\n'
    elif not text.endswith('\n'): text+='\n'
    for row in data['rows']:
        text+=','.join(row)+'\n'
    return text
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('new', solve(_vary({'existing': '', 'header': ['a', 'b'], 'rows': [['@', 'x']]})), _vary('a,b\n@,x\n'))
check('terminated', solve(_vary({'existing': 'a,b\nq,z\n', 'header': ['a', 'b'], 'rows': [['@', 'x']]})), _vary('a,b\nq,z\n@,x\n'))
check('unterminated', solve(_vary({'existing': 'a,b\nq,z', 'header': ['a', 'b'], 'rows': [['@', 'x']]})), _vary('a,b\nq,z\n@,x\n'))
check('no new', solve(_vary({'existing': 'a,b', 'header': ['a', 'b'], 'rows': []})), _vary('a,b'))
check('empty untouched', solve(_vary({'existing': '', 'header': ['a', 'b'], 'rows': []})), _vary(''))
check('two appended', solve(_vary({'existing': 'a\n', 'header': ['a'], 'rows': [['@'], ['z']]})), _vary('a\n@\nz\n'))
check('empty cells', solve(_vary({'existing': '', 'header': ['a', 'b'], 'rows': [['', '']]})), _vary('a,b\n,\n'))
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
newa,b cell,x a,b cell,x Passed
terminateda,b q,z cell,x a,b q,z cell,x Passed
unterminateda,b q,z cell,x a,b q,z cell,x Passed
no newa,b a,bFailed
empty untoucheda,b Failed
two appendeda cell z a cell z Passed
empty cellsa,b , a,b , Passed

SHA-256 / 2bb0778a4e540de0e598c3c38078033575dcd17af7f3c0efff6bf3fefccc50ce

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):
    if not data['rows']: return data['existing']+'\n'
    text=data['existing']
    if not text: text=','.join(data['header']) + '\n'
    elif not text.endswith('\n'): text+='\n'
    for row in data['rows']:
        text+=','.join(row)+'\n'
    return text
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('new', solve(_vary({'existing': '', 'header': ['a', 'b'], 'rows': [['@', 'x']]})), _vary('a,b\n@,x\n'))
check('terminated', solve(_vary({'existing': 'a,b\nq,z\n', 'header': ['a', 'b'], 'rows': [['@', 'x']]})), _vary('a,b\nq,z\n@,x\n'))
check('unterminated', solve(_vary({'existing': 'a,b\nq,z', 'header': ['a', 'b'], 'rows': [['@', 'x']]})), _vary('a,b\nq,z\n@,x\n'))
check('no new', solve(_vary({'existing': 'a,b', 'header': ['a', 'b'], 'rows': []})), _vary('a,b'))
check('empty untouched', solve(_vary({'existing': '', 'header': ['a', 'b'], 'rows': []})), _vary(''))
check('two appended', solve(_vary({'existing': 'a\n', 'header': ['a'], 'rows': [['@'], ['z']]})), _vary('a\n@\nz\n'))
check('empty cells', solve(_vary({'existing': '', 'header': ['a', 'b'], 'rows': [['', '']]})), _vary('a,b\n,\n'))
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
newa,b cell,x a,b cell,x Passed
terminateda,b q,z cell,x a,b q,z cell,x Passed
unterminateda,b q,z cell,x a,b q,z cell,x Passed
no newa,b a,bFailed
empty untouched Failed
two appendeda cell z a cell z Passed
empty cellsa,b , a,b , Passed

SHA-256 / 5d710c347c410dc764a8d07b8a44a54fbe5c6267ec8b60aea3b38bf86597e8ac

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):
    if not data['rows']: return data['existing']
    text=data['existing']
    if not text: text=','.join(data['header']) + '\n'
    elif not text.endswith('\n'): text+='\n'
    for row in data['rows']:
        text+=','.join(row)+'\n'
    return text
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('new', solve(_vary({'existing': '', 'header': ['a', 'b'], 'rows': [['@', 'x']]})), _vary('a,b\n@,x\n'))
check('terminated', solve(_vary({'existing': 'a,b\nq,z\n', 'header': ['a', 'b'], 'rows': [['@', 'x']]})), _vary('a,b\nq,z\n@,x\n'))
check('unterminated', solve(_vary({'existing': 'a,b\nq,z', 'header': ['a', 'b'], 'rows': [['@', 'x']]})), _vary('a,b\nq,z\n@,x\n'))
check('no new', solve(_vary({'existing': 'a,b', 'header': ['a', 'b'], 'rows': []})), _vary('a,b'))
check('empty untouched', solve(_vary({'existing': '', 'header': ['a', 'b'], 'rows': []})), _vary(''))
check('two appended', solve(_vary({'existing': 'a\n', 'header': ['a'], 'rows': [['@'], ['z']]})), _vary('a\n@\nz\n'))
check('empty cells', solve(_vary({'existing': '', 'header': ['a', 'b'], 'rows': [['', '']]})), _vary('a,b\n,\n'))
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
newa,b cell,x a,b cell,x Passed
terminateda,b q,z cell,x a,b q,z cell,x Passed
unterminateda,b q,z cell,x a,b q,z cell,x Passed
no newa,ba,bPassed
empty untouchedPassed
two appendeda cell z a cell z Passed
empty cellsa,b , a,b , Passed

SHA-256 / 4f9d1f290e925b7085db66b8d3a79f9cd9b4bcd0eae31270d055d9e2f5fa9010

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

Case digest / e3c526fde6b859869d776e2123197d28e184fe3655189ecb6ed0ccd1b88c7742