FAILURE MAP
← Case archive

FA-80981 / Music interval and transposition theory / Open access

Key signature and measure accidental resolution: measure accidentals leak across barlines · case 01

A sharp written in one measure still raises the same note after the barline, so F4 after | stays F#4 even in C major.

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

ROOT CAUSE

The barline token is skipped without clearing the per-measure accidental table.

VERIFIED REPAIR

Restore the barline reset step so that it reads `marks = {} continue`.

Unsuccessful approach: Clearing only natural signs at the barline lets explicit sharps and flats keep leaking into the next measure.

Case contract

Input [fifths, tokens]. fifths -7..7 gives signature sharps on F C G D A E B or flats on B E A D G C F. Tokens are "|" (barline) or letter + optional sign (# b x bb n) + single-digit octave. An explicit sign sets the alteration for that letter in that octave until the next barline (n = 0 cancels the signature); otherwise the signature applies. Return the MIDI numbers (C4 = 60) or None if any token or the signature is invalid.

Why this case matters

Pitch spelling and interval arithmetic decide the notes that notation, transposition and analysis tools display or play.

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
    fifths, tokens = x
    if not isinstance(fifths, int) or fifths < -7 or fifths > 7:
        return None
    base = {'C': 0, 'D': 2, 'E': 4, 'F': 5, 'G': 7, 'A': 9, 'B': 11}
    keysig = {}
    if fifths > 0:
        for letter in 'FCGDAEB'[:fifths]:
            keysig[letter] = 1
    else:
        for letter in 'BEADGCF'[:-fifths]:
            keysig[letter] = -1
    marks = {}
    out = []
    for tok in tokens:
        if tok == '|':
            continue
        letter, sign, octave = tok[0], tok[1:-1], tok[-1]
        if letter not in base or not octave.isdigit() or sign not in ('', '#', 'b', 'n', 'x', 'bb'):
            return None
        slot = letter + octave
        if sign:
            marks[slot] = {'#': 1, 'b': -1, 'n': 0, 'x': 2, 'bb': -2}[sign]
        alter = marks[slot] if slot in marks else keysig.get(letter, 0)
        out.append(12 * (int(octave) + 1) + base[letter] + alter)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([1, ['F4', 'Fn4', 'F4', '|', 'F4']], [66, 65, 65, 66]), ([0, ['C#4', 'C4', '|', 'C4']], [61, 61, 60]), ([0, ['C#4', 'C5', 'C4']], [61, 72, 61]), ([-1, ['B4', 'Bn4', 'B4', '|', 'B4']], [70, 71, 71, 70]), ([-3, ['E4', 'A4', 'B4', 'D4']], [63, 68, 70, 62]), ([2, ['F4', 'C5', 'G4']], [66, 73, 67]), ([-2, ['Eb4', 'E4', 'En4', 'E4']], [63, 63, 64, 64]), ([0, ['B#3', 'C4', 'B3', '|', 'B3']], [60, 60, 60, 59])], [([0, ['C#4', 'C4', '|', 'C4']], [61, 61, 60]), ([-2, ['Eb4', 'E4', 'En4', 'E4']], [63, 63, 64, 64]), ([0, ['Gbb4', 'G4', '|', 'G4']], [65, 65, 67]), ([-7, ['F4', 'C4', 'B3']], [64, 59, 58]), ([7, ['B3', 'E4', 'C4']], [60, 65, 61]), ([8, ['C4']], None), ([0, ['H4']], None), ([-1, ['Bbb4', 'B4', '|', 'B4']], [69, 69, 70])], [([0, ['C#4', 'C4', '|', 'C4']], [61, 61, 60]), ([-1, ['B4', 'Bn4', 'B4', '|', 'B4']], [70, 71, 71, 70]), ([3, ['Fx4', 'F4', '|', 'F4', 'G4']], [67, 67, 66, 68]), ([8, ['C4']], None), ([0, ['H4']], None), ([0, ['C#44']], None), ([4, ['D4', 'Dn4', 'D5', 'D4']], [63, 62, 75, 62]), ([-4, ['D4', 'Db4', 'D4', '|', 'D4']], [61, 61, 61, 61])], [([0, ['Gbb4', 'G4', '|', 'G4']], [65, 65, 67]), ([4, ['D4', 'Dn4', 'D5', 'D4']], [63, 62, 75, 62]), ([-4, ['D4', 'Db4', 'D4', '|', 'D4']], [61, 61, 61, 61]), ([5, ['A4', 'An4', '|', 'A4']], [70, 69, 70]), ([0, ['B#3', 'C4', 'B3', '|', 'B3']], [60, 60, 60, 59]), ([-5, ['G4', 'Gn4', 'G4', 'G5']], [66, 67, 67, 78]), ([1, ['Fn4', 'Fn5', 'F5', 'F4']], [65, 77, 77, 65]), ([6, ['E4', 'B4', 'A4']], [65, 71, 70])], [([3, ['Fx4', 'F4', '|', 'F4', 'G4']], [67, 67, 66, 68]), ([0, ['B#3', 'C4', 'B3', '|', 'B3']], [60, 60, 60, 59]), ([1, ['Fn4', 'Fn5', 'F5', 'F4']], [65, 77, 77, 65]), ([6, ['E4', 'B4', 'A4']], [65, 71, 70]), ([0, ['Ab4', '|', 'Ab4', 'A4']], [68, 68, 68]), ([0, ['F#3', 'F#4', 'F3', 'F4']], [54, 66, 54, 66]), ([-1, ['Bbb4', 'B4', '|', 'B4']], [69, 69, 70]), ([0, ['Cq4']], None)]]
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[66, 65, 65, 65][66, 65, 65, 66]Failed
oracle 1[61, 61, 61][61, 61, 60]Failed
oracle 2[61, 72, 61][61, 72, 61]Passed
oracle 3[70, 71, 71, 71][70, 71, 71, 70]Failed
oracle 4[63, 68, 70, 62][63, 68, 70, 62]Passed
oracle 5[66, 73, 67][66, 73, 67]Passed
oracle 6[63, 63, 64, 64][63, 63, 64, 64]Passed
oracle 7[60, 60, 60, 60][60, 60, 60, 59]Failed

SHA-256 / eca1727a3be04dce08a7cd5d9613c1a877f22d16b1b822460d2ff5ac6be5a055

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
    fifths, tokens = x
    if not isinstance(fifths, int) or fifths < -7 or fifths > 7:
        return None
    base = {'C': 0, 'D': 2, 'E': 4, 'F': 5, 'G': 7, 'A': 9, 'B': 11}
    keysig = {}
    if fifths > 0:
        for letter in 'FCGDAEB'[:fifths]:
            keysig[letter] = 1
    else:
        for letter in 'BEADGCF'[:-fifths]:
            keysig[letter] = -1
    marks = {}
    out = []
    for tok in tokens:
        if tok == '|':
            marks = {k: v for k, v in marks.items() if v != 0}
            continue
        letter, sign, octave = tok[0], tok[1:-1], tok[-1]
        if letter not in base or not octave.isdigit() or sign not in ('', '#', 'b', 'n', 'x', 'bb'):
            return None
        slot = letter + octave
        if sign:
            marks[slot] = {'#': 1, 'b': -1, 'n': 0, 'x': 2, 'bb': -2}[sign]
        alter = marks[slot] if slot in marks else keysig.get(letter, 0)
        out.append(12 * (int(octave) + 1) + base[letter] + alter)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([1, ['F4', 'Fn4', 'F4', '|', 'F4']], [66, 65, 65, 66]), ([0, ['C#4', 'C4', '|', 'C4']], [61, 61, 60]), ([0, ['C#4', 'C5', 'C4']], [61, 72, 61]), ([-1, ['B4', 'Bn4', 'B4', '|', 'B4']], [70, 71, 71, 70]), ([-3, ['E4', 'A4', 'B4', 'D4']], [63, 68, 70, 62]), ([2, ['F4', 'C5', 'G4']], [66, 73, 67]), ([-2, ['Eb4', 'E4', 'En4', 'E4']], [63, 63, 64, 64]), ([0, ['B#3', 'C4', 'B3', '|', 'B3']], [60, 60, 60, 59])], [([0, ['C#4', 'C4', '|', 'C4']], [61, 61, 60]), ([-2, ['Eb4', 'E4', 'En4', 'E4']], [63, 63, 64, 64]), ([0, ['Gbb4', 'G4', '|', 'G4']], [65, 65, 67]), ([-7, ['F4', 'C4', 'B3']], [64, 59, 58]), ([7, ['B3', 'E4', 'C4']], [60, 65, 61]), ([8, ['C4']], None), ([0, ['H4']], None), ([-1, ['Bbb4', 'B4', '|', 'B4']], [69, 69, 70])], [([0, ['C#4', 'C4', '|', 'C4']], [61, 61, 60]), ([-1, ['B4', 'Bn4', 'B4', '|', 'B4']], [70, 71, 71, 70]), ([3, ['Fx4', 'F4', '|', 'F4', 'G4']], [67, 67, 66, 68]), ([8, ['C4']], None), ([0, ['H4']], None), ([0, ['C#44']], None), ([4, ['D4', 'Dn4', 'D5', 'D4']], [63, 62, 75, 62]), ([-4, ['D4', 'Db4', 'D4', '|', 'D4']], [61, 61, 61, 61])], [([0, ['Gbb4', 'G4', '|', 'G4']], [65, 65, 67]), ([4, ['D4', 'Dn4', 'D5', 'D4']], [63, 62, 75, 62]), ([-4, ['D4', 'Db4', 'D4', '|', 'D4']], [61, 61, 61, 61]), ([5, ['A4', 'An4', '|', 'A4']], [70, 69, 70]), ([0, ['B#3', 'C4', 'B3', '|', 'B3']], [60, 60, 60, 59]), ([-5, ['G4', 'Gn4', 'G4', 'G5']], [66, 67, 67, 78]), ([1, ['Fn4', 'Fn5', 'F5', 'F4']], [65, 77, 77, 65]), ([6, ['E4', 'B4', 'A4']], [65, 71, 70])], [([3, ['Fx4', 'F4', '|', 'F4', 'G4']], [67, 67, 66, 68]), ([0, ['B#3', 'C4', 'B3', '|', 'B3']], [60, 60, 60, 59]), ([1, ['Fn4', 'Fn5', 'F5', 'F4']], [65, 77, 77, 65]), ([6, ['E4', 'B4', 'A4']], [65, 71, 70]), ([0, ['Ab4', '|', 'Ab4', 'A4']], [68, 68, 68]), ([0, ['F#3', 'F#4', 'F3', 'F4']], [54, 66, 54, 66]), ([-1, ['Bbb4', 'B4', '|', 'B4']], [69, 69, 70]), ([0, ['Cq4']], None)]]
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[66, 65, 65, 66][66, 65, 65, 66]Passed
oracle 1[61, 61, 61][61, 61, 60]Failed
oracle 2[61, 72, 61][61, 72, 61]Passed
oracle 3[70, 71, 71, 70][70, 71, 71, 70]Passed
oracle 4[63, 68, 70, 62][63, 68, 70, 62]Passed
oracle 5[66, 73, 67][66, 73, 67]Passed
oracle 6[63, 63, 64, 64][63, 63, 64, 64]Passed
oracle 7[60, 60, 60, 60][60, 60, 60, 59]Failed

SHA-256 / b7c716f1b6b84a243ce5c2bdbd9e57b4bb1f5e95b57f15862b0e0ea4a972746d

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
    fifths, tokens = x
    if not isinstance(fifths, int) or fifths < -7 or fifths > 7:
        return None
    base = {'C': 0, 'D': 2, 'E': 4, 'F': 5, 'G': 7, 'A': 9, 'B': 11}
    keysig = {}
    if fifths > 0:
        for letter in 'FCGDAEB'[:fifths]:
            keysig[letter] = 1
    else:
        for letter in 'BEADGCF'[:-fifths]:
            keysig[letter] = -1
    marks = {}
    out = []
    for tok in tokens:
        if tok == '|':
            marks = {}
            continue
        letter, sign, octave = tok[0], tok[1:-1], tok[-1]
        if letter not in base or not octave.isdigit() or sign not in ('', '#', 'b', 'n', 'x', 'bb'):
            return None
        slot = letter + octave
        if sign:
            marks[slot] = {'#': 1, 'b': -1, 'n': 0, 'x': 2, 'bb': -2}[sign]
        alter = marks[slot] if slot in marks else keysig.get(letter, 0)
        out.append(12 * (int(octave) + 1) + base[letter] + alter)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([1, ['F4', 'Fn4', 'F4', '|', 'F4']], [66, 65, 65, 66]), ([0, ['C#4', 'C4', '|', 'C4']], [61, 61, 60]), ([0, ['C#4', 'C5', 'C4']], [61, 72, 61]), ([-1, ['B4', 'Bn4', 'B4', '|', 'B4']], [70, 71, 71, 70]), ([-3, ['E4', 'A4', 'B4', 'D4']], [63, 68, 70, 62]), ([2, ['F4', 'C5', 'G4']], [66, 73, 67]), ([-2, ['Eb4', 'E4', 'En4', 'E4']], [63, 63, 64, 64]), ([0, ['B#3', 'C4', 'B3', '|', 'B3']], [60, 60, 60, 59])], [([0, ['C#4', 'C4', '|', 'C4']], [61, 61, 60]), ([-2, ['Eb4', 'E4', 'En4', 'E4']], [63, 63, 64, 64]), ([0, ['Gbb4', 'G4', '|', 'G4']], [65, 65, 67]), ([-7, ['F4', 'C4', 'B3']], [64, 59, 58]), ([7, ['B3', 'E4', 'C4']], [60, 65, 61]), ([8, ['C4']], None), ([0, ['H4']], None), ([-1, ['Bbb4', 'B4', '|', 'B4']], [69, 69, 70])], [([0, ['C#4', 'C4', '|', 'C4']], [61, 61, 60]), ([-1, ['B4', 'Bn4', 'B4', '|', 'B4']], [70, 71, 71, 70]), ([3, ['Fx4', 'F4', '|', 'F4', 'G4']], [67, 67, 66, 68]), ([8, ['C4']], None), ([0, ['H4']], None), ([0, ['C#44']], None), ([4, ['D4', 'Dn4', 'D5', 'D4']], [63, 62, 75, 62]), ([-4, ['D4', 'Db4', 'D4', '|', 'D4']], [61, 61, 61, 61])], [([0, ['Gbb4', 'G4', '|', 'G4']], [65, 65, 67]), ([4, ['D4', 'Dn4', 'D5', 'D4']], [63, 62, 75, 62]), ([-4, ['D4', 'Db4', 'D4', '|', 'D4']], [61, 61, 61, 61]), ([5, ['A4', 'An4', '|', 'A4']], [70, 69, 70]), ([0, ['B#3', 'C4', 'B3', '|', 'B3']], [60, 60, 60, 59]), ([-5, ['G4', 'Gn4', 'G4', 'G5']], [66, 67, 67, 78]), ([1, ['Fn4', 'Fn5', 'F5', 'F4']], [65, 77, 77, 65]), ([6, ['E4', 'B4', 'A4']], [65, 71, 70])], [([3, ['Fx4', 'F4', '|', 'F4', 'G4']], [67, 67, 66, 68]), ([0, ['B#3', 'C4', 'B3', '|', 'B3']], [60, 60, 60, 59]), ([1, ['Fn4', 'Fn5', 'F5', 'F4']], [65, 77, 77, 65]), ([6, ['E4', 'B4', 'A4']], [65, 71, 70]), ([0, ['Ab4', '|', 'Ab4', 'A4']], [68, 68, 68]), ([0, ['F#3', 'F#4', 'F3', 'F4']], [54, 66, 54, 66]), ([-1, ['Bbb4', 'B4', '|', 'B4']], [69, 69, 70]), ([0, ['Cq4']], None)]]
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[66, 65, 65, 66][66, 65, 65, 66]Passed
oracle 1[61, 61, 60][61, 61, 60]Passed
oracle 2[61, 72, 61][61, 72, 61]Passed
oracle 3[70, 71, 71, 70][70, 71, 71, 70]Passed
oracle 4[63, 68, 70, 62][63, 68, 70, 62]Passed
oracle 5[66, 73, 67][66, 73, 67]Passed
oracle 6[63, 63, 64, 64][63, 63, 64, 64]Passed
oracle 7[60, 60, 60, 59][60, 60, 60, 59]Passed

SHA-256 / d184c3ab10b3fb16eed98354407f8cef256bcc9e45bdecbe2a68f0d0715e8c87

Verification & scope

A deterministic bounded teaching model with a stipulated toy contract; it is not a complete music notation or theory engine. 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:58.713227+00:00.

Case digest / 06a13e677009984c8a2a5291256bd20fbbcd7a309e04cdff7e2cd559978ed9ef