FAILURE MAP
← Case archive

FA-79401 / Barcode symbology encoding / Open access

Odd-length all-digit data starts in set C · case 01

A three-digit quantity is encoded as a pair in C plus a switch to B for its last digit.

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

ROOT CAUSE

The all-digit start rule ignores parity, so odd strings leave a lone digit that forces a switch.

VERIFIED REPAIR

Start all-digit data in C only when its length is even.

Unsuccessful approach: Dropping the minimum length makes empty data start in set C.

Case contract

Plan Code 128 code sets for printable ASCII data (other characters -> None) as a list of [set, text] segments. Start in C when the data begins with at least 4 digits or is entirely digits of even length >= 2, else B. In C consume digit pairs and fall back to B when fewer than two digits remain in the run. In B switch to C before a run of at least 6 digits, or at least 4 digits that reach the end of the data; an odd run first encodes one digit in B. Empty data yields [["B", ""]].

Why this case matters

Retail, logistics, pharmacy and document workflows depend on encoders that produce exactly the module pattern, code-set switches, separators and quiet zones scanners expect; one misplaced module or separator makes a label unreadable or, worse, scan as different data.

1 / The failure

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

N = 1
observations = []
def solve(data):
    if any(not (32 <= ord(ch) <= 126) for ch in data):
        return None
    n = len(data)
    def run(j):
        k = j
        while k < n and data[k] in '0123456789':
            k += 1
        return k - j
    segs = []
    r = run(0)
    if r >= 4 or (r == n and n >= 2):
        cur = 'C'
    else:
        cur = 'B'
    buf = ''
    i = 0
    while i < n:
        if cur == 'C':
            if run(i) >= 2:
                buf += data[i:i + 2]
                i += 2
                continue
            segs.append(['C', buf])
            buf = ''
            cur = 'B'
            continue
        r = run(i)
        if r >= 6 or (r >= 4 and i + r == n):
            if r % 2 == 1:
                buf += data[i]
                i += 1
            if buf:
                segs.append(['B', buf])
            buf = ''
            cur = 'C'
            continue
        buf += data[i]
        i += 1
    if buf or not segs:
        segs.append([cur, buf])
    return segs
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['841', [['B', '841']]], ['', [['B', '']]], ['3580131', [['C', '358013'], ['B', '1']]], ['lot17764124x', [['B', 'lot'], ['C', '17764124'], ['B', 'x']]], ['xAB', [['B', 'xAB']]], [' 193261lot', [['B', ' '], ['C', '193261'], ['B', 'lot']]], ['AB', [['B', 'AB']]], ['402', [['B', '402']]]], [['754', [['B', '754']]], ['', [['B', '']]], ['Q7lotQ7lot', [['B', 'Q7lotQ7lot']]], ['101874486507729', [['C', '10187448650772'], ['B', '9']]], ['x22', [['B', 'x22']]], [' ', [['B', ' ']]], ['-006', [['B', '-006']]], ['967', [['B', '967']]]], [['623', [['B', '623']]], ['', [['B', '']]], ['0964853799773055547674lot', [['C', '0964853799773055547674'], ['B', 'lot']]], ['lot', [['B', 'lot']]], ['1', [['B', '1']]], ['Q7 lotAB', [['B', 'Q7 lotAB']]], ['-00331 ', [['B', '-00331 ']]], ['157', [['B', '157']]]], [['823', [['B', '823']]], ['', [['B', '']]], ['3807356726022 ', [['C', '380735672602'], ['B', '2 ']]], ['733-', [['B', '733-']]], ['46450162930', [['C', '4645016293'], ['B', '0']]], [' - ', [['B', ' - ']]], ['lot5899 ', [['B', 'lot5899 ']]], ['824', [['B', '824']]]], [['912', [['B', '912']]], ['', [['B', '']]], ['5776132lot', [['C', '577613'], ['B', '2lot']]], ['xlot045355094', [['B', 'xlot0'], ['C', '45355094']]], ['007775830', [['C', '00777583'], ['B', '0']]], ['AB8', [['B', 'AB8']]], ['014550632960 753', [['C', '014550632960'], ['B', ' 753']]], ['355', [['B', '355']]]]]
labels = ["regression: all-digit start parity", "repair trap", "combined fault", "control", "control", "boundary", "boundary", "control"]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (labels[i % len(labels)], i), solve(args), 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
regression: all-digit start parity 0[['C', '84'], ['B', '1']][['B', '841']]Failed
repair trap 1[['B', '']][['B', '']]Passed
combined fault 2[['C', '358013'], ['B', '1']][['C', '358013'], ['B', '1']]Passed
control 3[['B', 'lot'], ['C', '17764124'], ['B', 'x']][['B', 'lot'], ['C', '17764124'], ['B', 'x']]Passed
control 4[['B', 'xAB']][['B', 'xAB']]Passed
boundary 5[['B', ' '], ['C', '193261'], ['B', 'lot']][['B', ' '], ['C', '193261'], ['B', 'lot']]Passed
boundary 6[['B', 'AB']][['B', 'AB']]Passed
control 7[['C', '40'], ['B', '2']][['B', '402']]Failed

SHA-256 / cad8c905d574091172ad34b4da9202e6df76fde4d0f8031e0e7075994f1be6a1

2 / The unsuccessful fix

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

N = 1
observations = []
def solve(data):
    if any(not (32 <= ord(ch) <= 126) for ch in data):
        return None
    n = len(data)
    def run(j):
        k = j
        while k < n and data[k] in '0123456789':
            k += 1
        return k - j
    segs = []
    r = run(0)
    if r >= 4 or (r == n and n % 2 == 0):
        cur = 'C'
    else:
        cur = 'B'
    buf = ''
    i = 0
    while i < n:
        if cur == 'C':
            if run(i) >= 2:
                buf += data[i:i + 2]
                i += 2
                continue
            segs.append(['C', buf])
            buf = ''
            cur = 'B'
            continue
        r = run(i)
        if r >= 6 or (r >= 4 and i + r == n):
            if r % 2 == 1:
                buf += data[i]
                i += 1
            if buf:
                segs.append(['B', buf])
            buf = ''
            cur = 'C'
            continue
        buf += data[i]
        i += 1
    if buf or not segs:
        segs.append([cur, buf])
    return segs
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['841', [['B', '841']]], ['', [['B', '']]], ['3580131', [['C', '358013'], ['B', '1']]], ['lot17764124x', [['B', 'lot'], ['C', '17764124'], ['B', 'x']]], ['xAB', [['B', 'xAB']]], [' 193261lot', [['B', ' '], ['C', '193261'], ['B', 'lot']]], ['AB', [['B', 'AB']]], ['402', [['B', '402']]]], [['754', [['B', '754']]], ['', [['B', '']]], ['Q7lotQ7lot', [['B', 'Q7lotQ7lot']]], ['101874486507729', [['C', '10187448650772'], ['B', '9']]], ['x22', [['B', 'x22']]], [' ', [['B', ' ']]], ['-006', [['B', '-006']]], ['967', [['B', '967']]]], [['623', [['B', '623']]], ['', [['B', '']]], ['0964853799773055547674lot', [['C', '0964853799773055547674'], ['B', 'lot']]], ['lot', [['B', 'lot']]], ['1', [['B', '1']]], ['Q7 lotAB', [['B', 'Q7 lotAB']]], ['-00331 ', [['B', '-00331 ']]], ['157', [['B', '157']]]], [['823', [['B', '823']]], ['', [['B', '']]], ['3807356726022 ', [['C', '380735672602'], ['B', '2 ']]], ['733-', [['B', '733-']]], ['46450162930', [['C', '4645016293'], ['B', '0']]], [' - ', [['B', ' - ']]], ['lot5899 ', [['B', 'lot5899 ']]], ['824', [['B', '824']]]], [['912', [['B', '912']]], ['', [['B', '']]], ['5776132lot', [['C', '577613'], ['B', '2lot']]], ['xlot045355094', [['B', 'xlot0'], ['C', '45355094']]], ['007775830', [['C', '00777583'], ['B', '0']]], ['AB8', [['B', 'AB8']]], ['014550632960 753', [['C', '014550632960'], ['B', ' 753']]], ['355', [['B', '355']]]]]
labels = ["regression: all-digit start parity", "repair trap", "combined fault", "control", "control", "boundary", "boundary", "control"]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (labels[i % len(labels)], i), solve(args), 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
regression: all-digit start parity 0[['B', '841']][['B', '841']]Passed
repair trap 1[['C', '']][['B', '']]Failed
combined fault 2[['C', '358013'], ['B', '1']][['C', '358013'], ['B', '1']]Passed
control 3[['B', 'lot'], ['C', '17764124'], ['B', 'x']][['B', 'lot'], ['C', '17764124'], ['B', 'x']]Passed
control 4[['B', 'xAB']][['B', 'xAB']]Passed
boundary 5[['B', ' '], ['C', '193261'], ['B', 'lot']][['B', ' '], ['C', '193261'], ['B', 'lot']]Passed
boundary 6[['B', 'AB']][['B', 'AB']]Passed
control 7[['B', '402']][['B', '402']]Passed

SHA-256 / c5253bd73a949cc6e61ded6404414cdb256090b7a6b6aefc4dac3a08546a2e47

3 / The verified repair

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

N = 1
observations = []
def solve(data):
    if any(not (32 <= ord(ch) <= 126) for ch in data):
        return None
    n = len(data)
    def run(j):
        k = j
        while k < n and data[k] in '0123456789':
            k += 1
        return k - j
    segs = []
    r = run(0)
    if r >= 4 or (r == n and n >= 2 and n % 2 == 0):
        cur = 'C'
    else:
        cur = 'B'
    buf = ''
    i = 0
    while i < n:
        if cur == 'C':
            if run(i) >= 2:
                buf += data[i:i + 2]
                i += 2
                continue
            segs.append(['C', buf])
            buf = ''
            cur = 'B'
            continue
        r = run(i)
        if r >= 6 or (r >= 4 and i + r == n):
            if r % 2 == 1:
                buf += data[i]
                i += 1
            if buf:
                segs.append(['B', buf])
            buf = ''
            cur = 'C'
            continue
        buf += data[i]
        i += 1
    if buf or not segs:
        segs.append([cur, buf])
    return segs
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['841', [['B', '841']]], ['', [['B', '']]], ['3580131', [['C', '358013'], ['B', '1']]], ['lot17764124x', [['B', 'lot'], ['C', '17764124'], ['B', 'x']]], ['xAB', [['B', 'xAB']]], [' 193261lot', [['B', ' '], ['C', '193261'], ['B', 'lot']]], ['AB', [['B', 'AB']]], ['402', [['B', '402']]]], [['754', [['B', '754']]], ['', [['B', '']]], ['Q7lotQ7lot', [['B', 'Q7lotQ7lot']]], ['101874486507729', [['C', '10187448650772'], ['B', '9']]], ['x22', [['B', 'x22']]], [' ', [['B', ' ']]], ['-006', [['B', '-006']]], ['967', [['B', '967']]]], [['623', [['B', '623']]], ['', [['B', '']]], ['0964853799773055547674lot', [['C', '0964853799773055547674'], ['B', 'lot']]], ['lot', [['B', 'lot']]], ['1', [['B', '1']]], ['Q7 lotAB', [['B', 'Q7 lotAB']]], ['-00331 ', [['B', '-00331 ']]], ['157', [['B', '157']]]], [['823', [['B', '823']]], ['', [['B', '']]], ['3807356726022 ', [['C', '380735672602'], ['B', '2 ']]], ['733-', [['B', '733-']]], ['46450162930', [['C', '4645016293'], ['B', '0']]], [' - ', [['B', ' - ']]], ['lot5899 ', [['B', 'lot5899 ']]], ['824', [['B', '824']]]], [['912', [['B', '912']]], ['', [['B', '']]], ['5776132lot', [['C', '577613'], ['B', '2lot']]], ['xlot045355094', [['B', 'xlot0'], ['C', '45355094']]], ['007775830', [['C', '00777583'], ['B', '0']]], ['AB8', [['B', 'AB8']]], ['014550632960 753', [['C', '014550632960'], ['B', ' 753']]], ['355', [['B', '355']]]]]
labels = ["regression: all-digit start parity", "repair trap", "combined fault", "control", "control", "boundary", "boundary", "control"]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (labels[i % len(labels)], i), solve(args), 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
regression: all-digit start parity 0[['B', '841']][['B', '841']]Passed
repair trap 1[['B', '']][['B', '']]Passed
combined fault 2[['C', '358013'], ['B', '1']][['C', '358013'], ['B', '1']]Passed
control 3[['B', 'lot'], ['C', '17764124'], ['B', 'x']][['B', 'lot'], ['C', '17764124'], ['B', 'x']]Passed
control 4[['B', 'xAB']][['B', 'xAB']]Passed
boundary 5[['B', ' '], ['C', '193261'], ['B', 'lot']][['B', ' '], ['C', '193261'], ['B', 'lot']]Passed
boundary 6[['B', 'AB']][['B', 'AB']]Passed
control 7[['B', '402']][['B', '402']]Passed

SHA-256 / 703608f324553ed44233b47c7e1ab1edd1d1b3ed63f12272a99659788dcbdf78

Verification & scope

A deterministic bounded teaching model with a stipulated contract; it makes no claim of conformance to any published specification. 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:49:44.344976+00:00.

Case digest / 55350bd69d0fe623b6fa074471e5ec9130aed5bc8295467ad8645bd768f8ba0e