How to control Timeouts #761

Closed
opened 2026-02-16 17:28:10 -05:00 by yindo · 35 comments
Owner

Originally created by @mrbm on GitHub (Jul 16, 2025).

Originally assigned to: @thdxr on GitHub.

I am running ollama on my local network on a dedicaled m4 24gig with Qwen3:14b Quant with 65k context window.

I had it create a slightly more than basic react app and it created things, wrote some of the thngs in the dialog and wrote 50% of the things to disk, the other 50 it didn't I gave it a command to write the rest of the items...and then it did some, but not all of it, i did another command to finish...and now it just timesout.

I am reading the ollama serve logs and noticed that open code is sending a timeout singnal around 4 min ond each time.

So...the issue is opencode.

I didn't set a timeout in the config. Then i tried setting a timeout in the opencode config to 600 seconds, same results.

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "ollama-local-remote": {
      "npm": "@ai-sdk/openai-compatible",
      "options": {
        "baseURL": "http://192.168.XX.XXX:11434/v1",
        "timeout": 600000
      },
      "models": {
        "llama3:8b": {"name": "Ollama Llama3"},
        "qwen3:14b-65k": {
          "name": "qwen3:14b 65k (remote local)",
          "tools": true,
          "reasoning": true,
          "options": { "num_ctx": 65536 }
        },
        "qwen3:14b-q4_K_M": {
          "name": "qwen3:14b-q4_K_M (remote local)",
          "tools": true,
          "reasoning": true
        }

Is this the right way to do it? Or is this something that can't be changed. Thanks! OpenCode.ai special sauce is going to be for those homebuilds which are going to have less resources and as a result opencode needs to be able to wait longer. Love the community thoughts or is this coming soon. I think there was 3 releases yesterday so i know things are happening rapidly.

Originally created by @mrbm on GitHub (Jul 16, 2025). Originally assigned to: @thdxr on GitHub. I am running ollama on my local network on a dedicaled m4 24gig with Qwen3:14b Quant with 65k context window. I had it create a slightly more than basic react app and it created things, wrote some of the thngs in the dialog and wrote 50% of the things to disk, the other 50 it didn't I gave it a command to write the rest of the items...and then it did some, but not all of it, i did another command to finish...and now it just timesout. I am reading the ollama serve logs and noticed that open code is sending a timeout singnal around 4 min ond each time. So...the issue is opencode. I didn't set a timeout in the config. Then i tried setting a timeout in the opencode config to 600 seconds, same results. ``` { "$schema": "https://opencode.ai/config.json", "provider": { "ollama-local-remote": { "npm": "@ai-sdk/openai-compatible", "options": { "baseURL": "http://192.168.XX.XXX:11434/v1", "timeout": 600000 }, "models": { "llama3:8b": {"name": "Ollama Llama3"}, "qwen3:14b-65k": { "name": "qwen3:14b 65k (remote local)", "tools": true, "reasoning": true, "options": { "num_ctx": 65536 } }, "qwen3:14b-q4_K_M": { "name": "qwen3:14b-q4_K_M (remote local)", "tools": true, "reasoning": true } ``` Is this the right way to do it? Or is this something that can't be changed. Thanks! OpenCode.ai special sauce is going to be for those homebuilds which are going to have less resources and as a result opencode needs to be able to wait longer. Love the community thoughts or is this coming soon. I think there was 3 releases yesterday so i know things are happening rapidly.
yindo closed this issue 2026-02-16 17:28:10 -05:00
Author
Owner

@thdxr commented on GitHub (Jul 16, 2025):

hmm im not sure where this timeout is being set - i don't think that timeout option exists

@thdxr commented on GitHub (Jul 16, 2025): hmm im not sure where this timeout is being set - i don't think that `timeout` option exists
Author
Owner

@mrbm commented on GitHub (Jul 16, 2025):

I am not attempted to be super familiar with the code base, but just a quick search brings me to this:

https://github.com/sst/opencode/blob/dev/packages/opencode/src/util/timeout.ts

Is there a way to set this project to wait a certain time length max or indefinitely? Or does this have a default waiting period occuring at some stage of the project? Maybe some &http.Client method has a default timeout? I'm in a dr office waiting with my eyes dialated so can't really see anymore.. but maybe these notes help

@mrbm commented on GitHub (Jul 16, 2025): I am not attempted to be super familiar with the code base, but just a quick search brings me to this: https://github.com/sst/opencode/blob/dev/packages/opencode/src/util/timeout.ts Is there a way to set this project to wait a certain time length max or indefinitely? Or does this have a default waiting period occuring at some stage of the project? Maybe some &http.Client method has a default timeout? I'm in a dr office waiting with my eyes dialated so can't really see anymore.. but maybe these notes help
Author
Owner

@douglarek commented on GitHub (Jul 16, 2025):

Maybe same as #655, opencode does not complete a download service but ends abruptly. My scenario is upgrading software packages in the Gentoo overlay. The download stops halfway, causing the Manifest that records the package to write an incorrect checksum.

@douglarek commented on GitHub (Jul 16, 2025): Maybe same as #655, opencode does not complete a download service but ends abruptly. My scenario is upgrading software packages in the Gentoo overlay. The download stops halfway, causing the Manifest that records the package to write an incorrect checksum.
Author
Owner

@mrbm commented on GitHub (Jul 17, 2025):

https://github.com/sst/opencode/blob/60b55f9d921805a4a9d38c9eed05a060df08df82/packages/opencode/src/tool/bash.ts

i see timeouts here, i have no idea how this might be effecting http.client requests to an llm or requests for other things, but i think there is a possible issue somehere.

@mrbm commented on GitHub (Jul 17, 2025): https://github.com/sst/opencode/blob/60b55f9d921805a4a9d38c9eed05a060df08df82/packages/opencode/src/tool/bash.ts i see timeouts here, i have no idea how this might be effecting http.client requests to an llm or requests for other things, but i think there is a possible issue somehere.
Author
Owner

@mrbm commented on GitHub (Jul 17, 2025):

@thdxr i think the real pillar of strength that claude and google can't take from this project will be the ability to use local models which are obvious always going to run slower. I do think testing on a slow response scenario where from a separate machine running ollama might not response for 7 min while it thinks is a worthy test case to backtrack and find where open code might be closing the connection pre-maturely.

@mrbm commented on GitHub (Jul 17, 2025): @thdxr i think the real pillar of strength that claude and google can't take from this project will be the ability to use local models which are obvious always going to run slower. I do think testing on a slow response scenario where from a separate machine running ollama might not response for 7 min while it thinks is a worthy test case to backtrack and find where open code might be closing the connection pre-maturely.
Author
Owner

@thdxr commented on GitHub (Jul 24, 2025):

yep will look into this

@thdxr commented on GitHub (Jul 24, 2025): yep will look into this
Author
Owner

@noahfraiture commented on GitHub (Jul 28, 2025):

I agree that timeout would be very convenient, but also for other capabilities like bash execution

@noahfraiture commented on GitHub (Jul 28, 2025): I agree that timeout would be very convenient, but also for other capabilities like bash execution
Author
Owner

@ggaabe commented on GitHub (Jul 30, 2025):

running into timeouts from slow local model responses as well. would be great to control.

@ggaabe commented on GitHub (Jul 30, 2025): running into timeouts from slow local model responses as well. would be great to control.
Author
Owner

@dc-tec commented on GitHub (Aug 1, 2025):

Same here when running a larger local model, would be nice if we could configure the timeout.

@dc-tec commented on GitHub (Aug 1, 2025): Same here when running a larger local model, would be nice if we could configure the timeout.
Author
Owner

@dysangel commented on GitHub (Aug 3, 2025):

same. My model was trying to do multiple tool calls and eventually timing out. I'd be happy to just be able to disable the timeout for local use

@dysangel commented on GitHub (Aug 3, 2025): same. My model was trying to do multiple tool calls and eventually timing out. I'd be happy to just be able to disable the timeout for local use
Author
Owner

@egyptianbman commented on GitHub (Aug 9, 2025):

Same here, getting constant timeouts with ollama. When this happens, the request is not aborted so the model keeps churning and subsequent requests are more likely to fail as the model is busy.

@egyptianbman commented on GitHub (Aug 9, 2025): Same here, getting constant timeouts with ollama. When this happens, the request is not aborted so the model keeps churning and subsequent requests are more likely to fail as the model is busy.
Author
Owner

@dysangel commented on GitHub (Aug 9, 2025):

I've been looking into this the last few days. By default a lot of network requests time out after 5 minutes. I'm submitting a PR to mlx-lm to send back SSE comments which notify that the prompt is currently processing and keep the connection alive. If necessary we could make similar keepalive tweaks to ollama and llama.cpp etc to allow time for local models to process very large contexts without all the clients disconnecting

@dysangel commented on GitHub (Aug 9, 2025): I've been looking into this the last few days. By default a lot of network requests time out after 5 minutes. I'm submitting a PR to mlx-lm to send back SSE comments which notify that the prompt is currently processing and keep the connection alive. If necessary we could make similar keepalive tweaks to ollama and llama.cpp etc to allow time for local models to process very large contexts without all the clients disconnecting
Author
Owner

@jamviking commented on GitHub (Aug 9, 2025):

As I am experiencing the same timeout issue when running OpenCode against a local LMStudio installation, us local users need a way to override the default NodeJS timeout as documented here: https://blog.appsignal.com/2023/11/08/how-to-use-timeouts-in-nodejs.html

Hope this helps as I need it...

@jamviking commented on GitHub (Aug 9, 2025): As I am experiencing the same timeout issue when running OpenCode against a local LMStudio installation, us local users need a way to override the default NodeJS timeout as documented here: https://blog.appsignal.com/2023/11/08/how-to-use-timeouts-in-nodejs.html Hope this helps as I need it...
Author
Owner

@dysangel commented on GitHub (Aug 9, 2025):

@jamviking if you're using an MLX model, then yes that issue is still present

@dysangel commented on GitHub (Aug 9, 2025): @jamviking if you're using an MLX model, then yes that issue is still present
Author
Owner

@jamviking commented on GitHub (Aug 9, 2025):

@dysangel am actually using the GGUF version in LMStudio...

@jamviking commented on GitHub (Aug 9, 2025): @dysangel am actually using the GGUF version in LMStudio...
Author
Owner

@yokodev commented on GitHub (Aug 10, 2025):

Same here I'm using LMStudio with either Qwen3 coder or gpt-oss-20

and I get the timeoutError

Image
@yokodev commented on GitHub (Aug 10, 2025): Same here I'm using LMStudio with either Qwen3 coder or gpt-oss-20 and I get the timeoutError <img width="1869" height="948" alt="Image" src="https://github.com/user-attachments/assets/3dc9b83c-b420-4bb0-a4c2-33c3c6f9984b" />
Author
Owner

@TheHoodedFoot commented on GitHub (Aug 10, 2025):

Given that OpenCode uses the Vercel AI-SDK, could this be being limited by the maxDuration (https://vercel.com/docs/functions/limitations#max-duration)? My timeouts are all at about 5 minutes, which is the same as the default shown on the site.

@TheHoodedFoot commented on GitHub (Aug 10, 2025): Given that OpenCode uses the Vercel AI-SDK, could this be being limited by the maxDuration (https://vercel.com/docs/functions/limitations#max-duration)? My timeouts are all at about 5 minutes, which is the same as the default shown on the site.
Author
Owner

@TheHoodedFoot commented on GitHub (Aug 15, 2025):

I have been able to replicate the timeout issue outside of OpenCode with a simple example that uses the AI SDK. It seems that the timeout is being caused because the Bun fetch implementation has a default timeout of 5 minutes, which affects the AI SDK. In order to get around this, it is neccessary to override fetch() in createOpenAICompatible(). The fetch timeout can be set to false, which waits indefinitely.

The following example will work on my slow machine running llama.cpp locally without timing out, but if the fetch is not overriden then it will fail with a timeout after 5 minutes, just like OpenCode:

import { createOpenAICompatible } from '@ai-sdk/openai-compatible';
import { generateText } from 'ai';
import * as fs from 'fs';

const provider = createOpenAICompatible({
  name: 'provider-name',
  baseURL: 'http://127.0.0.1:5000/v1',
  fetch: async (input, init = {}) => {
    const fetchInit = {
      ...init,
      timeout: false,
    };
    return await fetch(input, fetchInit);
  },
});

const promptFromFile = fs.readFileSync('prompt.txt', { encoding: 'utf8' });
const { text } = await generateText({
  model: provider('qwen3-coder-30b-a3b-instruct'),
  prompt: promptFromFile,
});

process.stdout.write(text);

I assume that overriding the fetch function within OpenCode should have a similar effect.

@TheHoodedFoot commented on GitHub (Aug 15, 2025): I have been able to replicate the timeout issue outside of OpenCode with a simple example that uses the AI SDK. It seems that the timeout is being caused because the Bun fetch implementation has a default timeout of 5 minutes, which affects the AI SDK. In order to get around this, it is neccessary to override fetch() in createOpenAICompatible(). The fetch timeout can be set to false, which waits indefinitely. The following example will work on my slow machine running llama.cpp locally without timing out, but if the fetch is not overriden then it will fail with a timeout after 5 minutes, just like OpenCode: ``` import { createOpenAICompatible } from '@ai-sdk/openai-compatible'; import { generateText } from 'ai'; import * as fs from 'fs'; const provider = createOpenAICompatible({ name: 'provider-name', baseURL: 'http://127.0.0.1:5000/v1', fetch: async (input, init = {}) => { const fetchInit = { ...init, timeout: false, }; return await fetch(input, fetchInit); }, }); const promptFromFile = fs.readFileSync('prompt.txt', { encoding: 'utf8' }); const { text } = await generateText({ model: provider('qwen3-coder-30b-a3b-instruct'), prompt: promptFromFile, }); process.stdout.write(text); ``` I assume that overriding the fetch function within OpenCode should have a similar effect.
Author
Owner

@mrbm commented on GitHub (Aug 15, 2025):

@TheHoodedFoot nice detective work on this timeout issue, hopefully @thdxr sees this( it is Friday and i assume he takes breaks). If he can implement an override of the fetch as you suggested and it works...then I am ready to test and maybe that will put my mac mini m4 back in business!

@mrbm commented on GitHub (Aug 15, 2025): @TheHoodedFoot nice detective work on this timeout issue, hopefully @thdxr sees this( it is Friday and i assume he takes breaks). If he can implement an override of the fetch as you suggested and it works...then I am ready to test and maybe that will put my mac mini m4 back in business!
Author
Owner

@egyptianbman commented on GitHub (Aug 15, 2025):

I tested this and it seems to be working:

diff --git a/packages/opencode/src/provider/provider.ts b/packages/opencode/src/provider/provider.ts
index 42bb1804..5df59efd 100644
--- a/packages/opencode/src/provider/provider.ts
+++ b/packages/opencode/src/provider/provider.ts
@@ -305,9 +305,23 @@ export namespace Provider {
       const pkg = provider.npm ?? provider.id
       const mod = await import(await BunProc.install(pkg, "latest"))
       const fn = mod[Object.keys(mod).find((key) => key.startsWith("create"))!]
+      let options = { ...s.providers[provider.id]?.options }
+      // Inject custom fetch for local OpenAI-compatible providers
+      if (
+        provider.id === "ollama" &&
+        (provider.npm === "@ai-sdk/openai-compatible" || pkg === "@ai-sdk/openai-compatible") &&
+        options["baseURL"]
+      ) {
+        // Always override fetch to set timeout (default: false = unlimited, or user-configurable)
+        const userTimeout = options["timeout"] !== undefined ? options["timeout"] : false
+        options["fetch"] = async (input: any, init?: any) => {
+          return await fetch(input, { ...init, timeout: userTimeout })
+        }
+      }
       const loaded = fn({
         name: provider.id,
-        ...s.providers[provider.id]?.options,
+        ...options,
       })
       s.sdk.set(provider.id, loaded)
       return loaded as SDK
@egyptianbman commented on GitHub (Aug 15, 2025): I tested this and it seems to be working: ```diff diff --git a/packages/opencode/src/provider/provider.ts b/packages/opencode/src/provider/provider.ts index 42bb1804..5df59efd 100644 --- a/packages/opencode/src/provider/provider.ts +++ b/packages/opencode/src/provider/provider.ts @@ -305,9 +305,23 @@ export namespace Provider { const pkg = provider.npm ?? provider.id const mod = await import(await BunProc.install(pkg, "latest")) const fn = mod[Object.keys(mod).find((key) => key.startsWith("create"))!] + let options = { ...s.providers[provider.id]?.options } + // Inject custom fetch for local OpenAI-compatible providers + if ( + provider.id === "ollama" && + (provider.npm === "@ai-sdk/openai-compatible" || pkg === "@ai-sdk/openai-compatible") && + options["baseURL"] + ) { + // Always override fetch to set timeout (default: false = unlimited, or user-configurable) + const userTimeout = options["timeout"] !== undefined ? options["timeout"] : false + options["fetch"] = async (input: any, init?: any) => { + return await fetch(input, { ...init, timeout: userTimeout }) + } + } const loaded = fn({ name: provider.id, - ...s.providers[provider.id]?.options, + ...options, }) s.sdk.set(provider.id, loaded) return loaded as SDK ```
Author
Owner

@jamviking commented on GitHub (Aug 15, 2025):

The time out occurs when using LMStudio too... can you patch it too?

@jamviking commented on GitHub (Aug 15, 2025): The time out occurs when using LMStudio too... can you patch it too?
Author
Owner

@TheHoodedFoot commented on GitHub (Aug 16, 2025):

I have tested this with a call that took well over an hour to complete, and can confirm that this works for me too. Thanks @egyptianbman

@jamviking This fix happens before the call to the LLM, so it will work for any OpenAI compatible endpoint, including llama.cpp and LMstudio.

@TheHoodedFoot commented on GitHub (Aug 16, 2025): I have tested this with a call that took well over an hour to complete, and can confirm that this works for me too. Thanks @egyptianbman @jamviking This fix happens before the call to the LLM, so it will work for any OpenAI compatible endpoint, including llama.cpp and LMstudio.
Author
Owner

@egyptianbman commented on GitHub (Aug 18, 2025):

For those that are blocked by the fix being merged, I've found that https://github.com/charmbracelet/crush works as well as opencode and doesn't suffer from the timeout issue.

@egyptianbman commented on GitHub (Aug 18, 2025): For those that are blocked by the fix being merged, I've found that https://github.com/charmbracelet/crush works as well as opencode and doesn't suffer from the timeout issue.
Author
Owner

@dysangel commented on GitHub (Aug 18, 2025):

my fix for mlx-lm was merged into main, so if you set up an MLX server now, you should have no timeout issues

@dysangel commented on GitHub (Aug 18, 2025): my fix for mlx-lm was merged into main, so if you set up an MLX server now, you should have no timeout issues
Author
Owner

@eduardogarre commented on GitHub (Aug 24, 2025):

Also affected by this issue

@eduardogarre commented on GitHub (Aug 24, 2025): Also affected by this issue
Author
Owner

@mrbm commented on GitHub (Aug 24, 2025):

Hey @thdxr just making sure you saw this and the solution somebody provided.

@mrbm commented on GitHub (Aug 24, 2025): Hey @thdxr just making sure you saw this and the solution somebody provided.
Author
Owner

@adamwlarson commented on GitHub (Aug 26, 2025):

also impacted by this

@adamwlarson commented on GitHub (Aug 26, 2025): also impacted by this
Author
Owner

@dannyfranca commented on GitHub (Aug 30, 2025):

1+, Using GPT-5 with Opencode and high reasoning is not practical at all.

@dannyfranca commented on GitHub (Aug 30, 2025): 1+, Using GPT-5 with Opencode and high reasoning is not practical at all.
Author
Owner

@rekram1-node commented on GitHub (Aug 31, 2025):

support will be added in next release thx for your patience

@rekram1-node commented on GitHub (Aug 31, 2025): support will be added in next release thx for your patience
Author
Owner

@Cyrille37 commented on GitHub (Nov 5, 2025):

Thanks for timeout provider option, it works great.

I need an increased timeout with my computer without GPU

@Cyrille37 commented on GitHub (Nov 5, 2025): Thanks for `timeout` provider option, it works great. _I need an increased timeout with my computer without GPU_
Author
Owner

@wangsen992 commented on GitHub (Dec 16, 2025):

Thanks for timeout provider option, it works great.

I need an increased timeout with my computer without GPU

@Cyrille37 I'm look for a solution to this issue. Based on your comment it seems you managed to do this, may I ask how did you do it to enable longer timeouts? Thank you!

@wangsen992 commented on GitHub (Dec 16, 2025): > Thanks for `timeout` provider option, it works great. > > _I need an increased timeout with my computer without GPU_ @Cyrille37 I'm look for a solution to this issue. Based on your comment it seems you managed to do this, may I ask how did you do it to enable longer timeouts? Thank you!
Author
Owner

@rekram1-node commented on GitHub (Dec 16, 2025):

@wangsen992 what version are u on, what timeouts are u seeing?

@rekram1-node commented on GitHub (Dec 16, 2025): @wangsen992 what version are u on, what timeouts are u seeing?
Author
Owner

@Cyrille37 commented on GitHub (Dec 17, 2025):

@wangsen992 Added timeout in provider's options config. Have a look at #3708 for an example.

@Cyrille37 commented on GitHub (Dec 17, 2025): @wangsen992 Added `timeout` in provider's options config. Have a look at #3708 for an example.
Author
Owner

@Cyrille37 commented on GitHub (Dec 17, 2025):

Also, this option is not in documentation, only found in config schema.

@Cyrille37 commented on GitHub (Dec 17, 2025): Also, this option is not in [documentation](https://opencode.ai/docs/providers/#config), only found in [config schema](https://opencode.ai/config.json).
Author
Owner

@dysangel commented on GitHub (Dec 17, 2025):

@Cyrille37 thanks! I'll have to try open again sometime

@dysangel commented on GitHub (Dec 17, 2025): @Cyrille37 thanks! I'll have to try open again sometime
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#761