anomalyco / anomalyco/opencode

Variant limit overrides ignored for maxOutputTokens and compaction

Open
#48,323 1 comment 0 reactions 1 assignee View on GitHub

@nexxeln is already working on this.

Since Sep 10, 2026.

Dominant language
TypeScript
Stars
209k
Forks
27.5k
PR merge metrics
PR metrics pending

Description

Description

When a model variant defines its own limit (e.g. a longer output cap), it is never used.
The variant is only merged into request options (session/llm/request.ts:80-91); a
nested variant.limit ends up as an inert key in provider options.

Why is this needed? Most models become more expensive after 272k token, i want to have variants to limit this without redefining it as a different model.

Both values derived from the output limit still use only the base model:

  • maxOutputTokens sent to the provider (request.ts:129, via transform.ts:1468:
    Math.min(model.limit.output, outputTokenMax) || outputTokenMax)
  • compaction reserved/usable (processor.ts step-finish -> overflow.ts:
    cfg.compaction?.reserved ?? min(20_000, maxOutputTokens(model)))

Suggested fix: resolve the effective output limit as variant -> model -> default before
clamping. maxOutputTokens already has everything it needs at request.ts:80 (the variant is
already resolved there); overflow.ts would additionally need the active variant passed in.

Sketch:

export function maxOutputTokens(model, outputTokenMax = OUTPUT_TOKEN_MAX, variant?) {
  const limit = variant?.limit?.output ?? model.limit.output
  return Math.min(limit, outputTokenMax) || outputTokenMax
}
Plugins

(none)

OpenCode version

1.18.30

Steps to reproduce
  1. Define a model with a variant that has its own output limit:

    {
      "provider": {
        "myprovider": {
          "models": {
            "mymodel": {
              "variants": { "long": { "limit": { "output": 32000 } } }
            }
          }
        }
      }
    }
    
  2. Use the model with the long variant.

  3. Request is still capped at default output tokens; compaction reserved is also computed from default, not 32000.

Screenshot and/or share link

(n/a - request/token behavior, no visible symptom)

Operating System

Windows 11

Terminal

VS Code integrated terminal (opencode via VS Code CLI extension)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.