FAILURE MAP
← Case archive

FA-4091 / Sequence semantics / Open access

Stable last occurrence uniqueness · case 01

The operation returns a result or retained state that violates this contract: Keep only last occurrences, ordered by their original positions.

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

ROOT CAUSE

First-occurrence deduplication retains the wrong representative positions.

VERIFIED REPAIR

Keep only last occurrences, ordered by their original positions.

Unsuccessful approach: Sorting unique values cannot reproduce last-occurrence order.

Case contract

Keep only last occurrences, ordered by their original positions. 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

N = 1
observations = []
def solve(x, y=None):
    return list(dict.fromkeys(x))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('empty collection', solve([]), [])
check('singleton collection', solve(['a']), ['a'])
check('two distinct elements', solve(['a', 'b']), ['a', 'b'])
check('nonadjacent duplicate and unsorted order', solve(['b', 'a', 'b', 'c']), ['a', 'b', 'c'])
check('last-occurrence order is not lexical', solve(['b','a','c','b']), ['a','c','b'])
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
empty collection[][]Passed
singleton collection['a']['a']Passed
two distinct elements['a', 'b']['a', 'b']Passed
nonadjacent duplicate and unsorted order['b', 'a', 'c']['a', 'b', 'c']Failed
last-occurrence order is not lexical['b', 'a', 'c']['a', 'c', 'b']Failed

SHA-256 / 32365993eaac3820c3a1673b3034f9c202e2f3368f0b0e8a4ecc022aa06dc04d

2 / The unsuccessful fix

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

N = 1
observations = []
def solve(x, y=None):
    return sorted(set(x))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('empty collection', solve([]), [])
check('singleton collection', solve(['a']), ['a'])
check('two distinct elements', solve(['a', 'b']), ['a', 'b'])
check('nonadjacent duplicate and unsorted order', solve(['b', 'a', 'b', 'c']), ['a', 'b', 'c'])
check('last-occurrence order is not lexical', solve(['b','a','c','b']), ['a','c','b'])
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
empty collection[][]Passed
singleton collection['a']['a']Passed
two distinct elements['a', 'b']['a', 'b']Passed
nonadjacent duplicate and unsorted order['a', 'b', 'c']['a', 'b', 'c']Passed
last-occurrence order is not lexical['a', 'b', 'c']['a', 'c', 'b']Failed

SHA-256 / 019fe2da3394cb510ecb5daaee09b16fa467165f3fc94e1dac286e02a1fbde37

3 / The verified repair

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

N = 1
observations = []
def solve(x, y=None):
    return [v for i,v in enumerate(x) if v not in x[i+1:]]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('empty collection', solve([]), [])
check('singleton collection', solve(['a']), ['a'])
check('two distinct elements', solve(['a', 'b']), ['a', 'b'])
check('nonadjacent duplicate and unsorted order', solve(['b', 'a', 'b', 'c']), ['a', 'b', 'c'])
check('last-occurrence order is not lexical', solve(['b','a','c','b']), ['a','c','b'])
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
empty collection[][]Passed
singleton collection['a']['a']Passed
two distinct elements['a', 'b']['a', 'b']Passed
nonadjacent duplicate and unsorted order['a', 'b', 'c']['a', 'b', 'c']Passed
last-occurrence order is not lexical['a', 'c', 'b']['a', 'c', 'b']Passed

SHA-256 / d4b25fdd7dde1ac68b7c6776d6f8f225853a527e8674b0d474d7a949064e6e95

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

Case digest / 35021af2887d166745229c459552e751c26c6dedbdc49f1ddc689e7b191b05e9