FA-80486 / Bidirectional text layout / Open access
Visual reordering by levels: no odd level shortcut · case 01
Pure LTR lines with embedded even levels are reversed.
ROOT CAUSE
Lines without odd levels fall through with a lowest level of zero.
VERIFIED REPAIR
Return logical order when no odd level is present.
Unsuccessful approach: Using the highest level as the stop still reverses even runs once.
Case contract
Input resolved levels of one line. From the highest level down to the lowest odd level on the line, reverse every maximal visual run of characters at that level or higher. Return logical indices in visual order (identity when no odd level).
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):
levels = x
order = list(range(len(levels)))
odd = [l for l in levels if l % 2 == 1]
hi = max(levels)
lo = min(odd) if odd else 0
vis = [[lv, i] for i, lv in enumerate(levels)]
for lev in range(hi, lo - 1, -1):
i = 0
while i < len(vis):
if vis[i][0] >= lev:
j = i
while j < len(vis) and vis[j][0] >= lev:
j += 1
vis[i:j] = vis[i:j][::-1]
i = j
else:
i += 1
return [p[1] for p in vis]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('all even levels', [0, 2, 2, 0], [0, 1, 2, 3]), ('regression: no odd level shortcut', [0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 2, 3, 4, 5, 6, 7]), ('regression: no odd level shortcut', [2, 2, 2, 2, 2, 2], [0, 1, 2, 3, 4, 5]), ('regression: no odd level shortcut', [0, 0, 0, 0], [0, 1, 2, 3]), ('number inside RTL', [1, 1, 2, 2, 1], [4, 2, 3, 1, 0]), ('lowest odd is three', [2, 3, 3, 2], [0, 2, 1, 3]), ('control layout', [2, 2, 1, 1, 1, 1, 1, 1, 0, 0], [7, 6, 5, 4, 3, 2, 0, 1, 8, 9]), ('control layout', [0], [0])], [('regression: no odd level shortcut', [2, 2], [0, 1]), ('regression: no odd level shortcut', [2, 2], [0, 1]), ('regression: no odd level shortcut', [0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 0], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), ('regression: no odd level shortcut', [2, 2, 2, 2, 2], [0, 1, 2, 3, 4]), ('all even levels', [0, 2, 2, 0], [0, 1, 2, 3]), ('lowest odd is three', [2, 3, 3, 2], [0, 2, 1, 3]), ('control layout', [1, 1, 1, 3, 3, 2, 3, 3, 1, 1, 1], [10, 9, 8, 4, 3, 5, 7, 6, 2, 1, 0]), ('control layout', [1, 1, 1, 2, 2, 2, 2], [3, 4, 5, 6, 2, 1, 0])], [('regression: no odd level shortcut', [2, 2, 2, 2, 2, 2], [0, 1, 2, 3, 4, 5]), ('regression: no odd level shortcut', [2, 4, 4, 4, 4, 2, 2, 2, 2, 2], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]), ('regression: no odd level shortcut', [0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), ('regression: no odd level shortcut', [0, 0, 0], [0, 1, 2]), ('lowest odd is three', [2, 3, 3, 2], [0, 2, 1, 3]), ('all even levels', [0, 2, 2, 0], [0, 1, 2, 3]), ('control layout', [3, 3], [1, 0]), ('control layout', [2, 0, 0, 0, 1], [0, 1, 2, 3, 4])], [('regression: no odd level shortcut', [0, 0, 0, 0, 2, 2], [0, 1, 2, 3, 4, 5]), ('regression: no odd level shortcut', [4, 4, 4], [0, 1, 2]), ('regression: no odd level shortcut', [2, 2, 2, 2, 2], [0, 1, 2, 3, 4]), ('regression: no odd level shortcut', [2, 2], [0, 1]), ('number inside RTL', [1, 1, 2, 2, 1], [4, 2, 3, 1, 0]), ('all even levels', [0, 2, 2, 0], [0, 1, 2, 3]), ('control layout', [3, 3, 3, 1, 1, 1, 1, 0, 0, 0, 1], [6, 5, 4, 3, 2, 1, 0, 7, 8, 9, 10]), ('control layout', [0, 0, 0, 0, 1, 1], [0, 1, 2, 3, 5, 4])], [('regression: no odd level shortcut', [2, 2, 2], [0, 1, 2]), ('regression: no odd level shortcut', [2, 2, 2, 2, 2, 2, 2, 2], [0, 1, 2, 3, 4, 5, 6, 7]), ('regression: no odd level shortcut', [2, 2, 2, 2, 2, 2], [0, 1, 2, 3, 4, 5]), ('regression: no odd level shortcut', [0, 0], [0, 1]), ('lowest odd is three', [2, 3, 3, 2], [0, 2, 1, 3]), ('number inside RTL', [1, 1, 2, 2, 1], [4, 2, 3, 1, 0]), ('control layout', [1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1], [3, 2, 1, 0, 4, 5, 6, 7, 8, 9, 11, 10]), ('control layout', [2, 2, 1, 1, 1, 1, 3], [6, 5, 4, 3, 2, 0, 1])]]
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 |
|---|---|---|---|
| all even levels | [3, 2, 1, 0] | [0, 1, 2, 3] | Failed |
| regression: no odd level shortcut | [7, 6, 5, 4, 3, 2, 1, 0] | [0, 1, 2, 3, 4, 5, 6, 7] | Failed |
| regression: no odd level shortcut | [5, 4, 3, 2, 1, 0] | [0, 1, 2, 3, 4, 5] | Failed |
| regression: no odd level shortcut | [3, 2, 1, 0] | [0, 1, 2, 3] | Failed |
| number inside RTL | [4, 2, 3, 1, 0] | [4, 2, 3, 1, 0] | Passed |
| lowest odd is three | [0, 2, 1, 3] | [0, 2, 1, 3] | Passed |
| control layout | [7, 6, 5, 4, 3, 2, 0, 1, 8, 9] | [7, 6, 5, 4, 3, 2, 0, 1, 8, 9] | Passed |
| control layout | [0] | [0] | Passed |
SHA-256 / 23b2478213133da6073afc51113694fe6c3e09a4f20721c0b013349563f3aa38
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(x):
levels = x
order = list(range(len(levels)))
odd = [l for l in levels if l % 2 == 1]
hi = max(levels)
lo = min(odd) if odd else hi
vis = [[lv, i] for i, lv in enumerate(levels)]
for lev in range(hi, lo - 1, -1):
i = 0
while i < len(vis):
if vis[i][0] >= lev:
j = i
while j < len(vis) and vis[j][0] >= lev:
j += 1
vis[i:j] = vis[i:j][::-1]
i = j
else:
i += 1
return [p[1] for p in vis]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('all even levels', [0, 2, 2, 0], [0, 1, 2, 3]), ('regression: no odd level shortcut', [0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 2, 3, 4, 5, 6, 7]), ('regression: no odd level shortcut', [2, 2, 2, 2, 2, 2], [0, 1, 2, 3, 4, 5]), ('regression: no odd level shortcut', [0, 0, 0, 0], [0, 1, 2, 3]), ('number inside RTL', [1, 1, 2, 2, 1], [4, 2, 3, 1, 0]), ('lowest odd is three', [2, 3, 3, 2], [0, 2, 1, 3]), ('control layout', [2, 2, 1, 1, 1, 1, 1, 1, 0, 0], [7, 6, 5, 4, 3, 2, 0, 1, 8, 9]), ('control layout', [0], [0])], [('regression: no odd level shortcut', [2, 2], [0, 1]), ('regression: no odd level shortcut', [2, 2], [0, 1]), ('regression: no odd level shortcut', [0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 0], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), ('regression: no odd level shortcut', [2, 2, 2, 2, 2], [0, 1, 2, 3, 4]), ('all even levels', [0, 2, 2, 0], [0, 1, 2, 3]), ('lowest odd is three', [2, 3, 3, 2], [0, 2, 1, 3]), ('control layout', [1, 1, 1, 3, 3, 2, 3, 3, 1, 1, 1], [10, 9, 8, 4, 3, 5, 7, 6, 2, 1, 0]), ('control layout', [1, 1, 1, 2, 2, 2, 2], [3, 4, 5, 6, 2, 1, 0])], [('regression: no odd level shortcut', [2, 2, 2, 2, 2, 2], [0, 1, 2, 3, 4, 5]), ('regression: no odd level shortcut', [2, 4, 4, 4, 4, 2, 2, 2, 2, 2], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]), ('regression: no odd level shortcut', [0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), ('regression: no odd level shortcut', [0, 0, 0], [0, 1, 2]), ('lowest odd is three', [2, 3, 3, 2], [0, 2, 1, 3]), ('all even levels', [0, 2, 2, 0], [0, 1, 2, 3]), ('control layout', [3, 3], [1, 0]), ('control layout', [2, 0, 0, 0, 1], [0, 1, 2, 3, 4])], [('regression: no odd level shortcut', [0, 0, 0, 0, 2, 2], [0, 1, 2, 3, 4, 5]), ('regression: no odd level shortcut', [4, 4, 4], [0, 1, 2]), ('regression: no odd level shortcut', [2, 2, 2, 2, 2], [0, 1, 2, 3, 4]), ('regression: no odd level shortcut', [2, 2], [0, 1]), ('number inside RTL', [1, 1, 2, 2, 1], [4, 2, 3, 1, 0]), ('all even levels', [0, 2, 2, 0], [0, 1, 2, 3]), ('control layout', [3, 3, 3, 1, 1, 1, 1, 0, 0, 0, 1], [6, 5, 4, 3, 2, 1, 0, 7, 8, 9, 10]), ('control layout', [0, 0, 0, 0, 1, 1], [0, 1, 2, 3, 5, 4])], [('regression: no odd level shortcut', [2, 2, 2], [0, 1, 2]), ('regression: no odd level shortcut', [2, 2, 2, 2, 2, 2, 2, 2], [0, 1, 2, 3, 4, 5, 6, 7]), ('regression: no odd level shortcut', [2, 2, 2, 2, 2, 2], [0, 1, 2, 3, 4, 5]), ('regression: no odd level shortcut', [0, 0], [0, 1]), ('lowest odd is three', [2, 3, 3, 2], [0, 2, 1, 3]), ('number inside RTL', [1, 1, 2, 2, 1], [4, 2, 3, 1, 0]), ('control layout', [1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1], [3, 2, 1, 0, 4, 5, 6, 7, 8, 9, 11, 10]), ('control layout', [2, 2, 1, 1, 1, 1, 3], [6, 5, 4, 3, 2, 0, 1])]]
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 |
|---|---|---|---|
| all even levels | [0, 2, 1, 3] | [0, 1, 2, 3] | Failed |
| regression: no odd level shortcut | [7, 6, 5, 4, 3, 2, 1, 0] | [0, 1, 2, 3, 4, 5, 6, 7] | Failed |
| regression: no odd level shortcut | [5, 4, 3, 2, 1, 0] | [0, 1, 2, 3, 4, 5] | Failed |
| regression: no odd level shortcut | [3, 2, 1, 0] | [0, 1, 2, 3] | Failed |
| number inside RTL | [4, 2, 3, 1, 0] | [4, 2, 3, 1, 0] | Passed |
| lowest odd is three | [0, 2, 1, 3] | [0, 2, 1, 3] | Passed |
| control layout | [7, 6, 5, 4, 3, 2, 0, 1, 8, 9] | [7, 6, 5, 4, 3, 2, 0, 1, 8, 9] | Passed |
| control layout | [0] | [0] | Passed |
SHA-256 / 577b21a9a5cf8671b709cd241665be3232d6ce9f255ec52a58bef05f818c4516
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(x):
levels = x
order = list(range(len(levels)))
odd = [l for l in levels if l % 2 == 1]
if not odd:
return order
hi = max(levels)
lo = min(odd)
vis = [[lv, i] for i, lv in enumerate(levels)]
for lev in range(hi, lo - 1, -1):
i = 0
while i < len(vis):
if vis[i][0] >= lev:
j = i
while j < len(vis) and vis[j][0] >= lev:
j += 1
vis[i:j] = vis[i:j][::-1]
i = j
else:
i += 1
return [p[1] for p in vis]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('all even levels', [0, 2, 2, 0], [0, 1, 2, 3]), ('regression: no odd level shortcut', [0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 2, 3, 4, 5, 6, 7]), ('regression: no odd level shortcut', [2, 2, 2, 2, 2, 2], [0, 1, 2, 3, 4, 5]), ('regression: no odd level shortcut', [0, 0, 0, 0], [0, 1, 2, 3]), ('number inside RTL', [1, 1, 2, 2, 1], [4, 2, 3, 1, 0]), ('lowest odd is three', [2, 3, 3, 2], [0, 2, 1, 3]), ('control layout', [2, 2, 1, 1, 1, 1, 1, 1, 0, 0], [7, 6, 5, 4, 3, 2, 0, 1, 8, 9]), ('control layout', [0], [0])], [('regression: no odd level shortcut', [2, 2], [0, 1]), ('regression: no odd level shortcut', [2, 2], [0, 1]), ('regression: no odd level shortcut', [0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 0], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), ('regression: no odd level shortcut', [2, 2, 2, 2, 2], [0, 1, 2, 3, 4]), ('all even levels', [0, 2, 2, 0], [0, 1, 2, 3]), ('lowest odd is three', [2, 3, 3, 2], [0, 2, 1, 3]), ('control layout', [1, 1, 1, 3, 3, 2, 3, 3, 1, 1, 1], [10, 9, 8, 4, 3, 5, 7, 6, 2, 1, 0]), ('control layout', [1, 1, 1, 2, 2, 2, 2], [3, 4, 5, 6, 2, 1, 0])], [('regression: no odd level shortcut', [2, 2, 2, 2, 2, 2], [0, 1, 2, 3, 4, 5]), ('regression: no odd level shortcut', [2, 4, 4, 4, 4, 2, 2, 2, 2, 2], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]), ('regression: no odd level shortcut', [0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), ('regression: no odd level shortcut', [0, 0, 0], [0, 1, 2]), ('lowest odd is three', [2, 3, 3, 2], [0, 2, 1, 3]), ('all even levels', [0, 2, 2, 0], [0, 1, 2, 3]), ('control layout', [3, 3], [1, 0]), ('control layout', [2, 0, 0, 0, 1], [0, 1, 2, 3, 4])], [('regression: no odd level shortcut', [0, 0, 0, 0, 2, 2], [0, 1, 2, 3, 4, 5]), ('regression: no odd level shortcut', [4, 4, 4], [0, 1, 2]), ('regression: no odd level shortcut', [2, 2, 2, 2, 2], [0, 1, 2, 3, 4]), ('regression: no odd level shortcut', [2, 2], [0, 1]), ('number inside RTL', [1, 1, 2, 2, 1], [4, 2, 3, 1, 0]), ('all even levels', [0, 2, 2, 0], [0, 1, 2, 3]), ('control layout', [3, 3, 3, 1, 1, 1, 1, 0, 0, 0, 1], [6, 5, 4, 3, 2, 1, 0, 7, 8, 9, 10]), ('control layout', [0, 0, 0, 0, 1, 1], [0, 1, 2, 3, 5, 4])], [('regression: no odd level shortcut', [2, 2, 2], [0, 1, 2]), ('regression: no odd level shortcut', [2, 2, 2, 2, 2, 2, 2, 2], [0, 1, 2, 3, 4, 5, 6, 7]), ('regression: no odd level shortcut', [2, 2, 2, 2, 2, 2], [0, 1, 2, 3, 4, 5]), ('regression: no odd level shortcut', [0, 0], [0, 1]), ('lowest odd is three', [2, 3, 3, 2], [0, 2, 1, 3]), ('number inside RTL', [1, 1, 2, 2, 1], [4, 2, 3, 1, 0]), ('control layout', [1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1], [3, 2, 1, 0, 4, 5, 6, 7, 8, 9, 11, 10]), ('control layout', [2, 2, 1, 1, 1, 1, 3], [6, 5, 4, 3, 2, 0, 1])]]
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 |
|---|---|---|---|
| all even levels | [0, 1, 2, 3] | [0, 1, 2, 3] | Passed |
| regression: no odd level shortcut | [0, 1, 2, 3, 4, 5, 6, 7] | [0, 1, 2, 3, 4, 5, 6, 7] | Passed |
| regression: no odd level shortcut | [0, 1, 2, 3, 4, 5] | [0, 1, 2, 3, 4, 5] | Passed |
| regression: no odd level shortcut | [0, 1, 2, 3] | [0, 1, 2, 3] | Passed |
| number inside RTL | [4, 2, 3, 1, 0] | [4, 2, 3, 1, 0] | Passed |
| lowest odd is three | [0, 2, 1, 3] | [0, 2, 1, 3] | Passed |
| control layout | [7, 6, 5, 4, 3, 2, 0, 1, 8, 9] | [7, 6, 5, 4, 3, 2, 0, 1, 8, 9] | Passed |
| control layout | [0] | [0] | Passed |
SHA-256 / 2a14168bf650a5c5d96d6aafbe91ac28533bc33eaaceabbd648355d9099682c2
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:54.207733+00:00.
Case digest / e5b6d24a34094877ade25ba407526b9a5a03f97660d3ae844b8601ebd5622eac