Skip to content

convertConstToEnum emits non-string enum values (const: false -> enum: [false]); Gemini rejects with 400 TYPE_STRING #17

Description

@willowite

Summary

convertConstToEnum() turns every const into enum: [value], including boolean and number constants. Gemini accepts only string enum values, so any request that carries a tool with const: true / const: false (common in discriminated unions from MCP tools) is rejected with HTTP 400 before the model runs.

Error

Invalid value at 'request.tools[0].function_declarations[194].parameters.properties[0].value.items.any_of[0].properties[12].value.enum[0]' (TYPE_STRING), false
Invalid value at 'request.tools[0].function_declarations[195].parameters.properties[0].value.items.one_of[0].properties[10].value.properties[0].value.enum[0]' (TYPE_STRING), true
... (18 lines like this per request)
Status: 400

Every request with the full tool set fails, so the model is unusable as a subagent until the offending tools are removed.

Where

packages/opencode/src/plugin/request-helpers.ts, convertConstToEnum() on main:

if (key === 'const' && !schema.enum) {
  result.enum = [value]   // value may be boolean or number
}

Repro

Any tool whose JSON schema contains { "const": false } (or true, or a number), for example:

{ "type": "object", "properties": { "flag": { "const": false } } }

sent to google/antigravity-gemini-3.8-flash (effective gemini-3.8-flash-high).

Suggested fix

Convert only string constants, and leave non-string const without an enum (Gemini keeps the declared type):

if (key === 'const' && !schema.enum) {
  if (typeof value === 'string') {
    result.enum = [value]
  }
}

I run this change locally on 2.2.1 and the same tool set is accepted.

Environment

  • @cortexkit/opencode-antigravity-auth 2.2.1 (latest on npm)
  • OpenCode 1.18.31, Windows 11

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions