[PR #13150] fix(provider): infer type 'object' for schemas with properties but missing type in Gemini sanitization #14530

Open
opened 2026-02-16 18:19:19 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/13150

State: open
Merged: No


Summary

Follow-up to #11888. sanitizeGemini strips properties/required from non-object types, but misses the case where type is entirely undefined (undefined).

Fixes #13148

Problem

The current check:

if (result.type && result.type !== "object") {
  delete result.properties
  delete result.required
}

When type is undefined, result.type && ... short-circuits to false, so properties/required are not removed. MCP tools like Notion MCP define schemas where type is omitted but properties/required are present (valid per JSON Schema spec as implicit objects):

{
  "data": {
    "description": "The data required for updating a page",
    "properties": { "page_id": { "type": "string" } },
    "required": ["page_id"]
  }
}

This causes:

Bad Request: GenerateContentRequest.tools[0].function_declarations[90].parameters.properties[data].properties: only allowed for OBJECT type

Solution

Infer type: "object" when properties or required exist but type is missing, before the existing non-object stripping logic:

if (!result.type && (result.properties || result.required)) {
  result.type = "object"
}

Changes

  • packages/opencode/src/provider/transform.ts: Added 4 lines to infer missing type
  • packages/opencode/test/provider/transform.test.ts: Added 2 test cases for missing type inference

Related Issues

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/13150 **State:** open **Merged:** No --- ## Summary Follow-up to #11888. `sanitizeGemini` strips `properties`/`required` from non-object types, but **misses the case where `type` is entirely undefined** (`undefined`). Fixes #13148 ## Problem The current check: ```typescript if (result.type && result.type !== "object") { delete result.properties delete result.required } ``` When `type` is `undefined`, `result.type && ...` short-circuits to `false`, so `properties`/`required` are **not removed**. MCP tools like Notion MCP define schemas where `type` is omitted but `properties`/`required` are present (valid per JSON Schema spec as implicit objects): ```json { "data": { "description": "The data required for updating a page", "properties": { "page_id": { "type": "string" } }, "required": ["page_id"] } } ``` This causes: ``` Bad Request: GenerateContentRequest.tools[0].function_declarations[90].parameters.properties[data].properties: only allowed for OBJECT type ``` ## Solution Infer `type: "object"` when `properties` or `required` exist but `type` is missing, before the existing non-object stripping logic: ```typescript if (!result.type && (result.properties || result.required)) { result.type = "object" } ``` ## Changes - `packages/opencode/src/provider/transform.ts`: Added 4 lines to infer missing type - `packages/opencode/test/provider/transform.test.ts`: Added 2 test cases for missing type inference ## Related Issues - #13148 - Follow-up to #11888 / #11889
yindo added the pull-request label 2026-02-16 18:19:19 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#14530