Skip to content

fix(session): port upstream malformed model cost guard (anomalyco/opencode#43248) - #1613

Open
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1792601000-malformed-cost
Open

devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1792601000-malformed-cost

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #1573

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Session.getUsage multiplies token counts by the model's cost fields with decimal.js. When a provider or models.dev entry carries a malformed cost (an object, a string or NaN), new Decimal(...).mul(...) throws DecimalError and the whole turn fails after the model already answered.

Ported from upstream anomalyco/opencode#43248: each cost field goes through a finite() guard, so a non-finite value counts as 0 instead of throwing. Valid fields are still billed. Wrapped in altimate_change markers tagged upstream_fix:.

Note: session/session.ts has a second getUsage copy that nothing imports (callers use session/index.ts), so it is left untouched.

How did you verify your code works?

New test in test/session/session-getusage.test.ts sets input: {}, cache.read: NaN, cache.write: "x" and checks the output cost is still billed (1.5). It throws on main and passes on this branch. bun typecheck and bun run script/upstream/analyze.ts --markers --base origin/main --strict are clean.

Cost side effects

None. No new model calls, queries or resources. Malformed cost fields now count as 0 in the usage total instead of failing the turn.

Screenshots / recordings

N/A, no UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR
  • I checked for cost side effects (model calls, queries or cloud resources that grow with user data) and described them, or wrote "none"

Written by Devin


Summary by cubic

Fixes Session.getUsage so malformed model cost fields (objects, strings, or NaN) are treated as 0 instead of throwing DecimalError and failing the turn. Valid cost fields are still billed. Adds a test covering malformed cost input.

Written for commit 29ebce2. Summary will update on new commits.

View guided diff Turn on auto-fix

@coderabbitai

coderabbitai Bot commented Oct 28, 2026

Copy link
Copy Markdown

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f87fe9d6-adfa-4cfc-b92d-0970b0d58e64

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown

👋 This PR was automatically closed by our quality checks.

Common reasons:

  • New GitHub account with limited contribution history
  • PR description doesn't meet our guidelines
  • Contribution appears to be AI-generated without meaningful review

If you believe this was a mistake, please open an issue explaining your intended contribution and a maintainer will help you.

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Malformed model cost fields crash session usage accounting (DecimalError)

0 participants