fix: handle JSON Schema union type lists in moonshot_schema (both crash sites)#28422
Open
zccyman wants to merge 1 commit into
Open
fix: handle JSON Schema union type lists in moonshot_schema (both crash sites)#28422zccyman wants to merge 1 commit into
zccyman wants to merge 1 commit into
Conversation
Two crash sites in agent/moonshot_schema.py raised TypeError when a
tool parameter used JSON Schema union types (type: ["number", "string"]):
1. _fill_missing_type (L169): node["type"] not in {None, ""} fails when
type is a list (unhashable). Fix: add isinstance(t, list) guard to
treat union types as valid declarations and return early.
2. _repair_schema enum cleanup (L147): node_type in {scalar types} fails
when node_type is a list. Fix: add isinstance(node_type, str) guard
so enum cleanup only applies to scalar types.
The competing PR NousResearch#28322 only addressed crash site 2. This fix covers
both, with 4 tests covering:
- _fill_missing_type preserves list types
- _fill_missing_type still infers for missing types
- _repair_schema enum cleanup skips list types
- End-to-end sanitize pipeline with union-type parameters
Fixes NousResearch#28291
Collaborator
This was referenced May 19, 2026
Closed
This was referenced May 23, 2026
Contributor
Author
|
Thanks @alt-glitch for the cross-reference. Noted that this PR fixes both crash sites in |
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.
Problem
sanitize_moonshot_tools()raisesTypeError: unhashable type: 'list'when a tool parameter uses JSON Schema union types like"type": ["number", "string"]. This is a non-retryable error that completely blocks any conversation using kimi-* models when the toolset contains union-type parameters.Fixes #28291
Root Cause
Two crash sites in
agent/moonshot_schema.py:_fill_missing_type(L169):node["type"] not in {None, ""}— thenot inset membership check requires the operand to be hashable, whichlistis not._repair_schemaenum cleanup (L147):node_type in {"string", "integer", ...}— same issue.The existing PR #28322 only addresses crash site 2. This PR fixes both.
Fix
isinstance(t, list)guard — union types are valid declarations, return node as-is.isinstance(node_type, str)guard — enum cleanup only applies to scalar types.Changes
agent/moonshot_schema.py(+14/-3): Two isinstance guards for list-type handlingtests/agent/test_moonshot_schema.py(+51): 4 new tests inTestUnionTypeListclassTesting