FA-151 / Storage and queries / Open access
A top-k query uses distinct score levels instead of the kth row's score · case 01
Tie handling either truncates equivalent rows or admits an extra lower-scoring group beyond the kth-row boundary.
ROOT CAUSE
A row-count limit and a count of distinct score values are treated as the same ranking cutoff.
VERIFIED REPAIR
Sort rows deterministically, locate the kth row's score, and include every row with a score at least that cutoff.
Unsuccessful approach: Keeping the first k distinct score levels over-includes rows when earlier ties already consumed multiple positions.
Case contract
Rows are [unique_integer_id,integer_score]. For nonnegative k, return all rows tied with or above the kth row under score-descending ordering, with id ascending within ties. k=0 returns empty; k>=row_count returns all rows.
Why this case matters
Models FETCH FIRST k ROWS WITH TIES using an explicit score-only tie definition and deterministic output order. The task concerns rank cutoff cardinality, not cursor state or duplicate delivery.
1 / The failure
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(rows, k):
ordered = sorted(rows, key=lambda row: (-row[1], row[0]))
return ordered[:k]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('tie straddles a row-count boundary', solve([[3, N], [2, 3*N], [1, 3*N]], 1), [[1, 3*N], [2, 3*N]])
check('earlier tie consumes two row positions', solve([[4, N], [3, 2*N], [2, 3*N], [1, 3*N]], 2), [[1, 3*N], [2, 3*N]])
check('tie at a later cutoff includes every equal score', solve([[1, 4*N], [4, N], [3, 2*N], [2, 2*N]], 2), [[1, 4*N], [2, 2*N], [3, 2*N]])
check('zero limit', solve([[1, N]], 0), [])
check('oversized limit sorts all rows', solve([[2, -N], [1, 0]], N+3), [[1, 0], [2, -N]])
check('negative scores also tie', solve([[2, -N], [1, -N], [3, -N-1]], 1), [[1, -N], [2, -N]])
check('empty relation', solve([], N), [])
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 |
|---|---|---|---|
| tie straddles a row-count boundary | [[1, 3]] | [[1, 3], [2, 3]] | Failed |
| earlier tie consumes two row positions | [[1, 3], [2, 3]] | [[1, 3], [2, 3]] | Passed |
| tie at a later cutoff includes every equal score | [[1, 4], [2, 2]] | [[1, 4], [2, 2], [3, 2]] | Failed |
| zero limit | [] | [] | Passed |
| oversized limit sorts all rows | [[1, 0], [2, -1]] | [[1, 0], [2, -1]] | Passed |
| negative scores also tie | [[1, -1]] | [[1, -1], [2, -1]] | Failed |
| empty relation | [] | [] | Passed |
SHA-256 / c081fcca1eed11ba8ac528195f96fb2228704c777b5c067694645659421f976e
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(rows, k):
levels = sorted({row[1] for row in rows}, reverse=True)[:k]
return sorted([row for row in rows if row[1] in levels], key=lambda row: (-row[1], row[0]))
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('tie straddles a row-count boundary', solve([[3, N], [2, 3*N], [1, 3*N]], 1), [[1, 3*N], [2, 3*N]])
check('earlier tie consumes two row positions', solve([[4, N], [3, 2*N], [2, 3*N], [1, 3*N]], 2), [[1, 3*N], [2, 3*N]])
check('tie at a later cutoff includes every equal score', solve([[1, 4*N], [4, N], [3, 2*N], [2, 2*N]], 2), [[1, 4*N], [2, 2*N], [3, 2*N]])
check('zero limit', solve([[1, N]], 0), [])
check('oversized limit sorts all rows', solve([[2, -N], [1, 0]], N+3), [[1, 0], [2, -N]])
check('negative scores also tie', solve([[2, -N], [1, -N], [3, -N-1]], 1), [[1, -N], [2, -N]])
check('empty relation', solve([], N), [])
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 |
|---|---|---|---|
| tie straddles a row-count boundary | [[1, 3], [2, 3]] | [[1, 3], [2, 3]] | Passed |
| earlier tie consumes two row positions | [[1, 3], [2, 3], [3, 2]] | [[1, 3], [2, 3]] | Failed |
| tie at a later cutoff includes every equal score | [[1, 4], [2, 2], [3, 2]] | [[1, 4], [2, 2], [3, 2]] | Passed |
| zero limit | [] | [] | Passed |
| oversized limit sorts all rows | [[1, 0], [2, -1]] | [[1, 0], [2, -1]] | Passed |
| negative scores also tie | [[1, -1], [2, -1]] | [[1, -1], [2, -1]] | Passed |
| empty relation | [] | [] | Passed |
SHA-256 / 2fca6e4f5fad31094b0c5ce6a4fa130fc45c0a0a28557d629fefd3ff2d0221c1
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(rows, k):
ordered = sorted(rows, key=lambda row: (-row[1], row[0]))
if k == 0 or not ordered:
return []
cutoff = ordered[min(k, len(ordered))-1][1]
return [row for row in ordered if row[1] >= cutoff]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('tie straddles a row-count boundary', solve([[3, N], [2, 3*N], [1, 3*N]], 1), [[1, 3*N], [2, 3*N]])
check('earlier tie consumes two row positions', solve([[4, N], [3, 2*N], [2, 3*N], [1, 3*N]], 2), [[1, 3*N], [2, 3*N]])
check('tie at a later cutoff includes every equal score', solve([[1, 4*N], [4, N], [3, 2*N], [2, 2*N]], 2), [[1, 4*N], [2, 2*N], [3, 2*N]])
check('zero limit', solve([[1, N]], 0), [])
check('oversized limit sorts all rows', solve([[2, -N], [1, 0]], N+3), [[1, 0], [2, -N]])
check('negative scores also tie', solve([[2, -N], [1, -N], [3, -N-1]], 1), [[1, -N], [2, -N]])
check('empty relation', solve([], N), [])
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 |
|---|---|---|---|
| tie straddles a row-count boundary | [[1, 3], [2, 3]] | [[1, 3], [2, 3]] | Passed |
| earlier tie consumes two row positions | [[1, 3], [2, 3]] | [[1, 3], [2, 3]] | Passed |
| tie at a later cutoff includes every equal score | [[1, 4], [2, 2], [3, 2]] | [[1, 4], [2, 2], [3, 2]] | Passed |
| zero limit | [] | [] | Passed |
| oversized limit sorts all rows | [[1, 0], [2, -1]] | [[1, 0], [2, -1]] | Passed |
| negative scores also tie | [[1, -1], [2, -1]] | [[1, -1], [2, -1]] | Passed |
| empty relation | [] | [] | Passed |
SHA-256 / 7d0672c2d2f393b86474a5fbc7e51ea1ca7db8c6ee4bd5b260061703bae34221
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.986728+00:00.
Case digest / 62b070e277697517f22479c92a88d5c4fd92cc4c1e0884cfa29f949625ff1674