FAILURE MAP
← Case archive

FA-81786 / MIDI event timing / Open access

Channel note message encoder with running status: running status applied when disabled · case 01

Repeated status bytes are omitted even when running status is disabled.

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

ROOT CAUSE

The status-omission test ignores the running-status flag.

VERIFIED REPAIR

Restore the status omission rule step so that it reads `if not (rs and status == last):`.

Unsuccessful approach: Emitting status only when running status is off drops every status byte in running-status mode.

Case contract

Input [events, running_status] with events [kind, channel 1..16, note, velocity]. A note-on with velocity > 0 encodes as 0x90|(channel-1), note, velocity. A note-off (or note-on with velocity 0) encodes as 0x90|(channel-1), note, 0 when running status is enabled; otherwise as 0x80|(channel-1), note, velocity for an off and note, 64 for a velocity-0 on. With running status enabled, a status byte equal to the previous one is omitted. Invalid values return 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) != 2:
        return None
    events, rs = x
    out = []
    last = None
    for kind, ch, note, vel in events:
        if not 1 <= ch <= 16 or not 0 <= note <= 127 or not 0 <= vel <= 127:
            return None
        if kind == 'on' and vel > 0:
            status, data = 0x90 | (ch - 1), [note, vel]
        elif kind in ('on', 'off'):
            if rs:
                status, data = 0x90 | (ch - 1), [note, 0]
            else:
                status, data = 0x80 | (ch - 1), [note, vel if kind == 'off' else 64]
        else:
            return None
        if status != last:
            out.append(status)
        out.extend(data)
        last = status
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([[['on', 1, 60, 100], ['off', 1, 60, 40]], False], [144, 60, 100, 128, 60, 40]), ([[['on', 1, 60, 100], ['off', 1, 60, 40]], True], [144, 60, 100, 60, 0]), ([[['on', 1, 60, 100], ['on', 1, 64, 90]], False], [144, 60, 100, 144, 64, 90]), ([[['on', 16, 60, 100]], False], [159, 60, 100]), ([[['on', 0, 60, 100]], False], None), ([[['on', 17, 60, 100]], False], None), ([[['on', 2, 60, 0]], False], [129, 60, 64]), ([[['on', 1, 60, 100], ['on', 2, 60, 100]], True], [144, 60, 100, 145, 60, 100])], [([[['on', 1, 60, 100], ['on', 1, 64, 90]], True], [144, 60, 100, 64, 90]), ([[['on', 1, 60, 100], ['on', 1, 64, 90]], False], [144, 60, 100, 144, 64, 90]), ([[['on', 17, 60, 100]], False], None), ([[['on', 2, 60, 0]], False], [129, 60, 64]), ([[['off', 3, 60, 0]], False], [130, 60, 0]), ([[['on', 1, 128, 100]], False], None), ([[['cc', 1, 7, 100]], False], None), ([[['on', 10, 36, 127], ['off', 10, 36, 0], ['on', 10, 38, 127]], True], [153, 36, 127, 36, 0, 38, 127])], [([[['on', 1, 60, 100], ['off', 1, 60, 40]], True], [144, 60, 100, 60, 0]), ([[['on', 1, 60, 100], ['on', 1, 64, 90]], True], [144, 60, 100, 64, 90]), ([[['on', 1, 60, 100], ['on', 1, 64, 90]], False], [144, 60, 100, 144, 64, 90]), ([[['on', 2, 60, 0]], True], [145, 60, 0]), ([[['on', 1, 60, 100], ['on', 2, 60, 100]], True], [144, 60, 100, 145, 60, 100]), ([[['on', 1, 128, 100]], False], None), ([[['cc', 1, 7, 100]], False], None), ([[['on', 1, 60, 1]], True], [144, 60, 1])], [([[['on', 1, 60, 100], ['off', 1, 60, 40]], False], [144, 60, 100, 128, 60, 40]), ([[['on', 1, 60, 100], ['on', 1, 64, 90]], True], [144, 60, 100, 64, 90]), ([[['on', 1, 60, 100], ['on', 1, 64, 90]], False], [144, 60, 100, 144, 64, 90]), ([[['on', 2, 60, 0]], True], [145, 60, 0]), ([[['on', 1, 60, 100], ['on', 2, 60, 100]], True], [144, 60, 100, 145, 60, 100]), ([[['on', 10, 36, 127], ['off', 10, 36, 0], ['on', 10, 38, 127]], True], [153, 36, 127, 36, 0, 38, 127]), ([[['on', 1, 60, 1]], True], [144, 60, 1]), ([[['off', 5, 70, 90], ['off', 5, 71, 90]], True], [148, 70, 0, 71, 0])], [([[['on', 1, 60, 100], ['off', 1, 60, 40]], False], [144, 60, 100, 128, 60, 40]), ([[['on', 1, 60, 100], ['off', 1, 60, 40]], True], [144, 60, 100, 60, 0]), ([[['on', 1, 60, 100], ['on', 1, 64, 90]], False], [144, 60, 100, 144, 64, 90]), ([[['on', 16, 60, 100]], False], [159, 60, 100]), ([[['on', 1, 60, 100], ['on', 2, 60, 100]], True], [144, 60, 100, 145, 60, 100]), ([[['on', 10, 36, 127], ['off', 10, 36, 0], ['on', 10, 38, 127]], True], [153, 36, 127, 36, 0, 38, 127]), ([[['on', 1, 60, 1]], True], [144, 60, 1]), ([[['off', 5, 70, 90], ['off', 5, 71, 90]], True], [148, 70, 0, 71, 0])]]
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[144, 60, 100, 128, 60, 40][144, 60, 100, 128, 60, 40]Passed
oracle 1[144, 60, 100, 60, 0][144, 60, 100, 60, 0]Passed
oracle 2[144, 60, 100, 64, 90][144, 60, 100, 144, 64, 90]Failed
oracle 3[159, 60, 100][159, 60, 100]Passed
oracle 4NoneNonePassed
oracle 5NoneNonePassed
oracle 6[129, 60, 64][129, 60, 64]Passed
oracle 7[144, 60, 100, 145, 60, 100][144, 60, 100, 145, 60, 100]Passed

SHA-256 / 739b80114d8d5c246ee0c444623079576f178126a4137fe6261cb40764d41f5d

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) != 2:
        return None
    events, rs = x
    out = []
    last = None
    for kind, ch, note, vel in events:
        if not 1 <= ch <= 16 or not 0 <= note <= 127 or not 0 <= vel <= 127:
            return None
        if kind == 'on' and vel > 0:
            status, data = 0x90 | (ch - 1), [note, vel]
        elif kind in ('on', 'off'):
            if rs:
                status, data = 0x90 | (ch - 1), [note, 0]
            else:
                status, data = 0x80 | (ch - 1), [note, vel if kind == 'off' else 64]
        else:
            return None
        if not rs:
            out.append(status)
        out.extend(data)
        last = status
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([[['on', 1, 60, 100], ['off', 1, 60, 40]], False], [144, 60, 100, 128, 60, 40]), ([[['on', 1, 60, 100], ['off', 1, 60, 40]], True], [144, 60, 100, 60, 0]), ([[['on', 1, 60, 100], ['on', 1, 64, 90]], False], [144, 60, 100, 144, 64, 90]), ([[['on', 16, 60, 100]], False], [159, 60, 100]), ([[['on', 0, 60, 100]], False], None), ([[['on', 17, 60, 100]], False], None), ([[['on', 2, 60, 0]], False], [129, 60, 64]), ([[['on', 1, 60, 100], ['on', 2, 60, 100]], True], [144, 60, 100, 145, 60, 100])], [([[['on', 1, 60, 100], ['on', 1, 64, 90]], True], [144, 60, 100, 64, 90]), ([[['on', 1, 60, 100], ['on', 1, 64, 90]], False], [144, 60, 100, 144, 64, 90]), ([[['on', 17, 60, 100]], False], None), ([[['on', 2, 60, 0]], False], [129, 60, 64]), ([[['off', 3, 60, 0]], False], [130, 60, 0]), ([[['on', 1, 128, 100]], False], None), ([[['cc', 1, 7, 100]], False], None), ([[['on', 10, 36, 127], ['off', 10, 36, 0], ['on', 10, 38, 127]], True], [153, 36, 127, 36, 0, 38, 127])], [([[['on', 1, 60, 100], ['off', 1, 60, 40]], True], [144, 60, 100, 60, 0]), ([[['on', 1, 60, 100], ['on', 1, 64, 90]], True], [144, 60, 100, 64, 90]), ([[['on', 1, 60, 100], ['on', 1, 64, 90]], False], [144, 60, 100, 144, 64, 90]), ([[['on', 2, 60, 0]], True], [145, 60, 0]), ([[['on', 1, 60, 100], ['on', 2, 60, 100]], True], [144, 60, 100, 145, 60, 100]), ([[['on', 1, 128, 100]], False], None), ([[['cc', 1, 7, 100]], False], None), ([[['on', 1, 60, 1]], True], [144, 60, 1])], [([[['on', 1, 60, 100], ['off', 1, 60, 40]], False], [144, 60, 100, 128, 60, 40]), ([[['on', 1, 60, 100], ['on', 1, 64, 90]], True], [144, 60, 100, 64, 90]), ([[['on', 1, 60, 100], ['on', 1, 64, 90]], False], [144, 60, 100, 144, 64, 90]), ([[['on', 2, 60, 0]], True], [145, 60, 0]), ([[['on', 1, 60, 100], ['on', 2, 60, 100]], True], [144, 60, 100, 145, 60, 100]), ([[['on', 10, 36, 127], ['off', 10, 36, 0], ['on', 10, 38, 127]], True], [153, 36, 127, 36, 0, 38, 127]), ([[['on', 1, 60, 1]], True], [144, 60, 1]), ([[['off', 5, 70, 90], ['off', 5, 71, 90]], True], [148, 70, 0, 71, 0])], [([[['on', 1, 60, 100], ['off', 1, 60, 40]], False], [144, 60, 100, 128, 60, 40]), ([[['on', 1, 60, 100], ['off', 1, 60, 40]], True], [144, 60, 100, 60, 0]), ([[['on', 1, 60, 100], ['on', 1, 64, 90]], False], [144, 60, 100, 144, 64, 90]), ([[['on', 16, 60, 100]], False], [159, 60, 100]), ([[['on', 1, 60, 100], ['on', 2, 60, 100]], True], [144, 60, 100, 145, 60, 100]), ([[['on', 10, 36, 127], ['off', 10, 36, 0], ['on', 10, 38, 127]], True], [153, 36, 127, 36, 0, 38, 127]), ([[['on', 1, 60, 1]], True], [144, 60, 1]), ([[['off', 5, 70, 90], ['off', 5, 71, 90]], True], [148, 70, 0, 71, 0])]]
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[144, 60, 100, 128, 60, 40][144, 60, 100, 128, 60, 40]Passed
oracle 1[60, 100, 60, 0][144, 60, 100, 60, 0]Failed
oracle 2[144, 60, 100, 144, 64, 90][144, 60, 100, 144, 64, 90]Passed
oracle 3[159, 60, 100][159, 60, 100]Passed
oracle 4NoneNonePassed
oracle 5NoneNonePassed
oracle 6[129, 60, 64][129, 60, 64]Passed
oracle 7[60, 100, 60, 100][144, 60, 100, 145, 60, 100]Failed

SHA-256 / 43c60c078c3546b2733065c7e7886d20167c70ca3de06df94db53474fc8d3890

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) != 2:
        return None
    events, rs = x
    out = []
    last = None
    for kind, ch, note, vel in events:
        if not 1 <= ch <= 16 or not 0 <= note <= 127 or not 0 <= vel <= 127:
            return None
        if kind == 'on' and vel > 0:
            status, data = 0x90 | (ch - 1), [note, vel]
        elif kind in ('on', 'off'):
            if rs:
                status, data = 0x90 | (ch - 1), [note, 0]
            else:
                status, data = 0x80 | (ch - 1), [note, vel if kind == 'off' else 64]
        else:
            return None
        if not (rs and status == last):
            out.append(status)
        out.extend(data)
        last = status
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([[['on', 1, 60, 100], ['off', 1, 60, 40]], False], [144, 60, 100, 128, 60, 40]), ([[['on', 1, 60, 100], ['off', 1, 60, 40]], True], [144, 60, 100, 60, 0]), ([[['on', 1, 60, 100], ['on', 1, 64, 90]], False], [144, 60, 100, 144, 64, 90]), ([[['on', 16, 60, 100]], False], [159, 60, 100]), ([[['on', 0, 60, 100]], False], None), ([[['on', 17, 60, 100]], False], None), ([[['on', 2, 60, 0]], False], [129, 60, 64]), ([[['on', 1, 60, 100], ['on', 2, 60, 100]], True], [144, 60, 100, 145, 60, 100])], [([[['on', 1, 60, 100], ['on', 1, 64, 90]], True], [144, 60, 100, 64, 90]), ([[['on', 1, 60, 100], ['on', 1, 64, 90]], False], [144, 60, 100, 144, 64, 90]), ([[['on', 17, 60, 100]], False], None), ([[['on', 2, 60, 0]], False], [129, 60, 64]), ([[['off', 3, 60, 0]], False], [130, 60, 0]), ([[['on', 1, 128, 100]], False], None), ([[['cc', 1, 7, 100]], False], None), ([[['on', 10, 36, 127], ['off', 10, 36, 0], ['on', 10, 38, 127]], True], [153, 36, 127, 36, 0, 38, 127])], [([[['on', 1, 60, 100], ['off', 1, 60, 40]], True], [144, 60, 100, 60, 0]), ([[['on', 1, 60, 100], ['on', 1, 64, 90]], True], [144, 60, 100, 64, 90]), ([[['on', 1, 60, 100], ['on', 1, 64, 90]], False], [144, 60, 100, 144, 64, 90]), ([[['on', 2, 60, 0]], True], [145, 60, 0]), ([[['on', 1, 60, 100], ['on', 2, 60, 100]], True], [144, 60, 100, 145, 60, 100]), ([[['on', 1, 128, 100]], False], None), ([[['cc', 1, 7, 100]], False], None), ([[['on', 1, 60, 1]], True], [144, 60, 1])], [([[['on', 1, 60, 100], ['off', 1, 60, 40]], False], [144, 60, 100, 128, 60, 40]), ([[['on', 1, 60, 100], ['on', 1, 64, 90]], True], [144, 60, 100, 64, 90]), ([[['on', 1, 60, 100], ['on', 1, 64, 90]], False], [144, 60, 100, 144, 64, 90]), ([[['on', 2, 60, 0]], True], [145, 60, 0]), ([[['on', 1, 60, 100], ['on', 2, 60, 100]], True], [144, 60, 100, 145, 60, 100]), ([[['on', 10, 36, 127], ['off', 10, 36, 0], ['on', 10, 38, 127]], True], [153, 36, 127, 36, 0, 38, 127]), ([[['on', 1, 60, 1]], True], [144, 60, 1]), ([[['off', 5, 70, 90], ['off', 5, 71, 90]], True], [148, 70, 0, 71, 0])], [([[['on', 1, 60, 100], ['off', 1, 60, 40]], False], [144, 60, 100, 128, 60, 40]), ([[['on', 1, 60, 100], ['off', 1, 60, 40]], True], [144, 60, 100, 60, 0]), ([[['on', 1, 60, 100], ['on', 1, 64, 90]], False], [144, 60, 100, 144, 64, 90]), ([[['on', 16, 60, 100]], False], [159, 60, 100]), ([[['on', 1, 60, 100], ['on', 2, 60, 100]], True], [144, 60, 100, 145, 60, 100]), ([[['on', 10, 36, 127], ['off', 10, 36, 0], ['on', 10, 38, 127]], True], [153, 36, 127, 36, 0, 38, 127]), ([[['on', 1, 60, 1]], True], [144, 60, 1]), ([[['off', 5, 70, 90], ['off', 5, 71, 90]], True], [148, 70, 0, 71, 0])]]
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[144, 60, 100, 128, 60, 40][144, 60, 100, 128, 60, 40]Passed
oracle 1[144, 60, 100, 60, 0][144, 60, 100, 60, 0]Passed
oracle 2[144, 60, 100, 144, 64, 90][144, 60, 100, 144, 64, 90]Passed
oracle 3[159, 60, 100][159, 60, 100]Passed
oracle 4NoneNonePassed
oracle 5NoneNonePassed
oracle 6[129, 60, 64][129, 60, 64]Passed
oracle 7[144, 60, 100, 145, 60, 100][144, 60, 100, 145, 60, 100]Passed

SHA-256 / 11bcb1f1da34e29cdcf6e933561b3d237a43704cba3513c871a9de29ef85b2e0

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

Case digest / 96bf657582e7594022298cff9c57ba1ba9718eee61579d9598fce976d9d1a726