FA-80346 / Bidirectional text layout / Open access
First-strong paragraph direction: unmatched PDI · case 01
A stray PDI hides the rest of the paragraph from direction detection.
ROOT CAUSE
Every PDI decrements the isolate depth, driving it negative.
VERIFIED REPAIR
Only decrement when an isolate is open.
Unsuccessful approach: Resetting depth to zero closes all nested isolates at once.
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':
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 = [[('stray PDI before isolate', [['PDI', 'RLI', 'L', 'PDI', 'R'], 0], [1, 4]), ('regression: unmatched PDI', [['LRE', 'PDI', 'AL', 'PDI', 'AN', 'RLI', 'WS', 'AL', 'R', 'EN'], 1], [1, 2]), ('partial-repair probe', [['ON', 'RLI', 'ON', 'LRI', 'AL', 'PDI', 'L', 'NSM'], 0], [0, None]), ('partial-repair probe', [['LRI', 'ON', 'RLI', 'L', 'PDI', 'AL', 'R', 'WS'], 0], [0, None]), ('FSI content skipped', [['FSI', 'R', 'PDI', 'L'], 1], [0, 3]), ('numbers are not strong', [['EN', 'ON', 'R'], 0], [1, 2]), ('control layout', [['AL', 'PDI', 'L', 'WS', 'EN', 'L', 'ES', 'ON'], 0], [1, 0]), ('control layout', [['WS', 'L', 'PDI', 'WS', 'AL'], 1], [0, 1])], [('regression: unmatched PDI', [['PDI', 'PDI', 'L', 'ON', 'L', 'EN', 'ON', 'RLI'], 0], [0, 2]), ('regression: unmatched PDI', [['PDI', 'LRI', 'AL', 'ON'], 1], [1, None]), ('partial-repair probe', [['LRI', 'WS', 'RLI', 'AN', 'PDI', 'AN', 'R', 'LRE', 'ES', 'L'], 1], [1, None]), ('partial-repair probe', [['LRI', 'EN', 'AN', 'LRI', 'RLI', 'AL', 'R', 'AN', 'PDI', 'R'], 1], [1, None]), ('numbers are not strong', [['EN', 'ON', 'R'], 0], [1, 2]), ('nested isolates', [['LRI', 'RLI', 'R', 'PDI', 'L', 'PDI', 'R'], 0], [1, 6]), ('control layout', [['LRI', 'AL', 'L', 'ON', 'AL', 'L', 'WS'], 1], [1, None]), ('control layout', [['RLI', 'WS', 'ON', 'ON', 'ON', 'L', 'R', 'LRI'], 0], [0, None])], [('regression: unmatched PDI', [['PDI', 'FSI', 'L', 'NSM', 'R', 'NSM', 'L', 'EN', 'WS', 'R'], 1], [1, None]), ('regression: unmatched PDI', [['PDI', 'AL', 'ON', 'PDI', 'L', 'WS', 'FSI', 'PDI', 'ON', 'LRI'], 0], [1, 1]), ('partial-repair probe', [['ON', 'RLI', 'ON', 'LRI', 'AL', 'PDI', 'L', 'NSM'], 0], [0, None]), ('partial-repair probe', [['LRI', 'EN', 'AN', 'LRI', 'RLI', 'AL', 'R', 'AN', 'PDI', 'R'], 1], [1, None]), ('FSI content skipped', [['FSI', 'R', 'PDI', 'L'], 1], [0, 3]), ('nested isolates', [['LRI', 'RLI', 'R', 'PDI', 'L', 'PDI', 'R'], 0], [1, 6]), ('control layout', [['WS'], 1], [1, None]), ('control layout', [['LRE', 'WS', 'LRI'], 0], [0, None])], [('regression: unmatched PDI', [['ON', 'PDI', 'LRE', 'L', 'AN', 'R', 'AL'], 1], [0, 3]), ('regression: unmatched PDI', [['EN', 'PDI', 'L', 'EN', 'FSI'], 1], [0, 2]), ('partial-repair probe', [['ON', 'RLI', 'ON', 'LRI', 'AL', 'PDI', 'L', 'NSM'], 0], [0, None]), ('partial-repair probe', [['WS', 'LRI', 'FSI', 'PDI', 'R', 'LRE'], 1], [1, None]), ('nested isolates', [['LRI', 'RLI', 'R', 'PDI', 'L', 'PDI', 'R'], 0], [1, 6]), ('Arabic letter decides', [['ON', 'AL', 'L'], 0], [1, 1]), ('control layout', [['EN', 'FSI', 'FSI', 'FSI', 'R', 'FSI', 'L'], 0], [0, None]), ('control layout', [['NSM', 'AN'], 1], [1, None])], [('regression: unmatched PDI', [['PDI', 'PDI', 'LRI', 'WS', 'LRI', 'PDI', 'LRI', 'R', 'EN', 'L'], 1], [1, None]), ('regression: unmatched PDI', [['PDI', 'AN', 'R', 'FSI', 'ES', 'EN'], 0], [1, 2]), ('partial-repair probe', [['EN', 'ES', 'LRI', 'WS', 'WS', 'FSI', 'PDI', 'AL'], 1], [1, None]), ('partial-repair probe', [['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]), ('Arabic letter decides', [['ON', 'AL', 'L'], 0], [1, 1]), ('control layout', [['WS', 'AN', 'R', 'WS', 'EN', 'WS', 'PDI'], 1], [1, 2]), ('control layout', [['AN'], 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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| stray PDI before isolate | [0, 2] | [1, 4] | Failed |
| regression: unmatched PDI | [1, None] | [1, 2] | Failed |
| partial-repair probe | [0, None] | [0, None] | Passed |
| partial-repair probe | [0, None] | [0, None] | Passed |
| FSI content skipped | [0, 3] | [0, 3] | Passed |
| numbers are not strong | [1, 2] | [1, 2] | Passed |
| control layout | [1, 0] | [1, 0] | Passed |
| control layout | [0, 1] | [0, 1] | Passed |
SHA-256 / 5e3a3489d27acfc99d44255c2bef33308ab1d8608e8d05b5ba72133235ffecd9
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 = [[('stray PDI before isolate', [['PDI', 'RLI', 'L', 'PDI', 'R'], 0], [1, 4]), ('regression: unmatched PDI', [['LRE', 'PDI', 'AL', 'PDI', 'AN', 'RLI', 'WS', 'AL', 'R', 'EN'], 1], [1, 2]), ('partial-repair probe', [['ON', 'RLI', 'ON', 'LRI', 'AL', 'PDI', 'L', 'NSM'], 0], [0, None]), ('partial-repair probe', [['LRI', 'ON', 'RLI', 'L', 'PDI', 'AL', 'R', 'WS'], 0], [0, None]), ('FSI content skipped', [['FSI', 'R', 'PDI', 'L'], 1], [0, 3]), ('numbers are not strong', [['EN', 'ON', 'R'], 0], [1, 2]), ('control layout', [['AL', 'PDI', 'L', 'WS', 'EN', 'L', 'ES', 'ON'], 0], [1, 0]), ('control layout', [['WS', 'L', 'PDI', 'WS', 'AL'], 1], [0, 1])], [('regression: unmatched PDI', [['PDI', 'PDI', 'L', 'ON', 'L', 'EN', 'ON', 'RLI'], 0], [0, 2]), ('regression: unmatched PDI', [['PDI', 'LRI', 'AL', 'ON'], 1], [1, None]), ('partial-repair probe', [['LRI', 'WS', 'RLI', 'AN', 'PDI', 'AN', 'R', 'LRE', 'ES', 'L'], 1], [1, None]), ('partial-repair probe', [['LRI', 'EN', 'AN', 'LRI', 'RLI', 'AL', 'R', 'AN', 'PDI', 'R'], 1], [1, None]), ('numbers are not strong', [['EN', 'ON', 'R'], 0], [1, 2]), ('nested isolates', [['LRI', 'RLI', 'R', 'PDI', 'L', 'PDI', 'R'], 0], [1, 6]), ('control layout', [['LRI', 'AL', 'L', 'ON', 'AL', 'L', 'WS'], 1], [1, None]), ('control layout', [['RLI', 'WS', 'ON', 'ON', 'ON', 'L', 'R', 'LRI'], 0], [0, None])], [('regression: unmatched PDI', [['PDI', 'FSI', 'L', 'NSM', 'R', 'NSM', 'L', 'EN', 'WS', 'R'], 1], [1, None]), ('regression: unmatched PDI', [['PDI', 'AL', 'ON', 'PDI', 'L', 'WS', 'FSI', 'PDI', 'ON', 'LRI'], 0], [1, 1]), ('partial-repair probe', [['ON', 'RLI', 'ON', 'LRI', 'AL', 'PDI', 'L', 'NSM'], 0], [0, None]), ('partial-repair probe', [['LRI', 'EN', 'AN', 'LRI', 'RLI', 'AL', 'R', 'AN', 'PDI', 'R'], 1], [1, None]), ('FSI content skipped', [['FSI', 'R', 'PDI', 'L'], 1], [0, 3]), ('nested isolates', [['LRI', 'RLI', 'R', 'PDI', 'L', 'PDI', 'R'], 0], [1, 6]), ('control layout', [['WS'], 1], [1, None]), ('control layout', [['LRE', 'WS', 'LRI'], 0], [0, None])], [('regression: unmatched PDI', [['ON', 'PDI', 'LRE', 'L', 'AN', 'R', 'AL'], 1], [0, 3]), ('regression: unmatched PDI', [['EN', 'PDI', 'L', 'EN', 'FSI'], 1], [0, 2]), ('partial-repair probe', [['ON', 'RLI', 'ON', 'LRI', 'AL', 'PDI', 'L', 'NSM'], 0], [0, None]), ('partial-repair probe', [['WS', 'LRI', 'FSI', 'PDI', 'R', 'LRE'], 1], [1, None]), ('nested isolates', [['LRI', 'RLI', 'R', 'PDI', 'L', 'PDI', 'R'], 0], [1, 6]), ('Arabic letter decides', [['ON', 'AL', 'L'], 0], [1, 1]), ('control layout', [['EN', 'FSI', 'FSI', 'FSI', 'R', 'FSI', 'L'], 0], [0, None]), ('control layout', [['NSM', 'AN'], 1], [1, None])], [('regression: unmatched PDI', [['PDI', 'PDI', 'LRI', 'WS', 'LRI', 'PDI', 'LRI', 'R', 'EN', 'L'], 1], [1, None]), ('regression: unmatched PDI', [['PDI', 'AN', 'R', 'FSI', 'ES', 'EN'], 0], [1, 2]), ('partial-repair probe', [['EN', 'ES', 'LRI', 'WS', 'WS', 'FSI', 'PDI', 'AL'], 1], [1, None]), ('partial-repair probe', [['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]), ('Arabic letter decides', [['ON', 'AL', 'L'], 0], [1, 1]), ('control layout', [['WS', 'AN', 'R', 'WS', 'EN', 'WS', 'PDI'], 1], [1, 2]), ('control layout', [['AN'], 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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| stray PDI before isolate | [1, 4] | [1, 4] | Passed |
| regression: unmatched PDI | [1, 2] | [1, 2] | Passed |
| partial-repair probe | [0, 6] | [0, None] | Failed |
| partial-repair probe | [1, 5] | [0, None] | Failed |
| FSI content skipped | [0, 3] | [0, 3] | Passed |
| numbers are not strong | [1, 2] | [1, 2] | Passed |
| control layout | [1, 0] | [1, 0] | Passed |
| control layout | [0, 1] | [0, 1] | Passed |
SHA-256 / c869fbd23d099c1a72a2efbcfa1c55b6da413ab88dff5fd2dd2d53581616c92f
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 = [[('stray PDI before isolate', [['PDI', 'RLI', 'L', 'PDI', 'R'], 0], [1, 4]), ('regression: unmatched PDI', [['LRE', 'PDI', 'AL', 'PDI', 'AN', 'RLI', 'WS', 'AL', 'R', 'EN'], 1], [1, 2]), ('partial-repair probe', [['ON', 'RLI', 'ON', 'LRI', 'AL', 'PDI', 'L', 'NSM'], 0], [0, None]), ('partial-repair probe', [['LRI', 'ON', 'RLI', 'L', 'PDI', 'AL', 'R', 'WS'], 0], [0, None]), ('FSI content skipped', [['FSI', 'R', 'PDI', 'L'], 1], [0, 3]), ('numbers are not strong', [['EN', 'ON', 'R'], 0], [1, 2]), ('control layout', [['AL', 'PDI', 'L', 'WS', 'EN', 'L', 'ES', 'ON'], 0], [1, 0]), ('control layout', [['WS', 'L', 'PDI', 'WS', 'AL'], 1], [0, 1])], [('regression: unmatched PDI', [['PDI', 'PDI', 'L', 'ON', 'L', 'EN', 'ON', 'RLI'], 0], [0, 2]), ('regression: unmatched PDI', [['PDI', 'LRI', 'AL', 'ON'], 1], [1, None]), ('partial-repair probe', [['LRI', 'WS', 'RLI', 'AN', 'PDI', 'AN', 'R', 'LRE', 'ES', 'L'], 1], [1, None]), ('partial-repair probe', [['LRI', 'EN', 'AN', 'LRI', 'RLI', 'AL', 'R', 'AN', 'PDI', 'R'], 1], [1, None]), ('numbers are not strong', [['EN', 'ON', 'R'], 0], [1, 2]), ('nested isolates', [['LRI', 'RLI', 'R', 'PDI', 'L', 'PDI', 'R'], 0], [1, 6]), ('control layout', [['LRI', 'AL', 'L', 'ON', 'AL', 'L', 'WS'], 1], [1, None]), ('control layout', [['RLI', 'WS', 'ON', 'ON', 'ON', 'L', 'R', 'LRI'], 0], [0, None])], [('regression: unmatched PDI', [['PDI', 'FSI', 'L', 'NSM', 'R', 'NSM', 'L', 'EN', 'WS', 'R'], 1], [1, None]), ('regression: unmatched PDI', [['PDI', 'AL', 'ON', 'PDI', 'L', 'WS', 'FSI', 'PDI', 'ON', 'LRI'], 0], [1, 1]), ('partial-repair probe', [['ON', 'RLI', 'ON', 'LRI', 'AL', 'PDI', 'L', 'NSM'], 0], [0, None]), ('partial-repair probe', [['LRI', 'EN', 'AN', 'LRI', 'RLI', 'AL', 'R', 'AN', 'PDI', 'R'], 1], [1, None]), ('FSI content skipped', [['FSI', 'R', 'PDI', 'L'], 1], [0, 3]), ('nested isolates', [['LRI', 'RLI', 'R', 'PDI', 'L', 'PDI', 'R'], 0], [1, 6]), ('control layout', [['WS'], 1], [1, None]), ('control layout', [['LRE', 'WS', 'LRI'], 0], [0, None])], [('regression: unmatched PDI', [['ON', 'PDI', 'LRE', 'L', 'AN', 'R', 'AL'], 1], [0, 3]), ('regression: unmatched PDI', [['EN', 'PDI', 'L', 'EN', 'FSI'], 1], [0, 2]), ('partial-repair probe', [['ON', 'RLI', 'ON', 'LRI', 'AL', 'PDI', 'L', 'NSM'], 0], [0, None]), ('partial-repair probe', [['WS', 'LRI', 'FSI', 'PDI', 'R', 'LRE'], 1], [1, None]), ('nested isolates', [['LRI', 'RLI', 'R', 'PDI', 'L', 'PDI', 'R'], 0], [1, 6]), ('Arabic letter decides', [['ON', 'AL', 'L'], 0], [1, 1]), ('control layout', [['EN', 'FSI', 'FSI', 'FSI', 'R', 'FSI', 'L'], 0], [0, None]), ('control layout', [['NSM', 'AN'], 1], [1, None])], [('regression: unmatched PDI', [['PDI', 'PDI', 'LRI', 'WS', 'LRI', 'PDI', 'LRI', 'R', 'EN', 'L'], 1], [1, None]), ('regression: unmatched PDI', [['PDI', 'AN', 'R', 'FSI', 'ES', 'EN'], 0], [1, 2]), ('partial-repair probe', [['EN', 'ES', 'LRI', 'WS', 'WS', 'FSI', 'PDI', 'AL'], 1], [1, None]), ('partial-repair probe', [['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]), ('Arabic letter decides', [['ON', 'AL', 'L'], 0], [1, 1]), ('control layout', [['WS', 'AN', 'R', 'WS', 'EN', 'WS', 'PDI'], 1], [1, 2]), ('control layout', [['AN'], 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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| stray PDI before isolate | [1, 4] | [1, 4] | Passed |
| regression: unmatched PDI | [1, 2] | [1, 2] | Passed |
| partial-repair probe | [0, None] | [0, None] | Passed |
| partial-repair probe | [0, None] | [0, None] | Passed |
| FSI content skipped | [0, 3] | [0, 3] | Passed |
| numbers are not strong | [1, 2] | [1, 2] | Passed |
| control layout | [1, 0] | [1, 0] | Passed |
| control layout | [0, 1] | [0, 1] | Passed |
SHA-256 / bde639bcb37bf4facc107d0771e22ebef4b725669763ab5a7ce7623940db6ebd
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.940037+00:00.
Case digest / c42031017dd5513a527ab8c86a9ba907357037de6f582f16d14cbac3fb58aeff