fix(openai-chat): strip $ref siblings from tool schemas for Moonshot - #15
Merged
Conversation
Moonshot's strict validator 400s any schema node carrying a $ref next to
sibling keys ("At path '$defs.__schema20': when using $ref, type should be
defined in the referenced schema instead of the parent schema"). Codex emits
exactly that shape for deferred/dynamic tools with recursive parameter
schemas, which bricked every Kimi-routed session the moment such a tool was
loaded via tool_search (e.g. the thread-management tools).
Walk tool parameter schemas recursively for Moonshot targets and inline local
$ref targets when siblings are present. Bare $refs are left untouched so
recursive schemas keep working; unresolvable or cyclic refs collapse to the
bare ref (dropping the siblings) instead of producing a 400.
Gated to api.moonshot.ai/.cn and api.kimi.com: pre-2019-09 JSON Schema
ignores $ref siblings, so rewriting them globally would silently change
meaning for other providers. Shares the local JSON Pointer resolver with the
xAI root expansion (renamed resolveLocalSchemaRef); the two normalizers stay
separate because the providers reject different shapes with different failure
policies (xAI drops non-object roots; Moonshot must never drop tools).
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.
Moonshot's strict validator 400s any schema node carrying a $ref next to sibling keys ("At path '$defs.__schema20': when using $ref, type should be defined in the referenced schema instead of the parent schema"). Codex emits exactly that shape for deferred/dynamic tools with recursive parameter schemas, which bricked every Kimi-routed session the moment such a tool was loaded via tool_search (e.g. the thread-management tools).
Walk tool parameter schemas recursively for Moonshot targets and inline local $ref targets when siblings are present. Bare $refs are left untouched so recursive schemas keep working; unresolvable or cyclic refs collapse to the bare ref (dropping the siblings) instead of producing a 400.
Gated to api.moonshot.ai/.cn and api.kimi.com: pre-2019-09 JSON Schema ignores $ref siblings, so rewriting them globally would silently change meaning for other providers. Shares the local JSON Pointer resolver with the xAI root expansion (renamed resolveLocalSchemaRef); the two normalizers stay separate because the providers reject different shapes with different failure policies (xAI drops non-object roots; Moonshot must never drop tools).