Skip to content

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

@budu

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingcoreAnything 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