FAILURE MAP
← Case archive

FA-80671 / Bidirectional text layout / Open access

Bidi selection highlight: rectangle adjacency · case 01

Separate highlight fragments are fused across unselected gaps.

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

ROOT CAUSE

The merge accepts a slot one unit past the rectangle end.

VERIFIED REPAIR

Merge only slots exactly adjacent to the current rectangle.

Unsuccessful approach: Requiring a one-unit gap prevents merging contiguous slots.

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 = sorted(pos[i] for i in range(a, b))
    rects = []
    for p in sel:
        if rects and rects[-1][1] >= p - 1:
            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 = [[('regression: rectangle adjacency', [[2, 2, 2, 2, 1, 1, 1, 4, 4, 1, 1], 8, 2], [[2, 3], [4, 7], [9, 11]]), ('regression: rectangle adjacency', [[1, 1, 1, 1, 1, 3, 0, 0, 0, 0], 1, 10], [[0, 5], [6, 10]]), ('partial-repair probe', [[0, 3, 0, 0, 0, 3], 2, 0], [[0, 2]]), ('partial-repair probe', [[1, 1, 1, 1, 1, 1, 1, 0, 0, 0], 2, 8], [[0, 5], [7, 8]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('control layout', [[3, 3, 3, 3, 3, 3, 3, 3, 0, 3, 3], 10, 10], []), ('control layout', [[3, 3, 3, 1, 1], 3, 4], [[1, 2]])], [('regression: rectangle adjacency', [[2, 1, 1, 1, 1, 1, 1, 1, 2, 4, 4], 7, 10], [[0, 2], [3, 4]]), ('regression: rectangle adjacency', [[2, 2, 2, 2, 1, 1, 1, 4, 4, 1, 1], 8, 2], [[2, 3], [4, 7], [9, 11]]), ('partial-repair probe', [[2, 3, 3, 3, 3, 3, 0, 0, 0, 2, 2], 6, 9], [[6, 9]]), ('partial-repair probe', [[3, 3, 3, 3, 2, 2, 2, 1, 1], 4, 1], [[2, 5]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('control layout', [[1, 2, 2, 2, 4, 4, 4, 4, 1, 1, 1], 10, 9], [[1, 2]]), ('control layout', [[4, 4, 4, 4, 1, 1, 3], 1, 0], [[3, 4]])], [('regression: rectangle adjacency', [[0, 0, 0, 0, 2, 2, 2, 2, 1], 2, 6], [[2, 4], [5, 7]]), ('regression: rectangle adjacency', [[0, 0, 0, 3, 3, 0, 0, 3, 3, 3, 0], 3, 9], [[3, 7], [8, 10]]), ('regression: rectangle adjacency', [[4, 4, 1, 1, 1, 1, 2], 1, 6], [[1, 5], [6, 7]]), ('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]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('control layout', [[0, 0], 1, 2], [[1, 2]]), ('control layout', [[3, 3, 3, 1, 1], 3, 4], [[1, 2]])], [('regression: rectangle adjacency', [[4, 4, 4, 4, 3, 2], 1, 5], [[0, 1], [2, 5]]), ('regression: rectangle adjacency', [[0, 0, 0, 3, 1], 2, 4], [[2, 3], [4, 5]]), ('partial-repair probe', [[3, 2, 2, 2, 2, 0, 1], 7, 2], [[2, 7]]), ('partial-repair probe', [[1, 1, 1, 1, 1, 1, 2], 4, 6], [[1, 3]]), ('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, 1, 3], 1, 0], [[0, 1]]), ('control layout', [[1, 1, 1, 1], 1, 1], [])], [('regression: rectangle adjacency', [[2, 2, 2, 1, 1], 1, 4], [[1, 2], [3, 5]]), ('regression: rectangle adjacency', [[0, 0, 0, 3, 1], 2, 4], [[2, 3], [4, 5]]), ('regression: rectangle adjacency', [[0, 0, 0, 0, 2, 2, 2, 2, 1], 2, 6], [[2, 4], [5, 7]]), ('partial-repair probe', [[2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1], 11, 6], [[0, 5]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('control layout', [[4, 4, 4, 1, 1], 0, 1], [[2, 3]]), ('control layout', [[2, 2, 2, 1, 4, 4], 4, 3], [[2, 3]])]]
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
regression: rectangle adjacency[[2, 7], [9, 11]][[2, 3], [4, 7], [9, 11]]Failed
regression: rectangle adjacency[[0, 10]][[0, 5], [6, 10]]Failed
partial-repair probe[[0, 2]][[0, 2]]Passed
partial-repair probe[[0, 5], [7, 8]][[0, 5], [7, 8]]Passed
selection crossing direction change[[1, 4]][[1, 4]]Passed
backward selection[[0, 2]][[0, 2]]Passed
control layout[][]Passed
control layout[[1, 2]][[1, 2]]Passed

SHA-256 / 0e936c8bdb6a1770eed1720b7cae1aea1708cfc28d9bfff7a5e25171fa6a4b5f

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))
    rects = []
    for p in sel:
        if rects and rects[-1][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 = [[('regression: rectangle adjacency', [[2, 2, 2, 2, 1, 1, 1, 4, 4, 1, 1], 8, 2], [[2, 3], [4, 7], [9, 11]]), ('regression: rectangle adjacency', [[1, 1, 1, 1, 1, 3, 0, 0, 0, 0], 1, 10], [[0, 5], [6, 10]]), ('partial-repair probe', [[0, 3, 0, 0, 0, 3], 2, 0], [[0, 2]]), ('partial-repair probe', [[1, 1, 1, 1, 1, 1, 1, 0, 0, 0], 2, 8], [[0, 5], [7, 8]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('control layout', [[3, 3, 3, 3, 3, 3, 3, 3, 0, 3, 3], 10, 10], []), ('control layout', [[3, 3, 3, 1, 1], 3, 4], [[1, 2]])], [('regression: rectangle adjacency', [[2, 1, 1, 1, 1, 1, 1, 1, 2, 4, 4], 7, 10], [[0, 2], [3, 4]]), ('regression: rectangle adjacency', [[2, 2, 2, 2, 1, 1, 1, 4, 4, 1, 1], 8, 2], [[2, 3], [4, 7], [9, 11]]), ('partial-repair probe', [[2, 3, 3, 3, 3, 3, 0, 0, 0, 2, 2], 6, 9], [[6, 9]]), ('partial-repair probe', [[3, 3, 3, 3, 2, 2, 2, 1, 1], 4, 1], [[2, 5]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('control layout', [[1, 2, 2, 2, 4, 4, 4, 4, 1, 1, 1], 10, 9], [[1, 2]]), ('control layout', [[4, 4, 4, 4, 1, 1, 3], 1, 0], [[3, 4]])], [('regression: rectangle adjacency', [[0, 0, 0, 0, 2, 2, 2, 2, 1], 2, 6], [[2, 4], [5, 7]]), ('regression: rectangle adjacency', [[0, 0, 0, 3, 3, 0, 0, 3, 3, 3, 0], 3, 9], [[3, 7], [8, 10]]), ('regression: rectangle adjacency', [[4, 4, 1, 1, 1, 1, 2], 1, 6], [[1, 5], [6, 7]]), ('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]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('control layout', [[0, 0], 1, 2], [[1, 2]]), ('control layout', [[3, 3, 3, 1, 1], 3, 4], [[1, 2]])], [('regression: rectangle adjacency', [[4, 4, 4, 4, 3, 2], 1, 5], [[0, 1], [2, 5]]), ('regression: rectangle adjacency', [[0, 0, 0, 3, 1], 2, 4], [[2, 3], [4, 5]]), ('partial-repair probe', [[3, 2, 2, 2, 2, 0, 1], 7, 2], [[2, 7]]), ('partial-repair probe', [[1, 1, 1, 1, 1, 1, 2], 4, 6], [[1, 3]]), ('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, 1, 3], 1, 0], [[0, 1]]), ('control layout', [[1, 1, 1, 1], 1, 1], [])], [('regression: rectangle adjacency', [[2, 2, 2, 1, 1], 1, 4], [[1, 2], [3, 5]]), ('regression: rectangle adjacency', [[0, 0, 0, 3, 1], 2, 4], [[2, 3], [4, 5]]), ('regression: rectangle adjacency', [[0, 0, 0, 0, 2, 2, 2, 2, 1], 2, 6], [[2, 4], [5, 7]]), ('partial-repair probe', [[2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1], 11, 6], [[0, 5]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('control layout', [[4, 4, 4, 1, 1], 0, 1], [[2, 3]]), ('control layout', [[2, 2, 2, 1, 4, 4], 4, 3], [[2, 3]])]]
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
regression: rectangle adjacency[[2, 5], [5, 6], [6, 7], [9, 10], [10, 11]][[2, 3], [4, 7], [9, 11]]Failed
regression: rectangle adjacency[[0, 1], [1, 2], [2, 3], [3, 4], [4, 7], [7, 8], [8, 9], [9, 10]][[0, 5], [6, 10]]Failed
partial-repair probe[[0, 1], [1, 2]][[0, 2]]Failed
partial-repair probe[[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [7, 8]][[0, 5], [7, 8]]Failed
selection crossing direction change[[1, 2], [2, 3], [3, 4]][[1, 4]]Failed
backward selection[[0, 1], [1, 2]][[0, 2]]Failed
control layout[][]Passed
control layout[[1, 2]][[1, 2]]Passed

SHA-256 / 7bfe1132e31cc95e0a29068105daf227aede4553ba519c49af3b09cec8786068

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, 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))
    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 = [[('regression: rectangle adjacency', [[2, 2, 2, 2, 1, 1, 1, 4, 4, 1, 1], 8, 2], [[2, 3], [4, 7], [9, 11]]), ('regression: rectangle adjacency', [[1, 1, 1, 1, 1, 3, 0, 0, 0, 0], 1, 10], [[0, 5], [6, 10]]), ('partial-repair probe', [[0, 3, 0, 0, 0, 3], 2, 0], [[0, 2]]), ('partial-repair probe', [[1, 1, 1, 1, 1, 1, 1, 0, 0, 0], 2, 8], [[0, 5], [7, 8]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('control layout', [[3, 3, 3, 3, 3, 3, 3, 3, 0, 3, 3], 10, 10], []), ('control layout', [[3, 3, 3, 1, 1], 3, 4], [[1, 2]])], [('regression: rectangle adjacency', [[2, 1, 1, 1, 1, 1, 1, 1, 2, 4, 4], 7, 10], [[0, 2], [3, 4]]), ('regression: rectangle adjacency', [[2, 2, 2, 2, 1, 1, 1, 4, 4, 1, 1], 8, 2], [[2, 3], [4, 7], [9, 11]]), ('partial-repair probe', [[2, 3, 3, 3, 3, 3, 0, 0, 0, 2, 2], 6, 9], [[6, 9]]), ('partial-repair probe', [[3, 3, 3, 3, 2, 2, 2, 1, 1], 4, 1], [[2, 5]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('control layout', [[1, 2, 2, 2, 4, 4, 4, 4, 1, 1, 1], 10, 9], [[1, 2]]), ('control layout', [[4, 4, 4, 4, 1, 1, 3], 1, 0], [[3, 4]])], [('regression: rectangle adjacency', [[0, 0, 0, 0, 2, 2, 2, 2, 1], 2, 6], [[2, 4], [5, 7]]), ('regression: rectangle adjacency', [[0, 0, 0, 3, 3, 0, 0, 3, 3, 3, 0], 3, 9], [[3, 7], [8, 10]]), ('regression: rectangle adjacency', [[4, 4, 1, 1, 1, 1, 2], 1, 6], [[1, 5], [6, 7]]), ('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]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('control layout', [[0, 0], 1, 2], [[1, 2]]), ('control layout', [[3, 3, 3, 1, 1], 3, 4], [[1, 2]])], [('regression: rectangle adjacency', [[4, 4, 4, 4, 3, 2], 1, 5], [[0, 1], [2, 5]]), ('regression: rectangle adjacency', [[0, 0, 0, 3, 1], 2, 4], [[2, 3], [4, 5]]), ('partial-repair probe', [[3, 2, 2, 2, 2, 0, 1], 7, 2], [[2, 7]]), ('partial-repair probe', [[1, 1, 1, 1, 1, 1, 2], 4, 6], [[1, 3]]), ('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, 1, 3], 1, 0], [[0, 1]]), ('control layout', [[1, 1, 1, 1], 1, 1], [])], [('regression: rectangle adjacency', [[2, 2, 2, 1, 1], 1, 4], [[1, 2], [3, 5]]), ('regression: rectangle adjacency', [[0, 0, 0, 3, 1], 2, 4], [[2, 3], [4, 5]]), ('regression: rectangle adjacency', [[0, 0, 0, 0, 2, 2, 2, 2, 1], 2, 6], [[2, 4], [5, 7]]), ('partial-repair probe', [[2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1], 11, 6], [[0, 5]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('control layout', [[4, 4, 4, 1, 1], 0, 1], [[2, 3]]), ('control layout', [[2, 2, 2, 1, 4, 4], 4, 3], [[2, 3]])]]
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
regression: rectangle adjacency[[2, 3], [4, 7], [9, 11]][[2, 3], [4, 7], [9, 11]]Passed
regression: rectangle adjacency[[0, 5], [6, 10]][[0, 5], [6, 10]]Passed
partial-repair probe[[0, 2]][[0, 2]]Passed
partial-repair probe[[0, 5], [7, 8]][[0, 5], [7, 8]]Passed
selection crossing direction change[[1, 4]][[1, 4]]Passed
backward selection[[0, 2]][[0, 2]]Passed
control layout[][]Passed
control layout[[1, 2]][[1, 2]]Passed

SHA-256 / 64c5723e14a40a5b09721591dbf8a49c415ee0b0265d9545d940d3bffbcba61d

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

Case digest / 2e236acb1db1cf9280d30416e07581d929338d34bc89f13e1780a89355f9dae8