FAILURE MAP
← Case archive

FA-3031 / Text processing / Open access

A bounded replacement modifies every occurrence · case 01

A bounded replacement modifies every occurrence.

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: Replace at most the first two literal aa occurrences with X, nonoverlapping.

VERIFIED REPAIR

Implement the complete stated contract, including the boundary fixtures: Replace at most the first two literal aa occurrences with X, nonoverlapping.

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

Case contract

Replace at most the first two literal aa occurrences with X, nonoverlapping.

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.replace('aa','X')
    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('aaaaaa'), 'XXaa')
check('boundary 2', solve('aaaa'), 'XX')
check('boundary 3', solve('aaa'), 'Xa')
check('boundary 4', solve('b'), 'b')
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 1XXXXXaaFailed
boundary 2XXXXPassed
boundary 3XaXaPassed
boundary 4bbPassed

SHA-256 / 797f9077dc75c34d90d28e35884284c3568db07beb3d6e0fb2a10f1f492e174d

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:
        return x.replace('aa','X',1)
    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('aaaaaa'), 'XXaa')
check('boundary 2', solve('aaaa'), 'XX')
check('boundary 3', solve('aaa'), 'Xa')
check('boundary 4', solve('b'), 'b')
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 1XaaaaXXaaFailed
boundary 2XaaXXFailed
boundary 3XaXaPassed
boundary 4bbPassed

SHA-256 / e3eca6d5a8764b261fa0273b6a69ad1c8651bf0cf9e4d30ae79548a6abc7f98f

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:
        return x.replace('aa','X',2)
    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('aaaaaa'), 'XXaa')
check('boundary 2', solve('aaaa'), 'XX')
check('boundary 3', solve('aaa'), 'Xa')
check('boundary 4', solve('b'), 'b')
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 1XXaaXXaaPassed
boundary 2XXXXPassed
boundary 3XaXaPassed
boundary 4bbPassed

SHA-256 / 3b89cba71093c2ac6db8d1ab0bffc5fa9775dd0f9478b8d58c99fad8e5ba5996

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

Case digest / 8888e1e7ebdac986bd4ce5546bc6bd1e78e15b0fffa87997005cbd2917daf20c