anomalyco / anomalyco/opencode

Recursive $ref in postgres tool schemas breaks Meta Muse Spark ("Recursive JSON schemas are not currently supported")

Open
#45,800 1 comment 0 reactions 1 assignee View on GitHub

@fwang is already working on this.

Since Aug 28, 2026.

Dominant language
TypeScript
Stars
209k
Forks
27.5k
PR merge metrics
PR metrics pending

Description

Description
Summary

Using Muse Spark 1.2 Contributor via OpenCode Go (paid subscription) fails immediately with:
_

AI_APICallError: Error from provider (Console Go): Upstream request failed:
[invalid_request_error] Recursive JSON schemas are not currently supported

_
The error occurs on the first request before any tool executes. The cause is the PostgreSQL tool schemas (postgres-readonly_pg_explain, postgres-readonly_pg_readonly, postgres-readonly_pg_query) which contain a self-referencing $ref:

{
  "$defs": {
    "__schema0": {
      "anyOf": [
        {"type": "string"},
        {"type": "number"},
        {"type": "boolean"},
        {"type": "null"},
        {"type": "array", "items": {"$ref": "#/$defs/__schema0"}},
        {"type": "object", "additionalProperties": {"$ref": "#/$defs/__schema0"}}
      ]
    }
  }
}

Meta's Model API explicitly rejects recursive schemas (https://ai.developer.meta.com/docs/features/structured-output/) in tool parameters with HTTP 400.

Why it happens

packages/opencode/src/provider/transform.ts has per-provider schema sanitizers for OpenAI, Moonshot/Kimi, and Gemini — but no Meta/Muse-specific sanitization. The sanitizeOpenAISchema function (which applies to Meta via @ai-sdk/openai) preserves $ref/$defs verbatim, so recursive schemas pass through to Meta's API unchanged.

Suggested fix

Flatten recursive $ref cycles in the schema transform layer before sending to any provider that rejects them. The approach from unmerged PR #29295 (inline local $refs, replace recursive refs with permissive {}) or the merged MCP fix #16910 (fallback to {type:"object", additionalProperties:true}) would both work.

Workaround

Disable PostgreSQL tools in opencode.json:

{
  "permission": {
    "postgres-*": "deny"
  }
}
Environment
  • opencode: latest (2026-08-28) 1.18.23
  • Provider: opencode-go → Console Go → Meta Model API
  • Model: muse-spark-1.2-contributor
  • OS: Linux (Pop! OS 24.04)
Plugins

None

OpenCode version

1.18.23

Steps to reproduce
  1. opencode.json - define a local mcp server
  "mcp": {
    "postgres-readonly": {
      "type": "local",
      "enabled": true,
      "command": ["npx", "-y", "@yawlabs/postgres-mcp@latest"],
      "environment": {
        "DATABASE_URL": "postgresql://testuser:<TESTPASSWD>@localhost:5432/TESTDB",
        "ALLOW_WRITES": "0"
      }
    }
  }
  1. opencode.json - set permissions
"permission": {
  "postgres-readonly_*": "allow"
}
  1. Start opencode
  2. set model to Muse Spark 1.2 Contributor
  3. Type 'Hello'
  4. response should fail in a few seconds with

Error from provider (Console Go): Upstream request failed: [invalid_request_error] Recursive JSON schemas are not currently supported

  1. (Side note) setting MCP tool "enabled": false, and repeat steps 3 - 5, should result in a successful response.
Screenshot and/or share link

No response

Operating System

Linux (Pop! OS 24.04)

Terminal

COSMIC Terminal

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.