FAILURE MAP
← Case archive

FA-80711 / Bidirectional text layout / Open access

Per-line visual reordering: paragraph-wide reordering · case 01

Lines show characters from other lines after wrapping RTL text.

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

ROOT CAUSE

The whole paragraph is reordered first and then cut into lines visually.

VERIFIED REPAIR

Break lines in logical order and reorder each line separately.

Unsuccessful approach: Sorting each line by paragraph-wide visual position skips the per-line whitespace reset.

Case contract

Input [paragraph levels, classes, paragraph level, line lengths]. For each logical line: reset trailing WS to the paragraph level, then reorder that line alone by level reversal (lowest odd level of the line). Return per line the paragraph indices in visual order.

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, classes, para, line_lengths = x
    out = []
    start = 0
    glob = reorder(levels)
    for ln in line_lengths:
        idx = list(range(start, start + ln))
        lv = [levels[i] for i in idx]
        j = ln - 1
        while j >= 0 and classes[idx[j]] == 'WS':
            lv[j] = para
            j -= 1
        local = reorder(lv)
        out.append(glob[start:start + ln])
        start += ln
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('RTL run split across lines', [[1, 1, 1, 1, 1, 1], ['R', 'R', 'WS', 'R', 'R', 'R'], 0, [3, 3]], [[1, 0, 2], [5, 4, 3]]), ('regression: paragraph-wide reordering', [[1, 1, 1, 1, 1, 1, 1, 3, 3, 1, 1, 0, 0, 0], ['L', 'L', 'L', 'WS', 'L', 'WS', 'R', 'R', 'ON', 'WS', 'R', 'WS', 'R', 'WS'], 0, [1, 4, 2, 3, 4]], [[0], [4, 3, 2, 1], [6, 5], [8, 7, 9], [10, 11, 12, 13]]), ('regression: paragraph-wide reordering', [[1, 1, 1, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1], ['WS', 'L', 'R', 'L', 'WS', 'ON', 'WS', 'R', 'L', 'L', 'WS', 'L', 'WS'], 0, [4, 3, 4, 2]], [[3, 2, 1, 0], [4, 5, 6], [9, 8, 7, 10], [11, 12]]), ('regression: paragraph-wide reordering', [[1, 0, 0, 0, 0, 0], ['R', 'L', 'WS', 'WS', 'WS', 'WS'], 1, [3, 2, 1]], [[0, 1, 2], [4, 3], [5]]), ('control layout', [[2, 2, 2, 0], ['WS', 'ON', 'WS', 'L'], 0, [1, 2, 1]], [[0], [1, 2], [3]]), ('control layout', [[2, 2, 2, 0, 0, 1], ['R', 'R', 'R', 'L', 'R', 'R'], 0, [3, 2, 1]], [[0, 1, 2], [3, 4], [5]]), ('control layout', [[0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0], ['WS', 'L', 'R', 'L', 'R', 'L', 'WS', 'R', 'WS', 'ON', 'WS', 'L', 'R', 'WS'], 0, [5, 5, 2, 2]], [[0, 1, 2, 3, 4], [5, 6, 7, 8, 9], [10, 11], [12, 13]]), ('control layout', [[1, 1, 0, 0, 0], ['WS', 'WS', 'ON', 'R', 'R'], 0, [4, 1]], [[1, 0, 2, 3], [4]])], [('regression: paragraph-wide reordering', [[4, 4, 2, 2, 2, 1, 3], ['R', 'L', 'L', 'R', 'L', 'R', 'ON'], 0, [3, 2, 2]], [[0, 1, 2], [3, 4], [6, 5]]), ('regression: paragraph-wide reordering', [[0, 0, 3, 3, 3, 1, 1, 2, 0, 0], ['ON', 'R', 'L', 'ON', 'R', 'R', 'WS', 'L', 'R', 'WS'], 0, [5, 5]], [[0, 1, 4, 3, 2], [7, 6, 5, 8, 9]]), ('regression: paragraph-wide reordering', [[2, 4, 4, 2, 2, 2, 1], ['R', 'WS', 'WS', 'WS', 'WS', 'ON', 'L'], 1, [4, 2, 1]], [[3, 2, 1, 0], [4, 5], [6]]), ('regression: paragraph-wide reordering', [[1, 1, 4, 1, 1, 2, 4, 4, 4, 3, 3], ['R', 'L', 'ON', 'WS', 'R', 'L', 'R', 'R', 'WS', 'R', 'WS'], 0, [4, 3, 2, 1, 1]], [[2, 1, 0, 3], [5, 6, 4], [7, 8], [9], [10]]), ('RTL run split across lines', [[1, 1, 1, 1, 1, 1], ['R', 'R', 'WS', 'R', 'R', 'R'], 0, [3, 3]], [[1, 0, 2], [5, 4, 3]]), ('control layout', [[0, 0, 0, 0, 0, 0], ['WS', 'R', 'L', 'WS', 'L', 'ON'], 0, [4, 1, 1]], [[0, 1, 2, 3], [4], [5]]), ('control layout', [[2, 2, 2, 2], ['R', 'R', 'R', 'WS'], 0, [2, 2]], [[0, 1], [2, 3]]), ('control layout', [[1, 1, 1], ['WS', 'WS', 'R'], 1, [3]], [[2, 1, 0]])], [('regression: paragraph-wide reordering', [[3, 3, 3, 3, 1, 1, 1, 1, 3], ['WS', 'R', 'WS', 'WS', 'R', 'WS', 'R', 'L', 'L'], 0, [5, 3, 1]], [[4, 3, 2, 1, 0], [7, 6, 5], [8]]), ('regression: paragraph-wide reordering', [[1, 1, 1, 1, 1, 1, 1, 1], ['WS', 'L', 'L', 'ON', 'L', 'WS', 'WS', 'WS'], 1, [2, 5, 1]], [[1, 0], [6, 5, 4, 3, 2], [7]]), ('regression: paragraph-wide reordering', [[1, 1, 1, 1, 0, 0, 0, 0, 2, 2, 2], ['R', 'R', 'WS', 'R', 'ON', 'WS', 'WS', 'WS', 'L', 'R', 'L'], 1, [3, 5, 3]], [[2, 1, 0], [3, 4, 7, 6, 5], [8, 9, 10]]), ('regression: paragraph-wide reordering', [[0, 0, 0, 1, 1, 1, 1, 0, 2, 2, 2, 2, 2, 1], ['WS', 'WS', 'L', 'R', 'R', 'R', 'L', 'WS', 'WS', 'WS', 'R', 'WS', 'L', 'ON'], 1, [1, 3, 1, 2, 5, 1, 1]], [[0], [1, 2, 3], [4], [6, 5], [7, 11, 8, 9, 10], [12], [13]]), ('RTL run split across lines', [[1, 1, 1, 1, 1, 1], ['R', 'R', 'WS', 'R', 'R', 'R'], 0, [3, 3]], [[1, 0, 2], [5, 4, 3]]), ('control layout', [[2, 2, 2], ['WS', 'WS', 'R'], 1, [3]], [[0, 1, 2]]), ('control layout', [[0, 0, 3, 0, 0, 0, 0, 0], ['WS', 'R', 'WS', 'WS', 'ON', 'WS', 'R', 'L'], 0, [2, 5, 1]], [[0, 1], [2, 3, 4, 5, 6], [7]]), ('control layout', [[3, 2], ['WS', 'ON'], 0, [2]], [[0, 1]])], [('regression: paragraph-wide reordering', [[1, 1, 1, 1, 3, 3, 2, 1, 1, 2, 2], ['ON', 'L', 'L', 'R', 'ON', 'WS', 'WS', 'R', 'L', 'R', 'L'], 1, [1, 3, 2, 4, 1]], [[0], [3, 2, 1], [5, 4], [9, 8, 7, 6], [10]]), ('regression: paragraph-wide reordering', [[3, 2, 2, 2, 2, 1, 1, 1, 4, 4], ['R', 'WS', 'R', 'R', 'WS', 'WS', 'L', 'R', 'ON', 'L'], 1, [2, 3, 2, 2, 1]], [[1, 0], [4, 2, 3], [6, 5], [8, 7], [9]]), ('regression: paragraph-wide reordering', [[2, 2, 2, 2, 3, 3, 1], ['R', 'L', 'WS', 'WS', 'R', 'WS', 'WS'], 1, [4, 3]], [[3, 2, 0, 1], [6, 5, 4]]), ('regression: paragraph-wide reordering', [[2, 4, 4, 3, 3, 3, 3], ['WS', 'ON', 'R', 'ON', 'WS', 'R', 'WS'], 1, [5, 2]], [[4, 0, 3, 1, 2], [6, 5]]), ('RTL run split across lines', [[1, 1, 1, 1, 1, 1], ['R', 'R', 'WS', 'R', 'R', 'R'], 0, [3, 3]], [[1, 0, 2], [5, 4, 3]]), ('control layout', [[0, 0, 0, 0, 0, 0, 2], ['L', 'R', 'L', 'R', 'WS', 'L', 'WS'], 0, [1, 3, 1, 2]], [[0], [1, 2, 3], [4], [5, 6]]), ('control layout', [[2, 2, 2, 2], ['L', 'L', 'ON', 'R'], 0, [2, 2]], [[0, 1], [2, 3]]), ('control layout', [[2, 0, 0, 0, 0, 1], ['L', 'ON', 'WS', 'R', 'L', 'R'], 1, [5, 1]], [[0, 1, 2, 3, 4], [5]])], [('regression: paragraph-wide reordering', [[3, 3, 3, 3, 2, 2, 2, 0, 2, 2, 2, 2, 1, 1], ['WS', 'L', 'R', 'ON', 'L', 'R', 'WS', 'R', 'WS', 'R', 'WS', 'R', 'R', 'L'], 1, [3, 5, 5, 1]], [[2, 1, 0], [3, 4, 5, 6, 7], [12, 8, 9, 10, 11], [13]]), ('regression: paragraph-wide reordering', [[1, 1, 1, 1, 3, 0, 1], ['R', 'L', 'R', 'R', 'WS', 'L', 'R'], 0, [4, 1, 1, 1]], [[3, 2, 1, 0], [4], [5], [6]]), ('regression: paragraph-wide reordering', [[2, 2, 2, 1, 2, 4, 4, 4, 1, 1, 1, 1, 2, 2], ['R', 'L', 'R', 'WS', 'R', 'WS', 'WS', 'L', 'WS', 'L', 'WS', 'WS', 'ON', 'L'], 0, [2, 3, 2, 4, 3]], [[0, 1], [4, 3, 2], [5, 6], [9, 8, 7, 10], [12, 13, 11]]), ('regression: paragraph-wide reordering', [[1, 1, 1, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1], ['WS', 'L', 'R', 'L', 'WS', 'ON', 'WS', 'R', 'L', 'L', 'WS', 'L', 'WS'], 0, [4, 3, 4, 2]], [[3, 2, 1, 0], [4, 5, 6], [9, 8, 7, 10], [11, 12]]), ('RTL run split across lines', [[1, 1, 1, 1, 1, 1], ['R', 'R', 'WS', 'R', 'R', 'R'], 0, [3, 3]], [[1, 0, 2], [5, 4, 3]]), ('control layout', [[2, 2, 2], ['WS', 'L', 'ON'], 1, [3]], [[0, 1, 2]]), ('control layout', [[1, 1, 1], ['ON', 'R', 'R'], 0, [3]], [[2, 1, 0]]), ('control layout', [[1, 0, 0, 0, 0, 0, 0, 3], ['ON', 'WS', 'WS', 'L', 'R', 'WS', 'L', 'WS'], 1, [1, 1, 2, 2, 1, 1]], [[0], [1], [2, 3], [4, 5], [6], [7]])]]
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 fixtureActualExpectedOutcome
RTL run split across lines[[5, 4, 3], [2, 1, 0]][[1, 0, 2], [5, 4, 3]]Failed
regression: paragraph-wide reordering[[10], [9, 8, 7, 6], [5, 4], [3, 2, 1], [0, 11, 12, 13]][[0], [4, 3, 2, 1], [6, 5], [8, 7, 9], [10, 11, 12, 13]]Failed
regression: paragraph-wide reordering[[12, 11, 10, 9], [8, 7, 3], [4, 5, 6, 2], [1, 0]][[3, 2, 1, 0], [4, 5, 6], [9, 8, 7, 10], [11, 12]]Failed
regression: paragraph-wide reordering[[0, 1, 2], [3, 4], [5]][[0, 1, 2], [4, 3], [5]]Failed
control layout[[0], [1, 2], [3]][[0], [1, 2], [3]]Passed
control layout[[0, 1, 2], [3, 4], [5]][[0, 1, 2], [3, 4], [5]]Passed
control layout[[0, 1, 2, 3, 4], [5, 6, 7, 8, 9], [10, 11], [12, 13]][[0, 1, 2, 3, 4], [5, 6, 7, 8, 9], [10, 11], [12, 13]]Passed
control layout[[1, 0, 2, 3], [4]][[1, 0, 2, 3], [4]]Passed

SHA-256 / f777832387f700e5339dc366d9957bac4003a3736ed2d21bd7a6d3113893662d

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, classes, para, line_lengths = x
    out = []
    start = 0
    glob = reorder(levels)
    gpos = {i: v for v, i in enumerate(glob)}
    for ln in line_lengths:
        idx = list(range(start, start + ln))
        lv = [levels[i] for i in idx]
        j = ln - 1
        while j >= 0 and classes[idx[j]] == 'WS':
            lv[j] = para
            j -= 1
        local = reorder(lv)
        out.append(sorted(idx, key=lambda i: gpos[i]))
        start += ln
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('RTL run split across lines', [[1, 1, 1, 1, 1, 1], ['R', 'R', 'WS', 'R', 'R', 'R'], 0, [3, 3]], [[1, 0, 2], [5, 4, 3]]), ('regression: paragraph-wide reordering', [[1, 1, 1, 1, 1, 1, 1, 3, 3, 1, 1, 0, 0, 0], ['L', 'L', 'L', 'WS', 'L', 'WS', 'R', 'R', 'ON', 'WS', 'R', 'WS', 'R', 'WS'], 0, [1, 4, 2, 3, 4]], [[0], [4, 3, 2, 1], [6, 5], [8, 7, 9], [10, 11, 12, 13]]), ('regression: paragraph-wide reordering', [[1, 1, 1, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1], ['WS', 'L', 'R', 'L', 'WS', 'ON', 'WS', 'R', 'L', 'L', 'WS', 'L', 'WS'], 0, [4, 3, 4, 2]], [[3, 2, 1, 0], [4, 5, 6], [9, 8, 7, 10], [11, 12]]), ('regression: paragraph-wide reordering', [[1, 0, 0, 0, 0, 0], ['R', 'L', 'WS', 'WS', 'WS', 'WS'], 1, [3, 2, 1]], [[0, 1, 2], [4, 3], [5]]), ('control layout', [[2, 2, 2, 0], ['WS', 'ON', 'WS', 'L'], 0, [1, 2, 1]], [[0], [1, 2], [3]]), ('control layout', [[2, 2, 2, 0, 0, 1], ['R', 'R', 'R', 'L', 'R', 'R'], 0, [3, 2, 1]], [[0, 1, 2], [3, 4], [5]]), ('control layout', [[0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0], ['WS', 'L', 'R', 'L', 'R', 'L', 'WS', 'R', 'WS', 'ON', 'WS', 'L', 'R', 'WS'], 0, [5, 5, 2, 2]], [[0, 1, 2, 3, 4], [5, 6, 7, 8, 9], [10, 11], [12, 13]]), ('control layout', [[1, 1, 0, 0, 0], ['WS', 'WS', 'ON', 'R', 'R'], 0, [4, 1]], [[1, 0, 2, 3], [4]])], [('regression: paragraph-wide reordering', [[4, 4, 2, 2, 2, 1, 3], ['R', 'L', 'L', 'R', 'L', 'R', 'ON'], 0, [3, 2, 2]], [[0, 1, 2], [3, 4], [6, 5]]), ('regression: paragraph-wide reordering', [[0, 0, 3, 3, 3, 1, 1, 2, 0, 0], ['ON', 'R', 'L', 'ON', 'R', 'R', 'WS', 'L', 'R', 'WS'], 0, [5, 5]], [[0, 1, 4, 3, 2], [7, 6, 5, 8, 9]]), ('regression: paragraph-wide reordering', [[2, 4, 4, 2, 2, 2, 1], ['R', 'WS', 'WS', 'WS', 'WS', 'ON', 'L'], 1, [4, 2, 1]], [[3, 2, 1, 0], [4, 5], [6]]), ('regression: paragraph-wide reordering', [[1, 1, 4, 1, 1, 2, 4, 4, 4, 3, 3], ['R', 'L', 'ON', 'WS', 'R', 'L', 'R', 'R', 'WS', 'R', 'WS'], 0, [4, 3, 2, 1, 1]], [[2, 1, 0, 3], [5, 6, 4], [7, 8], [9], [10]]), ('RTL run split across lines', [[1, 1, 1, 1, 1, 1], ['R', 'R', 'WS', 'R', 'R', 'R'], 0, [3, 3]], [[1, 0, 2], [5, 4, 3]]), ('control layout', [[0, 0, 0, 0, 0, 0], ['WS', 'R', 'L', 'WS', 'L', 'ON'], 0, [4, 1, 1]], [[0, 1, 2, 3], [4], [5]]), ('control layout', [[2, 2, 2, 2], ['R', 'R', 'R', 'WS'], 0, [2, 2]], [[0, 1], [2, 3]]), ('control layout', [[1, 1, 1], ['WS', 'WS', 'R'], 1, [3]], [[2, 1, 0]])], [('regression: paragraph-wide reordering', [[3, 3, 3, 3, 1, 1, 1, 1, 3], ['WS', 'R', 'WS', 'WS', 'R', 'WS', 'R', 'L', 'L'], 0, [5, 3, 1]], [[4, 3, 2, 1, 0], [7, 6, 5], [8]]), ('regression: paragraph-wide reordering', [[1, 1, 1, 1, 1, 1, 1, 1], ['WS', 'L', 'L', 'ON', 'L', 'WS', 'WS', 'WS'], 1, [2, 5, 1]], [[1, 0], [6, 5, 4, 3, 2], [7]]), ('regression: paragraph-wide reordering', [[1, 1, 1, 1, 0, 0, 0, 0, 2, 2, 2], ['R', 'R', 'WS', 'R', 'ON', 'WS', 'WS', 'WS', 'L', 'R', 'L'], 1, [3, 5, 3]], [[2, 1, 0], [3, 4, 7, 6, 5], [8, 9, 10]]), ('regression: paragraph-wide reordering', [[0, 0, 0, 1, 1, 1, 1, 0, 2, 2, 2, 2, 2, 1], ['WS', 'WS', 'L', 'R', 'R', 'R', 'L', 'WS', 'WS', 'WS', 'R', 'WS', 'L', 'ON'], 1, [1, 3, 1, 2, 5, 1, 1]], [[0], [1, 2, 3], [4], [6, 5], [7, 11, 8, 9, 10], [12], [13]]), ('RTL run split across lines', [[1, 1, 1, 1, 1, 1], ['R', 'R', 'WS', 'R', 'R', 'R'], 0, [3, 3]], [[1, 0, 2], [5, 4, 3]]), ('control layout', [[2, 2, 2], ['WS', 'WS', 'R'], 1, [3]], [[0, 1, 2]]), ('control layout', [[0, 0, 3, 0, 0, 0, 0, 0], ['WS', 'R', 'WS', 'WS', 'ON', 'WS', 'R', 'L'], 0, [2, 5, 1]], [[0, 1], [2, 3, 4, 5, 6], [7]]), ('control layout', [[3, 2], ['WS', 'ON'], 0, [2]], [[0, 1]])], [('regression: paragraph-wide reordering', [[1, 1, 1, 1, 3, 3, 2, 1, 1, 2, 2], ['ON', 'L', 'L', 'R', 'ON', 'WS', 'WS', 'R', 'L', 'R', 'L'], 1, [1, 3, 2, 4, 1]], [[0], [3, 2, 1], [5, 4], [9, 8, 7, 6], [10]]), ('regression: paragraph-wide reordering', [[3, 2, 2, 2, 2, 1, 1, 1, 4, 4], ['R', 'WS', 'R', 'R', 'WS', 'WS', 'L', 'R', 'ON', 'L'], 1, [2, 3, 2, 2, 1]], [[1, 0], [4, 2, 3], [6, 5], [8, 7], [9]]), ('regression: paragraph-wide reordering', [[2, 2, 2, 2, 3, 3, 1], ['R', 'L', 'WS', 'WS', 'R', 'WS', 'WS'], 1, [4, 3]], [[3, 2, 0, 1], [6, 5, 4]]), ('regression: paragraph-wide reordering', [[2, 4, 4, 3, 3, 3, 3], ['WS', 'ON', 'R', 'ON', 'WS', 'R', 'WS'], 1, [5, 2]], [[4, 0, 3, 1, 2], [6, 5]]), ('RTL run split across lines', [[1, 1, 1, 1, 1, 1], ['R', 'R', 'WS', 'R', 'R', 'R'], 0, [3, 3]], [[1, 0, 2], [5, 4, 3]]), ('control layout', [[0, 0, 0, 0, 0, 0, 2], ['L', 'R', 'L', 'R', 'WS', 'L', 'WS'], 0, [1, 3, 1, 2]], [[0], [1, 2, 3], [4], [5, 6]]), ('control layout', [[2, 2, 2, 2], ['L', 'L', 'ON', 'R'], 0, [2, 2]], [[0, 1], [2, 3]]), ('control layout', [[2, 0, 0, 0, 0, 1], ['L', 'ON', 'WS', 'R', 'L', 'R'], 1, [5, 1]], [[0, 1, 2, 3, 4], [5]])], [('regression: paragraph-wide reordering', [[3, 3, 3, 3, 2, 2, 2, 0, 2, 2, 2, 2, 1, 1], ['WS', 'L', 'R', 'ON', 'L', 'R', 'WS', 'R', 'WS', 'R', 'WS', 'R', 'R', 'L'], 1, [3, 5, 5, 1]], [[2, 1, 0], [3, 4, 5, 6, 7], [12, 8, 9, 10, 11], [13]]), ('regression: paragraph-wide reordering', [[1, 1, 1, 1, 3, 0, 1], ['R', 'L', 'R', 'R', 'WS', 'L', 'R'], 0, [4, 1, 1, 1]], [[3, 2, 1, 0], [4], [5], [6]]), ('regression: paragraph-wide reordering', [[2, 2, 2, 1, 2, 4, 4, 4, 1, 1, 1, 1, 2, 2], ['R', 'L', 'R', 'WS', 'R', 'WS', 'WS', 'L', 'WS', 'L', 'WS', 'WS', 'ON', 'L'], 0, [2, 3, 2, 4, 3]], [[0, 1], [4, 3, 2], [5, 6], [9, 8, 7, 10], [12, 13, 11]]), ('regression: paragraph-wide reordering', [[1, 1, 1, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1], ['WS', 'L', 'R', 'L', 'WS', 'ON', 'WS', 'R', 'L', 'L', 'WS', 'L', 'WS'], 0, [4, 3, 4, 2]], [[3, 2, 1, 0], [4, 5, 6], [9, 8, 7, 10], [11, 12]]), ('RTL run split across lines', [[1, 1, 1, 1, 1, 1], ['R', 'R', 'WS', 'R', 'R', 'R'], 0, [3, 3]], [[1, 0, 2], [5, 4, 3]]), ('control layout', [[2, 2, 2], ['WS', 'L', 'ON'], 1, [3]], [[0, 1, 2]]), ('control layout', [[1, 1, 1], ['ON', 'R', 'R'], 0, [3]], [[2, 1, 0]]), ('control layout', [[1, 0, 0, 0, 0, 0, 0, 3], ['ON', 'WS', 'WS', 'L', 'R', 'WS', 'L', 'WS'], 1, [1, 1, 2, 2, 1, 1]], [[0], [1], [2, 3], [4, 5], [6], [7]])]]
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 fixtureActualExpectedOutcome
RTL run split across lines[[2, 1, 0], [5, 4, 3]][[1, 0, 2], [5, 4, 3]]Failed
regression: paragraph-wide reordering[[0], [4, 3, 2, 1], [6, 5], [9, 8, 7], [10, 11, 12, 13]][[0], [4, 3, 2, 1], [6, 5], [8, 7, 9], [10, 11, 12, 13]]Failed
regression: paragraph-wide reordering[[3, 2, 1, 0], [4, 5, 6], [10, 9, 8, 7], [12, 11]][[3, 2, 1, 0], [4, 5, 6], [9, 8, 7, 10], [11, 12]]Failed
regression: paragraph-wide reordering[[0, 1, 2], [3, 4], [5]][[0, 1, 2], [4, 3], [5]]Failed
control layout[[0], [1, 2], [3]][[0], [1, 2], [3]]Passed
control layout[[0, 1, 2], [3, 4], [5]][[0, 1, 2], [3, 4], [5]]Passed
control layout[[0, 1, 2, 3, 4], [5, 6, 7, 8, 9], [10, 11], [12, 13]][[0, 1, 2, 3, 4], [5, 6, 7, 8, 9], [10, 11], [12, 13]]Passed
control layout[[1, 0, 2, 3], [4]][[1, 0, 2, 3], [4]]Passed

SHA-256 / 1a19049f081d539e4fe25e9d711f0759424f93fc4f66e51f1b3c019898e88f4d

3 / The verified repair

Exit 0
"""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, classes, para, line_lengths = x
    out = []
    start = 0
    for ln in line_lengths:
        idx = list(range(start, start + ln))
        lv = [levels[i] for i in idx]
        j = ln - 1
        while j >= 0 and classes[idx[j]] == 'WS':
            lv[j] = para
            j -= 1
        local = reorder(lv)
        out.append([idx[v] for v in local])
        start += ln
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('RTL run split across lines', [[1, 1, 1, 1, 1, 1], ['R', 'R', 'WS', 'R', 'R', 'R'], 0, [3, 3]], [[1, 0, 2], [5, 4, 3]]), ('regression: paragraph-wide reordering', [[1, 1, 1, 1, 1, 1, 1, 3, 3, 1, 1, 0, 0, 0], ['L', 'L', 'L', 'WS', 'L', 'WS', 'R', 'R', 'ON', 'WS', 'R', 'WS', 'R', 'WS'], 0, [1, 4, 2, 3, 4]], [[0], [4, 3, 2, 1], [6, 5], [8, 7, 9], [10, 11, 12, 13]]), ('regression: paragraph-wide reordering', [[1, 1, 1, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1], ['WS', 'L', 'R', 'L', 'WS', 'ON', 'WS', 'R', 'L', 'L', 'WS', 'L', 'WS'], 0, [4, 3, 4, 2]], [[3, 2, 1, 0], [4, 5, 6], [9, 8, 7, 10], [11, 12]]), ('regression: paragraph-wide reordering', [[1, 0, 0, 0, 0, 0], ['R', 'L', 'WS', 'WS', 'WS', 'WS'], 1, [3, 2, 1]], [[0, 1, 2], [4, 3], [5]]), ('control layout', [[2, 2, 2, 0], ['WS', 'ON', 'WS', 'L'], 0, [1, 2, 1]], [[0], [1, 2], [3]]), ('control layout', [[2, 2, 2, 0, 0, 1], ['R', 'R', 'R', 'L', 'R', 'R'], 0, [3, 2, 1]], [[0, 1, 2], [3, 4], [5]]), ('control layout', [[0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0], ['WS', 'L', 'R', 'L', 'R', 'L', 'WS', 'R', 'WS', 'ON', 'WS', 'L', 'R', 'WS'], 0, [5, 5, 2, 2]], [[0, 1, 2, 3, 4], [5, 6, 7, 8, 9], [10, 11], [12, 13]]), ('control layout', [[1, 1, 0, 0, 0], ['WS', 'WS', 'ON', 'R', 'R'], 0, [4, 1]], [[1, 0, 2, 3], [4]])], [('regression: paragraph-wide reordering', [[4, 4, 2, 2, 2, 1, 3], ['R', 'L', 'L', 'R', 'L', 'R', 'ON'], 0, [3, 2, 2]], [[0, 1, 2], [3, 4], [6, 5]]), ('regression: paragraph-wide reordering', [[0, 0, 3, 3, 3, 1, 1, 2, 0, 0], ['ON', 'R', 'L', 'ON', 'R', 'R', 'WS', 'L', 'R', 'WS'], 0, [5, 5]], [[0, 1, 4, 3, 2], [7, 6, 5, 8, 9]]), ('regression: paragraph-wide reordering', [[2, 4, 4, 2, 2, 2, 1], ['R', 'WS', 'WS', 'WS', 'WS', 'ON', 'L'], 1, [4, 2, 1]], [[3, 2, 1, 0], [4, 5], [6]]), ('regression: paragraph-wide reordering', [[1, 1, 4, 1, 1, 2, 4, 4, 4, 3, 3], ['R', 'L', 'ON', 'WS', 'R', 'L', 'R', 'R', 'WS', 'R', 'WS'], 0, [4, 3, 2, 1, 1]], [[2, 1, 0, 3], [5, 6, 4], [7, 8], [9], [10]]), ('RTL run split across lines', [[1, 1, 1, 1, 1, 1], ['R', 'R', 'WS', 'R', 'R', 'R'], 0, [3, 3]], [[1, 0, 2], [5, 4, 3]]), ('control layout', [[0, 0, 0, 0, 0, 0], ['WS', 'R', 'L', 'WS', 'L', 'ON'], 0, [4, 1, 1]], [[0, 1, 2, 3], [4], [5]]), ('control layout', [[2, 2, 2, 2], ['R', 'R', 'R', 'WS'], 0, [2, 2]], [[0, 1], [2, 3]]), ('control layout', [[1, 1, 1], ['WS', 'WS', 'R'], 1, [3]], [[2, 1, 0]])], [('regression: paragraph-wide reordering', [[3, 3, 3, 3, 1, 1, 1, 1, 3], ['WS', 'R', 'WS', 'WS', 'R', 'WS', 'R', 'L', 'L'], 0, [5, 3, 1]], [[4, 3, 2, 1, 0], [7, 6, 5], [8]]), ('regression: paragraph-wide reordering', [[1, 1, 1, 1, 1, 1, 1, 1], ['WS', 'L', 'L', 'ON', 'L', 'WS', 'WS', 'WS'], 1, [2, 5, 1]], [[1, 0], [6, 5, 4, 3, 2], [7]]), ('regression: paragraph-wide reordering', [[1, 1, 1, 1, 0, 0, 0, 0, 2, 2, 2], ['R', 'R', 'WS', 'R', 'ON', 'WS', 'WS', 'WS', 'L', 'R', 'L'], 1, [3, 5, 3]], [[2, 1, 0], [3, 4, 7, 6, 5], [8, 9, 10]]), ('regression: paragraph-wide reordering', [[0, 0, 0, 1, 1, 1, 1, 0, 2, 2, 2, 2, 2, 1], ['WS', 'WS', 'L', 'R', 'R', 'R', 'L', 'WS', 'WS', 'WS', 'R', 'WS', 'L', 'ON'], 1, [1, 3, 1, 2, 5, 1, 1]], [[0], [1, 2, 3], [4], [6, 5], [7, 11, 8, 9, 10], [12], [13]]), ('RTL run split across lines', [[1, 1, 1, 1, 1, 1], ['R', 'R', 'WS', 'R', 'R', 'R'], 0, [3, 3]], [[1, 0, 2], [5, 4, 3]]), ('control layout', [[2, 2, 2], ['WS', 'WS', 'R'], 1, [3]], [[0, 1, 2]]), ('control layout', [[0, 0, 3, 0, 0, 0, 0, 0], ['WS', 'R', 'WS', 'WS', 'ON', 'WS', 'R', 'L'], 0, [2, 5, 1]], [[0, 1], [2, 3, 4, 5, 6], [7]]), ('control layout', [[3, 2], ['WS', 'ON'], 0, [2]], [[0, 1]])], [('regression: paragraph-wide reordering', [[1, 1, 1, 1, 3, 3, 2, 1, 1, 2, 2], ['ON', 'L', 'L', 'R', 'ON', 'WS', 'WS', 'R', 'L', 'R', 'L'], 1, [1, 3, 2, 4, 1]], [[0], [3, 2, 1], [5, 4], [9, 8, 7, 6], [10]]), ('regression: paragraph-wide reordering', [[3, 2, 2, 2, 2, 1, 1, 1, 4, 4], ['R', 'WS', 'R', 'R', 'WS', 'WS', 'L', 'R', 'ON', 'L'], 1, [2, 3, 2, 2, 1]], [[1, 0], [4, 2, 3], [6, 5], [8, 7], [9]]), ('regression: paragraph-wide reordering', [[2, 2, 2, 2, 3, 3, 1], ['R', 'L', 'WS', 'WS', 'R', 'WS', 'WS'], 1, [4, 3]], [[3, 2, 0, 1], [6, 5, 4]]), ('regression: paragraph-wide reordering', [[2, 4, 4, 3, 3, 3, 3], ['WS', 'ON', 'R', 'ON', 'WS', 'R', 'WS'], 1, [5, 2]], [[4, 0, 3, 1, 2], [6, 5]]), ('RTL run split across lines', [[1, 1, 1, 1, 1, 1], ['R', 'R', 'WS', 'R', 'R', 'R'], 0, [3, 3]], [[1, 0, 2], [5, 4, 3]]), ('control layout', [[0, 0, 0, 0, 0, 0, 2], ['L', 'R', 'L', 'R', 'WS', 'L', 'WS'], 0, [1, 3, 1, 2]], [[0], [1, 2, 3], [4], [5, 6]]), ('control layout', [[2, 2, 2, 2], ['L', 'L', 'ON', 'R'], 0, [2, 2]], [[0, 1], [2, 3]]), ('control layout', [[2, 0, 0, 0, 0, 1], ['L', 'ON', 'WS', 'R', 'L', 'R'], 1, [5, 1]], [[0, 1, 2, 3, 4], [5]])], [('regression: paragraph-wide reordering', [[3, 3, 3, 3, 2, 2, 2, 0, 2, 2, 2, 2, 1, 1], ['WS', 'L', 'R', 'ON', 'L', 'R', 'WS', 'R', 'WS', 'R', 'WS', 'R', 'R', 'L'], 1, [3, 5, 5, 1]], [[2, 1, 0], [3, 4, 5, 6, 7], [12, 8, 9, 10, 11], [13]]), ('regression: paragraph-wide reordering', [[1, 1, 1, 1, 3, 0, 1], ['R', 'L', 'R', 'R', 'WS', 'L', 'R'], 0, [4, 1, 1, 1]], [[3, 2, 1, 0], [4], [5], [6]]), ('regression: paragraph-wide reordering', [[2, 2, 2, 1, 2, 4, 4, 4, 1, 1, 1, 1, 2, 2], ['R', 'L', 'R', 'WS', 'R', 'WS', 'WS', 'L', 'WS', 'L', 'WS', 'WS', 'ON', 'L'], 0, [2, 3, 2, 4, 3]], [[0, 1], [4, 3, 2], [5, 6], [9, 8, 7, 10], [12, 13, 11]]), ('regression: paragraph-wide reordering', [[1, 1, 1, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1], ['WS', 'L', 'R', 'L', 'WS', 'ON', 'WS', 'R', 'L', 'L', 'WS', 'L', 'WS'], 0, [4, 3, 4, 2]], [[3, 2, 1, 0], [4, 5, 6], [9, 8, 7, 10], [11, 12]]), ('RTL run split across lines', [[1, 1, 1, 1, 1, 1], ['R', 'R', 'WS', 'R', 'R', 'R'], 0, [3, 3]], [[1, 0, 2], [5, 4, 3]]), ('control layout', [[2, 2, 2], ['WS', 'L', 'ON'], 1, [3]], [[0, 1, 2]]), ('control layout', [[1, 1, 1], ['ON', 'R', 'R'], 0, [3]], [[2, 1, 0]]), ('control layout', [[1, 0, 0, 0, 0, 0, 0, 3], ['ON', 'WS', 'WS', 'L', 'R', 'WS', 'L', 'WS'], 1, [1, 1, 2, 2, 1, 1]], [[0], [1], [2, 3], [4, 5], [6], [7]])]]
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 fixtureActualExpectedOutcome
RTL run split across lines[[1, 0, 2], [5, 4, 3]][[1, 0, 2], [5, 4, 3]]Passed
regression: paragraph-wide reordering[[0], [4, 3, 2, 1], [6, 5], [8, 7, 9], [10, 11, 12, 13]][[0], [4, 3, 2, 1], [6, 5], [8, 7, 9], [10, 11, 12, 13]]Passed
regression: paragraph-wide reordering[[3, 2, 1, 0], [4, 5, 6], [9, 8, 7, 10], [11, 12]][[3, 2, 1, 0], [4, 5, 6], [9, 8, 7, 10], [11, 12]]Passed
regression: paragraph-wide reordering[[0, 1, 2], [4, 3], [5]][[0, 1, 2], [4, 3], [5]]Passed
control layout[[0], [1, 2], [3]][[0], [1, 2], [3]]Passed
control layout[[0, 1, 2], [3, 4], [5]][[0, 1, 2], [3, 4], [5]]Passed
control layout[[0, 1, 2, 3, 4], [5, 6, 7, 8, 9], [10, 11], [12, 13]][[0, 1, 2, 3, 4], [5, 6, 7, 8, 9], [10, 11], [12, 13]]Passed
control layout[[1, 0, 2, 3], [4]][[1, 0, 2, 3], [4]]Passed

SHA-256 / 72a2c5670b84b717f573f9509e3f1960e3c76e2c5743ca7337cafdf3f4a9ee44

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

Case digest / 1d415205b529b50aad9579e67e4765c8df2a43e3358c97be5bb3fd1aeb38b1d0