Skip to content

fix: handle JSON Schema union type lists in moonshot_schema (both crash sites)#28422

Open
zccyman wants to merge 1 commit into
NousResearch:mainfrom
atyou2happy:fix/moonshot-union-type-crash-28291
Open

fix: handle JSON Schema union type lists in moonshot_schema (both crash sites)#28422
zccyman wants to merge 1 commit into
NousResearch:mainfrom
atyou2happy:fix/moonshot-union-type-crash-28291

Conversation

@zccyman

@zccyman zccyman commented May 19, 2026

Copy link
Copy Markdown
Contributor

Problem

sanitize_moonshot_tools() raises TypeError: 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:

  1. _fill_missing_type (L169): node["type"] not in {None, ""} — the not in set membership check requires the operand to be hashable, which list is not.
  2. _repair_schema enum cleanup (L147): node_type in {"string", "integer", ...} — same issue.

The existing PR #28322 only addresses crash site 2. This PR fixes both.

Fix

  • L169: Add isinstance(t, list) guard — union types are valid declarations, return node as-is.
  • L147: Add 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 handling
  • tests/agent/test_moonshot_schema.py (+51): 4 new tests in TestUnionTypeList class

Testing

46 passed, 0 failed (including 4 new tests)

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
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent loop, run_agent.py, prompt builder provider/kimi Kimi / Moonshot labels May 19, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Supersedes #28322 — this PR fixes both crash sites in moonshot_schema.py (L169 _fill_missing_type + L147 _repair_schema enum cleanup), while #28322 only addresses crash site 2. Fixes #28291.

@zccyman

zccyman commented May 27, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @alt-glitch for the cross-reference. Noted that this PR fixes both crash sites in moonshot_schema.py (L169 _fill_missing_type + L147 _repair_schema enum cleanup), while #28322 only addresses crash site 2. Fixes #28291. Ready for review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent loop, run_agent.py, prompt builder P2 Medium — degraded but workaround exists provider/kimi Kimi / Moonshot type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: moonshot_schema._fill_missing_type crashes on JSON Schema union types (list type)

2 participants