GeezerVison is showing github.com — Ollama provider overrides user-configured limit.context with the GGUF context_length, breaking compaction for num_ctx-capped variants · Issue #63899 · anomalyco/opencode
Ollama provider overrides user-configured limit.context with the GGUF context_length, breaking compaction for num_ctx-capped variants #63899DescriptionSummary
When a model is served through OpenCode's built-in Ollama integration, OpenCode ignores the limit.context I set in opencode.json and replaces it with the model's architecture maximum read from /api/show (model_info → *.context_length, which comes from the GGUF metadata). For my models that value is 262144, while the variants actually run with num_ctx 16384 / 32768 / 65536.
Because the Context panel and the auto-compaction budget both use the overridden 262144, auto-compaction never triggers before the real window fills. The Ollama runner then silently context-shifts / truncates, long responses die with "Response still truncated after two output token limit continuations", and resuming a full session can fail with a provider transport timeout (prefill of the oversized prompt exceeds the request timeout).
Setting limit.context is the documented way to make compaction work with local providers, so user config should win over auto-discovery.
Steps to reproduce
- Create an Ollama variant with a capped window from a model whose GGUF
context_length is 262144, e.g. a Modelfile with PARAMETER num_ctx 16384 (and PARAMETER num_predict 2048).
- In
~/.config/opencode/opencode.json, under the Ollama provider, set that model to:
"limit": { "context": 16384, "output": 2048 }
- Restart OpenCode and open a session with that model.
- Open the Context panel: Context Limit shows 262,144, not 16384. Usage is computed against 262144.
- Keep working until total tokens pass 16384: no compaction happens; the runner truncates/shifts context instead, and output-limit errors follow.
Expected behavior
An explicit limit.context in opencode.json takes precedence over values discovered from /api/show. Auto-discovery should only fill in limits the user has not set.
Alternatively (or additionally), when deriving a limit from /api/show, prefer the model's parameters (num_ctx) over model_info.*.context_length: num_ctx is the effective window the server will actually run, while context_length is only the architecture maximum. (A community discovery plugin resolves it in exactly this order: num_ctx first, model_info only as a fallback.)
Evidence
From /api/show for the variant: model_info contains qwen35.context_length = 262144, while its parameters contain num_ctx 16384 — Ollama itself correctly caps generation at 16384; only OpenCode's accounting uses 262144.
Inspecting the bundled Ollama plugin code in the OpenCode binary, the model is built roughly as:
model: (e) => ({ id: e.model, ...,
context: Object.entries(e.show.model_info ?? {}).flatMap(
([a, s]) => a.endsWith(".context_length") && ... ? [s] : [])[0] })
and later applied unconditionally:
typeof ee.context === "number" && ee.context > 0 && (me.limit.context = ee.context)
There seems to be no configuration option to disable this override.
Environment
- OS: Ubuntu 26.04.1 LTS (Linux)
- OpenCode: 2.x (V2 config schema; exact build available on request)
- Ollama: 0.32.1
- Model: Qwen3.8-27B GGUF variants (Q2_K / IQ3_XXS / Q4_K_M) with
num_ctx 16384–65536, served by Ollama on 2× Radeon RX 480
Workarounds tried
- Setting
limit.context / limit.output per model in opencode.json (with the exact :latest model id): no effect, the panel still shows 262144.
- The global compaction block (
auto: true, keep.tokens, buffer) is present but never fires, because the budget it is computed from is 262144.
- Only manual
/compact before hitting the real num_ctx wall avoids the failure.
Activityopencodejr commented on Nov 14, 2026 Thanks for the detailed write-up. I tried to reproduce this on 2.2.7, the latest release, since the issue only says 2.x, and I couldn't.
What I tried:
- A mock Ollama server on
127.0.0.1:11434 with one model, qwen-capped:latest. Its /api/show returns model_info with qwen35.context_length = 262144 and parameters with num_ctx 16384.
- This config, once in a project
opencode.json and once in ~/.config/opencode/opencode.json:
{ "providers": { "ollama": { "models": { "qwen-capped:latest": { "limit": { "context": 16384, "output": 2048 } } } } } }
- I then read the model list from OpenCode's API with
opencode api model.list. In both cases the Ollama model came back with limit: { context: 16384, output: 2048 }, so the configured limit won. Without a configured limit, it was 262144, the value discovered from Ollama.
Something in your setup must differ. Could you share:
- The exact output of
opencode --version.
- The Ollama part of your
~/.config/opencode/opencode.json, exactly as written: the top-level key (providers or provider), the provider ID and the model key.
- The model ID exactly as OpenCode shows it, from
opencode models.
- The output of
opencode debug config, run from the project where you see this, to check which config files are loaded. Leave out any API keys.
- Whether a project-level
opencode.json or .opencode directory also defines the Ollama provider.
You can reply here or edit the issue. If you edit it, please also leave a comment saying you've updated it, so we know you're done.
Simon-Shi23 commented on Nov 14, 2026 I reproduced the num_ctx problem on macOS against a real Ollama 0.17.7. A model built with PARAMETER num_ctx 8192 reports a qwen2.context_length of 32768 in /api/show, while OpenCode exposes the model with limit.context 32768. OpenCode should expose the configured runtime window instead.
I also tested the config override. With the model id spelled exactly as Ollama reports it, including the tag suffix, OpenCode reported limit.context 16384 from both the project config and ~/.config/opencode/opencode.json, same as the 2.2.7 check above. I couldn't reproduce the overwrite.
Can you assign this to me? Nss67 commented on Nov 14, 2026 Thanks both for looking at this so quickly — @opencodejr for the reproduction attempt, and @Simon-Shi23 for the macOS repro and for offering to pick this up (a +1 from me on that; your num_ctx discovery result matches what motivated this issue).
Version first, since it may be the crux: I am on opencode v2.2.6 — one below the 2.2.7 you tested on. My original report never filled the version in (it only said "2.x"); sorry about that.
Here are the diagnostics you asked for:
1. opencode --version
2. Ollama section of ~/.config/opencode/opencode.json, exactly as written (top-level key is providers):
"providers": {
"ollama": {
"models": {
"Q2-16k-TurboFast-Coder-Agentic-Qwen3.8-27B:latest": { "limit": { "context": 16384, "output": 8192 } },
"Q2-32k-Base-Coder-Agentic-Qwen3.8-27B:latest": { "limit": { "context": 32768, "output": 8192 } },
"Q2-32k-Fast-Coder-Agentic-Qwen3.8-27B:latest": { "limit": { "context": 32768, "output": 8192 } },
"Q2-64k-Deep-Coder-Agentic-Qwen3.8-27B:latest": { "limit": { "context": 65536, "output": 8192 } },
"Q3-16k-TurboFast-Coder-Agentic-Qwen3.8-27B:latest": { "limit": { "context": 16384, "output": 8192 } },
"Q3-32k-Base-Coder-Agentic-Qwen3.8-27B:latest": { "limit": { "context": 32768, "output": 8192 } },
"Q3-32k-Fast-Coder-Agentic-Qwen3.8-27B:latest": { "limit": { "context": 32768, "output": 8192 } },
"Q3-64k-Deep-Coder-Agentic-Qwen3.8-27B:latest": { "limit": { "context": 65536, "output": 8192 } },
"Q4-16k-TurboFast-Coder-Agentic-Qwen3.8-27B:latest": { "limit": { "context": 16384, "output": 8192 } },
"Q4-32k-Base-Coder-Agentic-Qwen3.8-27B:latest": { "limit": { "context": 32768, "output": 8192 } },
"Q4-32k-Fast-Coder-Agentic-Qwen3.8-27B:latest": { "limit": { "context": 32768, "output": 8192 } },
"Q4-64k-Deep-Coder-Agentic-Qwen3.8-27B:latest": { "limit": { "context": 65536, "output": 8192 } }
},
"settings": { "baseURL": "http://127.0.0.1:11434/v1" }
}
},
"compaction": { "auto": true, "keep": { "tokens": 10000 }, "buffer": "20%" },
"model": "ollama/Q2-64k-Deep-Coder-Agentic-Qwen3.8-27B:latest"
3. Model ID exactly as OpenCode shows it (opencode models):
ollama/Q2-16k-TurboFast-Coder-Agentic-Qwen3.8-27B:latest
(the other 11 variants list identically: ollama/Q2-/Q3-/Q4- × 16k-TurboFast / 32k-Base / 32k-Fast / 64k-Deep, all :latest)
4. opencode debug config (run from the project directory, /home/nss67 — it contains no API keys):
Full output (models object condensed to one line per model; values identical to section 2)
[
{
"type": "document",
"path": "/home/nss67/.config/opencode/opencode.json",
"info": {
"$schema": "https://opencode.ai/config.json",
"model": { "providerID": "ollama", "model": "Q2-64k-Deep-Coder-Agentic-Qwen3.8-27B:latest" },
"compaction": { "auto": true, "keep": { "tokens": 10000 }, "buffer": "20%" },
"providers": {
"ollama": {
"settings": { "baseURL": "http://127.0.0.1:11434/v1" },
"models": {
"Q2-16k-TurboFast-Coder-Agentic-Qwen3.8-27B:latest": { "limit": { "context": 16384, "output": 8192 } },
"Q2-32k-Base-Coder-Agentic-Qwen3.8-27B:latest": { "limit": { "context": 32768, "output": 8192 } },
"Q2-32k-Fast-Coder-Agentic-Qwen3.8-27B:latest": { "limit": { "context": 32768, "output": 8192 } },
"Q2-64k-Deep-Coder-Agentic-Qwen3.8-27B:latest": { "limit": { "context": 65536, "output": 8192 } },
"Q3-16k-TurboFast-Coder-Agentic-Qwen3.8-27B:latest": { "limit": { "context": 16384, "output": 8192 } },
"Q3-32k-Base-Coder-Agentic-Qwen3.8-27B:latest": { "limit": { "context": 32768, "output": 8192 } },
"Q3-32k-Fast-Coder-Agentic-Qwen3.8-27B:latest": { "limit": { "context": 32768, "output": 8192 } },
"Q3-64k-Deep-Coder-Agentic-Qwen3.8-27B:latest": { "limit": { "context": 65536, "output": 8192 } },
"Q4-16k-TurboFast-Coder-Agentic-Qwen3.8-27B:latest": { "limit": { "context": 16384, "output": 8192 } },
"Q4-32k-Base-Coder-Agentic-Qwen3.8-27B:latest": { "limit": { "context": 32768, "output": 8192 } },
"Q4-32k-Fast-Coder-Agentic-Qwen3.8-27B:latest": { "limit": { "context": 32768, "output": 8192 } },
"Q4-64k-Deep-Coder-Agentic-Qwen3.8-27B:latest": { "limit": { "context": 65536, "output": 8192 } }
}
}
}
}
},
{ "type": "directory", "path": "/home/nss67/.config/opencode" },
{ "type": "directory", "path": "/home/nss67/.opencode" }
]
5. Project-level config: No. There is no opencode.json in the project directory and no .opencode folder there defining the Ollama provider. (A ~/.opencode/ directory exists, but it only holds the binary, bin/opencode.)
Full disclosure — my setup had a second, separate problem, and my original report conflated two different states:
- I often start the server with
sudo, which makes HOME=/root. /root/.config/opencode/ was empty, so those server runs loaded no config at all — and in that state I saw 200,000 in the panel. I have since symlinked the real config into /root/.config/opencode/ (identical md5), so both homes now load the same file.
- The 262,144 readings came from sessions on 13 Nov (I have screenshots: model
ollama/Q2-16k-TurboFast-Coder-Agentic-Qwen3.8-27B:latest, Context Limit 262,144; in one of them Total Tokens hit exactly 16,384 with a response cut mid-sentence — the real cap was clearly num_ctx, not the panel number). Given the HOME mess above, I cannot retroactively prove which config each of those server processes had actually loaded — only that the limits were in the file on disk. So I can't swear the override alone produced those readings.
- Today, on the same v2.2.6 with the config verifiably loaded (see 4), the panel shows 16,384 for the 16k model and auto-compaction fired at 13,441 tokens (82%). But that run goes through a small local proxy that strips
*.context_length keys from /api/show responses — so it does not isolate the variable either.
So the clean experiment is still open, and I'm happy to run it: on v2.2.6 with the proxy bypassed (Ollama directly on 11434) and the config verified loaded, a fresh session + panel reading — or the same after upgrading to 2.2.7. Tell me which is more useful to you.
Setup: Ubuntu 26.04.1 LTS, Ollama 0.32.1, Qwen3.8-27B GGUF variants (num_ctx 16384 / 32768 / 65536), 2× AMD RX 480 (Vulkan). opencodejr commented on Nov 14, 2026 Thanks for the thorough follow-up and for untangling the sudo/HOME part. That explains a lot.
I re-ran my check on 2.2.6, your version, with the same mock Ollama server. Its /api/show reports qwen35.context_length = 262144 and num_ctx 16384, and the config sets limit.context: 16384 under providers.ollama.models["<id>:latest"]. OpenCode kept the configured 16384, the same result as on 2.2.7. @Simon-Shi23 couldn't reproduce the override on macOS either. Together with your finding that the panel shows 16,384 and auto-compaction fires once the config is really loaded, I think the explicit limit.context does take precedence. The earlier readings probably came from the server runs that loaded no config, so there's no need to run the clean experiment for that part.
The part that still stands is the other one. When no limit is configured, the Ollama integration uses the GGUF *.context_length from model_info (the architecture maximum) rather than the num_ctx the variant actually runs with. The code is written to read *.context_length, and the docs only say context is read from Ollama, so this is the current design rather than a bug. I'm treating it as a feature request: when deriving the context limit from /api/show, prefer num_ctx from parameters and fall back to model_info only when it isn't set. Maintainers will consider it, including @Simon-Shi23's offer to work on it. Until then, setting limit.context per model, as you already do, gives OpenCode the real window.
Nss67 commented on Nov 14, 2026 Small correction to my comment above and to the issue's environment section: my Ollama version is 0.40.16, not 0.32.1 — the 0.32.1 figure came from my older notes. Everything else in the diagnostics above is unchanged.
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|