anomalyco / anomalyco/opencode
Variant limit overrides ignored for maxOutputTokens and compaction
@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:
maxOutputTokenssent to the provider (request.ts:129, viatransform.ts:1468:
Math.min(model.limit.output, outputTokenMax) || outputTokenMax)- compaction
reserved/usable(processor.tsstep-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
-
Define a model with a variant that has its own output limit:
{ "provider": { "myprovider": { "models": { "mymodel": { "variants": { "long": { "limit": { "output": 32000 } } } } } } } } -
Use the model with the
longvariant. -
Request is still capped at default output tokens; compaction
reservedis 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.