Skip to content

opencode-go/glm-5.2 routed to 262K backend (DigitalOcean) despite 1M advertised context, overflow not classified #36481

Description

@Vladimir-Human

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

  1. models.dev metadata (what opencode trusts):

    "opencode-go": { "models": { "glm-5.2": { "limit": { "context": 1000000, "output": 131072 } } } }

    Cached at ~/.cache/opencode/models.json, refreshed from https://models.dev/api.json.

  2. docs/opencode.ai/docs/go/ table lists GLM-5.2 with 1M context and 131K output.

  3. DigitalOcean docs (docs.digitalocean.com/products/inference/details/models/):

    Z.ai GLM-5.2 — context 262,144, output 52,429

  4. 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.

  5. Endpoint https://opencode.ai/zen/go/v1/models returns only {id, owned_by} — no context_length field — 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:

  1. Backend routing mismatch: Go routes glm-5.2 to backends that cap at 262K while advertising 1M in metadata. Either route only to 1M-capable backends (Z.ai native, Fireworks) or update opencode-go/glm-5.2 metadata to reflect the lowest common backend (262K) so opencode computes usable correctly.

  2. 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 generic APICallError instead of ContextOverflowError, preventing graceful auto-compaction and leaving the session permanently stuck.

Repro

  1. Subscribe to OpenCode Go, connect via /connect.
  2. Use opencode-go/glm-5.2 as default model.
  3. Load a large session (10+ MCP servers, 100+ tool calls, AGENTS.md hierarchy) until compaction triggers.
  4. 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.2 via https://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

Proposed fix

Two independent fixes, both useful:

  1. Metadata honesty: in packages/opencode/src/provider/provider.ts (or via models.dev), cap opencode-go/glm-5.2 limit.context to the minimum across all backends Go routes to (262,144 today), until all backends support 1M. Alternatively, expose backend identity in https://opencode.ai/zen/go/v1/models so opencode can pick the right limit per request.

  2. Overflow classification: add to OVERFLOW_PATTERNS in packages/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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions