Skip to content

fix: sanitize empty Gemini object requirements#11955

Open
jstar0 wants to merge 3 commits into
Kilo-Org:mainfrom
jstar0:fix/gemini-schema-required
Open

fix: sanitize empty Gemini object requirements#11955
jstar0 wants to merge 3 commits into
Kilo-Org:mainfrom
jstar0:fix/gemini-schema-required

Conversation

@jstar0

@jstar0 jstar0 commented Jul 6, 2026

Copy link
Copy Markdown

Summary

Fixes #11950.

Gemini rejects function declarations when a nested object schema has required entries that are not defined in that same node's properties. MCP tools can expose this shape through array item schemas, which makes the request fail before any model output.

Changes

  • Filter Gemini-facing object required arrays to names that exist in the same schema node's properties.
  • Drop required when an object schema has no properties, or when filtering leaves no valid required fields.
  • Add regression coverage for array item schemas without properties, including the Kilo Gateway Gemini route.

Verification

bun test ./test/provider/transform.test.ts
bun run typecheck
git diff --check HEAD^..HEAD -- packages/opencode/src/provider/transform.ts packages/opencode/test/provider/transform.test.ts

@kilo-code-bot

kilo-code-bot Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

The previous WARNING (missing changeset for this user-facing bug fix) is resolved: this update adds .changeset/gemini-mcp-schema-required.md (patch bump for @kilocode/cli) with a concise, user-facing description in imperative mood. No other changes were made in this update.

Files Reviewed (3 files)
  • .changeset/gemini-mcp-schema-required.md
  • packages/opencode/src/provider/transform.ts
  • packages/opencode/test/provider/transform.test.ts
Previous Review Summary (commit b07dff5)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit b07dff5)

Status: 1 Issue Found | Recommendation: Merge (non-blocking)

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 0

The fix itself is correct: it filters the Gemini-facing required array against the sibling properties node (falling back to an empty properties object, then dropping required entirely when it's empty), which addresses the reported Gemini 400 for object schemas without properties (e.g. MCP array-item schemas). The recursive sanitizer already covers nested schemas, so array items are handled. New tests exercise the real ProviderTransform.schema implementation (no mocks), including the Kilo Gateway Gemini route. The Kilo-specific fix is scoped with kilocode_change markers inline in the existing Gemini sanitizer block, consistent with how nearby small fixes in this file are handled, so no fork-hygiene extraction is warranted here.

Issue Details (click to expand)

WARNING

File Line Issue
.changeset/ N/A This fixes a user-facing bug (#11950: Gemini requests failing for certain MCP tool schemas) but the PR has no changeset file. Per repo convention, user-facing bug fixes should include a .changeset/*.md entry (patch) describing the fix for release notes.
Files Reviewed (2 files)
  • packages/opencode/src/provider/transform.ts
  • packages/opencode/test/provider/transform.test.ts

Reviewed by claude-sonnet-5-20260630 · Input: 14 · Output: 2.4K · Cached: 245.2K

Review guidance: REVIEW.md from base branch main

@johnnyeric johnnyeric requested a review from chrarnoldus July 7, 2026 10:58
@chrarnoldus chrarnoldus self-assigned this Jul 7, 2026

expect(result.properties.issue_fields.items.required).toBeUndefined()
})

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

please move the new tests to a new file in a kilocode folder

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.

Gemini + any MCP with non-trivial schema: HTTP 400 before any model output (sanitize MCP tool schemas for Gemini)

2 participants