FA-48221 / Delimited text / Open access
An unterminated existing row merges with the first appended row · case 01
A structured table violates the declared record or column contract.
ROOT CAUSE
An unterminated existing row merges with the first appended row.
VERIFIED REPAIR
Preserve the named invariant at the faulty decision: elif not text.endswith('\n'): text+='\n'
Unsuccessful approach: The alternate implementation still violates the same declared invariant: an unterminated existing row merges with the first appended row.
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 not data['rows']: return data['existing']
text=data['existing']
if not text: text=','.join(data['header']) + '\n'
elif False: 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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| new | a,b
cell,x
| a,b
cell,x
| Passed |
| terminated | a,b
q,z
cell,x
| a,b
q,z
cell,x
| Passed |
| unterminated | a,b
q,zcell,x
| a,b
q,z
cell,x
| Failed |
| no new | a,b | a,b | Passed |
| empty untouched | | | Passed |
| two appended | a
cell
z
| a
cell
z
| Passed |
| empty cells | a,b
,
| a,b
,
| Passed |
SHA-256 / 4846e2e3fbb952a3c5a0233adf046deb4a003ac228d81ed33789d80e5892f03d
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']
text=data['existing']
if not text: text=','.join(data['header']) + '\n'
elif not text.endswith('\n'): text+=','
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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| new | a,b
cell,x
| a,b
cell,x
| Passed |
| terminated | a,b
q,z
cell,x
| a,b
q,z
cell,x
| Passed |
| unterminated | a,b
q,z,cell,x
| a,b
q,z
cell,x
| Failed |
| no new | a,b | a,b | Passed |
| empty untouched | | | Passed |
| two appended | a
cell
z
| a
cell
z
| Passed |
| empty cells | a,b
,
| a,b
,
| Passed |
SHA-256 / bca3a5f8b6ac6b892f2d28723e1ec921d1a7ea8aab892153bdc50f18c067fa73
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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| new | a,b
cell,x
| a,b
cell,x
| Passed |
| terminated | a,b
q,z
cell,x
| a,b
q,z
cell,x
| Passed |
| unterminated | a,b
q,z
cell,x
| a,b
q,z
cell,x
| Passed |
| no new | a,b | a,b | Passed |
| empty untouched | | | Passed |
| two appended | a
cell
z
| a
cell
z
| Passed |
| empty cells | a,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.789005+00:00.
Case digest / 0f29c903adb04e2f777e001ab1073ecdb71c989c8589fc2e54219597edf0b041