FA-5186 / Context managers / Open access
Nested context unwinding: Forgets to acquire the outer manager · case 01
Forgets to acquire the outer manager and changes the required Python-language result.
ROOT CAUSE
Forgets to acquire the outer manager. The executable reproducer isolates this operation from the rest of the contract.
VERIFIED REPAIR
Enter A then B and exit acquired managers in reverse order. A manager whose __enter__ raises is not exited; previously entered managers still exit. Body errors unwind both.
Unsuccessful approach: The alternative still fails because it forgets to acquire the inner manager.
Case contract
Enter A then B and exit acquired managers in reverse order. A manager whose __enter__ raises is not exited; previously entered managers still exit. Body errors unwind both. Inputs use the finite Python types shown in the fixtures. An error string denotes the specified caught exception, not an unhandled process failure.
Why this case matters
Runs Python standard-library language operations in a deterministic local reproducer. Literal expected answers are authored independently. Related defects share an evaluation group to avoid benchmark split leakage.
1 / The failure
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(fail, body_error):
log=[]
class Manager:
def __init__(self,name): self.name=name
def __enter__(self):
log.append('enter:'+self.name)
if fail==self.name: raise ValueError(self.name)
return self
def __exit__(self,typ,exc,tb): log.append('exit:'+self.name); return False
try:
with Manager('B'):
log.append('body')
if body_error: raise KeyError('body')
except Exception as exc: log.append(type(exc).__name__)
return log
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('normal nesting', solve(None, False), ['enter:A', 'enter:B', 'body', 'exit:B', 'exit:A'])
check('first enter fails', solve('A', False), ['enter:A', 'ValueError'])
check('second enter fails', solve('B', False), ['enter:A', 'enter:B', 'exit:A', 'ValueError'])
check('body unwinds both', solve(None, True), ['enter:A', 'enter:B', 'body', 'exit:B', 'exit:A', 'KeyError'])
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 |
|---|---|---|---|
| normal nesting | ['enter:B', 'body', 'exit:B'] | ['enter:A', 'enter:B', 'body', 'exit:B', 'exit:A'] | Failed |
| first enter fails | ['enter:B', 'body', 'exit:B'] | ['enter:A', 'ValueError'] | Failed |
| second enter fails | ['enter:B', 'ValueError'] | ['enter:A', 'enter:B', 'exit:A', 'ValueError'] | Failed |
| body unwinds both | ['enter:B', 'body', 'exit:B', 'KeyError'] | ['enter:A', 'enter:B', 'body', 'exit:B', 'exit:A', 'KeyError'] | Failed |
SHA-256 / 6ade3c21450b682c25008b02e233b4872fded5b40a61dc6281f026e887a55087
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(fail, body_error):
log=[]
class Manager:
def __init__(self,name): self.name=name
def __enter__(self):
log.append('enter:'+self.name)
if fail==self.name: raise ValueError(self.name)
return self
def __exit__(self,typ,exc,tb): log.append('exit:'+self.name); return False
try:
with Manager('A'):
log.append('body')
if body_error: raise KeyError('body')
except Exception as exc: log.append(type(exc).__name__)
return log
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('normal nesting', solve(None, False), ['enter:A', 'enter:B', 'body', 'exit:B', 'exit:A'])
check('first enter fails', solve('A', False), ['enter:A', 'ValueError'])
check('second enter fails', solve('B', False), ['enter:A', 'enter:B', 'exit:A', 'ValueError'])
check('body unwinds both', solve(None, True), ['enter:A', 'enter:B', 'body', 'exit:B', 'exit:A', 'KeyError'])
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 |
|---|---|---|---|
| normal nesting | ['enter:A', 'body', 'exit:A'] | ['enter:A', 'enter:B', 'body', 'exit:B', 'exit:A'] | Failed |
| first enter fails | ['enter:A', 'ValueError'] | ['enter:A', 'ValueError'] | Passed |
| second enter fails | ['enter:A', 'body', 'exit:A'] | ['enter:A', 'enter:B', 'exit:A', 'ValueError'] | Failed |
| body unwinds both | ['enter:A', 'body', 'exit:A', 'KeyError'] | ['enter:A', 'enter:B', 'body', 'exit:B', 'exit:A', 'KeyError'] | Failed |
SHA-256 / 3f3b753d4c39751a3572b7ec99061ec9be9b44574da2ff576ab77b85a782f7b1
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(fail, body_error):
log=[]
class Manager:
def __init__(self,name): self.name=name
def __enter__(self):
log.append('enter:'+self.name)
if fail==self.name: raise ValueError(self.name)
return self
def __exit__(self,typ,exc,tb): log.append('exit:'+self.name); return False
try:
with Manager('A'), Manager('B'):
log.append('body')
if body_error: raise KeyError('body')
except Exception as exc: log.append(type(exc).__name__)
return log
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('normal nesting', solve(None, False), ['enter:A', 'enter:B', 'body', 'exit:B', 'exit:A'])
check('first enter fails', solve('A', False), ['enter:A', 'ValueError'])
check('second enter fails', solve('B', False), ['enter:A', 'enter:B', 'exit:A', 'ValueError'])
check('body unwinds both', solve(None, True), ['enter:A', 'enter:B', 'body', 'exit:B', 'exit:A', 'KeyError'])
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 |
|---|---|---|---|
| normal nesting | ['enter:A', 'enter:B', 'body', 'exit:B', 'exit:A'] | ['enter:A', 'enter:B', 'body', 'exit:B', 'exit:A'] | Passed |
| first enter fails | ['enter:A', 'ValueError'] | ['enter:A', 'ValueError'] | Passed |
| second enter fails | ['enter:A', 'enter:B', 'exit:A', 'ValueError'] | ['enter:A', 'enter:B', 'exit:A', 'ValueError'] | Passed |
| body unwinds both | ['enter:A', 'enter:B', 'body', 'exit:B', 'exit:A', 'KeyError'] | ['enter:A', 'enter:B', 'body', 'exit:B', 'exit:A', 'KeyError'] | Passed |
SHA-256 / 3cfc64d2cd163d48503d274f83ab8b0b5d8e8d7cd25949cce96e9ae6429c4bf1
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:46.939126+00:00.
Case digest / e717cc1be1f35b82c636d18b05a6e907f4ce8f6c55b13922505360dfcb252eb1