FA-4716 / Scoped mappings / Open access
Chainmap write always top scope · case 01
The operation returns a result or retained state that violates this contract: Assignment always writes the first scope, even when the key exists only in an outer scope; return all scopes.
ROOT CAUSE
Updating the first existing binding mutates a parent instead of creating an inner shadow.
VERIFIED REPAIR
Assignment always writes the first scope, even when the key exists only in an outer scope; return all scopes.
Unsuccessful approach: Writing to the last scope mutates the outermost binding.
Case contract
Assignment always writes the first scope, even when the key exists only in an outer scope; return all 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):
a=[dict(m) for m in x]; next((m for m in a if y[0] in m),a[0])[y[0]]=y[1]; return a
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('shadow outer binding', solve([{}, {'a': 1}], ['a', 2]), [{'a': 2}, {'a': 1}])
check('new key belongs inner', solve([{}, {}], ['a', 1]), [{'a': 1}, {}])
check('replace inner', solve([{'a': 1}, {'a': 3}], ['a', 2]), [{'a': 2}, {'a': 3}])
check('one scope', 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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| shadow outer binding | [{}, {'a': 2}] | [{'a': 2}, {'a': 1}] | Failed |
| new key belongs inner | [{'a': 1}, {}] | [{'a': 1}, {}] | Passed |
| replace inner | [{'a': 2}, {'a': 3}] | [{'a': 2}, {'a': 3}] | Passed |
| one scope | [{'a': 1}] | [{'a': 1}] | Passed |
SHA-256 / 6967f50dce10cdc765bc45a49e1fb55c61f976052c7d93ebe89d1f5d7bab2ffb
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=[dict(m) for m in x]; a[-1][y[0]]=y[1]; return a
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('shadow outer binding', solve([{}, {'a': 1}], ['a', 2]), [{'a': 2}, {'a': 1}])
check('new key belongs inner', solve([{}, {}], ['a', 1]), [{'a': 1}, {}])
check('replace inner', solve([{'a': 1}, {'a': 3}], ['a', 2]), [{'a': 2}, {'a': 3}])
check('one scope', 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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| shadow outer binding | [{}, {'a': 2}] | [{'a': 2}, {'a': 1}] | Failed |
| new key belongs inner | [{}, {'a': 1}] | [{'a': 1}, {}] | Failed |
| replace inner | [{'a': 1}, {'a': 2}] | [{'a': 2}, {'a': 3}] | Failed |
| one scope | [{'a': 1}] | [{'a': 1}] | Passed |
SHA-256 / 1b2cd40b733fc31d3956b07c2c4320fbf4810e7f8b04935fe6be4c2ec4d9f9a5
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=[dict(m) for m in x]; c=ChainMap(*a); c[y[0]]=y[1]; return c.maps
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('shadow outer binding', solve([{}, {'a': 1}], ['a', 2]), [{'a': 2}, {'a': 1}])
check('new key belongs inner', solve([{}, {}], ['a', 1]), [{'a': 1}, {}])
check('replace inner', solve([{'a': 1}, {'a': 3}], ['a', 2]), [{'a': 2}, {'a': 3}])
check('one scope', 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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| shadow outer binding | [{'a': 2}, {'a': 1}] | [{'a': 2}, {'a': 1}] | Passed |
| new key belongs inner | [{'a': 1}, {}] | [{'a': 1}, {}] | Passed |
| replace inner | [{'a': 2}, {'a': 3}] | [{'a': 2}, {'a': 3}] | Passed |
| one scope | [{'a': 1}] | [{'a': 1}] | Passed |
SHA-256 / 44ec3dadaae122378011154d4423452ad998212dd4740a3662c178a7209ecd1c
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.105166+00:00.
Case digest / 862142228e320f76c9e4c6168006740695bda87b7f9581761e98cd4fe1a4c4b2