Description
#43248 guarded the cost operands, but the tier selection right above them is still unguarded:
input.model.cost?.tiers
?.filter((item) => item.tier.type === "context" && contextTokens > item.tier.size)
cost() in provider/provider.ts copies tier: item.tier straight from the models.dev / plugin payload with no guard of its own — unlike input/output/cache. So a malformed tiers still throws from getUsage and takes the turn with it. Same symptom as #43098 (fatal under opencode acp), different error:
cost.tiers |
error on dev |
[{ input, output, cache }] (no tier key) |
TypeError: undefined is not an object (evaluating 'item.tier.type') |
[null] |
TypeError: null is not an object (evaluating 'item.tier') |
{} (not an array) |
TypeError: input.model.cost?.tiers?.filter is not a function |
Note a non-numeric tier.size must not be coerced to 0 when fixing this — that would make the tier match every context instead of none.
OpenCode version
Reproduces on current dev (9b0dd36 — i.e. with #43248 already in).
Steps to reproduce
Call getUsage with a model whose cost.tiers is any of the three shapes above. Three failing unit tests in the PR that follows.
Operating System
macOS
Terminal
VS Code integrated terminal
Description
#43248 guarded the cost operands, but the tier selection right above them is still unguarded:
cost()inprovider/provider.tscopiestier: item.tierstraight from the models.dev / plugin payload with no guard of its own — unlikeinput/output/cache. So a malformedtiersstill throws fromgetUsageand takes the turn with it. Same symptom as #43098 (fatal underopencode acp), different error:cost.tiersdev[{ input, output, cache }](notierkey)TypeError: undefined is not an object (evaluating 'item.tier.type')[null]TypeError: null is not an object (evaluating 'item.tier'){}(not an array)TypeError: input.model.cost?.tiers?.filter is not a functionNote a non-numeric
tier.sizemust not be coerced to 0 when fixing this — that would make the tier match every context instead of none.OpenCode version
Reproduces on current
dev(9b0dd36— i.e. with #43248 already in).Steps to reproduce
Call
getUsagewith a model whosecost.tiersis any of the three shapes above. Three failing unit tests in the PR that follows.Operating System
macOS
Terminal
VS Code integrated terminal