{"abstract":"Selections dragged right-to-left highlight nothing.","category":"Bidirectional text layout","checks":8,"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.","evaluation_group":"w2-bidirectional-text-layout-selection-highlight","failed_approach":"Unconditionally swapping breaks forward selections.","family":"w2-bidirectional-text-layout-selection-highlight-backward-selection-normalisation","id":"FA-80676","implementations":{"attempt":{"sha256":"8560b50259d9b444c94db437fcf21d23a9e75f17037a9feeddea185e8b9b6527","source":"\"\"\"Failure Map reference implementation. Python standard library only.\"\"\"\nimport json\n\nN = 1\nobservations = []\ndef solve(x):\n    def reorder(lv):\n        vis = list(range(len(lv)))\n        odd = [l for l in lv if l % 2 == 1]\n        if not odd:\n            return vis\n        for lev in range(max(lv), min(odd) - 1, -1):\n            i = 0\n            while i < len(vis):\n                if lv[vis[i]] >= lev:\n                    j = i\n                    while j < len(vis) and lv[vis[j]] >= lev:\n                        j += 1\n                    vis[i:j] = vis[i:j][::-1]\n                    i = j\n                else:\n                    i += 1\n        return vis\n    \n    levels, a, b = x\n    a, b = b, a\n    vis = reorder(levels)\n    pos = [0] * len(levels)\n    for v, i in enumerate(vis):\n        pos[i] = v\n    sel = sorted(pos[i] for i in range(a, b))\n    rects = []\n    for p in sel:\n        if rects and rects[-1][1] == p:\n            rects[-1][1] = p + 1\n        else:\n            rects.append([p, p + 1])\n    return rects\ndef check(label, actual, expected):\n    observations.append({\"check\": label, \"actual\": actual, \"expected\": expected, \"passed\": actual == expected})\nfixtures = [[('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('regression: backward selection normalisation', [[2, 4, 4, 3, 3], 4, 1], [[2, 5]]), ('partial-repair probe', [[0, 0, 0, 1, 1, 1, 1], 1, 4], [[1, 3], [6, 7]]), ('partial-repair probe', [[1, 1, 1, 1, 1, 1, 4, 2, 2, 2, 2, 1], 4, 9], [[1, 4], [6, 8]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('control layout', [[1, 1], 1, 1], []), ('control layout', [[1, 1, 1], 0, 0], []), ('control layout', [[3], 1, 1], [])], [('regression: backward selection normalisation', [[1, 3, 3], 1, 0], [[2, 3]]), ('regression: backward selection normalisation', [[1, 1, 2, 1, 2, 2, 2, 2, 4, 4], 5, 1], [[0, 1], [6, 9]]), ('partial-repair probe', [[1, 1, 1, 1, 1, 1, 1, 0, 0, 0], 2, 8], [[0, 5], [7, 8]]), ('partial-repair probe', [[0, 2, 2, 0, 0, 0, 0, 2, 2], 0, 4], [[0, 4]]), ('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, 1, 2], 3, 3], []), ('control layout', [[4, 4, 2, 3, 3, 3, 4, 2, 2, 2, 2], 6, 6], [])], [('regression: backward selection normalisation', [[4, 4, 3, 4], 4, 2], [[0, 2]]), ('regression: backward selection normalisation', [[2, 2, 2, 2, 2, 4, 4], 7, 0], [[0, 7]]), ('partial-repair probe', [[1, 1, 1, 4, 4, 3, 3, 3, 2], 3, 7], [[1, 5]]), ('partial-repair probe', [[2, 2, 2, 2, 2, 4, 4, 4, 3, 3, 3], 10, 11], [[5, 6]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('control layout', [[4, 1, 3, 3, 3, 3], 0, 0], []), ('control layout', [[2, 2], 1, 1], [])], [('regression: backward selection normalisation', [[1], 1, 0], [[0, 1]]), ('regression: backward selection normalisation', [[3, 3, 3, 0], 4, 3], [[3, 4]]), ('partial-repair probe', [[2, 4, 4, 4, 4, 2, 2, 1, 1, 1, 4], 5, 11], [[0, 4], [9, 11]]), ('partial-repair probe', [[1, 1, 1, 1, 0, 0, 0], 3, 7], [[0, 1], [4, 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', [[0], 1, 1], []), ('control layout', [[1], 0, 0], [])], [('regression: backward selection normalisation', [[3, 3, 1, 1, 1, 4, 1, 1, 1, 1], 8, 6], [[2, 4]]), ('regression: backward selection normalisation', [[0, 0, 3, 3, 3, 2, 3, 0, 0], 8, 4], [[2, 3], [5, 8]]), ('partial-repair probe', [[0, 0, 0, 0], 0, 4], [[0, 4]]), ('partial-repair probe', [[0, 0, 0, 2, 1, 1, 1, 1, 1, 1, 1], 4, 7], [[7, 10]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('control layout', [[3, 3], 2, 2], []), ('control layout', [[1], 0, 0], [])]]\nfor label, args, expected in fixtures[N - 1]:\n    check(label, solve(args), expected)\nprint(json.dumps({\"observations\": observations, \"passed\": all(x[\"passed\"] for x in observations)}, ensure_ascii=False))\nraise SystemExit(0 if all(x[\"passed\"] for x in observations) else 1)\n"},"broken":{"sha256":"5698fa7906a794730f28cce1f1b3145f7b77ad9237570e0ecf923d54b97978c8","source":"\"\"\"Failure Map reference implementation. Python standard library only.\"\"\"\nimport json\n\nN = 1\nobservations = []\ndef solve(x):\n    def reorder(lv):\n        vis = list(range(len(lv)))\n        odd = [l for l in lv if l % 2 == 1]\n        if not odd:\n            return vis\n        for lev in range(max(lv), min(odd) - 1, -1):\n            i = 0\n            while i < len(vis):\n                if lv[vis[i]] >= lev:\n                    j = i\n                    while j < len(vis) and lv[vis[j]] >= lev:\n                        j += 1\n                    vis[i:j] = vis[i:j][::-1]\n                    i = j\n                else:\n                    i += 1\n        return vis\n    \n    levels, a, b = x\n    a, b = a, b\n    vis = reorder(levels)\n    pos = [0] * len(levels)\n    for v, i in enumerate(vis):\n        pos[i] = v\n    sel = sorted(pos[i] for i in range(a, b))\n    rects = []\n    for p in sel:\n        if rects and rects[-1][1] == p:\n            rects[-1][1] = p + 1\n        else:\n            rects.append([p, p + 1])\n    return rects\ndef check(label, actual, expected):\n    observations.append({\"check\": label, \"actual\": actual, \"expected\": expected, \"passed\": actual == expected})\nfixtures = [[('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('regression: backward selection normalisation', [[2, 4, 4, 3, 3], 4, 1], [[2, 5]]), ('partial-repair probe', [[0, 0, 0, 1, 1, 1, 1], 1, 4], [[1, 3], [6, 7]]), ('partial-repair probe', [[1, 1, 1, 1, 1, 1, 4, 2, 2, 2, 2, 1], 4, 9], [[1, 4], [6, 8]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('control layout', [[1, 1], 1, 1], []), ('control layout', [[1, 1, 1], 0, 0], []), ('control layout', [[3], 1, 1], [])], [('regression: backward selection normalisation', [[1, 3, 3], 1, 0], [[2, 3]]), ('regression: backward selection normalisation', [[1, 1, 2, 1, 2, 2, 2, 2, 4, 4], 5, 1], [[0, 1], [6, 9]]), ('partial-repair probe', [[1, 1, 1, 1, 1, 1, 1, 0, 0, 0], 2, 8], [[0, 5], [7, 8]]), ('partial-repair probe', [[0, 2, 2, 0, 0, 0, 0, 2, 2], 0, 4], [[0, 4]]), ('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, 1, 2], 3, 3], []), ('control layout', [[4, 4, 2, 3, 3, 3, 4, 2, 2, 2, 2], 6, 6], [])], [('regression: backward selection normalisation', [[4, 4, 3, 4], 4, 2], [[0, 2]]), ('regression: backward selection normalisation', [[2, 2, 2, 2, 2, 4, 4], 7, 0], [[0, 7]]), ('partial-repair probe', [[1, 1, 1, 4, 4, 3, 3, 3, 2], 3, 7], [[1, 5]]), ('partial-repair probe', [[2, 2, 2, 2, 2, 4, 4, 4, 3, 3, 3], 10, 11], [[5, 6]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('control layout', [[4, 1, 3, 3, 3, 3], 0, 0], []), ('control layout', [[2, 2], 1, 1], [])], [('regression: backward selection normalisation', [[1], 1, 0], [[0, 1]]), ('regression: backward selection normalisation', [[3, 3, 3, 0], 4, 3], [[3, 4]]), ('partial-repair probe', [[2, 4, 4, 4, 4, 2, 2, 1, 1, 1, 4], 5, 11], [[0, 4], [9, 11]]), ('partial-repair probe', [[1, 1, 1, 1, 0, 0, 0], 3, 7], [[0, 1], [4, 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', [[0], 1, 1], []), ('control layout', [[1], 0, 0], [])], [('regression: backward selection normalisation', [[3, 3, 1, 1, 1, 4, 1, 1, 1, 1], 8, 6], [[2, 4]]), ('regression: backward selection normalisation', [[0, 0, 3, 3, 3, 2, 3, 0, 0], 8, 4], [[2, 3], [5, 8]]), ('partial-repair probe', [[0, 0, 0, 0], 0, 4], [[0, 4]]), ('partial-repair probe', [[0, 0, 0, 2, 1, 1, 1, 1, 1, 1, 1], 4, 7], [[7, 10]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('control layout', [[3, 3], 2, 2], []), ('control layout', [[1], 0, 0], [])]]\nfor label, args, expected in fixtures[N - 1]:\n    check(label, solve(args), expected)\nprint(json.dumps({\"observations\": observations, \"passed\": all(x[\"passed\"] for x in observations)}, ensure_ascii=False))\nraise SystemExit(0 if all(x[\"passed\"] for x in observations) else 1)\n"},"fixed":{"sha256":"e71f1346431705ac362fb7df5bddfb86c771ba88b2cfd99718001622dbb6b6ee","source":"\"\"\"Failure Map reference implementation. Python standard library only.\"\"\"\nimport json\n\nN = 1\nobservations = []\ndef solve(x):\n    def reorder(lv):\n        vis = list(range(len(lv)))\n        odd = [l for l in lv if l % 2 == 1]\n        if not odd:\n            return vis\n        for lev in range(max(lv), min(odd) - 1, -1):\n            i = 0\n            while i < len(vis):\n                if lv[vis[i]] >= lev:\n                    j = i\n                    while j < len(vis) and lv[vis[j]] >= lev:\n                        j += 1\n                    vis[i:j] = vis[i:j][::-1]\n                    i = j\n                else:\n                    i += 1\n        return vis\n    \n    levels, a, b = x\n    a, b = min(a, b), max(a, b)\n    vis = reorder(levels)\n    pos = [0] * len(levels)\n    for v, i in enumerate(vis):\n        pos[i] = v\n    sel = sorted(pos[i] for i in range(a, b))\n    rects = []\n    for p in sel:\n        if rects and rects[-1][1] == p:\n            rects[-1][1] = p + 1\n        else:\n            rects.append([p, p + 1])\n    return rects\ndef check(label, actual, expected):\n    observations.append({\"check\": label, \"actual\": actual, \"expected\": expected, \"passed\": actual == expected})\nfixtures = [[('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('regression: backward selection normalisation', [[2, 4, 4, 3, 3], 4, 1], [[2, 5]]), ('partial-repair probe', [[0, 0, 0, 1, 1, 1, 1], 1, 4], [[1, 3], [6, 7]]), ('partial-repair probe', [[1, 1, 1, 1, 1, 1, 4, 2, 2, 2, 2, 1], 4, 9], [[1, 4], [6, 8]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('control layout', [[1, 1], 1, 1], []), ('control layout', [[1, 1, 1], 0, 0], []), ('control layout', [[3], 1, 1], [])], [('regression: backward selection normalisation', [[1, 3, 3], 1, 0], [[2, 3]]), ('regression: backward selection normalisation', [[1, 1, 2, 1, 2, 2, 2, 2, 4, 4], 5, 1], [[0, 1], [6, 9]]), ('partial-repair probe', [[1, 1, 1, 1, 1, 1, 1, 0, 0, 0], 2, 8], [[0, 5], [7, 8]]), ('partial-repair probe', [[0, 2, 2, 0, 0, 0, 0, 2, 2], 0, 4], [[0, 4]]), ('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, 1, 2], 3, 3], []), ('control layout', [[4, 4, 2, 3, 3, 3, 4, 2, 2, 2, 2], 6, 6], [])], [('regression: backward selection normalisation', [[4, 4, 3, 4], 4, 2], [[0, 2]]), ('regression: backward selection normalisation', [[2, 2, 2, 2, 2, 4, 4], 7, 0], [[0, 7]]), ('partial-repair probe', [[1, 1, 1, 4, 4, 3, 3, 3, 2], 3, 7], [[1, 5]]), ('partial-repair probe', [[2, 2, 2, 2, 2, 4, 4, 4, 3, 3, 3], 10, 11], [[5, 6]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('control layout', [[4, 1, 3, 3, 3, 3], 0, 0], []), ('control layout', [[2, 2], 1, 1], [])], [('regression: backward selection normalisation', [[1], 1, 0], [[0, 1]]), ('regression: backward selection normalisation', [[3, 3, 3, 0], 4, 3], [[3, 4]]), ('partial-repair probe', [[2, 4, 4, 4, 4, 2, 2, 1, 1, 1, 4], 5, 11], [[0, 4], [9, 11]]), ('partial-repair probe', [[1, 1, 1, 1, 0, 0, 0], 3, 7], [[0, 1], [4, 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', [[0], 1, 1], []), ('control layout', [[1], 0, 0], [])], [('regression: backward selection normalisation', [[3, 3, 1, 1, 1, 4, 1, 1, 1, 1], 8, 6], [[2, 4]]), ('regression: backward selection normalisation', [[0, 0, 3, 3, 3, 2, 3, 0, 0], 8, 4], [[2, 3], [5, 8]]), ('partial-repair probe', [[0, 0, 0, 0], 0, 4], [[0, 4]]), ('partial-repair probe', [[0, 0, 0, 2, 1, 1, 1, 1, 1, 1, 1], 4, 7], [[7, 10]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('control layout', [[3, 3], 2, 2], []), ('control layout', [[1], 0, 0], [])]]\nfor label, args, expected in fixtures[N - 1]:\n    check(label, solve(args), expected)\nprint(json.dumps({\"observations\": observations, \"passed\": all(x[\"passed\"] for x in observations)}, ensure_ascii=False))\nraise SystemExit(0 if all(x[\"passed\"] for x in observations) else 1)\n"}},"limitations":"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.","method":"Deterministic executable model with adversarial boundary fixtures.","provenance":{"created_by":"Failure Map","dependencies":"Python standard library","family":"w2-bidirectional-text-layout-selection-highlight-backward-selection-normalisation","generated_at":"2026-09-29T14:49:56.106552+00:00","license":"CC0-1.0","python":"3.12.14","seed":1,"split":"open-access"},"relevance":"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.","repair":"Normalise to the smaller and larger offset.","root_cause":"Anchor and focus are not ordered before building the range.","sha256":"309d48dd8a34047a4c327e175ef30cd0654686dcd51edd4759617c4ab5993771","title":"Bidi selection highlight: backward selection normalisation · case 01","variant":1,"variant_policy":"Five numbered records share a model and may reuse boundary fixtures.","verification":{"attempt":{"elapsed_ms":42.671,"exit_code":1,"observations":[{"actual":[[0,2]],"check":"backward selection","expected":[[0,2]],"passed":true},{"actual":[[2,5]],"check":"regression: backward selection normalisation","expected":[[2,5]],"passed":true},{"actual":[],"check":"partial-repair probe","expected":[[1,3],[6,7]],"passed":false},{"actual":[],"check":"partial-repair probe","expected":[[1,4],[6,8]],"passed":false},{"actual":[],"check":"selection crossing direction change","expected":[[1,4]],"passed":false},{"actual":[],"check":"control layout","expected":[],"passed":true},{"actual":[],"check":"control layout","expected":[],"passed":true},{"actual":[],"check":"control layout","expected":[],"passed":true}],"passed":false,"stderr":"","stdout":"{\"observations\": [{\"check\": \"backward selection\", \"actual\": [[0, 2]], \"expected\": [[0, 2]], \"passed\": true}, {\"check\": \"regression: backward selection normalisation\", \"actual\": [[2, 5]], \"expected\": [[2, 5]], \"passed\": true}, {\"check\": \"partial-repair probe\", \"actual\": [], \"expected\": [[1, 3], [6, 7]], \"passed\": false}, {\"check\": \"partial-repair probe\", \"actual\": [], \"expected\": [[1, 4], [6, 8]], \"passed\": false}, {\"check\": \"selection crossing direction change\", \"actual\": [], \"expected\": [[1, 4]], \"passed\": false}, {\"check\": \"control layout\", \"actual\": [], \"expected\": [], \"passed\": true}, {\"check\": \"control layout\", \"actual\": [], \"expected\": [], \"passed\": true}, {\"check\": \"control layout\", \"actual\": [], \"expected\": [], \"passed\": true}], \"passed\": false}\n"},"broken":{"elapsed_ms":38.854,"exit_code":1,"observations":[{"actual":[],"check":"backward selection","expected":[[0,2]],"passed":false},{"actual":[],"check":"regression: backward selection normalisation","expected":[[2,5]],"passed":false},{"actual":[[1,3],[6,7]],"check":"partial-repair probe","expected":[[1,3],[6,7]],"passed":true},{"actual":[[1,4],[6,8]],"check":"partial-repair probe","expected":[[1,4],[6,8]],"passed":true},{"actual":[[1,4]],"check":"selection crossing direction change","expected":[[1,4]],"passed":true},{"actual":[],"check":"control layout","expected":[],"passed":true},{"actual":[],"check":"control layout","expected":[],"passed":true},{"actual":[],"check":"control layout","expected":[],"passed":true}],"passed":false,"stderr":"","stdout":"{\"observations\": [{\"check\": \"backward selection\", \"actual\": [], \"expected\": [[0, 2]], \"passed\": false}, {\"check\": \"regression: backward selection normalisation\", \"actual\": [], \"expected\": [[2, 5]], \"passed\": false}, {\"check\": \"partial-repair probe\", \"actual\": [[1, 3], [6, 7]], \"expected\": [[1, 3], [6, 7]], \"passed\": true}, {\"check\": \"partial-repair probe\", \"actual\": [[1, 4], [6, 8]], \"expected\": [[1, 4], [6, 8]], \"passed\": true}, {\"check\": \"selection crossing direction change\", \"actual\": [[1, 4]], \"expected\": [[1, 4]], \"passed\": true}, {\"check\": \"control layout\", \"actual\": [], \"expected\": [], \"passed\": true}, {\"check\": \"control layout\", \"actual\": [], \"expected\": [], \"passed\": true}, {\"check\": \"control layout\", \"actual\": [], \"expected\": [], \"passed\": true}], \"passed\": false}\n"},"fixed":{"elapsed_ms":39.359,"exit_code":0,"observations":[{"actual":[[0,2]],"check":"backward selection","expected":[[0,2]],"passed":true},{"actual":[[2,5]],"check":"regression: backward selection normalisation","expected":[[2,5]],"passed":true},{"actual":[[1,3],[6,7]],"check":"partial-repair probe","expected":[[1,3],[6,7]],"passed":true},{"actual":[[1,4],[6,8]],"check":"partial-repair probe","expected":[[1,4],[6,8]],"passed":true},{"actual":[[1,4]],"check":"selection crossing direction change","expected":[[1,4]],"passed":true},{"actual":[],"check":"control layout","expected":[],"passed":true},{"actual":[],"check":"control layout","expected":[],"passed":true},{"actual":[],"check":"control layout","expected":[],"passed":true}],"passed":true,"stderr":"","stdout":"{\"observations\": [{\"check\": \"backward selection\", \"actual\": [[0, 2]], \"expected\": [[0, 2]], \"passed\": true}, {\"check\": \"regression: backward selection normalisation\", \"actual\": [[2, 5]], \"expected\": [[2, 5]], \"passed\": true}, {\"check\": \"partial-repair probe\", \"actual\": [[1, 3], [6, 7]], \"expected\": [[1, 3], [6, 7]], \"passed\": true}, {\"check\": \"partial-repair probe\", \"actual\": [[1, 4], [6, 8]], \"expected\": [[1, 4], [6, 8]], \"passed\": true}, {\"check\": \"selection crossing direction change\", \"actual\": [[1, 4]], \"expected\": [[1, 4]], \"passed\": true}, {\"check\": \"control layout\", \"actual\": [], \"expected\": [], \"passed\": true}, {\"check\": \"control layout\", \"actual\": [], \"expected\": [], \"passed\": true}, {\"check\": \"control layout\", \"actual\": [], \"expected\": [], \"passed\": true}], \"passed\": true}\n"}},"verified":true,"visibility":"public"}