[GH-ISSUE #1736] Large context window presents a problem #692

Closed
opened 2026-11-04 01:45:07 +07:00 by bsakaguchi · 9 comments
Owner

Originally created by @galmok on GitHub (Oct 9, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/1736

I am using opencode to work with Strata and while this seems fairly solid, I am hitting one problem again and again:

prompt (230219 tokens) + max tokens (32000) exceeds the context (262144); requests are never truncated. Send a smaller max_tokens (at most 31917 here), or add "fit_max_tokens": true to the model's strata-.json to shorten it to the room left (#545)

While this does show the problem and also presents a solution, I am uncertain what this does. Will it continue as normal (32000 token window) until the very end and then use a token window that fits the remaining space? Or will it change more than that?

If it just fits the last window to the remaining space, shouldn't that option be enabled by default?

Originally created by @galmok on GitHub (Oct 9, 2026). Original GitHub issue: https://github.com/Niko1221/Strata/issues/1736 I am using opencode to work with Strata and while this seems fairly solid, I am hitting one problem again and again: > prompt (230219 tokens) + max tokens (32000) exceeds the context (262144); requests are never truncated. Send a smaller max_tokens (at most 31917 here), or add "fit_max_tokens": true to the model's strata-<model>.json to shorten it to the room left (#545) While this does show the problem and also presents a solution, I am uncertain what this does. Will it continue as normal (32000 token window) until the very end and then use a token window that fits the remaining space? Or will it change more than that? If it just fits the last window to the remaining space, shouldn't that option be enabled by default?
Author
Owner

@AXYZE9 commented on GitHub (Oct 9, 2026):

You need to compact your context in OpenCode. Strata has nothing to do with it.

If it just fits the last window to the remaining space, shouldn't that option be enabled by default?

No, Strata (or any inference engine) shouldn't quietly change settings that were set.

<!-- gh-comment-id:6084354729 --> @AXYZE9 commented on GitHub (Oct 9, 2026): You need to compact your context in OpenCode. Strata has nothing to do with it. > If it just fits the last window to the remaining space, shouldn't that option be enabled by default? No, Strata (or any inference engine) shouldn't quietly change settings that were set.
Author
Owner

@CC-David-CC commented on GitHub (Oct 9, 2026):

use yarn on long contexts and rope on short contexts
proof:
https://github.com/Niko1221/Strata/pull/1692
https://github.com/Niko1221/Strata/pull/1698
https://github.com/Niko1221/Strata/pull/1702

<!-- gh-comment-id:6084805298 --> @CC-David-CC commented on GitHub (Oct 9, 2026): use yarn on long contexts and rope on short contexts proof: https://github.com/Niko1221/Strata/pull/1692 https://github.com/Niko1221/Strata/pull/1698 https://github.com/Niko1221/Strata/pull/1702
Author
Owner

@galmok commented on GitHub (Oct 9, 2026):

Well, I changed the strata option the error message mentioned and opencode could continue using the remaining context window (from 230K to 262K). The trigger in opencode does not happen already at 230K so the error from Strata is unexpected.

I added:

"fit_max_tokens": true

to my strata json model config file and strata is now more predictable when the context window gets big.

<!-- gh-comment-id:6085166882 --> @galmok commented on GitHub (Oct 9, 2026): Well, I changed the strata option the error message mentioned and opencode could continue using the remaining context window (from 230K to 262K). The trigger in opencode does not happen already at 230K so the error from Strata is unexpected. I added: "fit_max_tokens": true to my strata json model config file and strata is now more predictable when the context window gets big.
Author
Owner

@galmok commented on GitHub (Oct 9, 2026):

2. use yarn on long contexts and rope on short contexts

I am sorry to say, but at this point in time, I don't really know how to use this information. I am not familiar with all the different parameters to Strata.

<!-- gh-comment-id:6085200146 --> @galmok commented on GitHub (Oct 9, 2026): > 2\. use yarn on long contexts and rope on short contexts I am sorry to say, but at this point in time, I don't really know how to use this information. I am not familiar with all the different parameters to Strata.
Author
Owner

@galmok commented on GitHub (Oct 9, 2026):

Just to make it clear: The error shown actually is sent to opencode and is displayed in the opencode session.

<!-- gh-comment-id:6085259718 --> @galmok commented on GitHub (Oct 9, 2026): Just to make it clear: The error shown actually is sent to opencode and is displayed in the opencode session.
Author
Owner

@GM2080 commented on GitHub (Oct 9, 2026):

You need limit.context and limit.output in your opencode config, then it will compact automatically.
context - max_tokens = point at which it compacts to prevent the model from running out of context mid-turn.

An example opencode.config (this is for llama-swap, llama.cpp and q38-27b but the same still applies)

  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "llama-swap": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "llama-swap",
      "options": {
        "baseURL": "http://localhost:8080/v1",
        "includeUsage": true
      },
      "models": {
        "Qwen3.8-27b:coding": {
          "name": "Qwen3.8-27b:coding",
          "limit": {
            "context": 131072,
            "output": 32000
          },
          "modalities": {
            "input": ["text", "image"],
            "output": ["text"]
          },
          "variants": {
            "no-thinking": { "chat_template_kwargs": { "enable_thinking": false } },
            "low": { "chat_template_kwargs": { "enable_thinking": true, "reasoning_effort": "low" } },
            "medium": { "chat_template_kwargs": { "enable_thinking": true, "reasoning_effort": "medium" } },
            "xhigh": { "chat_template_kwargs": { "enable_thinking": true, "reasoning_effort": "xhigh" } }
          }
        },
      }

There are probably plugins or something for opencode that will read the /v1/models response and handle context/output and modalities for you.

<!-- gh-comment-id:6085887602 --> @GM2080 commented on GitHub (Oct 9, 2026): You need limit.context and limit.output in your opencode config, then it will compact automatically. *context - max_tokens = point at which it compacts* to prevent the model from running out of context mid-turn. An example opencode.config (this is for llama-swap, llama.cpp and q38-27b but the same still applies) ```json "$schema": "https://opencode.ai/config.json", "provider": { "llama-swap": { "npm": "@ai-sdk/openai-compatible", "name": "llama-swap", "options": { "baseURL": "http://localhost:8080/v1", "includeUsage": true }, "models": { "Qwen3.8-27b:coding": { "name": "Qwen3.8-27b:coding", "limit": { "context": 131072, "output": 32000 }, "modalities": { "input": ["text", "image"], "output": ["text"] }, "variants": { "no-thinking": { "chat_template_kwargs": { "enable_thinking": false } }, "low": { "chat_template_kwargs": { "enable_thinking": true, "reasoning_effort": "low" } }, "medium": { "chat_template_kwargs": { "enable_thinking": true, "reasoning_effort": "medium" } }, "xhigh": { "chat_template_kwargs": { "enable_thinking": true, "reasoning_effort": "xhigh" } } } }, } ``` There are probably plugins or something for opencode that will read the /v1/models response and handle context/output and modalities for you.
Author
Owner

@galmok commented on GitHub (Oct 9, 2026):

6. You need limit.context and limit.output in your opencode config, then it will compact automatically.
context - max_tokens = point at which it compacts to prevent the model from running out of context mid-turn.
An example opencode.config (this is for llama-swap, llama.cpp and q38-27b but the same still applies)
[snip]

    There are probably plugins or something for opencode that will read the /v1/models response and handle context/output and modalities for you.

Thanks. I'll read up on this soon. :)

<!-- gh-comment-id:6087637601 --> @galmok commented on GitHub (Oct 9, 2026): > 6\. You need limit.context and limit.output in your opencode config, then it will compact automatically. > _context - max_tokens = point at which it compacts_ to prevent the model from running out of context mid-turn. > An example opencode.config (this is for llama-swap, llama.cpp and q38-27b but the same still applies) [snip] > > > > There are probably plugins or something for opencode that will read the /v1/models response and handle context/output and modalities for you. Thanks. I'll read up on this soon. :)
Author
Owner

@Xhen911 commented on GitHub (Oct 10, 2026):

Root cause is an arithmetic mismatch — and the repo's own docs point users straight into it.

serve/server.py gives a reply the room left after the prompt:

room = ctx - CTX_SLACK(8) - len(prompt)

A request whose max_tokens exceeds room is refused with 400, never truncated. So with --max-context 262144 and a client that always asks for its full output cap, the longest prompt that can ever be sent is:

262144 - 8 - 32768 = 229,368 tokens

That is why the error appears "unexpectedly" at ~230K — it isn't OpenCode's compaction threshold misfiring, it's the hard ceiling once the output reservation is counted. Your own numbers match exactly: 230219 + 32000 > 262144, leaving 31,917 (the same 31,917 the error quotes).

The reason it bites OpenCode users in particular is that docs/DETAILS.md tells them to declare the full context. The OpenCode example added in #543 reads:

// context: what you chose in setup; output: what one reply may use (prompt + output must fit)
"limit": { "context": 262144, "output": 32768 },

which contradicts itself — the comment states the rule ("prompt + output must fit") and the numbers break it by exactly the amount above. Following the docs reproduces this issue. It should be:

// context: what you chose in setup MINUS output
"limit": { "context": 229376, "output": 32768 },   // 262144 - 32768

and the paragraph under it ("Set limit.context to the context you chose in setup") should say "minus limit.output".

With limit.context = 229376, OpenCode compacts before the prompt reaches the ceiling and the 400 never happens. In my testing it compacted earlier still, since it also reserves output and compaction.reserved on top — the safe direction. Verified end to end: compaction agent fires, session continues, server-side prompt drops from ~193K to ~8K.

On fit_max_tokens: a good stopgap and worth keeping as a backstop, but it isn't the fix. It shortens the reply to whatever room is left, so the turn still degrades — it just degrades quietly instead of erroring.

Which also answers the original question ("shouldn't that be the default?"). The engine deliberately never truncates anything, and fit_max_tokens only ever clips the reply, never the prompt — so defaulting it on would silently cap output rather than resolve an over-full context. The prompt budget belongs on the client, and the docs should say so.

<!-- gh-comment-id:6097568060 --> @Xhen911 commented on GitHub (Oct 10, 2026): Root cause is an arithmetic mismatch — and the repo's own docs point users straight into it. `serve/server.py` gives a reply the room left after the prompt: room = ctx - CTX_SLACK(8) - len(prompt) A request whose `max_tokens` exceeds `room` is refused with 400, never truncated. So with `--max-context 262144` and a client that always asks for its full output cap, the longest prompt that can ever be sent is: 262144 - 8 - 32768 = 229,368 tokens That is why the error appears "unexpectedly" at ~230K — it isn't OpenCode's compaction threshold misfiring, it's the hard ceiling once the output reservation is counted. Your own numbers match exactly: 230219 + 32000 > 262144, leaving 31,917 (the same 31,917 the error quotes). The reason it bites OpenCode users in particular is that **`docs/DETAILS.md` tells them to declare the full context.** The OpenCode example added in #543 reads: // context: what you chose in setup; output: what one reply may use (prompt + output must fit) "limit": { "context": 262144, "output": 32768 }, which contradicts itself — the comment states the rule ("prompt + output must fit") and the numbers break it by exactly the amount above. Following the docs reproduces this issue. It should be: // context: what you chose in setup MINUS output "limit": { "context": 229376, "output": 32768 }, // 262144 - 32768 and the paragraph under it ("Set `limit.context` to the context you chose in setup") should say "minus `limit.output`". With `limit.context` = 229376, OpenCode compacts before the prompt reaches the ceiling and the 400 never happens. In my testing it compacted earlier still, since it also reserves `output` and `compaction.reserved` on top — the safe direction. Verified end to end: compaction agent fires, session continues, server-side prompt drops from ~193K to ~8K. On `fit_max_tokens`: a good stopgap and worth keeping as a backstop, but it isn't the fix. It shortens the *reply* to whatever room is left, so the turn still degrades — it just degrades quietly instead of erroring. Which also answers the original question ("shouldn't that be the default?"). The engine deliberately never truncates anything, and `fit_max_tokens` only ever clips the reply, never the prompt — so defaulting it on would silently cap output rather than resolve an over-full context. The prompt budget belongs on the client, and the docs should say so.
Author
Owner

@Niko1221 commented on GitHub (Oct 13, 2026):

Thanks for the report. To keep the tracker current we are closing issues older than three days: 0.1.44 is out with a long list of fixes, and many older reports are covered by it or by 0.1.43.1.

If this still happens on 0.1.44, please leave a comment here with your engine log (and the version line it prints), and we will reopen it. A new issue that links this one works too.

<!-- gh-comment-id:6156195652 --> @Niko1221 commented on GitHub (Oct 13, 2026): Thanks for the report. To keep the tracker current we are closing issues older than three days: [0.1.44](https://github.com/Niko1221/Strata/releases/tag/v0.1.44) is out with a long list of fixes, and many older reports are covered by it or by 0.1.43.1. If this still happens on 0.1.44, please leave a comment here with your engine log (and the version line it prints), and we will reopen it. A new issue that links this one works too.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#692
No description provided.