FAILURE MAP
← Case archive

FA-60201 / Inventory cost layering / Open access

Inter-warehouse transfer of cost layers: freight residual cents · case 01

A few cents of transfer freight disappear from inventory on every transfer.

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

ROOT CAUSE

Residual cents after flooring freight shares are never assigned.

THE FAILURE

Residual cents after flooring freight shares are never assigned.

Unsuccessful approach: Assigning the residual to the last piece contradicts the stipulated first-piece rule.

Case contract

Layers are [qty, total value]. A transfer of qty draws FIFO from src; a partial draw takes floor(t*value/qty) and leaves the residue in src; a layer is removed when its quantity reaches zero. Freight is split across the drawn pieces by quantity (floor), residual cents to the first piece, and each piece is appended to dst in draw order as the newest layers. qty<=0 or qty above src stock returns {"error"}. Return {src, dst}.

Why this case matters

Inventory valuation and cost-of-goods decisions depend on this rule.

1 / The failure

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

N = 1
observations = []
def solve(x):
    src = [list(l) for l in x['src']]
    dst = [list(l) for l in x['dst']]
    q = x['qty']
    if q <= 0 or q > sum(l[0] for l in src):
        return {'error': 'invalid quantity'}
    pieces = []
    while q > 0:
        lq, lv = src[0]
        t = min(q, lq)
        val = lv if t == lq else t * lv // lq
        pieces.append([t, val])
        src[0] = [lq - t, lv - val]
        if src[0][0] == 0:
            src.pop(0)
        q -= t
    fr = x['freight']
    tq = x['qty']
    shares = [fr * p[0] // tq for p in pieces]
    for p, s in zip(pieces, shares):
        dst.append([p[0], p[1] + s])
    return {'src': src, 'dst': dst}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['span layers', {'src': [[3, 100], [5, 260]], 'dst': [[2, 90]], 'qty': 6, 'freight': 101}, {'src': [[2, 104]], 'dst': [[2, 90], [3, 151], [3, 206]]}], ['partial residue', {'src': [[3, 101], [4, 77]], 'dst': [], 'qty': 2, 'freight': 11}, {'src': [[1, 34], [4, 77]], 'dst': [[2, 78]]}], ['odd layer value', {'src': [[4, 99], [1, 5]], 'dst': [], 'qty': 3, 'freight': 1}, {'src': [[1, 25], [1, 5]], 'dst': [[3, 75]]}], ['free goods layer', {'src': [[5, 0], [2, 40]], 'dst': [[1, 10]], 'qty': 2, 'freight': 8}, {'src': [[3, 0], [2, 40]], 'dst': [[1, 10], [2, 8]]}], ['uneven freight', {'src': [[1, 50], [1, 60], [5, 300]], 'dst': [], 'qty': 5, 'freight': 14}, {'src': [[2, 120]], 'dst': [[1, 54], [1, 62], [3, 188]]}], ['insufficient', {'src': [[2, 20]], 'dst': [], 'qty': 4, 'freight': 5}, {'error': 'invalid quantity'}], ['nothing requested', {'src': [[2, 20]], 'dst': [], 'qty': 0, 'freight': 5}, {'error': 'invalid quantity'}], ['exact all', {'src': [[2, 21], [1, 12]], 'dst': [[4, 44]], 'qty': 3, 'freight': 0}, {'src': [], 'dst': [[4, 44], [2, 21], [1, 12]]}]], [['span layers', {'src': [[3, 100], [5, 260]], 'dst': [[2, 90]], 'qty': 5, 'freight': 101}, {'src': [[3, 156]], 'dst': [[2, 90], [3, 161], [2, 144]]}], ['partial residue', {'src': [[3, 101], [4, 77]], 'dst': [], 'qty': 2, 'freight': 12}, {'src': [[1, 34], [4, 77]], 'dst': [[2, 79]]}], ['odd layer value', {'src': [[4, 99], [1, 5]], 'dst': [], 'qty': 3, 'freight': 2}, {'src': [[1, 25], [1, 5]], 'dst': [[3, 76]]}], ['free goods layer', {'src': [[5, 0], [2, 40]], 'dst': [[1, 10]], 'qty': 2, 'freight': 9}, {'src': [[3, 0], [2, 40]], 'dst': [[1, 10], [2, 9]]}], ['uneven freight', {'src': [[1, 50], [1, 60], [5, 300]], 'dst': [], 'qty': 5, 'freight': 15}, {'src': [[2, 120]], 'dst': [[1, 53], [1, 63], [3, 189]]}], ['insufficient', {'src': [[2, 20]], 'dst': [], 'qty': 5, 'freight': 5}, {'error': 'invalid quantity'}], ['nothing requested', {'src': [[2, 20]], 'dst': [], 'qty': 0, 'freight': 5}, {'error': 'invalid quantity'}], ['exact all', {'src': [[2, 21], [1, 13]], 'dst': [[4, 44]], 'qty': 3, 'freight': 0}, {'src': [], 'dst': [[4, 44], [2, 21], [1, 13]]}]], [['span layers', {'src': [[3, 100], [5, 260]], 'dst': [[2, 90]], 'qty': 6, 'freight': 101}, {'src': [[2, 104]], 'dst': [[2, 90], [3, 151], [3, 206]]}], ['partial residue', {'src': [[3, 101], [4, 77]], 'dst': [], 'qty': 2, 'freight': 13}, {'src': [[1, 34], [4, 77]], 'dst': [[2, 80]]}], ['odd layer value', {'src': [[4, 99], [1, 5]], 'dst': [], 'qty': 3, 'freight': 3}, {'src': [[1, 25], [1, 5]], 'dst': [[3, 77]]}], ['free goods layer', {'src': [[5, 0], [2, 40]], 'dst': [[1, 10]], 'qty': 2, 'freight': 10}, {'src': [[3, 0], [2, 40]], 'dst': [[1, 10], [2, 10]]}], ['uneven freight', {'src': [[1, 50], [1, 60], [5, 300]], 'dst': [], 'qty': 5, 'freight': 16}, {'src': [[2, 120]], 'dst': [[1, 54], [1, 63], [3, 189]]}], ['insufficient', {'src': [[2, 20]], 'dst': [], 'qty': 6, 'freight': 5}, {'error': 'invalid quantity'}], ['nothing requested', {'src': [[2, 20]], 'dst': [], 'qty': 0, 'freight': 5}, {'error': 'invalid quantity'}], ['exact all', {'src': [[2, 21], [1, 14]], 'dst': [[4, 44]], 'qty': 3, 'freight': 0}, {'src': [], 'dst': [[4, 44], [2, 21], [1, 14]]}]], [['span layers', {'src': [[3, 100], [5, 260]], 'dst': [[2, 90]], 'qty': 5, 'freight': 101}, {'src': [[3, 156]], 'dst': [[2, 90], [3, 161], [2, 144]]}], ['partial residue', {'src': [[3, 101], [4, 77]], 'dst': [], 'qty': 2, 'freight': 14}, {'src': [[1, 34], [4, 77]], 'dst': [[2, 81]]}], ['odd layer value', {'src': [[4, 99], [1, 5]], 'dst': [], 'qty': 3, 'freight': 4}, {'src': [[1, 25], [1, 5]], 'dst': [[3, 78]]}], ['free goods layer', {'src': [[5, 0], [2, 40]], 'dst': [[1, 10]], 'qty': 2, 'freight': 11}, {'src': [[3, 0], [2, 40]], 'dst': [[1, 10], [2, 11]]}], ['uneven freight', {'src': [[1, 50], [1, 60], [5, 300]], 'dst': [], 'qty': 5, 'freight': 17}, {'src': [[2, 120]], 'dst': [[1, 54], [1, 63], [3, 190]]}], ['insufficient', {'src': [[2, 20]], 'dst': [], 'qty': 7, 'freight': 5}, {'error': 'invalid quantity'}], ['nothing requested', {'src': [[2, 20]], 'dst': [], 'qty': 0, 'freight': 5}, {'error': 'invalid quantity'}], ['exact all', {'src': [[2, 21], [1, 15]], 'dst': [[4, 44]], 'qty': 3, 'freight': 0}, {'src': [], 'dst': [[4, 44], [2, 21], [1, 15]]}]], [['span layers', {'src': [[3, 100], [5, 260]], 'dst': [[2, 90]], 'qty': 6, 'freight': 101}, {'src': [[2, 104]], 'dst': [[2, 90], [3, 151], [3, 206]]}], ['partial residue', {'src': [[3, 101], [4, 77]], 'dst': [], 'qty': 2, 'freight': 15}, {'src': [[1, 34], [4, 77]], 'dst': [[2, 82]]}], ['odd layer value', {'src': [[4, 99], [1, 5]], 'dst': [], 'qty': 3, 'freight': 5}, {'src': [[1, 25], [1, 5]], 'dst': [[3, 79]]}], ['free goods layer', {'src': [[5, 0], [2, 40]], 'dst': [[1, 10]], 'qty': 2, 'freight': 12}, {'src': [[3, 0], [2, 40]], 'dst': [[1, 10], [2, 12]]}], ['uneven freight', {'src': [[1, 50], [1, 60], [5, 300]], 'dst': [], 'qty': 5, 'freight': 18}, {'src': [[2, 120]], 'dst': [[1, 55], [1, 63], [3, 190]]}], ['insufficient', {'src': [[2, 20]], 'dst': [], 'qty': 8, 'freight': 5}, {'error': 'invalid quantity'}], ['nothing requested', {'src': [[2, 20]], 'dst': [], 'qty': 0, 'freight': 5}, {'error': 'invalid quantity'}], ['exact all', {'src': [[2, 21], [1, 16]], 'dst': [[4, 44]], 'qty': 3, 'freight': 0}, {'src': [], 'dst': [[4, 44], [2, 21], [1, 16]]}]]]
for label, args, expected in fixtures[N-1]:
    check(label, 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
span layers{'dst': [[2, 90], [3, 150], [3, 206]], 'src': [[2, 104]]}{'dst': [[2, 90], [3, 151], [3, 206]], 'src': [[2, 104]]}Failed
partial residue{'dst': [[2, 78]], 'src': [[1, 34], [4, 77]]}{'dst': [[2, 78]], 'src': [[1, 34], [4, 77]]}Passed
odd layer value{'dst': [[3, 75]], 'src': [[1, 25], [1, 5]]}{'dst': [[3, 75]], 'src': [[1, 25], [1, 5]]}Passed
free goods layer{'dst': [[1, 10], [2, 8]], 'src': [[3, 0], [2, 40]]}{'dst': [[1, 10], [2, 8]], 'src': [[3, 0], [2, 40]]}Passed
uneven freight{'dst': [[1, 52], [1, 62], [3, 188]], 'src': [[2, 120]]}{'dst': [[1, 54], [1, 62], [3, 188]], 'src': [[2, 120]]}Failed
insufficient{'error': 'invalid quantity'}{'error': 'invalid quantity'}Passed
nothing requested{'error': 'invalid quantity'}{'error': 'invalid quantity'}Passed
exact all{'dst': [[4, 44], [2, 21], [1, 12]], 'src': []}{'dst': [[4, 44], [2, 21], [1, 12]], 'src': []}Passed

SHA-256 / c066ad70ce6220e9e2a426571dc50ef14ae2dbd5dbd5f3c1b80ac108affd01d7

2 / The unsuccessful fix

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

N = 1
observations = []
def solve(x):
    src = [list(l) for l in x['src']]
    dst = [list(l) for l in x['dst']]
    q = x['qty']
    if q <= 0 or q > sum(l[0] for l in src):
        return {'error': 'invalid quantity'}
    pieces = []
    while q > 0:
        lq, lv = src[0]
        t = min(q, lq)
        val = lv if t == lq else t * lv // lq
        pieces.append([t, val])
        src[0] = [lq - t, lv - val]
        if src[0][0] == 0:
            src.pop(0)
        q -= t
    fr = x['freight']
    tq = x['qty']
    shares = [fr * p[0] // tq for p in pieces]
    shares[-1] += fr - sum(shares)
    for p, s in zip(pieces, shares):
        dst.append([p[0], p[1] + s])
    return {'src': src, 'dst': dst}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['span layers', {'src': [[3, 100], [5, 260]], 'dst': [[2, 90]], 'qty': 6, 'freight': 101}, {'src': [[2, 104]], 'dst': [[2, 90], [3, 151], [3, 206]]}], ['partial residue', {'src': [[3, 101], [4, 77]], 'dst': [], 'qty': 2, 'freight': 11}, {'src': [[1, 34], [4, 77]], 'dst': [[2, 78]]}], ['odd layer value', {'src': [[4, 99], [1, 5]], 'dst': [], 'qty': 3, 'freight': 1}, {'src': [[1, 25], [1, 5]], 'dst': [[3, 75]]}], ['free goods layer', {'src': [[5, 0], [2, 40]], 'dst': [[1, 10]], 'qty': 2, 'freight': 8}, {'src': [[3, 0], [2, 40]], 'dst': [[1, 10], [2, 8]]}], ['uneven freight', {'src': [[1, 50], [1, 60], [5, 300]], 'dst': [], 'qty': 5, 'freight': 14}, {'src': [[2, 120]], 'dst': [[1, 54], [1, 62], [3, 188]]}], ['insufficient', {'src': [[2, 20]], 'dst': [], 'qty': 4, 'freight': 5}, {'error': 'invalid quantity'}], ['nothing requested', {'src': [[2, 20]], 'dst': [], 'qty': 0, 'freight': 5}, {'error': 'invalid quantity'}], ['exact all', {'src': [[2, 21], [1, 12]], 'dst': [[4, 44]], 'qty': 3, 'freight': 0}, {'src': [], 'dst': [[4, 44], [2, 21], [1, 12]]}]], [['span layers', {'src': [[3, 100], [5, 260]], 'dst': [[2, 90]], 'qty': 5, 'freight': 101}, {'src': [[3, 156]], 'dst': [[2, 90], [3, 161], [2, 144]]}], ['partial residue', {'src': [[3, 101], [4, 77]], 'dst': [], 'qty': 2, 'freight': 12}, {'src': [[1, 34], [4, 77]], 'dst': [[2, 79]]}], ['odd layer value', {'src': [[4, 99], [1, 5]], 'dst': [], 'qty': 3, 'freight': 2}, {'src': [[1, 25], [1, 5]], 'dst': [[3, 76]]}], ['free goods layer', {'src': [[5, 0], [2, 40]], 'dst': [[1, 10]], 'qty': 2, 'freight': 9}, {'src': [[3, 0], [2, 40]], 'dst': [[1, 10], [2, 9]]}], ['uneven freight', {'src': [[1, 50], [1, 60], [5, 300]], 'dst': [], 'qty': 5, 'freight': 15}, {'src': [[2, 120]], 'dst': [[1, 53], [1, 63], [3, 189]]}], ['insufficient', {'src': [[2, 20]], 'dst': [], 'qty': 5, 'freight': 5}, {'error': 'invalid quantity'}], ['nothing requested', {'src': [[2, 20]], 'dst': [], 'qty': 0, 'freight': 5}, {'error': 'invalid quantity'}], ['exact all', {'src': [[2, 21], [1, 13]], 'dst': [[4, 44]], 'qty': 3, 'freight': 0}, {'src': [], 'dst': [[4, 44], [2, 21], [1, 13]]}]], [['span layers', {'src': [[3, 100], [5, 260]], 'dst': [[2, 90]], 'qty': 6, 'freight': 101}, {'src': [[2, 104]], 'dst': [[2, 90], [3, 151], [3, 206]]}], ['partial residue', {'src': [[3, 101], [4, 77]], 'dst': [], 'qty': 2, 'freight': 13}, {'src': [[1, 34], [4, 77]], 'dst': [[2, 80]]}], ['odd layer value', {'src': [[4, 99], [1, 5]], 'dst': [], 'qty': 3, 'freight': 3}, {'src': [[1, 25], [1, 5]], 'dst': [[3, 77]]}], ['free goods layer', {'src': [[5, 0], [2, 40]], 'dst': [[1, 10]], 'qty': 2, 'freight': 10}, {'src': [[3, 0], [2, 40]], 'dst': [[1, 10], [2, 10]]}], ['uneven freight', {'src': [[1, 50], [1, 60], [5, 300]], 'dst': [], 'qty': 5, 'freight': 16}, {'src': [[2, 120]], 'dst': [[1, 54], [1, 63], [3, 189]]}], ['insufficient', {'src': [[2, 20]], 'dst': [], 'qty': 6, 'freight': 5}, {'error': 'invalid quantity'}], ['nothing requested', {'src': [[2, 20]], 'dst': [], 'qty': 0, 'freight': 5}, {'error': 'invalid quantity'}], ['exact all', {'src': [[2, 21], [1, 14]], 'dst': [[4, 44]], 'qty': 3, 'freight': 0}, {'src': [], 'dst': [[4, 44], [2, 21], [1, 14]]}]], [['span layers', {'src': [[3, 100], [5, 260]], 'dst': [[2, 90]], 'qty': 5, 'freight': 101}, {'src': [[3, 156]], 'dst': [[2, 90], [3, 161], [2, 144]]}], ['partial residue', {'src': [[3, 101], [4, 77]], 'dst': [], 'qty': 2, 'freight': 14}, {'src': [[1, 34], [4, 77]], 'dst': [[2, 81]]}], ['odd layer value', {'src': [[4, 99], [1, 5]], 'dst': [], 'qty': 3, 'freight': 4}, {'src': [[1, 25], [1, 5]], 'dst': [[3, 78]]}], ['free goods layer', {'src': [[5, 0], [2, 40]], 'dst': [[1, 10]], 'qty': 2, 'freight': 11}, {'src': [[3, 0], [2, 40]], 'dst': [[1, 10], [2, 11]]}], ['uneven freight', {'src': [[1, 50], [1, 60], [5, 300]], 'dst': [], 'qty': 5, 'freight': 17}, {'src': [[2, 120]], 'dst': [[1, 54], [1, 63], [3, 190]]}], ['insufficient', {'src': [[2, 20]], 'dst': [], 'qty': 7, 'freight': 5}, {'error': 'invalid quantity'}], ['nothing requested', {'src': [[2, 20]], 'dst': [], 'qty': 0, 'freight': 5}, {'error': 'invalid quantity'}], ['exact all', {'src': [[2, 21], [1, 15]], 'dst': [[4, 44]], 'qty': 3, 'freight': 0}, {'src': [], 'dst': [[4, 44], [2, 21], [1, 15]]}]], [['span layers', {'src': [[3, 100], [5, 260]], 'dst': [[2, 90]], 'qty': 6, 'freight': 101}, {'src': [[2, 104]], 'dst': [[2, 90], [3, 151], [3, 206]]}], ['partial residue', {'src': [[3, 101], [4, 77]], 'dst': [], 'qty': 2, 'freight': 15}, {'src': [[1, 34], [4, 77]], 'dst': [[2, 82]]}], ['odd layer value', {'src': [[4, 99], [1, 5]], 'dst': [], 'qty': 3, 'freight': 5}, {'src': [[1, 25], [1, 5]], 'dst': [[3, 79]]}], ['free goods layer', {'src': [[5, 0], [2, 40]], 'dst': [[1, 10]], 'qty': 2, 'freight': 12}, {'src': [[3, 0], [2, 40]], 'dst': [[1, 10], [2, 12]]}], ['uneven freight', {'src': [[1, 50], [1, 60], [5, 300]], 'dst': [], 'qty': 5, 'freight': 18}, {'src': [[2, 120]], 'dst': [[1, 55], [1, 63], [3, 190]]}], ['insufficient', {'src': [[2, 20]], 'dst': [], 'qty': 8, 'freight': 5}, {'error': 'invalid quantity'}], ['nothing requested', {'src': [[2, 20]], 'dst': [], 'qty': 0, 'freight': 5}, {'error': 'invalid quantity'}], ['exact all', {'src': [[2, 21], [1, 16]], 'dst': [[4, 44]], 'qty': 3, 'freight': 0}, {'src': [], 'dst': [[4, 44], [2, 21], [1, 16]]}]]]
for label, args, expected in fixtures[N-1]:
    check(label, 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
span layers{'dst': [[2, 90], [3, 150], [3, 207]], 'src': [[2, 104]]}{'dst': [[2, 90], [3, 151], [3, 206]], 'src': [[2, 104]]}Failed
partial residue{'dst': [[2, 78]], 'src': [[1, 34], [4, 77]]}{'dst': [[2, 78]], 'src': [[1, 34], [4, 77]]}Passed
odd layer value{'dst': [[3, 75]], 'src': [[1, 25], [1, 5]]}{'dst': [[3, 75]], 'src': [[1, 25], [1, 5]]}Passed
free goods layer{'dst': [[1, 10], [2, 8]], 'src': [[3, 0], [2, 40]]}{'dst': [[1, 10], [2, 8]], 'src': [[3, 0], [2, 40]]}Passed
uneven freight{'dst': [[1, 52], [1, 62], [3, 190]], 'src': [[2, 120]]}{'dst': [[1, 54], [1, 62], [3, 188]], 'src': [[2, 120]]}Failed
insufficient{'error': 'invalid quantity'}{'error': 'invalid quantity'}Passed
nothing requested{'error': 'invalid quantity'}{'error': 'invalid quantity'}Passed
exact all{'dst': [[4, 44], [2, 21], [1, 12]], 'src': []}{'dst': [[4, 44], [2, 21], [1, 12]], 'src': []}Passed

SHA-256 / d6f0416206960f13103e25ef45b7075ebf8a39bb41141dbc9c8e3abeb49bbb55

HELD IN THE MEMBER ARCHIVE

The verified repair and its recorded checks are member-only.

This mechanism has 8 recorded checks per implementation. The open-access tier publishes the failure and the unsuccessful fix; the repaired source that passes every check, and the observations that prove it, are available to members.

Every case sharing this mechanism uses the same contract and the same repair, so this one record is held back for all of them.

Member access is invitation-based. Sign in with your invited account to inspect the repair.

Sign in to the archive ↗

Verification & scope

Stipulated bounded teaching model with explicit toy rules; not an accounting-standard implementation. 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:46:43.449550+00:00.

Case digest / 06a95ea05e1355c82650f475e3c9b05ad29a51a091d2cea1d63d48fe061003f1