Skip to content

Risk-control compiler relies on locale encoding for UTF-8 definitions and output #84

Closed

Description

@lanyue-llk

The risk-control compiler reads locked UTF-8 Markdown/JSON and writes multilingual JSON using the process's default text encoding.

With UTF-8 mode and locale coercion disabled under a US-ASCII locale, parse_sections() raises UnicodeDecodeError on Chinese rules. The final ensure_ascii=False write can likewise fail or emit bytes inconsistent with consumers that explicitly read UTF-8.

Reproduced in the current candidate:

PYTHONUTF8=0 PYTHONCOERCECLOCALE=0 LC_ALL=C uv run --frozen python - <<'PY'
import locale, tempfile
from pathlib import Path
from lexbench_webfetch.risk_control_dataset import parse_sections
print(locale.getencoding())
with tempfile.TemporaryDirectory() as directory:
    rules = Path(directory) / 'rules.md'
    rules.write_bytes('# 中文规则\n'.encode('utf-8'))
    parse_sections((rules,))
PY

Observed: US-ASCII, then UnicodeDecodeError.

Expected: explicitly use UTF-8 for definition reads and compiled dataset writes. Add a non-UTF-8-locale subprocess control with UTF-8 mode disabled, covering both compilation and a UTF-8 consumer roundtrip.

This is inherited from the pinned pre-migration compiler: https://github.com/lexmount/lexbench-webfetch/blob/5a5b9367118dcc25f126ee16ef4de2d7c666f190/src/lexbench_webfetch/risk_control_dataset.py . The default-encoding reads and final write are unchanged; the migration changes definition discovery, not their encoding. Browser Eval already exposed this compiler before PR81.

Tracked separately from #81 under the maintainer's instruction to leave independent historical defects to follow-up issues.

Activity

  1. self-assigned this
    on Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions