FAILURE MAP
← Case archive

FA-79481 / Barcode symbology encoding / Open access

Code 39 accepts a 4:1 wide ratio · case 01

Symbols printed with an out-of-range ratio are wider than planned and fail grading.

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

ROOT CAUSE

Only ratios below 2 are rejected.

VERIFIED REPAIR

Accept exactly the supported ratios 2 and 3.

Unsuccessful approach: Rejecting only ratios above 3 lets 1:1 symbols through, which cannot be decoded.

Case contract

Encode text for Code 39 with a wide:narrow ratio of 2 or 3. Standard mode accepts only the 43 characters 0-9 A-Z - . space $ / + %. Full ASCII mode maps lowercase to "+" plus the capital, controls 1..26 to "$" plus A..Z, NUL to %U, 27..31 to %A..%E, DEL to %T, and punctuation (including the four standard shift characters $ % + /) to its two-character escape. Every symbol character, including the start/stop "*", has 6 narrow and 3 wide elements, and one narrow gap separates adjacent characters. Return the framed data and the total width in narrow modules.

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(text, mode, ratio):
    std = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%'
    if ratio < 2:
        return {'error': 'ratio'}
    if mode == 'standard':
        for ch in text:
            if ch not in std:
                return {'error': 'char', 'char': ch}
        enc = text
    else:
        punct = {'$': '/D', '%': '/E', '+': '/K', '/': '/O', '!': '/A', '"': '/B', '#': '/C', '&': '/F', "'": '/G',
                 '(': '/H', ')': '/I', '*': '/J', ',': '/L', ':': '/Z', ';': '%F', '<': '%G', '=': '%H', '>': '%I',
                 '?': '%J', '@': '%V', '[': '%K', '\\': '%L', ']': '%M', '^': '%N', '_': '%O', '`': '%W',
                 '{': '%P', '|': '%Q', '}': '%R', '~': '%S'}
        enc = ''
        for ch in text:
            o = ord(ch)
            if o > 127:
                return {'error': 'char', 'char': ch}
            if ch in punct:
                enc += punct[ch]
            elif 'a' <= ch <= 'z':
                enc += '+' + ch.upper()
            elif 1 <= o <= 26:
                enc += '$' + chr(o + 64)
            elif o == 0:
                enc += '%U'
            elif 27 <= o <= 31:
                enc += '%' + chr(o - 27 + 65)
            elif o == 127:
                enc += '%T'
            else:
                enc += ch
    count = len(enc) + 2
    return {'data': '*' + enc + '*', 'modules': count * (6 + 3 * ratio) + (count - 1)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[('café', 'standard', 4), {'error': 'ratio'}], [('ABPN/7PN/7', 'full', 1), {'error': 'ratio'}], [('Z-9a+blot', 'standard', 2), {'error': 'char', 'char': 'a'}], [('PN/7PN/7$5', 'full', 3), {'data': '*PN/O7PN/O7/D5*', 'modules': 239}], [('\x1b', 'full', 2), {'data': '*%A*', 'modules': 51}], [('', 'full', 3), {'data': '**', 'modules': 31}], [('café', 'standard', 3), {'error': 'char', 'char': 'c'}], [('a+ba+b', 'full', 4), {'error': 'ratio'}]], [[('\x00caféq', 'full', 4), {'error': 'ratio'}], [('', 'standard', 1), {'error': 'ratio'}], [('\x1blotlot', 'full', 2), {'data': '*%A+L+O+T+L+O+T*', 'modules': 207}], [('#1', 'full', 2), {'data': '*/C1*', 'modules': 64}], [('ABa+b', 'full', 2), {'data': '*AB+A/K+B*', 'modules': 129}], [('', 'full', 3), {'data': '**', 'modules': 31}], [('\x1b', 'full', 2), {'data': '*%A*', 'modules': 51}], [('q$5café', 'standard', 4), {'error': 'ratio'}]], [[('\x7f#1', 'standard', 4), {'error': 'ratio'}], [(' ', 'full', 1), {'error': 'ratio'}], [('$5 \x00', 'full', 2), {'data': '*/D5 %U*', 'modules': 103}], [('$550%', 'full', 3), {'data': '*/D550/E*', 'modules': 143}], [('*\x1bcafé', 'full', 2), {'error': 'char', 'char': 'é'}], [('q \x00', 'full', 2), {'data': '*+Q %U*', 'modules': 90}], [('xcafé50%', 'standard', 3), {'error': 'char', 'char': 'x'}], [('', 'full', 4), {'error': 'ratio'}]], [[('a+blot\x1b', 'full', 4), {'error': 'ratio'}], [('', 'full', 1), {'error': 'ratio'}], [('qPN/7café', 'full', 2), {'error': 'char', 'char': 'é'}], [('*', 'full', 2), {'data': '*/J*', 'modules': 51}], [('AB12', 'standard', 2), {'data': '*AB12*', 'modules': 77}], [('\x7f\tlot', 'full', 3), {'data': '*%T$I+L+O+T*', 'modules': 191}], [('#1café', 'full', 2), {'error': 'char', 'char': 'é'}], [('PN/7', 'full', 4), {'error': 'ratio'}]], [[('PN/7', 'standard', 4), {'error': 'ratio'}], [('\x7f$5', 'full', 1), {'error': 'ratio'}], [('$5lot', 'full', 3), {'data': '*/D5+L+O+T*', 'modules': 175}], [('', 'standard', 2), {'data': '**', 'modules': 25}], [('$5a+bAB', 'full', 3), {'data': '*/D5+A/K+BAB*', 'modules': 207}], [('#112\x7f', 'full', 3), {'data': '*/C112%T*', 'modules': 143}], [('q*PN/7', 'standard', 2), {'error': 'char', 'char': 'q'}], [('Z-9$512', 'standard', 4), {'error': 'ratio'}]]]
labels = ["regression: wide to narrow ratio validation", "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: wide to narrow ratio validation 0{'char': 'c', 'error': 'char'}{'error': 'ratio'}Failed
repair trap 1{'error': 'ratio'}{'error': 'ratio'}Passed
combined fault 2{'char': 'a', 'error': 'char'}{'char': 'a', 'error': 'char'}Passed
control 3{'data': '*PN/O7PN/O7/D5*', 'modules': 239}{'data': '*PN/O7PN/O7/D5*', 'modules': 239}Passed
control 4{'data': '*%A*', 'modules': 51}{'data': '*%A*', 'modules': 51}Passed
boundary 5{'data': '**', 'modules': 31}{'data': '**', 'modules': 31}Passed
boundary 6{'char': 'c', 'error': 'char'}{'char': 'c', 'error': 'char'}Passed
control 7{'data': '*+A/K+B+A/K+B*', 'modules': 265}{'error': 'ratio'}Failed

SHA-256 / 3755bc2f05607a6ff8ec3a437a6563d5e1d4de6d3ba70556036543076ae35288

2 / The unsuccessful fix

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

N = 1
observations = []
def solve(text, mode, ratio):
    std = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%'
    if ratio > 3:
        return {'error': 'ratio'}
    if mode == 'standard':
        for ch in text:
            if ch not in std:
                return {'error': 'char', 'char': ch}
        enc = text
    else:
        punct = {'$': '/D', '%': '/E', '+': '/K', '/': '/O', '!': '/A', '"': '/B', '#': '/C', '&': '/F', "'": '/G',
                 '(': '/H', ')': '/I', '*': '/J', ',': '/L', ':': '/Z', ';': '%F', '<': '%G', '=': '%H', '>': '%I',
                 '?': '%J', '@': '%V', '[': '%K', '\\': '%L', ']': '%M', '^': '%N', '_': '%O', '`': '%W',
                 '{': '%P', '|': '%Q', '}': '%R', '~': '%S'}
        enc = ''
        for ch in text:
            o = ord(ch)
            if o > 127:
                return {'error': 'char', 'char': ch}
            if ch in punct:
                enc += punct[ch]
            elif 'a' <= ch <= 'z':
                enc += '+' + ch.upper()
            elif 1 <= o <= 26:
                enc += '$' + chr(o + 64)
            elif o == 0:
                enc += '%U'
            elif 27 <= o <= 31:
                enc += '%' + chr(o - 27 + 65)
            elif o == 127:
                enc += '%T'
            else:
                enc += ch
    count = len(enc) + 2
    return {'data': '*' + enc + '*', 'modules': count * (6 + 3 * ratio) + (count - 1)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[('café', 'standard', 4), {'error': 'ratio'}], [('ABPN/7PN/7', 'full', 1), {'error': 'ratio'}], [('Z-9a+blot', 'standard', 2), {'error': 'char', 'char': 'a'}], [('PN/7PN/7$5', 'full', 3), {'data': '*PN/O7PN/O7/D5*', 'modules': 239}], [('\x1b', 'full', 2), {'data': '*%A*', 'modules': 51}], [('', 'full', 3), {'data': '**', 'modules': 31}], [('café', 'standard', 3), {'error': 'char', 'char': 'c'}], [('a+ba+b', 'full', 4), {'error': 'ratio'}]], [[('\x00caféq', 'full', 4), {'error': 'ratio'}], [('', 'standard', 1), {'error': 'ratio'}], [('\x1blotlot', 'full', 2), {'data': '*%A+L+O+T+L+O+T*', 'modules': 207}], [('#1', 'full', 2), {'data': '*/C1*', 'modules': 64}], [('ABa+b', 'full', 2), {'data': '*AB+A/K+B*', 'modules': 129}], [('', 'full', 3), {'data': '**', 'modules': 31}], [('\x1b', 'full', 2), {'data': '*%A*', 'modules': 51}], [('q$5café', 'standard', 4), {'error': 'ratio'}]], [[('\x7f#1', 'standard', 4), {'error': 'ratio'}], [(' ', 'full', 1), {'error': 'ratio'}], [('$5 \x00', 'full', 2), {'data': '*/D5 %U*', 'modules': 103}], [('$550%', 'full', 3), {'data': '*/D550/E*', 'modules': 143}], [('*\x1bcafé', 'full', 2), {'error': 'char', 'char': 'é'}], [('q \x00', 'full', 2), {'data': '*+Q %U*', 'modules': 90}], [('xcafé50%', 'standard', 3), {'error': 'char', 'char': 'x'}], [('', 'full', 4), {'error': 'ratio'}]], [[('a+blot\x1b', 'full', 4), {'error': 'ratio'}], [('', 'full', 1), {'error': 'ratio'}], [('qPN/7café', 'full', 2), {'error': 'char', 'char': 'é'}], [('*', 'full', 2), {'data': '*/J*', 'modules': 51}], [('AB12', 'standard', 2), {'data': '*AB12*', 'modules': 77}], [('\x7f\tlot', 'full', 3), {'data': '*%T$I+L+O+T*', 'modules': 191}], [('#1café', 'full', 2), {'error': 'char', 'char': 'é'}], [('PN/7', 'full', 4), {'error': 'ratio'}]], [[('PN/7', 'standard', 4), {'error': 'ratio'}], [('\x7f$5', 'full', 1), {'error': 'ratio'}], [('$5lot', 'full', 3), {'data': '*/D5+L+O+T*', 'modules': 175}], [('', 'standard', 2), {'data': '**', 'modules': 25}], [('$5a+bAB', 'full', 3), {'data': '*/D5+A/K+BAB*', 'modules': 207}], [('#112\x7f', 'full', 3), {'data': '*/C112%T*', 'modules': 143}], [('q*PN/7', 'standard', 2), {'error': 'char', 'char': 'q'}], [('Z-9$512', 'standard', 4), {'error': 'ratio'}]]]
labels = ["regression: wide to narrow ratio validation", "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: wide to narrow ratio validation 0{'error': 'ratio'}{'error': 'ratio'}Passed
repair trap 1{'data': '*ABPN/O7PN/O7*', 'modules': 139}{'error': 'ratio'}Failed
combined fault 2{'char': 'a', 'error': 'char'}{'char': 'a', 'error': 'char'}Passed
control 3{'data': '*PN/O7PN/O7/D5*', 'modules': 239}{'data': '*PN/O7PN/O7/D5*', 'modules': 239}Passed
control 4{'data': '*%A*', 'modules': 51}{'data': '*%A*', 'modules': 51}Passed
boundary 5{'data': '**', 'modules': 31}{'data': '**', 'modules': 31}Passed
boundary 6{'char': 'c', 'error': 'char'}{'char': 'c', 'error': 'char'}Passed
control 7{'error': 'ratio'}{'error': 'ratio'}Passed

SHA-256 / 670412e0b64faa96b4e8d8447f600af1965148ecece0b035cc46db7a7b3323d9

3 / The verified repair

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

N = 1
observations = []
def solve(text, mode, ratio):
    std = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%'
    if ratio not in (2, 3):
        return {'error': 'ratio'}
    if mode == 'standard':
        for ch in text:
            if ch not in std:
                return {'error': 'char', 'char': ch}
        enc = text
    else:
        punct = {'$': '/D', '%': '/E', '+': '/K', '/': '/O', '!': '/A', '"': '/B', '#': '/C', '&': '/F', "'": '/G',
                 '(': '/H', ')': '/I', '*': '/J', ',': '/L', ':': '/Z', ';': '%F', '<': '%G', '=': '%H', '>': '%I',
                 '?': '%J', '@': '%V', '[': '%K', '\\': '%L', ']': '%M', '^': '%N', '_': '%O', '`': '%W',
                 '{': '%P', '|': '%Q', '}': '%R', '~': '%S'}
        enc = ''
        for ch in text:
            o = ord(ch)
            if o > 127:
                return {'error': 'char', 'char': ch}
            if ch in punct:
                enc += punct[ch]
            elif 'a' <= ch <= 'z':
                enc += '+' + ch.upper()
            elif 1 <= o <= 26:
                enc += '$' + chr(o + 64)
            elif o == 0:
                enc += '%U'
            elif 27 <= o <= 31:
                enc += '%' + chr(o - 27 + 65)
            elif o == 127:
                enc += '%T'
            else:
                enc += ch
    count = len(enc) + 2
    return {'data': '*' + enc + '*', 'modules': count * (6 + 3 * ratio) + (count - 1)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[('café', 'standard', 4), {'error': 'ratio'}], [('ABPN/7PN/7', 'full', 1), {'error': 'ratio'}], [('Z-9a+blot', 'standard', 2), {'error': 'char', 'char': 'a'}], [('PN/7PN/7$5', 'full', 3), {'data': '*PN/O7PN/O7/D5*', 'modules': 239}], [('\x1b', 'full', 2), {'data': '*%A*', 'modules': 51}], [('', 'full', 3), {'data': '**', 'modules': 31}], [('café', 'standard', 3), {'error': 'char', 'char': 'c'}], [('a+ba+b', 'full', 4), {'error': 'ratio'}]], [[('\x00caféq', 'full', 4), {'error': 'ratio'}], [('', 'standard', 1), {'error': 'ratio'}], [('\x1blotlot', 'full', 2), {'data': '*%A+L+O+T+L+O+T*', 'modules': 207}], [('#1', 'full', 2), {'data': '*/C1*', 'modules': 64}], [('ABa+b', 'full', 2), {'data': '*AB+A/K+B*', 'modules': 129}], [('', 'full', 3), {'data': '**', 'modules': 31}], [('\x1b', 'full', 2), {'data': '*%A*', 'modules': 51}], [('q$5café', 'standard', 4), {'error': 'ratio'}]], [[('\x7f#1', 'standard', 4), {'error': 'ratio'}], [(' ', 'full', 1), {'error': 'ratio'}], [('$5 \x00', 'full', 2), {'data': '*/D5 %U*', 'modules': 103}], [('$550%', 'full', 3), {'data': '*/D550/E*', 'modules': 143}], [('*\x1bcafé', 'full', 2), {'error': 'char', 'char': 'é'}], [('q \x00', 'full', 2), {'data': '*+Q %U*', 'modules': 90}], [('xcafé50%', 'standard', 3), {'error': 'char', 'char': 'x'}], [('', 'full', 4), {'error': 'ratio'}]], [[('a+blot\x1b', 'full', 4), {'error': 'ratio'}], [('', 'full', 1), {'error': 'ratio'}], [('qPN/7café', 'full', 2), {'error': 'char', 'char': 'é'}], [('*', 'full', 2), {'data': '*/J*', 'modules': 51}], [('AB12', 'standard', 2), {'data': '*AB12*', 'modules': 77}], [('\x7f\tlot', 'full', 3), {'data': '*%T$I+L+O+T*', 'modules': 191}], [('#1café', 'full', 2), {'error': 'char', 'char': 'é'}], [('PN/7', 'full', 4), {'error': 'ratio'}]], [[('PN/7', 'standard', 4), {'error': 'ratio'}], [('\x7f$5', 'full', 1), {'error': 'ratio'}], [('$5lot', 'full', 3), {'data': '*/D5+L+O+T*', 'modules': 175}], [('', 'standard', 2), {'data': '**', 'modules': 25}], [('$5a+bAB', 'full', 3), {'data': '*/D5+A/K+BAB*', 'modules': 207}], [('#112\x7f', 'full', 3), {'data': '*/C112%T*', 'modules': 143}], [('q*PN/7', 'standard', 2), {'error': 'char', 'char': 'q'}], [('Z-9$512', 'standard', 4), {'error': 'ratio'}]]]
labels = ["regression: wide to narrow ratio validation", "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: wide to narrow ratio validation 0{'error': 'ratio'}{'error': 'ratio'}Passed
repair trap 1{'error': 'ratio'}{'error': 'ratio'}Passed
combined fault 2{'char': 'a', 'error': 'char'}{'char': 'a', 'error': 'char'}Passed
control 3{'data': '*PN/O7PN/O7/D5*', 'modules': 239}{'data': '*PN/O7PN/O7/D5*', 'modules': 239}Passed
control 4{'data': '*%A*', 'modules': 51}{'data': '*%A*', 'modules': 51}Passed
boundary 5{'data': '**', 'modules': 31}{'data': '**', 'modules': 31}Passed
boundary 6{'char': 'c', 'error': 'char'}{'char': 'c', 'error': 'char'}Passed
control 7{'error': 'ratio'}{'error': 'ratio'}Passed

SHA-256 / 0ff839737dbecf8387d251526cb7d692f8448e192db56325c91fa290505bcab4

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

Case digest / c78a4d86ebc9528249e8120e827cb72e16f49506627bee5fd8df07c31419a8a5