fix(strict-schema): preserve chained $ref during sibling-key expansion#3205
Merged
seratch merged 1 commit intoopenai:mainfrom May 8, 2026
Merged
fix(strict-schema): preserve chained $ref during sibling-key expansion#3205seratch merged 1 commit intoopenai:mainfrom
seratch merged 1 commit intoopenai:mainfrom
Conversation
When a $ref pointing to an alias definition (a $ref-only schema that
itself points to another definition) had sibling keys like `description`,
`ensure_strict_json_schema` silently dropped the inner $ref and lost
the actual type. The merge `{**resolved, **json_schema}` ran while
json_schema still contained its own $ref, so the resolved schema's
$ref was overwritten before the subsequent pop removed it entirely.
Pop the original $ref before the merge so the resolved schema's $ref
survives into the recursive expansion call, allowing the chain to
fully resolve.
Member
|
@codex review |
|
Codex Review: Didn't find any major issues. Can't wait for the next one! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
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.
Summary
When a
$refpointing to an alias definition (a$ref-only schema that itself points to another definition) had sibling keys likedescription,ensure_strict_json_schemasilently dropped the inner$refand lost the underlying type. The merge{**resolved, **json_schema}ran whilejson_schemastill contained its own$ref, so the resolved schema's$refwas overwritten by the original (now-stale)$ref, and the subsequentpop("$ref")then removed it entirely.This is a small, surgical fix: pop the original
$reffrom the schema before the merge so the resolved schema's$ref(if any) survives into the recursive expansion call. The recursive call then fully resolves the chain.Repro (failed before fix)
This pattern arises naturally when Pydantic models reference other models that are themselves thin aliases (e.g.
RootModel, generic aliases, type aliases that emit single-key$refdefinitions).Test plan
test_chained_ref_with_sibling_keys_is_resolvedintests/test_strict_schema.pyfails before the fix and passes after.tests/test_strict_schema.pyandtests/test_strict_schema_oneof.pytests still pass (19 passed).tests/test_function_schema.py,tests/test_agent_runner.py,tests/test_function_tool.py,tests/mcp/test_mcp_util.py(305 total passed, 0 failed).