Skip to content

retryCount in format.json_schema breaks structured output on opencode >=1.18 (HTTP 400 "Upstream request failed") #226

Closed

Description

@tomyumtinker

Problem

Auto-capture / profile learning via the opencodeProvider path always fails against opencode 1.18.10. The error surfaces misleadingly as:

opencode reported APIError: Error from provider (Console Go): Upstream request failed; details={"statusCode":400}

The provider is a red herring — the request never reaches it. opencode's own log shows the real cause:

level=WARN message="schema rejection" kind=Body
reason="Expected OutputFormatJsonSchema, got {\"type\":\"json_schema\",\"schema\":{...},\"retryCount\":2}
       at [0][\"info\"][\"format\"]"

Root cause

dist/services/ai/opencode-provider.js builds the session prompt format as:

format: {
  type: "json_schema",
  schema: args.jsonSchema,
  ...(args.retryCount !== undefined ? { retryCount: args.retryCount } : {}),
},

retryCount is a field of opencode's OutputFormatJsonSchema type, not a top-level sibling of type/schema. opencode's request-body schema validator rejects the payload with HTTP 400 before any provider is contacted.

Impact

  • opencodeProvider / opencodeModel auto-capture always fails → falls back to "External API not configured" (for users who rely on the opencode path, capture silently never works).
  • Error message is misleading ("Error from provider … Upstream request failed"), making the true cause hard to find.

Steps to reproduce

  1. opencode 1.18.10, opencode-mem 2.22.2.
  2. Set opencodeProvider + opencodeModel (e.g. "opencode-go" + "deepseek-v4-flash").
  3. Trigger auto-capture (idle session).
  4. Observe the HTTP 400 and the schema rejection WARN in ~/.local/share/opencode/log/opencode.log.

Suggested fix

Remove retryCount from the format object (or place it inside the schema per opencode's OutputFormatJsonSchema definition). Workaround that avoids this entirely: configure the manual provider path (memoryProvider: "openai-chat" with an OpenAI-compatible endpoint).

Environment

  • opencode: 1.18.10
  • opencode-mem: 2.22.2
  • OS: Linux (openSUSE Tumbleweed)

Activity

  1. EyJunge1 commented on Aug 2, 2026

    @EyJunge1
    Collaborator

    Thanks for the detailed report. We verified this against OpenCode 1.18.10 using otherwise identical structured-output requests with and without retryCount.

    Both payloads were accepted and reached the provider; removing retryCount did not change the result. OpenCode’s schema also explicitly defines retryCount as a valid top-level field of OutputFormatJsonSchema.

    The underlying structured-output handling is tracked upstream:

    Since removing retryCount in opencode-mem would not fix the underlying failure and would only remove a valid API field, we will not apply a workaround here. Closing this issue as an upstream OpenCode problem.

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions