FAILURE MAP
← Case archive

FA-3756 / Parsing / Open access

Balanced delimiters close in the wrong nesting order · case 01

Balanced delimiters close in the wrong nesting order.

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

ROOT CAUSE

The implementation applies an operation whose text or grammar semantics violate this contract: Validate only round and square brackets using proper type-matched nesting.

VERIFIED REPAIR

Implement the complete stated contract, including the boundary fixtures: Validate only round and square brackets using proper type-matched nesting.

Unsuccessful approach: The attempted repair handles the primary example but still violates a separate boundary of the same contract.

Case contract

Validate only round and square brackets using proper type-matched nesting.

Why this case matters

A local executable model for consumers of structured text; oracle values are authored literals, not outputs copied from the repaired implementation.

1 / The failure

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
import re, unicodedata, json, csv, io, html, base64, binascii, codecs, struct
from urllib.parse import quote, unquote, unquote_to_bytes, urlencode, parse_qsl, urlsplit, urlunsplit
from email.header import decode_header, make_header
from email.utils import getaddresses
from xml.etree import ElementTree as ET
import shlex, string, textwrap

N = 1
observations = []
def solve(x):
    try:
        return x.count('(')==x.count(')') and x.count('[')==x.count(']')
    except Exception as exc:
        return {"error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('boundary 1', solve('([)]'), False)
check('boundary 2', solve('(]'), False)
check('boundary 3', solve('([])'), True)
check('boundary 4', solve(''), True)
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
boundary 1TrueFalseFailed
boundary 2FalseFalsePassed
boundary 3TrueTruePassed
boundary 4TrueTruePassed

SHA-256 / cb460f686992df01b3d75f33505a2f82a859c74dc5b2b71d786fad53e41d6431

2 / The unsuccessful fix

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
import re, unicodedata, json, csv, io, html, base64, binascii, codecs, struct
from urllib.parse import quote, unquote, unquote_to_bytes, urlencode, parse_qsl, urlsplit, urlunsplit
from email.header import decode_header, make_header
from email.utils import getaddresses
from xml.etree import ElementTree as ET
import shlex, string, textwrap

N = 1
observations = []
def solve(x):
    try:
        depth=0
        for c in x:
            depth+=1 if c in '([' else -1
            if depth<0: return False
        return depth==0
    except Exception as exc:
        return {"error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('boundary 1', solve('([)]'), False)
check('boundary 2', solve('(]'), False)
check('boundary 3', solve('([])'), True)
check('boundary 4', solve(''), True)
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
boundary 1TrueFalseFailed
boundary 2TrueFalseFailed
boundary 3TrueTruePassed
boundary 4TrueTruePassed

SHA-256 / 0d964738d23cec465c2ca726368cc3a94cdd6cc7f6171a006fb9163923151e53

3 / The verified repair

Exit 0
"""Failure Map reference implementation. Python standard library only."""
import json
import re, unicodedata, json, csv, io, html, base64, binascii, codecs, struct
from urllib.parse import quote, unquote, unquote_to_bytes, urlencode, parse_qsl, urlsplit, urlunsplit
from email.header import decode_header, make_header
from email.utils import getaddresses
from xml.etree import ElementTree as ET
import shlex, string, textwrap

N = 1
observations = []
def solve(x):
    try:
        stack=[]
        for c in x:
            if c in '([': stack.append(c)
            elif not stack or stack.pop()!= {')':'(',']':'['}[c]: return False
        return not stack
    except Exception as exc:
        return {"error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('boundary 1', solve('([)]'), False)
check('boundary 2', solve('(]'), False)
check('boundary 3', solve('([])'), True)
check('boundary 4', solve(''), True)
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
boundary 1FalseFalsePassed
boundary 2FalseFalsePassed
boundary 3TrueTruePassed
boundary 4TrueTruePassed

SHA-256 / e903cfb2223b9bf21d116a6cb2afbc1de26c38959a39f1000bd6fd43cd7c7e7d

Verification & scope

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

Case digest / 9d7c56817a397d6dabd4ae24c68957d331ea43abc32d9bb16725f508de48e112