Repository navigation
Description
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-32kqwen2.5-coder:7b-opencode-64kqwen3.5:9b-opencode-32kqwen3.5:9b-opencode-64k
Example Modelfile:
FROM qwen2.5-coder:7b
PARAMETER num_ctx 32768Ollama works correctly with these models.
Example:
ollama run qwen2.5-coder:7b-opencode-32k "Rispondi solo con OK"returns:
OKAlso 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
- Start Ollama locally on
127.0.0.1:11434 - Configure OpenCode with the Ollama provider through
@ai-sdk/openai-compatible - Use model
ollama/qwen2.5-coder:7b-opencode-32k - Start OpenCode
- Send a very simple message like:
ciaoActual 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 publishingAfter 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 ...workscurl /v1/chat/completionsworks
- 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
Activity
github-actions commentedon Apr 12, 2026
This issue might be a duplicate of existing issues. Please check:
@ai-sdk/openai-compatible, similar config, model receives empty/incorrect content and hangs) — very similar symptoms and configurationPlease review those issues and see if any of the workarounds or findings there apply to your situation. If your issue is distinct, feel free to note the differences.
Luporosso76 commentedon Apr 12, 2026
Thanks, I checked both issues.
#5187 looks especially close to my case:
@ai-sdk/openai-compatible#20669 also seems related, especially because my logs show OpenCode entering the default agent flow (
agent=titleand thenagent=build) before getting stuck, which seems consistent with local OpenAI-compatible/tool-call brittleness.What seems most relevant in my case is:
1.4.30.20.5ollama/qwen2.5-coder:7b-opencode-32kollama run ...worksPOST /v1/chat/completionsworksciaoSo I agree this is likely related to #5187, with #20669 also looking relevant for the default agent/tool-call path.
If helpful, I can provide the exact config and logs from my reproduction.
Luporosso76 commentedon Apr 15, 2026
I found several additional Ollama-related issues that seem consistent with the same broader failure cluster around local Ollama / OpenAI-compatible integration:
ollama launch opencode --model gemma4maxOutputTokenswith local Ollama, while direct Ollama API calls workollama/qwen2.5-coder:7band no responseThis makes my issue look less like a single model/config problem and more like a broader OpenCode ↔ Ollama local integration problem.
Luporosso76 commentedon Apr 15, 2026
I tested again after upgrading to OpenCode 1.4.6, and the issue is still reproducible.
Current status:
Behavior is unchanged:
ollama run ...worksPOST /v1/chat/completionsworksciaostill hangsSo at least on my setup, this is still present in 1.4.6.
Luporosso76 commentedon Apr 16, 2026
I narrowed this down further.
With the same Ollama setup and the same model:
So this is not a general Ollama connectivity or basic text-generation problem.
The failure seems specific to the agentic flow used by Plan/Build (tool orchestration, tool-call parsing, or agent loop handling), while plain chat completions work correctly.
This seems consistent with the broader local OpenAI-compatible / Ollama issues discussed in #5187 and #20669.
Luporosso76 commentedon Apr 24, 2026
I manually tested all relevant Ollama endpoints with the same model and trivial prompt, and they all work correctly.
Successful manual tests:
So this is not caused by:
?beta=truequery parameterThis strongly suggests Opencode is sending a problematic request payload or using a client-side flow that differs from the simple successful manual requests.
Given the Ollama logs also show:
aborting completion request due to client closing the connectionthe issue now looks much more like a Opencode request construction / streaming / tools / client-handling problem, not an Ollama endpoint problem.
LukeShortCloud commentedon Apr 30, 2026
Possibly related: in Nanocoder the fix was to disable some timeouts: Nano-Collective/nanocoder#441 (comment) . OpenCode might have similar configurable options.
madjestic commentedon May 2, 2026
I am experiencing a very similar issue. I've tried the suggested workaround, but that did not fix it for me. Here's my config:
Also I noticed that while looking at the Opencode - ollama communication by redirecting the url to a 8080 proxy via
mitmdumpI see that the responce message gets dumped only after the Opencode prompt is cancelled (by pressing Escape twice after sending a simple prompt).Bazmundi commentedon Jun 8, 2026
opencode 1.16.2 with ollama 0.30.6 and gemma4:latest exhibits the same problem
vladanan commentedon Jun 29, 2026
On 1.17.11 and Ollama version 0.30.11 the same issue is present.
toldk98 commentedon Jul 4, 2026
I can reproduce this on OpenCode 1.17.13 with Ollama 0.22.1.
Environment:
Configuration:
Steps to reproduce:
"Say OK"
Expected:
The model should immediately answer "OK".
Actual:
OpenCode never returns a response.
Observations:
ollama psshows gemma4:e2b-32k running at 100% CPU./v1/chat/completionswhile OpenCode is still waiting, that request also hangs./v1/chat/completionsworks correctly outside OpenCode.stream: falseandstream: truework correctly with curl.Example:
curl http://localhost:11434/v1/chat/completions
-H "Content-Type: application/json"
-d '{
"model":"gemma4:e2b-32k",
"messages":[{"role":"user","content":"Say OK"}],
"stream":true
}'
Response times after restarting Ollama:
The problem only appears after OpenCode sends its request. It looks like the request issued by OpenCode causes Ollama to stop completing subsequent chat requests until Ollama is restarted.
xchrisbradley commentedon Jul 11, 2026
any updates on this?
madjestic commentedon Jul 12, 2026
djmaxus commentedon Jul 12, 2026
@madjestic Did you mean llama.cpp?
In any case, Pi + Ollama does work!
madjestic commentedon Jul 12, 2026
Yes, I've mistyped. Glad that ollama works with pi too!
akiramotoai commentedon Jul 16, 2026
Same core symptom here (opencode fails/hangs with a local Ollama provider via
@ai-sdk/openai-compatible, whilePOST /v1/chat/completionsto the same model is rock-solid), but I isolated two things I haven't seen in the thread. Sharing in case they help narrow it down.Env: opencode
1.18.2, Ollama0.32.0, macOS 26.5 (Darwin 25.5, arm64),qwen3:14b@num_ctx 16384, provider@ai-sdk/openai-compatible@http://localhost:11434/v1. Drivingopencode runheadless (spawned from another process), with custom agents.1. Headless: opencode blocks on inherited stdin (a distinct "hang")
When
opencode runis spawned programmatically (parent's stdin is a pipe — daemon/orchestrator/CI), it blocks and never returns. It never reaches the model: Ollama's access log shows noPOST /v1/chat/completionsduring the hang, only theGET /api/psprobe.Workaround — give it
/dev/nullas stdin:or
stdin=DEVNULLon the subprocess. Inherited-pipe stdin → hangs;/dev/null→ does not. This likely accounts for "hangs on simple prompts" whenever opencode runs outside an interactive TTY.2. With stdin fixed, an intermittent fast-fail in
createUserMessageremainsAfter the stdin fix, a fraction of runs fail in ~1s — again before any Ollama request (no POST in Ollama's log) — with:
{"type":"error","error":{"name":"UnknownError","data":{"message":"Unexpected server error. Check server logs for details.","ref":"err_..."}}}--print-logs --log-level DEBUGgives the server-side stack:i.e. it dies while creating the user message, before the provider call.
3. It's phase-intermittent, not input-dependent
The identical invocation (same flags, same custom agent, same fresh git dir, same prompt) passes 5/5 in one window and fails 0/5 in another. Ruled out as determinants: stdin mode, dir freshness, pipe-vs-file output capture,
--pure/--format json, the prompt text, custom-vs-default agent, and the doc workarounds (apiKeydummy +tools: true+127.0.0.1) — none made it reliable. Ollama stays healthy throughout (curl /v1/chat/completionssucceeds during the failures).Happy to share a minimal repro harness if that's useful.
github-actions commentedon Sep 15, 2026
To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.