FAILURE MAP
← Case archive

FA-81806 / MIDI event timing / Open access

MIDI Time Code quarter-frame assembly: rate bits leak into the hour · case 01

At 25 fps the rate-code bits are folded into the hours field, so 01:02:03 decodes with hour 9 after wrapping.

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

ROOT CAUSE

Piece 7 is shifted into the hours without masking off the rate-code bits.

VERIFIED REPAIR

Restore the hours high bit step so that it reads `(nib[7] & 0x1) << 4`.

Unsuccessful approach: Masking two bits still includes the low rate-code bit in the hours.

Case contract

Input the data bytes of received quarter-frame messages. The last eight must carry piece numbers 0..7 (high nibble) in order; low nibbles give frames (pieces 0,1 as low/high nibble), seconds (2,3), minutes (4,5) and hours (6 low nibble, piece 7 bit 0 as hours bit 4); piece 7 bits 1-2 give the rate code (0: 24, 1: 25, 2: 30 drop, 3: 30 fps). The reported time is the decoded time plus 2 frames, carried into seconds, minutes and hours (mod 24). Return [h, m, s, f, rate_code] or None.

Why this case matters

MIDI sequencers, file readers and synth drivers depend on exact event ordering and tick/time arithmetic.

1 / The failure

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

N = 1
observations = []
def solve(x):
    if not isinstance(x, list) or len(x) < 8:
        return None
    last8 = x[-8:]
    if [b >> 4 for b in last8] != list(range(8)):
        return None
    nib = [b & 0x0F for b in last8]
    frames = nib[0] | (nib[1] << 4)
    secs = nib[2] | (nib[3] << 4)
    mins = nib[4] | (nib[5] << 4)
    hours = nib[6] | (nib[7] << 4)
    rate = (nib[7] >> 1) & 0x3
    fps = [24, 25, 30, 30][rate]
    frames += 2
    secs += frames // fps
    frames %= fps
    mins += secs // 60
    secs %= 60
    hours = (hours + mins // 60) % 24
    mins %= 60
    return [hours, mins, secs, frames, rate]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([0, 16, 32, 48, 64, 80, 96, 112], [0, 0, 0, 2, 0]), ([5, 17, 32, 48, 64, 80, 96, 114], [0, 0, 0, 23, 1]), ([10, 16, 47, 48, 78, 81, 97, 117], [17, 30, 15, 12, 2]), ([7, 17, 43, 51, 75, 83, 103, 113], [0, 0, 0, 1, 0]), ([12, 17, 43, 51, 75, 83, 103, 119], [0, 0, 0, 0, 3]), ([6, 17, 43, 51, 75, 83, 102, 113], [23, 0, 0, 0, 0]), ([0, 16, 32, 48, 64, 80, 96], None), ([16, 32, 48, 64, 80, 96, 112, 0], None)], [([5, 17, 32, 48, 64, 80, 96, 114], [0, 0, 0, 23, 1]), ([4, 16, 35, 48, 66, 80, 97, 114], [1, 2, 3, 6, 1]), ([10, 16, 47, 48, 78, 81, 97, 117], [17, 30, 15, 12, 2]), ([8, 17, 43, 51, 75, 83, 97, 114], [2, 0, 0, 1, 1]), ([0, 16, 32, 48, 64, 80, 96], None), ([16, 32, 48, 64, 80, 96, 112, 0], None), ([3, 0, 16, 32, 48, 64, 80, 98, 112], [2, 0, 0, 2, 0]), ([9, 16, 41, 48, 73, 80, 105, 112], [9, 9, 9, 11, 0])], [([5, 17, 32, 48, 64, 80, 96, 114], [0, 0, 0, 23, 1]), ([4, 16, 35, 48, 66, 80, 97, 114], [1, 2, 3, 6, 1]), ([10, 16, 47, 48, 78, 81, 97, 117], [17, 30, 15, 12, 2]), ([0, 16, 32, 48, 64, 80, 100, 119], [20, 0, 0, 2, 3]), ([12, 17, 43, 51, 75, 83, 103, 119], [0, 0, 0, 0, 3]), ([8, 17, 43, 51, 75, 83, 97, 114], [2, 0, 0, 1, 1]), ([7, 16, 38, 48, 69, 80, 96, 115], [16, 5, 6, 9, 1]), ([9, 16, 41, 48, 73, 80, 105, 112], [9, 9, 9, 11, 0])], [([10, 16, 47, 48, 78, 81, 97, 117], [17, 30, 15, 12, 2]), ([0, 16, 32, 48, 64, 80, 100, 119], [20, 0, 0, 2, 3]), ([12, 17, 43, 51, 75, 83, 103, 119], [0, 0, 0, 0, 3]), ([8, 17, 43, 51, 75, 83, 97, 114], [2, 0, 0, 1, 1]), ([7, 16, 38, 48, 69, 80, 96, 115], [16, 5, 6, 9, 1]), ([13, 17, 43, 51, 64, 80, 99, 117], [19, 1, 0, 1, 2]), ([4, 17, 40, 51, 66, 82, 108, 118], [12, 34, 56, 22, 3]), ([8, 17, 43, 51, 75, 83, 103, 115], [0, 0, 0, 1, 1])], [([0, 16, 32, 48, 64, 80, 96, 112], [0, 0, 0, 2, 0]), ([7, 17, 43, 51, 75, 83, 103, 113], [0, 0, 0, 1, 0]), ([8, 17, 43, 51, 75, 83, 97, 114], [2, 0, 0, 1, 1]), ([7, 16, 38, 48, 69, 80, 96, 115], [16, 5, 6, 9, 1]), ([13, 17, 43, 51, 64, 80, 99, 117], [19, 1, 0, 1, 2]), ([6, 17, 43, 51, 75, 83, 102, 113], [23, 0, 0, 0, 0]), ([4, 17, 40, 51, 66, 82, 108, 118], [12, 34, 56, 22, 3]), ([8, 17, 43, 51, 75, 83, 103, 115], [0, 0, 0, 1, 1])]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("oracle %d" % 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
oracle 0[0, 0, 0, 2, 0][0, 0, 0, 2, 0]Passed
oracle 1[8, 0, 0, 23, 1][0, 0, 0, 23, 1]Failed
oracle 2[9, 30, 15, 12, 2][17, 30, 15, 12, 2]Failed
oracle 3[0, 0, 0, 1, 0][0, 0, 0, 1, 0]Passed
oracle 4[0, 0, 0, 0, 3][0, 0, 0, 0, 3]Passed
oracle 5[23, 0, 0, 0, 0][23, 0, 0, 0, 0]Passed
oracle 6NoneNonePassed
oracle 7NoneNonePassed

SHA-256 / 1c2e9cc7d2c51b9c5fcae959a320a089c7d38f7590253ad8445440298206fa21

2 / The unsuccessful fix

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

N = 1
observations = []
def solve(x):
    if not isinstance(x, list) or len(x) < 8:
        return None
    last8 = x[-8:]
    if [b >> 4 for b in last8] != list(range(8)):
        return None
    nib = [b & 0x0F for b in last8]
    frames = nib[0] | (nib[1] << 4)
    secs = nib[2] | (nib[3] << 4)
    mins = nib[4] | (nib[5] << 4)
    hours = nib[6] | ((nib[7] & 0x3) << 4)
    rate = (nib[7] >> 1) & 0x3
    fps = [24, 25, 30, 30][rate]
    frames += 2
    secs += frames // fps
    frames %= fps
    mins += secs // 60
    secs %= 60
    hours = (hours + mins // 60) % 24
    mins %= 60
    return [hours, mins, secs, frames, rate]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([0, 16, 32, 48, 64, 80, 96, 112], [0, 0, 0, 2, 0]), ([5, 17, 32, 48, 64, 80, 96, 114], [0, 0, 0, 23, 1]), ([10, 16, 47, 48, 78, 81, 97, 117], [17, 30, 15, 12, 2]), ([7, 17, 43, 51, 75, 83, 103, 113], [0, 0, 0, 1, 0]), ([12, 17, 43, 51, 75, 83, 103, 119], [0, 0, 0, 0, 3]), ([6, 17, 43, 51, 75, 83, 102, 113], [23, 0, 0, 0, 0]), ([0, 16, 32, 48, 64, 80, 96], None), ([16, 32, 48, 64, 80, 96, 112, 0], None)], [([5, 17, 32, 48, 64, 80, 96, 114], [0, 0, 0, 23, 1]), ([4, 16, 35, 48, 66, 80, 97, 114], [1, 2, 3, 6, 1]), ([10, 16, 47, 48, 78, 81, 97, 117], [17, 30, 15, 12, 2]), ([8, 17, 43, 51, 75, 83, 97, 114], [2, 0, 0, 1, 1]), ([0, 16, 32, 48, 64, 80, 96], None), ([16, 32, 48, 64, 80, 96, 112, 0], None), ([3, 0, 16, 32, 48, 64, 80, 98, 112], [2, 0, 0, 2, 0]), ([9, 16, 41, 48, 73, 80, 105, 112], [9, 9, 9, 11, 0])], [([5, 17, 32, 48, 64, 80, 96, 114], [0, 0, 0, 23, 1]), ([4, 16, 35, 48, 66, 80, 97, 114], [1, 2, 3, 6, 1]), ([10, 16, 47, 48, 78, 81, 97, 117], [17, 30, 15, 12, 2]), ([0, 16, 32, 48, 64, 80, 100, 119], [20, 0, 0, 2, 3]), ([12, 17, 43, 51, 75, 83, 103, 119], [0, 0, 0, 0, 3]), ([8, 17, 43, 51, 75, 83, 97, 114], [2, 0, 0, 1, 1]), ([7, 16, 38, 48, 69, 80, 96, 115], [16, 5, 6, 9, 1]), ([9, 16, 41, 48, 73, 80, 105, 112], [9, 9, 9, 11, 0])], [([10, 16, 47, 48, 78, 81, 97, 117], [17, 30, 15, 12, 2]), ([0, 16, 32, 48, 64, 80, 100, 119], [20, 0, 0, 2, 3]), ([12, 17, 43, 51, 75, 83, 103, 119], [0, 0, 0, 0, 3]), ([8, 17, 43, 51, 75, 83, 97, 114], [2, 0, 0, 1, 1]), ([7, 16, 38, 48, 69, 80, 96, 115], [16, 5, 6, 9, 1]), ([13, 17, 43, 51, 64, 80, 99, 117], [19, 1, 0, 1, 2]), ([4, 17, 40, 51, 66, 82, 108, 118], [12, 34, 56, 22, 3]), ([8, 17, 43, 51, 75, 83, 103, 115], [0, 0, 0, 1, 1])], [([0, 16, 32, 48, 64, 80, 96, 112], [0, 0, 0, 2, 0]), ([7, 17, 43, 51, 75, 83, 103, 113], [0, 0, 0, 1, 0]), ([8, 17, 43, 51, 75, 83, 97, 114], [2, 0, 0, 1, 1]), ([7, 16, 38, 48, 69, 80, 96, 115], [16, 5, 6, 9, 1]), ([13, 17, 43, 51, 64, 80, 99, 117], [19, 1, 0, 1, 2]), ([6, 17, 43, 51, 75, 83, 102, 113], [23, 0, 0, 0, 0]), ([4, 17, 40, 51, 66, 82, 108, 118], [12, 34, 56, 22, 3]), ([8, 17, 43, 51, 75, 83, 103, 115], [0, 0, 0, 1, 1])]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("oracle %d" % 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
oracle 0[0, 0, 0, 2, 0][0, 0, 0, 2, 0]Passed
oracle 1[8, 0, 0, 23, 1][0, 0, 0, 23, 1]Failed
oracle 2[17, 30, 15, 12, 2][17, 30, 15, 12, 2]Passed
oracle 3[0, 0, 0, 1, 0][0, 0, 0, 1, 0]Passed
oracle 4[8, 0, 0, 0, 3][0, 0, 0, 0, 3]Failed
oracle 5[23, 0, 0, 0, 0][23, 0, 0, 0, 0]Passed
oracle 6NoneNonePassed
oracle 7NoneNonePassed

SHA-256 / aaacf8ffc6211b501609f0632993c517c19ba5080e423be482d0bb16c1e5008e

3 / The verified repair

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

N = 1
observations = []
def solve(x):
    if not isinstance(x, list) or len(x) < 8:
        return None
    last8 = x[-8:]
    if [b >> 4 for b in last8] != list(range(8)):
        return None
    nib = [b & 0x0F for b in last8]
    frames = nib[0] | (nib[1] << 4)
    secs = nib[2] | (nib[3] << 4)
    mins = nib[4] | (nib[5] << 4)
    hours = nib[6] | ((nib[7] & 0x1) << 4)
    rate = (nib[7] >> 1) & 0x3
    fps = [24, 25, 30, 30][rate]
    frames += 2
    secs += frames // fps
    frames %= fps
    mins += secs // 60
    secs %= 60
    hours = (hours + mins // 60) % 24
    mins %= 60
    return [hours, mins, secs, frames, rate]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([0, 16, 32, 48, 64, 80, 96, 112], [0, 0, 0, 2, 0]), ([5, 17, 32, 48, 64, 80, 96, 114], [0, 0, 0, 23, 1]), ([10, 16, 47, 48, 78, 81, 97, 117], [17, 30, 15, 12, 2]), ([7, 17, 43, 51, 75, 83, 103, 113], [0, 0, 0, 1, 0]), ([12, 17, 43, 51, 75, 83, 103, 119], [0, 0, 0, 0, 3]), ([6, 17, 43, 51, 75, 83, 102, 113], [23, 0, 0, 0, 0]), ([0, 16, 32, 48, 64, 80, 96], None), ([16, 32, 48, 64, 80, 96, 112, 0], None)], [([5, 17, 32, 48, 64, 80, 96, 114], [0, 0, 0, 23, 1]), ([4, 16, 35, 48, 66, 80, 97, 114], [1, 2, 3, 6, 1]), ([10, 16, 47, 48, 78, 81, 97, 117], [17, 30, 15, 12, 2]), ([8, 17, 43, 51, 75, 83, 97, 114], [2, 0, 0, 1, 1]), ([0, 16, 32, 48, 64, 80, 96], None), ([16, 32, 48, 64, 80, 96, 112, 0], None), ([3, 0, 16, 32, 48, 64, 80, 98, 112], [2, 0, 0, 2, 0]), ([9, 16, 41, 48, 73, 80, 105, 112], [9, 9, 9, 11, 0])], [([5, 17, 32, 48, 64, 80, 96, 114], [0, 0, 0, 23, 1]), ([4, 16, 35, 48, 66, 80, 97, 114], [1, 2, 3, 6, 1]), ([10, 16, 47, 48, 78, 81, 97, 117], [17, 30, 15, 12, 2]), ([0, 16, 32, 48, 64, 80, 100, 119], [20, 0, 0, 2, 3]), ([12, 17, 43, 51, 75, 83, 103, 119], [0, 0, 0, 0, 3]), ([8, 17, 43, 51, 75, 83, 97, 114], [2, 0, 0, 1, 1]), ([7, 16, 38, 48, 69, 80, 96, 115], [16, 5, 6, 9, 1]), ([9, 16, 41, 48, 73, 80, 105, 112], [9, 9, 9, 11, 0])], [([10, 16, 47, 48, 78, 81, 97, 117], [17, 30, 15, 12, 2]), ([0, 16, 32, 48, 64, 80, 100, 119], [20, 0, 0, 2, 3]), ([12, 17, 43, 51, 75, 83, 103, 119], [0, 0, 0, 0, 3]), ([8, 17, 43, 51, 75, 83, 97, 114], [2, 0, 0, 1, 1]), ([7, 16, 38, 48, 69, 80, 96, 115], [16, 5, 6, 9, 1]), ([13, 17, 43, 51, 64, 80, 99, 117], [19, 1, 0, 1, 2]), ([4, 17, 40, 51, 66, 82, 108, 118], [12, 34, 56, 22, 3]), ([8, 17, 43, 51, 75, 83, 103, 115], [0, 0, 0, 1, 1])], [([0, 16, 32, 48, 64, 80, 96, 112], [0, 0, 0, 2, 0]), ([7, 17, 43, 51, 75, 83, 103, 113], [0, 0, 0, 1, 0]), ([8, 17, 43, 51, 75, 83, 97, 114], [2, 0, 0, 1, 1]), ([7, 16, 38, 48, 69, 80, 96, 115], [16, 5, 6, 9, 1]), ([13, 17, 43, 51, 64, 80, 99, 117], [19, 1, 0, 1, 2]), ([6, 17, 43, 51, 75, 83, 102, 113], [23, 0, 0, 0, 0]), ([4, 17, 40, 51, 66, 82, 108, 118], [12, 34, 56, 22, 3]), ([8, 17, 43, 51, 75, 83, 103, 115], [0, 0, 0, 1, 1])]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("oracle %d" % 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
oracle 0[0, 0, 0, 2, 0][0, 0, 0, 2, 0]Passed
oracle 1[0, 0, 0, 23, 1][0, 0, 0, 23, 1]Passed
oracle 2[17, 30, 15, 12, 2][17, 30, 15, 12, 2]Passed
oracle 3[0, 0, 0, 1, 0][0, 0, 0, 1, 0]Passed
oracle 4[0, 0, 0, 0, 3][0, 0, 0, 0, 3]Passed
oracle 5[23, 0, 0, 0, 0][23, 0, 0, 0, 0]Passed
oracle 6NoneNonePassed
oracle 7NoneNonePassed

SHA-256 / bcbf1075c31acc16a408d8052744b8f5086eaa90ec66b1ef6e85aff7d0438405

Verification & scope

A deterministic bounded teaching model with a stipulated toy contract; it is not a complete Standard MIDI File or MIDI 1.0/2.0 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:50:06.344302+00:00.

Case digest / 4ce0894ff161dbece320bc44b3a5e927c85e3fdbd7c342be1ed07321426714d4