FAILURE MAP
← Case archive

FA-80661 / Bidirectional text layout / Open access

Bidi selection highlight: selection end exclusivity · case 01

Highlights include one character past the selection.

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

ROOT CAUSE

The selected range includes the focus index.

THE FAILURE

The selected range includes the focus index.

Unsuccessful approach: Shifting both ends drops the first selected character.

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, min(b + 1, len(levels))))
    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 = [[('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('regression: selection end exclusivity', [[3, 1, 1, 1, 1, 1, 1, 1, 1, 1], 1, 5], [[5, 9]]), ('regression: selection end exclusivity', [[3, 3, 1, 1, 1, 3, 3, 3, 3, 1, 1], 0, 8], [[3, 11]]), ('regression: selection end exclusivity', [[1, 1], 0, 1], [[1, 2]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('control layout', [[3, 3, 3, 3, 3, 1], 6, 6], []), ('control layout', [[1], 1, 1], []), ('control layout', [[3], 1, 1], [])], [('regression: selection end exclusivity', [[1, 1, 0, 0, 0, 0], 2, 2], []), ('regression: selection end exclusivity', [[3, 3, 3, 3, 3], 0, 3], [[2, 5]]), ('partial-repair probe', [[3, 3, 3, 0], 4, 3], [[3, 4]]), ('regression: selection end exclusivity', [[3, 3, 3, 0, 3, 3, 3, 1, 1, 1], 4, 1], [[0, 2], [3, 4]]), ('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, 1], 2, 2], []), ('control layout', [[2, 2], 2, 2], [])], [('regression: selection end exclusivity', [[1, 1, 1, 1], 2, 0], [[2, 4]]), ('regression: selection end exclusivity', [[3, 3], 1, 1], []), ('regression: selection end exclusivity', [[2, 2, 2, 2, 2, 2, 2, 2], 3, 5], [[3, 5]]), ('regression: selection end exclusivity', [[0, 0, 0, 3, 3, 0, 0, 3, 3, 3, 0], 3, 9], [[3, 7], [8, 10]]), ('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], 1, 1], []), ('control layout', [[0, 0, 0], 3, 3], [])], [('regression: selection end exclusivity', [[1, 1, 1, 0], 3, 1], [[0, 2]]), ('regression: selection end exclusivity', [[4, 1, 1, 1, 1], 3, 3], []), ('regression: selection end exclusivity', [[0, 0, 0, 0, 2, 2, 2, 2, 1], 2, 6], [[2, 4], [5, 7]]), ('regression: selection end exclusivity', [[1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0], 8, 10], [[8, 10]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('control layout', [[1, 1], 2, 2], []), ('control layout', [[2, 2], 2, 2], [])], [('regression: selection end exclusivity', [[1, 1, 1], 0, 0], []), ('regression: selection end exclusivity', [[0, 3, 0, 1], 0, 2], [[0, 2]]), ('regression: selection end exclusivity', [[0, 1, 1, 1, 1, 0, 0, 0], 6, 3], [[1, 3], [5, 6]]), ('regression: selection end exclusivity', [[3, 3, 1, 1, 1, 1, 0, 0], 6, 7], [[6, 7]]), ('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, 3, 3, 3, 0, 0, 3, 3], 8, 8], []), ('control layout', [[1], 1, 1], [])]]
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
selection crossing direction change[[1, 5]][[1, 4]]Failed
regression: selection end exclusivity[[4, 9]][[5, 9]]Failed
regression: selection end exclusivity[[2, 11]][[3, 11]]Failed
regression: selection end exclusivity[[0, 2]][[1, 2]]Failed
backward selection[[0, 2]][[0, 2]]Passed
control layout[][]Passed
control layout[][]Passed
control layout[][]Passed

SHA-256 / 982d7af9f1d1e8e76d1f02d0a7f132f60d101524ddbc9caacf729ac90a23f98a

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 + 1, min(b + 1, len(levels))))
    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 = [[('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('regression: selection end exclusivity', [[3, 1, 1, 1, 1, 1, 1, 1, 1, 1], 1, 5], [[5, 9]]), ('regression: selection end exclusivity', [[3, 3, 1, 1, 1, 3, 3, 3, 3, 1, 1], 0, 8], [[3, 11]]), ('regression: selection end exclusivity', [[1, 1], 0, 1], [[1, 2]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('control layout', [[3, 3, 3, 3, 3, 1], 6, 6], []), ('control layout', [[1], 1, 1], []), ('control layout', [[3], 1, 1], [])], [('regression: selection end exclusivity', [[1, 1, 0, 0, 0, 0], 2, 2], []), ('regression: selection end exclusivity', [[3, 3, 3, 3, 3], 0, 3], [[2, 5]]), ('partial-repair probe', [[3, 3, 3, 0], 4, 3], [[3, 4]]), ('regression: selection end exclusivity', [[3, 3, 3, 0, 3, 3, 3, 1, 1, 1], 4, 1], [[0, 2], [3, 4]]), ('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, 1], 2, 2], []), ('control layout', [[2, 2], 2, 2], [])], [('regression: selection end exclusivity', [[1, 1, 1, 1], 2, 0], [[2, 4]]), ('regression: selection end exclusivity', [[3, 3], 1, 1], []), ('regression: selection end exclusivity', [[2, 2, 2, 2, 2, 2, 2, 2], 3, 5], [[3, 5]]), ('regression: selection end exclusivity', [[0, 0, 0, 3, 3, 0, 0, 3, 3, 3, 0], 3, 9], [[3, 7], [8, 10]]), ('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], 1, 1], []), ('control layout', [[0, 0, 0], 3, 3], [])], [('regression: selection end exclusivity', [[1, 1, 1, 0], 3, 1], [[0, 2]]), ('regression: selection end exclusivity', [[4, 1, 1, 1, 1], 3, 3], []), ('regression: selection end exclusivity', [[0, 0, 0, 0, 2, 2, 2, 2, 1], 2, 6], [[2, 4], [5, 7]]), ('regression: selection end exclusivity', [[1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0], 8, 10], [[8, 10]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('control layout', [[1, 1], 2, 2], []), ('control layout', [[2, 2], 2, 2], [])], [('regression: selection end exclusivity', [[1, 1, 1], 0, 0], []), ('regression: selection end exclusivity', [[0, 3, 0, 1], 0, 2], [[0, 2]]), ('regression: selection end exclusivity', [[0, 1, 1, 1, 1, 0, 0, 0], 6, 3], [[1, 3], [5, 6]]), ('regression: selection end exclusivity', [[3, 3, 1, 1, 1, 1, 0, 0], 6, 7], [[6, 7]]), ('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, 3, 3, 3, 0, 0, 3, 3], 8, 8], []), ('control layout', [[1], 1, 1], [])]]
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
selection crossing direction change[[2, 5]][[1, 4]]Failed
regression: selection end exclusivity[[4, 8]][[5, 9]]Failed
regression: selection end exclusivity[[2, 10]][[3, 11]]Failed
regression: selection end exclusivity[[0, 1]][[1, 2]]Failed
backward selection[[0, 1]][[0, 2]]Failed
control layout[][]Passed
control layout[][]Passed
control layout[][]Passed

SHA-256 / 625a46c7e49e30a8c80c005ddd713dc75afedd1fc88c6ec13ef969a3e332cb8d

HELD IN THE MEMBER ARCHIVE

The verified repair and its recorded checks are member-only.

This mechanism has 8 recorded checks per implementation. The open-access tier publishes the failure and the unsuccessful fix; the repaired source that passes every check, and the observations that prove it, are available to members.

Every case sharing this mechanism uses the same contract and the same repair, so this one record is held back for all of them.

Member access is invitation-based. Sign in with your invited account to inspect the repair.

Sign in to the archive ↗

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

Case digest / dc49cdb5bf6c185a65d5cc96e5f40ec5b6310ec1feac612d34fa350bf7c2efdb