FAILURE MAP
← Case archive

FA-79406 / Barcode symbology encoding / Open access

Code 128 switches to set C for four digits in mid-data · case 01

Symbols grow when a four-digit run sits between letters, because two switch characters cost more than the pairs save.

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

ROOT CAUSE

The interior run threshold is 4 instead of 6.

VERIFIED REPAIR

Switch into C mid-data only for runs of six or more digits.

Unsuccessful approach: A strict > 6 test leaves six-digit interior runs in B.

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 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 >= 4 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 = [[[' lot1300 ', [['B', ' lot1300 ']]], [' 193261lot', [['B', ' '], ['C', '193261'], ['B', 'lot']]], ['3580131', [['C', '358013'], ['B', '1']]], ['lot17764124x', [['B', 'lot'], ['C', '17764124'], ['B', 'x']]], ['xAB', [['B', 'xAB']]], ['AB', [['B', 'AB']]], ['x15', [['B', 'x15']]], ['lot3821-AB', [['B', 'lot3821-AB']]]], [['741025864Q70329 ', [['C', '74102586'], ['B', '4Q70329 ']]], ['-494318 0580944', [['B', '-'], ['C', '494318'], ['B', ' 0'], ['C', '580944']]], ['Q7lotQ7lot', [['B', 'Q7lotQ7lot']]], ['101874486507729', [['C', '10187448650772'], ['B', '9']]], ['x22', [['B', 'x22']]], [' ', [['B', ' ']]], ['-006', [['B', '-006']]], ['03 2849 ', [['B', '03 2849 ']]]], [['x5197AB', [['B', 'x5197AB']]], ['Q780759lotAB', [['B', 'Q'], ['C', '780759'], ['B', 'lotAB']]], ['0964853799773055547674lot', [['C', '0964853799773055547674'], ['B', 'lot']]], ['lot', [['B', 'lot']]], ['1', [['B', '1']]], ['Q7 lotAB', [['B', 'Q7 lotAB']]], ['-753024468324', [['B', '-'], ['C', '753024468324']]], [' 29428AB ', [['B', ' 29428AB ']]]], [['lot1743-0346174', [['B', 'lot1743-0'], ['C', '346174']]], [' 705791-x', [['B', ' '], ['C', '705791'], ['B', '-x']]], ['3807356726022 ', [['C', '380735672602'], ['B', '2 ']]], ['733-', [['B', '733-']]], ['46450162930', [['C', '4645016293'], ['B', '0']]], [' - ', [['B', ' - ']]], [' Q7', [['B', ' Q7']]], ['Q7lot1604lot', [['B', 'Q7lot1604lot']]]], [['x12345-', [['B', 'x12345-']]], ['-869837ABx', [['B', '-'], ['C', '869837'], ['B', 'ABx']]], ['5776132lot', [['C', '577613'], ['B', '2lot']]], ['xlot045355094', [['B', 'xlot0'], ['C', '45355094']]], ['007775830', [['C', '00777583'], ['B', '0']]], ['AB8', [['B', 'AB8']]], ['014550632960 753', [['C', '014550632960'], ['B', ' 753']]], ['6 25164lot', [['B', '6 25164lot']]]]]
labels = ["regression: mid-data switch threshold", "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: mid-data switch threshold 0[['B', ' lot'], ['C', '1300'], ['B', ' ']][['B', ' lot1300 ']]Failed
repair trap 1[['B', ' '], ['C', '193261'], ['B', 'lot']][['B', ' '], ['C', '193261'], ['B', 'lot']]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', 'AB']][['B', 'AB']]Passed
boundary 6[['B', 'x15']][['B', 'x15']]Passed
control 7[['B', 'lot'], ['C', '3821'], ['B', '-AB']][['B', 'lot3821-AB']]Failed

SHA-256 / 21a5565597496bc6196f9d43f5641e3e99b2674b843a4e3a6757749d15f6762e

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 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 = [[[' lot1300 ', [['B', ' lot1300 ']]], [' 193261lot', [['B', ' '], ['C', '193261'], ['B', 'lot']]], ['3580131', [['C', '358013'], ['B', '1']]], ['lot17764124x', [['B', 'lot'], ['C', '17764124'], ['B', 'x']]], ['xAB', [['B', 'xAB']]], ['AB', [['B', 'AB']]], ['x15', [['B', 'x15']]], ['lot3821-AB', [['B', 'lot3821-AB']]]], [['741025864Q70329 ', [['C', '74102586'], ['B', '4Q70329 ']]], ['-494318 0580944', [['B', '-'], ['C', '494318'], ['B', ' 0'], ['C', '580944']]], ['Q7lotQ7lot', [['B', 'Q7lotQ7lot']]], ['101874486507729', [['C', '10187448650772'], ['B', '9']]], ['x22', [['B', 'x22']]], [' ', [['B', ' ']]], ['-006', [['B', '-006']]], ['03 2849 ', [['B', '03 2849 ']]]], [['x5197AB', [['B', 'x5197AB']]], ['Q780759lotAB', [['B', 'Q'], ['C', '780759'], ['B', 'lotAB']]], ['0964853799773055547674lot', [['C', '0964853799773055547674'], ['B', 'lot']]], ['lot', [['B', 'lot']]], ['1', [['B', '1']]], ['Q7 lotAB', [['B', 'Q7 lotAB']]], ['-753024468324', [['B', '-'], ['C', '753024468324']]], [' 29428AB ', [['B', ' 29428AB ']]]], [['lot1743-0346174', [['B', 'lot1743-0'], ['C', '346174']]], [' 705791-x', [['B', ' '], ['C', '705791'], ['B', '-x']]], ['3807356726022 ', [['C', '380735672602'], ['B', '2 ']]], ['733-', [['B', '733-']]], ['46450162930', [['C', '4645016293'], ['B', '0']]], [' - ', [['B', ' - ']]], [' Q7', [['B', ' Q7']]], ['Q7lot1604lot', [['B', 'Q7lot1604lot']]]], [['x12345-', [['B', 'x12345-']]], ['-869837ABx', [['B', '-'], ['C', '869837'], ['B', 'ABx']]], ['5776132lot', [['C', '577613'], ['B', '2lot']]], ['xlot045355094', [['B', 'xlot0'], ['C', '45355094']]], ['007775830', [['C', '00777583'], ['B', '0']]], ['AB8', [['B', 'AB8']]], ['014550632960 753', [['C', '014550632960'], ['B', ' 753']]], ['6 25164lot', [['B', '6 25164lot']]]]]
labels = ["regression: mid-data switch threshold", "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: mid-data switch threshold 0[['B', ' lot1300 ']][['B', ' lot1300 ']]Passed
repair trap 1[['B', ' 193261lot']][['B', ' '], ['C', '193261'], ['B', 'lot']]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', 'AB']][['B', 'AB']]Passed
boundary 6[['B', 'x15']][['B', 'x15']]Passed
control 7[['B', 'lot3821-AB']][['B', 'lot3821-AB']]Passed

SHA-256 / e7a2286654c66e126e414abbf528b12e7c498679afc8e5da15bf178433366fd0

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 = [[[' lot1300 ', [['B', ' lot1300 ']]], [' 193261lot', [['B', ' '], ['C', '193261'], ['B', 'lot']]], ['3580131', [['C', '358013'], ['B', '1']]], ['lot17764124x', [['B', 'lot'], ['C', '17764124'], ['B', 'x']]], ['xAB', [['B', 'xAB']]], ['AB', [['B', 'AB']]], ['x15', [['B', 'x15']]], ['lot3821-AB', [['B', 'lot3821-AB']]]], [['741025864Q70329 ', [['C', '74102586'], ['B', '4Q70329 ']]], ['-494318 0580944', [['B', '-'], ['C', '494318'], ['B', ' 0'], ['C', '580944']]], ['Q7lotQ7lot', [['B', 'Q7lotQ7lot']]], ['101874486507729', [['C', '10187448650772'], ['B', '9']]], ['x22', [['B', 'x22']]], [' ', [['B', ' ']]], ['-006', [['B', '-006']]], ['03 2849 ', [['B', '03 2849 ']]]], [['x5197AB', [['B', 'x5197AB']]], ['Q780759lotAB', [['B', 'Q'], ['C', '780759'], ['B', 'lotAB']]], ['0964853799773055547674lot', [['C', '0964853799773055547674'], ['B', 'lot']]], ['lot', [['B', 'lot']]], ['1', [['B', '1']]], ['Q7 lotAB', [['B', 'Q7 lotAB']]], ['-753024468324', [['B', '-'], ['C', '753024468324']]], [' 29428AB ', [['B', ' 29428AB ']]]], [['lot1743-0346174', [['B', 'lot1743-0'], ['C', '346174']]], [' 705791-x', [['B', ' '], ['C', '705791'], ['B', '-x']]], ['3807356726022 ', [['C', '380735672602'], ['B', '2 ']]], ['733-', [['B', '733-']]], ['46450162930', [['C', '4645016293'], ['B', '0']]], [' - ', [['B', ' - ']]], [' Q7', [['B', ' Q7']]], ['Q7lot1604lot', [['B', 'Q7lot1604lot']]]], [['x12345-', [['B', 'x12345-']]], ['-869837ABx', [['B', '-'], ['C', '869837'], ['B', 'ABx']]], ['5776132lot', [['C', '577613'], ['B', '2lot']]], ['xlot045355094', [['B', 'xlot0'], ['C', '45355094']]], ['007775830', [['C', '00777583'], ['B', '0']]], ['AB8', [['B', 'AB8']]], ['014550632960 753', [['C', '014550632960'], ['B', ' 753']]], ['6 25164lot', [['B', '6 25164lot']]]]]
labels = ["regression: mid-data switch threshold", "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: mid-data switch threshold 0[['B', ' lot1300 ']][['B', ' lot1300 ']]Passed
repair trap 1[['B', ' '], ['C', '193261'], ['B', 'lot']][['B', ' '], ['C', '193261'], ['B', 'lot']]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', 'AB']][['B', 'AB']]Passed
boundary 6[['B', 'x15']][['B', 'x15']]Passed
control 7[['B', 'lot3821-AB']][['B', 'lot3821-AB']]Passed

SHA-256 / d4754753281ef7b126f24f3c610dc59b6cadb6845995ac14ab09438275cd9294

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

Case digest / 7575b0cd34d36adf9f82a673bd0202d959c22fb1a3ca4dbd803e9239481d8dde