Skip to content

TypeError: undefined is not an object (evaluating 'schema2._zod.def') - zod v3/v4 conflict when plugins bundle zod v4 #21155

@hrygo

Description

@hrygo

Describe the bug
When a plugin that depends on zod v4 is installed (e.g. oh-my-openagent), opencode crashes immediately with the following error when attempting to execute any tool:

TypeError: undefined is not an object (evaluating 'schema2._zod.def')
    at process (/$bunfs/root/src/cli/cmd/tui/worker.js:80980:29)
    at toJsoNschema (/$bunfs/root/src/cli/cmd/tui/worker.js:81668:15)

To Reproduce

  1. Install oh-my-openagent (depends on zod ^4.1.8)
  2. Add it to opencode.json: `"plugin": ["oh-my-openagent"]`
  3. Run `opencode`
  4. Type any instruction (e.g., "hello")
  5. Crash on first tool execution — any model, any plugin

Expected behavior
OpenCode should work normally with plugins that bundle zod v4.

Environment

  • opencode version: 1.3.16
  • OS: macOS 25.3.0
  • Plugin: oh-my-openagent@3.15.2 (zod ^4.1.8)

Root Cause Analysis
The bundled worker.js in opencode's Bun runtime internally uses zod v3's private API `_zod.def` in the `toJsonSchema` function (worker.js:81668). When a plugin brings in zod v4, zod v4 schemas are passed to this function, but zod v4 does not expose the same `_zod.def` internal structure. This causes `schema2` to be undefined.

Reproduction

  • `opencode --pure` (no plugins) → works perfectly
  • `opencode` with oh-my-openagent → crash on first tool

Possible Fixes

  1. Migrate internal `toJsonSchema` to use public zod APIs or a version-agnostic schema extraction approach
  2. Pin opencode's bundled zod to v4 to match the plugin ecosystem
  3. Isolate plugins' zod v4 from the global Bun module scope (module bundling/pinning)

Metadata

Metadata

Assignees

Labels

coreAnything pertaining to core functionality of the application (opencode server stuff)

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions