FAILURE MAP
← Case archive

FA-80361 / Bidirectional text layout / Open access

First-strong paragraph direction: nested isolate depth · case 01

Text after an inner PDI is treated as outside all isolates.

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

ROOT CAUSE

Opening an isolate sets depth to 1 instead of incrementing it.

VERIFIED REPAIR

Increment the depth for every initiator.

Unsuccessful approach: Incrementing but zeroing on every PDI still breaks nesting.

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', '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 = [[('nested isolates', [['LRI', 'RLI', 'R', 'PDI', 'L', 'PDI', 'R'], 0], [1, 6]), ('regression: nested isolate depth', [['LRI', 'ON', 'RLI', 'L', 'PDI', 'AL', 'R', 'WS'], 0], [0, None]), ('regression: nested isolate depth', [['LRI', 'WS', 'RLI', 'AN', 'PDI', 'AN', 'R', 'LRE', 'ES', 'L'], 1], [1, None]), ('regression: nested isolate depth', [['LRI', 'EN', 'AN', 'LRI', 'RLI', 'AL', 'R', 'AN', 'PDI', 'R'], 1], [1, None]), ('FSI content skipped', [['FSI', 'R', 'PDI', 'L'], 1], [0, 3]), ('stray PDI before isolate', [['PDI', 'RLI', 'L', 'PDI', 'R'], 0], [1, 4]), ('control layout', [['WS', 'L', 'EN', 'WS', 'EN'], 1], [0, 1]), ('control layout', [['FSI', 'EN', 'PDI', 'RLI'], 1], [1, None])], [('regression: nested isolate depth', [['WS', 'LRI', 'FSI', 'PDI', 'R', 'LRE'], 1], [1, None]), ('regression: nested isolate depth', [['FSI', 'RLI', 'AL', 'LRE', 'LRI', 'PDI', 'AL', 'L'], 1], [1, None]), ('regression: nested isolate depth', [['EN', 'ES', 'LRI', 'WS', 'WS', 'FSI', 'PDI', 'AL'], 1], [1, None]), ('regression: nested isolate depth', [['LRI', 'EN', 'AN', 'LRI', 'RLI', 'AL', 'R', 'AN', 'PDI', 'R'], 1], [1, None]), ('numbers are not strong', [['EN', 'ON', 'R'], 0], [1, 2]), ('stray PDI before isolate', [['PDI', 'RLI', 'L', 'PDI', 'R'], 0], [1, 4]), ('control layout', [['RLI', 'AL', 'L', 'L', 'LRE'], 1], [1, None]), ('control layout', [['ON', 'WS'], 1], [1, None])], [('regression: nested isolate depth', [['ON', 'RLI', 'ON', 'LRI', 'AL', 'PDI', 'L', 'NSM'], 0], [0, None]), ('regression: nested isolate depth', [['FSI', 'RLI', 'AL', 'LRE', 'LRI', 'PDI', 'AL', 'L'], 1], [1, None]), ('regression: nested isolate depth', [['LRI', 'ON', 'RLI', 'L', 'PDI', 'AL', 'R', 'WS'], 0], [0, None]), ('regression: nested isolate depth', [['WS', 'LRI', 'FSI', 'PDI', 'R', 'LRE'], 1], [1, None]), ('Arabic letter decides', [['ON', 'AL', 'L'], 0], [1, 1]), ('FSI content skipped', [['FSI', 'R', 'PDI', 'L'], 1], [0, 3]), ('control layout', [['LRI', 'RLI', 'AN', 'WS'], 1], [1, None]), ('control layout', [['AL', 'PDI', 'ON', 'R', 'ON', 'EN', 'LRE', 'NSM', 'R', 'R'], 1], [1, 0])], [('regression: nested isolate depth', [['LRI', 'WS', 'RLI', 'AN', 'PDI', 'AN', 'R', 'LRE', 'ES', 'L'], 1], [1, None]), ('nested isolates', [['LRI', 'RLI', 'R', 'PDI', 'L', 'PDI', 'R'], 0], [1, 6]), ('regression: nested isolate depth', [['LRI', 'ON', 'RLI', 'L', 'PDI', 'AL', 'R', 'WS'], 0], [0, None]), ('regression: nested isolate depth', [['EN', 'ES', 'LRI', 'WS', 'WS', 'FSI', 'PDI', 'AL'], 1], [1, None]), ('stray PDI before isolate', [['PDI', 'RLI', 'L', 'PDI', 'R'], 0], [1, 4]), ('Arabic letter decides', [['ON', 'AL', 'L'], 0], [1, 1]), ('control layout', [['ES', 'PDI', 'R', 'LRI', 'EN', 'PDI', 'AN', 'WS', 'RLI'], 0], [1, 2]), ('control layout', [['R', 'RLI', 'PDI', 'RLI', 'PDI', 'FSI', 'PDI', 'RLI', 'R'], 1], [1, 0])], [('nested isolates', [['LRI', 'RLI', 'R', 'PDI', 'L', 'PDI', 'R'], 0], [1, 6]), ('regression: nested isolate depth', [['ON', 'RLI', 'ON', 'LRI', 'AL', 'PDI', 'L', 'NSM'], 0], [0, None]), ('regression: nested isolate depth', [['LRI', 'ON', 'RLI', 'L', 'PDI', 'AL', 'R', 'WS'], 0], [0, None]), ('regression: nested isolate depth', [['FSI', 'RLI', 'AL', 'LRE', 'LRI', 'PDI', 'AL', 'L'], 1], [1, None]), ('stray PDI before isolate', [['PDI', 'RLI', 'L', 'PDI', 'R'], 0], [1, 4]), ('numbers are not strong', [['EN', 'ON', 'R'], 0], [1, 2]), ('control layout', [['AN', 'L', 'PDI', 'AL', 'R', 'WS', 'EN', 'RLI', 'WS'], 1], [0, 1]), ('control layout', [['LRI'], 0], [0, 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
nested isolates[0, 4][1, 6]Failed
regression: nested isolate depth[1, 5][0, None]Failed
regression: nested isolate depth[1, 6][1, None]Failed
regression: nested isolate depth[1, 9][1, None]Failed
FSI content skipped[0, 3][0, 3]Passed
stray PDI before isolate[1, 4][1, 4]Passed
control layout[0, 1][0, 1]Passed
control layout[1, None][1, None]Passed

SHA-256 / 7f33ef99be397361a860f3b7496c51c9fc4e5a62c4a0c1668de9a16d3b2c167f

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'):
            depth += 1
        elif c == 'PDI':
            depth = 0
        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 = [[('nested isolates', [['LRI', 'RLI', 'R', 'PDI', 'L', 'PDI', 'R'], 0], [1, 6]), ('regression: nested isolate depth', [['LRI', 'ON', 'RLI', 'L', 'PDI', 'AL', 'R', 'WS'], 0], [0, None]), ('regression: nested isolate depth', [['LRI', 'WS', 'RLI', 'AN', 'PDI', 'AN', 'R', 'LRE', 'ES', 'L'], 1], [1, None]), ('regression: nested isolate depth', [['LRI', 'EN', 'AN', 'LRI', 'RLI', 'AL', 'R', 'AN', 'PDI', 'R'], 1], [1, None]), ('FSI content skipped', [['FSI', 'R', 'PDI', 'L'], 1], [0, 3]), ('stray PDI before isolate', [['PDI', 'RLI', 'L', 'PDI', 'R'], 0], [1, 4]), ('control layout', [['WS', 'L', 'EN', 'WS', 'EN'], 1], [0, 1]), ('control layout', [['FSI', 'EN', 'PDI', 'RLI'], 1], [1, None])], [('regression: nested isolate depth', [['WS', 'LRI', 'FSI', 'PDI', 'R', 'LRE'], 1], [1, None]), ('regression: nested isolate depth', [['FSI', 'RLI', 'AL', 'LRE', 'LRI', 'PDI', 'AL', 'L'], 1], [1, None]), ('regression: nested isolate depth', [['EN', 'ES', 'LRI', 'WS', 'WS', 'FSI', 'PDI', 'AL'], 1], [1, None]), ('regression: nested isolate depth', [['LRI', 'EN', 'AN', 'LRI', 'RLI', 'AL', 'R', 'AN', 'PDI', 'R'], 1], [1, None]), ('numbers are not strong', [['EN', 'ON', 'R'], 0], [1, 2]), ('stray PDI before isolate', [['PDI', 'RLI', 'L', 'PDI', 'R'], 0], [1, 4]), ('control layout', [['RLI', 'AL', 'L', 'L', 'LRE'], 1], [1, None]), ('control layout', [['ON', 'WS'], 1], [1, None])], [('regression: nested isolate depth', [['ON', 'RLI', 'ON', 'LRI', 'AL', 'PDI', 'L', 'NSM'], 0], [0, None]), ('regression: nested isolate depth', [['FSI', 'RLI', 'AL', 'LRE', 'LRI', 'PDI', 'AL', 'L'], 1], [1, None]), ('regression: nested isolate depth', [['LRI', 'ON', 'RLI', 'L', 'PDI', 'AL', 'R', 'WS'], 0], [0, None]), ('regression: nested isolate depth', [['WS', 'LRI', 'FSI', 'PDI', 'R', 'LRE'], 1], [1, None]), ('Arabic letter decides', [['ON', 'AL', 'L'], 0], [1, 1]), ('FSI content skipped', [['FSI', 'R', 'PDI', 'L'], 1], [0, 3]), ('control layout', [['LRI', 'RLI', 'AN', 'WS'], 1], [1, None]), ('control layout', [['AL', 'PDI', 'ON', 'R', 'ON', 'EN', 'LRE', 'NSM', 'R', 'R'], 1], [1, 0])], [('regression: nested isolate depth', [['LRI', 'WS', 'RLI', 'AN', 'PDI', 'AN', 'R', 'LRE', 'ES', 'L'], 1], [1, None]), ('nested isolates', [['LRI', 'RLI', 'R', 'PDI', 'L', 'PDI', 'R'], 0], [1, 6]), ('regression: nested isolate depth', [['LRI', 'ON', 'RLI', 'L', 'PDI', 'AL', 'R', 'WS'], 0], [0, None]), ('regression: nested isolate depth', [['EN', 'ES', 'LRI', 'WS', 'WS', 'FSI', 'PDI', 'AL'], 1], [1, None]), ('stray PDI before isolate', [['PDI', 'RLI', 'L', 'PDI', 'R'], 0], [1, 4]), ('Arabic letter decides', [['ON', 'AL', 'L'], 0], [1, 1]), ('control layout', [['ES', 'PDI', 'R', 'LRI', 'EN', 'PDI', 'AN', 'WS', 'RLI'], 0], [1, 2]), ('control layout', [['R', 'RLI', 'PDI', 'RLI', 'PDI', 'FSI', 'PDI', 'RLI', 'R'], 1], [1, 0])], [('nested isolates', [['LRI', 'RLI', 'R', 'PDI', 'L', 'PDI', 'R'], 0], [1, 6]), ('regression: nested isolate depth', [['ON', 'RLI', 'ON', 'LRI', 'AL', 'PDI', 'L', 'NSM'], 0], [0, None]), ('regression: nested isolate depth', [['LRI', 'ON', 'RLI', 'L', 'PDI', 'AL', 'R', 'WS'], 0], [0, None]), ('regression: nested isolate depth', [['FSI', 'RLI', 'AL', 'LRE', 'LRI', 'PDI', 'AL', 'L'], 1], [1, None]), ('stray PDI before isolate', [['PDI', 'RLI', 'L', 'PDI', 'R'], 0], [1, 4]), ('numbers are not strong', [['EN', 'ON', 'R'], 0], [1, 2]), ('control layout', [['AN', 'L', 'PDI', 'AL', 'R', 'WS', 'EN', 'RLI', 'WS'], 1], [0, 1]), ('control layout', [['LRI'], 0], [0, 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
nested isolates[0, 4][1, 6]Failed
regression: nested isolate depth[1, 5][0, None]Failed
regression: nested isolate depth[1, 6][1, None]Failed
regression: nested isolate depth[1, 9][1, None]Failed
FSI content skipped[0, 3][0, 3]Passed
stray PDI before isolate[1, 4][1, 4]Passed
control layout[0, 1][0, 1]Passed
control layout[1, None][1, None]Passed

SHA-256 / efe2d8a51ebe66c7935bde9f76287bc92a9e3168a7841d1b6c52420334ec63bd

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 = [[('nested isolates', [['LRI', 'RLI', 'R', 'PDI', 'L', 'PDI', 'R'], 0], [1, 6]), ('regression: nested isolate depth', [['LRI', 'ON', 'RLI', 'L', 'PDI', 'AL', 'R', 'WS'], 0], [0, None]), ('regression: nested isolate depth', [['LRI', 'WS', 'RLI', 'AN', 'PDI', 'AN', 'R', 'LRE', 'ES', 'L'], 1], [1, None]), ('regression: nested isolate depth', [['LRI', 'EN', 'AN', 'LRI', 'RLI', 'AL', 'R', 'AN', 'PDI', 'R'], 1], [1, None]), ('FSI content skipped', [['FSI', 'R', 'PDI', 'L'], 1], [0, 3]), ('stray PDI before isolate', [['PDI', 'RLI', 'L', 'PDI', 'R'], 0], [1, 4]), ('control layout', [['WS', 'L', 'EN', 'WS', 'EN'], 1], [0, 1]), ('control layout', [['FSI', 'EN', 'PDI', 'RLI'], 1], [1, None])], [('regression: nested isolate depth', [['WS', 'LRI', 'FSI', 'PDI', 'R', 'LRE'], 1], [1, None]), ('regression: nested isolate depth', [['FSI', 'RLI', 'AL', 'LRE', 'LRI', 'PDI', 'AL', 'L'], 1], [1, None]), ('regression: nested isolate depth', [['EN', 'ES', 'LRI', 'WS', 'WS', 'FSI', 'PDI', 'AL'], 1], [1, None]), ('regression: nested isolate depth', [['LRI', 'EN', 'AN', 'LRI', 'RLI', 'AL', 'R', 'AN', 'PDI', 'R'], 1], [1, None]), ('numbers are not strong', [['EN', 'ON', 'R'], 0], [1, 2]), ('stray PDI before isolate', [['PDI', 'RLI', 'L', 'PDI', 'R'], 0], [1, 4]), ('control layout', [['RLI', 'AL', 'L', 'L', 'LRE'], 1], [1, None]), ('control layout', [['ON', 'WS'], 1], [1, None])], [('regression: nested isolate depth', [['ON', 'RLI', 'ON', 'LRI', 'AL', 'PDI', 'L', 'NSM'], 0], [0, None]), ('regression: nested isolate depth', [['FSI', 'RLI', 'AL', 'LRE', 'LRI', 'PDI', 'AL', 'L'], 1], [1, None]), ('regression: nested isolate depth', [['LRI', 'ON', 'RLI', 'L', 'PDI', 'AL', 'R', 'WS'], 0], [0, None]), ('regression: nested isolate depth', [['WS', 'LRI', 'FSI', 'PDI', 'R', 'LRE'], 1], [1, None]), ('Arabic letter decides', [['ON', 'AL', 'L'], 0], [1, 1]), ('FSI content skipped', [['FSI', 'R', 'PDI', 'L'], 1], [0, 3]), ('control layout', [['LRI', 'RLI', 'AN', 'WS'], 1], [1, None]), ('control layout', [['AL', 'PDI', 'ON', 'R', 'ON', 'EN', 'LRE', 'NSM', 'R', 'R'], 1], [1, 0])], [('regression: nested isolate depth', [['LRI', 'WS', 'RLI', 'AN', 'PDI', 'AN', 'R', 'LRE', 'ES', 'L'], 1], [1, None]), ('nested isolates', [['LRI', 'RLI', 'R', 'PDI', 'L', 'PDI', 'R'], 0], [1, 6]), ('regression: nested isolate depth', [['LRI', 'ON', 'RLI', 'L', 'PDI', 'AL', 'R', 'WS'], 0], [0, None]), ('regression: nested isolate depth', [['EN', 'ES', 'LRI', 'WS', 'WS', 'FSI', 'PDI', 'AL'], 1], [1, None]), ('stray PDI before isolate', [['PDI', 'RLI', 'L', 'PDI', 'R'], 0], [1, 4]), ('Arabic letter decides', [['ON', 'AL', 'L'], 0], [1, 1]), ('control layout', [['ES', 'PDI', 'R', 'LRI', 'EN', 'PDI', 'AN', 'WS', 'RLI'], 0], [1, 2]), ('control layout', [['R', 'RLI', 'PDI', 'RLI', 'PDI', 'FSI', 'PDI', 'RLI', 'R'], 1], [1, 0])], [('nested isolates', [['LRI', 'RLI', 'R', 'PDI', 'L', 'PDI', 'R'], 0], [1, 6]), ('regression: nested isolate depth', [['ON', 'RLI', 'ON', 'LRI', 'AL', 'PDI', 'L', 'NSM'], 0], [0, None]), ('regression: nested isolate depth', [['LRI', 'ON', 'RLI', 'L', 'PDI', 'AL', 'R', 'WS'], 0], [0, None]), ('regression: nested isolate depth', [['FSI', 'RLI', 'AL', 'LRE', 'LRI', 'PDI', 'AL', 'L'], 1], [1, None]), ('stray PDI before isolate', [['PDI', 'RLI', 'L', 'PDI', 'R'], 0], [1, 4]), ('numbers are not strong', [['EN', 'ON', 'R'], 0], [1, 2]), ('control layout', [['AN', 'L', 'PDI', 'AL', 'R', 'WS', 'EN', 'RLI', 'WS'], 1], [0, 1]), ('control layout', [['LRI'], 0], [0, 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
nested isolates[1, 6][1, 6]Passed
regression: nested isolate depth[0, None][0, None]Passed
regression: nested isolate depth[1, None][1, None]Passed
regression: nested isolate depth[1, None][1, None]Passed
FSI content skipped[0, 3][0, 3]Passed
stray PDI before isolate[1, 4][1, 4]Passed
control layout[0, 1][0, 1]Passed
control layout[1, None][1, None]Passed

SHA-256 / c57985c89ceca0b6c5d7fee485350ef497f0fc351887693bfe08ece446a60d6d

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

Case digest / 6e3e682d53a146394ace5ce73f2fe1923e46f99d5583c5d7dfd38200f4ca4299