Skip to content

Variant limit overrides ignored for maxOutputTokens and compaction #48323

Closed as not planned

Description

@hendrikp

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)

Activity

  1. github-actions commented on Sep 10, 2026

    @github-actions
    Contributor

    This issue might be related to existing issues around variant field handling. Please check:

  2. thdxr commented on Oct 11, 2026

    @thdxr
    Member

    Thanks for the report! OpenCode 2.0 is now out and development is focused on V2, so we're closing issues filed against OpenCode 1. Please upgrade (opencode upgrade --major, details: https://anoma.ly/notes/opencode-2-0), and if this is still relevant on 2.0, reopen this issue or open a new one with your 2.0 version.

    — from 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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