Skip to content

fix(a2ui): pin schema_manager file reads to UTF-8#2911

Open
genisis0x wants to merge 2 commits into
ag2ai:mainfrom
genisis0x:fix/a2ui-schema_manager-utf8
Open

fix(a2ui): pin schema_manager file reads to UTF-8#2911
genisis0x wants to merge 2 commits into
ag2ai:mainfrom
genisis0x:fix/a2ui-schema_manager-utf8

Conversation

@genisis0x

Copy link
Copy Markdown
Contributor

Problem

A2UISchemaManager in autogen/agents/experimental/a2ui/schema_manager.py loads JSON and text files from disk through five call sites:

  • the custom catalog file passed by the caller (line 105);
  • _load_spec_json and _load_spec_text reading the upstream A2UI spec bundle (lines 228, 236);
  • _load_version_json and _load_version_text reading the version-pinned schemas (lines 243, 251).

None of these passed an explicit encoding, so on platforms whose default locale.getencoding() is not UTF-8 — notably Windows, which defaults to cp1252 / cp932 — non-ASCII bytes in catalog descriptions, component labels, or rule files raise UnicodeDecodeError mid-load and A2UISchemaManager.__init__ fails before the manager can be constructed.

JSON is defined over UTF-8 (RFC 8259 §8.1), and the .md rule files follow the same convention.

Change

  • autogen/agents/experimental/a2ui/schema_manager.py — pass encoding="utf-8" at every file-read call site. No behavioural changes.
  • test/agents/experimental/a2ui/test_schema_manager.py — new regression test test_custom_catalog_file_load_handles_non_ascii writing a catalog with Chinese ("智能按钮") and accented Latin ("Composant interactif — étiquette") characters across both the catalog $id and a nested component description, then asserting the loaded schema round-trips bit-for-bit.

Same pattern as the previously-merged UTF-8 encoding pins (#2815, #2818, #2819, #2825, #2826, #2827) and the matching pins in #2909 / #2910.

Validation

  • uv run python -m pytest test/agents/experimental/a2ui/test_schema_manager.py -v15/15 pass (including new test).
  • uv run ruff check autogen/agents/experimental/a2ui/schema_manager.py test/agents/experimental/a2ui/test_schema_manager.py — clean.
  • uv run ruff format --check ... — already formatted.

Note: the a2ui test module is gated on the a2a optional dependency (a2a-sdk>=1.0.0,<2); installed locally via uv pip install before running the suite.

AI assistance

Diff drafted with assistance and reviewed end-to-end against the existing UTF-8 pin convention used in the surrounding codebase. The regression test exercises the catalog file-load branch with mixed-script bytes through both the $id and a nested component description, mirroring the read-side tests added in #2909 / #2910.

genisis0x added 2 commits May 28, 2026 17:00
A2UISchemaManager loads JSON and text files from disk through five
open() / Path() call sites — the custom catalog passed by the caller
and the four internal _load_spec_json / _load_spec_text /
_load_version_json / _load_version_text helpers that read the
upstream A2UI spec bundle and the version-pinned schemas. None of
the call sites passed an explicit encoding, so on platforms whose
default locale.getencoding() is not UTF-8 — notably Windows, which
defaults to cp1252 / cp932 — non-ASCII bytes in catalog descriptions,
component labels, or rule files raise UnicodeDecodeError mid-load
and the schema manager fails to construct.

JSON is defined over UTF-8 (RFC 8259 §8.1) and the .md rule files
follow the same convention, so pin encoding='utf-8' at every call
site.

Adds test_custom_catalog_file_load_handles_non_ascii exercising the
custom-catalog file-load branch with a payload that mixes Chinese
('智能按钮') and accented Latin ('Composant interactif — étiquette')
characters across both the catalog $id and a nested component
description. Asserts the loaded schema round-trips bit-for-bit.

Local: uv run pytest test/agents/experimental/a2ui/test_schema_manager.py
-- 15/15 green (incl. new test). ruff check + format clean.
The non-ASCII regression test's tmp_path fixture lacked a type
annotation, tripping mypy no-untyped-def in the type-check CI. Annotate
it as Path, matching the existing fixture convention in the test suite.
@codecov

codecov Bot commented May 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
autogen/agents/experimental/a2ui/schema_manager.py 82.19% <100.00%> (+82.19%) ⬆️

... and 535 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant