r/LocalLLM • • 3d ago

Question opencode+qwen3 keeps looping; what am I doing wrong?

I have been trying these local LLM for coding tasks. I am running a local Qwen3-32B quantized in LMStudio. I am trying to use it with opencode. But after 3 prompts or questions, the agent session turn into some infinite loop of reasoning or some tool calling infinite loop of some kind. Sometimes it tells me how to do things instead of doing them.

I can't be the first one to run into this. What's going on? What am I doing wrong? Is there a basic "how to" somewhere I didn't find that explains how to set this up so that it is useful?

0 Upvotes

9 comments sorted by

2

u/AutomaticLanguage334 3d ago

the thing you're doing wrong is that you're running a rather dated model. Qwen didn't start optimizing for agent workflows until Qwen3.5 I believe. consider switching to a more modern model if you want proper tool calling. (specifically, Qwen3.8-27B is the one you want at the moment, though Inkling-2 is the current hotness at the moment)

it could also be a low quant biting you. Q1 / Q2 quants on smaller models can be pretty inconsistent with their output quality.

1

u/esaule 3d ago

Thanks! It's Q4 models i am using.

Just switched to a qwen3.8-27B quantized and it feels already a lot better. It behaves a lot more like how codex behaves. It is surely not as good. (And clearly not as fast.) But it seems to behave in a more coherent way. Thanks!

1

u/CaramelEmotional3092 2d ago

If you have the ram, try the flash version, ie, qwen 3.8 flash next. It's a significant step up, but can potentially run quick as it has only 6b active at a time.

2

u/asdonne 3d ago

I had a similar problem with Claude-code + ollama caused by inconsistent context settings between the two. I believe the context was being truncated which was causing problems. Explicitly setting the context length in both programs fixed the issue but ultimately a quantisised 32b model is going to have limited performance.

1

u/esaule 3d ago

Yes, I have had to specify a 65k context window. Otherwise it loops instantly. But I saw the looping even very early.

I understand that a local model will likely not be competitive with a frontier model. But I feel it should be able to do basics.

Someone else suggested moving to a more recent qwen and that does seem to behave better.

What context window length do you suggest?

1

u/asdonne 2d ago

I'm still playing around and trying to get something usable so I don't have anything to recommend other than as large as you can but no larger.

I think part of the issue is not so much that the smaller local models are less competitive but they are just not smart enough to effectively use the tools. Or rather newer and larger models are required.

I'm looking into optimised models that have been tailored for limited hardware but haven't had the time to look into them yet

1

u/magicdoorai 2d ago

On the context question, the exact number matters less than LM Studio and opencode agreeing on it.

Current opencode docs say that for a model not in its catalog, it assumes a 200,000 token context limit and a 32,000 token output limit. Local discovery may pick up the real value, but check. If LM Studio loaded 65k and opencode thinks it has much more room, it won't compact in time.

You can set it explicitly in that model's entry in your opencode config, matching what LM Studio actually loaded:

"limit": {
  "context": 65536,
  "output": 8192
}

Also check the context overflow behaviour in LM Studio. The options are stop at limit, truncate middle, and rolling window. The last two drop part of the conversation, which in an agent session could easily make it lose track of what it already did and repeat it. While debugging, I'd use stop at limit so an overflow is obvious.

For size, 65k is a sensible place to stay if the model plus that context fits fully in your VRAM or unified memory. Go higher only if it still fits. If it loops again with matching limits and no overflow, I'd look at the model or quant next.

Docs: https://opencode.ai/docs/models/

1

u/Pitiful_Dot2876 2d ago

Hi, not sure if this will help you in any way, but I built a tool to observe what our coding agents are doing. Maybe with it you'll be able to check what's going on and why it's looping.
https://github.com/radekwojpl2/session-observer

1

u/Future_AGI 2d ago

65k is fine for the 27B as long as opencode knows that number too. If you added LM Studio as a custom OpenAI-compatible provider, opencode has no context number for that model and assumes 200k, so its automatic compaction waits until about 170k tokens, far past the 65k you set. Either switch to the built-in lmstudio provider (it reads the context from LM Studio) or set limit.context for the 27B to 65k in your opencode config.