Repository navigation
Description
Summary
opencode-go/glm-5.2 is advertised with a 1,000,000-token context window (both on https://opencode.ai/docs/go/ and via https://models.dev/api.json), but the Go backend routes GLM-5.2 requests to providers that only support 262,144 tokens (DigitalOcean Inference Engine, Cloudflare Workers AI). opencode trusts the models.dev metadata, computes usable against 1M, and only discovers the real backend cap when the provider returns a hard overflow error — at which point compaction has already failed.
Result: paying Go subscribers hit unrecoverable Conversation history too large to compact at ~230K input tokens, far below the advertised 1M, and lose the session.
Error
Error from provider (DigitalOcean): This model's maximum context length is 262144 tokens.
However, you requested 32000 output tokens and your prompt contains at least 230145 input tokens,
for a total of at least 262145 tokens. Please reduce the length of the input prompt or the number
of requested output tokens. (parameter=input_tokens, value=230145)
Followed by:
Conversation history too large to compact - exceeds model context limit 406.6K (41%) · $113.22
Expected vs actual
| Advertised | Actual (DigitalOcean backend) | |
|---|---|---|
| Context | 1,000,000 | 262,144 |
| Output | 131,072 | 52,429 |
usable (opencode computes) |
~849K | — |
usable (real backend) |
— | ~189K |
opencode computes usable = model.limit.context - maxOutputTokens - reserved = 1,000,000 - 131,072 - 20,000 ≈ 849K (per packages/opencode/src/session/overflow.ts). Compaction triggers near 849K. The compaction prompt alone (system + tools + MCP defs + skills) exceeds 230K, so the very first compaction request overflows the real 262K backend.
Evidence
-
models.dev metadata (what opencode trusts):
"opencode-go": { "models": { "glm-5.2": { "limit": { "context": 1000000, "output": 131072 } } } }
Cached at
~/.cache/opencode/models.json, refreshed fromhttps://models.dev/api.json. -
docs/opencode.ai/docs/go/ table lists GLM-5.2 with 1M context and 131K output.
-
DigitalOcean docs (
docs.digitalocean.com/products/inference/details/models/):Z.ai GLM-5.2 — context 262,144, output 52,429
-
Cloudflare changelog (
developers.cloudflare.com/changelog/2026-06-16-glm-52-workers-ai):Workers AI is launching the model with a 262,144 token context window and plans to increase this in the future.
-
Endpoint
https://opencode.ai/zen/go/v1/modelsreturns only{id, owned_by}— nocontext_lengthfield — so opencode cannot detect the real backend cap from the provider and falls back to models.dev's 1M claim.
Root cause
Two compounding bugs:
-
Backend routing mismatch: Go routes
glm-5.2to backends that cap at 262K while advertising 1M in metadata. Either route only to 1M-capable backends (Z.ai native, Fireworks) or updateopencode-go/glm-5.2metadata to reflect the lowest common backend (262K) so opencode computesusablecorrectly. -
Overflow error not classified (already tracked in fix(provider): Z.AI GLM overflow error not classified as context overflow, causing chain compaction #27629): the DigitalOcean/Z.ai overflow error phrasing ("This model's maximum context length is 262144 tokens. However, you requested…") is not in
OVERFLOW_PATTERNS(packages/opencode/src/provider/error.ts), so it is treated as a genericAPICallErrorinstead ofContextOverflowError, preventing graceful auto-compaction and leaving the session permanently stuck.
Repro
- Subscribe to OpenCode Go, connect via
/connect. - Use
opencode-go/glm-5.2as default model. - Load a large session (10+ MCP servers, 100+ tool calls, AGENTS.md hierarchy) until compaction triggers.
- Observe: compaction request itself exceeds 262K → DigitalOcean returns overflow → opencode does not classify as context overflow →
Conversation history too large to compact→ session dead.
Environment:
- opencode 1.17.18
- Windows / PowerShell
- Provider:
opencode-go/glm-5.2viahttps://opencode.ai/zen/go/v1 - 10 MCP servers enabled (github, tg, web-search, mcp-fetch, mcp-playwright, mcp-git, mcp-memopalace, mcp-codegraph, mcp-context7, mcp-grep)
Related issues
- fix(provider): Z.AI GLM overflow error not classified as context overflow, causing chain compaction #27629 — Z.AI GLM overflow error not classified as context overflow (same root cause Roadmap & Existing Issues #2)
- GLM5.2 in go plan has some problem #33029 — GLM-5.2 in Go plan inheriting upstream Z.ai quota limits (same pattern: Go metadata vs upstream reality mismatch)
- OpenCode Go: 11/12 models silently fail with Insufficient Balance - upstream provider accounts depleted, breaks multi-agent orchestration #28129, After subscribing to OpenCode Go, I encountered the Insufficient balance error when using non-free models such as GLM 5.1 and Kimi v2.6. #30950 — Go upstream provider account depletion surfacing as user-facing errors
- OAuth/Codex GPT-5.5 behaves like ~400k context while GPT-5.4 shows 1M #24561 — context limit mismatch between metadata and actual provider limits (umbrella)
- Auto-compaction triggers at ~200k tokens instead of model's actual context window (1M) #15871 — hardcoded context window ignoring actual model limits
- fix(provider): classify "tokens in request more than max tokens allowed" as context overflow #27519 — same class of bug, OpenAI-compatible overflow phrasing
Proposed fix
Two independent fixes, both useful:
-
Metadata honesty: in
packages/opencode/src/provider/provider.ts(or via models.dev), capopencode-go/glm-5.2limit.contextto the minimum across all backends Go routes to (262,144 today), until all backends support 1M. Alternatively, expose backend identity inhttps://opencode.ai/zen/go/v1/modelsso opencode can pick the right limit per request. -
Overflow classification: add to
OVERFLOW_PATTERNSinpackages/opencode/src/provider/error.ts:/This model's maximum context length is \d+ tokens/i, /maximum context length is \d+ tokens\. However, you requested/i,
This ensures that even when metadata lies, the overflow is recognised and auto-compaction can reduce context instead of bricking the session.
Why this matters
Go subscribers pay for the advertised 1M context. Silently routing to 262K backends — and then bricking the session because the overflow is not recognised — is a paid-feature regression. The $113.22 session cost is not refundable through opencode; the user is left with a dead session and no indication that the root cause is backend routing, not their usage.
Activity
PowerfulShell commentedon Jul 12, 2026
The OpenCode Go gateway still times out active streams after ~60s. These changes make the failure visible and protect your files, but can't prevent the server from closing the connection. That requires an upstream server-side change (longer timeout, SSE heartbeats).
i had the same issue when ask which ever model, premium to flash, all of them cannot do a single 3500 line html files. will always return "terminated" without further explaining what went wrong.
github-actions commentedon Sep 11, 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.