FA-80666 / Bidirectional text layout / Open access
Bidi selection highlight: slot sorting · case 01
RTL selections are drawn as many one-unit fragments.
ROOT CAUSE
Visual slots are merged in logical order without sorting.
THE FAILURE
Visual slots are merged in logical order without sorting.
Unsuccessful approach: Sorting in descending order defeats the adjacency merge.
Case contract
Input [levels, anchor, focus]. The logical selection covers characters min..max-1. Each selected character occupies its unit visual slot (level reversal); merge adjacent slots into [x0, x1) rectangles sorted by x. Return the rectangles.
Why this case matters
Mixed right-to-left and left-to-right text must resolve levels and visual order exactly, or words, numbers and carets land in the wrong place.
1 / The failure
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(x):
def reorder(lv):
vis = list(range(len(lv)))
odd = [l for l in lv if l % 2 == 1]
if not odd:
return vis
for lev in range(max(lv), min(odd) - 1, -1):
i = 0
while i < len(vis):
if lv[vis[i]] >= lev:
j = i
while j < len(vis) and lv[vis[j]] >= lev:
j += 1
vis[i:j] = vis[i:j][::-1]
i = j
else:
i += 1
return vis
levels, a, b = x
a, b = min(a, b), max(a, b)
vis = reorder(levels)
pos = [0] * len(levels)
for v, i in enumerate(vis):
pos[i] = v
sel = [pos[i] for i in range(a, b)]
rects = []
for p in sel:
if rects and rects[-1][1] == p:
rects[-1][1] = p + 1
else:
rects.append([p, p + 1])
return rects
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('regression: slot sorting', [[0, 0, 0, 0, 2, 0, 0, 0, 3, 3, 0, 0], 12, 7], [[7, 12]]), ('partial-repair probe', [[0, 0, 0, 0, 0, 2, 0, 0, 1, 0], 8, 6], [[6, 8]]), ('partial-repair probe', [[2, 2, 2, 2, 1, 1, 4, 4, 4, 4, 1], 8, 6], [[1, 3]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('control layout', [[4, 4, 4, 4, 1, 1, 3], 1, 0], [[3, 4]]), ('control layout', [[2, 2, 2, 1, 1, 1, 1, 3, 3], 6, 5], [[3, 4]]), ('control layout', [[0], 1, 1], [])], [('regression: slot sorting', [[3, 3, 3, 3, 3, 3, 3, 2], 8, 4], [[0, 3], [7, 8]]), ('regression: slot sorting', [[1, 1, 1, 1, 3, 1, 1, 1, 2, 2, 2], 9, 3], [[0, 1], [3, 8]]), ('regression: slot sorting', [[3, 3, 3, 1, 1, 1, 2], 4, 2], [[3, 5]]), ('regression: slot sorting', [[3, 3, 3, 2, 2, 1, 1, 1, 1, 2, 2], 3, 8], [[3, 6], [9, 11]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('control layout', [[1, 2, 2, 2, 4, 4, 4, 4, 1, 1, 1], 10, 9], [[1, 2]]), ('control layout', [[1, 1, 2, 2, 2, 2, 1, 3, 3, 1, 1], 8, 9], [[2, 3]])], [('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('regression: slot sorting', [[1, 1, 1, 1, 4, 4, 3, 2, 2], 4, 7], [[0, 3]]), ('regression: slot sorting', [[1, 1, 1, 4, 4, 3, 3, 3, 2], 3, 7], [[1, 5]]), ('partial-repair probe', [[0, 0, 0, 0, 0, 2, 0, 0, 1, 0], 8, 6], [[6, 8]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('control layout', [[0, 0], 0, 0], []), ('control layout', [[3, 3, 3, 1, 1, 1, 1, 2, 2, 2, 2], 2, 1], [[9, 10]]), ('control layout', [[1, 1], 1, 1], [])], [('regression: slot sorting', [[4, 4, 4, 1, 1, 1, 1, 1, 1, 1, 1], 6, 11], [[0, 5]]), ('regression: slot sorting', [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3], 8, 3], [[4, 9]]), ('regression: slot sorting', [[3, 3, 3, 3, 2], 4, 2], [[0, 2]]), ('partial-repair probe', [[4, 2, 2, 2, 2, 2, 2, 2], 7, 1], [[1, 7]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('control layout', [[2, 2], 0, 0], []), ('control layout', [[1, 3, 3, 3, 3, 0, 0], 1, 0], [[4, 5]])], [('regression: slot sorting', [[0, 1, 1, 2, 2, 0, 0, 0, 0], 2, 8], [[1, 4], [5, 8]]), ('regression: slot sorting', [[2, 2, 1, 1], 4, 1], [[0, 2], [3, 4]]), ('regression: slot sorting', [[1, 1, 1, 4, 4, 4], 3, 1], [[3, 5]]), ('partial-repair probe', [[2, 2, 4, 2, 2, 2, 2, 2], 7, 4], [[4, 7]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('control layout', [[1, 3, 3, 3, 0, 0, 3, 3], 8, 8], []), ('control layout', [[2, 2, 2, 2, 2, 4, 4, 4, 3, 3, 3], 10, 11], [[5, 6]])]]
for label, args, expected in fixtures[N - 1]:
check(label, solve(args), expected)
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 |
|---|---|---|---|
| selection crossing direction change | [[1, 2], [3, 4], [2, 3]] | [[1, 4]] | Failed |
| regression: slot sorting | [[7, 8], [9, 10], [8, 9], [10, 12]] | [[7, 12]] | Failed |
| partial-repair probe | [[6, 8]] | [[6, 8]] | Passed |
| partial-repair probe | [[1, 3]] | [[1, 3]] | Passed |
| backward selection | [[1, 2], [0, 1]] | [[0, 2]] | Failed |
| control layout | [[3, 4]] | [[3, 4]] | Passed |
| control layout | [[3, 4]] | [[3, 4]] | Passed |
| control layout | [] | [] | Passed |
SHA-256 / 8ca99e755671cbb5e3edb762933f7699af3ba0db5f8b243aa0b7aeb6e7b80d96
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(x):
def reorder(lv):
vis = list(range(len(lv)))
odd = [l for l in lv if l % 2 == 1]
if not odd:
return vis
for lev in range(max(lv), min(odd) - 1, -1):
i = 0
while i < len(vis):
if lv[vis[i]] >= lev:
j = i
while j < len(vis) and lv[vis[j]] >= lev:
j += 1
vis[i:j] = vis[i:j][::-1]
i = j
else:
i += 1
return vis
levels, a, b = x
a, b = min(a, b), max(a, b)
vis = reorder(levels)
pos = [0] * len(levels)
for v, i in enumerate(vis):
pos[i] = v
sel = sorted((pos[i] for i in range(a, b)), reverse=True)
rects = []
for p in sel:
if rects and rects[-1][1] == p:
rects[-1][1] = p + 1
else:
rects.append([p, p + 1])
return rects
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('regression: slot sorting', [[0, 0, 0, 0, 2, 0, 0, 0, 3, 3, 0, 0], 12, 7], [[7, 12]]), ('partial-repair probe', [[0, 0, 0, 0, 0, 2, 0, 0, 1, 0], 8, 6], [[6, 8]]), ('partial-repair probe', [[2, 2, 2, 2, 1, 1, 4, 4, 4, 4, 1], 8, 6], [[1, 3]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('control layout', [[4, 4, 4, 4, 1, 1, 3], 1, 0], [[3, 4]]), ('control layout', [[2, 2, 2, 1, 1, 1, 1, 3, 3], 6, 5], [[3, 4]]), ('control layout', [[0], 1, 1], [])], [('regression: slot sorting', [[3, 3, 3, 3, 3, 3, 3, 2], 8, 4], [[0, 3], [7, 8]]), ('regression: slot sorting', [[1, 1, 1, 1, 3, 1, 1, 1, 2, 2, 2], 9, 3], [[0, 1], [3, 8]]), ('regression: slot sorting', [[3, 3, 3, 1, 1, 1, 2], 4, 2], [[3, 5]]), ('regression: slot sorting', [[3, 3, 3, 2, 2, 1, 1, 1, 1, 2, 2], 3, 8], [[3, 6], [9, 11]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('control layout', [[1, 2, 2, 2, 4, 4, 4, 4, 1, 1, 1], 10, 9], [[1, 2]]), ('control layout', [[1, 1, 2, 2, 2, 2, 1, 3, 3, 1, 1], 8, 9], [[2, 3]])], [('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('regression: slot sorting', [[1, 1, 1, 1, 4, 4, 3, 2, 2], 4, 7], [[0, 3]]), ('regression: slot sorting', [[1, 1, 1, 4, 4, 3, 3, 3, 2], 3, 7], [[1, 5]]), ('partial-repair probe', [[0, 0, 0, 0, 0, 2, 0, 0, 1, 0], 8, 6], [[6, 8]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('control layout', [[0, 0], 0, 0], []), ('control layout', [[3, 3, 3, 1, 1, 1, 1, 2, 2, 2, 2], 2, 1], [[9, 10]]), ('control layout', [[1, 1], 1, 1], [])], [('regression: slot sorting', [[4, 4, 4, 1, 1, 1, 1, 1, 1, 1, 1], 6, 11], [[0, 5]]), ('regression: slot sorting', [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3], 8, 3], [[4, 9]]), ('regression: slot sorting', [[3, 3, 3, 3, 2], 4, 2], [[0, 2]]), ('partial-repair probe', [[4, 2, 2, 2, 2, 2, 2, 2], 7, 1], [[1, 7]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('control layout', [[2, 2], 0, 0], []), ('control layout', [[1, 3, 3, 3, 3, 0, 0], 1, 0], [[4, 5]])], [('regression: slot sorting', [[0, 1, 1, 2, 2, 0, 0, 0, 0], 2, 8], [[1, 4], [5, 8]]), ('regression: slot sorting', [[2, 2, 1, 1], 4, 1], [[0, 2], [3, 4]]), ('regression: slot sorting', [[1, 1, 1, 4, 4, 4], 3, 1], [[3, 5]]), ('partial-repair probe', [[2, 2, 4, 2, 2, 2, 2, 2], 7, 4], [[4, 7]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('control layout', [[1, 3, 3, 3, 0, 0, 3, 3], 8, 8], []), ('control layout', [[2, 2, 2, 2, 2, 4, 4, 4, 3, 3, 3], 10, 11], [[5, 6]])]]
for label, args, expected in fixtures[N - 1]:
check(label, solve(args), expected)
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 |
|---|---|---|---|
| selection crossing direction change | [[3, 4], [2, 3], [1, 2]] | [[1, 4]] | Failed |
| regression: slot sorting | [[11, 12], [10, 11], [9, 10], [8, 9], [7, 8]] | [[7, 12]] | Failed |
| partial-repair probe | [[7, 8], [6, 7]] | [[6, 8]] | Failed |
| partial-repair probe | [[2, 3], [1, 2]] | [[1, 3]] | Failed |
| backward selection | [[1, 2], [0, 1]] | [[0, 2]] | Failed |
| control layout | [[3, 4]] | [[3, 4]] | Passed |
| control layout | [[3, 4]] | [[3, 4]] | Passed |
| control layout | [] | [] | Passed |
SHA-256 / 17f8ab11d760b234fc48fc076a9ec7c43baadabb29b6344544c6c333333fffcd
HELD IN THE MEMBER ARCHIVE
The verified repair and its recorded checks are member-only.
This mechanism has 8 recorded checks per implementation. The open-access tier publishes the failure and the unsuccessful fix; the repaired source that passes every check, and the observations that prove it, are available to members.
Every case sharing this mechanism uses the same contract and the same repair, so this one record is held back for all of them.
Member access is invitation-based. Sign in with your invited account to inspect the repair.
Sign in to the archive ↗Verification & scope
A deterministic toy bidi model over stipulated class labels and integer levels; it is inspired by, but does not claim conformance to, any published algorithm. 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:49:56.106345+00:00.
Case digest / 6365b6d9ae91c6444ee56eb6a7aeccae2da0bbc794957f685dcd68d8d401b9b6