FAILURE MAP
← Case archive

FA-4571 / Iterator consumption / Open access

Groupby materialize before advancing · case 01

The operation returns a result or retained state that violates this contract: Materialize each group before advancing the outer group iterator, since group iterators share their source.

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

ROOT CAUSE

Advancing the outer iterator exhausts group iterators sharing its source.

VERIFIED REPAIR

Materialize each group before advancing the outer group iterator, since group iterators share their source.

Unsuccessful approach: Replacing invalidated groups with empty lists silently loses their contents.

Case contract

Materialize each group before advancing the outer group iterator, since group iterators share their source. 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):
    groups=list(it.groupby(x)); return [[k,list(g)] for k,g in groups]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('two groups', solve(['a', 'a', 'b']), [['a', ['a', 'a']], ['b', ['b']]])
check('one group', solve(['a', 'a']), [['a', ['a', 'a']]])
check('empty', solve([]), [])
check('three runs', solve(['b', 'a', 'b']), [['b', ['b']], ['a', ['a']], ['b', ['b']]])
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
two groups[['a', []], ['b', []]][['a', ['a', 'a']], ['b', ['b']]]Failed
one group[['a', []]][['a', ['a', 'a']]]Failed
empty[][]Passed
three runs[['b', []], ['a', []], ['b', []]][['b', ['b']], ['a', ['a']], ['b', ['b']]]Failed

SHA-256 / 1d8e3ffaddb14e9ee23cc909e957ba4d53ca01afae4afd2b62fa3b93b523a5a9

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):
    groups=list(it.groupby(x)); return [[k,[]] for k,g in groups]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('two groups', solve(['a', 'a', 'b']), [['a', ['a', 'a']], ['b', ['b']]])
check('one group', solve(['a', 'a']), [['a', ['a', 'a']]])
check('empty', solve([]), [])
check('three runs', solve(['b', 'a', 'b']), [['b', ['b']], ['a', ['a']], ['b', ['b']]])
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
two groups[['a', []], ['b', []]][['a', ['a', 'a']], ['b', ['b']]]Failed
one group[['a', []]][['a', ['a', 'a']]]Failed
empty[][]Passed
three runs[['b', []], ['a', []], ['b', []]][['b', ['b']], ['a', ['a']], ['b', ['b']]]Failed

SHA-256 / 3da4bf0c67a18fa6e99fa90566964416d484cd1e91c53e032595977bfaea209b

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):
    return [[k,list(g)] for k,g in it.groupby(x)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('two groups', solve(['a', 'a', 'b']), [['a', ['a', 'a']], ['b', ['b']]])
check('one group', solve(['a', 'a']), [['a', ['a', 'a']]])
check('empty', solve([]), [])
check('three runs', solve(['b', 'a', 'b']), [['b', ['b']], ['a', ['a']], ['b', ['b']]])
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
two groups[['a', ['a', 'a']], ['b', ['b']]][['a', ['a', 'a']], ['b', ['b']]]Passed
one group[['a', ['a', 'a']]][['a', ['a', 'a']]]Passed
empty[][]Passed
three runs[['b', ['b']], ['a', ['a']], ['b', ['b']]][['b', ['b']], ['a', ['a']], ['b', ['b']]]Passed

SHA-256 / 3ab59a5bf74048490f48054364b876bb0806d56bbd03cc0cbed95afa1b0b84f9

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

Case digest / 0a1f7e3dc09917886fef0f1925a1801d7968623373cb60f4ecc8a26664cc2811