{"abstract":"CTE lookup searches outer scopes before inner scopes.","category":"Data systems","checks":7,"contract":"Interpret nested query blocks using actions push(definitions), pop, and read(name). Every push opens a new CTE scope; reads search innermost scope first then outer scopes. Empty inner scopes still hide nothing, popping restores outer definitions, and unresolved names yield MISSING. Definitions are already evaluated row lists.","evaluation_group":"s3-data-systems-cte-lexical-environments","failed_approach":"Restricting lookup to the innermost scope fixes shadowing but prevents outer fallback.","family":"s3-data-systems-cte-lexical-environments-scope-direction","id":"FA-45601","implementations":{"attempt":{"sha256":"065c73d60a3f465daea384e76813def732224c6d0582db088787ab8b15b312a9","source":"\"\"\"Failure Map reference implementation. Python standard library only.\"\"\"\nimport json\n\nN = 1\nobservations = []\ndef solve(d):\n    try:\n        scopes=[{}]; out=[]\n        for action,arg in d:\n            if action=='push': scopes.append(dict(arg))\n            elif action=='pop': scopes.pop()\n            else:\n                found='MISSING'\n                for scope in scopes[-1:]:\n                    if arg in scope: found=scope[arg]; break\n                out.append(found)\n        return out\n    except (IndexError, KeyError, ValueError, StopIteration) as exc:\n        return {\"representation_error\": type(exc).__name__}\ndef check(label, actual, expected):\n    observations.append({\"check\": label, \"actual\": actual, \"expected\": expected, \"passed\": actual == expected})\nif N == 1:\n    check('inner shadow', solve([['push', {'x': [1]}], ['push', {'x': [2]}], ['read', 'x'], ['pop', None], ['read', 'x']]), [[2], [1]])\n    check('outer fallback', solve([['push', {'x': [1]}], ['push', {}], ['read', 'x']]), [[1]])\n    check('empty shadow', solve([['push', {'x': [1]}], ['push', {'x': []}], ['read', 'x']]), [[]])\n    check('missing name', solve([['read', 'x']]), ['MISSING'])\n    check('restore missing', solve([['push', {'x': [1]}], ['pop', None], ['read', 'x']]), ['MISSING'])\n    check('nested pops', solve([['push', {'x': [1]}], ['push', {'x': [2]}], ['push', {}], ['pop', None], ['pop', None], ['read', 'x']]), [[1]])\n    check('no actions', solve([]), [])\nelif N == 2:\n    check('inner shadow', solve([['push', {'x': [2]}], ['push', {'x': [3]}], ['read', 'x'], ['pop', None], ['read', 'x']]), [[3], [2]])\n    check('outer fallback', solve([['push', {'x': [2]}], ['push', {}], ['read', 'x']]), [[2]])\n    check('empty shadow', solve([['push', {'x': [2]}], ['push', {'x': []}], ['read', 'x']]), [[]])\n    check('missing name', solve([['read', 'x']]), ['MISSING'])\n    check('restore missing', solve([['push', {'x': [2]}], ['pop', None], ['read', 'x']]), ['MISSING'])\n    check('nested pops', solve([['push', {'x': [2]}], ['push', {'x': [3]}], ['push', {}], ['pop', None], ['pop', None], ['read', 'x']]), [[2]])\n    check('no actions', solve([]), [])\nelif N == 3:\n    check('inner shadow', solve([['push', {'x': [3]}], ['push', {'x': [4]}], ['read', 'x'], ['pop', None], ['read', 'x']]), [[4], [3]])\n    check('outer fallback', solve([['push', {'x': [3]}], ['push', {}], ['read', 'x']]), [[3]])\n    check('empty shadow', solve([['push', {'x': [3]}], ['push', {'x': []}], ['read', 'x']]), [[]])\n    check('missing name', solve([['read', 'x']]), ['MISSING'])\n    check('restore missing', solve([['push', {'x': [3]}], ['pop', None], ['read', 'x']]), ['MISSING'])\n    check('nested pops', solve([['push', {'x': [3]}], ['push', {'x': [4]}], ['push', {}], ['pop', None], ['pop', None], ['read', 'x']]), [[3]])\n    check('no actions', solve([]), [])\nelif N == 4:\n    check('inner shadow', solve([['push', {'x': [4]}], ['push', {'x': [5]}], ['read', 'x'], ['pop', None], ['read', 'x']]), [[5], [4]])\n    check('outer fallback', solve([['push', {'x': [4]}], ['push', {}], ['read', 'x']]), [[4]])\n    check('empty shadow', solve([['push', {'x': [4]}], ['push', {'x': []}], ['read', 'x']]), [[]])\n    check('missing name', solve([['read', 'x']]), ['MISSING'])\n    check('restore missing', solve([['push', {'x': [4]}], ['pop', None], ['read', 'x']]), ['MISSING'])\n    check('nested pops', solve([['push', {'x': [4]}], ['push', {'x': [5]}], ['push', {}], ['pop', None], ['pop', None], ['read', 'x']]), [[4]])\n    check('no actions', solve([]), [])\nelif N == 5:\n    check('inner shadow', solve([['push', {'x': [5]}], ['push', {'x': [6]}], ['read', 'x'], ['pop', None], ['read', 'x']]), [[6], [5]])\n    check('outer fallback', solve([['push', {'x': [5]}], ['push', {}], ['read', 'x']]), [[5]])\n    check('empty shadow', solve([['push', {'x': [5]}], ['push', {'x': []}], ['read', 'x']]), [[]])\n    check('missing name', solve([['read', 'x']]), ['MISSING'])\n    check('restore missing', solve([['push', {'x': [5]}], ['pop', None], ['read', 'x']]), ['MISSING'])\n    check('nested pops', solve([['push', {'x': [5]}], ['push', {'x': [6]}], ['push', {}], ['pop', None], ['pop', None], ['read', 'x']]), [[5]])\n    check('no actions', solve([]), [])\nprint(json.dumps({\"observations\": observations, \"passed\": all(x[\"passed\"] for x in observations)}, ensure_ascii=False))\nraise SystemExit(0 if all(x[\"passed\"] for x in observations) else 1)\n"},"broken":{"sha256":"56ff06d20787fbc8810273e6f689ea948fed56532b74607dab16590eca8a6719","source":"\"\"\"Failure Map reference implementation. Python standard library only.\"\"\"\nimport json\n\nN = 1\nobservations = []\ndef solve(d):\n    try:\n        scopes=[{}]; out=[]\n        for action,arg in d:\n            if action=='push': scopes.append(dict(arg))\n            elif action=='pop': scopes.pop()\n            else:\n                found='MISSING'\n                for scope in scopes:\n                    if arg in scope: found=scope[arg]; break\n                out.append(found)\n        return out\n    except (IndexError, KeyError, ValueError, StopIteration) as exc:\n        return {\"representation_error\": type(exc).__name__}\ndef check(label, actual, expected):\n    observations.append({\"check\": label, \"actual\": actual, \"expected\": expected, \"passed\": actual == expected})\nif N == 1:\n    check('inner shadow', solve([['push', {'x': [1]}], ['push', {'x': [2]}], ['read', 'x'], ['pop', None], ['read', 'x']]), [[2], [1]])\n    check('outer fallback', solve([['push', {'x': [1]}], ['push', {}], ['read', 'x']]), [[1]])\n    check('empty shadow', solve([['push', {'x': [1]}], ['push', {'x': []}], ['read', 'x']]), [[]])\n    check('missing name', solve([['read', 'x']]), ['MISSING'])\n    check('restore missing', solve([['push', {'x': [1]}], ['pop', None], ['read', 'x']]), ['MISSING'])\n    check('nested pops', solve([['push', {'x': [1]}], ['push', {'x': [2]}], ['push', {}], ['pop', None], ['pop', None], ['read', 'x']]), [[1]])\n    check('no actions', solve([]), [])\nelif N == 2:\n    check('inner shadow', solve([['push', {'x': [2]}], ['push', {'x': [3]}], ['read', 'x'], ['pop', None], ['read', 'x']]), [[3], [2]])\n    check('outer fallback', solve([['push', {'x': [2]}], ['push', {}], ['read', 'x']]), [[2]])\n    check('empty shadow', solve([['push', {'x': [2]}], ['push', {'x': []}], ['read', 'x']]), [[]])\n    check('missing name', solve([['read', 'x']]), ['MISSING'])\n    check('restore missing', solve([['push', {'x': [2]}], ['pop', None], ['read', 'x']]), ['MISSING'])\n    check('nested pops', solve([['push', {'x': [2]}], ['push', {'x': [3]}], ['push', {}], ['pop', None], ['pop', None], ['read', 'x']]), [[2]])\n    check('no actions', solve([]), [])\nelif N == 3:\n    check('inner shadow', solve([['push', {'x': [3]}], ['push', {'x': [4]}], ['read', 'x'], ['pop', None], ['read', 'x']]), [[4], [3]])\n    check('outer fallback', solve([['push', {'x': [3]}], ['push', {}], ['read', 'x']]), [[3]])\n    check('empty shadow', solve([['push', {'x': [3]}], ['push', {'x': []}], ['read', 'x']]), [[]])\n    check('missing name', solve([['read', 'x']]), ['MISSING'])\n    check('restore missing', solve([['push', {'x': [3]}], ['pop', None], ['read', 'x']]), ['MISSING'])\n    check('nested pops', solve([['push', {'x': [3]}], ['push', {'x': [4]}], ['push', {}], ['pop', None], ['pop', None], ['read', 'x']]), [[3]])\n    check('no actions', solve([]), [])\nelif N == 4:\n    check('inner shadow', solve([['push', {'x': [4]}], ['push', {'x': [5]}], ['read', 'x'], ['pop', None], ['read', 'x']]), [[5], [4]])\n    check('outer fallback', solve([['push', {'x': [4]}], ['push', {}], ['read', 'x']]), [[4]])\n    check('empty shadow', solve([['push', {'x': [4]}], ['push', {'x': []}], ['read', 'x']]), [[]])\n    check('missing name', solve([['read', 'x']]), ['MISSING'])\n    check('restore missing', solve([['push', {'x': [4]}], ['pop', None], ['read', 'x']]), ['MISSING'])\n    check('nested pops', solve([['push', {'x': [4]}], ['push', {'x': [5]}], ['push', {}], ['pop', None], ['pop', None], ['read', 'x']]), [[4]])\n    check('no actions', solve([]), [])\nelif N == 5:\n    check('inner shadow', solve([['push', {'x': [5]}], ['push', {'x': [6]}], ['read', 'x'], ['pop', None], ['read', 'x']]), [[6], [5]])\n    check('outer fallback', solve([['push', {'x': [5]}], ['push', {}], ['read', 'x']]), [[5]])\n    check('empty shadow', solve([['push', {'x': [5]}], ['push', {'x': []}], ['read', 'x']]), [[]])\n    check('missing name', solve([['read', 'x']]), ['MISSING'])\n    check('restore missing', solve([['push', {'x': [5]}], ['pop', None], ['read', 'x']]), ['MISSING'])\n    check('nested pops', solve([['push', {'x': [5]}], ['push', {'x': [6]}], ['push', {}], ['pop', None], ['pop', None], ['read', 'x']]), [[5]])\n    check('no actions', solve([]), [])\nprint(json.dumps({\"observations\": observations, \"passed\": all(x[\"passed\"] for x in observations)}, ensure_ascii=False))\nraise SystemExit(0 if all(x[\"passed\"] for x in observations) else 1)\n"},"fixed":{"sha256":"6f6534aa1ff2c258ca2015af67b08f8ac06efa282c875621256588015773afb8","source":"\"\"\"Failure Map reference implementation. Python standard library only.\"\"\"\nimport json\n\nN = 1\nobservations = []\ndef solve(d):\n    try:\n        scopes=[{}]; out=[]\n        for action,arg in d:\n            if action=='push': scopes.append(dict(arg))\n            elif action=='pop': scopes.pop()\n            else:\n                found='MISSING'\n                for scope in reversed(scopes):\n                    if arg in scope: found=scope[arg]; break\n                out.append(found)\n        return out\n    except (IndexError, KeyError, ValueError, StopIteration) as exc:\n        return {\"representation_error\": type(exc).__name__}\ndef check(label, actual, expected):\n    observations.append({\"check\": label, \"actual\": actual, \"expected\": expected, \"passed\": actual == expected})\nif N == 1:\n    check('inner shadow', solve([['push', {'x': [1]}], ['push', {'x': [2]}], ['read', 'x'], ['pop', None], ['read', 'x']]), [[2], [1]])\n    check('outer fallback', solve([['push', {'x': [1]}], ['push', {}], ['read', 'x']]), [[1]])\n    check('empty shadow', solve([['push', {'x': [1]}], ['push', {'x': []}], ['read', 'x']]), [[]])\n    check('missing name', solve([['read', 'x']]), ['MISSING'])\n    check('restore missing', solve([['push', {'x': [1]}], ['pop', None], ['read', 'x']]), ['MISSING'])\n    check('nested pops', solve([['push', {'x': [1]}], ['push', {'x': [2]}], ['push', {}], ['pop', None], ['pop', None], ['read', 'x']]), [[1]])\n    check('no actions', solve([]), [])\nelif N == 2:\n    check('inner shadow', solve([['push', {'x': [2]}], ['push', {'x': [3]}], ['read', 'x'], ['pop', None], ['read', 'x']]), [[3], [2]])\n    check('outer fallback', solve([['push', {'x': [2]}], ['push', {}], ['read', 'x']]), [[2]])\n    check('empty shadow', solve([['push', {'x': [2]}], ['push', {'x': []}], ['read', 'x']]), [[]])\n    check('missing name', solve([['read', 'x']]), ['MISSING'])\n    check('restore missing', solve([['push', {'x': [2]}], ['pop', None], ['read', 'x']]), ['MISSING'])\n    check('nested pops', solve([['push', {'x': [2]}], ['push', {'x': [3]}], ['push', {}], ['pop', None], ['pop', None], ['read', 'x']]), [[2]])\n    check('no actions', solve([]), [])\nelif N == 3:\n    check('inner shadow', solve([['push', {'x': [3]}], ['push', {'x': [4]}], ['read', 'x'], ['pop', None], ['read', 'x']]), [[4], [3]])\n    check('outer fallback', solve([['push', {'x': [3]}], ['push', {}], ['read', 'x']]), [[3]])\n    check('empty shadow', solve([['push', {'x': [3]}], ['push', {'x': []}], ['read', 'x']]), [[]])\n    check('missing name', solve([['read', 'x']]), ['MISSING'])\n    check('restore missing', solve([['push', {'x': [3]}], ['pop', None], ['read', 'x']]), ['MISSING'])\n    check('nested pops', solve([['push', {'x': [3]}], ['push', {'x': [4]}], ['push', {}], ['pop', None], ['pop', None], ['read', 'x']]), [[3]])\n    check('no actions', solve([]), [])\nelif N == 4:\n    check('inner shadow', solve([['push', {'x': [4]}], ['push', {'x': [5]}], ['read', 'x'], ['pop', None], ['read', 'x']]), [[5], [4]])\n    check('outer fallback', solve([['push', {'x': [4]}], ['push', {}], ['read', 'x']]), [[4]])\n    check('empty shadow', solve([['push', {'x': [4]}], ['push', {'x': []}], ['read', 'x']]), [[]])\n    check('missing name', solve([['read', 'x']]), ['MISSING'])\n    check('restore missing', solve([['push', {'x': [4]}], ['pop', None], ['read', 'x']]), ['MISSING'])\n    check('nested pops', solve([['push', {'x': [4]}], ['push', {'x': [5]}], ['push', {}], ['pop', None], ['pop', None], ['read', 'x']]), [[4]])\n    check('no actions', solve([]), [])\nelif N == 5:\n    check('inner shadow', solve([['push', {'x': [5]}], ['push', {'x': [6]}], ['read', 'x'], ['pop', None], ['read', 'x']]), [[6], [5]])\n    check('outer fallback', solve([['push', {'x': [5]}], ['push', {}], ['read', 'x']]), [[5]])\n    check('empty shadow', solve([['push', {'x': [5]}], ['push', {'x': []}], ['read', 'x']]), [[]])\n    check('missing name', solve([['read', 'x']]), ['MISSING'])\n    check('restore missing', solve([['push', {'x': [5]}], ['pop', None], ['read', 'x']]), ['MISSING'])\n    check('nested pops', solve([['push', {'x': [5]}], ['push', {'x': [6]}], ['push', {}], ['pop', None], ['pop', None], ['read', 'x']]), [[5]])\n    check('no actions', solve([]), [])\nprint(json.dumps({\"observations\": observations, \"passed\": all(x[\"passed\"] for x in observations)}, ensure_ascii=False))\nraise SystemExit(0 if all(x[\"passed\"] for x in observations) else 1)\n"}},"limitations":"Offline stipulated semantics over valid small inputs; no performance, concurrency, or production-engine conformance claim. 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.","method":"Deterministic executable model with adversarial boundary fixtures.","provenance":{"created_by":"Failure Map","dependencies":"Python standard library","family":"s3-data-systems-cte-lexical-environments-scope-direction","generated_at":"2026-09-29T14:44:23.919062+00:00","license":"CC0-1.0","python":"3.12.14","seed":1,"split":"open-access"},"relevance":"A bounded deterministic data engine model makes representation and changelog faults reproducible.","repair":"Preserve the stated physical representation and operation order: Interpret nested query blocks using actions push(definitions), pop, and read(name). Every push opens a new CTE scope; reads search innermost scope first then outer scopes. Empty inner scopes still hide nothing, popping restores outer definitions, and unresolved names yield MISSING. Definitions are already evaluated row lists.","root_cause":"cte-lexical-environments: CTE lookup searches outer scopes before inner scopes.","sha256":"0f4f3de66d8391f353d03a4ee51d147cdfc4f3081d8b432ce981040ab09cda28","title":"CTE lookup searches outer scopes before inner scopes · case 01","variant":1,"variant_policy":"Five numbered records share a model and may reuse boundary fixtures.","verification":{"attempt":{"elapsed_ms":40.169,"exit_code":1,"observations":[{"actual":[[2],[1]],"check":"inner shadow","expected":[[2],[1]],"passed":true},{"actual":["MISSING"],"check":"outer fallback","expected":[[1]],"passed":false},{"actual":[[]],"check":"empty shadow","expected":[[]],"passed":true},{"actual":["MISSING"],"check":"missing name","expected":["MISSING"],"passed":true},{"actual":["MISSING"],"check":"restore missing","expected":["MISSING"],"passed":true},{"actual":[[1]],"check":"nested pops","expected":[[1]],"passed":true},{"actual":[],"check":"no actions","expected":[],"passed":true}],"passed":false,"stderr":"","stdout":"{\"observations\": [{\"check\": \"inner shadow\", \"actual\": [[2], [1]], \"expected\": [[2], [1]], \"passed\": true}, {\"check\": \"outer fallback\", \"actual\": [\"MISSING\"], \"expected\": [[1]], \"passed\": false}, {\"check\": \"empty shadow\", \"actual\": [[]], \"expected\": [[]], \"passed\": true}, {\"check\": \"missing name\", \"actual\": [\"MISSING\"], \"expected\": [\"MISSING\"], \"passed\": true}, {\"check\": \"restore missing\", \"actual\": [\"MISSING\"], \"expected\": [\"MISSING\"], \"passed\": true}, {\"check\": \"nested pops\", \"actual\": [[1]], \"expected\": [[1]], \"passed\": true}, {\"check\": \"no actions\", \"actual\": [], \"expected\": [], \"passed\": true}], \"passed\": false}\n"},"broken":{"elapsed_ms":43.19,"exit_code":1,"observations":[{"actual":[[1],[1]],"check":"inner shadow","expected":[[2],[1]],"passed":false},{"actual":[[1]],"check":"outer fallback","expected":[[1]],"passed":true},{"actual":[[1]],"check":"empty shadow","expected":[[]],"passed":false},{"actual":["MISSING"],"check":"missing name","expected":["MISSING"],"passed":true},{"actual":["MISSING"],"check":"restore missing","expected":["MISSING"],"passed":true},{"actual":[[1]],"check":"nested pops","expected":[[1]],"passed":true},{"actual":[],"check":"no actions","expected":[],"passed":true}],"passed":false,"stderr":"","stdout":"{\"observations\": [{\"check\": \"inner shadow\", \"actual\": [[1], [1]], \"expected\": [[2], [1]], \"passed\": false}, {\"check\": \"outer fallback\", \"actual\": [[1]], \"expected\": [[1]], \"passed\": true}, {\"check\": \"empty shadow\", \"actual\": [[1]], \"expected\": [[]], \"passed\": false}, {\"check\": \"missing name\", \"actual\": [\"MISSING\"], \"expected\": [\"MISSING\"], \"passed\": true}, {\"check\": \"restore missing\", \"actual\": [\"MISSING\"], \"expected\": [\"MISSING\"], \"passed\": true}, {\"check\": \"nested pops\", \"actual\": [[1]], \"expected\": [[1]], \"passed\": true}, {\"check\": \"no actions\", \"actual\": [], \"expected\": [], \"passed\": true}], \"passed\": false}\n"},"fixed":{"elapsed_ms":44.451,"exit_code":0,"observations":[{"actual":[[2],[1]],"check":"inner shadow","expected":[[2],[1]],"passed":true},{"actual":[[1]],"check":"outer fallback","expected":[[1]],"passed":true},{"actual":[[]],"check":"empty shadow","expected":[[]],"passed":true},{"actual":["MISSING"],"check":"missing name","expected":["MISSING"],"passed":true},{"actual":["MISSING"],"check":"restore missing","expected":["MISSING"],"passed":true},{"actual":[[1]],"check":"nested pops","expected":[[1]],"passed":true},{"actual":[],"check":"no actions","expected":[],"passed":true}],"passed":true,"stderr":"","stdout":"{\"observations\": [{\"check\": \"inner shadow\", \"actual\": [[2], [1]], \"expected\": [[2], [1]], \"passed\": true}, {\"check\": \"outer fallback\", \"actual\": [[1]], \"expected\": [[1]], \"passed\": true}, {\"check\": \"empty shadow\", \"actual\": [[]], \"expected\": [[]], \"passed\": true}, {\"check\": \"missing name\", \"actual\": [\"MISSING\"], \"expected\": [\"MISSING\"], \"passed\": true}, {\"check\": \"restore missing\", \"actual\": [\"MISSING\"], \"expected\": [\"MISSING\"], \"passed\": true}, {\"check\": \"nested pops\", \"actual\": [[1]], \"expected\": [[1]], \"passed\": true}, {\"check\": \"no actions\", \"actual\": [], \"expected\": [], \"passed\": true}], \"passed\": true}\n"}},"verified":true,"visibility":"public"}