Skip to content

Malformed cost.tiers still crashes the turn (TypeError, not DecimalError) #43254

Description

@macurandb

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

Activity

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions