FAILURE MAP
← Case archive

FA-48776 / Delimited text / Open access

Chunk draining splits at the final newline instead of the first · case 01

A structured table violates the declared record or column contract.

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

ROOT CAUSE

Chunk draining splits at the final newline instead of the first.

VERIFIED REPAIR

Preserve the named invariant at the faulty decision: record,carry=carry.split('\n',1)

Unsuccessful approach: The alternate implementation still violates the same declared invariant: chunk draining splits at the final newline instead of the first.

Case contract

Consume arbitrary text chunks of an unquoted LF-delimited table. Complete records emit immediately into an output list; carry partial records across chunks. EOF emits a nonempty remaining fragment, but not a phantom row after final LF. Empty complete physical records are retained. Return comma-split rows.

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):
    rows=[]; carry=''
    for chunk in data:
        carry+=chunk
        while '\n' in carry:
            record,carry=carry.rsplit('\n',1)
            rows.append(record.split(','))
    if carry: rows.append(carry.split(','))
    return rows
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('split cell', solve(_vary(['a,', '@', '\nx,y\n'])), _vary([['a', '@'], ['x', 'y']]))
check('several per chunk', solve(_vary(['a,b\n@,z\n'])), _vary([['a', 'b'], ['@', 'z']]))
check('empty chunks', solve(_vary(['', '@', '', '\n', ''])), _vary([['@']]))
check('partial final', solve(_vary(['a,b\n@'])), _vary([['a', 'b'], ['@']]))
check('empty rows', solve(_vary(['\n\n'])), _vary([[''], ['']]))
check('empty input', solve(_vary([])), _vary([]))
check('no newline', solve(_vary(['@'])), _vary([['@']]))
check('split delimiter', solve(_vary(['a', '\n', 'b'])), _vary([['a'], ['b']]))
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
split cell[['a', 'cell\nx', 'y']][['a', 'cell'], ['x', 'y']]Failed
several per chunk[['a', 'b\ncell', 'z']][['a', 'b'], ['cell', 'z']]Failed
empty chunks[['cell']][['cell']]Passed
partial final[['a', 'b'], ['cell']][['a', 'b'], ['cell']]Passed
empty rows[['\n']][[''], ['']]Failed
empty input[][]Passed
no newline[['cell']][['cell']]Passed
split delimiter[['a'], ['b']][['a'], ['b']]Passed

SHA-256 / 0c14bbb32c34c10cd11127e1b76c1c46bfe3767671ab287b775219f5584bb7d2

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):
    rows=[]; carry=''
    for chunk in data:
        carry+=chunk
        while '\n' in carry:
            record,carry=carry.split('\n',1)[::-1]
            rows.append(record.split(','))
    if carry: rows.append(carry.split(','))
    return rows
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('split cell', solve(_vary(['a,', '@', '\nx,y\n'])), _vary([['a', '@'], ['x', 'y']]))
check('several per chunk', solve(_vary(['a,b\n@,z\n'])), _vary([['a', 'b'], ['@', 'z']]))
check('empty chunks', solve(_vary(['', '@', '', '\n', ''])), _vary([['@']]))
check('partial final', solve(_vary(['a,b\n@'])), _vary([['a', 'b'], ['@']]))
check('empty rows', solve(_vary(['\n\n'])), _vary([[''], ['']]))
check('empty input', solve(_vary([])), _vary([]))
check('no newline', solve(_vary(['@'])), _vary([['@']]))
check('split delimiter', solve(_vary(['a', '\n', 'b'])), _vary([['a'], ['b']]))
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
split cell[['x', 'y\n'], ['a', 'cell']][['a', 'cell'], ['x', 'y']]Failed
several per chunk[['cell', 'z\n'], ['a', 'b']][['a', 'b'], ['cell', 'z']]Failed
empty chunks[[''], ['cell']][['cell']]Failed
partial final[['cell'], ['a', 'b']][['a', 'b'], ['cell']]Failed
empty rows[['\n']][[''], ['']]Failed
empty input[][]Passed
no newline[['cell']][['cell']]Passed
split delimiter[[''], ['ab']][['a'], ['b']]Failed

SHA-256 / e6c76daa0c70738ad9e0c8affff1c24d4c2441b1b2482842fb1c081fb2ceb2d8

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):
    rows=[]; carry=''
    for chunk in data:
        carry+=chunk
        while '\n' in carry:
            record,carry=carry.split('\n',1)
            rows.append(record.split(','))
    if carry: rows.append(carry.split(','))
    return rows
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('split cell', solve(_vary(['a,', '@', '\nx,y\n'])), _vary([['a', '@'], ['x', 'y']]))
check('several per chunk', solve(_vary(['a,b\n@,z\n'])), _vary([['a', 'b'], ['@', 'z']]))
check('empty chunks', solve(_vary(['', '@', '', '\n', ''])), _vary([['@']]))
check('partial final', solve(_vary(['a,b\n@'])), _vary([['a', 'b'], ['@']]))
check('empty rows', solve(_vary(['\n\n'])), _vary([[''], ['']]))
check('empty input', solve(_vary([])), _vary([]))
check('no newline', solve(_vary(['@'])), _vary([['@']]))
check('split delimiter', solve(_vary(['a', '\n', 'b'])), _vary([['a'], ['b']]))
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
split cell[['a', 'cell'], ['x', 'y']][['a', 'cell'], ['x', 'y']]Passed
several per chunk[['a', 'b'], ['cell', 'z']][['a', 'b'], ['cell', 'z']]Passed
empty chunks[['cell']][['cell']]Passed
partial final[['a', 'b'], ['cell']][['a', 'b'], ['cell']]Passed
empty rows[[''], ['']][[''], ['']]Passed
empty input[][]Passed
no newline[['cell']][['cell']]Passed
split delimiter[['a'], ['b']][['a'], ['b']]Passed

SHA-256 / 85410585cfb2fad32494d3b27709ac40176364ac6f648ab54678ed08bd179c6b

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

Case digest / b1402706262d606e07302233e673d4eebbf5ee802e797d9ec31babb54f802951