FAILURE MAP
← Case archive

FA-47541 / Delimited text / Open access

Blank section closure leaves the old table active · 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

Blank-line closure is ignored by the section cursor.

VERIFIED REPAIR

Preserve the named invariant at the faulty decision: current = None

Unsuccessful approach: Reloading the last section still assigns orphan records to a closed table.

Case contract

Read a bounded sectioned TSV stream: @name starts a new table, the next record is its header, subsequent records its data. Names are unique and nonempty. A blank line closes a section; body records outside sections and sections without headers reject. Return ordered [name, header, rows] sections.

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):
    sections, current, needs_header = [], None, False
    for line in data:
        if line.startswith('%'):
            if current is not None and needs_header: return None
            name = line[1:]
            if not name or any(s[0] == name for s in sections): return None
            current = [name, [], []]
            sections.append(current)
            needs_header = True
        elif line == '':
            if needs_header: return None
            current = current
        elif current is None: return None
        elif needs_header:
            current[1] = line.split('\t')
            needs_header = False
        else: current[2].append(line.split('\t'))
    if needs_header: return None
    return sections
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('two sections', solve(_vary(['%one', 'a\tb', '@\tz', '%two', 'x', 'q'])), _vary([['one', ['a', 'b'], [['@', 'z']]], ['two', ['x'], [['q']]]]))
check('section close', solve(_vary(['%one', 'a', 'x', '', 'orphan'])), _vary(None))
check('empty section', solve(_vary(['%one', '%two', 'a'])), _vary(None))
check('missing eof header', solve(_vary(['%one'])), _vary(None))
check('duplicate', solve(_vary(['%one', 'a', '%one', 'b'])), _vary(None))
check('empty name', solve(_vary(['%', 'a'])), _vary(None))
check('normal', solve(_vary(['%one', 'a', '%'])), _vary(None))
check('zero', solve(_vary([])), _vary([]))
check('body control', solve(_vary(['%one', 'a', 'cell', 'two'])), _vary([['one', ['a'], [['cell'], ['two']]]]))
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
two sections[['one', ['a', 'b'], [['cell', 'z']]], ['two', ['x'], [['q']]]][['one', ['a', 'b'], [['cell', 'z']]], ['two', ['x'], [['q']]]]Passed
section close[['one', ['a'], [['x'], ['orphan']]]]NoneFailed
empty sectionNoneNonePassed
missing eof headerNoneNonePassed
duplicateNoneNonePassed
empty nameNoneNonePassed
normalNoneNonePassed
zero[][]Passed
body control[['one', ['a'], [['cell'], ['two']]]][['one', ['a'], [['cell'], ['two']]]]Passed

SHA-256 / 25334c51d3c90d626bf2593167f5ba14a63acab0fa098841a2cc8bea1c64a2fd

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):
    sections, current, needs_header = [], None, False
    for line in data:
        if line.startswith('%'):
            if current is not None and needs_header: return None
            name = line[1:]
            if not name or any(s[0] == name for s in sections): return None
            current = [name, [], []]
            sections.append(current)
            needs_header = True
        elif line == '':
            if needs_header: return None
            current = sections[-1] if sections else None
        elif current is None: return None
        elif needs_header:
            current[1] = line.split('\t')
            needs_header = False
        else: current[2].append(line.split('\t'))
    if needs_header: return None
    return sections
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('two sections', solve(_vary(['%one', 'a\tb', '@\tz', '%two', 'x', 'q'])), _vary([['one', ['a', 'b'], [['@', 'z']]], ['two', ['x'], [['q']]]]))
check('section close', solve(_vary(['%one', 'a', 'x', '', 'orphan'])), _vary(None))
check('empty section', solve(_vary(['%one', '%two', 'a'])), _vary(None))
check('missing eof header', solve(_vary(['%one'])), _vary(None))
check('duplicate', solve(_vary(['%one', 'a', '%one', 'b'])), _vary(None))
check('empty name', solve(_vary(['%', 'a'])), _vary(None))
check('normal', solve(_vary(['%one', 'a', '%'])), _vary(None))
check('zero', solve(_vary([])), _vary([]))
check('body control', solve(_vary(['%one', 'a', 'cell', 'two'])), _vary([['one', ['a'], [['cell'], ['two']]]]))
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
two sections[['one', ['a', 'b'], [['cell', 'z']]], ['two', ['x'], [['q']]]][['one', ['a', 'b'], [['cell', 'z']]], ['two', ['x'], [['q']]]]Passed
section close[['one', ['a'], [['x'], ['orphan']]]]NoneFailed
empty sectionNoneNonePassed
missing eof headerNoneNonePassed
duplicateNoneNonePassed
empty nameNoneNonePassed
normalNoneNonePassed
zero[][]Passed
body control[['one', ['a'], [['cell'], ['two']]]][['one', ['a'], [['cell'], ['two']]]]Passed

SHA-256 / 91d729fc26f0b8770581b423f8abf7c4879fdbd2b5601514c5cd79189b5cba93

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):
    sections, current, needs_header = [], None, False
    for line in data:
        if line.startswith('%'):
            if current is not None and needs_header: return None
            name = line[1:]
            if not name or any(s[0] == name for s in sections): return None
            current = [name, [], []]
            sections.append(current)
            needs_header = True
        elif line == '':
            if needs_header: return None
            current = None
        elif current is None: return None
        elif needs_header:
            current[1] = line.split('\t')
            needs_header = False
        else: current[2].append(line.split('\t'))
    if needs_header: return None
    return sections
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('two sections', solve(_vary(['%one', 'a\tb', '@\tz', '%two', 'x', 'q'])), _vary([['one', ['a', 'b'], [['@', 'z']]], ['two', ['x'], [['q']]]]))
check('section close', solve(_vary(['%one', 'a', 'x', '', 'orphan'])), _vary(None))
check('empty section', solve(_vary(['%one', '%two', 'a'])), _vary(None))
check('missing eof header', solve(_vary(['%one'])), _vary(None))
check('duplicate', solve(_vary(['%one', 'a', '%one', 'b'])), _vary(None))
check('empty name', solve(_vary(['%', 'a'])), _vary(None))
check('normal', solve(_vary(['%one', 'a', '%'])), _vary(None))
check('zero', solve(_vary([])), _vary([]))
check('body control', solve(_vary(['%one', 'a', 'cell', 'two'])), _vary([['one', ['a'], [['cell'], ['two']]]]))
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
two sections[['one', ['a', 'b'], [['cell', 'z']]], ['two', ['x'], [['q']]]][['one', ['a', 'b'], [['cell', 'z']]], ['two', ['x'], [['q']]]]Passed
section closeNoneNonePassed
empty sectionNoneNonePassed
missing eof headerNoneNonePassed
duplicateNoneNonePassed
empty nameNoneNonePassed
normalNoneNonePassed
zero[][]Passed
body control[['one', ['a'], [['cell'], ['two']]]][['one', ['a'], [['cell'], ['two']]]]Passed

SHA-256 / 91c98c2c92c3b05585df3aef0b29296ddd37f20cba70ec5ea288fad98b73b730

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

Case digest / f0472f75408beed6a24d67759afa462d60fbc4e075ca7869a9e8a98fe296fd6d