Skip to content

[moonshot] v0.8.61 #3265 fix incomplete — parameters still missing type:object for $ref / anyOf / allOf root schemas #3281

@jghwwnq

Description

@jghwwnq

Description

The v0.8.61 fix for #3265 (sanitize_for_kimi_parameters) only adds "type": "object" to the parameters root when the schema matches a narrow set of conditions:

let root_object_schema = obj.is_empty()
    || obj.contains_key("properties")
    || obj.contains_key("required")
    || obj.contains_key("additionalProperties");

This means other valid JSON Schema root shapes are left without type — and Kimi/Moonshot still rejects them with the same 400 error:

  • {"$ref": "#/definitions/FileArgs"} — no type added
  • {"allOf": [...]} — no type added
  • {"anyOf": [...]} — no type added
  • {"oneOf": [...]} — no type added

Secondary issue: sanitize_for_kimi removes type from root

Even for schemas that DO get type: "object" injected, the subsequent sanitize_for_kimi pass removes type from the parent when anyOf/oneOf is present:

// sanitize_for_kimi, line 979-981:
let should_push = obj.contains_key("type") 
    && (obj.contains_key("anyOf") || obj.contains_key("oneOf"));
if should_push && let Some(type_val) = obj.remove("type") {
    // pushes type into items, removes from parent
}

This means a parameters schema like:

{"anyOf": [{"type": "object", "properties": {...}}, {"type": "null"}]}

After sanitize_for_kimi_parameters adds type → then sanitize_for_kimi removes it. Net result: no type at root → Kimi 400.

Reproduction

Same as #3265 — switch to Moonshot provider with kimi-k2.7-code, send any message. The error persists in v0.8.61 for tools whose parameters use $ref / anyOf / allOf / oneOf at root.

Suggested Fix

  1. sanitize_for_kimi_parameters: always add "type": "object" when missing, not just for the narrow root_object_schema shapes
  2. sanitize_for_kimi: when pushing type into anyOf/oneOf items, keep it on the parent instead of removing it — Kimi requires type at every level ([moonshot] tools.function.parameters.type is required and must be "object" — empty {} rejected by Kimi API #3265)

Environment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    Status
    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions