FAILURE MAP
← Case archive

FA-80351 / Bidirectional text layout / Open access

First-strong paragraph direction: first-strong isolate initiator · case 01

Letters inside an FSI isolate decide the paragraph direction.

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

ROOT CAUSE

FSI is missing from the isolate initiator set.

VERIFIED REPAIR

Skip the content of LRI, RLI and FSI isolates.

Unsuccessful approach: Adding LRE to the set wrongly hides embedding content.

Case contract

Input [bidi classes, default level]. Scan for the first L (level 0) or R/AL (level 1), skipping characters between an isolate initiator (LRI, RLI, FSI) and its matching PDI (nesting counted; an unmatched PDI is ignored). Embedding codes are not skipped. Return [level, index of deciding character] or [default, None].

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):
    classes, default = x
    depth = 0
    for i, c in enumerate(classes):
        if c in ('LRI', 'RLI'):
            depth += 1
        elif c == 'PDI':
            if depth > 0:
                depth -= 1
        elif depth == 0:
            if c == 'L':
                return [0, i]
            if c in ('R', 'AL'):
                return [1, i]
    return [default, None]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('FSI content skipped', [['FSI', 'R', 'PDI', 'L'], 1], [0, 3]), ('regression: first-strong isolate initiator', [['PDI', 'FSI', 'WS', 'AL', 'L'], 1], [1, None]), ('partial-repair probe', [['LRE', 'R', 'WS', 'EN', 'L'], 1], [1, 1]), ('partial-repair probe', [['EN', 'LRE', 'AL', 'FSI'], 1], [1, 2]), ('Arabic letter decides', [['ON', 'AL', 'L'], 0], [1, 1]), ('numbers are not strong', [['EN', 'ON', 'R'], 0], [1, 2]), ('control layout', [['ON', 'AN', 'R', 'FSI', 'LRI', 'AN', 'FSI', 'WS', 'EN', 'WS'], 1], [1, 2]), ('control layout', [['LRI', 'PDI', 'FSI', 'PDI', 'PDI', 'WS', 'PDI', 'L'], 0], [0, 7])], [('regression: first-strong isolate initiator', [['FSI', 'L'], 0], [0, None]), ('regression: first-strong isolate initiator', [['PDI', 'FSI', 'ON', 'R', 'RLI', 'WS', 'FSI', 'AL'], 1], [1, None]), ('partial-repair probe', [['PDI', 'RLI', 'LRE', 'ON', 'EN', 'PDI', 'R', 'L'], 0], [1, 6]), ('partial-repair probe', [['LRE', 'R', 'WS', 'EN', 'L'], 1], [1, 1]), ('FSI content skipped', [['FSI', 'R', 'PDI', 'L'], 1], [0, 3]), ('numbers are not strong', [['EN', 'ON', 'R'], 0], [1, 2]), ('control layout', [['ON', 'AL', 'FSI'], 0], [1, 1]), ('control layout', [['AL', 'PDI', 'WS', 'ON', 'PDI'], 1], [1, 0])], [('regression: first-strong isolate initiator', [['EN', 'FSI', 'L', 'RLI'], 1], [1, None]), ('regression: first-strong isolate initiator', [['FSI', 'R', 'L', 'LRE'], 1], [1, None]), ('partial-repair probe', [['LRE', 'AN', 'L', 'AN'], 1], [0, 2]), ('partial-repair probe', [['EN', 'LRE', 'R'], 0], [1, 2]), ('stray PDI before isolate', [['PDI', 'RLI', 'L', 'PDI', 'R'], 0], [1, 4]), ('numbers are not strong', [['EN', 'ON', 'R'], 0], [1, 2]), ('control layout', [['ON', 'R', 'AL', 'ES', 'PDI', 'RLI', 'AN', 'RLI', 'WS', 'LRI'], 1], [1, 1]), ('control layout', [['FSI', 'LRI', 'L', 'ON', 'FSI', 'FSI', 'ON', 'RLI', 'R', 'PDI'], 0], [0, None])], [('regression: first-strong isolate initiator', [['NSM', 'FSI', 'R', 'PDI', 'AL', 'AN', 'WS', 'PDI'], 0], [1, 4]), ('regression: first-strong isolate initiator', [['PDI', 'FSI', 'ON', 'R', 'RLI', 'WS', 'FSI', 'AL'], 1], [1, None]), ('partial-repair probe', [['PDI', 'LRE', 'ON', 'R', 'FSI', 'WS'], 1], [1, 3]), ('partial-repair probe', [['PDI', 'RLI', 'LRE', 'ON', 'EN', 'PDI', 'R', 'L'], 0], [1, 6]), ('nested isolates', [['LRI', 'RLI', 'R', 'PDI', 'L', 'PDI', 'R'], 0], [1, 6]), ('FSI content skipped', [['FSI', 'R', 'PDI', 'L'], 1], [0, 3]), ('control layout', [['WS', 'R', 'LRI', 'RLI', 'R', 'EN', 'ON', 'R'], 0], [1, 1]), ('control layout', [['FSI', 'ES', 'NSM', 'NSM', 'WS', 'PDI', 'AL', 'AL', 'ON', 'ES'], 1], [1, 6])], [('regression: first-strong isolate initiator', [['FSI', 'AL', 'ON', 'RLI', 'FSI', 'PDI'], 1], [1, None]), ('regression: first-strong isolate initiator', [['FSI', 'L', 'EN', 'LRI'], 1], [1, None]), ('partial-repair probe', [['LRE', 'AN', 'L', 'AN'], 1], [0, 2]), ('partial-repair probe', [['ON', 'ES', 'LRE', 'R', 'L', 'AN', 'RLI', 'R', 'L'], 1], [1, 3]), ('numbers are not strong', [['EN', 'ON', 'R'], 0], [1, 2]), ('nested isolates', [['LRI', 'RLI', 'R', 'PDI', 'L', 'PDI', 'R'], 0], [1, 6]), ('control layout', [['FSI', 'ON', 'LRI', 'RLI', 'LRE', 'AN', 'LRI', 'LRI'], 0], [0, None]), ('control layout', [['PDI', 'ON', 'PDI', 'FSI', 'EN'], 1], [1, None])]]
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
FSI content skipped[1, 1][0, 3]Failed
regression: first-strong isolate initiator[1, 3][1, None]Failed
partial-repair probe[1, 1][1, 1]Passed
partial-repair probe[1, 2][1, 2]Passed
Arabic letter decides[1, 1][1, 1]Passed
numbers are not strong[1, 2][1, 2]Passed
control layout[1, 2][1, 2]Passed
control layout[0, 7][0, 7]Passed

SHA-256 / 21cf46088a788e4c82e13741636b75ce0e83cba49c5727628dcc80d3c87ee8db

2 / The unsuccessful fix

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    classes, default = x
    depth = 0
    for i, c in enumerate(classes):
        if c in ('LRI', 'RLI', 'FSI', 'LRE'):
            depth += 1
        elif c == 'PDI':
            if depth > 0:
                depth -= 1
        elif depth == 0:
            if c == 'L':
                return [0, i]
            if c in ('R', 'AL'):
                return [1, i]
    return [default, None]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('FSI content skipped', [['FSI', 'R', 'PDI', 'L'], 1], [0, 3]), ('regression: first-strong isolate initiator', [['PDI', 'FSI', 'WS', 'AL', 'L'], 1], [1, None]), ('partial-repair probe', [['LRE', 'R', 'WS', 'EN', 'L'], 1], [1, 1]), ('partial-repair probe', [['EN', 'LRE', 'AL', 'FSI'], 1], [1, 2]), ('Arabic letter decides', [['ON', 'AL', 'L'], 0], [1, 1]), ('numbers are not strong', [['EN', 'ON', 'R'], 0], [1, 2]), ('control layout', [['ON', 'AN', 'R', 'FSI', 'LRI', 'AN', 'FSI', 'WS', 'EN', 'WS'], 1], [1, 2]), ('control layout', [['LRI', 'PDI', 'FSI', 'PDI', 'PDI', 'WS', 'PDI', 'L'], 0], [0, 7])], [('regression: first-strong isolate initiator', [['FSI', 'L'], 0], [0, None]), ('regression: first-strong isolate initiator', [['PDI', 'FSI', 'ON', 'R', 'RLI', 'WS', 'FSI', 'AL'], 1], [1, None]), ('partial-repair probe', [['PDI', 'RLI', 'LRE', 'ON', 'EN', 'PDI', 'R', 'L'], 0], [1, 6]), ('partial-repair probe', [['LRE', 'R', 'WS', 'EN', 'L'], 1], [1, 1]), ('FSI content skipped', [['FSI', 'R', 'PDI', 'L'], 1], [0, 3]), ('numbers are not strong', [['EN', 'ON', 'R'], 0], [1, 2]), ('control layout', [['ON', 'AL', 'FSI'], 0], [1, 1]), ('control layout', [['AL', 'PDI', 'WS', 'ON', 'PDI'], 1], [1, 0])], [('regression: first-strong isolate initiator', [['EN', 'FSI', 'L', 'RLI'], 1], [1, None]), ('regression: first-strong isolate initiator', [['FSI', 'R', 'L', 'LRE'], 1], [1, None]), ('partial-repair probe', [['LRE', 'AN', 'L', 'AN'], 1], [0, 2]), ('partial-repair probe', [['EN', 'LRE', 'R'], 0], [1, 2]), ('stray PDI before isolate', [['PDI', 'RLI', 'L', 'PDI', 'R'], 0], [1, 4]), ('numbers are not strong', [['EN', 'ON', 'R'], 0], [1, 2]), ('control layout', [['ON', 'R', 'AL', 'ES', 'PDI', 'RLI', 'AN', 'RLI', 'WS', 'LRI'], 1], [1, 1]), ('control layout', [['FSI', 'LRI', 'L', 'ON', 'FSI', 'FSI', 'ON', 'RLI', 'R', 'PDI'], 0], [0, None])], [('regression: first-strong isolate initiator', [['NSM', 'FSI', 'R', 'PDI', 'AL', 'AN', 'WS', 'PDI'], 0], [1, 4]), ('regression: first-strong isolate initiator', [['PDI', 'FSI', 'ON', 'R', 'RLI', 'WS', 'FSI', 'AL'], 1], [1, None]), ('partial-repair probe', [['PDI', 'LRE', 'ON', 'R', 'FSI', 'WS'], 1], [1, 3]), ('partial-repair probe', [['PDI', 'RLI', 'LRE', 'ON', 'EN', 'PDI', 'R', 'L'], 0], [1, 6]), ('nested isolates', [['LRI', 'RLI', 'R', 'PDI', 'L', 'PDI', 'R'], 0], [1, 6]), ('FSI content skipped', [['FSI', 'R', 'PDI', 'L'], 1], [0, 3]), ('control layout', [['WS', 'R', 'LRI', 'RLI', 'R', 'EN', 'ON', 'R'], 0], [1, 1]), ('control layout', [['FSI', 'ES', 'NSM', 'NSM', 'WS', 'PDI', 'AL', 'AL', 'ON', 'ES'], 1], [1, 6])], [('regression: first-strong isolate initiator', [['FSI', 'AL', 'ON', 'RLI', 'FSI', 'PDI'], 1], [1, None]), ('regression: first-strong isolate initiator', [['FSI', 'L', 'EN', 'LRI'], 1], [1, None]), ('partial-repair probe', [['LRE', 'AN', 'L', 'AN'], 1], [0, 2]), ('partial-repair probe', [['ON', 'ES', 'LRE', 'R', 'L', 'AN', 'RLI', 'R', 'L'], 1], [1, 3]), ('numbers are not strong', [['EN', 'ON', 'R'], 0], [1, 2]), ('nested isolates', [['LRI', 'RLI', 'R', 'PDI', 'L', 'PDI', 'R'], 0], [1, 6]), ('control layout', [['FSI', 'ON', 'LRI', 'RLI', 'LRE', 'AN', 'LRI', 'LRI'], 0], [0, None]), ('control layout', [['PDI', 'ON', 'PDI', 'FSI', 'EN'], 1], [1, None])]]
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
FSI content skipped[0, 3][0, 3]Passed
regression: first-strong isolate initiator[1, None][1, None]Passed
partial-repair probe[1, None][1, 1]Failed
partial-repair probe[1, None][1, 2]Failed
Arabic letter decides[1, 1][1, 1]Passed
numbers are not strong[1, 2][1, 2]Passed
control layout[1, 2][1, 2]Passed
control layout[0, 7][0, 7]Passed

SHA-256 / fe4d512e44829688376f64d5d58be67a51396e0b7ca3adc6e06e5f5541d3068c

3 / The verified repair

Exit 0
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    classes, default = x
    depth = 0
    for i, c in enumerate(classes):
        if c in ('LRI', 'RLI', 'FSI'):
            depth += 1
        elif c == 'PDI':
            if depth > 0:
                depth -= 1
        elif depth == 0:
            if c == 'L':
                return [0, i]
            if c in ('R', 'AL'):
                return [1, i]
    return [default, None]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('FSI content skipped', [['FSI', 'R', 'PDI', 'L'], 1], [0, 3]), ('regression: first-strong isolate initiator', [['PDI', 'FSI', 'WS', 'AL', 'L'], 1], [1, None]), ('partial-repair probe', [['LRE', 'R', 'WS', 'EN', 'L'], 1], [1, 1]), ('partial-repair probe', [['EN', 'LRE', 'AL', 'FSI'], 1], [1, 2]), ('Arabic letter decides', [['ON', 'AL', 'L'], 0], [1, 1]), ('numbers are not strong', [['EN', 'ON', 'R'], 0], [1, 2]), ('control layout', [['ON', 'AN', 'R', 'FSI', 'LRI', 'AN', 'FSI', 'WS', 'EN', 'WS'], 1], [1, 2]), ('control layout', [['LRI', 'PDI', 'FSI', 'PDI', 'PDI', 'WS', 'PDI', 'L'], 0], [0, 7])], [('regression: first-strong isolate initiator', [['FSI', 'L'], 0], [0, None]), ('regression: first-strong isolate initiator', [['PDI', 'FSI', 'ON', 'R', 'RLI', 'WS', 'FSI', 'AL'], 1], [1, None]), ('partial-repair probe', [['PDI', 'RLI', 'LRE', 'ON', 'EN', 'PDI', 'R', 'L'], 0], [1, 6]), ('partial-repair probe', [['LRE', 'R', 'WS', 'EN', 'L'], 1], [1, 1]), ('FSI content skipped', [['FSI', 'R', 'PDI', 'L'], 1], [0, 3]), ('numbers are not strong', [['EN', 'ON', 'R'], 0], [1, 2]), ('control layout', [['ON', 'AL', 'FSI'], 0], [1, 1]), ('control layout', [['AL', 'PDI', 'WS', 'ON', 'PDI'], 1], [1, 0])], [('regression: first-strong isolate initiator', [['EN', 'FSI', 'L', 'RLI'], 1], [1, None]), ('regression: first-strong isolate initiator', [['FSI', 'R', 'L', 'LRE'], 1], [1, None]), ('partial-repair probe', [['LRE', 'AN', 'L', 'AN'], 1], [0, 2]), ('partial-repair probe', [['EN', 'LRE', 'R'], 0], [1, 2]), ('stray PDI before isolate', [['PDI', 'RLI', 'L', 'PDI', 'R'], 0], [1, 4]), ('numbers are not strong', [['EN', 'ON', 'R'], 0], [1, 2]), ('control layout', [['ON', 'R', 'AL', 'ES', 'PDI', 'RLI', 'AN', 'RLI', 'WS', 'LRI'], 1], [1, 1]), ('control layout', [['FSI', 'LRI', 'L', 'ON', 'FSI', 'FSI', 'ON', 'RLI', 'R', 'PDI'], 0], [0, None])], [('regression: first-strong isolate initiator', [['NSM', 'FSI', 'R', 'PDI', 'AL', 'AN', 'WS', 'PDI'], 0], [1, 4]), ('regression: first-strong isolate initiator', [['PDI', 'FSI', 'ON', 'R', 'RLI', 'WS', 'FSI', 'AL'], 1], [1, None]), ('partial-repair probe', [['PDI', 'LRE', 'ON', 'R', 'FSI', 'WS'], 1], [1, 3]), ('partial-repair probe', [['PDI', 'RLI', 'LRE', 'ON', 'EN', 'PDI', 'R', 'L'], 0], [1, 6]), ('nested isolates', [['LRI', 'RLI', 'R', 'PDI', 'L', 'PDI', 'R'], 0], [1, 6]), ('FSI content skipped', [['FSI', 'R', 'PDI', 'L'], 1], [0, 3]), ('control layout', [['WS', 'R', 'LRI', 'RLI', 'R', 'EN', 'ON', 'R'], 0], [1, 1]), ('control layout', [['FSI', 'ES', 'NSM', 'NSM', 'WS', 'PDI', 'AL', 'AL', 'ON', 'ES'], 1], [1, 6])], [('regression: first-strong isolate initiator', [['FSI', 'AL', 'ON', 'RLI', 'FSI', 'PDI'], 1], [1, None]), ('regression: first-strong isolate initiator', [['FSI', 'L', 'EN', 'LRI'], 1], [1, None]), ('partial-repair probe', [['LRE', 'AN', 'L', 'AN'], 1], [0, 2]), ('partial-repair probe', [['ON', 'ES', 'LRE', 'R', 'L', 'AN', 'RLI', 'R', 'L'], 1], [1, 3]), ('numbers are not strong', [['EN', 'ON', 'R'], 0], [1, 2]), ('nested isolates', [['LRI', 'RLI', 'R', 'PDI', 'L', 'PDI', 'R'], 0], [1, 6]), ('control layout', [['FSI', 'ON', 'LRI', 'RLI', 'LRE', 'AN', 'LRI', 'LRI'], 0], [0, None]), ('control layout', [['PDI', 'ON', 'PDI', 'FSI', 'EN'], 1], [1, None])]]
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
FSI content skipped[0, 3][0, 3]Passed
regression: first-strong isolate initiator[1, None][1, None]Passed
partial-repair probe[1, 1][1, 1]Passed
partial-repair probe[1, 2][1, 2]Passed
Arabic letter decides[1, 1][1, 1]Passed
numbers are not strong[1, 2][1, 2]Passed
control layout[1, 2][1, 2]Passed
control layout[0, 7][0, 7]Passed

SHA-256 / 894ddcb46c62532dc2c613b7f07c46a3f3c5b406f5222614a70e78885187b4f1

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

Case digest / aad2401a839d91bac4e03c7a52b6895cc07ceb6a35059d5833fd729901db1b04