FAILURE MAP
← Case archive

FA-4541 / Iterator consumption / Open access

Takewhile consumes first failure · case 01

The operation returns a result or retained state that violates this contract: Consume the prefix before sentinel, consuming but excluding the first sentinel; return [prefix,remainder].

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

ROOT CAUSE

Filtering the whole stream does not stop at the first predicate failure.

VERIFIED REPAIR

Consume the prefix before sentinel, consuming but excluding the first sentinel; return [prefix,remainder].

Unsuccessful approach: Index-based partitioning incorrectly returns the consumed sentinel in the tail.

Case contract

Consume the prefix before sentinel, consuming but excluding the first sentinel; return [prefix,remainder]. 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
import itertools as it
from collections import deque
N = 1
observations = []
def solve(x, y=None):
    g=iter(x); a=[v for v in g if v!=y]; return [a,list(g)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('middle stop', solve(['a', 'stop', 'b'], 'stop'), [['a'], ['b']])
check('stop first', solve(['stop', 'a'], 'stop'), [[], ['a']])
check('no stop', solve(['a'], 'stop'), [['a'], []])
check('empty', solve([], 'stop'), [[], []])
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
middle stop[['a', 'b'], []][['a'], ['b']]Failed
stop first[['a'], []][[], ['a']]Failed
no stop[['a'], []][['a'], []]Passed
empty[[], []][[], []]Passed

SHA-256 / 86e66064cdf40cfcdf24775c880e969b0b41012d7168b8df2eaada859b7576db

2 / The unsuccessful fix

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
import itertools as it
from collections import deque
N = 1
observations = []
def solve(x, y=None):
    i=x.index(y) if y in x else len(x); return [x[:i],x[i:]]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('middle stop', solve(['a', 'stop', 'b'], 'stop'), [['a'], ['b']])
check('stop first', solve(['stop', 'a'], 'stop'), [[], ['a']])
check('no stop', solve(['a'], 'stop'), [['a'], []])
check('empty', solve([], 'stop'), [[], []])
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
middle stop[['a'], ['stop', 'b']][['a'], ['b']]Failed
stop first[[], ['stop', 'a']][[], ['a']]Failed
no stop[['a'], []][['a'], []]Passed
empty[[], []][[], []]Passed

SHA-256 / 06446dce6288590a3081a7271b89246cf0802e57bd5caf10e1fcff55f60b8021

3 / The verified repair

Exit 0
"""Failure Map reference implementation. Python standard library only."""
import json
import itertools as it
from collections import deque
N = 1
observations = []
def solve(x, y=None):
    g=iter(x); a=list(it.takewhile(lambda v:v!=y,g)); return [a,list(g)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('middle stop', solve(['a', 'stop', 'b'], 'stop'), [['a'], ['b']])
check('stop first', solve(['stop', 'a'], 'stop'), [[], ['a']])
check('no stop', solve(['a'], 'stop'), [['a'], []])
check('empty', solve([], 'stop'), [[], []])
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
middle stop[['a'], ['b']][['a'], ['b']]Passed
stop first[[], ['a']][[], ['a']]Passed
no stop[['a'], []][['a'], []]Passed
empty[[], []][[], []]Passed

SHA-256 / efc6cd21ff52871bca5f11592e7b6e11696583106da9db125c169a7a9d14e027

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

Case digest / c0f98337df47414c4ec587b55a3cfc4d7c919e989daabdda305d541d9876fd95