Preserve boolean `$defs` semantics during schema transformation

Merged
DS
2mo ago
+1160-12

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

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.

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.