FAILURE MAP
← Case archive

FA-4801 / Heap invariants / Open access

Heapify required before successive pops · case 01

The operation returns a result or retained state that violates this contract: Build a min heap from arbitrary input and pop all values in sorted order, retaining duplicates.

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

ROOT CAUSE

Heap pop is applied to an arbitrary array without establishing the heap invariant.

VERIFIED REPAIR

Build a min heap from arbitrary input and pop all values in sorted order, retaining duplicates.

Unsuccessful approach: Deduplication before heap construction loses repeated input values.

Case contract

Build a min heap from arbitrary input and pop all values in sorted order, retaining duplicates. Inputs are the finite Python values shown by the executable fixtures; no concurrent execution is assumed.

Why this case matters

A controlled local-runtime regression for collection APIs, language semantics, or ownership wrappers. Fixtures include boundary and interaction cases.

1 / The failure

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
from collections import Counter, ChainMap, deque
import heapq
N = 1
observations = []
def solve(x, y=None):
    a=list(x); return [heapq.heappop(a) for _ in range(len(a))]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('arbitrary input order', solve(['c', 'a', 'b']), ['a', 'b', 'c'])
check('duplicates retained', solve(['b', 'a', 'b']), ['a', 'b', 'b'])
check('empty', solve([]), [])
check('singleton', solve(['a']), ['a'])
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
arbitrary input order['c', 'a', 'b']['a', 'b', 'c']Failed
duplicates retained['b', 'a', 'b']['a', 'b', 'b']Failed
empty[][]Passed
singleton['a']['a']Passed

SHA-256 / 209f0f22817997f39390e321bf04be7bd56d5599d9c96309001262e1ea62ee8d

2 / The unsuccessful fix

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
from collections import Counter, ChainMap, deque
import heapq
N = 1
observations = []
def solve(x, y=None):
    a=list(dict.fromkeys(x)); heapq.heapify(a); return [heapq.heappop(a) for _ in range(len(a))]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('arbitrary input order', solve(['c', 'a', 'b']), ['a', 'b', 'c'])
check('duplicates retained', solve(['b', 'a', 'b']), ['a', 'b', 'b'])
check('empty', solve([]), [])
check('singleton', solve(['a']), ['a'])
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
arbitrary input order['a', 'b', 'c']['a', 'b', 'c']Passed
duplicates retained['a', 'b']['a', 'b', 'b']Failed
empty[][]Passed
singleton['a']['a']Passed

SHA-256 / 65b64fc68d8a2536f5edd3b8ea57e35884e780eb4fedbe103bd5431352d32e39

3 / The verified repair

Exit 0
"""Failure Map reference implementation. Python standard library only."""
import json
from collections import Counter, ChainMap, deque
import heapq
N = 1
observations = []
def solve(x, y=None):
    a=list(x); heapq.heapify(a); return [heapq.heappop(a) for _ in range(len(a))]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('arbitrary input order', solve(['c', 'a', 'b']), ['a', 'b', 'c'])
check('duplicates retained', solve(['b', 'a', 'b']), ['a', 'b', 'b'])
check('empty', solve([]), [])
check('singleton', solve(['a']), ['a'])
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
arbitrary input order['a', 'b', 'c']['a', 'b', 'c']Passed
duplicates retained['a', 'b', 'b']['a', 'b', 'b']Passed
empty[][]Passed
singleton['a']['a']Passed

SHA-256 / dcebf8e35aaf9dd7b7562cbfac84586cb7fb316ebff09cee8ecb4a313b3c3446

Verification & scope

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

Case digest / 66046e34a42f515c9d8624fa0d502790355a9a4158bd9ba33dfa638edd0d7538