FA-80691 / Bidirectional text layout / Open access
Bidi hit testing: trailing side for RTL · case 01
Clicking the right half of an RTL character places the caret after it logically.
ROOT CAUSE
The trailing flag ignores the character direction.
VERIFIED REPAIR
Flip the half-to-edge mapping for RTL characters.
Unsuccessful approach: Clearing trailing for all RTL characters is also wrong.
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 = vis[v]
right_half = px - 2 * v >= 1
rtl = levels[i] % 2 == 1
trailing = right_half
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: trailing side for RTL', [[1, 1, 1, 1, 1, 1, 0, 0, 3], 6], [2, True, 3]), ('regression: trailing side for RTL', [[3, 3, 3, 2, 2, 2, 2, 0, 0], 0], [2, True, 3]), ('regression: trailing side for RTL', [[1, 1, 1, 1, 4, 4, 4, 4, 3], -3], [8, True, 9]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('control layout', [[2, 2, 3, 3, 1, 1, 1], 8], [1, False, 1]), ('control layout', [[0], 1], [0, True, 1])], [('regression: trailing side for RTL', [[1, 1, 1, 3, 3, 3, 3, 2, 3], 11], [8, False, 8]), ('regression: trailing side for RTL', [[0, 0, 2, 3, 3, 3, 3, 3], 19], [3, False, 3]), ('regression: trailing side for RTL', [[3, 3, 3, 3, 4, 4, 4, 1], 8], [3, True, 4]), ('regression: trailing side for RTL', [[2, 2, 2, 3, 3, 3], 6], [5, True, 6]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('control layout', [[0, 0, 0, 0, 2, 2], 15], [5, True, 6]), ('control layout', [[1, 1, 0], 7], [2, True, 3])], [('regression: trailing side for RTL', [[1, 1, 2, 3], 2], [3, True, 4]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('regression: trailing side for RTL', [[1, 1, 1, 0, 3, 3, 3, 3, 0, 0], 14], [4, True, 5]), ('regression: trailing side for RTL', [[1, 1, 1, 1], -1], [3, True, 4]), ('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, 2, 2, 1, 1, 3, 1], 11], [1, True, 2]), ('control layout', [[0, 0, 0, 1], 0], [0, False, 0])], [('regression: trailing side for RTL', [[3, 3, 3, 3, 3, 3, 2, 2, 2, 2], 1], [5, False, 5]), ('regression: trailing side for RTL', [[2, 2, 2, 2, 2, 2, 3, 3], 17], [6, False, 6]), ('regression: trailing side for RTL', [[3, 3, 3, 3, 3, 3, 3], 6], [3, True, 4]), ('regression: trailing side for RTL', [[1, 1], -1], [1, True, 2]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('click left of RTL line', [[1, 1, 1], -1], [2, True, 3]), ('control layout', [[1, 2, 2], 1], [1, True, 2]), ('control layout', [[4, 4], -2], [0, False, 0])], [('regression: trailing side for RTL', [[2, 2, 2, 1, 1], -3], [4, True, 5]), ('regression: trailing side for RTL', [[3, 3, 3, 3, 2, 2, 2, 2, 1, 1], 4], [3, True, 4]), ('regression: trailing side for RTL', [[1, 0, 3, 3, 3, 3, 3, 3, 3], -2], [0, True, 1]), ('regression: trailing side for RTL', [[1, 1], 0], [1, True, 2]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('control layout', [[4], 4], [0, True, 1]), ('control layout', [[2, 2, 2, 2, 2, 2, 2, 1, 1, 1], 16], [5, False, 5])]]
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 |
|---|---|---|---|
| click left of RTL line | [2, False, 2] | [2, True, 3] | Failed |
| regression: trailing side for RTL | [2, False, 2] | [2, True, 3] | Failed |
| regression: trailing side for RTL | [2, False, 2] | [2, True, 3] | Failed |
| regression: trailing side for RTL | [8, False, 8] | [8, True, 9] | Failed |
| right half of RTL char | [1, True, 2] | [1, False, 1] | Failed |
| click past end | [1, True, 2] | [1, False, 1] | Failed |
| control layout | [1, False, 1] | [1, False, 1] | Passed |
| control layout | [0, True, 1] | [0, True, 1] | Passed |
SHA-256 / d08fc0c799ea01260b46713b6ed0aaa734e1fb27a13cadfe76281c6c2199b8e6
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[v]
right_half = px - 2 * v >= 1
rtl = levels[i] % 2 == 1
trailing = right_half and not 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: trailing side for RTL', [[1, 1, 1, 1, 1, 1, 0, 0, 3], 6], [2, True, 3]), ('regression: trailing side for RTL', [[3, 3, 3, 2, 2, 2, 2, 0, 0], 0], [2, True, 3]), ('regression: trailing side for RTL', [[1, 1, 1, 1, 4, 4, 4, 4, 3], -3], [8, True, 9]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('control layout', [[2, 2, 3, 3, 1, 1, 1], 8], [1, False, 1]), ('control layout', [[0], 1], [0, True, 1])], [('regression: trailing side for RTL', [[1, 1, 1, 3, 3, 3, 3, 2, 3], 11], [8, False, 8]), ('regression: trailing side for RTL', [[0, 0, 2, 3, 3, 3, 3, 3], 19], [3, False, 3]), ('regression: trailing side for RTL', [[3, 3, 3, 3, 4, 4, 4, 1], 8], [3, True, 4]), ('regression: trailing side for RTL', [[2, 2, 2, 3, 3, 3], 6], [5, True, 6]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('control layout', [[0, 0, 0, 0, 2, 2], 15], [5, True, 6]), ('control layout', [[1, 1, 0], 7], [2, True, 3])], [('regression: trailing side for RTL', [[1, 1, 2, 3], 2], [3, True, 4]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('regression: trailing side for RTL', [[1, 1, 1, 0, 3, 3, 3, 3, 0, 0], 14], [4, True, 5]), ('regression: trailing side for RTL', [[1, 1, 1, 1], -1], [3, True, 4]), ('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, 2, 2, 1, 1, 3, 1], 11], [1, True, 2]), ('control layout', [[0, 0, 0, 1], 0], [0, False, 0])], [('regression: trailing side for RTL', [[3, 3, 3, 3, 3, 3, 2, 2, 2, 2], 1], [5, False, 5]), ('regression: trailing side for RTL', [[2, 2, 2, 2, 2, 2, 3, 3], 17], [6, False, 6]), ('regression: trailing side for RTL', [[3, 3, 3, 3, 3, 3, 3], 6], [3, True, 4]), ('regression: trailing side for RTL', [[1, 1], -1], [1, True, 2]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('click left of RTL line', [[1, 1, 1], -1], [2, True, 3]), ('control layout', [[1, 2, 2], 1], [1, True, 2]), ('control layout', [[4, 4], -2], [0, False, 0])], [('regression: trailing side for RTL', [[2, 2, 2, 1, 1], -3], [4, True, 5]), ('regression: trailing side for RTL', [[3, 3, 3, 3, 2, 2, 2, 2, 1, 1], 4], [3, True, 4]), ('regression: trailing side for RTL', [[1, 0, 3, 3, 3, 3, 3, 3, 3], -2], [0, True, 1]), ('regression: trailing side for RTL', [[1, 1], 0], [1, True, 2]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('control layout', [[4], 4], [0, True, 1]), ('control layout', [[2, 2, 2, 2, 2, 2, 2, 1, 1, 1], 16], [5, False, 5])]]
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 |
|---|---|---|---|
| click left of RTL line | [2, False, 2] | [2, True, 3] | Failed |
| regression: trailing side for RTL | [2, False, 2] | [2, True, 3] | Failed |
| regression: trailing side for RTL | [2, False, 2] | [2, True, 3] | Failed |
| regression: trailing side for RTL | [8, False, 8] | [8, True, 9] | Failed |
| right half of RTL char | [1, False, 1] | [1, False, 1] | Passed |
| click past end | [1, False, 1] | [1, False, 1] | Passed |
| control layout | [1, False, 1] | [1, False, 1] | Passed |
| control layout | [0, True, 1] | [0, True, 1] | Passed |
SHA-256 / 38f6fb7c2e5dd03cabecd2da2c3755493e82c534b329720b08af13d490a65456
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: trailing side for RTL', [[1, 1, 1, 1, 1, 1, 0, 0, 3], 6], [2, True, 3]), ('regression: trailing side for RTL', [[3, 3, 3, 2, 2, 2, 2, 0, 0], 0], [2, True, 3]), ('regression: trailing side for RTL', [[1, 1, 1, 1, 4, 4, 4, 4, 3], -3], [8, True, 9]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('control layout', [[2, 2, 3, 3, 1, 1, 1], 8], [1, False, 1]), ('control layout', [[0], 1], [0, True, 1])], [('regression: trailing side for RTL', [[1, 1, 1, 3, 3, 3, 3, 2, 3], 11], [8, False, 8]), ('regression: trailing side for RTL', [[0, 0, 2, 3, 3, 3, 3, 3], 19], [3, False, 3]), ('regression: trailing side for RTL', [[3, 3, 3, 3, 4, 4, 4, 1], 8], [3, True, 4]), ('regression: trailing side for RTL', [[2, 2, 2, 3, 3, 3], 6], [5, True, 6]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('control layout', [[0, 0, 0, 0, 2, 2], 15], [5, True, 6]), ('control layout', [[1, 1, 0], 7], [2, True, 3])], [('regression: trailing side for RTL', [[1, 1, 2, 3], 2], [3, True, 4]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('regression: trailing side for RTL', [[1, 1, 1, 0, 3, 3, 3, 3, 0, 0], 14], [4, True, 5]), ('regression: trailing side for RTL', [[1, 1, 1, 1], -1], [3, True, 4]), ('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, 2, 2, 1, 1, 3, 1], 11], [1, True, 2]), ('control layout', [[0, 0, 0, 1], 0], [0, False, 0])], [('regression: trailing side for RTL', [[3, 3, 3, 3, 3, 3, 2, 2, 2, 2], 1], [5, False, 5]), ('regression: trailing side for RTL', [[2, 2, 2, 2, 2, 2, 3, 3], 17], [6, False, 6]), ('regression: trailing side for RTL', [[3, 3, 3, 3, 3, 3, 3], 6], [3, True, 4]), ('regression: trailing side for RTL', [[1, 1], -1], [1, True, 2]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('click left of RTL line', [[1, 1, 1], -1], [2, True, 3]), ('control layout', [[1, 2, 2], 1], [1, True, 2]), ('control layout', [[4, 4], -2], [0, False, 0])], [('regression: trailing side for RTL', [[2, 2, 2, 1, 1], -3], [4, True, 5]), ('regression: trailing side for RTL', [[3, 3, 3, 3, 2, 2, 2, 2, 1, 1], 4], [3, True, 4]), ('regression: trailing side for RTL', [[1, 0, 3, 3, 3, 3, 3, 3, 3], -2], [0, True, 1]), ('regression: trailing side for RTL', [[1, 1], 0], [1, True, 2]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('control layout', [[4], 4], [0, True, 1]), ('control layout', [[2, 2, 2, 2, 2, 2, 2, 1, 1, 1], 16], [5, False, 5])]]
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 |
|---|---|---|---|
| click left of RTL line | [2, True, 3] | [2, True, 3] | Passed |
| regression: trailing side for RTL | [2, True, 3] | [2, True, 3] | Passed |
| regression: trailing side for RTL | [2, True, 3] | [2, True, 3] | Passed |
| regression: trailing side for RTL | [8, True, 9] | [8, True, 9] | Passed |
| right half of RTL char | [1, False, 1] | [1, False, 1] | Passed |
| click past end | [1, False, 1] | [1, False, 1] | Passed |
| control layout | [1, False, 1] | [1, False, 1] | Passed |
| control layout | [0, True, 1] | [0, True, 1] | Passed |
SHA-256 / 690902346e54d7e6219a886a259210e3821de631cbfe1184d0f878a18230b4fd
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.127010+00:00.
Case digest / 810a96e6e02586b8c0058a5d811ce70709849a08516816da1fd6de10197eca3b