anomalyco / anomalyco/opencode

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

Open
#43,254 0 comments 0 reactions 1 assignee View on GitHub

@jlongster is already working on this.

Since Aug 18, 2026.

Dominant language
TypeScript
Stars
209k
Forks
27.5k
PR merge metrics
PR metrics pending

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.