FAILURE MAP
← Case archive

FA-4726 / Scoped mappings / Open access

Chainmap iteration order comes from outer scopes · case 01

The operation returns a result or retained state that violates this contract: ChainMap key iteration begins with the last scope and appends previously unseen keys from inner scopes; lookup values still favor inner scopes.

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

ROOT CAUSE

Inner-first key traversal differs from the ChainMap outer-first key-order rule.

VERIFIED REPAIR

ChainMap key iteration begins with the last scope and appends previously unseen keys from inner scopes; lookup values still favor inner scopes.

Unsuccessful approach: Sorting keys discards scope encounter order.

Case contract

ChainMap key iteration begins with the last scope and appends previously unseen keys from inner scopes; lookup values still favor inner scopes. 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):
    c=ChainMap(*x); return [[k,c[k]] for k in dict.fromkeys(k for m in x for k in m)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('outer order with inner values', solve([{'a': 2, 'c': 3}, {'b': 1, 'a': 1}]), [['b', 1], ['a', 2], ['c', 3]])
check('one scope order', solve([{'b': 2, 'a': 1}]), [['b', 2], ['a', 1]])
check('empty scopes', solve([{}, {}]), [])
check('inner only key', solve([{'a': 1}, {}]), [['a', 1]])
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
outer order with inner values[['a', 2], ['c', 3], ['b', 1]][['b', 1], ['a', 2], ['c', 3]]Failed
one scope order[['b', 2], ['a', 1]][['b', 2], ['a', 1]]Passed
empty scopes[][]Passed
inner only key[['a', 1]][['a', 1]]Passed

SHA-256 / c8701c68eebb8ca46920683047fc27a704cac3ddd42fd711c3661ec61362d0f6

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):
    c=ChainMap(*x); return [[k,c[k]] for k in sorted(c)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('outer order with inner values', solve([{'a': 2, 'c': 3}, {'b': 1, 'a': 1}]), [['b', 1], ['a', 2], ['c', 3]])
check('one scope order', solve([{'b': 2, 'a': 1}]), [['b', 2], ['a', 1]])
check('empty scopes', solve([{}, {}]), [])
check('inner only key', solve([{'a': 1}, {}]), [['a', 1]])
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
outer order with inner values[['a', 2], ['b', 1], ['c', 3]][['b', 1], ['a', 2], ['c', 3]]Failed
one scope order[['a', 1], ['b', 2]][['b', 2], ['a', 1]]Failed
empty scopes[][]Passed
inner only key[['a', 1]][['a', 1]]Passed

SHA-256 / b637c278b88d863b789d90757b6b18a402a70551c99aaafb123f1ac3899cff91

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):
    c=ChainMap(*x); return [[k,c[k]] for k in c]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('outer order with inner values', solve([{'a': 2, 'c': 3}, {'b': 1, 'a': 1}]), [['b', 1], ['a', 2], ['c', 3]])
check('one scope order', solve([{'b': 2, 'a': 1}]), [['b', 2], ['a', 1]])
check('empty scopes', solve([{}, {}]), [])
check('inner only key', solve([{'a': 1}, {}]), [['a', 1]])
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
outer order with inner values[['b', 1], ['a', 2], ['c', 3]][['b', 1], ['a', 2], ['c', 3]]Passed
one scope order[['b', 2], ['a', 1]][['b', 2], ['a', 1]]Passed
empty scopes[][]Passed
inner only key[['a', 1]][['a', 1]]Passed

SHA-256 / b3efe855efac945c3bc382df9da7a7e9b13488e6db97bbee2373d80a29695e87

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

Case digest / 8b3ca01e4a49e7b5d1866a01116a5d59d7ff09e085e7f2adc47fa5f5bc744933