Skip to content

fix: handle invalid maxOutputTokens value (0 or undefined)#22016

Open
Jedeiah wants to merge 1 commit intoanomalyco:devfrom
Jedeiah:fix/maxOutputTokens-validation
Open

fix: handle invalid maxOutputTokens value (0 or undefined)#22016
Jedeiah wants to merge 1 commit intoanomalyco:devfrom
Jedeiah:fix/maxOutputTokens-validation

Conversation

@Jedeiah
Copy link
Copy Markdown

@Jedeiah Jedeiah commented Apr 11, 2026

Issue for this PR

Closes #21858
Closes #21522

Type of change

  • Bug fix

What does this PR do?

Fixes maxOutputTokens returning 0 when model.limit.output is 0, undefined, or negative. Returns OUTPUT_TOKEN_MAX (32000) as fallback when model output limit is invalid.

When plugins pass maxOutputTokens=0 via chat.params hook, OpenCode 1.4.0+ requires >= 1, which causes "maxOutputTokens must be >= 1" error for local providers like Ollama.

How did you verify your code works?

  • Added 5 unit tests for maxOutputTokens function covering edge cases (undefined, 0, negative, valid values)
  • All tests pass

Screenshots / recordings

N/A (not a UI change)

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Fixes anomalyco#21858
Fixes anomalyco#21522

- Returns OUTPUT_TOKEN_MAX when model.limit.output is 0, undefined, or negative
- Adds unit tests for maxOutputTokens function
@github-actions github-actions bot added needs:compliance This means the issue will auto-close after 2 hours. and removed needs:compliance This means the issue will auto-close after 2 hours. labels Apr 11, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Ollama integration: Invalid maxOutputTokens error Invalid argument for parameter maxOutputTokens: maxOutputTokens must be >= 1

1 participant