Skip to content

Bug: OpenAI-compatible provider rejects Ollama's reasoning field, causing infinite spin/hang #21903

Closed

Description

@budu

Description

When using OpenCode with Ollama or other local OpenAI-compatible endpoints, if the model response includes a field reasoning (as produced by Ollama), the result is an infinite spin on 'Build - ' and high CPU, with no output. OpenCode expects Copilot/OpenAI-specific fields: reasoning_text or reasoning_opaque only, and does not accept the generic reasoning field. As a result, UI never recovers. This is confirmed for Ollama 0.20.4 (gemma4, qwen3.5) on Arch Linux. See reproduction step 5 for actual Ollama response proof.

I've tested with a patched version of OpenCode and it works.

modified   packages/opencode/src/provider/sdk/copilot/chat/openai-compatible-chat-language-model.ts
@@ -757,6 +757,7 @@ const OpenAICompatibleChatResponseSchema = z.object({
         // Copilot-specific reasoning fields
         reasoning_text: z.string().nullish(),
         reasoning_opaque: z.string().nullish(),
+        reasoning: z.string().nullish(),  // Ollama-compatibility
         tool_calls: z
           .array(
             z.object({
@@ -792,6 +793,7 @@ const createOpenAICompatibleChatChunkSchema = <ERROR_SCHEMA extends z.core.$ZodT
               // Copilot-specific reasoning fields
               reasoning_text: z.string().nullish(),
               reasoning_opaque: z.string().nullish(),
+              reasoning: z.string().nullish(),  // Ollama-compatibility
               tool_calls: z
                 .array(
                   z.object({

Plugins

No response

OpenCode version

1.4.3

Steps to reproduce

  1. Launch Ollama (0.20.4 or later) with a compatible chat model (e.g., gemma4, qwen3.5)
  2. Configure OpenCode to use your local OpenAI-compatible backend: ollama launch opencode
  3. Prompt the model (any message)
  4. Observe: UI spins/hangs with high CPU, never returns output
  5. Inspect Ollama's response JSON, which looks like:
{
  "id": "chatcmpl-123",
  "object": "chat.completion",
  "choices": [{
    "message": {
      "role": "assistant",
      "content": "...",
      "reasoning": "Some chain-of-thought reasoning steps"
    }
  }]
}
  1. Confirm OpenCode only parses reasoning_text/reasoning_opaque (see openai-compatible-chat-language-model.ts), not reasoning.
  2. Workaround: Patch the Zod schema in OpenCode to accept reasoning: z.string().nullish().

Screenshot and/or share link

No response

Operating System

Linux (Arch)

Terminal

Kitty

Activity

  1. added
    bugSomething isn't working
    on Apr 10, 2026
  2. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Apr 10, 2026
  3. budu commented on Apr 10, 2026

    @budu
    Author

    It looks like I was totally wrong and OpenCode works without the fix after all.

    OpenCode spinning endlessly seems to be related to running in a specific directory, I'm looking for an explanation.

  4. budu commented on Apr 10, 2026

    @budu
    Author

    This actually appears to be a much worse issue related to #6845

    I was running OpenCode from big directory and it was trying to scan everything.

    So OpenCode actually end up responding to my prompt after 5+ minutes. The worse being that it then start using 100% CPU for quite some time.

    I then noticed high disk space usage:

    $ du ~/.local/share/opencode/snapshot/global/
    55G	/home/budu/.local/share/opencode/snapshot/global/
    

    I think enabling snapshot by default without some kind of limit nor any UI notice is extremely bad design.

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingcoreAnything pertaining to core functionality of the application (opencode server stuff)

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions