FA-5176 / Context managers / Open access
Context enter binding: Calls __enter__ manually and loses guaranteed exit on body failure · case 01
Calls __enter__ manually and loses guaranteed exit on body failure and changes the required Python-language result.
ROOT CAUSE
Calls __enter__ manually and loses guaranteed exit on body failure. The executable reproducer isolates this operation from the rest of the contract.
VERIFIED REPAIR
Bind the exact __enter__ return value to the with target, including false values. A failing __enter__ prevents body and __exit__; body exceptions still call __exit__.
Unsuccessful approach: The alternative still fails because it binds the manager object label instead of its __enter__ result.
Case contract
Bind the exact __enter__ return value to the with target, including false values. A failing __enter__ prevents body and __exit__; body exceptions still call __exit__. 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(payload, fail, body_error):
log=[]
try:
log.append('enter')
if fail: raise ValueError('enter failed')
log.append(['body',payload])
if body_error: raise KeyError('body failed')
log.append('exit')
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('ordinary binding', solve('value', False, False), ['enter', ['body', 'value'], 'exit'])
check('false return remains bound', solve(0, False, False), ['enter', ['body', 0], 'exit'])
check('None return remains bound', solve(None, False, False), ['enter', ['body', None], 'exit'])
check('enter failure skips exit', solve('value', True, False), ['enter', 'ValueError'])
check('body failure still exits', solve('value', False, True), ['enter', ['body', 'value'], 'exit', '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 |
|---|---|---|---|
| ordinary binding | ['enter', ['body', 'value'], 'exit'] | ['enter', ['body', 'value'], 'exit'] | Passed |
| false return remains bound | ['enter', ['body', 0], 'exit'] | ['enter', ['body', 0], 'exit'] | Passed |
| None return remains bound | ['enter', ['body', None], 'exit'] | ['enter', ['body', None], 'exit'] | Passed |
| enter failure skips exit | ['enter', 'ValueError'] | ['enter', 'ValueError'] | Passed |
| body failure still exits | ['enter', ['body', 'value'], 'KeyError'] | ['enter', ['body', 'value'], 'exit', 'KeyError'] | Failed |
SHA-256 / f1a3f9b26aeae6a0b7a9b4649d4a4daa84645e7c7d69269056945f0fe4a6ed25
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(payload, fail, body_error):
log=[]
class Manager:
def __init__(self): self.value='manager'
def __enter__(self):
log.append('enter')
if fail: raise ValueError('enter failed')
return payload
def __exit__(self,typ,exc,tb): log.append('exit'); return False
manager=Manager()
try:
with manager as bound:
log.append(['body',manager.value])
if body_error: raise KeyError('body failed')
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('ordinary binding', solve('value', False, False), ['enter', ['body', 'value'], 'exit'])
check('false return remains bound', solve(0, False, False), ['enter', ['body', 0], 'exit'])
check('None return remains bound', solve(None, False, False), ['enter', ['body', None], 'exit'])
check('enter failure skips exit', solve('value', True, False), ['enter', 'ValueError'])
check('body failure still exits', solve('value', False, True), ['enter', ['body', 'value'], 'exit', '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 |
|---|---|---|---|
| ordinary binding | ['enter', ['body', 'manager'], 'exit'] | ['enter', ['body', 'value'], 'exit'] | Failed |
| false return remains bound | ['enter', ['body', 'manager'], 'exit'] | ['enter', ['body', 0], 'exit'] | Failed |
| None return remains bound | ['enter', ['body', 'manager'], 'exit'] | ['enter', ['body', None], 'exit'] | Failed |
| enter failure skips exit | ['enter', 'ValueError'] | ['enter', 'ValueError'] | Passed |
| body failure still exits | ['enter', ['body', 'manager'], 'exit', 'KeyError'] | ['enter', ['body', 'value'], 'exit', 'KeyError'] | Failed |
SHA-256 / 1e347d27e380eec6baaf824a3a2026081931f7aa0acf869cc5f8ed1b5d24c587
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(payload, fail, body_error):
log=[]
class Manager:
def __init__(self): self.value='manager'
def __enter__(self):
log.append('enter')
if fail: raise ValueError('enter failed')
return payload
def __exit__(self,typ,exc,tb): log.append('exit'); return False
manager=Manager()
try:
with manager as bound:
log.append(['body',bound])
if body_error: raise KeyError('body failed')
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('ordinary binding', solve('value', False, False), ['enter', ['body', 'value'], 'exit'])
check('false return remains bound', solve(0, False, False), ['enter', ['body', 0], 'exit'])
check('None return remains bound', solve(None, False, False), ['enter', ['body', None], 'exit'])
check('enter failure skips exit', solve('value', True, False), ['enter', 'ValueError'])
check('body failure still exits', solve('value', False, True), ['enter', ['body', 'value'], 'exit', '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 |
|---|---|---|---|
| ordinary binding | ['enter', ['body', 'value'], 'exit'] | ['enter', ['body', 'value'], 'exit'] | Passed |
| false return remains bound | ['enter', ['body', 0], 'exit'] | ['enter', ['body', 0], 'exit'] | Passed |
| None return remains bound | ['enter', ['body', None], 'exit'] | ['enter', ['body', None], 'exit'] | Passed |
| enter failure skips exit | ['enter', 'ValueError'] | ['enter', 'ValueError'] | Passed |
| body failure still exits | ['enter', ['body', 'value'], 'exit', 'KeyError'] | ['enter', ['body', 'value'], 'exit', 'KeyError'] | Passed |
SHA-256 / 73b8659395ff0179c5440f6dec07c2cc5f47e44c7f652f79e33d9410b3729621
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.820375+00:00.
Case digest / 5721f11f52629c5e7857903225c85da146363ca409ea5da58952dfd4df63d06d