FA-80701 / Bidirectional text layout / Open access
Bidi hit testing: half boundary · case 01
Clicks in the right half are treated as left half.
ROOT CAUSE
The right-half test requires more than one unit into the slot.
VERIFIED REPAIR
The right half starts one unit into the slot.
Unsuccessful approach: Using the parity of x misclassifies clicks outside the line.
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 != 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 = [[('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('regression: half boundary', [[3, 3, 3, 3, 1, 1, 1, 1, 1], 15], [1, False, 1]), ('partial-repair probe', [[4, 4, 4, 4, 1, 1, 1, 1], 16], [3, True, 4]), ('partial-repair probe', [[1, 3, 3, 3, 3, 1, 3], 14], [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', [[0, 0, 3, 1, 1, 1, 1, 3], 14], [2, True, 3]), ('control layout', [[1, 1], 2], [0, True, 1])], [('regression: half boundary', [[2, 2, 1, 1, 2, 2, 2, 2, 2, 2], 1], [4, True, 5]), ('regression: half boundary', [[3, 3, 3, 1, 1, 1], 3], [4, False, 4]), ('partial-repair probe', [[1, 1, 1, 1, 2, 2, 2], -3], [4, False, 4]), ('partial-repair probe', [[4, 4, 4, 4, 4, 4], 14], [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', [[2, 0, 0, 0], 9], [3, True, 4]), ('control layout', [[2, 2], 2], [1, False, 1])], [('regression: half boundary', [[0, 0, 0, 0, 3, 3, 3, 1, 3], 13], [6, False, 6]), ('regression: half boundary', [[3, 3, 3], 1], [2, False, 2]), ('partial-repair probe', [[1, 1], -1], [1, True, 2]), ('partial-repair probe', [[4, 4, 4, 2, 2, 2], 12], [5, True, 6]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('control layout', [[2, 2, 2, 2, 1, 1, 1, 2, 3], 2], [8, True, 9]), ('control layout', [[2, 2, 1, 1, 1, 2], 15], [1, True, 2])], [('regression: half boundary', [[2, 2, 2, 2, 2], 3], [1, True, 2]), ('regression: half boundary', [[1, 0, 0, 0, 0], 3], [1, True, 2]), ('partial-repair probe', [[1, 1, 1], -1], [2, True, 3]), ('partial-repair probe', [[1, 1, 3, 3, 3, 3, 3, 3, 3], 18], [0, False, 0]), ('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], 3], [0, False, 0]), ('control layout', [[2, 2, 2, 2], -2], [0, False, 0])], [('regression: half boundary', [[4, 4, 4, 1, 1, 1], 3], [4, False, 4]), ('regression: half boundary', [[0, 0, 0, 0, 1, 1, 1, 1, 0, 0], 13], [5, False, 5]), ('partial-repair probe', [[4], 4], [0, True, 1]), ('partial-repair probe', [[0, 0, 1, 1, 1, 1, 1], -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, 1, 1, 1, 1, 1], 6], [2, True, 3]), ('control layout', [[3, 3, 3, 3, 3, 3, 3], 6], [3, True, 4])]]
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 |
|---|---|---|---|
| right half of RTL char | [1, True, 2] | [1, False, 1] | Failed |
| regression: half boundary | [1, True, 2] | [1, False, 1] | Failed |
| partial-repair probe | [3, True, 4] | [3, True, 4] | Passed |
| partial-repair probe | [0, False, 0] | [0, False, 0] | Passed |
| click left of RTL line | [2, True, 3] | [2, True, 3] | Passed |
| click past end | [1, False, 1] | [1, False, 1] | Passed |
| control layout | [2, True, 3] | [2, True, 3] | Passed |
| control layout | [0, True, 1] | [0, True, 1] | Passed |
SHA-256 / 33329e8bfd52af149274c662f6db34080828ec61c0f1b7aab096769296f84103
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 == 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 = [[('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('regression: half boundary', [[3, 3, 3, 3, 1, 1, 1, 1, 1], 15], [1, False, 1]), ('partial-repair probe', [[4, 4, 4, 4, 1, 1, 1, 1], 16], [3, True, 4]), ('partial-repair probe', [[1, 3, 3, 3, 3, 1, 3], 14], [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', [[0, 0, 3, 1, 1, 1, 1, 3], 14], [2, True, 3]), ('control layout', [[1, 1], 2], [0, True, 1])], [('regression: half boundary', [[2, 2, 1, 1, 2, 2, 2, 2, 2, 2], 1], [4, True, 5]), ('regression: half boundary', [[3, 3, 3, 1, 1, 1], 3], [4, False, 4]), ('partial-repair probe', [[1, 1, 1, 1, 2, 2, 2], -3], [4, False, 4]), ('partial-repair probe', [[4, 4, 4, 4, 4, 4], 14], [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', [[2, 0, 0, 0], 9], [3, True, 4]), ('control layout', [[2, 2], 2], [1, False, 1])], [('regression: half boundary', [[0, 0, 0, 0, 3, 3, 3, 1, 3], 13], [6, False, 6]), ('regression: half boundary', [[3, 3, 3], 1], [2, False, 2]), ('partial-repair probe', [[1, 1], -1], [1, True, 2]), ('partial-repair probe', [[4, 4, 4, 2, 2, 2], 12], [5, True, 6]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('control layout', [[2, 2, 2, 2, 1, 1, 1, 2, 3], 2], [8, True, 9]), ('control layout', [[2, 2, 1, 1, 1, 2], 15], [1, True, 2])], [('regression: half boundary', [[2, 2, 2, 2, 2], 3], [1, True, 2]), ('regression: half boundary', [[1, 0, 0, 0, 0], 3], [1, True, 2]), ('partial-repair probe', [[1, 1, 1], -1], [2, True, 3]), ('partial-repair probe', [[1, 1, 3, 3, 3, 3, 3, 3, 3], 18], [0, False, 0]), ('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], 3], [0, False, 0]), ('control layout', [[2, 2, 2, 2], -2], [0, False, 0])], [('regression: half boundary', [[4, 4, 4, 1, 1, 1], 3], [4, False, 4]), ('regression: half boundary', [[0, 0, 0, 0, 1, 1, 1, 1, 0, 0], 13], [5, False, 5]), ('partial-repair probe', [[4], 4], [0, True, 1]), ('partial-repair probe', [[0, 0, 1, 1, 1, 1, 1], -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, 1, 1, 1, 1, 1], 6], [2, True, 3]), ('control layout', [[3, 3, 3, 3, 3, 3, 3], 6], [3, True, 4])]]
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 |
|---|---|---|---|
| right half of RTL char | [1, False, 1] | [1, False, 1] | Passed |
| regression: half boundary | [1, False, 1] | [1, False, 1] | Passed |
| partial-repair probe | [3, False, 3] | [3, True, 4] | Failed |
| partial-repair probe | [0, True, 1] | [0, False, 0] | Failed |
| click left of RTL line | [2, False, 2] | [2, True, 3] | Failed |
| click past end | [1, False, 1] | [1, False, 1] | Passed |
| control layout | [2, True, 3] | [2, True, 3] | Passed |
| control layout | [0, True, 1] | [0, True, 1] | Passed |
SHA-256 / 9ef0248b93ac46fcb7dfe5582cec74b11ed60b8a4b8322a387864b5930abe17a
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 = [[('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('regression: half boundary', [[3, 3, 3, 3, 1, 1, 1, 1, 1], 15], [1, False, 1]), ('partial-repair probe', [[4, 4, 4, 4, 1, 1, 1, 1], 16], [3, True, 4]), ('partial-repair probe', [[1, 3, 3, 3, 3, 1, 3], 14], [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', [[0, 0, 3, 1, 1, 1, 1, 3], 14], [2, True, 3]), ('control layout', [[1, 1], 2], [0, True, 1])], [('regression: half boundary', [[2, 2, 1, 1, 2, 2, 2, 2, 2, 2], 1], [4, True, 5]), ('regression: half boundary', [[3, 3, 3, 1, 1, 1], 3], [4, False, 4]), ('partial-repair probe', [[1, 1, 1, 1, 2, 2, 2], -3], [4, False, 4]), ('partial-repair probe', [[4, 4, 4, 4, 4, 4], 14], [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', [[2, 0, 0, 0], 9], [3, True, 4]), ('control layout', [[2, 2], 2], [1, False, 1])], [('regression: half boundary', [[0, 0, 0, 0, 3, 3, 3, 1, 3], 13], [6, False, 6]), ('regression: half boundary', [[3, 3, 3], 1], [2, False, 2]), ('partial-repair probe', [[1, 1], -1], [1, True, 2]), ('partial-repair probe', [[4, 4, 4, 2, 2, 2], 12], [5, True, 6]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('control layout', [[2, 2, 2, 2, 1, 1, 1, 2, 3], 2], [8, True, 9]), ('control layout', [[2, 2, 1, 1, 1, 2], 15], [1, True, 2])], [('regression: half boundary', [[2, 2, 2, 2, 2], 3], [1, True, 2]), ('regression: half boundary', [[1, 0, 0, 0, 0], 3], [1, True, 2]), ('partial-repair probe', [[1, 1, 1], -1], [2, True, 3]), ('partial-repair probe', [[1, 1, 3, 3, 3, 3, 3, 3, 3], 18], [0, False, 0]), ('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], 3], [0, False, 0]), ('control layout', [[2, 2, 2, 2], -2], [0, False, 0])], [('regression: half boundary', [[4, 4, 4, 1, 1, 1], 3], [4, False, 4]), ('regression: half boundary', [[0, 0, 0, 0, 1, 1, 1, 1, 0, 0], 13], [5, False, 5]), ('partial-repair probe', [[4], 4], [0, True, 1]), ('partial-repair probe', [[0, 0, 1, 1, 1, 1, 1], -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, 1, 1, 1, 1, 1], 6], [2, True, 3]), ('control layout', [[3, 3, 3, 3, 3, 3, 3], 6], [3, True, 4])]]
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 |
|---|---|---|---|
| right half of RTL char | [1, False, 1] | [1, False, 1] | Passed |
| regression: half boundary | [1, False, 1] | [1, False, 1] | Passed |
| partial-repair probe | [3, True, 4] | [3, True, 4] | Passed |
| partial-repair probe | [0, False, 0] | [0, False, 0] | Passed |
| click left of RTL line | [2, True, 3] | [2, True, 3] | Passed |
| click past end | [1, False, 1] | [1, False, 1] | Passed |
| control layout | [2, True, 3] | [2, True, 3] | Passed |
| control layout | [0, True, 1] | [0, True, 1] | Passed |
SHA-256 / 49588ba90853d2ebfe47042a2ee8cb4e6a8d801640bdd5b6db46d212aa42dab2
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.158505+00:00.
Case digest / 72045c549a6a7d66fc8f6153125c46596d3217df60d1186859ee78edd909fe37