FAILURE MAP
← Case archive

FA-80696 / Bidirectional text layout / Open access

Bidi hit testing: visual slot lookup · case 01

Clicks hit the character with the logical index equal to the slot.

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

ROOT CAUSE

The slot is used as the logical index.

VERIFIED REPAIR

Look up the logical index at the visual slot.

Unsuccessful approach: Reading the order backwards is not the mapping either.

Case contract

Input [levels, x in half-character units]. Clamp to a visual slot (each character 2 units). The right half of an LTR character or the left half of an RTL character is its trailing side. Points before the line use the left half of slot 0, beyond it the right half of the last slot. Return [logical index, trailing, caret offset].

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, px = x
    n = len(levels)
    if n == 0:
        return [None, False, 0]
    vis = reorder(levels)
    v = min(max(px // 2, 0), n - 1)
    i = v
    right_half = px - 2 * v >= 1
    rtl = levels[i] % 2 == 1
    trailing = right_half != rtl
    return [i, trailing, i + 1 if trailing else i]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('click left of RTL line', [[1, 1, 1], -1], [2, True, 3]), ('regression: visual slot lookup', [[2, 2, 2, 1, 1], 8], [2, False, 2]), ('regression: visual slot lookup', [[1, 1, 1, 1, 3, 3, 0, 1, 2, 2], 1], [5, False, 5]), ('partial-repair probe', [[0, 0, 0, 0], -1], [0, False, 0]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('control layout', [[1], 4], [0, False, 0]), ('control layout', [[2, 2, 2, 2, 2, 4, 2, 2, 2], 9], [4, True, 5])], [('regression: visual slot lookup', [[1, 1, 1, 3], 10], [0, False, 0]), ('regression: visual slot lookup', [[1, 1, 1, 1, 1, 1], 9], [1, False, 1]), ('regression: visual slot lookup', [[1, 1, 1, 0, 0, 1, 1], -3], [2, True, 3]), ('regression: visual slot lookup', [[1, 1, 2, 2, 2, 3, 3], 16], [0, False, 0]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('control layout', [[1], 4], [0, False, 0]), ('control layout', [[4, 4, 4, 1, 4, 4, 4], 6], [3, True, 4])], [('regression: visual slot lookup', [[3, 3, 3, 3, 3, 1, 2, 2, 2, 2], 11], [4, False, 4]), ('regression: visual slot lookup', [[1, 2], 7], [0, False, 0]), ('regression: visual slot lookup', [[4, 4, 4, 4, 1, 1], 11], [3, True, 4]), ('regression: visual slot lookup', [[2, 2, 2, 1, 1, 1, 2], 0], [6, False, 6]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('click left of RTL line', [[1, 1, 1], -1], [2, True, 3]), ('control layout', [[2], 4], [0, True, 1]), ('control layout', [[1], 3], [0, False, 0])], [('regression: visual slot lookup', [[1, 3, 3, 3, 3, 1, 1, 1], 9], [3, False, 3]), ('regression: visual slot lookup', [[1, 1, 1, 0, 0, 0, 3], -1], [2, True, 3]), ('partial-repair probe', [[1, 0, 0, 0, 0], -1], [0, True, 1]), ('regression: visual slot lookup', [[1, 1, 1, 1, 1, 1, 1, 1, 3], 17], [0, False, 0]), ('click left of RTL line', [[1, 1, 1], -1], [2, True, 3]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('control layout', [[1], 3], [0, False, 0]), ('control layout', [[1], -2], [0, True, 1])], [('regression: visual slot lookup', [[3, 3, 0, 0, 0], -2], [1, True, 2]), ('regression: visual slot lookup', [[1, 1, 1, 3, 3], 13], [0, False, 0]), ('regression: visual slot lookup', [[3, 3, 3, 3, 1, 1, 1], -2], [6, True, 7]), ('regression: visual slot lookup', [[0, 0, 0, 2, 2, 3, 3, 3, 3, 1], 20], [5, False, 5]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('control layout', [[1], 0], [0, True, 1]), ('control layout', [[2, 2, 2], 3], [1, True, 2])]]
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
click left of RTL line[0, True, 1][2, True, 3]Failed
regression: visual slot lookup[4, True, 5][2, False, 2]Failed
regression: visual slot lookup[0, False, 0][5, False, 5]Failed
partial-repair probe[0, False, 0][0, False, 0]Passed
click past end[2, False, 2][1, False, 1]Failed
right half of RTL char[0, False, 0][1, False, 1]Failed
control layout[0, False, 0][0, False, 0]Passed
control layout[4, True, 5][4, True, 5]Passed

SHA-256 / fac5fdf7c5b358961ddccdfa6c5c4c8ff3b97c9854cae4f4cf639d42726bc498

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, px = x
    n = len(levels)
    if n == 0:
        return [None, False, 0]
    vis = reorder(levels)
    v = min(max(px // 2, 0), n - 1)
    i = vis[n - 1 - v]
    right_half = px - 2 * v >= 1
    rtl = levels[i] % 2 == 1
    trailing = right_half != rtl
    return [i, trailing, i + 1 if trailing else i]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('click left of RTL line', [[1, 1, 1], -1], [2, True, 3]), ('regression: visual slot lookup', [[2, 2, 2, 1, 1], 8], [2, False, 2]), ('regression: visual slot lookup', [[1, 1, 1, 1, 3, 3, 0, 1, 2, 2], 1], [5, False, 5]), ('partial-repair probe', [[0, 0, 0, 0], -1], [0, False, 0]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('control layout', [[1], 4], [0, False, 0]), ('control layout', [[2, 2, 2, 2, 2, 4, 2, 2, 2], 9], [4, True, 5])], [('regression: visual slot lookup', [[1, 1, 1, 3], 10], [0, False, 0]), ('regression: visual slot lookup', [[1, 1, 1, 1, 1, 1], 9], [1, False, 1]), ('regression: visual slot lookup', [[1, 1, 1, 0, 0, 1, 1], -3], [2, True, 3]), ('regression: visual slot lookup', [[1, 1, 2, 2, 2, 3, 3], 16], [0, False, 0]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('control layout', [[1], 4], [0, False, 0]), ('control layout', [[4, 4, 4, 1, 4, 4, 4], 6], [3, True, 4])], [('regression: visual slot lookup', [[3, 3, 3, 3, 3, 1, 2, 2, 2, 2], 11], [4, False, 4]), ('regression: visual slot lookup', [[1, 2], 7], [0, False, 0]), ('regression: visual slot lookup', [[4, 4, 4, 4, 1, 1], 11], [3, True, 4]), ('regression: visual slot lookup', [[2, 2, 2, 1, 1, 1, 2], 0], [6, False, 6]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('click left of RTL line', [[1, 1, 1], -1], [2, True, 3]), ('control layout', [[2], 4], [0, True, 1]), ('control layout', [[1], 3], [0, False, 0])], [('regression: visual slot lookup', [[1, 3, 3, 3, 3, 1, 1, 1], 9], [3, False, 3]), ('regression: visual slot lookup', [[1, 1, 1, 0, 0, 0, 3], -1], [2, True, 3]), ('partial-repair probe', [[1, 0, 0, 0, 0], -1], [0, True, 1]), ('regression: visual slot lookup', [[1, 1, 1, 1, 1, 1, 1, 1, 3], 17], [0, False, 0]), ('click left of RTL line', [[1, 1, 1], -1], [2, True, 3]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('control layout', [[1], 3], [0, False, 0]), ('control layout', [[1], -2], [0, True, 1])], [('regression: visual slot lookup', [[3, 3, 0, 0, 0], -2], [1, True, 2]), ('regression: visual slot lookup', [[1, 1, 1, 3, 3], 13], [0, False, 0]), ('regression: visual slot lookup', [[3, 3, 3, 3, 1, 1, 1], -2], [6, True, 7]), ('regression: visual slot lookup', [[0, 0, 0, 2, 2, 3, 3, 3, 3, 1], 20], [5, False, 5]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('control layout', [[1], 0], [0, True, 1]), ('control layout', [[2, 2, 2], 3], [1, True, 2])]]
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
click left of RTL line[0, True, 1][2, True, 3]Failed
regression: visual slot lookup[4, True, 5][2, False, 2]Failed
regression: visual slot lookup[7, False, 7][5, False, 5]Failed
partial-repair probe[3, False, 3][0, False, 0]Failed
click past end[0, True, 1][1, False, 1]Failed
right half of RTL char[0, False, 0][1, False, 1]Failed
control layout[0, False, 0][0, False, 0]Passed
control layout[4, True, 5][4, True, 5]Passed

SHA-256 / 1ae877f596255b6be4a04c0629543a7c808a708245d35bb6e4477e5979424865

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, px = x
    n = len(levels)
    if n == 0:
        return [None, False, 0]
    vis = reorder(levels)
    v = min(max(px // 2, 0), n - 1)
    i = vis[v]
    right_half = px - 2 * v >= 1
    rtl = levels[i] % 2 == 1
    trailing = right_half != rtl
    return [i, trailing, i + 1 if trailing else i]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('click left of RTL line', [[1, 1, 1], -1], [2, True, 3]), ('regression: visual slot lookup', [[2, 2, 2, 1, 1], 8], [2, False, 2]), ('regression: visual slot lookup', [[1, 1, 1, 1, 3, 3, 0, 1, 2, 2], 1], [5, False, 5]), ('partial-repair probe', [[0, 0, 0, 0], -1], [0, False, 0]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('control layout', [[1], 4], [0, False, 0]), ('control layout', [[2, 2, 2, 2, 2, 4, 2, 2, 2], 9], [4, True, 5])], [('regression: visual slot lookup', [[1, 1, 1, 3], 10], [0, False, 0]), ('regression: visual slot lookup', [[1, 1, 1, 1, 1, 1], 9], [1, False, 1]), ('regression: visual slot lookup', [[1, 1, 1, 0, 0, 1, 1], -3], [2, True, 3]), ('regression: visual slot lookup', [[1, 1, 2, 2, 2, 3, 3], 16], [0, False, 0]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('control layout', [[1], 4], [0, False, 0]), ('control layout', [[4, 4, 4, 1, 4, 4, 4], 6], [3, True, 4])], [('regression: visual slot lookup', [[3, 3, 3, 3, 3, 1, 2, 2, 2, 2], 11], [4, False, 4]), ('regression: visual slot lookup', [[1, 2], 7], [0, False, 0]), ('regression: visual slot lookup', [[4, 4, 4, 4, 1, 1], 11], [3, True, 4]), ('regression: visual slot lookup', [[2, 2, 2, 1, 1, 1, 2], 0], [6, False, 6]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('click left of RTL line', [[1, 1, 1], -1], [2, True, 3]), ('control layout', [[2], 4], [0, True, 1]), ('control layout', [[1], 3], [0, False, 0])], [('regression: visual slot lookup', [[1, 3, 3, 3, 3, 1, 1, 1], 9], [3, False, 3]), ('regression: visual slot lookup', [[1, 1, 1, 0, 0, 0, 3], -1], [2, True, 3]), ('partial-repair probe', [[1, 0, 0, 0, 0], -1], [0, True, 1]), ('regression: visual slot lookup', [[1, 1, 1, 1, 1, 1, 1, 1, 3], 17], [0, False, 0]), ('click left of RTL line', [[1, 1, 1], -1], [2, True, 3]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('control layout', [[1], 3], [0, False, 0]), ('control layout', [[1], -2], [0, True, 1])], [('regression: visual slot lookup', [[3, 3, 0, 0, 0], -2], [1, True, 2]), ('regression: visual slot lookup', [[1, 1, 1, 3, 3], 13], [0, False, 0]), ('regression: visual slot lookup', [[3, 3, 3, 3, 1, 1, 1], -2], [6, True, 7]), ('regression: visual slot lookup', [[0, 0, 0, 2, 2, 3, 3, 3, 3, 1], 20], [5, False, 5]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('control layout', [[1], 0], [0, True, 1]), ('control layout', [[2, 2, 2], 3], [1, True, 2])]]
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
click left of RTL line[2, True, 3][2, True, 3]Passed
regression: visual slot lookup[2, False, 2][2, False, 2]Passed
regression: visual slot lookup[5, False, 5][5, False, 5]Passed
partial-repair probe[0, False, 0][0, False, 0]Passed
click past end[1, False, 1][1, False, 1]Passed
right half of RTL char[1, False, 1][1, False, 1]Passed
control layout[0, False, 0][0, False, 0]Passed
control layout[4, True, 5][4, True, 5]Passed

SHA-256 / 049a09e237a8c71b67dace9b397a4b5555dea1f79aeccde054e28e9c8d326785

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

Case digest / 1dde73fb9f02fde11da75d7caabed2d729edf35f0985024d75761090aadd7fe9