fix: handle invalid maxOutputTokens value (0 or undefined)#22016
fix: handle invalid maxOutputTokens value (0 or undefined)#22016Jedeiah wants to merge 13 commits intoanomalyco:devfrom
Conversation
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
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
|
When will this PR be merged in pls? I try to add limit.context/output into the model info but it doesn't work, as this comment: #22253 (comment) |
根本原因是 oh-my-openagent 读取到某些模型的能力缓存 limit.output = 0, 以下是合理的临时方案(可丢给Ai让它去解决): 方案 A(限自定义模型,且要覆盖所有 agent 用到的模型才有效): 如果你用的是自定义 provider 里声明的模型,可以在 opencode.json 的对应模型 {
"provider": {
"your-provider": {
"models": {
"your-model-id": {
"limit": {
"output": 4096,
"context": 128000
}
}
}
}
}
}注意:oh-my-openagent 会启动多个 agent,每个 agent 用不同模型。 方案 B(治本,推荐): 直接给 oh-my-openagent 的 dist/index.js 打补丁, 文件路径(以 macOS 为例,Windows 路径类似): 改动 1 - applySessionPromptParams 写入时(搜 model.maxTokens !== undefined): 改前: 改后: 改动 2 - 读取会话参数发请求时(搜 storedPromptParams.maxOutputTokens !== undefined): 改前: if (storedPromptParams.maxOutputTokens !== undefined) {
output.maxOutputTokens = storedPromptParams.maxOutputTokens;
}改后: if (typeof storedPromptParams.maxOutputTokens === "number" && storedPromptParams.maxOutputTokens > 0) {
output.maxOutputTokens = storedPromptParams.maxOutputTokens;
}改动 3 - compatibility 结果写回时(搜 compatibility.maxTokens !== undefined): 改前: if (compatibility.maxTokens !== undefined) {
output.maxOutputTokens = compatibility.maxTokens;
} else {
delete output.maxOutputTokens;
}改后: if (typeof compatibility.maxTokens === "number" && compatibility.maxTokens > 0) {
output.maxOutputTokens = compatibility.maxTokens;
} else {
delete output.maxOutputTokens;
}改完后删除模型能力缓存再重启: |
# Conflicts: # packages/opencode/src/provider/transform.ts
…into fix/maxOutputTokens-validation
|
Hi @maintainers, this PR has been open for a while and I've resolved the merge conflicts. The code passes all unit tests and meets the contributing guidelines. Could someone please review and merge it? This fixes the maxOutputTokens >= 1 error for issues #21858 and #21522. Thank you! |
|
Hi @thdxr @Brendonovich @kitlangton, this PR has been open for a while and I've resolved the merge conflicts. The code passes all unit tests and meets the contributing guidelines. Could someone please review and merge it? This fixes the maxOutputTokens >= 1 error for issues #21858 and #21522. Thank you! |
|
The unit test failure on Windows () is a pre-existing flaky test in the base branch, not caused by my changes. I verified locally - the test passes on macOS. This appears to be the same issue mentioned in PR #22587 where the author also noted: 'The unit (windows) CI failure is unrelated to this PR. This appears to be a pre-existing issue on the base branch.' Could someone approve and merge this PR? Thank you! |
…maxOutputTokens-validation
…edeiah/opencode into fix/maxOutputTokens-validation
Issue for this PR
Closes #21858
Closes #21522
Type of change
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?
Screenshots / recordings
N/A (not a UI change)
Checklist