Skip to content

OpenCode 1.4.3 hangs with local Ollama provider on simple prompts, while /v1/chat/completions works #22132

Description

@Luporosso76

Description

Title:
OpenCode 1.4.3 hangs with local Ollama provider on simple prompts, while /v1/chat/completions works

Body:

Summary

OpenCode hangs when using a local Ollama provider configured through @ai-sdk/openai-compatible.

The issue happens even with a very simple prompt like ciao.

Important detail: the same model works correctly when called directly through Ollama's OpenAI-compatible endpoint (/v1/chat/completions), so the problem does not appear to be Ollama itself.

Environment

  • OpenCode: 1.4.3
  • Ollama: 0.20.5
  • OS: Ubuntu 25.10
  • Kernel: 6.17.0-20-generic
  • CPU: AMD Ryzen 7 6800H
  • RAM: 30 GiB
  • GPU: AMD Radeon 680M (integrated)
  • Ollama running as a systemd service
  • Provider backend: local Ollama via http://127.0.0.1:11434/v1

What I tested

I created dedicated Ollama models for OpenCode with larger context windows, because the docs/issues suggest OpenCode needs more context than Ollama's defaults.

Created models:

  • qwen2.5-coder:7b-opencode-32k
  • qwen2.5-coder:7b-opencode-64k
  • qwen3.5:9b-opencode-32k
  • qwen3.5:9b-opencode-64k

Example Modelfile:

FROM qwen2.5-coder:7b
PARAMETER num_ctx 32768

Ollama works correctly with these models.

Example:

ollama run qwen2.5-coder:7b-opencode-32k "Rispondi solo con OK"

returns:

OK

Also this works:

curl http://127.0.0.1:11434/v1/chat/completions \
  -H 'Content-Type: application/json' \
  -d '{
    "model": "qwen2.5-coder:7b-opencode-32k",
    "messages": [
      { "role": "user", "content": "Rispondi solo con OK" }
    ]
  }'

Response:

{"id":"chatcmpl-...","object":"chat.completion","choices":[{"index":0,"message":{"role":"assistant","content":"OK"},"finish_reason":"stop"}], ...}

So Ollama itself is responding correctly.

OpenCode config

~/.config/opencode/opencode.json

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "ollama": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "Ollama",
      "options": {
        "baseURL": "http://127.0.0.1:11434/v1",
        "apiKey": "ollama",
        "timeout": 120000,
        "chunkTimeout": 15000,
        "setCacheKey": true
      },
      "models": {
        "qwen2.5-coder:7b-opencode-32k": {
          "name": "qwen2.5-coder:7b-opencode-32k"
        },
        "qwen2.5-coder:7b-opencode-64k": {
          "name": "qwen2.5-coder:7b-opencode-64k"
        },
        "qwen3.5:9b-opencode-32k": {
          "name": "qwen3.5:9b-opencode-32k"
        },
        "qwen3.5:9b-opencode-64k": {
          "name": "qwen3.5:9b-opencode-64k"
        }
      }
    }
  },
  "model": "ollama/qwen2.5-coder:7b-opencode-32k",
  "small_model": "ollama/qwen2.5-coder:7b-opencode-32k"
}

I also tested with a cleaner/minimal config and still reproduced the same behavior.

Steps to reproduce

  1. Start Ollama locally on 127.0.0.1:11434
  2. Configure OpenCode with the Ollama provider through @ai-sdk/openai-compatible
  3. Use model ollama/qwen2.5-coder:7b-opencode-32k
  4. Start OpenCode
  5. Send a very simple message like:
ciao

Actual behavior

OpenCode hangs indefinitely.

CPU usage goes up (Ollama works), but no final response is shown in OpenCode, even though direct curl requests to /v1/chat/completions return normally.

Expected behavior

OpenCode should return a normal text response for a simple prompt, just like the direct Ollama API call does.

Relevant log excerpt

This is the part that looks suspicious to me:

service=llm providerID=ollama modelID=qwen2.5-coder:7b-opencode-32k sessionID=... small=true agent=title mode=primary stream
...
service=session.processor process
service=llm providerID=ollama modelID=qwen2.5-coder:7b-opencode-32k sessionID=... small=false agent=build mode=primary stream
...
service=bus type=session.updated publishing

After that, the UI remains stuck.

I also noticed that even for a trivial prompt, OpenCode still appears to enter the build flow.

Notes

  • This does not look like an Ollama connectivity issue, because:
    • ollama run ... works
    • curl /v1/chat/completions works
  • This may be related to the OpenAI-compatible provider flow, agent/tool loop, or streaming/session finalization.

Happy to provide more logs if needed.

Plugins

No response

OpenCode version

No response

Steps to reproduce

No response

Screenshot and/or share link

No response

Operating System

No response

Terminal

No response

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