FAILURE MAP
← Case archive

FA-4681 / Multiset accounting / Open access

Counter most common stable ties · case 01

The operation returns a result or retained state that violates this contract: Return at most n [key,count] pairs by descending count, breaking ties by first insertion order.

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

ROOT CAUSE

Lexical keys break frequency ties instead of first insertion order.

VERIFIED REPAIR

Return at most n [key,count] pairs by descending count, breaking ties by first insertion order.

Unsuccessful approach: Truncating insertion order does not rank by frequency.

Case contract

Return at most n [key,count] pairs by descending count, breaking ties by first insertion order. 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):
    return [[k,v] for k,v in sorted(x.items(),key=lambda p:(-p[1],p[0]))[:y]]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('tie insertion order', solve({'b': 2, 'a': 2, 'c': 3}, 3), [['c', 3], ['b', 2], ['a', 2]])
check('zero requested', solve({'a': 1}, 0), [])
check('negative count included', solve({'a': -1}, 2), [['a', -1]])
check('empty', solve({}, 2), [])
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
tie insertion order[['c', 3], ['a', 2], ['b', 2]][['c', 3], ['b', 2], ['a', 2]]Failed
zero requested[][]Passed
negative count included[['a', -1]][['a', -1]]Passed
empty[][]Passed

SHA-256 / 263620826214410dc6a7b35d8c4f52fce49b289d80025848394189a9b051dcda

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):
    return [[k,v] for k,v in list(x.items())[:y]]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('tie insertion order', solve({'b': 2, 'a': 2, 'c': 3}, 3), [['c', 3], ['b', 2], ['a', 2]])
check('zero requested', solve({'a': 1}, 0), [])
check('negative count included', solve({'a': -1}, 2), [['a', -1]])
check('empty', solve({}, 2), [])
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
tie insertion order[['b', 2], ['a', 2], ['c', 3]][['c', 3], ['b', 2], ['a', 2]]Failed
zero requested[][]Passed
negative count included[['a', -1]][['a', -1]]Passed
empty[][]Passed

SHA-256 / a26acc36bd0193d67aa7c2c6a4f4ed2ac0bc4ee5af77f42a29cd03ccdc5cce5e

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):
    return [list(v) for v in Counter(x).most_common(y)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('tie insertion order', solve({'b': 2, 'a': 2, 'c': 3}, 3), [['c', 3], ['b', 2], ['a', 2]])
check('zero requested', solve({'a': 1}, 0), [])
check('negative count included', solve({'a': -1}, 2), [['a', -1]])
check('empty', solve({}, 2), [])
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
tie insertion order[['c', 3], ['b', 2], ['a', 2]][['c', 3], ['b', 2], ['a', 2]]Passed
zero requested[][]Passed
negative count included[['a', -1]][['a', -1]]Passed
empty[][]Passed

SHA-256 / d73871dc2635bb2464bdbdee3ce577b7bf2549dbe2185ae2950d4f14c51421e1

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

Case digest / c2f97db3396a9e0cc04613144d922d5a0b5bddcd9e20438baf3a71f46fb4ad01