Rewrite nested `$ref`s when merging JSON schema definitions
Merged
LI
1mo ago+103+103+012345678901234567890123456789-15-15-01234567890123456789
This pull request was posted by Codex Desktop using gpt-6-luna on behalf of David.
Why we make these changes
When output schemas have colliding $defs, the merge walker can leave references in six nested schema keywords pointing to another output type's definition. This can make a schema accept values of the wrong type. Closes #10589.
New public surface
none
User-visible behavior
Before: merged schemas could resolve nested references to the wrong definition. After: references in contains, if, then, else, dependentSchemas, and tuple-form items follow renamed definitions, including through shared definitions.
Verification
test_merge_json_schema_defs_nested_subschemascovers the six keywords, transitive references, input preservation, and boolean schemas.test_output_json_schema_contains_refs_preserve_branch_typescoversAgent.output_json_schema().- Targeted tests, Ruff, and targeted Pyright passed.
What changes for existing users
Merged output schemas preserve nested references to the intended definitions.
- Closes #10589
Checklist
- No breaking changes in accordance with the version policy.
- Any permitted compatibility impact has a label, warning, migration, release note, and exact API-check waiver. (Not applicable.)
- PR title is fit for the release changelog.