FA-80566 / Bidirectional text layout / Open access
Mirrored glyph rendering: mirror level lookup · case 01
Brackets are mirrored based on the level found at their visual slot.
ROOT CAUSE
Mirroring is applied after reordering using the visual position as a logical index.
THE FAILURE
Mirroring is applied after reordering using the visual position as a logical index.
Unsuccessful approach: Using the first character's level for all characters ignores mixed levels.
Case contract
Input [text, resolved levels]. Characters at odd levels with a mirror pair ( ) [ ] { } < > « » are replaced by their mirror, decided per logical character; then runs are reversed from the highest level to the lowest odd level. Return the visual string.
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
import itertools
N = 1
observations = []
def solve(x):
text, levels = x
M = {'(': ')', ')': '(', '[': ']', ']': '[', '{': '}', '}': '{', '<': '>', '>': '<', '«': '»', '»': '«'}
n = len(text)
glyphs = list(text)
order = list(range(n))
odd = [l for l in levels if l % 2]
if odd:
for lev in range(max(levels), min(odd) - 1, -1):
runs = []
for key, grp in itertools.groupby(order, key=lambda i: levels[i] >= lev):
g = list(grp)
runs.extend(g[::-1] if key else g)
order = runs
return ''.join(M.get(text[i], text[i]) if levels[v] % 2 == 1 else text[i] for v, i in enumerate(order))
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: mirror level lookup', ['y[]x}<()]a', [4, 4, 2, 1, 3, 3, 2, 2, 1, 3]], 'a[>{()xy[]'), ('regression: mirror level lookup', ['{»{»}(»a>', [2, 2, 2, 1, 4, 2, 2, 2, 4]], '}(»a>«{»{'), ('regression: mirror level lookup', [']]{)«)<x»<}[', [1, 4, 4, 4, 4, 1, 1, 1, 2, 2, 2, 3]], '»<}]x>(]{)«['), ('regression: mirror level lookup', ['[}a[y{]}»', [2, 1, 1, 3, 2, 2, 2, 2, 3]], ']y{]}«a{['), ('bracket at level two', ['(x)', [2, 2, 2]], '(x)'), ('guillemets RTL', ['«ab»', [1, 1, 1, 1]], '«ba»'), ('control layout', ['y<', [1, 1]], '>y'), ('control layout', ['ba', [3, 3]], 'ab')], [('regression: mirror level lookup', ['>[){x', [3, 3, 3, 3, 4]], 'x}(]<'), ('regression: mirror level lookup', ['»>x»', [1, 2, 2, 2]], '>x»«'), ('regression: mirror level lookup', ['}<a<(a>«]', [1, 1, 1, 2, 2, 2, 2, 2, 2]], '<(a>«]a>{'), ('regression: mirror level lookup', ['[]<<«y»]xb)', [2, 2, 2, 2, 2, 3, 3, 3, 3, 1, 3]], '(b[]<<«x[«y'), ('bracket in RTL run', ['a(b)', [1, 1, 1, 1]], '(b)a'), ('guillemets RTL', ['«ab»', [1, 1, 1, 1]], '«ba»'), ('control layout', ['»', [2]], '»'), ('control layout', ['«{>}]]ax}', [1, 1, 1, 1, 1, 1, 1, 1, 1]], '{xa[[{<}»')], [('regression: mirror level lookup', ['}«x[[ab', [1, 1, 1, 1, 2, 1, 1]], 'ba[]x»{'), ('regression: mirror level lookup', ['y«{»]<]', [2, 2, 2, 1, 1, 4, 4]], '<][«y«{'), ('regression: mirror level lookup', ['>b<x<b»b)b', [0, 0, 0, 0, 1, 1, 1, 1, 2, 2]], '>b<x)bb«b>'), ('partial-repair probe', [')}<)<>[(a', [0, 0, 0, 0, 3, 3, 3, 3, 1]], ')}<)a)]<>'), ('guillemets RTL', ['«ab»', [1, 1, 1, 1]], '«ba»'), ('bracket in RTL run', ['a(b)', [1, 1, 1, 1]], '(b)a'), ('control layout', ['ya[', [1, 1, 1]], ']ay'), ('bracket at level two', ['(x)', [2, 2, 2]], '(x)')], [('regression: mirror level lookup', ['ay]»y[', [2, 2, 2, 2, 1, 2]], '[yay]»'), ('regression: mirror level lookup', ['xx>>}(b]{]«', [1, 1, 2, 1, 3, 3, 3, 3, 1, 1, 3]], '»[}[b){<>xx'), ('regression: mirror level lookup', ['«])ay}xb', [2, 2, 2, 2, 2, 3, 3, 4]], '«])aybx{'), ('partial-repair probe', ['««a<>x{)}>', [1, 1, 2, 2, 2, 4, 2, 2, 1, 1]], '<{a<>x{)»»'), ('bracket in RTL run', ['a(b)', [1, 1, 1, 1]], '(b)a'), ('guillemets RTL', ['«ab»', [1, 1, 1, 1]], '«ba»'), ('control layout', ['a[', [1, 1]], ']a'), ('control layout', ['(x)](', [1, 1, 1, 1, 3]], ')[(x)')], [('regression: mirror level lookup', ['a]»y]«)<»<x)', [3, 3, 3, 2, 4, 2, 2, 2, 2, 1, 1, 1]], '(x>«[ay]«)<»'), ('regression: mirror level lookup', [']]b{{{)', [3, 2, 2, 1, 1, 1, 1]], '(}}}[]b'), ('regression: mirror level lookup', ['xy(»«y{(', [2, 2, 4, 3, 3, 3, 3, 1]], ')xy}y»«('), ('regression: mirror level lookup', ['y{]]>[[x>>', [1, 1, 1, 2, 2, 2, 2, 2, 1, 2]], '><]>[[x[}y'), ('bracket in RTL run', ['a(b)', [1, 1, 1, 1]], '(b)a'), ('bracket at level two', ['(x)', [2, 2, 2]], '(x)'), ('control layout', [')>b»', [1, 1, 1, 1]], '«b<('), ('control layout', ['«x', [3, 3]], 'x»')]]
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 |
|---|---|---|---|
| regression: mirror level lookup | a]<{)(xy][ | a[>{()xy[] | Failed |
| regression: mirror level lookup | }(»a>»{»{ | }(»a>«{»{ | Failed |
| regression: mirror level lookup | «<}[x>([{)«[ | »<}]x>(]{)«[ | Failed |
| regression: mirror level lookup | [y}[}»a}] | ]y{]}«a{[ | Failed |
| bracket at level two | (x) | (x) | Passed |
| guillemets RTL | «ba» | «ba» | Passed |
| control layout | >y | >y | Passed |
| control layout | ab | ab | Passed |
SHA-256 / 35dfc0fa383d8a4d38b8e92eccc6e4ea260de162104f5bea6cf8bffe8152c876
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
import itertools
N = 1
observations = []
def solve(x):
text, levels = x
M = {'(': ')', ')': '(', '[': ']', ']': '[', '{': '}', '}': '{', '<': '>', '>': '<', '«': '»', '»': '«'}
n = len(text)
glyphs = [M.get(ch, ch) if levels[0] % 2 == 1 else ch for i, ch in enumerate(text)]
order = list(range(n))
odd = [l for l in levels if l % 2]
if odd:
for lev in range(max(levels), min(odd) - 1, -1):
runs = []
for key, grp in itertools.groupby(order, key=lambda i: levels[i] >= lev):
g = list(grp)
runs.extend(g[::-1] if key else g)
order = runs
return ''.join(glyphs[i] for i in order)
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: mirror level lookup', ['y[]x}<()]a', [4, 4, 2, 1, 3, 3, 2, 2, 1, 3]], 'a[>{()xy[]'), ('regression: mirror level lookup', ['{»{»}(»a>', [2, 2, 2, 1, 4, 2, 2, 2, 4]], '}(»a>«{»{'), ('regression: mirror level lookup', [']]{)«)<x»<}[', [1, 4, 4, 4, 4, 1, 1, 1, 2, 2, 2, 3]], '»<}]x>(]{)«['), ('regression: mirror level lookup', ['[}a[y{]}»', [2, 1, 1, 3, 2, 2, 2, 2, 3]], ']y{]}«a{['), ('bracket at level two', ['(x)', [2, 2, 2]], '(x)'), ('guillemets RTL', ['«ab»', [1, 1, 1, 1]], '«ba»'), ('control layout', ['y<', [1, 1]], '>y'), ('control layout', ['ba', [3, 3]], 'ab')], [('regression: mirror level lookup', ['>[){x', [3, 3, 3, 3, 4]], 'x}(]<'), ('regression: mirror level lookup', ['»>x»', [1, 2, 2, 2]], '>x»«'), ('regression: mirror level lookup', ['}<a<(a>«]', [1, 1, 1, 2, 2, 2, 2, 2, 2]], '<(a>«]a>{'), ('regression: mirror level lookup', ['[]<<«y»]xb)', [2, 2, 2, 2, 2, 3, 3, 3, 3, 1, 3]], '(b[]<<«x[«y'), ('bracket in RTL run', ['a(b)', [1, 1, 1, 1]], '(b)a'), ('guillemets RTL', ['«ab»', [1, 1, 1, 1]], '«ba»'), ('control layout', ['»', [2]], '»'), ('control layout', ['«{>}]]ax}', [1, 1, 1, 1, 1, 1, 1, 1, 1]], '{xa[[{<}»')], [('regression: mirror level lookup', ['}«x[[ab', [1, 1, 1, 1, 2, 1, 1]], 'ba[]x»{'), ('regression: mirror level lookup', ['y«{»]<]', [2, 2, 2, 1, 1, 4, 4]], '<][«y«{'), ('regression: mirror level lookup', ['>b<x<b»b)b', [0, 0, 0, 0, 1, 1, 1, 1, 2, 2]], '>b<x)bb«b>'), ('partial-repair probe', [')}<)<>[(a', [0, 0, 0, 0, 3, 3, 3, 3, 1]], ')}<)a)]<>'), ('guillemets RTL', ['«ab»', [1, 1, 1, 1]], '«ba»'), ('bracket in RTL run', ['a(b)', [1, 1, 1, 1]], '(b)a'), ('control layout', ['ya[', [1, 1, 1]], ']ay'), ('bracket at level two', ['(x)', [2, 2, 2]], '(x)')], [('regression: mirror level lookup', ['ay]»y[', [2, 2, 2, 2, 1, 2]], '[yay]»'), ('regression: mirror level lookup', ['xx>>}(b]{]«', [1, 1, 2, 1, 3, 3, 3, 3, 1, 1, 3]], '»[}[b){<>xx'), ('regression: mirror level lookup', ['«])ay}xb', [2, 2, 2, 2, 2, 3, 3, 4]], '«])aybx{'), ('partial-repair probe', ['««a<>x{)}>', [1, 1, 2, 2, 2, 4, 2, 2, 1, 1]], '<{a<>x{)»»'), ('bracket in RTL run', ['a(b)', [1, 1, 1, 1]], '(b)a'), ('guillemets RTL', ['«ab»', [1, 1, 1, 1]], '«ba»'), ('control layout', ['a[', [1, 1]], ']a'), ('control layout', ['(x)](', [1, 1, 1, 1, 3]], ')[(x)')], [('regression: mirror level lookup', ['a]»y]«)<»<x)', [3, 3, 3, 2, 4, 2, 2, 2, 2, 1, 1, 1]], '(x>«[ay]«)<»'), ('regression: mirror level lookup', [']]b{{{)', [3, 2, 2, 1, 1, 1, 1]], '(}}}[]b'), ('regression: mirror level lookup', ['xy(»«y{(', [2, 2, 4, 3, 3, 3, 3, 1]], ')xy}y»«('), ('regression: mirror level lookup', ['y{]]>[[x>>', [1, 1, 1, 2, 2, 2, 2, 2, 1, 2]], '><]>[[x[}y'), ('bracket in RTL run', ['a(b)', [1, 1, 1, 1]], '(b)a'), ('bracket at level two', ['(x)', [2, 2, 2]], '(x)'), ('control layout', [')>b»', [1, 1, 1, 1]], '«b<('), ('control layout', ['«x', [3, 3]], 'x»')]]
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 |
|---|---|---|---|
| regression: mirror level lookup | a]<}()xy[] | a[>{()xy[] | Failed |
| regression: mirror level lookup | }(»a>»{»{ | }(»a>«{»{ | Failed |
| regression: mirror level lookup | «>{]x>([}(»[ | »<}]x>(]{)«[ | Failed |
| regression: mirror level lookup | [y{]}»a}[ | ]y{]}«a{[ | Failed |
| bracket at level two | (x) | (x) | Passed |
| guillemets RTL | «ba» | «ba» | Passed |
| control layout | >y | >y | Passed |
| control layout | ab | ab | Passed |
SHA-256 / 25b9b5b66995ef4d924cdad7f0607d101a9197f2dccd5d84bf1462f678e29f0b
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:54.895826+00:00.
Case digest / 233992c9a83428cbe5570b6e009a839264b8aedf55beaa091177a270316d9b53