Skip to content

fix(kimi): add missing required arrays to tool schemas#2001

Open
cuipengcx90 wants to merge 1 commit into
MoonshotAI:mainfrom
cuipengcx90:fix/kimi-required-arrays
Open

fix(kimi): add missing required arrays to tool schemas#2001
cuipengcx90 wants to merge 1 commit into
MoonshotAI:mainfrom
cuipengcx90:fix/kimi-required-arrays

Conversation

@cuipengcx90

Copy link
Copy Markdown

Related Issue

Related to #792 and #1610, but addresses a distinct schema-validation case.

PR #1720 sanitizes entries in an existing required array. This PR handles object schemas where the required property is absent.

Problem

Standard JSON Schema permits object schemas to omit required. Kimi-compatible APIs apply stricter Moonshot-flavored JSON Schema validation and may reject tool definitions before execution with required must be an array when a root or nested object node omits the property.

Kimi Code already normalizes local references and missing type fields for this provider, but it forwards missing required properties unchanged.

What changed

  • Add required: [] to explicitly typed or inferred object nodes only when the property is absent.
  • Preserve existing required values, including invalid values that should remain visible to downstream validation.
  • Apply the same normalization in the Kosong and agent-core-v2 Kimi provider paths.
  • Cover root objects, nested properties, array items, allOf/anyOf/oneOf branches, existing and invalid required values, non-object schemas, input immutability, and provider request conversion.
  • Add a patch changeset for @moonshot-ai/kimi-code.

Validation

  • Kosong suite: 1,283 tests passed.
  • Kimi-focused suites: 147 tests passed.
  • agent-core-v2 suite: 3,694 tests passed; one unrelated timing-sensitive plan event snapshot failed in the full parallel run and passed when rerun in isolation.
  • Root pnpm typecheck: passed.
  • Root pnpm lint: exited successfully; changed files have zero warnings and zero errors under type-aware lint.
  • git diff --check: passed.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

@changeset-bot

changeset-bot Bot commented Jul 21, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 29164b0

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 29164b0f9e

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

return;
}

if (node['type'] === 'object' && !hasOwn(node, 'required')) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Treat undefined required as missing

When a tool schema is built with an own required: undefined property (for example from a computed optional schema field), this guard treats it as present and skips adding []; the OpenAI client serializes JSON with undefined fields omitted, so the Kimi request still goes out without any required array and hits the same required must be an array rejection. The mirrored agent-core-v2 normalizer has the same guard, so both provider paths need to consider undefined missing while still preserving other invalid values if desired.

Useful? React with 👍 / 👎.

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