Preserve boolean `$defs` semantics during schema transformation
This pull request was posted by Codex Desktop using gpt-6.1-sol on behalf of David.
Referenced boolean $defs entries crash inlining. OpenAI root references to true also crash, while a root reference to false can lose its rejecting constraint. See #8621.
New public surface
none
User-visible behavior
Before: inlining {'$ref': '#/$defs/X'} with $defs: {'X': False} raises TypeError. After: it produces {'not': {}}, which rejects every value.
Inlining resolves escaped $defs names exactly once, so encoded-name boolean decoys are not selected and encoded recursive root references stay intact. A referenced false definition becomes not: {} after sibling keywords. Singleton union folding retains that canonical rejecting member under allOf, anyOf, or oneOf. OpenAI true root references retain siblings; OpenAI rejects false root references before sending a request. Google OpenAPI rejects referenced false definitions before request construction.
The singleton-union fix changes folding only; traversal and dictionary merging are unchanged. General boolean nodes are unchanged. The matching-type traversal from #9561 and untyped Gemini Live properties remain unchanged; the latter is tracked in PR comment. Dictionary-root sibling merging remains tracked in PR comment.
Verification
test_inline_boolean_defscovers false definitions with sibling keywords.test_inline_boolean_defs_escaped_namesandtest_inline_dictionary_defs_escaped_namescover escaped-name boolean decoys, root/nested input preservation, and encoded recursive root references.test_inline_boolean_defs_single_member_unionchecks true and false union members.test_openai_boolean_root_toolreplays livegpt-4.1-miniChat and Responses recordings:trueroots call the tool with the expected wire schema;falseroots raise before HTTP.test_openai_boolean_root_defs_escaped_namesandtest_openai_dictionary_root_defs_escaped_namescover OpenAI escaped names and boolean decoys.test_google_inlined_boolean_definition_toolreplays a livegemini-3.8-flashGenerateContent recording: the true definition reaches the expectedparameters_json_schemaand completes a tool call; false is refused before HTTP.test_tool_def_rejects_false_definitionseparately unit-checks the Gemini Live adapter refusal before opening a socket; it makes no WebSocket acceptance claim.
Targeted schema regressions, Pyright, Ruff, and pre-commit pass.
What changes for existing users
Escaped references resolve to their intended definitions, and referenced false schemas keep rejecting during inlining. OpenAI refuses false root references; Google OpenAPI refuses referenced false definitions before request construction.
- Closes #8621
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.