Repository navigation
fix(agent): resolve shared local $defs once in Express catalog instructions - #4492
Merged
gspencergoog merged 1 commit intoDec 3, 2026
Conversation
gspencergoog
force-pushed
the
fix-something/20261201-express-prompt-diamond-dag
branch
from
December 1, 2026 19:21
f35b07b to
7a542c6
Compare
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces a caching mechanism (SchemaTraversalCache) to ExpressPromptGenerator to optimize the resolution of local #/$defs/... schema definitions. Previously, resolving deeply nested or shared definitions through multiple branches (such as oneOf, anyOf, or allOf) resulted in exponential time complexity. By caching traversal results, these definitions are now resolved in linear time. The changes also include comprehensive unit tests to verify the performance improvement and correctness of the schema resolution. There are no review comments to address, and the implementation looks solid.
gspencergoog
marked this pull request as ready for review
December 1, 2026 21:11
ditman
approved these changes
Dec 3, 2026
…ctions `ExpressPromptGenerator` listed a property's map keys with three traversals that removed each schema from their visited set on the way back up, so a local definition reached through several `oneOf`, `anyOf`, or `allOf` branches was resolved once per path. A chain of definitions that each reference the next one twice took time exponential in its length: 21.6 s for an `allOf` chain of depth 16. Cache each schema node's result for one `generateComponentSignatures` call instead. A node reached again while it is being resolved still yields no result, which is what stops reference cycles. Output for acyclic schemas is unchanged.
gspencergoog
force-pushed
the
fix-something/20261201-express-prompt-diamond-dag
branch
from
December 3, 2026 17:24
7a542c6 to
f43daae
Compare
gspencergoog
enabled auto-merge (squash)
December 3, 2026 17:26
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Architecture & Contract Brief
resolveObjectProperties,resolveStructuredProperty, andisProtocolWireEnvelopein the TypeScript Express prompt generator removed each schema from their visited set on the way back up, so a local$defsdefinition was resolved once per path that reached it.dereferenceLocalSchemacalls at two chain depths. It failed before the fix and passes after.allOfdefinitions can resolve differently depending on which one is reached first.ExpressPromptGenerator.generateCatalogInstructionsin@a2ui/agentonly.Summary
ExpressPromptGenerator.generateCatalogInstructionstook time exponential in the depth of a chain of local$defswhen each definition referenced the next one through more than oneoneOf,anyOf, orallOfbranch. This PR caches each schema node's result for one call, which makes the work linear. The traversals were added in #4184.This fixes a downstream issue in Google code.
Reviewer Focus
SchemaTraversalCacheand the in-progress marker inprompt-generator.ts. An entry is written when a traversal enters a node and overwritten when it leaves. Entries are never removed, which is what removes the repeated work and also what changes results inside reference cycles.$refis followed.dereferenceLocalSchemareturns a new merged object for every$refnode, so two$refnodes that name one definition stay separate keys and the keys beside each$refstill apply to that node alone.hasWireEnvelopePropertiesanddirectObjectPropertiesare the existing rules moved into helpers, in the same order.Changes
prompt-generator.ts: replace the path-scopedvisitedsets of the three traversals with aSchemaTraversalCachethatgenerateComponentSignaturescreates once per call.isProtocolWireEnvelopenow takes the node before dereferencing and dereferences it itself.prompt-generator.test.ts: add a linear-work test foroneOf,anyOf, andallOfchains, and a test that a definition shared by two branches keeps its properties on the second visit.CHANGELOG.md: add anUnreleasedentry.Impact & Risks
allOfchain took 0.8 s at depth 12, 4.3 s at depth 14, and 21.6 s at depth 16. After the change, depth 30 takes about 1 ms for each of the three keywords.allOfdefinitions, the listed map keys and the wire-envelope classification of a definition inside the cycle can differ from before, and depend on which definition the traversal enters first. Self-referencing definitions resolve as before.Testing
yarn vitest run tests/unit tests/conformanceintypescript/agents/a2ui_agent: 53 files and 2038 tests pass.oneOfandanyOf) and 106523 calls against a limit of 2733 (allOf).eslinton the two changed TypeScript files,prettier --checkon the three changed files, and./scripts/fix_licenses.py --checkpass.scripts/e2e_test.shwas not run.Pre-launch Checklist
One time:
For this PR: