FA-146 / Storage and queries / Open access
A row filter removes contributions before a group threshold is evaluated · case 01
A group made of individually small contributions disappears even though its total meets the reporting threshold.
ROOT CAUSE
An aggregate eligibility rule is pushed down to individual rows before grouping, changing the relation being summed.
VERIFIED REPAIR
Sum all signed contributions per group, then retain groups whose completed aggregate is at least the threshold.
Unsuccessful approach: Moving the filter after aggregation but making it strictly greater still omits groups exactly at the contract's threshold.
Case contract
Rows are [group_string,signed_integer_amount]. Return a map of existing groups to their full sum, keeping groups whose sum is >= threshold. Never invent groups for empty input; negative contributions must participate before filtering.
Why this case matters
A deterministic model of WHERE versus HAVING placement and inclusive reporting thresholds. It exercises query rewriting correctness when filters do not commute with aggregation, including signed adjustments.
1 / The failure
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(rows, threshold):
totals = {}
for group, amount in rows:
if amount >= threshold:
totals[group] = totals.get(group, 0) + amount
return totals
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('small contributions jointly qualify', solve([['a', N], ['a', N]], 2*N), {'a': 2*N})
check('exact single contribution qualifies', solve([['a', 3*N]], 3*N), {'a': 3*N})
check('negative adjustment changes eligibility', solve([['a', 4*N], ['a', -3*N]], 2*N), {})
check('group-specific totals do not mingle', solve([['a', N], ['b', 5*N], ['a', 2*N]], 3*N), {'a': 3*N, 'b': 5*N})
check('below-threshold completed group', solve([['a', N], ['a', -1]], N), {})
check('zero threshold retains a real cancelling group', solve([['a', N], ['a', -N]], 0), {'a': 0})
check('empty relation does not invent a zero group', solve([], 0), {})
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 |
|---|---|---|---|
| small contributions jointly qualify | {} | {'a': 2} | Failed |
| exact single contribution qualifies | {'a': 3} | {'a': 3} | Passed |
| negative adjustment changes eligibility | {'a': 4} | {} | Failed |
| group-specific totals do not mingle | {'b': 5} | {'a': 3, 'b': 5} | Failed |
| below-threshold completed group | {'a': 1} | {} | Failed |
| zero threshold retains a real cancelling group | {'a': 1} | {'a': 0} | Failed |
| empty relation does not invent a zero group | {} | {} | Passed |
SHA-256 / 1d5027bce9f02fbb8d3259b81de335979a3c040eba9523c6cdb0353f6a9068b3
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(rows, threshold):
totals = {}
for group, amount in rows:
totals[group] = totals.get(group, 0) + amount
return {group: total for group, total in totals.items() if total > threshold}
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('small contributions jointly qualify', solve([['a', N], ['a', N]], 2*N), {'a': 2*N})
check('exact single contribution qualifies', solve([['a', 3*N]], 3*N), {'a': 3*N})
check('negative adjustment changes eligibility', solve([['a', 4*N], ['a', -3*N]], 2*N), {})
check('group-specific totals do not mingle', solve([['a', N], ['b', 5*N], ['a', 2*N]], 3*N), {'a': 3*N, 'b': 5*N})
check('below-threshold completed group', solve([['a', N], ['a', -1]], N), {})
check('zero threshold retains a real cancelling group', solve([['a', N], ['a', -N]], 0), {'a': 0})
check('empty relation does not invent a zero group', solve([], 0), {})
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 |
|---|---|---|---|
| small contributions jointly qualify | {} | {'a': 2} | Failed |
| exact single contribution qualifies | {} | {'a': 3} | Failed |
| negative adjustment changes eligibility | {} | {} | Passed |
| group-specific totals do not mingle | {'b': 5} | {'a': 3, 'b': 5} | Failed |
| below-threshold completed group | {} | {} | Passed |
| zero threshold retains a real cancelling group | {} | {'a': 0} | Failed |
| empty relation does not invent a zero group | {} | {} | Passed |
SHA-256 / be634c07c4f50e1d971e9d1276f8d6fd748a0bc49829aaf199223b75ced472af
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(rows, threshold):
totals = {}
for group, amount in rows:
totals[group] = totals.get(group, 0) + amount
return {group: total for group, total in totals.items() if total >= threshold}
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('small contributions jointly qualify', solve([['a', N], ['a', N]], 2*N), {'a': 2*N})
check('exact single contribution qualifies', solve([['a', 3*N]], 3*N), {'a': 3*N})
check('negative adjustment changes eligibility', solve([['a', 4*N], ['a', -3*N]], 2*N), {})
check('group-specific totals do not mingle', solve([['a', N], ['b', 5*N], ['a', 2*N]], 3*N), {'a': 3*N, 'b': 5*N})
check('below-threshold completed group', solve([['a', N], ['a', -1]], N), {})
check('zero threshold retains a real cancelling group', solve([['a', N], ['a', -N]], 0), {'a': 0})
check('empty relation does not invent a zero group', solve([], 0), {})
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 |
|---|---|---|---|
| small contributions jointly qualify | {'a': 2} | {'a': 2} | Passed |
| exact single contribution qualifies | {'a': 3} | {'a': 3} | Passed |
| negative adjustment changes eligibility | {} | {} | Passed |
| group-specific totals do not mingle | {'a': 3, 'b': 5} | {'a': 3, 'b': 5} | Passed |
| below-threshold completed group | {} | {} | Passed |
| zero threshold retains a real cancelling group | {'a': 0} | {'a': 0} | Passed |
| empty relation does not invent a zero group | {} | {} | Passed |
SHA-256 / eecd14c2c915f7f63d9d3a3f7558c1599fff84ec0bf51db078f59c6128333ab5
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:36:50.983275+00:00.
Case digest / 8c32280b5bd57598109939cacd9320b3d630abd2c50732dc14fa906979aecb98