FAILURE MAP
← Case archive

FA-46236 / Bounded deques / Open access

Deque merge takes right-run ties before left-run ties · case 01

Deque merge takes right-run ties before left-run ties.

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

ROOT CAUSE

Deque merge takes right-run ties before left-run ties.

VERIFIED REPAIR

Restore the documented equal key stability invariant in merge-runs.

Unsuccessful approach: The partial repair still applies the incorrect transition to an admitted boundary or multi-element case.

Case contract

Merge sorted deque runs by key, placing equal keys from the left run first and preserving each run order. Split the merged stream at output capacity.

Why this case matters

Controlled bounded deque implementation model with explicit storage and lifecycle observations.

1 / The failure

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

N = 1
observations = []
def solve(x):
    a,b,cap=x
    out=[]
    i=j=0
    while i<len(a) and j<len(b):
        if a[i][0]<b[j][0]:
            out.append(a[i]);i+=1
        else:
            out.append(b[j]);j+=1
    out.extend(a[i:])
    out.extend(b[j:])
    return [out[:cap],out[cap:]]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('0', solve([[[1,N],[2,N+1]],[[1,N+2],[3,N+3]],3]), {1: [[[1, 1], [1, 3], [2, 2]], [[3, 4]]], 2: [[[1, 2], [1, 4], [2, 3]], [[3, 5]]], 3: [[[1, 3], [1, 5], [2, 4]], [[3, 6]]], 4: [[[1, 4], [1, 6], [2, 5]], [[3, 7]]], 5: [[[1, 5], [1, 7], [2, 6]], [[3, 8]]]}[N])
check('1', solve([[[1,N]],[],2]), {1: [[[1, 1]], []], 2: [[[1, 2]], []], 3: [[[1, 3]], []], 4: [[[1, 4]], []], 5: [[[1, 5]], []]}[N])
check('2', solve([[],[[1,N]],0]), {1: [[], [[1, 1]]], 2: [[], [[1, 2]]], 3: [[], [[1, 3]]], 4: [[], [[1, 4]]], 5: [[], [[1, 5]]]}[N])
check('3', solve([[[1,N],[1,N+1]],[[1,N+2]],3]), {1: [[[1, 1], [1, 2], [1, 3]], []], 2: [[[1, 2], [1, 3], [1, 4]], []], 3: [[[1, 3], [1, 4], [1, 5]], []], 4: [[[1, 4], [1, 5], [1, 6]], []], 5: [[[1, 5], [1, 6], [1, 7]], []]}[N])
check('4', solve([[[4,N]],[[1,N+1],[2,N+2]],4]), {1: [[[1, 2], [2, 3], [4, 1]], []], 2: [[[1, 3], [2, 4], [4, 2]], []], 3: [[[1, 4], [2, 5], [4, 3]], []], 4: [[[1, 5], [2, 6], [4, 4]], []], 5: [[[1, 6], [2, 7], [4, 5]], []]}[N])
check('5', solve([[],[],2]), {1: [[], []], 2: [[], []], 3: [[], []], 4: [[], []], 5: [[], []]}[N])
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
0[[[1, 3], [1, 1], [2, 2]], [[3, 4]]][[[1, 1], [1, 3], [2, 2]], [[3, 4]]]Failed
1[[[1, 1]], []][[[1, 1]], []]Passed
2[[], [[1, 1]]][[], [[1, 1]]]Passed
3[[[1, 3], [1, 1], [1, 2]], []][[[1, 1], [1, 2], [1, 3]], []]Failed
4[[[1, 2], [2, 3], [4, 1]], []][[[1, 2], [2, 3], [4, 1]], []]Passed
5[[], []][[], []]Passed

SHA-256 / 91259d300d10120e2cb7c5836f7330e9a19dade7a160d01591189857ae5026e5

2 / The unsuccessful fix

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

N = 1
observations = []
def solve(x):
    a,b,cap=x
    out=[]
    i=j=0
    while i<len(a) and j<len(b):
        if a[i][0]<b[j][0] or (i==0 and j==0 and a[i][0]==b[j][0]):
            out.append(a[i]);i+=1
        else:
            out.append(b[j]);j+=1
    out.extend(a[i:])
    out.extend(b[j:])
    return [out[:cap],out[cap:]]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('0', solve([[[1,N],[2,N+1]],[[1,N+2],[3,N+3]],3]), {1: [[[1, 1], [1, 3], [2, 2]], [[3, 4]]], 2: [[[1, 2], [1, 4], [2, 3]], [[3, 5]]], 3: [[[1, 3], [1, 5], [2, 4]], [[3, 6]]], 4: [[[1, 4], [1, 6], [2, 5]], [[3, 7]]], 5: [[[1, 5], [1, 7], [2, 6]], [[3, 8]]]}[N])
check('1', solve([[[1,N]],[],2]), {1: [[[1, 1]], []], 2: [[[1, 2]], []], 3: [[[1, 3]], []], 4: [[[1, 4]], []], 5: [[[1, 5]], []]}[N])
check('2', solve([[],[[1,N]],0]), {1: [[], [[1, 1]]], 2: [[], [[1, 2]]], 3: [[], [[1, 3]]], 4: [[], [[1, 4]]], 5: [[], [[1, 5]]]}[N])
check('3', solve([[[1,N],[1,N+1]],[[1,N+2]],3]), {1: [[[1, 1], [1, 2], [1, 3]], []], 2: [[[1, 2], [1, 3], [1, 4]], []], 3: [[[1, 3], [1, 4], [1, 5]], []], 4: [[[1, 4], [1, 5], [1, 6]], []], 5: [[[1, 5], [1, 6], [1, 7]], []]}[N])
check('4', solve([[[4,N]],[[1,N+1],[2,N+2]],4]), {1: [[[1, 2], [2, 3], [4, 1]], []], 2: [[[1, 3], [2, 4], [4, 2]], []], 3: [[[1, 4], [2, 5], [4, 3]], []], 4: [[[1, 5], [2, 6], [4, 4]], []], 5: [[[1, 6], [2, 7], [4, 5]], []]}[N])
check('5', solve([[],[],2]), {1: [[], []], 2: [[], []], 3: [[], []], 4: [[], []], 5: [[], []]}[N])
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
0[[[1, 1], [1, 3], [2, 2]], [[3, 4]]][[[1, 1], [1, 3], [2, 2]], [[3, 4]]]Passed
1[[[1, 1]], []][[[1, 1]], []]Passed
2[[], [[1, 1]]][[], [[1, 1]]]Passed
3[[[1, 1], [1, 3], [1, 2]], []][[[1, 1], [1, 2], [1, 3]], []]Failed
4[[[1, 2], [2, 3], [4, 1]], []][[[1, 2], [2, 3], [4, 1]], []]Passed
5[[], []][[], []]Passed

SHA-256 / e48a28f31443859f4bdcd94a4383f7bd9a1b99dd3fb35e40aaac28238391f932

3 / The verified repair

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

N = 1
observations = []
def solve(x):
    a,b,cap=x
    out=[]
    i=j=0
    while i<len(a) and j<len(b):
        if a[i][0]<=b[j][0]:
            out.append(a[i]);i+=1
        else:
            out.append(b[j]);j+=1
    out.extend(a[i:])
    out.extend(b[j:])
    return [out[:cap],out[cap:]]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('0', solve([[[1,N],[2,N+1]],[[1,N+2],[3,N+3]],3]), {1: [[[1, 1], [1, 3], [2, 2]], [[3, 4]]], 2: [[[1, 2], [1, 4], [2, 3]], [[3, 5]]], 3: [[[1, 3], [1, 5], [2, 4]], [[3, 6]]], 4: [[[1, 4], [1, 6], [2, 5]], [[3, 7]]], 5: [[[1, 5], [1, 7], [2, 6]], [[3, 8]]]}[N])
check('1', solve([[[1,N]],[],2]), {1: [[[1, 1]], []], 2: [[[1, 2]], []], 3: [[[1, 3]], []], 4: [[[1, 4]], []], 5: [[[1, 5]], []]}[N])
check('2', solve([[],[[1,N]],0]), {1: [[], [[1, 1]]], 2: [[], [[1, 2]]], 3: [[], [[1, 3]]], 4: [[], [[1, 4]]], 5: [[], [[1, 5]]]}[N])
check('3', solve([[[1,N],[1,N+1]],[[1,N+2]],3]), {1: [[[1, 1], [1, 2], [1, 3]], []], 2: [[[1, 2], [1, 3], [1, 4]], []], 3: [[[1, 3], [1, 4], [1, 5]], []], 4: [[[1, 4], [1, 5], [1, 6]], []], 5: [[[1, 5], [1, 6], [1, 7]], []]}[N])
check('4', solve([[[4,N]],[[1,N+1],[2,N+2]],4]), {1: [[[1, 2], [2, 3], [4, 1]], []], 2: [[[1, 3], [2, 4], [4, 2]], []], 3: [[[1, 4], [2, 5], [4, 3]], []], 4: [[[1, 5], [2, 6], [4, 4]], []], 5: [[[1, 6], [2, 7], [4, 5]], []]}[N])
check('5', solve([[],[],2]), {1: [[], []], 2: [[], []], 3: [[], []], 4: [[], []], 5: [[], []]}[N])
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
0[[[1, 1], [1, 3], [2, 2]], [[3, 4]]][[[1, 1], [1, 3], [2, 2]], [[3, 4]]]Passed
1[[[1, 1]], []][[[1, 1]], []]Passed
2[[], [[1, 1]]][[], [[1, 1]]]Passed
3[[[1, 1], [1, 2], [1, 3]], []][[[1, 1], [1, 2], [1, 3]], []]Passed
4[[[1, 2], [2, 3], [4, 1]], []][[[1, 2], [2, 3], [4, 1]], []]Passed
5[[], []][[], []]Passed

SHA-256 / 29c5f698168933d5a694c57753f86162759032454083f9ea1c95002fa7e116db

Verification & scope

Offline finite deterministic model; no claim of production implementation or concurrent memory-model conformance. 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:44:30.159850+00:00.

Case digest / 8a226a43ab49ed7d91856036f647d5cc24ef9a7a7f63f9339e479c23e992a797