fix(shared): guard maxOutputTokens <= 0 in model settings compatibility (#3305)
When model metadata reports maxOutputTokens as 0 or negative, the clamp logic would set maxTokens to 0 and break generation. Added a positive-value guard so invalid metadata is ignored and the user-requested maxTokens is preserved. 🤖 Generated with OhMyOpenCode assistance https://github.com/code-yeongyu/oh-my-opencode
This commit is contained in:
@@ -486,6 +486,30 @@ describe("resolveCompatibleModelSettings", () => {
|
|||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test("#given capabilities.maxOutputTokens is 0 #then maxTokens preserved unchanged", () => {
|
||||||
|
const result = resolveCompatibleModelSettings({
|
||||||
|
providerID: "openai",
|
||||||
|
modelID: "gpt-5.4",
|
||||||
|
desired: { maxTokens: 200_000 },
|
||||||
|
capabilities: { maxOutputTokens: 0 },
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(result.maxTokens).toBe(200_000)
|
||||||
|
expect(result.changes).toEqual([])
|
||||||
|
})
|
||||||
|
|
||||||
|
test("#given capabilities.maxOutputTokens is -1 #then maxTokens preserved unchanged", () => {
|
||||||
|
const result = resolveCompatibleModelSettings({
|
||||||
|
providerID: "openai",
|
||||||
|
modelID: "gpt-5.4",
|
||||||
|
desired: { maxTokens: 200_000 },
|
||||||
|
capabilities: { maxOutputTokens: -1 },
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(result.maxTokens).toBe(200_000)
|
||||||
|
expect(result.changes).toEqual([])
|
||||||
|
})
|
||||||
|
|
||||||
// Passthrough: undefined desired values produce no changes
|
// Passthrough: undefined desired values produce no changes
|
||||||
test("no-op when desired settings are empty", () => {
|
test("no-op when desired settings are empty", () => {
|
||||||
const result = resolveCompatibleModelSettings({
|
const result = resolveCompatibleModelSettings({
|
||||||
|
|||||||
@@ -165,6 +165,7 @@ export function resolveCompatibleModelSettings(
|
|||||||
if (
|
if (
|
||||||
maxTokens !== undefined &&
|
maxTokens !== undefined &&
|
||||||
input.capabilities?.maxOutputTokens !== undefined &&
|
input.capabilities?.maxOutputTokens !== undefined &&
|
||||||
|
input.capabilities.maxOutputTokens > 0 &&
|
||||||
maxTokens > input.capabilities.maxOutputTokens
|
maxTokens > input.capabilities.maxOutputTokens
|
||||||
) {
|
) {
|
||||||
changes.push({
|
changes.push({
|
||||||
|
|||||||
Reference in New Issue
Block a user