Skip to content

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

Closed as not planned

Description

@bitrogue

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

Activity

  1. Parker-Fawcett commented on Sep 6, 2026

    @Parker-Fawcett

    Another instance of the same root cause, different MCP server: substack-mcp's set_post_body tool publishes a ProseMirror-style document schema (packages/substack-mcp/src/api/substack/document.js) where listItemNode and bulletListNode/orderedListNode reference each other via getters — a genuine mutual recursion that zod-to-json-schema turns into a $ref cycle. Same symptoms as this issue: fails on the very first message, even with the plain build agent and no other plugins/MCPs enabled, as soon as substack MCP is configured and model is muse-spark-1.2/1.3-contributor-free via Console. Workaround that worked for me: "permission": {"substack_set_post_body": "deny"} in opencode.jsonc, which drops just that one tool and leaves the rest of the MCP working. +1 for fixing this generally in the schema transform layer rather than per-MCP-server, since it's clearly not limited to postgres/houseCARL/substack — any tool with a tree-shaped schema will hit it.

  2. thdxr commented on Oct 11, 2026

    @thdxr
    Member

    Thanks for the report! OpenCode 2.0 is now out and development is focused on V2, so we're closing issues filed against OpenCode 1. Please upgrade (opencode upgrade --major, details: https://anoma.ly/notes/opencode-2-0), and if this is still relevant on 2.0, reopen this issue or open a new one with your 2.0 version.

    — from 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊

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