Repository navigation
fix(dart/a2ui_agent): reject multiple v0.9 catalogs in Express format (#3341) - #4277
jihanurrahman33 wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the Dart Express compiler, decompiler, and prompt generator to enforce that multiple active catalogs are only supported when targeting A2UI v1.0 or later, introducing the checkMixedCatalogs helper to validate this constraint. The feedback highlights several redundant invocations of checkMixedCatalogs in compile, compileStep, decompile, and generate methods, noting that these checks are already performed during the instantiation of ExpressCompiler and ExpressDecompiler. Removing these duplicate validations will simplify the codebase and prevent unnecessary overhead, particularly in performance-sensitive streaming compilation paths.
| if (catalogs.isEmpty) { | ||
| throw A2uiCatalogError('Compiling Express needs at least one catalog.'); | ||
| } | ||
| checkMixedCatalogs(catalogs); |
There was a problem hiding this comment.
The call to checkMixedCatalogs is redundant here because the ExpressCompiler constructor already validates the catalogs upon instantiation. Removing this duplicate check simplifies the method and avoids redundant validation overhead.
| if (catalogs.isEmpty) { | |
| throw A2uiCatalogError('Compiling Express needs at least one catalog.'); | |
| } | |
| checkMixedCatalogs(catalogs); | |
| if (catalogs.isEmpty) { | |
| throw A2uiCatalogError('Compiling Express needs at least one catalog.'); | |
| } |
| if (compiler.catalogs.isEmpty) { | ||
| throw A2uiCatalogError('Compiling Express needs at least one catalog.'); | ||
| } | ||
| checkMixedCatalogs(compiler.catalogs); |
There was a problem hiding this comment.
The call to checkMixedCatalogs here is redundant and introduces unnecessary overhead. ExpressScopeSession is constructed with an ExpressCompiler instance, whose constructor already validates the catalogs. Since compileStep is called repeatedly for every chunk of streaming input, performing this validation on every step is inefficient.
| if (compiler.catalogs.isEmpty) { | |
| throw A2uiCatalogError('Compiling Express needs at least one catalog.'); | |
| } | |
| checkMixedCatalogs(compiler.catalogs); | |
| if (compiler.catalogs.isEmpty) { | |
| throw A2uiCatalogError('Compiling Express needs at least one catalog.'); | |
| } |
| if (catalogs.isEmpty) { | ||
| throw A2uiCatalogError('Decompiling Express needs at least one catalog.'); | ||
| } | ||
| checkMixedCatalogs(catalogs); |
There was a problem hiding this comment.
The call to checkMixedCatalogs is redundant here because the ExpressDecompiler constructor already validates the catalogs upon instantiation. Removing this duplicate check simplifies the method and avoids redundant validation overhead.
| if (catalogs.isEmpty) { | |
| throw A2uiCatalogError('Decompiling Express needs at least one catalog.'); | |
| } | |
| checkMixedCatalogs(catalogs); | |
| if (catalogs.isEmpty) { | |
| throw A2uiCatalogError('Decompiling Express needs at least one catalog.'); | |
| } |
| if (catalogs.isEmpty) { | ||
| throw A2uiCatalogError('An Express prompt needs at least one catalog.'); | ||
| } | ||
| checkMixedCatalogs(catalogs); |
There was a problem hiding this comment.
The call to checkMixedCatalogs is redundant here because ExpressDecompiler(catalogs) is instantiated immediately on the next line, and its constructor already performs this exact validation. Removing this duplicate check simplifies the method and avoids redundant validation overhead.
| if (catalogs.isEmpty) { | |
| throw A2uiCatalogError('An Express prompt needs at least one catalog.'); | |
| } | |
| checkMixedCatalogs(catalogs); | |
| if (catalogs.isEmpty) { | |
| throw A2uiCatalogError('An Express prompt needs at least one catalog.'); | |
| } |
|
Thanks @gemini-code-assist! The redundant calls to |
|
Thanks for the update, @jihanurrahman33. It's great to hear that the redundant calls have been cleaned up and that the test suite remains robust. This change significantly improves the maintainability of the Express components by centralizing the catalog validation logic. Everything looks solid. |
📖 Docs Site Preview DeployedPreview URL: https://a2ui.org/pr-preview/pr-4277/ Built from commit |
gspencergoog
left a comment
There was a problem hiding this comment.
This PR adds checkMixedCatalogs in dart/a2ui_agent/lib/src/utils/catalogs.dart and calls it from the ExpressFormat, ExpressCompiler, and ExpressDecompiler constructors so that binding multiple catalogs targeting a protocol version before v1.0 throws A2uiCatalogError, fixing #3341. It also removes the obsolete _catalogsV0_9 multi-catalog prompt section from ExpressPromptGenerator, updates Dart unit and conformance tests for single-catalog v0.9 Express, and removes the outdated Dart v1.0 limitation note from specification/proposals/express/a2ui_express.md.
The runtime validation, conformance test updates, and specification edit match the Python and TypeScript SDKs, and all Dart/Flutter, format, static, and docs CI checks pass at 2adc57fa (health / changelog / run changelog health check failed due to no changelog entry). All four prior gemini-code-assist threads were cleanly addressed in 2adc57fa. Two low-severity documentation findings note constructor and helper doc comments that omit incompatible-version or A2uiCatalogError details. Citation audit: 0 critical/high findings checked.
🤖 Agent-generated
| /// In Express, when several catalogs are active, components and function calls | ||
| /// carry per-item `catalogId` fields, which requires A2UI v1.0 or later. | ||
| /// | ||
| /// Throws [A2uiCatalogError] if any catalog id repeats, or if several catalogs |
There was a problem hiding this comment.
checkMixedCatalogs calls catalogsProtocolVersion(catalogs) when catalogs.length > 1. That helper also throws A2uiCatalogError when the catalogs target incompatible protocol versions. Callers reading the docstring miss that passing catalogs of different protocol versions throws A2uiCatalogError.
| /// Throws [A2uiCatalogError] if any catalog id repeats, or if several catalogs | |
| /// Throws [A2uiCatalogError] if any catalog id repeats, if the catalogs target | |
| /// different protocol versions, or if several catalogs |
Details
Evidence (Read): dart/a2ui_agent/lib/src/utils/catalogs.dart:75-80 states /// Throws [A2uiCatalogError] if any catalog id repeats, or if several catalogs / /// target a version before v1.0. while line 80 calls catalogsProtocolVersion(catalogs), which throws A2uiCatalogError when catalogs target incompatible protocol versions (dart/a2ui_agent/lib/src/utils/catalogs.dart:42-45).
🤖 Agent-generated
| /// The first of [catalogs] is the default for a surface that does not name | ||
| /// its catalog. | ||
| ExpressCompiler(this.catalogs); | ||
| ExpressCompiler(this.catalogs) { |
There was a problem hiding this comment.
ExpressCompiler now calls checkMixedCatalogs(catalogs) in its constructor instead of compile(). Its constructor docstring does not document that construction throws A2uiCatalogError. Callers instantiating ExpressCompiler are not warned that construction throws A2uiCatalogError on duplicate IDs, mismatched versions, or multiple pre-v1.0 catalogs.
| ExpressCompiler(this.catalogs) { | |
| /// | |
| /// Throws [A2uiCatalogError] if two of [catalogs] share an id, if they | |
| /// target different protocol versions, or if several target a version before | |
| /// v1.0. | |
| ExpressCompiler(this.catalogs) { |
Details
Evidence (Read): dart/a2ui_agent/lib/src/inference_formats/express/compiler.dart:151-155 adds checkMixedCatalogs(catalogs); to ExpressCompiler(this.catalogs) and line 182 removes or they target different versions from compile(), leaving the constructor without a Throws [A2uiCatalogError] comment.
The same constructor contract update applies to ExpressDecompiler(this.catalogs) (decompiler.dart:58-62), ExpressFormat (format.dart:66, 80), and ExpressFormatFactory.createFormat (format.dart:45). Also, the sentence The first of [catalogs] is the default for a surface that does not name its catalog. on ExpressCompiler, ExpressDecompiler, ExpressFormat, ExpressParser, and ExpressPromptGenerator is left over from pre-v1.0 multi-catalog support. Pre-v1.0 now allows only one catalog, and v1.0 multi-catalog surfaces have no default catalog (compiler.dart:330-338).
🤖 Agent-generated
Fixes #3341
Summary of Changes
Enforces
A2uiCatalogErrorwhen multiple catalogs are passed below v1.0 across Dart Express components (ExpressFormat,ExpressCompiler,ExpressDecompiler,ExpressPromptGenerator), matching Python (check_mixed_catalogs) and TypeScript (checkMixedCatalogs).dart/a2ui_agent/lib/src/utils/catalogs.dart:checkMixedCatalogs(List<CatalogApi> catalogs)which verifies distinct catalog IDs and requires protocol versionv1.0or later when multiple catalogs are active.dart/a2ui_agent/lib/src/inference_formats/express/:format.dart: ReplacedcheckDistinctIdswithcheckMixedCatalogs.compiler.dart: EnforcedcheckMixedCatalogsinExpressCompilerconstructor,compile(), andcompileIncremental().decompiler.dart: EnforcedcheckMixedCatalogsinExpressDecompilerconstructor anddecompile().prompt_generator.dart: EnforcedcheckMixedCatalogsinExpressPromptGenerator.generate()and removed legacy non-standard v0.9 multi-catalog prompt generator helper_catalogsV0_9.dart/a2ui_agent/test/:test_express_create_format_rejects_several_v0_9_catalogsinrequest_processor_conformance_test.dart._ONE_CATALOG_PER_SURFACEhandling inlowering.py).express_test.dart,express_decompiler_test.dart, andgenerator_test.dartto assert that multiple v0.9 catalogs throwA2uiCatalogError.specification/proposals/express/a2ui_express.md:Verification
dart analyzeacrossdart/a2ui_agent: 0 issues found.dart formatacrossdart/a2ui_agent: clean.dart testacrossdart/a2ui_agent: all 1,934 tests passed.dart testacrossdart/a2ui_core: all 2,405 tests passed.