Skip to content

Custom tool with tool.schema.number() argument crashes with "Cannot read properties of undefined (reading 'split')" #38956

Closed as not planned

Description

@gfoureau

Description

Description

Custom tools defined via @opencode-ai/plugin crash with Cannot read properties of undefined (reading 'split') when the tool's args schema includes a tool.schema.number() field and the LLM calls the tool with an argument for that field. Tools with no arguments work fine. Tools using only tool.schema.string() arguments also work fine — the crash is specific to the number type.

Environment

  • opencode version: 1.18.5 (macOS, darwin/fs-events backend)
  • @opencode-ai/plugin version: 1.18.5 (also reproduced on 1.18.4)
  • Reproduced with two different models/providers: deepseek-v4-flash-free and Gemini 3.5 — not model-specific.
  • Tool loaded from a project-local .opencode/tools/game.ts

Expected behavior

Tool executes and returns 9.

Actual behavior

Cannot read properties of undefined (reading 'split')

The agent then silently falls back to computing the sum itself in text, without surfacing the error clearly to the user (only a one-line inline error appears before the tool result).

Workaround found

Changing both args to tool.schema.string() and converting inside execute avoids the crash entirely:

export const add = tool({
  description: "Add two numbers",
  args: {
    a: tool.schema.string().describe("First number"),
    b: tool.schema.string().describe("Second number"),
  },
  async execute(args) {
    return String(Number(args.a) + Number(args.b))
  },
})

This strongly suggests the bug is in the Zod→JSON-Schema conversion path specific to the number type when serializing the tool schema for the model/provider, not in the model's tool-calling behavior itself (reproduced across two unrelated providers).

Additional notes

  • No matching stack trace appears in ~/.local/share/opencode/log/*.log — the error appears to be caught/displayed only in the session UI, not logged at ERROR level, which made this harder to trace. Might be worth logging the full stack trace for tool execution errors.
  • Happy to provide more detail or test a patch if useful.

Plugins

No response

OpenCode version

1.18.5

Steps to reproduce

  1. Create .opencode/tools/game.ts:
import { tool } from "@opencode-ai/plugin"

export default tool({
  description: "ping",
  args: {},
  async execute() { return "pong" },
})

export const add = tool({
  description: "Add two numbers",
  args: {
    a: tool.schema.number().describe("First number"),
    b: tool.schema.number().describe("Second number"),
  },
  async execute(args) {
    return args.a + args.b
  },
})
  1. Start opencode in the project directory, confirm the file loads (no Cannot find module errors, npm install completed successfully in .opencode).
  2. Prompt: "add 3 and 6" (triggers game_add).

Screenshot and/or share link

No response

Operating System

macOS 26.5.2

Terminal

No response

Activity

  1. github-actions commented on Sep 25, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

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

Metadata

Metadata

Assignees

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