FAILURE MAP
← Case archive

FA-96001 / Postal address normalization / Open access

Address label line wrapper: overlong words are split only once · case 01

A word more than twice the width leaves a line longer than the label.

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

ROOT CAUSE

The chunking uses a single if instead of repeating until the remainder fits.

VERIFIED REPAIR

Repeat chunking while the remainder is longer than the width.

Unsuccessful approach: Looping without flushing the pending line first emits the chunks ahead of the words that preceded them.

Case contract

Input [text, width, max_lines]. Words are whitespace-separated. A word longer than width first flushes the current line, then is emitted in width-sized chunks, the final remainder continuing as an ordinary word. Words join with single spaces while the line length stays <= width. Return {"lines": the first max_lines lines, "overflow": whether more than max_lines lines were needed}.

Why this case matters

Label printers and carrier manifests cap line length and line count; an off-by-one silently truncates part of the address.

1 / The failure

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    text, width, max_lines = x
    lines, cur = [], ''
    for w in text.split():
        if len(w) > width:
            if cur:
                lines.append(cur)
                cur = ''
            lines.append(w[:width])
            w = w[width:]
        if not cur:
            cur = w
        elif len(cur) + 1 + len(w) <= width:
            cur = cur + ' ' + w
        else:
            lines.append(cur)
            cur = w
    if cur:
        lines.append(cur)
    return {'lines': lines[:max_lines], 'overflow': len(lines) > max_lines}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['exact fit including the separator', ['ATTN ZORBLE', 11, 3], {'lines': ['ATTN ZORBLE'], 'overflow': False}], ['one character over once the separator counts', ['ATTN ZORBLET', 11, 3], {'lines': ['ATTN', 'ZORBLET'], 'overflow': False}], ['exactly the line budget', ['ATTN ZORBLETO', 11, 2], {'lines': ['ATTN', 'ZORBLETO'], 'overflow': False}], ['more lines than the budget', ['ATTN ZORBLETO DOCK ZORBLETON', 11, 3], {'lines': ['ATTN', 'ZORBLETO', 'DOCK'], 'overflow': True}], ['overlong word after a short word', ['SUITE ZORBLETONVALEZORBLETONVAL', 11, 5], {'lines': ['SUITE', 'ZORBLETONVA', 'LEZORBLETON', 'VAL'], 'overflow': False}], ['repeated spaces collapse', ['1  FAKE   RD', 11, 2], {'lines': ['1 FAKE RD'], 'overflow': False}]], [['exact fit including the separator', ['ATTN ZORBLET', 12, 3], {'lines': ['ATTN ZORBLET'], 'overflow': False}], ['one character over once the separator counts', ['ATTN ZORBLETO', 12, 3], {'lines': ['ATTN', 'ZORBLETO'], 'overflow': False}], ['exactly the line budget', ['ATTN ZORBLETON', 12, 2], {'lines': ['ATTN', 'ZORBLETON'], 'overflow': False}], ['more lines than the budget', ['ATTN ZORBLETON DOCK ZORBLETONV', 12, 3], {'lines': ['ATTN', 'ZORBLETON', 'DOCK'], 'overflow': True}], ['overlong word after a short word', ['SUITE ZORBLETONVALEZORBLETONVALEZ', 12, 5], {'lines': ['SUITE', 'ZORBLETONVAL', 'EZORBLETONVA', 'LEZ'], 'overflow': False}], ['repeated spaces collapse', ['2  FAKE   RD', 12, 2], {'lines': ['2 FAKE RD'], 'overflow': False}]], [['exact fit including the separator', ['ATTN ZORBLETO', 13, 3], {'lines': ['ATTN ZORBLETO'], 'overflow': False}], ['one character over once the separator counts', ['ATTN ZORBLETON', 13, 3], {'lines': ['ATTN', 'ZORBLETON'], 'overflow': False}], ['exactly the line budget', ['ATTN ZORBLETONV', 13, 2], {'lines': ['ATTN', 'ZORBLETONV'], 'overflow': False}], ['more lines than the budget', ['ATTN ZORBLETONV DOCK ZORBLETONVA', 13, 3], {'lines': ['ATTN', 'ZORBLETONV', 'DOCK'], 'overflow': True}], ['overlong word after a short word', ['SUITE ZORBLETONVALEZORBLETONVALEZOR', 13, 5], {'lines': ['SUITE', 'ZORBLETONVALE', 'ZORBLETONVALE', 'ZOR'], 'overflow': False}], ['repeated spaces collapse', ['3  FAKE   RD', 13, 2], {'lines': ['3 FAKE RD'], 'overflow': False}]], [['exact fit including the separator', ['ATTN ZORBLETON', 14, 3], {'lines': ['ATTN ZORBLETON'], 'overflow': False}], ['one character over once the separator counts', ['ATTN ZORBLETONV', 14, 3], {'lines': ['ATTN', 'ZORBLETONV'], 'overflow': False}], ['exactly the line budget', ['ATTN ZORBLETONVA', 14, 2], {'lines': ['ATTN', 'ZORBLETONVA'], 'overflow': False}], ['more lines than the budget', ['ATTN ZORBLETONVA DOCK ZORBLETONVAL', 14, 3], {'lines': ['ATTN', 'ZORBLETONVA', 'DOCK'], 'overflow': True}], ['overlong word after a short word', ['SUITE ZORBLETONVALEZORBLETONVALEZORBL', 14, 5], {'lines': ['SUITE', 'ZORBLETONVALEZ', 'ORBLETONVALEZO', 'RBL'], 'overflow': False}], ['repeated spaces collapse', ['4  FAKE   RD', 14, 2], {'lines': ['4 FAKE RD'], 'overflow': False}]], [['exact fit including the separator', ['ATTN ZORBLETONV', 15, 3], {'lines': ['ATTN ZORBLETONV'], 'overflow': False}], ['one character over once the separator counts', ['ATTN ZORBLETONVA', 15, 3], {'lines': ['ATTN', 'ZORBLETONVA'], 'overflow': False}], ['exactly the line budget', ['ATTN ZORBLETONVAL', 15, 2], {'lines': ['ATTN', 'ZORBLETONVAL'], 'overflow': False}], ['more lines than the budget', ['ATTN ZORBLETONVAL DOCK ZORBLETONVALE', 15, 3], {'lines': ['ATTN', 'ZORBLETONVAL', 'DOCK'], 'overflow': True}], ['overlong word after a short word', ['SUITE ZORBLETONVALEZORBLETONVALEZORBLET', 15, 5], {'lines': ['SUITE', 'ZORBLETONVALEZO', 'RBLETONVALEZORB', 'LET'], 'overflow': False}], ['repeated spaces collapse', ['5  FAKE   RD', 15, 2], {'lines': ['5 FAKE RD'], 'overflow': False}]]]
for label, arg, expected in fixtures[N - 1]:
    check(label, solve(arg), expected)
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
exact fit including the separator{'lines': ['ATTN ZORBLE'], 'overflow': False}{'lines': ['ATTN ZORBLE'], 'overflow': False}Passed
one character over once the separator counts{'lines': ['ATTN', 'ZORBLET'], 'overflow': False}{'lines': ['ATTN', 'ZORBLET'], 'overflow': False}Passed
exactly the line budget{'lines': ['ATTN', 'ZORBLETO'], 'overflow': False}{'lines': ['ATTN', 'ZORBLETO'], 'overflow': False}Passed
more lines than the budget{'lines': ['ATTN', 'ZORBLETO', 'DOCK'], 'overflow': True}{'lines': ['ATTN', 'ZORBLETO', 'DOCK'], 'overflow': True}Passed
overlong word after a short word{'lines': ['SUITE', 'ZORBLETONVA', 'LEZORBLETONVAL'], 'overflow': False}{'lines': ['SUITE', 'ZORBLETONVA', 'LEZORBLETON', 'VAL'], 'overflow': False}Failed
repeated spaces collapse{'lines': ['1 FAKE RD'], 'overflow': False}{'lines': ['1 FAKE RD'], 'overflow': False}Passed

SHA-256 / bf9c17e61bd579db779fa08fc3f6bd35e1bac8fe49284fe5299da97529671fad

2 / The unsuccessful fix

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    text, width, max_lines = x
    lines, cur = [], ''
    for w in text.split():
        while len(w) > width:
            lines.append(w[:width])
            w = w[width:]
        if not cur:
            cur = w
        elif len(cur) + 1 + len(w) <= width:
            cur = cur + ' ' + w
        else:
            lines.append(cur)
            cur = w
    if cur:
        lines.append(cur)
    return {'lines': lines[:max_lines], 'overflow': len(lines) > max_lines}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['exact fit including the separator', ['ATTN ZORBLE', 11, 3], {'lines': ['ATTN ZORBLE'], 'overflow': False}], ['one character over once the separator counts', ['ATTN ZORBLET', 11, 3], {'lines': ['ATTN', 'ZORBLET'], 'overflow': False}], ['exactly the line budget', ['ATTN ZORBLETO', 11, 2], {'lines': ['ATTN', 'ZORBLETO'], 'overflow': False}], ['more lines than the budget', ['ATTN ZORBLETO DOCK ZORBLETON', 11, 3], {'lines': ['ATTN', 'ZORBLETO', 'DOCK'], 'overflow': True}], ['overlong word after a short word', ['SUITE ZORBLETONVALEZORBLETONVAL', 11, 5], {'lines': ['SUITE', 'ZORBLETONVA', 'LEZORBLETON', 'VAL'], 'overflow': False}], ['repeated spaces collapse', ['1  FAKE   RD', 11, 2], {'lines': ['1 FAKE RD'], 'overflow': False}]], [['exact fit including the separator', ['ATTN ZORBLET', 12, 3], {'lines': ['ATTN ZORBLET'], 'overflow': False}], ['one character over once the separator counts', ['ATTN ZORBLETO', 12, 3], {'lines': ['ATTN', 'ZORBLETO'], 'overflow': False}], ['exactly the line budget', ['ATTN ZORBLETON', 12, 2], {'lines': ['ATTN', 'ZORBLETON'], 'overflow': False}], ['more lines than the budget', ['ATTN ZORBLETON DOCK ZORBLETONV', 12, 3], {'lines': ['ATTN', 'ZORBLETON', 'DOCK'], 'overflow': True}], ['overlong word after a short word', ['SUITE ZORBLETONVALEZORBLETONVALEZ', 12, 5], {'lines': ['SUITE', 'ZORBLETONVAL', 'EZORBLETONVA', 'LEZ'], 'overflow': False}], ['repeated spaces collapse', ['2  FAKE   RD', 12, 2], {'lines': ['2 FAKE RD'], 'overflow': False}]], [['exact fit including the separator', ['ATTN ZORBLETO', 13, 3], {'lines': ['ATTN ZORBLETO'], 'overflow': False}], ['one character over once the separator counts', ['ATTN ZORBLETON', 13, 3], {'lines': ['ATTN', 'ZORBLETON'], 'overflow': False}], ['exactly the line budget', ['ATTN ZORBLETONV', 13, 2], {'lines': ['ATTN', 'ZORBLETONV'], 'overflow': False}], ['more lines than the budget', ['ATTN ZORBLETONV DOCK ZORBLETONVA', 13, 3], {'lines': ['ATTN', 'ZORBLETONV', 'DOCK'], 'overflow': True}], ['overlong word after a short word', ['SUITE ZORBLETONVALEZORBLETONVALEZOR', 13, 5], {'lines': ['SUITE', 'ZORBLETONVALE', 'ZORBLETONVALE', 'ZOR'], 'overflow': False}], ['repeated spaces collapse', ['3  FAKE   RD', 13, 2], {'lines': ['3 FAKE RD'], 'overflow': False}]], [['exact fit including the separator', ['ATTN ZORBLETON', 14, 3], {'lines': ['ATTN ZORBLETON'], 'overflow': False}], ['one character over once the separator counts', ['ATTN ZORBLETONV', 14, 3], {'lines': ['ATTN', 'ZORBLETONV'], 'overflow': False}], ['exactly the line budget', ['ATTN ZORBLETONVA', 14, 2], {'lines': ['ATTN', 'ZORBLETONVA'], 'overflow': False}], ['more lines than the budget', ['ATTN ZORBLETONVA DOCK ZORBLETONVAL', 14, 3], {'lines': ['ATTN', 'ZORBLETONVA', 'DOCK'], 'overflow': True}], ['overlong word after a short word', ['SUITE ZORBLETONVALEZORBLETONVALEZORBL', 14, 5], {'lines': ['SUITE', 'ZORBLETONVALEZ', 'ORBLETONVALEZO', 'RBL'], 'overflow': False}], ['repeated spaces collapse', ['4  FAKE   RD', 14, 2], {'lines': ['4 FAKE RD'], 'overflow': False}]], [['exact fit including the separator', ['ATTN ZORBLETONV', 15, 3], {'lines': ['ATTN ZORBLETONV'], 'overflow': False}], ['one character over once the separator counts', ['ATTN ZORBLETONVA', 15, 3], {'lines': ['ATTN', 'ZORBLETONVA'], 'overflow': False}], ['exactly the line budget', ['ATTN ZORBLETONVAL', 15, 2], {'lines': ['ATTN', 'ZORBLETONVAL'], 'overflow': False}], ['more lines than the budget', ['ATTN ZORBLETONVAL DOCK ZORBLETONVALE', 15, 3], {'lines': ['ATTN', 'ZORBLETONVAL', 'DOCK'], 'overflow': True}], ['overlong word after a short word', ['SUITE ZORBLETONVALEZORBLETONVALEZORBLET', 15, 5], {'lines': ['SUITE', 'ZORBLETONVALEZO', 'RBLETONVALEZORB', 'LET'], 'overflow': False}], ['repeated spaces collapse', ['5  FAKE   RD', 15, 2], {'lines': ['5 FAKE RD'], 'overflow': False}]]]
for label, arg, expected in fixtures[N - 1]:
    check(label, solve(arg), expected)
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
exact fit including the separator{'lines': ['ATTN ZORBLE'], 'overflow': False}{'lines': ['ATTN ZORBLE'], 'overflow': False}Passed
one character over once the separator counts{'lines': ['ATTN', 'ZORBLET'], 'overflow': False}{'lines': ['ATTN', 'ZORBLET'], 'overflow': False}Passed
exactly the line budget{'lines': ['ATTN', 'ZORBLETO'], 'overflow': False}{'lines': ['ATTN', 'ZORBLETO'], 'overflow': False}Passed
more lines than the budget{'lines': ['ATTN', 'ZORBLETO', 'DOCK'], 'overflow': True}{'lines': ['ATTN', 'ZORBLETO', 'DOCK'], 'overflow': True}Passed
overlong word after a short word{'lines': ['ZORBLETONVA', 'LEZORBLETON', 'SUITE VAL'], 'overflow': False}{'lines': ['SUITE', 'ZORBLETONVA', 'LEZORBLETON', 'VAL'], 'overflow': False}Failed
repeated spaces collapse{'lines': ['1 FAKE RD'], 'overflow': False}{'lines': ['1 FAKE RD'], 'overflow': False}Passed

SHA-256 / 4c3291027e0d815245dd7b7b924c8a7ac88b57de2c1b838293a1db4d6b91940e

3 / The verified repair

Exit 0
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    text, width, max_lines = x
    lines, cur = [], ''
    for w in text.split():
        while len(w) > width:
            if cur:
                lines.append(cur)
                cur = ''
            lines.append(w[:width])
            w = w[width:]
        if not cur:
            cur = w
        elif len(cur) + 1 + len(w) <= width:
            cur = cur + ' ' + w
        else:
            lines.append(cur)
            cur = w
    if cur:
        lines.append(cur)
    return {'lines': lines[:max_lines], 'overflow': len(lines) > max_lines}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['exact fit including the separator', ['ATTN ZORBLE', 11, 3], {'lines': ['ATTN ZORBLE'], 'overflow': False}], ['one character over once the separator counts', ['ATTN ZORBLET', 11, 3], {'lines': ['ATTN', 'ZORBLET'], 'overflow': False}], ['exactly the line budget', ['ATTN ZORBLETO', 11, 2], {'lines': ['ATTN', 'ZORBLETO'], 'overflow': False}], ['more lines than the budget', ['ATTN ZORBLETO DOCK ZORBLETON', 11, 3], {'lines': ['ATTN', 'ZORBLETO', 'DOCK'], 'overflow': True}], ['overlong word after a short word', ['SUITE ZORBLETONVALEZORBLETONVAL', 11, 5], {'lines': ['SUITE', 'ZORBLETONVA', 'LEZORBLETON', 'VAL'], 'overflow': False}], ['repeated spaces collapse', ['1  FAKE   RD', 11, 2], {'lines': ['1 FAKE RD'], 'overflow': False}]], [['exact fit including the separator', ['ATTN ZORBLET', 12, 3], {'lines': ['ATTN ZORBLET'], 'overflow': False}], ['one character over once the separator counts', ['ATTN ZORBLETO', 12, 3], {'lines': ['ATTN', 'ZORBLETO'], 'overflow': False}], ['exactly the line budget', ['ATTN ZORBLETON', 12, 2], {'lines': ['ATTN', 'ZORBLETON'], 'overflow': False}], ['more lines than the budget', ['ATTN ZORBLETON DOCK ZORBLETONV', 12, 3], {'lines': ['ATTN', 'ZORBLETON', 'DOCK'], 'overflow': True}], ['overlong word after a short word', ['SUITE ZORBLETONVALEZORBLETONVALEZ', 12, 5], {'lines': ['SUITE', 'ZORBLETONVAL', 'EZORBLETONVA', 'LEZ'], 'overflow': False}], ['repeated spaces collapse', ['2  FAKE   RD', 12, 2], {'lines': ['2 FAKE RD'], 'overflow': False}]], [['exact fit including the separator', ['ATTN ZORBLETO', 13, 3], {'lines': ['ATTN ZORBLETO'], 'overflow': False}], ['one character over once the separator counts', ['ATTN ZORBLETON', 13, 3], {'lines': ['ATTN', 'ZORBLETON'], 'overflow': False}], ['exactly the line budget', ['ATTN ZORBLETONV', 13, 2], {'lines': ['ATTN', 'ZORBLETONV'], 'overflow': False}], ['more lines than the budget', ['ATTN ZORBLETONV DOCK ZORBLETONVA', 13, 3], {'lines': ['ATTN', 'ZORBLETONV', 'DOCK'], 'overflow': True}], ['overlong word after a short word', ['SUITE ZORBLETONVALEZORBLETONVALEZOR', 13, 5], {'lines': ['SUITE', 'ZORBLETONVALE', 'ZORBLETONVALE', 'ZOR'], 'overflow': False}], ['repeated spaces collapse', ['3  FAKE   RD', 13, 2], {'lines': ['3 FAKE RD'], 'overflow': False}]], [['exact fit including the separator', ['ATTN ZORBLETON', 14, 3], {'lines': ['ATTN ZORBLETON'], 'overflow': False}], ['one character over once the separator counts', ['ATTN ZORBLETONV', 14, 3], {'lines': ['ATTN', 'ZORBLETONV'], 'overflow': False}], ['exactly the line budget', ['ATTN ZORBLETONVA', 14, 2], {'lines': ['ATTN', 'ZORBLETONVA'], 'overflow': False}], ['more lines than the budget', ['ATTN ZORBLETONVA DOCK ZORBLETONVAL', 14, 3], {'lines': ['ATTN', 'ZORBLETONVA', 'DOCK'], 'overflow': True}], ['overlong word after a short word', ['SUITE ZORBLETONVALEZORBLETONVALEZORBL', 14, 5], {'lines': ['SUITE', 'ZORBLETONVALEZ', 'ORBLETONVALEZO', 'RBL'], 'overflow': False}], ['repeated spaces collapse', ['4  FAKE   RD', 14, 2], {'lines': ['4 FAKE RD'], 'overflow': False}]], [['exact fit including the separator', ['ATTN ZORBLETONV', 15, 3], {'lines': ['ATTN ZORBLETONV'], 'overflow': False}], ['one character over once the separator counts', ['ATTN ZORBLETONVA', 15, 3], {'lines': ['ATTN', 'ZORBLETONVA'], 'overflow': False}], ['exactly the line budget', ['ATTN ZORBLETONVAL', 15, 2], {'lines': ['ATTN', 'ZORBLETONVAL'], 'overflow': False}], ['more lines than the budget', ['ATTN ZORBLETONVAL DOCK ZORBLETONVALE', 15, 3], {'lines': ['ATTN', 'ZORBLETONVAL', 'DOCK'], 'overflow': True}], ['overlong word after a short word', ['SUITE ZORBLETONVALEZORBLETONVALEZORBLET', 15, 5], {'lines': ['SUITE', 'ZORBLETONVALEZO', 'RBLETONVALEZORB', 'LET'], 'overflow': False}], ['repeated spaces collapse', ['5  FAKE   RD', 15, 2], {'lines': ['5 FAKE RD'], 'overflow': False}]]]
for label, arg, expected in fixtures[N - 1]:
    check(label, solve(arg), expected)
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
exact fit including the separator{'lines': ['ATTN ZORBLE'], 'overflow': False}{'lines': ['ATTN ZORBLE'], 'overflow': False}Passed
one character over once the separator counts{'lines': ['ATTN', 'ZORBLET'], 'overflow': False}{'lines': ['ATTN', 'ZORBLET'], 'overflow': False}Passed
exactly the line budget{'lines': ['ATTN', 'ZORBLETO'], 'overflow': False}{'lines': ['ATTN', 'ZORBLETO'], 'overflow': False}Passed
more lines than the budget{'lines': ['ATTN', 'ZORBLETO', 'DOCK'], 'overflow': True}{'lines': ['ATTN', 'ZORBLETO', 'DOCK'], 'overflow': True}Passed
overlong word after a short word{'lines': ['SUITE', 'ZORBLETONVA', 'LEZORBLETON', 'VAL'], 'overflow': False}{'lines': ['SUITE', 'ZORBLETONVA', 'LEZORBLETON', 'VAL'], 'overflow': False}Passed
repeated spaces collapse{'lines': ['1 FAKE RD'], 'overflow': False}{'lines': ['1 FAKE RD'], 'overflow': False}Passed

SHA-256 / 00140be3251941f06c3f328e5c46e4293f1547ba400ffaed34e27ba530d10916

Verification & scope

A deterministic toy contract over synthetic, obviously fictitious addresses. The rules are stipulated for this model only and make no claim of conformance with any postal authority standard. 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:52:18.759064+00:00.

Case digest / b0fc8c5527817d8e669dcfe0da4643184dd34f55a62853bfe2db4d050ad59bb7