Skip to content

fix(openai-chat): strip $ref siblings from tool schemas for Moonshot - #15

Merged
pavelhov merged 1 commit into
mainfrom
codex/moonshot-ref-sibling-schema
Aug 20, 2026
Merged

fix(openai-chat): strip $ref siblings from tool schemas for Moonshot#15
pavelhov merged 1 commit into
mainfrom
codex/moonshot-ref-sibling-schema

Conversation

@pavelhov

Copy link
Copy Markdown
Owner

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).

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).
@pavelhov
pavelhov merged commit 3e4ad27 into main Aug 20, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant